var intCheckedCars = 0
var strListType = ''
function funCheckBox(strItem){
	if (document.getElementById('frm_'+strItem).checked == true){
		document.getElementById('frm_'+strItem).checked = false;
		document.getElementById('img_'+strItem).src = '_Graphics/CheckBox.gif';
	}
	else{
		document.getElementById('frm_'+strItem).checked = true;
		document.getElementById('img_'+strItem).src = '_Graphics/CheckBox_Active.gif';
	}
	funGetCars(strListType)
}

function funCheckBoxResultCars(strItem){
	if (document.getElementById('frm_'+strItem).checked == true){
		document.getElementById('frm_'+strItem).checked = false;
		document.getElementById('img_'+strItem).src = '_Graphics/CheckBox.gif';
		intCheckedCars = intCheckedCars - 1
	}
	else{
		if (intCheckedCars < 4){
			document.getElementById('frm_'+strItem).checked = true;
			document.getElementById('img_'+strItem).src = '_Graphics/CheckBox_Active.gif';
			intCheckedCars = intCheckedCars + 1
		}
		else{
			alert('U kunt maximaal 4 wagens selecteren');
		}
	}
	document.getElementById('CheckedCars').innerHTML = 'U heeft '+intCheckedCars+' wagen(s) geselecteerd'
}


function funCheckBoxCar(strItem,strType){
	if (document.getElementById('frm_'+strItem).checked == true){
		document.getElementById('frm_'+strItem).checked = false;
		document.getElementById('img_'+strItem).src = '_Graphics/CheckBox.gif';
		if (strType != 'List'){document.getElementById('Image_'+strItem).className = 'Car_Image_DS';}
		else{funGetCars('List');}
	}
	else{
		document.getElementById('frm_'+strItem).checked = true;
		document.getElementById('img_'+strItem).src = '_Graphics/CheckBox_Active.gif';
		if (strType != 'List'){document.getElementById('Image_'+strItem).className = '';}
		else{funGetCars('List');}
	}
}



function funViewPriceType(strUpdateCars){
	if (strUpdateCars != 'No'){
		if (document.getElementById('frm_PriceType_B').checked == true){
			document.getElementById('frm_PriceType_B').checked = false;
			document.getElementById('img_PriceType_B').src = '_Graphics/CheckBox.gif';
			document.getElementById('frm_PriceType_A').checked = true;
			document.getElementById('img_PriceType_A').src = '_Graphics/CheckBox_Active.gif';
		}
		else{
			document.getElementById('frm_PriceType_A').checked = false;
			document.getElementById('img_PriceType_A').src = '_Graphics/CheckBox.gif';
			document.getElementById('frm_PriceType_B').checked = true;
			document.getElementById('img_PriceType_B').src = '_Graphics/CheckBox_Active.gif';
		}
	}
	if (funGetSelectedItem('PriceType') == 'Lease,'){
		document.getElementById('strLeasePrice').style.display = "block";
		document.getElementById('strPrice').style.display = "none";
	}
	else {
		document.getElementById('strPrice').style.display = "block";
		document.getElementById('strLeasePrice').style.display = "none";
	}
	if (strUpdateCars != 'No'){
		funGetCars(strListType)
	}
}

function funGetSelectedItem(strField){
	var strTotal = '';
	for (var i=0; i < document.FrmMain.elements[strField].length; i++) {
		if (document.FrmMain.elements[strField][i].checked){
			strTotal= strTotal+document.FrmMain.elements[strField][i].value+',';
		}
	}
	return strTotal
}



function funGetCars(strListTypeIn){
	intCheckedCars = 0
	strListType = strListTypeIn
	var strLabel 		= funGetSelectedItem('strLabel');
	var strPrice		= document.FrmMain.strPrice.value;
	var strLeasePrice	= document.FrmMain.strLeasePrice.value;
	var strFuel			= funGetSelectedItem('strFuel');
	var strTax			= funGetSelectedItem('strTax');
	var PriceType		= funGetSelectedItem('PriceType');
	var strLeasePrice	= document.FrmMain.strLeasePrice.value;
	
	var xmlHttp;
	try{ // Firefox, Opera 8.0+, Safari  
		xmlHttp=new XMLHttpRequest();  
	}
	catch (e){  // Internet Explorer  
		try{    
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
		}
		catch (e){    
			try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
			}
			catch (e){      
				alert("Your browser does not support AJAX!");      
				return false;      
			}  
		}  
	}

	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
			document.getElementById('Cars').innerHTML = xmlHttp.responseText;
			//alert(xmlHttp.responseText);
		}
	}
	if (strListType == 'List'){
		var strModels		= funGetSelectedItem('Models');
		strScript = 'Get_CarsList.asp?strLabel='+strLabel+'&PriceType='+PriceType+'&strLeasePrice='+strLeasePrice+'&strPrice='+strPrice+'&strFuel='+strFuel+'&strTax='+strTax+'&strModels='+strModels;
		strListType = 'List';
		document.getElementById('CheckedCars').innerHTML = ''
	}
	else{
		strScript = 'Get_Cars.asp?strLabel='+strLabel+'&PriceType='+PriceType+'&strLeasePrice='+strLeasePrice+'&strPrice='+strPrice+'&strFuel='+strFuel+'&strTax='+strTax;
		strListType = '';
	}
	
	xmlHttp.open("GET",strScript,true);
	xmlHttp.send(null); 
}





function funGetCarDetails(intCar,strMethod){
	
	var xmlHttp;
	try{ // Firefox, Opera 8.0+, Safari  
		xmlHttp=new XMLHttpRequest();  
	}
	catch (e){  // Internet Explorer  
		try{    
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
		}
		catch (e){    
			try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
			}
			catch (e){      
				alert("Your browser does not support AJAX!");      
				return false;      
			}  
		}  
	}

	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
			document.getElementById('ContainerCar'+intCar).innerHTML = xmlHttp.responseText;
			//alert(xmlHttp.responseText);
		}
	}
	strScript = 'Get_CarsDetails.asp?Car='+intCar+'&Method='+strMethod;
	
	
	xmlHttp.open("GET",strScript,true);
	xmlHttp.send(null); 
}


function funSubmitResult(){
	if (intCheckedCars <= 0){
		alert('U heeft nog geen wagens geselecteerd.')
	}
	else{
	document.forms['FrmMain'].submit();
	return false;
	}

}


function funViewForm(intCar,strAction,strFormAction,Refer){
	if (strAction == 'Send'){
		strFormAction = 'TenderForm.asp?Action='+strAction+'&Refer='+Refer;
	}
	else if (Refer == 'Result' && strFormAction == 'Return'){
		strFormAction = 'Result.asp';
	}
	else if (Refer == 'Compare' && strFormAction == 'Return'){
		strFormAction = 'Compare.asp';
	}
	else{
		strFormAction = 'TenderForm.asp?Refer='+Refer;
	}
	document.forms["FrmMain"].Car.value = intCar;
	document.forms["FrmMain"].setAttribute('action',strFormAction);
	document.forms['FrmMain'].submit();
}

