function resetHandler(e)
{
	var percentages,percentagesLength,i,percentage;
	percentages=['GemelHfrsaP','PizuiimP','ICosherP','Keren2','NikuiP','Nikui47P','KerenP'];//These 7 inputs should be disabled whenever the form resets
	percentagesLength=percentages.length;
	for(i=0;i<percentagesLength;i++)
	{
		percentage=document.getElementById(IDPREFIX+percentages[i]);
		removeClass('Disabled',percentage,true);
		percentage.readOnly=false;
	}
}
//Resizes elements when window resizes
function resizeHandler(e)
{
	var container,children,childrenLength,i,heights,
		matzav,yeshuv,radios,radiosLength,
		nikui,nikui47,keren,other;
	container=document.getElementById('Container');
	children=container.childNodes;
	childrenLength=children.length;
	heights=[];
	for(i=0;i<childrenLength;i++)
	{
		if('number'===typeof children[i].clientHeight)
		{
			heights.push(children[i].clientHeight);
		}
	}
	heights.sort(Array.numericSort);
	for(i=0;i<childrenLength;i++)
	{
		if(('number'===typeof children[i].clientHeight)&&(0!==children[i].clientHeight))
		{
			children[i].style.height=heights[heights.length-1]+'px';
		}
	}
	//MSIE specific fixes.
	if(true===window.IE)
	{
		if(true!==window.resized)
		{
			other=document.getElementById(IDPREFIX+'Other');
			children=document.getElementById(IDPREFIX+'Children');
			radios=document.forms[0][NAMEPREFIX+'Deduction'];
			//radiosLength=radios.length;
			yeshuv=document.getElementById(IDPREFIX+'Yeshuv');
			yeshuv.style.width=(children.clientWidth-20)+'px';
			matzav=document.getElementById(IDPREFIX+'Matzav');
			matzav.style.width=(children.clientWidth+4)+'px';
//			for(i=0;i<radiosLength;i++)
//			{
//				radios[i].parentNode.nextSibling.style.position='relative';
//				radios[i].parentNode.nextSibling.style.top='-0.5em';
//			}
			if(990<document.documentElement.clientWidth)
			{
				nikui=document.getElementById(IDPREFIX+'Nikui');
				nikui47=document.getElementById(IDPREFIX+'Nikui47');
				keren=document.getElementById(IDPREFIX+'Keren');
				nikui.size=nikui47.size=keren.size=other.size;
			}
			window.resized=true;
		}
	}
}
//Allows the reset buttons to work correctly by assigning an empty string as the callbacked input's default value 
function resetCarValue()
{
	var car,tmp;
	car=document.getElementById(IDPREFIX+'Car');
	tmp=car.value;
	car.value='';
	car.defaultValue='';
	car.setAttribute('value','');
	car.value=tmp;
}
//Prevents browser from navigating to '#' (top of page) when clicking on settlements anchors
function abortNavigation(e)
{
	var evt,anchor;
	evt=new CommonEvent(e);
	anchor=evt.sender.href;
	evt.sender.href='';
	evt.sender.removeAttribute('href');
	setTimeout(function(){evt.sender.href=anchor;},0);
	evt.cancel();
	return false;
}
//Async callback, updates settlement list depending on the selected date
function updateYeshuv(e)
{
	var evt;
	window[IDPREFIX+'YeshuvCallback'].lastValue=document.getElementById(IDPREFIX+'Yeshuv').value;
	window[IDPREFIX+'YeshuvCallback'].Callback(document.getElementById(IDPREFIX+'MmNow').value,document.getElementById(IDPREFIX+'YyNow').value);
	evt=new CommonEvent(e);
	evt.cancel();
	return false;
}
//Selects an option from the options list of the settlements DropDownLists, selected value is determined according to the clicked anchor's text
function assignSelectedSettlement(e)
{
	var evt,settlement,i,settlementsList,settlements,settlementsLength;
	evt=new CommonEvent(e);
	settlementsList=document.getElementById(IDPREFIX+'Yeshuv');
	settlements=settlementsList.options;
	settlementsLength=settlements.length;
	settlement=evt.sender.firstChild.nodeValue;
	for(i=0;i<settlementsLength;i++)
	{
		if(settlements[i].text===settlement)
		{
			settlements[i].selected=true;
			break;
		}
	}
	toggleSearch(null);
	settlementsList.focus();
}
//Updates the UL list-items so only elements with matching values remain on display
function updateSearch(e)
{
	var evt,i,searchExpression,settlementsList,settlements,settlementsLength,searchArea;
	settlementsList=document.getElementById('SettlementsUL');
	settlements=settlementsList.childNodes;
	settlementsLength=settlements.length;
	evt=new CommonEvent(e);
	searchExpression=evt.sender.value;
	searchArea=document.getElementById('SearchArea');
	for(i=0;i<settlementsLength;i++)
	{
		if(0===settlements[i].firstChild.firstChild.nodeValue.indexOf(searchExpression))
		{
			removeClass('Gone',settlements[i],true);
		}
		else
		{
			addClass('Gone',settlements[i],false);
		}
	}
}
//Toggles the settlement search area
function toggleSearch(e)
{
	var evt,searchArea,tmp,searchAreaHead,searchAreaBody;
	searchArea=document.getElementById('SearchArea');
	if(hasClass('Gone',searchArea))
	{
		removeClass('Gone',searchArea,true);
		searchAreaHead=document.getElementById('SearchAreaHead');
		searchAreaBody=document.getElementById('SearchAreaBody');
		searchArea.style.width=(4+(tmp=searchArea.previousSibling.previousSibling.clientWidth))+'px';
		searchAreaBody.style.width=searchAreaHead.style.width=searchAreaBody.parentNode.parentNode.clientWidth+'px';
		if(0===tmp)
		{//MSIE goes here
			searchArea.style.width=(Math.round((document.body.clientWidth-173)/2))+'px';
		}
	}
	else
	{
		addClass('Gone',searchArea,false);
	}
	if(null!==e)//Actual event, prevent form-submit.
	{
		evt=new CommonEvent(e);
		evt.cancel();
	}
	return false;
}
//Async callback, updates 'Car' input with values from the server, also - hides invalid car type(depending on selected year)
function updateCarType(e)
{
	var carType,mmNow,yyNow,year;
	carType=document.getElementById(IDPREFIX+'CarType');
	mmNow=document.getElementById(IDPREFIX+'MmNow');
	yyNow=document.getElementById(IDPREFIX+'YyNow');
	year=Number(yyNow.value);
	if(null!==carType.seven)
	{
		carType.appendChild(carType.seven);
		carType.seven=null;
	}
	if(2004>year)
	{
		if(7==carType.selectedIndex)
		{
			carType.selectedIndex--;
		}
		carType.seven=carType.removeChild(carType.options[7]);
	}
	window[IDPREFIX+'CarCallBack'].Callback(carType.value,
											mmNow.value,
											yyNow.value);
}
//Toggles working spouse checkbox div
function toggleBenZug(e)
{
	var benZugDiv,matzav;
	benZugDiv=document.getElementById(IDPREFIX+'BenZug').parentNode.parentNode;
	matzav=document.getElementById(IDPREFIX+'Matzav');
	if((1===matzav.selectedIndex)||(5===matzav.selectedIndex))
	{
		removeClass('Gone',benZugDiv,true);
	}
	else
	{
		addClass('Gone',benZugDiv,false);
	}
}
//Stores an async call return value in the widows past results buffer.
//Excessive values are shifted out
function storeResult(e)
{
	if(null!==window.lastResult)
	{
		window.pastResults.push(window.lastResult);
		window.lastResult=null;
		if(6<window.pastResults.length)
		{
			window.pastResults.shift();
		}
		if(1<window.pastResults.length)
		{
			removeClass('Gone',document.getElementById('TopHistory'),true);
			removeClass('Gone',document.getElementById('BottomHistory'),true);
		}
	}
}
//Removes values from 'Disabled' form fields.
function resetForm(e)
{
	var evt,form,elements,elementsLength,i,monetary,percentage,idx;
	if(null!==e)
	{
		evt=new CommonEvent(e);
	}
	form=document.forms[0];
	elements=form.elements;
	elementsLength=elements.length;
	monetary=['GemelHfrsa','Pizuiim','ICosher','Keren2','Nikui','Nikui47','Keren'];//These 7 inputs reset only if their counterparts are disabled
	for(i=0;i<elementsLength;i++)
	{
		if((null!==e)&&(elements[i]===evt.sender)){continue;}
		if((hasClass('Disabled',elements[i]))&&('Car'!==elements[i].id.replace(IDPREFIX,'')))
		{
			elements[i].value='';
		}
		else if(-1!==(idx=monetary.indexOf(elements[i].id.replace(IDPREFIX,''))))
		{
			percentage=document.getElementById(IDPREFIX+monetary[idx]+'P');
			if(!hasClass('Disabled',percentage))
			{
				elements[i].value='';
			}
		}
	}
}
//Inits the page, sets global-constant values, attaches event listeners
function body_Load()
{
	var form,carType,mmNow,yyNow,
		searchButton,closeButton,
		dynamicFilterTextBox,dynamicFilter,
		matzav,i,elements,elementsLength,
		//Checkboxes
		rGemelHfrsa,rPizuiim,rICosher,
		rKeren2,rNikui,rNikui47,rKeren,
		//'Kupot' TextBoxes
		gemelHfrsa,pizuiim,
		iCosher,keren2,
		nikui,nikui47,keren,
		//radios
		radios,radiosLength,
		//PayTax
		payTaxP,
		//Dates
		taarLeida,taarAlia,taarGius,taarShichrur,
		//Buttons
		topCalculate,bottomCalculate,
		topHistory,bottomHistory,
		yeshuv;

	form=document.forms[0];
	attachEventListener('submit',form,function(e)
	{//Gecko needs this, it allows us to prevent doing a form.submit() when doing async calls
		var evt=new CommonEvent(e);
		evt.cancel();
		return false;
	});

	searchButton=document.getElementById('SearchButton');
	closeButton=document.getElementById('CloseButton');
	dynamicFilter=document.getElementById('DynamicFilter');

	carType=document.getElementById(IDPREFIX+'CarType');
	mmNow=document.getElementById(IDPREFIX+'MmNow');
	yyNow=document.getElementById(IDPREFIX+'YyNow');
	matzav=document.getElementById(IDPREFIX+'Matzav');

	rGemelHfrsa=document.getElementById(IDPREFIX+'RGemelHfrsa');
	rPizuiim=document.getElementById(IDPREFIX+'RPizuiim');
	rICosher=document.getElementById(IDPREFIX+'RICosher');
	rKeren2=document.getElementById(IDPREFIX+'RKeren2');
	rNikui=document.getElementById(IDPREFIX+'RNikui');
	rNikui47=document.getElementById(IDPREFIX+'RNikui47');
	rKeren=document.getElementById(IDPREFIX+'RKeren');
	
	gemelHfrsa=document.getElementById(IDPREFIX+'GemelHfrsa');
	pizuiim=document.getElementById(IDPREFIX+'Pizuiim');
	iCosher=document.getElementById(IDPREFIX+'ICosher');
	keren2=document.getElementById(IDPREFIX+'Keren2');
	nikui=document.getElementById(IDPREFIX+'Nikui');
	nikui47=document.getElementById(IDPREFIX+'Nikui47');
	keren=document.getElementById(IDPREFIX+'Keren');

	payTaxP=document.getElementById(IDPREFIX+'PayTaxP');

	taarLeida=document.getElementById(IDPREFIX+'TaarLeida');
	taarAlia=document.getElementById(IDPREFIX+'TaarAlia');
	taarGius=document.getElementById(IDPREFIX+'TaarGius');
	taarShichrur=document.getElementById(IDPREFIX+'TaarShichrur');

	topCalculate=document.getElementById(IDPREFIX+'TopCalculateButton');
	bottomCalculate=document.getElementById(IDPREFIX+'BottomCalculateButton');
	topHistory=document.getElementById('TopHistory');
	bottomHistory=document.getElementById('BottomHistory');

	yeshuv=document.getElementById(IDPREFIX+'Yeshuv');

	attachEventListener('change',taarLeida,validateDate);
	attachEventListener('change',taarLeida,updateNikui47Percentage);
	attachEventListener('change',taarAlia,validateDate);
	attachEventListener('change',taarGius,validateDate);
	attachEventListener('change',taarShichrur,validateDate);

	elements=form.elements;
	elementsLength=elements.length;
	for(i=0;i<elementsLength;i++)
	{
		if((('text'===elements[i].type)&&(!hasClass('Disabled',elements[i])))||('select-one'===elements[i].type))
		{
			attachEventListener('change',elements[i],resetForm);
		}
	}

	carType.seven=null;//Temp. storage for the unwanted option in carType.
	window[IDPREFIX+'YeshuvCallback'].lastValue=null;//the last 'yeshuv' value selected, will be re-selected once the DropDownList is recreated.
	window.dateRX=new RegExp('^([0-9]{4})-([0-9]{2})-([0-9]{2})T00:00:00$');//RegExp, matches dates.
	window.lastResult=null;//Last result received from the server

	//Settlements depend on date
	attachEventListener('change',yyNow,updateYeshuv);
	attachEventListener('change',mmNow,updateYeshuv);
	//Vehicle worth depends on date and type
	attachEventListener('change',yyNow,updateCarType);
	attachEventListener('change',mmNow,updateCarType);
	attachEventListener('change',carType,updateCarType);

	//Search mechanism
	attachEventListener('click',searchButton,toggleSearch);
	attachEventListener('click',closeButton,toggleSearch);
	attachEventListener('keyup',dynamicFilter,updateSearch);
	attachEventListener('change',dynamicFilter,updateSearch);
	populateSearch();//Fills the search area with values from the drop-down list

	//Only married users are asked for spouse employment status
	attachEventListener('change',matzav,toggleBenZug);
	toggleBenZug(null);

	//Resize elements when window resizes
	attachEventListener('resize',window,resizeHandler);
	resizeHandler(null);

	//Attaches listeners that 'power-up' the 'kupot' related fields, these fields availability depends on each other
	attachEventListener('click',rGemelHfrsa,toggleInputs);
	attachEventListener('click',rGemelHfrsa,toggleLinkedInputs);
	attachEventListener('click',rPizuiim,toggleInputs);
	attachEventListener('click',rICosher,toggleInputs);
	attachEventListener('click',rKeren2,toggleInputs);
	attachEventListener('click',rKeren2,toggleLinkedInputs);
	attachEventListener('click',rNikui,toggleInputs);
	attachEventListener('click',rNikui,toggleLinkedInputs);
	attachEventListener('click',rNikui47,toggleInputs);
	attachEventListener('click',rKeren,toggleInputs);
	attachEventListener('click',rKeren,toggleLinkedInputs);

	//Attaches listeners that disable the percentages textboxes whenever a monetary value is assigned to a neighboring textbox
	attachEventListener('change',gemelHfrsa,disableNeighboringPercentageTextBox);
	attachEventListener('change',pizuiim,disableNeighboringPercentageTextBox);
	attachEventListener('change',iCosher,disableNeighboringPercentageTextBox);
	attachEventListener('change',keren2,disableNeighboringPercentageTextBox);
	attachEventListener('change',nikui,disableNeighboringPercentageTextBox);
	attachEventListener('change',nikui47,disableNeighboringPercentageTextBox);
	attachEventListener('change',keren,disableNeighboringPercentageTextBox);

	attachEventListener('reset',form,resetHandler);

	//Deduction radios cause the top 'Kupot' percentages textBoxes to change values
	radios=document.forms[0][NAMEPREFIX+'Deduction'];
//	radiosLength=radios.length;
//	for(i=0;i<radiosLength;i++)
//	{
//		attachEventListener('click',radios[i],resetPercentages);
//	}

	//Allows translations between enum values(matzav.options[i].value) and hebrew texts (matzav.options[i].text)
	window.maritalStatus={};
	for(i=0;i<matzav.options.length;i++)
	{
		window.maritalStatus[matzav.options[i].value]=matzav.options[i].text;
	}

	attachEventListener('change',payTaxP,resetEmployerTax);

	updateHelpAnchors();//Allows helpful anchors to spawn pop-ups

	//Async calculation
	attachEventListener('click',topCalculate,calculate);
	attachEventListener('click',bottomCalculate,calculate);

	//Pops-up the history page
	window.pastResults=[];//History storage.
	attachEventListener('click',topHistory,showHistory);
	attachEventListener('click',bottomHistory,showHistory);
	
}
//Resets the employerTax dropdown list
function resetEmployerTax(e)
{
	var evt;
	evt=new CommonEvent(e);
	if((0==evt.sender.selectedIndex)||(2==evt.sender.selectedIndex))
	{
		document.getElementById(IDPREFIX+'EmployerTaxP').selectedIndex=0;
	}
}
//Resets percentages upon radio button click
function resetPercentages(e)
{
	var evt,nikuiP,gemelHfrsaP;
	evt=new CommonEvent(e);
	nikuiP=document.getElementById(IDPREFIX+'NikuiP');
	gemelHfrsaP=document.getElementById(IDPREFIX+'GemelHfrsaP');
	resetForm(null);
	if('Mekifa'===evt.sender.value)
	{
		nikuiP.value='5.5';
		nikuiP.defaultValue='5.5';
		nikuiP.setAttribute('value','5.5');
		gemelHfrsaP.value='6.0';
		gemelHfrsaP.defaultValue='6.0';
		gemelHfrsaP.setAttribute('value','6.0');
	}
	else
	{
		nikuiP.value='5.0';
		nikuiP.defaultValue='5.0';
		nikuiP.setAttribute('value','5.0');
		gemelHfrsaP.value='5.0';
		gemelHfrsaP.defaultValue='5.0';
		gemelHfrsaP.setAttribute('value','5.0');
	}
}
//Updates Nikui47P according to the birth date
function updateNikui47Percentage(e)
{
	var evt,nikui47P,dateObj,yyNow,year;
	evt=new CommonEvent(e);
	nikui47P=document.getElementById(IDPREFIX+'Nikui47P');
	yyNow=document.getElementById(IDPREFIX+'YyNow');
	dateObj={year:0,month:0,day:0};
	normalizeDate(evt.sender.value,normalizeDate.defaultRX,dateObj);
	year=Number(yyNow.options[yyNow.selectedIndex].value);
	if(!hasClass('Disabled',nikui47P))
	{
		if( (year > (dateObj.year+50) ) || ( (year >= (dateObj.year+50) ) && (1===dateObj.month) && (1===dateObj.day) ) )
		{
			nikui47P.value='7.5';
		}
		else
		{
			nikui47P.value='5.0';
		}
	}
}

//Locks the related percentage textbox
function disableNeighboringPercentageTextBox(e)
{
	var evt,i;
	evt=new CommonEvent(e);
	evt.sender.nextSibling.value='';
	addClass('Disabled',evt.sender.nextSibling,false);
	evt.sender.nextSibling.readOnly=true;
	for(i=0;i<Page_Validators.length;i++)
	{
		ValidatorValidate(Page_Validators[i]);
	}
}
//Toggles the 4 textboxes that are only available when their neighboring checkboxes are checked.
//simulates click-events on linked checkboxes.
function toggleLinkedInputs(e)
{
	var evt,linkedInput,sourceId,i,radios,radiosLength;
	evt=new CommonEvent(e);
	sourceId=evt.sender.id.replace(IDPREFIX,'');
	switch(sourceId)
	{
		case 'RGemelHfrsa':
			linkedInput=document.getElementById(IDPREFIX+'RNikui');
			break;
		case 'RNikui':
			linkedInput=document.getElementById(IDPREFIX+'RGemelHfrsa');
			break;
		case 'RKeren2':
			linkedInput=document.getElementById(IDPREFIX+'RKeren');
			break;
		case 'RKeren':
			linkedInput=document.getElementById(IDPREFIX+'RKeren2');
			break;
	}
	linkedInput.checked=evt.sender.checked;
	toggleInputs({target:linkedInput});
	if(('RGemelHfrsa'===sourceId)||('RNikui'===sourceId))
	{
		radios=document.forms[0][NAMEPREFIX+'Deduction'];
//		radiosLength=radios.length;
//		for(i=0;i<radiosLength;i++)
//		{
//			radios[i].disabled=!evt.sender.checked;
//		}
	}
}
//Toggles the 7 textboxes that are only available when their neighboring checkboxes are checked.
function toggleInputs(e)
{
	var evt,i,inputs,inputsLength;
	evt=new CommonEvent(e);
	inputs=evt.sender.parentNode.parentNode.getElementsByTagName('input');
	inputsLength=inputs.length;
	for(i=0;i<inputsLength;i++)
	{
		if((evt.sender.checked)&&(inputs[i]!==evt.sender))
		{
			inputs[i].value=inputs[i].defaultValue;
			inputs[i].readOnly=false;
			removeClass('Disabled',inputs[i],true);
		}
		else if(inputs[i]!==evt.sender)
		{
			inputs[i].value='';
			inputs[i].readOnly=true;
			addClass('Disabled',inputs[i],false);
		}
	}
	resetForm(null);
}
//fills the search area with the values from the settlements DropDownLists, assigns event handlers and other attributes wherever needed
function populateSearch()
{
	var ul,li,a,yeshuv,yeshuvLength,i,searchAreaBody,searchAreaHead,lastValue;
	searchAreaBody=document.getElementById('SearchAreaBody');
	searchAreaHead=document.getElementById('SearchAreaHead');
	yeshuv=document.getElementById(IDPREFIX+'Yeshuv');
	searchAreaBody.style.overflowX='hidden';
	yeshuvLength=yeshuv.options.length;
	ul=document.getElementById('SettlementsUL');
	if(null!==ul){ul.parentNode.removeChild(ul);}
	ul=document.createElement('ul');
	ul.id='SettlementsUL';
	lastValue=window[IDPREFIX+'YeshuvCallback'].lastValue;
	for(i=1;i<yeshuvLength;i++)
	{
		if(yeshuv.options[i].value==lastValue){yeshuv.selectedIndex=i;}
		ul.appendChild(li=document.createElement('li'));
		a=document.createElement('a');
		addClass('Anchor',a,false);
		a.appendChild(document.createTextNode(yeshuv.options[i].firstChild.nodeValue));
		a.href='#';
		attachEventListener('click',a,abortNavigation);
		attachEventListener('click',a,assignSelectedSettlement);
		li.appendChild(a);
		a=null;
		li=null;
	}
	searchAreaBody.appendChild(ul);
	updateSearch({target:document.getElementById('DynamicFilter')});
}
//Date custom validator, allows user to enter our custom date format.
function validateDate(e)
{
	var evt         =   new CommonEvent(e);
	var passedDate  =   normalizeDate(evt.sender.value,normalizeDate.defaultRX,null);
	var passedYear  =   passedDate.substring(6,10);
	var currentDate =   new Date();
	var currentYear =   currentDate.getFullYear();
	if ((passedYear * 1) > currentYear)
	{
	    evt.sender.value = passedDate.substring(0,6) + ((passedYear * 1) - 100);
	}
	else
	{
	    evt.sender.value = passedDate;
	}
}
//Main calculation goes here (via async callback)...
function calculate(e)
{
	setTimeout(function(){//Workaround for MSIE delay in updating form-field values
		var elements,elementsLength,i,params,id,value;
		for(i=0;i<Page_Validators.length;i++)
		{
			ValidatorValidate(Page_Validators[i]);
			if(false===Page_Validators[i].isvalid){return;}
		}
		elements=document.forms[0].elements;
		elementsLength=elements.length;
		params=[];
		for(i=0;i<elementsLength;i++)
		{
			if(('select-one'===elements[i].type)||('checkbox'===elements[i].type)||('radio'===elements[i].type)||('text'===elements[i].type))
			{
				//if((('undefined'===typeof elements[i].readOnly)||(false===elements[i].readOnly))&&('DynamicFilter'!==elements[i].id))
				//{
					id=elements[i].id.replace(IDPREFIX,'');
					if(('checkbox'===elements[i].type)||('radio'===elements[i].type))
					{
						value=elements[i].checked;
					}
					else
					{
						value=elements[i].value.replace(/,/g,'');
					}
					params.push([id,value]);
				//}
			}
		}
		addClass('CallBackInProgress',document.body,true);
		window[IDPREFIX+'HiddenCallback'].Callback(params.join('\t'));
	},0);
}
//Async callback , populates the form-fields value attribute with data from the server
function updateFields()
{
	var resultsString,lines,linesLength,i,j,k,
		lineArray,field,matches,select,
		options,optionsLength,
		value,day,month,year,
		childrenStart,childrenEnd,
		childrenStr,shnati=false;
	removeClass('CallBackInProgress',document.body,false);
	resultsString=document.getElementById(IDPREFIX+'Results').value;
	//Results arrive as an xml document stored within the textarea ('Results').
	//These string.replace calls transorm it into a id<tab>value<newline> list
	resultsString=resultsString.replace(/xmlns="http:\/\/tempuri.org\/"/g,'');//Namespace has no meaning in this context
	resultsString=resultsString.replace(/<([^>]*)>([^<]*)<\/([^>]*)>/g,'$1\t$2');//XML becoms tab separated
	//Not really needed...Though it looks nicer.
	resultsString=resultsString.replace('<?xml version="1.0"?>','');
	resultsString=resultsString.replace('<HOvedDescription xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">','');
	resultsString=resultsString.replace('</HOvedDescription>','');
	resultsString=resultsString.replace(/[ \r\f\u00A0\u2028\u2029]/g,'');//Remove whitespace, tabs and newlines(delimiters)
	resultsString=resultsString.replace('<Children/>','Children\t0');
	if(-1!==(childrenStart=resultsString.indexOf('<Children>')))
	{
		if(-1!==(childrenEnd=resultsString.lastIndexOf('</Children>')))
		{
			childrenStr=resultsString.substr(childrenStart,11+childrenEnd-childrenStart);
			childrenStr.match(/<SerializableKeyValuePairOfDateTimeNullableOfBoolean>/g).length
			resultsString=resultsString.substr(0,childrenStart)+'Children\t'+childrenStr.match(/<SerializableKeyValuePairOfDateTimeNullableOfBoolean>/g).length+resultsString.substr(11+childrenEnd);
		}
	}
	lines=resultsString.split('\n');
	window.lastResult=lines;
	storeResult(null);
	linesLength=lines.length;
	shnati=false;
	for(i=0;i<linesLength;i++)
	{
		lineArray=lines[i].split('\t');
		if(2!==lineArray.length){continue;}//Malformed line
		if(null!==(field=document.getElementById(IDPREFIX+lineArray[0])))
		{
			if(hasClass('Untouchable',field))
			{
				//TextBox with 'Untouchable' class should not be updated
				continue;
			}
			if('text'===field.type)//Most inputs belong here...
			{
				matches=window.dateRX.exec(lineArray[1]);
				value=null;
				if((null!==matches)&&(4===matches.length))
				{//Date, note that value remains null
					day=matches[3];
					month=matches[2];
					year=matches[1];
					if((1===Number(day))&&(1===Number(month))&&(1===Number(year)))
					{//DateTime.MinValue
						lineArray[1]='';
					}
					else
					{
						lineArray[1]=day+'/'+month+'/'+year;
					}
				}
				else
				{//Should be numeric
					value=Number(lineArray[1]);
				}
				if('number'===typeof value)
				{
					if(0===value)
					{//Zero is rendered as an empty string
						value='';
					}
					else if(field.id.replace(IDPREFIX,'')!=='Children')//Obviously 'Children' should not be presented in fixed point.
					{//Non-zero get two digits precision regardless of their actual value
						value=Number.beautify(value);
					}
					field.value=value;
				}
				else if(null===value)
				{//Date...
					field.value=lineArray[1];
				}
			}
		}
		else
		{//Special treatment
			if('Taarich'===lineArray[0])
			{//The month/year dropdown is populated from this value
				matches=window.dateRX.exec(lineArray[1]);
				if((null!==matches)&&(4===matches.length))
				{
					select=document.getElementById(IDPREFIX+'YyNow');
					options=select.options;
					optionsLength=options.length;
					for(j=0;j<optionsLength;j++)
					{
						if(Number(options[j].value)===Number(matches[1]))
						{
							select.selectedIndex=j;
							break;
						}
					}
					select=document.getElementById(IDPREFIX+'MmNow');
					options=select.options;
					optionsLength=options.length;
					if(true===shnati)
					{
						select.selectedIndex=optionsLength-1;
					}
					else
					{
						for(j=0;j<optionsLength;j++)
						{
							if(Number(options[j].value)===Number(matches[2]))
							{
								select.selectedIndex=j;
								break;
							}
						}
					}
				}
			}
			else if(('Shnati'===lineArray[0])&&('true'===lineArray[1]))
			{
				//This depends on the order in which the fields are presented to us within the xml response.
				//Should MmNow arrive ahead of Shnati the wrong value will be displayed on the dropdown list
				shnati=true;
			}
		}
	}
}
//An "at least one of four fields is required" custom validator validation function
function checkRequiredFields(source,args)
{
	var maskoret,shonot,netoGilum,netoGilumPens;
	maskoret=document.getElementById(IDPREFIX+'Maskoret');
	shonot=document.getElementById(IDPREFIX+'Shonot');
	netoGilum=document.getElementById(IDPREFIX+'NetoGilum');
	netoGilumPens=document.getElementById(IDPREFIX+'NetoGilumPens');
	args.IsValid=!((''===ValidatorTrim(maskoret.value))&&(''===ValidatorTrim(shonot.value))&&(''===ValidatorTrim(netoGilum.value))&&(''===ValidatorTrim(netoGilumPens.value)));
}
//Displays the history pop-up
function showHistory(e)
{
	var history, windowFeatures,historyTable;
	history=window.popUps.history;
	windowFeatures='top=0,left=0,channelmode=0,directories=1,fullscreen=0,menubar=1,location=1,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=1,width='+screen.availWidth+',height='+screen.availHeight;
	if('object'===typeof history)
	{
		history.close();
		delete history;
	}
	if('undefined'===typeof history)
	{
		history=window.popUps.history=window.open('NetWizardHistory.html','history');
	}
	if(true===history.closed)
	{
		history=window.popUps.history=window.open('NetWizardHistory.html','history');
	}
}
function DoSetEmployeeTaxDiv(ddl)
{
  var ddlEmployerTax;
  if ((ddl.value * 1) >= 2008)
  {
    ddlEmployerTax = document.getElementById(IDPREFIX+'EmployerTaxP');
    ddlEmployerTax.selectedIndex = 0;
    EmployerTaxDiv.style.display='none';
	}
	else
	{
    EmployerTaxDiv.style.display='';
	}
}