function updateCar(e)
{
	var carType;
	carType=document.getElementById(IDPREFIX+'CarType');
	if(0===carType.selectedIndex)
	{
		document.getElementById(IDPREFIX+'Car').value='';
	}
	else
	{
		window[IDPREFIX+'CarCallBack'].Callback(carType.value);
	}
}
function fixTable(table)
{
	var tHead,tBody,i,j;
	tHead=table.createTHead();
	tBody=table.tBodies[0];
	tHead.appendChild(tBody.rows[0]);
	removeClass('InnerDataTablesTH',tHead.rows[0],true);
	for(i=0;i<tHead.rows[0].cells.length;i++)
	{
		addClass('InnerDataTablesTH InnerDataTablesBottomTH',tHead.rows[0].cells[i],false);
	}
	for(i=0;i<tBody.rows.length;i++)
	{
		removeClass('InnerDataTablesTD',tBody.rows[i],true);
		for(j=0;j<tBody.rows[i].cells.length;j++)
		{
			addClass('InnerDataTablesTD',tBody.rows[i].cells[j],false);
			if(i!==0)
			{
				addClass('ltr',tBody.rows[i].cells[j],false);
			}
			if(j===(tBody.rows[i].cells.length-1))
			{
				addClass('InnerDataTablesLastTD',tBody.rows[i].cells[j],false);
			}
			if(i===(tBody.rows.length-1))
			{
				addClass('InnerDataTablesBottomTD',tBody.rows[i].cells[j],false);
			}
			if(0>Number(tBody.rows[i].cells[j].firstChild.nodeValue.replace(/,/g,'')))//Percentages will always return false here...
			{
				tBody.rows[i].cells[j].style.color='red';
			}
		}
	}
	addClass('InnerDataTablesLastTH',tHead.rows[0].cells[tHead.rows[0].cells.length-1],false);
}
function revealResults()
{
	var table,error,header,headerRow,headerCell;
	table=document.getElementById(IDPREFIX+'Results');
	if(null!==table)
	{
		fixTable(table);
		table=document.getElementById(IDPREFIX+'RechevResults');
		if(null!==table)
		{
			fixTable(table);
			header=document.getElementById(IDPREFIX+'RechevHeader');
			headerRow=table.tHead.insertRow(0);
			headerCell=headerRow.appendChild(document.createElement('th'));
			headerCell.colSpan=table.tHead.rows[table.tHead.rows.length-1].cells.length;
			headerCell.appendChild(document.createTextNode(header.firstChild.nodeValue));
			addClass('InnerDataTablesTH InnerDataTablesLastTH',headerCell,false);
			header.parentNode.removeChild(header);
		}
		removeClass('Hidden',document.getElementById(IDPREFIX+'ResultsCallBack_div'),true);
	}
	else if(null!==(error=document.getElementById('error')))
	{
		alert(error.value);
	}
}
function doAsyncCall(e)
{
	var evt,maskoret,carType,matzav,children;
	if(true===Page_ClientValidate())
	{
		maskoret=document.getElementById(IDPREFIX+'Maskoret').value;
		carType=document.getElementById(IDPREFIX+'CarType').value;
		matzav=document.getElementById(IDPREFIX+'Matzav').value;
		children=document.getElementById(IDPREFIX+'Children').value;
		children=(''===children)?'0':children;
		addClass('Hidden',document.getElementById(IDPREFIX+'ResultsCallBack_div'),false);
		window[IDPREFIX+'ResultsCallBack'].Callback(maskoret,carType,matzav,children);
	}
	evt=new CommonEvent(e);
	evt.cancel();
	return false;
}
function body_Load()
{
	var calculateButton,selects,selectsLength,carType,i,maskoret,width,height;
	updateHelpAnchors();
	calculateButton=document.getElementById(IDPREFIX+'CalculateButton');
	carType=document.getElementById(IDPREFIX+'CarType');
	attachEventListener('click',calculateButton,doAsyncCall);
	attachEventListener('submit',calculateButton.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;
	});
	attachEventListener('reset',calculateButton.form,function(e){setTimeout(updateCar,0);});
	attachEventListener('change',carType,updateCar);
	if(window.IE)
	{
		maskoret=document.getElementById(IDPREFIX+'Maskoret');
		width=(maskoret.clientWidth+4)+'px';
		height=(maskoret.clientHeight+4)+'px';
		selects=document.getElementsByTagName('select');
		selectsLength=selects.length;
		for(i=0;i<selectsLength;i++)
		{
			selects[i].style.width=width;
			selects[i].style.height=height;
		}
	}
}
