refreshModels// AJAX Library 

var ns			=	(window.navigator.appName.toLowerCase() == "netscape");
var ie			=	(window.navigator.appName.toLowerCase() == "microsoft internet explorer"); 
var agt			=	navigator.userAgent.toLowerCase();
var is_major	=	parseInt(navigator.appVersion);
var is_ie5		=	(ie && (is_major == 4) && (agt.indexOf("msie 5")!=-1) );
var is_ie4up	=	(ie && (is_major >= 4));
var is_ns5up	=	(ns && (is_major >= 5));
var is_mac		= 	(agt.indexOf("mac")!=-1); 

var dId;//variable to get derivativeId
var dur;//variable to get time duration
var userduration;//variable to get time duration
var int;//variable to get interest level

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

var http = getHTTPObject();


function refreshModels_pe(manufacturerId)
{ 
	if(manufacturerId > 0)
	{
		//alert("refreshModels called with " + manufacturerId);
		http.open("GET","/gen1/" + manufacturerId + ".xml",true);
		http.onreadystatechange = HttpModelHandler_pe;
		http.send(null);	
		
	}

	document.getElementById("model_name").focus();	
}

function HttpModelHandler_pe()
{
	if(http.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(http.status == 200)
		{
			// data has been collected call populate method with xml tree.
			populateModelOptions_pe(http.responseXML.documentElement);
		}
		else
		{
			alert("Problem retrieving data from the server, status code1: "  + http.status);
		}
	}
}

function getOptionDetails(rType,rid)
{
		var der_id=document.getElementById("lead[derivativeid]").value;
		http.open("GET","/relationDetails.php?rid="+rid+"&rtype="+rType+"&did="+der_id,true);
		http.onreadystatechange = relationDetails;
		http.send(null);	
}


function populateModelOptions_pe(modelsNode)
{
	var modelList = document.getElementById("model_name");	
	for (var count = modelList.options.length-1; count >-1; count--)
	{
		modelList.options[count] = null;
	}

	var modelNodes = modelsNode.getElementsByTagName("model");

	var idValue;
	var textValue; 
	var optionItem;
	
    var manufactureridList = document.getElementById("manufacturer_name");
	var manufacturer_nameList = document.getElementById("pe_form[manufacturerid_pe]");
	manufacturer_nameList.value = manufactureridList.options[manufactureridList.options.selectedIndex].text;
   // populate the dropdown list with data from the xml doc
	for (var count = 0; count < modelNodes.length; count++)
	{
   		//textValue = GetInnerText(modelNodes[count]);
  		idValue = modelNodes[count].getAttribute("id");
  		textValue = modelNodes[count].getAttribute("modelname");
		optionItem = new Option( textValue, idValue,  false, false);
		modelList.options[modelList.length] = optionItem;
	}
}


function updateModel()
{
    var modelidList = document.getElementById("model_name");
	var model_nameList = document.getElementById("pe_form[modelid_pe]");
	model_nameList.value = modelidList.options[modelidList.options.selectedIndex].text;

}

function refreshModels(manufacturerId)
{
dur="";	
document.navfrm.duration.value = "-1";
document.navfrm.interest.value = "-1";
document.getElementById("carconfig").style.display = "none";
document.getElementById("configinstruction").style.display = "block";


	if(manufacturerId > 0)
	{
		//alert("refreshModels called with " + manufacturerId);
		http.open("GET","/gen1/" + manufacturerId + ".xml",true);
		http.onreadystatechange = HttpModelHandler;
		http.send(null);	
		
	}

	// need to clear the derivative list		
	
	var derivativeList = document.getElementById("derivativeid");	
	for (var count = derivativeList.options.length-1; count >-1; count--)
	{
		derivativeList.options[count] = null;
	}
	
	
	optionItem = new Option("Select version", "",  false, false);
	derivativeList.options[derivativeList.length] = optionItem;	
	
	// refresh the spec window.
	/*document.getElementById("carconfig").innerHTML = "";
	document.getElementById("submitForm").style.visibility="hidden";
	document.getElementById("carconfig").style.display = "none";
	document.getElementById("configinstruction").style.display = "block";*/
	// focus derivative window
	document.getElementById("modelid").focus();
	
	// Temporary to write details to page
document.getElementById('selectedDetail').innerHTML = "http://www.motorati.co.uk/mycar.php?t=quote";
	document.getElementById('selectedDetail').innerHTML += '&manufacturer=' + manufacturerId;
	
}

function HttpModelHandler()
{
	if(http.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(http.status == 200)
		{
			// data has been collected call populate method with xml tree.
			populateModelOptions(http.responseXML.documentElement);
		}
		else
		{
			alert("Problem retrieving data from the server, status code2: "  + http.status);
		}
	}
}

function populateModelOptions(modelsNode)
{
	var modelList = document.getElementById("modelid");	
	for (var count = modelList.options.length-1; count >-1; count--)
	{
		modelList.options[count] = null;
	}

	var modelNodes = modelsNode.getElementsByTagName("model");

	var idValue;
	var textValue; 
	var optionItem;
	
	
	// populate the dropdown list with data from the xml doc
	for (var count = 0; count < modelNodes.length; count++)
	{
		if (modelNodes[count].getAttribute("year_dis")=="0" || modelNodes[count].getAttribute("modelname")== "Select model" || modelNodes[count].getAttribute("modelname")== "Select Model"){
			//textValue = GetInnerText(modelNodes[count]);
			idValue = modelNodes[count].getAttribute("id");
			textValue = modelNodes[count].getAttribute("modelname");
			optionItem = new Option( textValue, idValue,  false, false);
			modelList.options[modelList.length] = optionItem;
		}
	}
}

function refreshDerivatives(modelId)
{
dur="";	
document.navfrm.duration.value = "-1";
document.navfrm.interest.value = "-1";
document.getElementById("carconfig").style.display = "none";
document.getElementById("configinstruction").style.display = "block";

	if(modelId > 0)
	{
		http.open("GET","/gen1/m" + modelId + ".xml",true);
		http.onreadystatechange = HttpDerivativeHandler;
		http.send(null);	
	}
	
	// refresh the spec window;
/*	document.getElementById("carconfig").innerHTML = "";
	document.getElementById("submitForm").style.visibility="hidden";
	document.getElementById("carconfig").style.display = "none";	
	document.getElementById("configinstruction").style.display = "block";
	document.getElementById("derivativeid").focus();*/
	
	
	
	// Temporary to write details to page
	document.getElementById('selectedDetail').innerHTML += '&model=' + modelId;
}

function HttpDerivativeHandler()
{
	if(http.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(http.status == 200)
		{
			// data has been collected call populate method with xml tree.
			populateDerivativeOptions(http.responseXML.documentElement);
		}
		else
		{
			alert("problem retrieving data from the server, status code3: "  + http.status);
		}
	}
}


function populateDerivativeOptions(derivativesNode)
{
	//alert("populateModelOptions called" + derivativesNode);

	var derivativeList = document.getElementById("derivativeid");	
	for (var count = derivativeList.options.length-1; count >-1; count--)
	{
		derivativeList.options[count] = null;
	}

	var derivativeNodes = derivativesNode.getElementsByTagName("derivative");

	var idValue;
	var textValue; 
	var optionItem;
	
	
	// populate the dropdown list with data from the xml doc
	for (var count = 0; count < derivativeNodes.length; count++)
	{
		idValue = derivativeNodes[count].getAttribute("id");
		textValue = derivativeNodes[count].getAttribute("derivativename");		
		optionItem = new Option( textValue, idValue,  false, false);
		derivativeList.options[derivativeList.length] = optionItem;
	}
}

function refreshSpecPartExchange(derivativeId)
{
	if(derivativeId > 0)
	{
//		http.open("GET","/gen/d" + derivativeId + ".html",true);
		http.open("GET","/part_exchange.php",true);
		http.onreadystatechange = HttpSpecHandlerPartExchange;
		http.send(null);	
	}
	
	// Temporary to write details to page
	document.getElementById('selectedDetail').innerHTML += '&derivative=' + derivativeId;
}


function HttpSpecHandlerPartExchange()
{
	if(http.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(http.status == 200)
		{
			// data has been collected call populate method with xml tree.
				
			document.getElementById("configinstruction").style.display = "none";
			document.getElementById("carconfig").innerHTML = http.responseText;
			document.getElementById("model_name").value = document.getElementById("period").value;
			document.getElementById("skip_pe").href="javascript:refreshSpec('" + document.getElementById("derivativeid").value + "');";
			document.getElementById("carconfig").style.display = "block";
		}
		else
		{
			alert("problem retrieving data from the server, status code4: "  + http.status);
		}
	}
}

function refreshSpec2()
{
	
	refreshSpec(document.getElementById("derivativeid").value);
}


function refreshSpec1()
{
	
	refreshSpec(document.getElementById("derivativeid").checked);
}

function refreshSpec(derivativeId)
{
dur="";	
document.navfrm.duration.value = "-1";
document.navfrm.interest.value = "-1";
document.getElementById("carconfig").style.display = "none";
document.getElementById("configinstruction").style.display = "block";
	dId=derivativeId;
	// Temporary to write details to page
	document.getElementById('selectedDetail').innerHTML += '&derivative=' + derivativeId;
}

function timeduration(duration)
{
	document.navfrm.interest.value = "-1";
	document.getElementById("carconfig").style.display = "none";
	document.getElementById("configinstruction").style.display = "block";
	dur=duration;
	userduration=duration;
	// Temporary to write details to page
	document.getElementById('selectedDetail').innerHTML += '&lead[duration]=' + duration;
	
}

function leadinterest(interest)
{
	if(dur!=undefined && dur!="")
	{
		dur="";
		int=interest;
		if(document.getElementById('manufacturerid').value!="-1" && document.getElementById('modelid').value!="-1" && document.getElementById('derivativeid').value!="" && document.getElementById('duration').value!="-1" && document.getElementById('interest').value!="-1")
		{
			if(dId > 0)
			{
				http.open("GET","/gen1/d" + dId + ".html",true);
		//		http.open("GET","/car_details.php?der_id=" + derivativeId,true);
				http.onreadystatechange = HttpSpecHandler;
				http.send(null);
			}
		}
	}
// Temporary to write details to page
document.getElementById('selectedDetail').innerHTML += '&lead[interest]=' + interest;
//alert(document.getElementById('selectedDetail').innerHTML);
	
}

/*****************************************************************************
Developer: Sakthi
Following script developed for populating Models and Derivatives in Car page.
******************************************************************************/

/* Populating script starts here */

/* Models script starts here */

function refreshModels_1(manufacturerId)
{
dur="";	
document.navfrm.duration.value = "-1";
document.navfrm.interest.value = "-1";
document.getElementById("carconfig").style.display = "none";
document.getElementById("configinstruction").style.display = "block";

	if(manufacturerId > 0)
	{
		//alert("refreshModels called with " + manufacturerId);
		http.open("GET","/gen1/" + manufacturerId + ".xml",true);
		http.onreadystatechange = HttpModelHandler_1;
		http.send(null);	
		
	}
	
	// Temporary to write details to page
	document.getElementById('selectedDetail').innerHTML = "http://www.motorati.co.uk/mycar.php?t=quote";
	document.getElementById('selectedDetail').innerHTML += '&manufacturer=' + manufacturerId;
	
}

function HttpModelHandler_1()
{
	if(http.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(http.status == 200)
		{
			// data has been collected call populate method with xml tree.
			populateModelOptions_1(http.responseXML.documentElement);
		}
		else
		{
			alert("Problem retrieving data from the server, status code2: "  + http.status);
		}
	}
}

function populateModelOptions_1(modelsNode)
{
	//alert(model_id)
	var modelList = document.getElementById("modelid");	
	for (var count = modelList.options.length-1; count >-1; count--)
	{
		modelList.options[count] = null;
	}

	var modelNodes = modelsNode.getElementsByTagName("model");

	var idValue;
	var textValue; 
	var optionItem;
	
	
	// populate the dropdown list with data from the xml doc
	for (var count = 0; count < modelNodes.length; count++)
	{
		if (modelNodes[count].getAttribute("year_dis")=="0" || modelNodes[count].getAttribute("modelname")== "Select model" || modelNodes[count].getAttribute("modelname")== "Select Model"){
			//textValue = GetInnerText(modelNodes[count]);
			idValue = modelNodes[count].getAttribute("id");
			textValue = modelNodes[count].getAttribute("modelname");
			if(idValue==modelId){
			optionItem = new Option( textValue, idValue,  true, true);
			}
			else
			{
			optionItem = new Option( textValue, idValue,  false, false);
			}
			modelList.options[modelList.length] = optionItem;
		}
	}
}

/* Models script ends here */

/* Derivative script starts here */

var http1=getHTTPObject();
function refreshDerivatives_1(modelId)
{
dur="";	
document.navfrm.duration.value = "-1";
document.navfrm.interest.value = "-1";
document.getElementById("carconfig").style.display = "none";
document.getElementById("configinstruction").style.display = "block";

	if(modelId > 0)
	{
		http1.open("GET","/gen1/m" + modelId + ".xml",true);
		http1.onreadystatechange = HttpDerivativeHandler_1;
		http1.send(null);	
	}
	
	// refresh the spec window;
/*	document.getElementById("carconfig").innerHTML = "";
	document.getElementById("submitForm").style.visibility="hidden";
	document.getElementById("carconfig").style.display = "none";	
	document.getElementById("configinstruction").style.display = "block";
	document.getElementById("derivativeid").focus();*/
	
	
	
	// Temporary to write details to page
	document.getElementById('selectedDetail').innerHTML += '&model=' + modelId;
}

function HttpDerivativeHandler_1()
{
	if(http1.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(http1.status == 200)
		{
			// data has been collected call populate method with xml tree.
			populateDerivativeOptions_1(http1.responseXML.documentElement);
		}
		else
		{
			alert("problem retrieving data from the server, status code3: "  + http1.status);
		}
	}
}


function populateDerivativeOptions_1(derivativesNode)
{

//alert("populateModelOptions called" + derivativesNode);

	var derivativeList = document.getElementById("derivativeid");	
	for (var count = derivativeList.options.length-1; count >-1; count--)
	{
		derivativeList.options[count] = null;
	}

	var derivativeNodes = derivativesNode.getElementsByTagName("derivative");

	var idValue;
	var textValue; 
	var optionItem;
	
	
	// populate the dropdown list with data from the xml doc
	for (var count = 0; count < derivativeNodes.length; count++)
	{
		idValue = derivativeNodes[count].getAttribute("id");
		textValue = derivativeNodes[count].getAttribute("derivativename");		
		if(idValue==derivativeId){
		optionItem = new Option( textValue, idValue,  true, true);
		}
		else
		{
		optionItem = new Option( textValue, idValue,  false, false);
		}
		derivativeList.options[derivativeList.length] = optionItem;
	}
}

/* Derivative script ends here */


var http2=getHTTPObject();
function carDetails(derivativeId)
{
			if(derivativeId > 0)
			{
				http2.open("GET","/gen1/d" + derivativeId + ".html",true);
				http2.onreadystatechange = HttpSpecHandler_1;
				http2.send(null);
			}
// Temporary to write details to page
//alert(document.getElementById('selectedDetail').innerHTML);
	
}

function HttpSpecHandler_1()
{
	if(http2.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(http2.status == 200)
		{
			// data has been collected call populate method with xml tree.
				
			document.getElementById("configinstruction").style.display = "none";
			document.getElementById("carconfig").innerHTML = http2.responseText;
			document.getElementById("carconfig").style.display = "block";
			document.getElementById("submitForm").style.visibility="hidden";

		}
		else
		{
			alert("problem retrieving data from the server, status code: "  + http2.status);
		}
	}
}

function timeduration_1(duration)
{
	document.navfrm.interest.value = "-1";
//	document.getElementById("carconfig").style.display = "none";
//	document.getElementById("configinstruction").style.display = "block";
	dur=duration;
	// Temporary to write details to page
	document.getElementById('selectedDetail').innerHTML += '&lead[duration]=' + duration;
}

function leadinterest_1(interest)
{
	if(dur!=undefined && dur!="")
	{
		dur="";
		int=interest;
		if(document.getElementById('manufacturerid').value!="-1" && document.getElementById('modelid').value!="-1" && document.getElementById('derivativeid').value!="" && document.getElementById('duration').value!="-1" && document.getElementById('interest').value!="-1")
		{
			if(derivativeId > 0)
			{
				http.open("GET","/gen1/d" + derivativeId + ".html",true);
		//		http.open("GET","/car_details.php?der_id=" + derivativeId,true);
				http.onreadystatechange = HttpSpecHandler;
				http.send(null);
			}
		}
	}
// Temporary to write details to page
document.getElementById('selectedDetail').innerHTML += '&lead[interest]=' + interest;
//alert(document.getElementById('selectedDetail').innerHTML);
	
}


/* Populating script ends here */
/****************************************************************************/

function HttpSpecHandler()
{
	if(http.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(http.status == 200)
		{
			// data has been collected call populate method with xml tree.
				
			document.getElementById("configinstruction").style.display = "none";
			document.getElementById("carconfig").innerHTML = http.responseText;
			document.getElementById("carconfig").style.display = "block";
			document.getElementById("submitForm").style.visibility="visible";

		}
		else
		{
			alert("problem retrieving data from the server, status code: "  + http.status);
		}
	}
}

function refreshSMSConfirm()
{
	if(smsLeadId > 0)
	{
		http.open("GET","/xmlapi.php?t=quoteconfirmed&leadid=" + smsLeadId,true);
		http.onreadystatechange = HttpSMSConfirmHandler;
		http.send(null);	
	}
}

function HttpSMSConfirmHandler()
{
	if(http.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(http.status == 200)
		{
			// data has been collected call populate method with xml tree.
			UpdateConfirmStatus(http.responseXML.documentElement);
		}
		else
		{
			alert("Problem retrieving data from the server, status code6: "  + http.status);
		}
	}
}

function UpdateConfirmStatus(xmlNode)
{
	var statusCode = GetNodeValue(xmlNode,"status");
	//alert("lead " + statusCode + " with lead " + smsLeadId);
	
	if(statusCode != "1")
	{
		setTimeout("refreshSMSConfirm(" + smsLeadId  + ")",10000);
	}
	else
	{
		// the item has been confirmed lets replace the contents with a new button
		document.getElementById("smspending").style.display='none';
		document.getElementById("smsreceived").style.display='inline';
	}

}




// returns the node text value 
function GetInnerText (node)
{
	return (node.textContent || node.innerText || node.text || node.nodeValue || node.Value || node.Value) ;
}


function GetNodeValue(tree, el){
    return tree.getElementsByTagName(el)[0].firstChild.nodeValue;
 }


// END AJAX Library
function optionGetColourPrice(optioncode)
{
	arr = optioncode.split('|');

	// if we are taking the default values they will be zero.

	return((arr.length != 3) ? 0 : arr[0]);
}


function optionGetPrice(optioncode)
{
	arr = optioncode.split('|');

	// if we are taking the default values they will be zero.

	return((arr.length != 2) ? 0 : arr[1]);
}

function optionCheck(optionfield,rel_id)
{
	selected_id_arr=(optionfield.value).split("|");
	selected_id=selected_id_arr[0];
	var select_options = new Array();
	var de_select_options = new Array();
	var rid="0";
	var isRo=false;
	var isIo=false;
	var incOptions = "";	
	
	if(rel_id.length>0) {
		rel_arr = rel_id.split("|");
		arr_len=rel_arr.length;
		var rel_type=0;
		for(i=0;i<arr_len;i++)
		{
			if(document.getElementById(rel_arr[i]))
			{
				relations=(document.getElementById(rel_arr[i]).value).split("|");
				var fieldCheck = optionfield.checked
				switch(relations[0].toUpperCase())
				{
					case "OO":
					if(fieldCheck==true)
					{
						for(j=1;j<relations.length;j++)
						{
							opt_id_arr=relations[j].split("_");
							if(selected_id != opt_id_arr[0]) de_select_options[opt_id_arr[0]]="1";
						}
					}
						break
					case "RO":
						if(fieldCheck==true){
							if (selected_id + "_1" == relations[1]) 
							{
								isRo=true;
								rid=rel_arr[i];
							}
						}
						break
					case "RA":
						if (selected_id + "_1" == relations[1]) {
							for(j=1;j<relations.length;j++)
							{
								opt_id_arr=relations[j].split("_");
								if(fieldCheck==true)
								{
									select_options[opt_id_arr[0]]="1";
								} else {
									de_select_options[opt_id_arr[0]]="1";
								}
							}
						}
						break
					case "NW":
						if(fieldCheck==true)
						{
							if (selected_id + "_1" == relations[1]) {
								for(j=1;j<relations.length;j++)
								{
									opt_id_arr=relations[j].split("_");
									if(selected_id != opt_id_arr[0]) de_select_options[opt_id_arr[0]]="1";
								}
							}
						}
						break
					case "IN":
						if (selected_id + "_1" == relations[1])
						{
							incOptions = document.getElementById("IncludedOptions").value;
							if (fieldCheck)
							{
								// Add the ID to the list of IN
								incOptions = incOptions + "|" + rel_arr[i];
							} else {
								var incOptions_arr = incOptions.split("|");
								var incOptions="";
								for(ctr=0;ctr<incOptions_arr.length;ctr++)
								{
									if(incOptions_arr[ctr] != rel_arr[i])
									{
										if (ctr > 0) incOptions = incOptions + "|";
										incOptions = incOptions + incOptions_arr[ctr];
									}
								}
							}
							document.getElementById("IncludedOptions").value = incOptions;
							for(j=1;j<relations.length;j++)
							{
								opt_id_arr=relations[j].split("_");
								if(fieldCheck==true)
								{
									select_options[opt_id_arr[0]]="1";
								} else {
									de_select_options[opt_id_arr[0]]="1";
								}
							}
						}
						break
					case "IO":
						if(fieldCheck==true){
							if (selected_id + "_1" == relations[1]) isIo=true;
						}
						break
				}
			}
		}
	}
	for (selCnt in de_select_options)
	{
		if(document.getElementById(selCnt))
			document.getElementById(selCnt).checked=false;
	}
	
	for (selCnt in select_options)
	{
		if(document.getElementById(selCnt))
			document.getElementById(selCnt).checked=true;
	}

	if(isRo)
	{
		var der_id=document.getElementById("lead[derivativeid]").value
		getROOptions(der_id,rid,selected_id);
	} else {
		calculateTotal();
	}
}

function getROOptions(der_id,rid,selected_id)
{
		http.open("GET","/RODetails.php?rid="+rid+"&did="+der_id+"&popt="+selected_id,true);
		http.onreadystatechange = relationDetails;
		http.send(null);	
}

function relationDetails()
{
	if(http.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(http.status == 200)
		{
/*			var layerObj = document.getElementById("optionDetails");
			layerObj.style.visibility = "visible";*/
			toggleOptWindow();
			var iFrameBody = document.getElementById("modalwin").contentWindow.document.body;
			iFrameBody.innerHTML = http.responseText;		
//			layerObj.innerHTML=http.responseText;
		}
		else
		{
			alert("Problem retrieving data from the server, status code1: "  + http.status);
		}
	}
}

function toggleOptWindow()
{
		if(document.getElementById("modalwin").style.visibility != "visible")
		{
			// show overlay
			var arrayPageSize = getPageSize();
			var objOverlay = document.getElementById('overlay');
			objOverlay.style.height = (arrayPageSize[1] + 'px');
			objOverlay.style.display = 'block';
			
			var objOverlayIframe = document.getElementById('overlayiframe');
			objOverlayIframe.style.height = (arrayPageSize[1] + 'px');
			objOverlayIframe.style.display = 'block';
		}
		else
		{
			var objOverlay = document.getElementById('overlay');
			var objOverlayIframe = document.getElementById('overlayiframe');
			objOverlay.style.display = 'none';
			objOverlayIframe.style.display = 'none';
		}
		
		newVisibility = (document.getElementById("modalwin").style.visibility != "visible") ? "visible" : "hidden";
		// center modal
		
		getwindowdims();
		//alert("window is " + w_y + " and " + w_x + " and window height is " + document.getElementById("modalwin").style.width);
		
		s_x = getpagescrollx();
		s_y = getpagescrolly();
	
		// to center the window we need to know the window width and height	
		
		
		startx = s_x + ((w_x / 2) - (443 /2));
		starty = s_y + ((w_y / 2) - (179 /2));
	
		document.getElementById("modalwin").style.left = startx + "px";
		document.getElementById("modalwin").style.top = starty + "px";
		
		document.getElementById("modalwin").style.visibility = newVisibility;	
		scroll(startx,starty - 200);
}

function closeOptionWindow()
{
/*	var layerObj = document.getElementById("optionDetails");
	layerObj.style.visibility = "hidden";
	layerObj.innerHTML="";*/
	toggleOptWindow();
}

function closeROSWindow(optCode)
{
	document.getElementById(optCode).checked=false;
	closeOptionWindow()	
}

function selOption(optfield)
{
	document.getElementById(optfield.value).checked=true;
	closeOptionWindow();
	calculateTotal();
}

function calculateTotal()
{

	optionCost = 0;
	incCost=0;
	incOptions = document.getElementById("IncludedOptions").value;
	var incArr = new Array();
	var incOptions_arr = incOptions.split("|");
	for(ctr=0;ctr<incOptions_arr.length;ctr++)
	{
		if(document.getElementById(incOptions_arr[ctr]))
		{
			var childIds = "";
			rel_ids_to_check=(document.getElementById(incOptions_arr[ctr]).value).split("|");
			for(child_ctr=2;child_ctr < rel_ids_to_check.length;child_ctr++)
			{
				if(child_ctr > 2) childIds = childIds + "|";
				rid = rel_ids_to_check[child_ctr].split("_");
				childIds=childIds + rid[0];
			}
			rid = rel_ids_to_check[1].split("_");
			incArr[rid[0]]=childIds;
		}
	}

	for ( var i=0;i<document.quotefrm.elements.length;i++ ){
		if(document.quotefrm.elements[i].type=="checkbox"){
			if(document.quotefrm.elements[i].checked)
			{
				option_val_arr = (document.quotefrm.elements[i].value).split("|");
				optionCost = Number(optionCost) + Number(option_val_arr[1]);
				if(incArr[option_val_arr[0]])
				{
					if(incArr[option_val_arr[0]].length > 1)
					{
						var arr_opt = new Array();
						arr_opt = incArr[option_val_arr[0]].split("|");
						for(chld_amt=0;chld_amt<arr_opt.length;chld_amt++)
						{
							if(document.getElementById(arr_opt[chld_amt]).checked)
							{
								document.getElementById("row_" + arr_opt[chld_amt]).style.background="#EAEEF2";
								document.getElementById("rate_" + arr_opt[chld_amt]).style.textDecoration="line-through";
								
								amtDeduct=(document.getElementById(arr_opt[chld_amt]).value).split("|");
								incCost = Number(incCost) + Number(amtDeduct[1]);
							}
						}
					}
				}
			} else {
				document.getElementById("rate_" + document.quotefrm.elements[i].id).style.textDecoration="none";
				document.getElementById("row_" + document.quotefrm.elements[i].id).style.background="#d8e0e7";
			}
		}
	}

	if(document.getElementById("lead[cost_options]")) document.getElementById("lead[cost_options]").value = (Number(optionCost) - Number(incCost));
	if(document.getElementById("bid[rrp_option]")) document.getElementById("bid[rrp_option]").value = (Number(optionCost) - Number(incCost));

	refreshTotalsDisplay();

}



function updateColourSelect(value,incexterior)
{
	optionCost = optionGetColourPrice(value);
	document.getElementById("cost_colour").innerHTML = (optionCost == 0) ? "" :  moneyFormat(optionCost,0,".",",");
	if (document.getElementById("lead[cost_colour]"))document.getElementById("lead[cost_colour]").value = optionCost;
	refreshTotalsDisplay(incexterior);
}


function updateSelect(field,value,incexterior)
{ 
	optionCost = optionGetPrice(value);
	document.getElementById("cost_" + field).innerHTML = (optionCost == 0) ? "" :  moneyFormat(optionCost,0,".",",");
	document.getElementById("lead[cost_" + field + "]").value = optionCost;
	if (field=='colour') document.getElementById("bid[colour]").value=value;
	if (field=='wheel'){
		if(document.getElementById("bidoption[wheel_pref]")) document.getElementById("bidoption[wheel_pref]").value=value;
	}

	
	refreshTotalsDisplay(incexterior);
}

function refreshTotalsDisplay(incexterior)
{
	// get the latest total by combining checkboxes and select box totals
	totalOptions=0;
	if(document.getElementById('lead[cost_options]'))
	{
		totalOptions = Number(document.getElementById('lead[cost_options]').value);
//		del_charges = Number(document.getElementById("lead[cost_onroad]").value) + Number(document.getElementById("lead[cost_del]").value) + Number(document.getElementById("lead[cost_regfee]").value)
	}

	if(document.getElementById('bid[rrp_option]'))
	{
		totalOptions = Number(document.getElementById('bid[rrp_option]').value);
//		del_charges = Number(document.getElementById("lead[cost_onroad]").value) + Number(document.getElementById("lead[cost_del]").value) + Number(document.getElementById("lead[cost_regfee]").value)
	}

	document.getElementById('cost_options').innerHTML = (totalOptions == 0) ? "0" : moneyFormat(totalOptions,0,".",",");
	ValidateBidInput();
//	ValidateBidtotal();
}




function moneyFormat( n, c, d, t )
{
	n=Math.round(n);
	var m = ( c = Math.abs( c ) + 1 ? c : 2, d = d || ",", t = t || ".", /(\d+)(?:(\.\d+)|)/.exec( n + "" ) ), x = m[1].length % 3;
	var r = (x ? m[1].substr( 0, x ) + t : "" ) + m[1].substr( x ).replace( /(\d{3})(?=\d)/g, "$1" + t ) + ( c ? d + ( +m[2] ).toFixed( c ).substr( 2 ) : "" );

	// fix to remove , from end of the string when money is less than 3 characters
	if(r[r.length-1] == ',')
	{
		// strip the last character.
		r = r.slice(0,r.length-1);
	}
//	r=Math.round(r);

	return("&pound;" + r);
}


function getpagescrolly(){
if(is_ie4up)return document.body.scrollTop;
else return window.pageYOffset;
}

function getpagescrollx(){
if(is_ie4up)return document.body.scrollLeft;
else return window.pageXOffset;
}

function getwindowdims()
{
	w_y=(is_ie4up)?document.body.clientHeight:window.innerHeight;
	w_x=(is_ie4up)?document.body.clientWidth:window.innerWidth;
}


function makePOSTRequest(url, parameters,type) {
  http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
	 http_request = new XMLHttpRequest();
	 if (http_request.overrideMimeType) {
		// set type accordingly to anticipated content type
		//http_request.overrideMimeType('text/xml');
		http_request.overrideMimeType('text/html');
	 }
  } else if (window.ActiveXObject) { // IE
	 try {
		http_request = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
		try {
		   http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	 }
  }
  if (!http_request) {
	 alert('Cannot create XMLHTTP instance');
	 return false;
  }
  if(type=="1")
	  http_request.onreadystatechange = alertContents;
 else
	  http_request.onreadystatechange = PEConfig;
 
  http_request.open('POST', url, true);
  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http_request.setRequestHeader("Content-length", parameters.length);
  http_request.setRequestHeader("Connection", "close");
  http_request.send(parameters);
}

function PEConfig() {
  if (http_request.readyState == 4) {
	 if (http_request.status == 200) {
		//alert(http_request.responseText);
		result = http_request.responseText;
		document.getElementById('carconfig').innerHTML = result;            
	 } else {
		alert('There was a problem with the request');
	 }
  }
}




function alertContents() {
  if (http_request.readyState == 4) {
	 if (http_request.status == 200) {
		//alert(http_request.responseText);
		result = http_request.responseText;
		document.getElementById("container").innerHTML=result;
	 } else {
		alert('There was a problem with the request:' + http_request.status);
	 }
  }
}

function toggleModal()
{

/*	if(document.getElementById("lead[colourpref1]")){
		if (document.getElementById("lead[colourpref1]").value == "-1") {
			alert("Please select your colour preference");
			document.getElementById("lead[colourpref1]").focus();
			return;
		}
	}
	if(!document.getElementById("trim_standard")){
		if(document.getElementById("leadopt[]")){
			if (document.getElementById("leadopt[]").value == "-1") {
				alert("Please select a Trim preference");
				document.getElementById("leadopt[]").focus();
				return;
			}
		}
	}*/
	

	var disp_conf=true;
	if (document.getElementById("radio1").checked==true){
		disp_conf=false;
		if(document.getElementById("pe_form") != null) 
		{
			var pe_valid = submit_page();
			if (pe_valid == true){
				disp_conf=true;
			} else {
				return;
			}
		}
	}
	
	if (disp_conf==false) {
		var poststr;
		for ( var i=0;i<document.quotefrm.elements.length;i++ ){
			toAdd=true;
			if(document.quotefrm.elements[i].type=="checkbox"){
				if(document.quotefrm.elements[i].checked==false) toAdd=false;
			}
			if(toAdd){
				if (i > 0) poststr = poststr + "&";
				poststr = poststr + document.quotefrm.elements[i].name + "=" + encodeURI( document.quotefrm.elements[i].value );
			}
		}
		makePOSTRequest('part_exchange.php', poststr,"2");
	} else {
		if (document.getElementById("part_exchange"))
		{
			var newdiv = document.createElement('div');
			var divIdName = 'duration';
			newdiv.setAttribute('id',divIdName);
			newdiv.innerHTML = '<input type="hidden" id="lead[duration]" name="lead[duration]" value="'+userduration+'"/>';
			newdiv.innerHTML += '<input type="hidden" id="lead[interest]" name="lead[interest]" value="'+int+'"/>';
			document.getElementById('part_exchange').appendChild(newdiv);

			if(document.getElementById('manufacturerid').value!="-1" && document.getElementById('modelid').value!="-1" && document.getElementById('derivativeid').value!="" && document.getElementById('duration').value!="-1" && document.getElementById('interest').value!="-1")
			 {
			 	document.part_Exchange.submit();
			 }
			
			/*var partpath="/mycar.php?lead[duration]="+dur+"&lead[interest]="+int;
		 document.part_Exchange.action=encodeURI(partpath);*/
			
		}
		else
		{
				 if(document.getElementById('manufacturerid').value!="-1" && document.getElementById('modelid').value!="-1" && document.getElementById('derivativeid').value!="" && document.getElementById('duration').value!="-1" && document.getElementById('interest').value!="-1")
			 {	
				//alert(dur)
				var newdiv = document.createElement('div');
				var divIdName = 'duration';
				newdiv.setAttribute('id',divIdName);
				newdiv.innerHTML = '<input type="hidden" id="lead[duration]" name="lead[duration]" value="'+userduration+'"/>';
				newdiv.innerHTML += '<input type="hidden" id="lead[interest]" name="lead[interest]" value="'+int+'"/>';
				document.getElementById('optionDetails').appendChild(newdiv);
				//alert(document.getElementById('optionDetails').innerHTML)
				document.quotefrm.submit();
			 }
		// document.cookie = "lead[duration]"+"="+dur+"; path=/";
		 //document.cookie = "lead[interest]"+"="+int+"; path=/";
		// var path="/mycar.php?lead[duration]="+dur+"&lead[interest]="+int;
		 //document.quotefrm.action=encodeURI(path);
			 
			 
		}
		/*
		if(document.getElementById("modalwin").style.visibility != "visible")
		{
			// show overlay
			var arrayPageSize = getPageSize();
			var objOverlay = document.getElementById('overlay');
			objOverlay.style.height = (arrayPageSize[1] + 'px');
			objOverlay.style.display = 'block';
			
			var objOverlayIframe = document.getElementById('overlayiframe');
			objOverlayIframe.style.height = (arrayPageSize[1] + 'px');
			objOverlayIframe.style.display = 'block';
		}
		else
		{
			var objOverlay = document.getElementById('overlay');
			var objOverlayIframe = document.getElementById('overlayiframe');
			objOverlay.style.display = 'none';
			objOverlayIframe.style.display = 'none';
		}
		
		newVisibility = (document.getElementById("modalwin").style.visibility != "visible") ? "visible" : "hidden";
		*/
		// center modal
		
		/*
		getwindowdims();
		//alert("window is " + w_y + " and " + w_x + " and window height is " + document.getElementById("modalwin").style.width);
		
		s_x = getpagescrollx();
		s_y = getpagescrolly();
	
		// to center the window we need to know the window width and height	
		
		
		startx = s_x + ((w_x / 2) - (443 /2));
		starty = s_y + ((w_y / 2) - (179 /2));
	
		document.getElementById("modalwin").style.left = startx + "px";
		document.getElementById("modalwin").style.top = starty + "px";
		*/
		
//		document.getElementById("modalwin").style.visibility = newVisibility;	
//		scroll(0,0);
		
	}
}

function ManufacturerAdd(id)
{
	if(document.getElementById("manufacturerselect" + id).value != undefined && document.getElementById("manufacturerselect" + id).value != "")
	{
		document.getElementById("manufacturer" + (id + 1)).style.display = "block";
		document.getElementById("btn" + id).style.visibility = "hidden";
		document.getElementById("manufacturerselect" + (id + 1)).focus();
	}
}

function ManufacturerRemove(id)
{
	document.getElementById("btn" + (id - 1)).style.visibility = "visible";
	document.getElementById("manufacturerselect" + id).selectedIndex = 0;
    document.getElementById("manufacturer" + id).style.display = "none";
	document.getElementById("manufacturerselect" + (id - 1)).focus();    
}

/* Function copys dealer information to billing */
function DealerCopyInfo()
{
	copyfieldsArr = new Array("address1","address2","town","county");
	
	for(i = 0; i < copyfieldsArr.length; i++)
	{
		document.getElementById("dealer[billing_" + copyfieldsArr[i] + "]").value = document.getElementById("dealer[" + copyfieldsArr[i] + "]").value;
	}
	
	document.getElementById("dealer[billing_postcode]").value = document.getElementById("dbf[postcode]").value;
}


function UpdateBidRequirement(reqfield)
{	
	reqCost = optionGetPrice(reqfield.value);

	if(reqfield.checked)
	{
		document.getElementById('row' + reqfield.value).className='trn';
		document.getElementById("lead[cost_options]").value = Number(document.getElementById("lead[cost_options]").value) + Number(reqCost);
		document.getElementById("reqactual").value = Number(document.getElementById("reqactual").value) + 1;		
	}
	else
	{	
		document.getElementById('row' + reqfield.value).className='trn';
		document.getElementById("lead[cost_options]").value = Number(document.getElementById("lead[cost_options]").value) - Number(reqCost);		
		document.getElementById("reqactual").value = Number(document.getElementById("reqactual").value) - 1;		
	}
	refreshTotalsDisplay();
}

/* Function refreshes the options total */
function RefreshExtraOptionsTotal()
{
	additional_cost = 0;
	
	// requested costs
	
	// add costs
	
	for(i = 1; i <= 10; i++)
	{
		if(document.getElementById("add" + i).style.display != "none")
		{
			
			optionCost = optionGetPrice(document.getElementById("addoption[" + i + "]").value);
			additional_cost += Number(optionCost);
		}
	}

	document.getElementById("lead[cost_extraoptions]").value = additional_cost;
	refreshTotalsDisplay();
}

currindex = 1;
function addExtraOption()
{	
	// before adding the item check it hasn't already been added
	
	selindex = document.getElementById('addoptionselect').selectedIndex;
	optiondescription = document.getElementById('addoptionselect').options[selindex].text;
	optionid = document.getElementById('addoptionselect').options[selindex].value;
	optionCost = optionGetPrice(optionid);

	
	if(optionid != "")
	{
		repitionbool = false;
		for(i = 1; i <= 10; i++)
		{	
			if(document.getElementById("add" + i).style.display != "none")
			{	
				if(document.getElementById("addoption[" + i + "]").value == optionid)
				{
					alert("This item has already been added or has been included");
					return;
				}
			}
		}
		
		
		document.getElementById("addoption[" + currindex + "]").value = optionid;

		document.getElementById("add" + currindex).style.display = "";
		document.getElementById("addprice" + currindex).innerHTML = moneyFormat(Number(optionCost),0,".",",");
		document.getElementById("adddescription" + currindex).innerHTML = optiondescription;


		document.getElementById("addoption[" + currindex + "]").click();
		currindex++;	
		document.getElementById("extracount").value++;
	}
	
	document.getElementById('addoptionselect').selectedIndex = 0;
	RefreshExtraOptionsTotal();
}

function removeExtraOption(optionint)
{
		document.getElementById('add' + optionint).style.display = 'none';
		RefreshExtraOptionsTotal();
}


/* Method checks to see the bid is less than the existing bid and also asks for confirmation 
if bid is less than 10% of the vehicle price or item this avoids missing zero type problems. */

function CheckBid()
{
	// check bid is less than previous bid or rrp
	// if not reject
	
	checkBidBool = true;
	
	bidAmount = Number(document.getElementById("bid[disc_amount]").value);
	if (isNaN(bidAmount)) bidAmount=0;

	return(checkBidBool);
}


function MatchSet(type,weight)
{
	document.getElementById("match[" + type + "]").value = weight;
	MatchRecalculate();
}

function MatchRecalculate()
{
	// calculate required options
	// get required percentage 3 for 100% 2 for 80%+ 1 for 50% 0 for none.
	reqactual = document.getElementById("reqactual").value;
	reqcount = document.getElementById("reqcount").value
	reqpercentage = (reqactual / reqcount) * 100;


	if(reqpercentage >= 100)
	{
		reqmatch = 3;
	}
	else if(reqpercentage >= 75)
	{
		reqmatch = 2;		
	}
	else if(reqpercentage >= 50)
	{
		reqmatch = 1;
	}
	else
	{
		reqmatch = 0;
	}
	
	document.getElementById("match[req]").value = reqmatch;
	if(reqmatch < 3)
	{
		// extra items have been added if they exceed the missing required
		// add an additional point.
		missing = reqcount - reqactual;
		document.getElementById("match[extra]").value = (document.getElementById("extracount").value >= missing) ? 1 : 0;
	}
	
	match = Number(document.getElementById("match[colour]").value) 
	+ Number(document.getElementById("match[trim]").value) 
	+ Number(document.getElementById("match[wheel]").value)
	+ Number(document.getElementById("match[req]").value)
	+ Number(document.getElementById("match[extra]").value);

}

 
function ValidateBidInput(t)
{
	reg_fee=0;
	del_charge=0;
	on_road=0;
	disc_amount=0;
	base_cost=0;

	org_regfee=0;
	org_del_charge=0;
	org_onroad=0;

	if(document.getElementById('lead[cost_options]'))
	{
		totalOptions = Number(document.getElementById('lead[cost_options]').value);
		if(document.getElementById("lead[cost_regfee]")) reg_fee=document.getElementById("lead[cost_regfee]").value;
		if(document.getElementById("lead[cost_del]")) del_charge=document.getElementById("lead[cost_del]").value;
		if(document.getElementById("lead[cost_onroad]")) on_road=document.getElementById("lead[cost_onroad]").value;
		if(document.getElementById("lead[cost_rrp]")) base_cost=document.getElementById("lead[cost_rrp]").value;
	}

	if(document.getElementById('bid[rrp_option]'))
	{
		totalOptions = Number(document.getElementById('bid[rrp_option]').value);
		if(document.getElementById("bid[chng_cost_regfee]")) reg_fee=document.getElementById("bid[chng_cost_regfee]").value;
		if(document.getElementById("bid[chng_cost_del]")) del_charge=document.getElementById("bid[chng_cost_del]").value;
		if(document.getElementById("bid[chng_cost_onroad]")) on_road=document.getElementById("bid[chng_cost_onroad]").value;
		if(document.getElementById("bid[disc_amount]")) disc_amount=document.getElementById("bid[disc_amount]").value;
		if(document.getElementById("bid[rrp_base]")) base_cost=document.getElementById("bid[rrp_base]").value;

		if(document.getElementById("bid[cost_regfee]")) org_regfee=document.getElementById("bid[cost_regfee]").value;
		if(document.getElementById("bid[cost_delivery]")) org_del_charge=document.getElementById("bid[cost_delivery]").value;
		if(document.getElementById("bid[cost_onroad]")) org_on_road=document.getElementById("bid[cost_onroad]").value;
	}

	var costTotal=Number(base_cost) + Number(reg_fee) + Number(del_charge) + Number(on_road) + Number(totalOptions);
	var orgCost=0;
	if(document.getElementById('bid[rrp_option]')) orgCost=Number(base_cost) + Number(org_regfee) + Number(org_del_charge) + Number(org_on_road) + Number(totalOptions);

//	totalOptions = Number(document.getElementById("lead[cost_extraoptions]").value) +  Number(document.getElementById('lead[cost_options]').value) + Number(document.getElementById('lead[cost_wheel]').value) + Number(document.getElementById('lead[cost_trim]').value) + Number(document.getElementById('lead[cost_colour]').value);
	document.getElementById("cost_total").innerHTML=moneyFormat(costTotal,0,".",",");
	var bid_amt=Number(costTotal) - Number(disc_amount);
	if(document.getElementById("lead[cost_total]")) document.getElementById("lead[cost_total]").value=Math.round(costTotal);
	if(document.getElementById("off_to_customer")) document.getElementById("off_to_customer").innerHTML = moneyFormat(bid_amt,0,".",",");
	if(document.getElementById("bid[bid_amount]")) document.getElementById("bid[bid_amount]").value=Math.round(bid_amt);
	if(document.getElementById("bid[bid_saving]")) document.getElementById("bid[bid_saving]").value=Math.round(Number(orgCost) - Number(bid_amt));
}

function ValidateBidtotal(t)
{ 
	if(document.getElementById("bid[chng_cost_regfee]")){
		reg_fee=document.getElementById("bid[chng_cost_regfee]").value;
	} else if(document.getElementById("lead[cost_regfee]")){
		reg_fee=document.getElementById("lead[cost_regfee]").value;
    } else {
		reg_fee="0";
	}
	if(document.getElementById("bid[chng_cost_del]")){
		del_charge=document.getElementById("bid[chng_cost_del]").value;
	} else if(document.getElementById("lead[cost_del]")){
		del_charge=document.getElementById("lead[cost_del]").value;
	} else {
		del_charge="0";
	}
	if(document.getElementById("bid[disc_amount]")){
		disc_amount=document.getElementById("bid[disc_amount]").value;
	} else {
		disc_amount=0;
	}
	
	if(document.getElementById("bid[chng_cost_onroad]")){
		on_road=document.getElementById("bid[chng_cost_onroad]").value;
	} else if(document.getElementById("lead[cost_onroad]")){
		on_road=document.getElementById("lead[cost_onroad]").value;
	} else {
		on_road="0";
	}
	
	totalOptions = Number(document.getElementById('lead[cost_options]').value);

//	totalOptions = Number(document.getElementById("lead[cost_extraoptions]").value) +  Number(document.getElementById('lead[cost_options]').value) + Number(document.getElementById('lead[cost_wheel]').value) + Number(document.getElementById('lead[cost_trim]').value) + Number(document.getElementById('lead[cost_colour]').value);
	var bid_amt=Number(document.getElementById('lead[cost_rrp]').value) + Number(totalOptions) + Number(reg_fee) + Number(del_charge) + Number(on_road);
	if(document.getElementById("cost_total")){
	document.getElementById("cost_total").innerHTML = moneyFormat(bid_amt,0,".",",");
	}
	if(document.getElementById("bid[disc_amount]")){
		disc_amount=document.getElementById("bid[disc_amount]").value;
	} else {
		disc_amount=0;
	}
	
	bid_amt = bid_amt - Number(disc_amount);
	if(document.getElementById("bid[bid_amount]")){
	document.getElementById("bid[bid_amount]").value=Math.round(bid_amt); }
}

function CheckNumeric(t)
{
	var v = "0123456789.";
	var w = ""; 
	for (i=0; i < t.value.length; i++)
	{
		x = t.value.charAt(i);
		if (v.indexOf(x,0) != -1)
		{	
			w += x;
		}
	}
	t.value = w;
}

function switchhelp(whichhelp) {

	//document.getElementById("description").style.display="block";
	for (i=1; i <= 8; i++) {
		document.getElementById("instruction"+i).style.display="none";
	}
	document.getElementById("instruction"+whichhelp).style.display="block";
}

function acceptpayment()
{
	
	document.paymentfrm.action="payment.php";
//	document.paymentfrm.action="https://motorati.co.uk/payment.php";
	document.paymentfrm.submit();	
}

function acceptBid1(bidid,amount)
{
	confirmationBool = confirm("Are you sure you want to accept this offer and proceed to pay the deposit?","");
	if(confirmationBool)
	{	
		// set the fields and submit the form.
		document.getElementById("bidid").value = bidid;
		document.acceptfrm.action="payment.php";
//		document.acceptfrm.action="https://motorati.co.uk/payment.php";
		document.acceptfrm.submit();
	}
	else
	{
		// do nothing
		return false;
	}
}

function u_select(chkObj)
{	
	document.getElementById("u_select").value=chkObj.value;
	proceed_offer();
}

function proceed_offer()
{
	var sel_option = document.getElementById("u_select").value
	if(sel_option=="")
	{
		alert("Please select one option");
		return;
	}
	
	arr = sel_option.split('_');

	switch(arr[0])
	{
		case "talk": // Client wants to talk to Dealer
			http.open("GET","/call_back_mail.php?bid="+arr[1]+"&type=talk",true);
			http.onreadystatechange = dealer_info;
			http.send(null);				
		break;
		case "c": // Client has requested a call back
			http.open("GET","/call_back_mail.php?bid="+arr[1]+"&type=tel",true);
			http.onreadystatechange = call_back;
			http.send(null);	
		break;
		case "rd": // Client has requested dealer to contact him via email
			http.open("GET","/call_back_mail.php?bid="+arr[1]+"&type=mail",true);
			http.onreadystatechange = call_back;
			http.send(null);	
		break;
		case "a": // Client has accepted the bid and needs to pay the amount
			confirmationBool = confirm("Are you sure you want to accept this offer and proceed to pay the deposit?","");
			if(confirmationBool)
			{	
				// set the fields and submit the form.
				document.getElementById("bidid").value = arr[1];
				document.acceptfrm.action="payment.php";
		//		document.acceptfrm.action="https://motorati.co.uk/payment.php";
				document.acceptfrm.submit();
			}
			else
			{
				// do nothing
				return;
			}
		
		break;
		case "chat":
			var chat_url="/chat_window.php?tuid=" + document.getElementById("touserid").value + "&fruid=" + document.getElementById("fromuserid").value;
			chat_url=chat_url + "&leadid=" + document.getElementById("u_leadid").value;
			chat_url=chat_url + "&fdlid=" + document.getElementById("fromdealerid").value;
			chat_url=chat_url + "&un=" + document.getElementById("u_name").value;
			window.open(chat_url,'Motorati','width=500,height=365');
		break;
	}
}

function getmessage(tuserid,fruserid)
{
	http.open("GET","/getmessage.php?tuid="+tuserid+"&fruid=" + fruserid,true);
	http.onreadystatechange = chat_message_details;
	http.send(null);				
//	document.getElementById("chat_display").value = document.getElementById("chat_display").value + " --" + tuserid + "--" + fruserid + "--";
}

function chat_message_details()
{
	if (http.readyState == 4) {
		if (http.status == 200) {
				var response=http.responseText;
				if(trim(response) != "")
				{
					var obj=document.getElementById("chat_display")
					document.getElementById("chat_display").value = response +  document.getElementById("chat_display").value 
				}
		} else {
			alert("Failed: " + http.status);	
		}
	}
}


function send_admin_msg()
{
	
	email=document.getElementById("email").value;
	username=document.getElementById("username").value;
	adminid=document.getElementById("adminid").value;
	msg=document.getElementById("txt_value").value;
	if(msg != "" && trim(adminid) != "")
	{
		var url="/sendadminmessage.php?email=" + email + "&uname=" + username + "&adminid=" + adminid;
		url = url + "&msg=" + msg;
		http.open("GET",url,true);
		http.onreadystatechange = send_chat_message;
		http.send(null);						
	}	
}



function cycle(tuserid,fuserid) {
	getmessage(tuserid,fuserid);
	window.setTimeout('cycle(' + tuserid + 	',' + fuserid + ');',2000);
}



function closeRequestWindow()
{
	document.location="/myoffers.php";
}


function send_msg()
{
	tuid=document.getElementById("touserid").value;
	fruid=document.getElementById("fromuserid").value;
	frdid=document.getElementById("fromdealerid").value;
	name=document.getElementById("name").value;
	u_leadid=document.getElementById("leadid").value;
	msg=document.getElementById("txt_value").value;
	if(msg != "")
	{
		var url="/sendmessage.php?tuid=" + tuid + "&fruid=" + fruid + "&frdid=" + frdid + "&name=" + name + "&leadid=" + u_leadid;
		url = url + "&msg=" + msg;
		http.open("GET",url,true);
		http.onreadystatechange = send_chat_message;
		http.send(null);						
	}
	
}

function send_chat_message()
{
	if (http.readyState == 4) {
		if (http.status == 200) {
			document.getElementById("chat_display").value =  "Me: " + document.getElementById("txt_value").value  + "\n" + document.getElementById("chat_display").value;	
			document.getElementById("txt_value").value="";
		} else {
			alert(http.status);
		}
	}
}



function dealer_info()
{
	if (http.readyState == 4) {
		if (http.status == 200) {
//			toggleOptWindow();
//			var iFrameBody = document.getElementById("modalwin").contentWindow.document.body;
			document.getElementById("dealer_info").style.display="block";
			document.getElementById("dealer_info").style.visibility="visible";
			document.getElementById("dealer_add").innerHTML=http.responseText;		
//			alert(http.responseText);
		} else {
			alert('There was a problem with the request:' + http.status);
		}
	}	
}

function call_back()
{
	if (http.readyState == 4) {
		if (http.status == 200) {
			alert("Your request has been sent to the selected dealer who will respond to you at the earliest");
		} else {
			alert('There was a problem with the request:' + http_request.status);
		}
	}
}



function acceptBid(bidid,amount,leadid)
{
		
		document.getElementById("bidid").value = bidid;
		document.adjust.submit();
}


function validBidAdjust(maxBid,adjustBid)
{
	document.adjustfrm.submit();
}


//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//

function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {	

		xScroll = document.body.scrollWidth;

		yScroll = window.innerHeight + window.scrollMaxY;

	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac

		xScroll = document.body.scrollWidth;

		yScroll = document.body.scrollHeight;

	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari

		xScroll = document.body.offsetWidth;

		yScroll = document.body.offsetHeight;

	}

	

	var windowWidth, windowHeight;

	if (self.innerHeight) {	// all except Explorer

		windowWidth = self.innerWidth;

		windowHeight = self.innerHeight;

	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode

		windowWidth = document.documentElement.clientWidth;

		windowHeight = document.documentElement.clientHeight;

	} else if (document.body) { // other Explorers

		windowWidth = document.body.clientWidth;

		windowHeight = document.body.clientHeight;

	}	

	
	// for small pages with total height less then height of the viewport

	if(yScroll < windowHeight){

		pageHeight = windowHeight;

	} else { 

		pageHeight = yScroll;

	}



	// for small pages with total width less then width of the viewport

	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 

	return arrayPageSize;

}


function preSelect(whichManufacturer,whichModel,whichDerivative) {
	//alert(whichManufacturer + ' / ' + whichModel + ' / ' + whichDerivative);
	document.getElementById('manufacturerid').value=whichManufacturer;
	//refreshModels(whichManufacturer);
	//document.getElementById('modelid').value=whichModel;
	//refreshDerivatives(whichModel);
	//document.getElementById('derivativeid').value=whichDerivative;
	refreshSpec(whichDerivative);
}

function trim(str)
{
	
	var str1=str.replace(/\S/g,"|");
	var i=str1.indexOf("|")-1;
	var j=str1.lastIndexOf("|")+1;
	var trimStr=str.substring(0,i).replace(/\s/g,"") + str.substring(i+1,j)
	trimStr = trimStr + str.substring(j).replace(/\s/g,"");
	//alert("This is being trimmed");
	return trimStr;
}

function skip_pe()
{
	document.getElementById("radio1").checked=false;
	document.getElementById("radio2").checked=true;
	toggleModal()
}

function submit_page()
{
	var strTrimed = document.part_Exchange.manufacturer_name[document.part_Exchange.manufacturer_name.selectedIndex].value;
	if (strTrimed=="-1")
	{
			alert("Please select Manufacturer Name");
			document.part_Exchange.manufacturer_name.focus();
			return false;
	}
	
	var strTrimed = document.part_Exchange.model_name[document.part_Exchange.model_name.selectedIndex].value;
	if (strTrimed=="")
	{
			alert("Please select Model Name");
			document.part_Exchange.model_name.focus();
			return false;
	}

	var strTrimed = trim(document.getElementById("pe_form[version_pe]").value);
	if (strTrimed=="")
	{
			alert("Please enter version of the vehicle");
			document.getElementById("pe_form[version_pe]").focus();
			return false;
	}

	var strTrimed = trim(document.getElementById("pe_form[vehicle_regprefix]").value);
	if (strTrimed=="")
	{
			alert("Please enter the Registration Number");
			document.getElementById("pe_form[vehicle_regprefix]").focus();
			return false;
	}
	
	var strTrimed = document.getElementById("pe_form[vehicle_regmonth]").selectedIndex;
	if (strTrimed=="0")
	{
			alert("Please select Registration Month");
			document.getElementById("pe_form[vehicle_regmonth]").focus();
			return false;
	}

	var strTrimed = document.getElementById("pe_form[vehicle_regyear]").selectedIndex;
	if (strTrimed=="0")
	{
			alert("Please select Registration Year");
			document.getElementById("pe_form[vehicle_regyear]").focus();
			return false;
	}


	var strTrimed = trim(document.getElementById("pe_form[vehicle_exterior]").value);
	if (strTrimed=="")
	{
			alert("Please enter Exterior colour");
			document.getElementById("pe_form[vehicle_exterior]").focus();
			return false;
	}

	var strTrimed = trim(document.getElementById("pe_form[vehicle_interior]").value);
	if (strTrimed=="")
	{
			alert("Please enter valid Interior Trim");
			document.getElementById("pe_form[vehicle_interior]").focus();
			return false;
	}

	var strTrimed = trim(document.getElementById("pe_form[vehicle_mileagerecorded]").value);
	if (strTrimed=="")
	{
			alert("Please enter valid Recorded Mileage");
			document.getElementById("pe_form[vehicle_mileagerecorded]").focus();
			return false;
	}
	
	var strTrimed = document.getElementById("pe_form[vehicle_servicehistory]").selectedIndex;
	if (strTrimed=="0")
	{
			alert("Please select Full Service History");
			document.getElementById("pe_form[vehicle_servicehistory]").focus();
			return false;
	}
	
	var strTrimed = trim(document.getElementById("pe_form[vehicle_lastservice_mileage]").value);
	if (strTrimed=="")
	{
			alert("Please enter valid Last Serviced Miles");
			document.getElementById("pe_form[vehicle_lastservice_mileage]").focus();
			return false;
	}
	
	var strTrimed = document.getElementById("pe_form[vehicle_origin]").selectedIndex;
	if (strTrimed=="0")
	{
			alert("Please select Vehicle origin");
			document.getElementById("pe_form[vehicle_origin]").focus();
			return false;
	}
	
	var strTrimed = document.getElementById("pe_form[vehicle_bodyrepairs]").selectedIndex;
	if (strTrimed=="0")
	{
			alert("Please select Previous body repairs");
			document.getElementById("pe_form[vehicle_bodyrepairs]").focus();
			return false;
	}
	
	var strTrimed = document.getElementById("pe_form[vehicle_tyrecondition]").selectedIndex;
	if (strTrimed=="0")
	{
			alert("Please select Tyres");
			document.getElementById("pe_form[vehicle_tyrecondition]").focus();
			return false;
	}
	return true;
}




/* Rollover tooltip script */

var dom = (document.getElementById) ? true : false;
var ns5 = (!document.all && dom || window.opera) ? true: false;
var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
var ie4 = (document.all && !dom) ? true : false;
var nodyn = (!ns5 && !ie4 && !ie5 && !dom) ? true : false;

var origWidth, origHeight;
if (nodyn) { event = "No" }


var tipFollowMouse= true;	
var tipWidth= 327;
var tipHeight= 158;
var offX= 20;
var offY= -44; 

var wttipFollowMouse= false;	//for what'sthis variable intialization
var wttipWidth= 306;
var wttipHeight= 120;
var wtoffX= 12;
var wtoffY= -46;


var messages = new Array();
messages[0] = new Array('/images/help_bubble_blue.gif','<img src="/images/instruction1_new.gif" width="24" height="24" border="0" alt="1" style="float: left; padding: 0px 5px 0px 0px;"> <span style="float: right; width: 215px;height:160px;">Motorati is ready and waiting to find you the best possible deal. Once you have decided on which car you want to buy we will do the leg work.</span>');
messages[1] = new Array('/images/help_bubble_blue.gif','<img src="/images/instruction2_new.gif" width="24" height="24" border="0" alt="2" style="float: left; padding: 0px 5px 0px 0px;"> <span style="float: right; width: 215px;height:160px;">You now need to give us your requirements using our Multi-brand configurator. This is an easy to use drop down list giving you all vehicles available and allows you to select additional options. The following stage will ask you to supply us with your contact details so that we can get in touch once we have found suitable vehicles for you.</span>');
messages[2] = new Array('/images/help_bubble_blue.gif','<img src="/images/instruction3_new.gif" width="24" height="24" border="0" alt="3" style="float: left; padding: 0px 5px 0px 0px;"> <span style="float: right; width: 215px;height:160px;">Motorati will ask you to reply to an SMS (call the Motorati team if you do not have a mobile phone), this is to confirm that the details you have supplied us are valid. Once you have replied back to the SMS our dealer network will then be notified regarding your request.</span>');
messages[3] = new Array('/images/help_bubble_blue.gif','<img src="/images/instruction4_new.gif" width="24" height="24" border="0" alt="4" style="float: left; padding: 0px 5px 0px 0px;"> <span style="float: right; width: 215px;height:160px;">Over the next 5 working days you will receive a selection of offers from dealers, ranging from price, specification saving & proximity. You will receive an email asking you to login to the website and view your offers.</span>');
messages[4] = new Array('/images/help_bubble_mauve.gif','<img src="/images/instruction5_new.gif" width="24" height="24" border="0" alt="5" style="float: left; padding: 0px 5px 0px 0px;"> <span style="color: #297225; float: right; width: 215px;">Once the 5 working days have expired, you can view your quotes and compare. Our easy to use Comparator View allows you to look at all offers in vertical columns with a full breakdown so you can decide on the one that jumps out at you.</span>');
messages[5] = new Array('/images/help_bubble_mauve.gif','<img src="/images/instruction6_new.gif" width="24" height="24" border="0" alt="6" style="float: left; padding: 0px 5px 0px 0px;"> <span style="color: #297225; float: right; width: 215px;">This option allows you to hold the vehicle ASAP to avoid any disappointment at later stages. The supplying dealer will then be given your details and the transaction can be completed. This Holding Deposit will then be credited back to you.</span>');
messages[6] = new Array('/images/help_bubble_mauve_large.gif','<img src="/images/instruction6_new.gif" width="24" height="24" border="0" alt="6" style="float: left; padding: 0px 5px 0px 0px;"> <span style="color: #297225; float: right; width: 215px;height:208px;">If you have any questions or you would like more details on the vehicle in question, you can speak to the supplying dealer directly. It’s your choice whether you would like to <br/>&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;talk to the dealer<br/>&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;request a call back from dealer, or<br/>&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;request the dealer to contact you by<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;email<br/>Once you are happy to proceed you can finalize the deal directly with the supplying dealer.</span>');
messages[7] = new Array('/images/help_bubble_mauve.gif','<img src="/images/instruction7_new.gif" width="24" height="24" border="0" alt="7" style="float: left; padding: 0px 5px 0px 0px;"> <span style="color: #297225; ; float: right; width: 215px;">Your chosen dealer delivers your sparkling new car to your doorstep. No hassle. No sweat.</span>');


messages[8] = new Array('/images/whatsthislayer.gif','<img src="/images/motlogin_close.gif" border="0" alt="Close" title="Close" style="float:right; padding: 0px 5px 0px 0px;" onClick="whatthisclose();"><span style="float: left; padding: 35px 0px 0px 0px;">Customer is Very Interested to buy a car.</span>');

messages[9] = new Array('/images/whatsthislayer.gif','<img src="/images/motlogin_close.gif" border="0" alt="Close" title="Close" style="float: right; padding: 0px 5px 0px 0px;" onClick="whatthisclose();"> <span style="float: left; padding: 35px 0px 0px 0px;">Customer is Considering to buy a car.</span>');

messages[10] = new Array('/images/whatsthislayer.gif','<img src="/images/motlogin_close.gif" border="0" alt="Close" title="Close" style="float: right; padding: 0px 5px 0px 0px;" onClick="whatthisclose();"><span style="float: left; padding: 35px 0px 0px 0px;">Customer is Just Browsing to buy a car.</span>');


if (document.images) {
	var theImgs = new Array();
	for (var i=0; i<messages.length; i++){
  	theImgs[i] = new Image();
		theImgs[i].src = messages[i][0];
  }
}

var startStr = '<table border="0" cellspacing="0" cellpadding="0"><tr><td valign="top" width="' + tipWidth + '"  height="' + tipHeight + '" background="';
var midStr = '" border="0"><div style="padding: 20px 30px 0px 45px;">';
var endStr = '<' + '/div><' + '/td><' + '/tr><' + '/table>';

//what'sthis table
var wtstartStr = '<table border="0" cellspacing="0" cellpadding="0"><tr><td valign="top" width="' + wttipWidth + '"  height="' + wttipHeight + '" background="';
var wtmidStr = '" border="0"><div style="padding: 10px 5px 0px 45px;">';
var wtendStr = '<' + '/div><' + '/td><' + '/tr><' + '/table>';



var tooltip, tipcss;

var wttooltip, wttipcss;//what this element variable declaration


function initTip() {
	if (nodyn) return;
	tooltip = (ie4)? document.all['tipDiv']: (ie5||ns5)? document.getElementById('tipDiv'): null;
	tipcss = tooltip.style;
	if (ie4||ie5||ns5) {
		tipcss.width = tipWidth+"px";
	}
	if (tooltip&&tipFollowMouse) {
		document.onmousemove = trackMouse;
	}
}


//function to initialize style
function initTipwt() {
	if (nodyn) return;
	wttooltip = (ie4)? document.all['tipDiv']: (ie5||ns5)? document.getElementById('tipDiv'): null;
	wttipcss = wttooltip.style;
	if (ie4||ie5||ns5) {
		wttipcss.width = wttipWidth+"px";
		}
	}


window.onload = initTip;

var t1,t2;
var tipOn = false;
function doTooltip(evt,num) {
	if (!tooltip) return;
	if (t1) clearTimeout(t1);	if (t2) clearTimeout(t2);
	tipOn = true;
	if (ie4||ie5||ns5) {
		var tip = startStr + messages[num][0] + midStr + messages[num][1] + endStr;
	 	tooltip.innerHTML = tip;
	}
	if (!tipFollowMouse) positionTip(evt);
	else t1=setTimeout("tipcss.visibility='visible'",100);
}


var wtt1,wtt2;
var wttipOn = false;

function whatthis(evet,num)//what's this onclick function
{
	initTipwt();//load the what's this style
	if (!wttooltip) return;
	if (wtt1) clearTimeout(wtt1);	if (wtt2) clearTimeout(wtt2);
	wttipOn = true;
	if (ie4||ie5||ns5) {
		var wttip = wtstartStr + messages[num][0] + wtmidStr + messages[num][1] + wtendStr;
	 	wttooltip.innerHTML = wttip;
		
	}
	if (!wttipFollowMouse)wtpositionTip(evet);
	else wtt1=setTimeout("wttipcss.visibility='visible'",100);
}


function whatthisclose()//what's this close button
{
document.getElementById('tipDiv').innerHTML="";
}


var mouseX, mouseY;
function trackMouse(evt) {
	standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
	mouseX = (ns5)? evt.pageX: window.event.clientX + standardbody.scrollLeft;
	mouseY = (ns5)? evt.pageY: window.event.clientY + standardbody.scrollTop;
	if (tipOn) positionTip(evt);
}

function positionTip(evt) {
	if (!tipFollowMouse) {
		mouseX = (ns5)? evt.pageX: window.event.clientX + standardbody.scrollLeft;
		mouseY = (ns5)? evt.pageY: window.event.clientY + standardbody.scrollTop;
	}
	var tpWd = (ie4||ie5)? tooltip.clientWidth: tooltip.offsetWidth;
	var tpHt = (ie4||ie5)? tooltip.clientHeight: tooltip.offsetHeight;
	var winWd = (ns5)? window.innerWidth-20+window.pageXOffset: standardbody.clientWidth+standardbody.scrollLeft;
	var winHt = (ns5)? window.innerHeight-20+window.pageYOffset: standardbody.clientHeight+standardbody.scrollTop;
	if ((mouseX+offX+tpWd)>winWd) 
		tipcss.left = mouseX-(tpWd+offX)+"px";
	else tipcss.left = mouseX+offX+"px";
	if ((mouseY+offY+tpHt)>winHt) 
		tipcss.top = winHt-(tpHt+offY)+"px";
	else tipcss.top = mouseY+offY+"px";
	if (!tipFollowMouse) t1=setTimeout("tipcss.visibility='visible'",100);
}

var wtmouseX, wtmouseY;//function to load the layer
function wtpositionTip(evt) {
	standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
	if (!wttipFollowMouse) {
		wtmouseX = (ns5)? evt.pageX: window.event.clientX + standardbody.scrollLeft;
		wtmouseY = (ns5)? evt.pageY: window.event.clientY + standardbody.scrollTop;
	}
	var tpWd = (ie4||ie5)? wttooltip.clientWidth: wttooltip.offsetWidth;
	var tpHt = (ie4||ie5)? wttooltip.clientHeight: wttooltip.offsetHeight;
	var winWd = (ns5)? window.innerWidth-20+window.pageXOffset: standardbody.clientWidth+standardbody.scrollLeft;
	var winHt = (ns5)? window.innerHeight-20+window.pageYOffset: standardbody.clientHeight+standardbody.scrollTop;
	if ((wtmouseX+wtoffX+tpWd)>winWd) 
		wttipcss.left = wtmouseX-(tpWd+wtoffX)+"px";
	else wttipcss.left = wtmouseX+wtoffX+"px";
	if ((wtmouseY+wtoffY+tpHt)>winHt) 
		wttipcss.top = winHt-(tpHt+wtoffY)+"px";
	else wttipcss.top = wtmouseY+wtoffY+"px";
	if (!wttipFollowMouse) 
	wtt1=setTimeout("wttipcss.visibility='visible'",100);
//	wtt1=setTimeout("wttipcss.visibility='hidden'",5000);
}



function view_lead_details(leadid,bidid,act){

//	    document.getElementById("container").innerHTML="";
		document.getElementById(act+bidid).style.display = 'none'
		document.getElementById(act+leadid).style.display = 'block'

		/*var arrayPageSize = getPageSize();
		var objOverlay = document.getElementById('overlay');
		objOverlay.style.height = (arrayPageSize[1] + 'px');
		objOverlay.style.display = 'block';
			
		var objOverlayIframe = document.getElementById('overlayiframe');
		objOverlayIframe.style.height = (arrayPageSize[1] + 'px');
		objOverlayIframe.style.display = 'block';
		*/
		http.open("GET","/bid.php?leadid=" + leadid + "&bidid=" + bidid + "&act=view",true);
		http.onreadystatechange = HttpViewLeadDetails;
		http.send(null);	
//	document.getElementById("det_but" + bidid).href="#";
}


function HttpViewLeadDetails()
{
	if(http.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(http.status == 200)
		{
			// data has been collected call populate method with xml tree.
				
			//document.getElementById("modalwin2").style.display = 'none'
			//var objOverlay = document.getElementById('overlay');
			//var objOverlayIframe = document.getElementById('overlayiframe');
			//objOverlay.style.display = 'none';
			//objOverlayIframe.style.display = 'none';
			document.getElementById("container").innerHTML = http.responseText;
//			document.getElementById("period").value = document.getElementById("period").value;
		}
		else
		{
			alert("problem retrieving data from the server, status code: "  + http.status);
		}
	}

}

function place_offer(leadid,act){

//	    document.getElementById("container").innerHTML="";
		if (document.getElementById(act+leadid)) document.getElementById(act+leadid).style.display = 'none'
		if (document.getElementById("l" + leadid)) document.getElementById("l" + leadid).style.display = 'block'

		/*var arrayPageSize = getPageSize();
		var objOverlay = document.getElementById('overlay');
		objOverlay.style.height = (arrayPageSize[1] + 'px');
		objOverlay.style.display = 'block';
			
		var objOverlayIframe = document.getElementById('overlayiframe');
		objOverlayIframe.style.height = (arrayPageSize[1] + 'px');
		objOverlayIframe.style.display = 'block';
		*/
		http.open("GET","/bid.php?leadid=" + leadid,true);
		http.onreadystatechange = Httpplace_offer;
		http.send(null);	
//	document.getElementById("det_but" + bidid).href="#";
}


function Httpplace_offer()
{
	if(http.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(http.status == 200)
		{
			// data has been collected call populate method with xml tree.
				
			//document.getElementById("modalwin2").style.display = 'none'
			//var objOverlay = document.getElementById('overlay');
			//var objOverlayIframe = document.getElementById('overlayiframe');
			//objOverlay.style.display = 'none';
			//objOverlayIframe.style.display = 'none'; 
			document.getElementById("container").innerHTML = http.responseText;
//			document.getElementById("period").value = document.getElementById("period").value;
		}
		else
		{
			alert("problem retrieving data from the server, status code: "  + http.status);
		}
	}

}

function withdraw()
{	
		//alert("This offer has been withdrawn successfully");
		
}

function adjust_lead_details(leadid,bidid,act){

//	    document.getElementById("container").innerHTML="";
		if (document.getElementById(act+bidid)) document.getElementById(act+bidid).style.display = 'none'
		if (document.getElementById(act+leadid)) document.getElementById(act+leadid).style.display = "block"

		/*var arrayPageSize = getPageSize();
		var objOverlay = document.getElementById('overlay');
		objOverlay.style.height = (arrayPageSize[1] + 'px');
		objOverlay.style.display = 'block';
			
		var objOverlayIframe = document.getElementById('overlayiframe');
		objOverlayIframe.style.height = (arrayPageSize[1] + 'px');
		objOverlayIframe.style.display = 'block';
		*/
		http.open("GET","/bid.php?leadid=" + leadid + "&bidid=" + bidid + "&act=adjust",true);
		http.onreadystatechange = HttpAdjustLeadDetails;
		http.send(null);	
//	document.getElementById("det_but" + bidid).href="#";
}


function HttpAdjustLeadDetails()
{
	if(http.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(http.status == 200)
		{
			// data has been collected call populate method with xml tree.
				
			//document.getElementById("modalwin1").style.display = 'none'
			//var objOverlay = document.getElementById('overlay');
			//var objOverlayIframe = document.getElementById('overlayiframe');
			//objOverlay.style.display = 'none';
			//objOverlayIframe.style.display = 'none';
			document.getElementById("container").innerHTML = http.responseText;
//			document.getElementById("period").value = document.getElementById("period").value;
		}
		else
		{
			alert("problem retrieving data from the server, status code: "  + http.status);
		}
	}

}
function bidsubmit(leadid){
	
//	    document.getElementById("container").innerHTML="";
		var newCarType="";
		if(document.getElementById("new1").checked==true) newCarType="newInStock";
		if(document.getElementById("new2").checked==true) newCarType="newInStockWithLead";
		if(document.getElementById("new3").checked==true) newCarType="PreReg";
		if(document.getElementById("new4").checked==true) newCarType="ExDemo";
		document.getElementById("bid[newcar]").value=newCarType;
		document.getElementById("submit_link").style.display = 'none';
		document.getElementById("bid_submit").style.display = 'block';
		
//		document.getElementById(leadid).style.display = "block"
		var poststr="";
		var ctr=0;
		for ( var i=0;i<document.quotefrm.elements.length;i++ ){
			if(document.quotefrm.elements[i].title != "rel_data")
			{
				if(document.quotefrm.elements[i].type=="checkbox"){
					if(document.quotefrm.elements[i].checked==true)
					{
						if (ctr > 0) poststr = poststr + "&";
						poststr = poststr + document.quotefrm.elements[i].name + "=" + encodeURI( document.quotefrm.elements[i].value );
						ctr++;
					}
				} else {
					if (ctr > 0) poststr = poststr + "&";
					poststr = poststr + document.quotefrm.elements[i].name + "=" + encodeURI( document.quotefrm.elements[i].value );
					ctr++;
				}
			}
		}
  		makePOSTRequest('bid.php', poststr,"1");


		/*var arrayPageSize = getPageSize();
		var objOverlay = document.getElementById('overlay');
		objOverlay.style.height = (arrayPageSize[1] + 'px');
		objOverlay.style.display = 'block';
			
		var objOverlayIframe = document.getElementById('overlayiframe');
		objOverlayIframe.style.height = (arrayPageSize[1] + 'px');
		objOverlayIframe.style.display = 'block';
		*/
		//http.open("GET","/bid.php?leadid=" + leadid + "&bidid=" + bidid + "&act=adjust",true);
		
//			document.bidfrm.submit();
		//alert("Your bid has been placed successfully. All the best");
//		http.onreadystatechange = HttpbidsubmitDetails;
//		http.send(null);	

//	document.getElementById("det_but" + bidid).href="#";
}


function HttpbidsubmitDetails()
{
	if(http.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(http.status == 200)
		{
			// data has been collected call populate method with xml tree.
				
			//document.getElementById("modalwin1").style.display = 'none'
			//var objOverlay = document.getElementById('overlay');
			//var objOverlayIframe = document.getElementById('overlayiframe');
			//objOverlay.style.display = 'none';
			//objOverlayIframe.style.display = 'none';
			
			document.getElementById("container").innerHTML = http.responseText;
//			document.getElementById("period").value = document.getElementById("period").value;
		}
		else
		{
			alert("problem retrieving data from the server, status code: "  + http.status);
		}
	}

}


function bidAdjust(bidid){
	
//	    document.getElementById("container").innerHTML="";
		document.getElementById("adjust_this").style.display = 'none'
		document.getElementById(bidid).style.display = "block"
		var newCarType="";
		if(document.getElementById("new1").checked==true) newCarType="newInStock";
		if(document.getElementById("new2").checked==true) newCarType="newInStockWithLead";
		if(document.getElementById("new3").checked==true) newCarType="PreReg";
		if(document.getElementById("new4").checked==true) newCarType="ExDemo";
		document.getElementById("bid[newcar]").value=newCarType;

		/*var arrayPageSize = getPageSize();
		var objOverlay = document.getElementById('overlay');
		objOverlay.style.height = (arrayPageSize[1] + 'px');
		objOverlay.style.display = 'block';
			
		var objOverlayIframe = document.getElementById('overlayiframe');
		objOverlayIframe.style.height = (arrayPageSize[1] + 'px');
		objOverlayIframe.style.display = 'block';
		*/
		//http.open("GET","/bid.php?leadid=" + leadid + "&bidid=" + bidid + "&act=adjust",true);

//			document.bidfrm.submit();
		var poststr="";
		var ctr=0;
		for ( var i=0;i<document.quotefrm.elements.length;i++ ){
			if (document.quotefrm.elements[i].type=="checkbox")
			{
				if (document.quotefrm.elements[i].checked)
				{
					if (ctr > 0) poststr = poststr + "&";
					poststr = poststr + document.quotefrm.elements[i].name + "=" + encodeURI( document.quotefrm.elements[i].value );
					ctr++;
				}
					
			} else {
				if (ctr > 0) poststr = poststr + "&";
				poststr = poststr + document.quotefrm.elements[i].name + "=" + encodeURI( document.quotefrm.elements[i].value );
				ctr++;
			}
		}
	  http_request = false;
	  if (window.XMLHttpRequest) { // Mozilla, Safari,...
		 http_request = new XMLHttpRequest();
		 if (http_request.overrideMimeType) {
			// set type accordingly to anticipated content type
			//http_request.overrideMimeType('text/xml');
			http_request.overrideMimeType('text/html');
		 }
	  } else if (window.ActiveXObject) { // IE
		 try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		 } catch (e) {
			try {
			   http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		 }
	  }
	  if (!http_request) {
		 alert('Cannot create XMLHTTP instance');
		 return false;
	  }
		http_request.onreadystatechange = HttpbidAdjustDetails;
	    http_request.open('POST', "bid.php", true);
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http_request.setRequestHeader("Content-length", poststr.length);
		http_request.setRequestHeader("Connection", "close");
		http_request.send(poststr);
		
		//alert("Your bid has been adjusted successfully");
//		http_request.send(null);	
//	document.getElementById("det_but" + bidid).href="#";
}


function HttpbidAdjustDetails()
{
	if(http_request.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(http_request.status == 200)
		{
			// data has been collected call populate method with xml tree.
				
			//document.getElementById("modalwin1").style.display = 'none'
			//var objOverlay = document.getElementById('overlay');
			//var objOverlayIframe = document.getElementById('overlayiframe');
			//objOverlay.style.display = 'none';
			//objOverlayIframe.style.display = 'none';
			document.location="myhome.php";
			
//			document.getElementById("period").value = document.getElementById("period").value;
		}
		else
		{
			alert("problem retrieving data from the server, status code: "  + http.status);
		}
	}

}


function hideTip() {
	if (!tooltip) return;
	t2=setTimeout("tipcss.visibility='hidden'",100);
	tipOn = false;
}

function configure_car_fn()
{
	document.getElementById("configure_car").src="/images/btn_configure1.gif"
}

function configure_car_hover()
{
	document.getElementById("configure_car").src="/images/btn_configure2.gif"	
}

function part_exbid(leadid,peid,req_type)
{
		http.open("GET","/partexchangedetails.php?id=" + leadid + "&pe_id=" + peid + "&act=" + req_type ,true);
		http.onreadystatechange = HttpShowBid;
		http.send(null);	
}

function part_exbidadjust(leadid,peid,bidid,req_type)
{
		http.open("GET","/partexchangedetails.php?id=" + leadid + "&pe_id=" + peid + "&act=" + req_type + "&bidid=" + bidid ,true);
		http.onreadystatechange = HttpShowBid;
		http.send(null);	
}


function HttpShowBid()
{
		if(http.readyState == 4)
	{
		if(http.status == 200)
		{
			document.getElementById("container").innerHTML = http.responseText;
		}
		else
		{
			alert("problem retrieving data from the server, status code: "  + http.status);
		}
	}
}	

function getadminmessage(email)
{
	http.open("GET","/getadminmessage.php?email="+email,true);
	http.onreadystatechange = admin_chat_message_details;
	http.send(null);				
//	document.getElementById("chat_display").value = document.getElementById("chat_display").value + " --" + tuserid + "--" + fruserid + "--";
}

function admin_chat_message_details()
{
	var resp_arr;
	if (http.readyState == 4) {
		if (http.status == 200) {
				var response=http.responseText;
				if(trim(response) != "")
				{
					resp_arr=response.split('^');
					var obj=document.getElementById("chat_display")
					document.getElementById("adminid").value=resp_arr[0];
					document.getElementById("chat_display").value = resp_arr[1] +  document.getElementById("chat_display").value 
				}
		} else {
			alert("Failed: " + http.status);
		}
	}
}


function send_admin_msg()
{
	var email=document.getElementById("email").value;
	var username=document.getElementById("username").value;
	var adminid=document.getElementById("adminid").value;
	var msg=document.getElementById("txt_value").value;
	if(msg != "" && trim(adminid) != "")
	{
		var url="/sendadminmessage.php?email=" + email + "&uname=" + username + "&adminid=" + adminid;
		url = url + "&msg=" + msg;
		http.open("GET",url,true);
		http.onreadystatechange = send_chat_message;
		http.send(null);						
	}	
}


function cycle1(email) {
	getadminmessage(email);
	window.setTimeout('cycle1(\'' + email + '\');',2000);
}



function send_chat_request()
{
	uname=document.getElementById("username").value;
	email=document.getElementById("emailid").value;
	if(trim(uname)=="")
	{
		alert("Please enter your Name");
		document.getElementById().setfocus();
		return;
	}
	if(trim(email)=="")
	{
		alert("Please enter your Email address");
		document.getElementById().setfocus();
		return;
	}
	document.chat_request.submit();

}


document.write('<' + 'div id="tipDiv" style="position:absolute; visibility:hidden; z-index:100;"><' + '/div>')


function isnArray() {
argnr=isnArray.arguments.length
for (var i=0;i<argnr;i++) {
  this[i+1] = isnArray.arguments[i];
  }
}

function createclock()
{
	var isnMonths=new isnArray("Jan","Feb","Mar","Apr","May","June","July","Aug","Sep","Oct","Nov","Dec");
	var isnDays= new isnArray("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
	
	Stamp = new Date();
	var Hours;
	var Mins;
	var Time;
	var Sec;
	Hours = Stamp.getHours();
	
	Mins = Stamp.getMinutes();
	
	Sec = Stamp.getSeconds();
//alert(Sec);

	if (Mins < 10) {
    	Mins = "0" + Mins;
    }
	window.setTimeout("createclock()",1000);
/*	if(Sec==0)
	{
		document.getElementById("clock").innerHTML= Stamp.getDate() +" "+isnMonths[(Stamp.getMonth() + 1)]+ " "+Stamp.getFullYear() + ' | ' + Hours + ":" + Mins;
	//	document.location=document.location;
	}*/
	if(document.getElementById("clock"))
	{
	document.getElementById("clock").innerHTML= Stamp.getDate() +" "+isnMonths[(Stamp.getMonth() + 1)]+ " "+Stamp.getFullYear() + ' | ' + Hours + ":" + Mins;
	}
	if(document.getElementById("clock_img"))
	{
	document.getElementById("clock_img").title=Stamp.getDate() +" "+isnMonths[(Stamp.getMonth() + 1)]+ " "+Stamp.getFullYear() + ' | ' + Hours + ":" + Mins;
	document.getElementById("clock_img").alt=Stamp.getDate() +" "+isnMonths[(Stamp.getMonth() + 1)]+ " "+Stamp.getFullYear() + ' | ' + Hours + ":" + Mins;
	}
}



