/* The following function creates an XMLHttpRequest object... */

function changeDates(url){
//alert (url);
if (url.indexOf("?")!=-1)
	newurl=url+"&changedate=true";
else
	newurl=url+"?changedate=true";

window.location=newurl;
  

}//end function



function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

var http = createRequestObject(); 

/* Function called to get the product categories list */
/* old way */
/*

function getTermCost(pid){
transtype=document.all("shop").value;
term=document.cart_quantity.rterm.value;

http.open('get', 'internal_request.php?action=evaluate&products_id='+pid+'&term='+term+'&transtype='+transtype);
	http.onreadystatechange = handleTermCost; 
	http.send(null);
}

function handleTermCost(){
	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
		document.getElementById('displayResponse').innerHTML = response;
	}
}
*/
function getValidUser(){
//transtype=document.all("shop").value;
//term=document.cart_quantity.rterm.value;
cid=document.getElementById('existing_email').value;
pw=document.getElementById('existing_password').value;

http.open('get', 'internal_rcms_billing.php?action=validation&cust_email='+cid);
http.onreadystatechange = handleValidUser; 
http.send(null);

}

function handleValidUser(){
	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
		document.getElementById('divBillingAddress').innerHTML = response;
	}
}


function getRCMSBillingContact(){
cemail=document.getElementById('existing_email').value;
pw=document.getElementById('existing_password').value;
	//if(cemail != "" & pw != "" ){
		http.open('get', 'internal_rcms_billing.php?action=billing&cust_email='+cemail+'&cust_pw='+pw);
		http.onreadystatechange = handleRCMSBillingContact; 
		http.send(null);
	//}
}

function handleRCMSBillingContact(){
	if(http.readyState == 1 | http.readyState == 2){ //Finished loading the response
 		document.getElementById('divBillingAddress').innerHTML = '<table ><tr><td><img src="images/working.gif"></td><td class="main">Loading...</td></tr></table> ';
	}
	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
 		start=response.search('<span1>');
		end=response.search('</span1>');

        //CI.COM 03 TIVA 04/01/2008 code added for PTR 5243
		//document.getElementById("divLogin").innerHTML = response.substring(start+'<span1>'.length,end);
		var resp1 = response.substring(start+'<span1>'.length,end);
		document.getElementById("divLogin").innerHTML = resp1;

		start=response.search('<span2>');
		end=response.search('</span2>');
 		document.getElementById("existing_company").value = response.substring(start+'<span2>'.length,end);

		//CI.COM TIVA 04/01/2008 code added for PTR 5243 {Start}
		//document.getElementById("existing_company").disabled=true;
		if (resp1 == ""){
		  document.getElementById("existing_company").disabled=true;
		}
		//CI.COM TIVA 04/01/2008 code added for PTR 5243 {End}

		document.getElementById('divBillingAddress').innerHTML = response.substring(end);

		//CI.COM TIVA 04/01/2008 code added for PTR 5243 {Start}
		if (resp1 != ""){
    		alert("Invalid Existing Email/Password.");
		}		
		//CI.COM TIVA 04/01/2008 code added for PTR 5243 {End}

	}
}

function getTermCartProductsCosts(qs){
 
transtype='Rental';
term=document.getElementById("trans_form").rterm.value;
http.open('get', 'internal_request_detail.php?action=changeTerm&term='+term+'&transtype='+transtype+'&'+qs);
	http.onreadystatechange = handleTermCartProductsCosts; 
	http.send(null);

}

function handleTermCartProductsCosts(){
 	if(http.readyState == 1 | http.readyState == 2){ //Finished loading the response
 		document.getElementById('divShoppingCartRentalTotal').innerHTML = '<table ><tr><td><img src="images/working.gif"></td><td class="main"></td></tr></table> ';
		document.getElementById('divShoppingCartTotal').innerHTML = '<table ><tr><td><img src="images/working.gif"></td><td class="main"></td></tr></table> ';
for(i=0;i<20;i++){
 		document.getElementById('divShoppingCartPrice'+i).innerHTML = '<table ><tr><td><img src="images/working.gif"></td><td class="main"></td></tr></table> ';
 	}
	}
	 
	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
		start=response.search('<span1>');
		end=response.search('</span1>');
 		document.getElementById("divShoppingCart").innerHTML = response.substring(0,start);
		document.getElementById("divShoppingCartRentalTotal").innerHTML = response.substring(start+'<span1>'.length,end);
		start=response.search('<span2>');
		end=response.search('</span2>');

		document.getElementById("divShoppingCartTotal").innerHTML = response.substring(start+'<span2>'.length,end);
	}
}

var productid="";
function getTermProductsCosts(qs){
 transtype=document.getElementById("trans_form").shop.value;
term=document.getElementById("trans_form").rterm.value;
  http.open('get', 'internal_request.php?case=evaluate&term='+term+'&transtype='+transtype+'&'+qs);
	http.onreadystatechange = handleTermProductsCosts; 
	http.send(null);
}

function handleTermProductsCosts(){
 	if(http.readyState == 1 | http.readyState == 2){ //Finished loading the response
	for(i=1;i<20;i++){
  		document.getElementById('divRentPrice'+i).innerHTML = '<span><img src="images/working.gif"></span>';
 	}
	}
	
	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
	//alert(response);
 		document.getElementById("display_list").innerHTML = response;
	}
}



/* new way */

function getTermCost(pid){
transtype=document.all("shop").value;
term=document.cart_quantity.rterm.value;

http.open('get', 'internal_request_detail.php?action=evaluate&products_id='+pid+'&term='+term+'&transtype='+transtype);
	http.onreadystatechange = handleTermCost; 
	http.send(null);
}

function handleTermCost(){
 	if(http.readyState == 1 | http.readyState == 2){ //Finished loading the response
   		document.getElementById('divRentPrice').innerHTML = '<span><img src="images/working.gif"></span>';
 	}
	
	
	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
		document.getElementById('displayResponse').innerHTML = response;
	}
}

var productid="";
function getTermCosts(pid){
//alert (pid);
transtype=document.all("shop").value;
term=document.getElementById(pid).rterm.value;
 productid=pid;
http.open('get', 'internal_request_detail.php?action=evaluate&products_id='+productid+'&term='+term+'&transtype='+transtype);
	http.onreadystatechange = handleTermCosts; 
	http.send(null);
}

function handleTermCosts(){
	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
		//alert(response);
		document.getElementById("display"+productid).innerHTML = response;
	}
}



function getTermCosts_New(qs){
//alert (qs);
transtype=document.getElementById("trans_form_new").shop.value;
term=document.getElementById("trans_form_new").rterm.value;
//term=document.cart_quantity.rterm.value;
 http.open('get', 'internal_request_new.php?case=evaluate&term='+term+'&transtype='+transtype+'&'+qs);
	http.onreadystatechange = handleTermCosts_New; 
	http.send(null);
}

function handleTermCosts_New(){
	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
 		document.getElementById("display_list_new").innerHTML = response;
	}
}


function getStartDates(rentaltermdays,rentalterm){

startday=document.checkout_address.startday.value;
startmonth=document.checkout_address.startmonth.value;
startyear=document.checkout_address.startyear.value;
/*
startday=document.getElementById("checkout_address").startday.value;
startmonth=document.getElementById("checkout_address").startmonth.value;
startyear=document.getElementById("checkout_address").startyear.value;


startday=document.getElementById("startday").value;
startmonth=document.getElementById("startmonth").value;
startyear=document.getElementById("startyear").value;
*/
//sdate=startmonth+"-"+startday+"-"+startyear;
    http.open('get', 'internal_request.php?case=dates&startmonth='+startmonth+'&startday='+startday+'&startyear='+startyear+'&rentaltermdays='+rentaltermdays+'&rentalterm='+rentalterm);
	http.onreadystatechange = handleStartDates; 
	http.send(null);
}

function handleStartDates(){
	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
		//alert (response);
		document.getElementById('return_dates_display').innerHTML = response;
	}
}


function getSubCats(newurl){
	make=document.ddlMakeForm.ddlMake.value;
    http.open('get', newurl+'&make='+make+'&action=getModels');
	http.onreadystatechange = handleSubCats; 
	http.send(null);
	
	}
function handleSubCats(){
	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
//		 alert (document.getElementById('divModels'));
		document.getElementById('divModels').innerHTML = response;
	}
}


function getBodyTypes(newurl,make){
	model=document.ddlModelForm.ddlModel.value;
	
// alert(str+'  -  '+model+'  -  '+fixtkey);
//	alert(newurl+'&make='+make);

    http.open('get', newurl+'&make='+make+'&model='+model+'&action=getBodyTypes');
	http.onreadystatechange = handleBodyTypes; 
	http.send(null);
	
	}
function handleBodyTypes(){
	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
		//alert (response);
		document.getElementById('divBodyTypes').innerHTML = response;
	}
}

function getBodyTypesCodes(newurl,make,model){

str=document.BodyTypeForm.ddlBodyType.value;
	bodytype=str.substr(0,str.indexOf("/"));
req=str.substr(str.indexOf("/")+1);
fixtkey=req.substr(req.indexOf("-")+1);
req=req.substr(0,1);
if(req==0){
	str1=newurl;
	newstr1=str1.replace(/internal_vehicle.php/,"index.php");
	newstr2=newstr1.replace(/cPath=1/,"cPath="+fixtkey+"&fixt=1");
	window.location=newstr2;
	}
// alert(str+'  -  '+model+'  -  '+bodytype+'  -  '+req+'  -  '+fixtkey);
//	alert(newurl+'&make='+make);

    http.open('get', newurl+'&make='+make+'&model='+model+'&bodytype='+bodytype+'&action=getBodyCodes');
	http.onreadystatechange = handleBodyCodes; 
	http.send(null);
	
	}
function handleBodyCodes(){
	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
		//alert (response);
		document.getElementById('divBodyCodes').innerHTML = response;
	}
}

function getItems(newurl,make,model,bodytype){
	bodycode=document.ddlBodyCodeForm.ddlBodyCode.value;
// 	alert(make+'  -  '+model+'  -  '+bodytype+'  -  '+bodycode);
//	alert(newurl);

//var str="Hello world!"
//document.write(str.match("world") + "<br />")
//var str="Visit Microsoft!"
	str1=newurl;
	newstr1=str1.replace(/internal_vehicle.php/,"index.php");
	newstr2=newstr1.replace(/cPath=1/,"cPath="+bodycode+"&fixt=1");

	window.location=newstr2;
//alert(document.getElementById('divFixtureProducts'));

   // http.open('get', newurl+'&make='+make+'&model='+model+'&bodytype='+bodytype+'&bodycode='+bodycode+'&action=getItems');
	//http.onreadystatechange = handleItems; 
	//http.send(null);
	
	}
function handleItems(){
	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
		document.getElementById('divFixtureProducts').innerHTML = response;
	}
}


function makeSelected(model ){
	model=document.ddlModelForm.ddlModel;
	alert(model)
	if(model!=null)
	model.selected=true;
	}

//CI.COM TISN Adds the below function for PTR 4813 05-Nov-2007 starts here..
function venAddress()
{
    venueAddress=document.getElementById("cboVenue").value;
	if(venueAddress=="")
	{
	  document.getElementById('divTaxDistrict').style.visibility='Visible';
	}
    http.open('get', 'deliveryTo_address.php?venueAdd='+venueAddress);
	http.onreadystatechange = handleVenueAddress; 
	http.send(null);
}
function handleVenueAddress(){
	if(http.readyState == 4){ //Finished loading the response
	    var response = http.responseText;
		document.getElementById('divVenueAddress').innerHTML = response;
		if(response!="")
		{
		 document.getElementById('divTaxDistrict').style.visibility='hidden';
		}
		
	}
}
//CI.COM TISN Adds the below function for PTR 4813 05-Nov-2007 Ends here..



