// JavaScript Document


	function LoadAirPort(RL,DA){
		 if(!RL){
		 	var url=rootpath + '/services/parts/dta/dta.dairport.asp?id='+document.MyForm.OAirport.value+'&co='+document.MyForm.DCountry.value+'&Act='+document.MyForm.DAirport.value+'&shipper='+document.MyForm.KnownShipper.value;
		 }else{
			 //var url=rootpath + '/services/parts/dta/dta.dairport.asp?id='+document.MyForm.OAirport.value+'&co='+document.MyForm.DCountry.value+'&Act='+DA+'&shipper='+document.MyForm.KnownShipper[1].checked;
			 var url=rootpath + '/services/parts/dta/dta.dairport.asp?id='+document.MyForm.OAirport.value+'&co='+document.MyForm.DCountry.value+'&Act='+DA+'&shipper='+document.MyForm.KnownShipper.value;
		 }
		 getObject("DAirDiv").innerHTML = "<img src=\"/images/framework/loading_animation.gif\" align=\"absmiddle\"> Loading Please Wait ";
		   
		 xmlHttp=GetXmlHttpObject(AirPortChanged)
		 xmlHttp.open("GET", url , true)
		 xmlHttp.send(null)
	}
	  
	function AirPortChanged(){
		 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			 document.getElementById("DAirDiv").innerHTML=xmlHttp.responseText
			 LoadPort(false,'');
		}
	}
	
	function LoadPort(RL,DP){
		if(!RL){
		 	var url=rootpath + '/services/parts/lcl/lcl.dport.asp?id='+document.MyForm.OPort.value+'&co='+document.MyForm.DCountry.value+'&Act='+document.MyForm.DPort.value;
		}else{
			var url=rootpath + '/services/parts/lcl/lcl.dport.asp?id='+document.MyForm.OPort.value+'&co='+document.MyForm.DCountry.value+'&Act='+DP;
		}
		 getObject("DportDiv").innerHTML = "<img src=\"/images/framework/loading_animation.gif\" align=\"absmiddle\"> Loading Please Wait ";
		   
		 xmlHttp=GetXmlHttpObject(PortChanged)
		 xmlHttp.open("GET", url , true)
		 xmlHttp.send(null)
	}
	  
	function PortChanged(){
		 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			 document.getElementById("DportDiv").innerHTML=xmlHttp.responseText
		}
	}
		
	
/*
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XX Distance and Google Maps
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/

	function loadDistance() {
		if(document.MyForm.OPort.value!="0") {
			if (isZip(document.MyForm.OZipCode.value)) {
				
				/* FILL RESPONSE DIVS WITH LOADING MSG*/
			   getObject("Distance").setAttribute("class", "Distance");
			   getObject("Distance").innerHTML = "<img src=\"/images/framework/loading_animation.gif\" align=\"absmiddle\"> Getting Port Zipcode ";
			   
			   var url=rootpath + '/services/parts/fcl/get.port.zip.asp?id='+document.MyForm.OPort.value;
			   
			   xmlHttp=GetXmlHttpObject(loadDistanceChanged)
			   xmlHttp.open("GET", url , true)
			   xmlHttp.send(null)
			   
			}else{
				getObject("Distance").setAttribute("class", "Distance");
			    getObject("Distance").innerHTML = "Please enter a valid US Or CA Pickup Zip Code ";
			}
		}else{
			getObject("Distance").setAttribute("class", "DistanceHide");
			getObject('Distance').innerHTML = '';
		}
	}
	
	function loadDistanceChanged(){
		 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			start = document.MyForm.OZipCode.value;
			end = xmlHttp.responseText;
			LoadPort(false,'');
			if(isZip(end)){
				getObject("Distance").innerHTML = "<img src=\"/images/framework/loading_animation.gif\" align=\"absmiddle\"> Calculating driving distance from <b>"+document.MyForm.OZipCode.value+"</b> to <b>"+end+"</b>";
				GUnload();
				load();
				//document.getElementById('Distance').innerHTML = 'zipcode';
			}else{
				document.MyForm.Dist.value = "0"
				getObject('Distance').innerHTML = 'Sorry we where not able to calculate the driving distance automaticly, please enter the driving distance between pickup zip code and port <input name="DistMan" type="text" class="field3" id="DistMan" value="'+DistMan+'" size="4" />';
			}
		}
	}
		
	
	
/*Google Function*/
	function load() {
		  var dirn = new GDirections();
		  
		  GEvent.addListener(dirn,"error", function() {
			//GLog.write("Failed: "+dirn.getStatus().code);
			document.MyForm.Dist.value = "0"
			document.getElementById('Distance').innerHTML = 'Sorry we where not able to calculate the driving distance automaticly, please enter the driving distance between pickup zip code and port <input name="DistMan" type="text" class="field3" id="DistMan" value="'+DistMan+'" size="4" />';
		  });
		
		  GEvent.addListener(dirn,"load", function() {
			distance = dirn.getDistance().meters
			
			if(distance != null && distance != 0){
				distance = (distance /1609.344); // distance in miles
				distance = Math.round(distance);
				document.MyForm.Dist.value = distance
				document.getElementById('Distance').innerHTML = 'The estimated driving distance between pickup zip code and port is <b>'+distance+' miles</b>';
			} else {
				document.MyForm.Dist.value = "0"
				document.getElementById('Distance').innerHTML = '2Sorry we where not able to calculate the driving distance automaticly, please enter the driving distance between pickup zip code and port <input name="DistMan" type="text" class="field3" id="DistMan" value="<%= HtmlEscape(DistMan)%>" size="4" />';
			} 

		  });
		  dirn.loadFromWaypoints([start,end],{getSteps:true}); 
		  
		}
		
/*General Function*/
	function TestCountryData(){
		if(document.MyForm.DCountry.value=="225"){
			var r=confirm("You are currently on the international shipment page\n\rDo you wand to change it to a domestic shipment?");
			if (r==true) {
				document.MyForm.Act.value='';
				document.MyForm.action='/services/index_dom.asp' 
				document.MyForm.submit();
			}else{
				document.MyForm.DCountry.value=0;
			}
		}
	}
	
	function TestCustomCountryData(){
		if(document.MyForm.DCountry.value=="225"){
			var r=confirm("You are currently on the international quote page\n\rDo you wand to change it to a domestic quote?");
			if (r==true) {
				document.MyForm.Act.value='';
				document.MyForm.action='/services/custom_dom.asp' 
				document.MyForm.submit();
			}else{
				document.MyForm.DCountry.value=0;
			}
		}
	}
	
	function JumpToDomestic(){
		document.MyForm.Act.value='';
		document.MyForm.action='/services/index_dom.asp' 
		document.MyForm.submit();
	}

/*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Copy data between forms
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/
function copyover(objname,objType){
	if(objname.name=="OLocation"){	
		if(objname.value=="Business without dock"||objname.value=="Residence"){
			slidedown('OCPick');
		}else{
			slideup('OCPick');
		}
	}
}




