var puLat,puLng,drLat,drLng,tblvclfcs,bi,theprice;
var waypoints = new Array();
puLat=0;
drLat=0;
puLng=0;
drLng=0;
tblvclfcs=0;
bi=135;
theprice=0;

function odClick(ctrl,odt,odtdesc) {
var tbladr,tdctrl,tdcomment,tdinstruct,inputname,inputid,tblodq,searchtxt,btntxt;

//alert(ctrl + "," + odt + "," + odtdesc);

toggleTblprice (0);

	if (ctrl==1) {
	 tdctrl="tdorigctrl";
	 tblctrl="tblorigctrl";
	 tbladr="tblorigadr";
	 tdcomment="origComment";
	 tdinstruct="origInstruct";
	 tblodq="tblorigQ";
	 hidODType="hidOrigType";
	 tdadr="origAdrTxtPc"
	 ctrlhidAdrTxt="hidOrigAdress";
	 tblList="tbladlist";
	}
	else {
	 tdctrl="tddestctrl";
	 tblctrl="tbldestctrl";
	 tbladr="tbldestadr";
	 tdcomment="destComment";
	 tdinstruct="destInstruct";
	 tblodq="tbldestQ";
	 hidODType="hidDestType";
	 tdadr="destAdrTxtPc"
	 ctrlhidAdrTxt="hidDestAdress";
	 tblList="tbladlistDest";
	}
	
	 
	 dom = findDOM(tblodq,1);
	 dom.display='none';
	
	 
	 //dom = findDOM(tdadr,1);
	 //dom.innerHTML="";
	 
	 document.getElementById(tdadr).innerHTML="";
	 document.getElementById(ctrlhidAdrTxt).value="";
	 
	 document.getElementById(hidODType).value=odt;

	if (odt==-1) {
		var tdcontent
		
		//tdcontent="<input type='text' name='txtFrom' id='txtFrom' size='25'> <input type='button' value='Search' onClick=\"getFullAddress(document.frmBooking.txtFrom,'txtFrom',0)\">"		
		document.getElementById("txtOrigPostcode").display="none";
		document.getElementById("btnTxtFrom").display="inline";
		document.getElementById("txtFrom").display="inline";
		document.getElementById(tdcomment).innerHTML = "<b>Please enter the street name and/or any part of postcode and click submit.</b>";

		dom = findDOM(tblctrl,1);
		dom.display='none';
		
		dom = findDOM(tbladr,1);
		dom.display='inline';
		//onClick="getFullAddress(this.form.txtFrom,'txtFrom',0)"
		
		if (ctrl==1) {
		//alert("posa " + ctrl);
		//dom = findDOM("rdDstType1",1);
		//dom = document.getElementById("rdDstType1")
		//dom.display='inline';
		dom = findDOM("rdDstType15",1);
		dom.display='inline';
		dom = findDOM("rdDstType16",1);
		dom.display='inline';
		dom = findDOM("rdDstType3",1);
		dom.display='inline';
		dom = findDOM("rdDstType-1",1);
		dom.display='inline';
		}
		else {
		//alert("posa else");
		//dom = findDOM("rdOrgType1",1);
		//dom = document.getElementById("rdOrgType1")
		//dom.display='inline';
		dom = findDOM("rdOrgType15",1);
		dom.display='inline';
		dom = findDOM("rdOrgType16",1);
		dom.display='inline';
		dom = findDOM("rdOrgType3",1);
		dom.display='inline';
		dom = findDOM("rdOrgType-1",1);
		dom.display='inline';
		}
		
	}

	else if (odt==3) {
		
		    	dom = findDOM(tblctrl,1);
			if (dom.display=='none') {
			dom.display='inline';
		
			dom = findDOM(tbladr,1);
			dom.display='none';
			
			dom = findDOM(tblList,1);
			dom.display='none';
			}
		
			if (ctrl==1) {
			inputname="txtOrigPostcode";
			inputid="txtOrigPostcode";
			btntxt="btnTxtFrom";
			searchtxt="txtFrom";
			}
			else {
			inputname="txtDestPostcode";
			inputid="txtDestPostcode";
			btntxt="btnTxtDestination";
			searchtxt="txtDestination";
			}
			
		document.getElementById(tdctrl).innerHTML = "<input type='text' name='" + inputname + "' id='" + inputid + "' onblur='getAddressPC(" + ctrl + ")'>";
		document.getElementById(inputname).display="inline";
		document.getElementById(btntxt).display="none";
		document.getElementById(searchtxt).display="none";
		document.getElementById(tdcomment).innerHTML = "Please enter the full postcode including spaces.<br>Examples; (SW1 9SJ) (N1 9PU).";
		document.getElementById(tdinstruct).innerHTML = "<b>Enter Postcode</b>";
	
	
		if (ctrl==1) {
		//alert(ctrl);
		//dom = findDOM("rdDstType1",1);
		//dom=document.getElementById("rdDstType1")
		//dom.display='inline';
		dom = findDOM("rdDstType15",1);
		dom.display='inline';
		dom = findDOM("rdDstType16",1);
		dom.display='inline';
		dom = findDOM("rdDstType3",1);
		dom.display='inline';
		dom = findDOM("rdDstType-1",1);
		dom.display='inline';
		}
		else {
		//alert(ctrl);
		//dom = findDOM("rdOrgType1",1);
		//dom=document.getElementById("rdOrgType1")
		//dom.display='inline';
		dom = findDOM("rdOrgType15",1);
		dom.display='inline';
		dom = findDOM("rdOrgType16",1);
		dom.display='inline';
		dom = findDOM("rdOrgType3",1);
		dom.display='inline';
		dom = findDOM("rdOrgType-1",1);
		dom.display='inline';
		}
		
	}
	else {

		dom = findDOM(tblctrl,1);
		//alert(dom.display);
	
			if (dom.display=='none') {
			dom.display='inline';
			
			dom = findDOM(tbladr,1);
			dom.display='none';
			
			dom = findDOM(tblList,1);
			dom.display='none';
			}
			
		if (ctrl==1) {
		inputname="origList";
		inputid="origList";
			
			//if (odt==1) { 
				//dom = findDOM("rdDstType1",1);
				//dom.display='none';
				//dom = findDOM("rdDstType15",1);
				//dom.display='none';
				//dom = findDOM("rdDstType16",1);
				//dom.display='none';
				//dom = findDOM("rdDstType3",1);
				//dom.display='none';
				//dom = findDOM("rdDstType-1",1);
				//dom.display='none';
			//}
			//else {
				//dom = findDOM("rdDstType1",1);
				//dom.display='inline';
				//dom = findDOM("rdDstType15",1);
				//dom.display='inline';
				//dom = findDOM("rdDstType16",1);
				//dom.display='inline';
				//dom = findDOM("rdDstType3",1);
				//dom.display='inline';
				//dom = findDOM("rdDstType-1",1);
				//dom.display='inline';
				//alert(odt);
			//}
			
		}
		else {
		inputname="destList";
		inputid="destList";
		
			//if (odt==1) { 
				//dom = findDOM("rdOrgType1",1);
				//dom.display='none';
				//dom = findDOM("rdOrgType15",1);
				//dom.display='none';
				//dom = findDOM("rdOrgType16",1);
				//dom.display='none';
				//dom = findDOM("rdOrgType3",1);
				//dom.display='none';
				//dom = findDOM("rdOrgType-1",1);
				//dom.display='none';
			//}
		//	else {
				//dom = findDOM("rdOrgType1",1);
				//dom.display='inline';
				//dom = findDOM("rdOrgType15",1);
				//dom.display='inline';
				//dom = findDOM("rdOrgType16",1);
				//dom.display='inline';
				//dom = findDOM("rdOrgType3",1);
				//dom.display='inline';
				//dom = findDOM("rdOrgType-1",1);
				//dom.display='inline';
			//}
		}
		
		if (odt==-5) {
		document.getElementById(tdctrl).innerHTML = "<select id='" + inputid + "' name='" + inputname + "' style='width:180px; font-size:11px;' onchange='gtAdBk(" + ctrl +")'><option value='-1'></option></select>";
		pplAdBk(ctrl,odt,odtdesc);
		}
		else {
		document.getElementById(tdctrl).innerHTML = "<select id='" + inputid + "' name='" + inputname + "' style='width:180px; font-size:11px;' onchange='getPostcode(" + ctrl +")'><option value='-1'></option></select>";
		populateCtrl(ctrl,odt,odtdesc);
		}
	}
}



function populateCtrl(ctrl,odt,odtdesc) {

 var odidnodes,oddescnodes,odpostcodenodes,odlocnodes,odid,oddesc,odpostcode,i,odcomment,odinstruct,odslc
 
if (ctrl==1) {
document.getElementById("origComment").innerHTML="<img src='images/status_progress.gif'>";
}
else if (ctrl==2){
document.getElementById("destComment").innerHTML="<img src='images/status_progress.gif'>";
}
 
 strUrl = "xmlGetOdList.asp?bi=" + bi + "&odt=" + odt;
        
        myRand = parseInt(Math.random()*99999999999999);
        strUrl = strUrl +"&mr="+myRand;
        // Mozilla/Safari
       //alert(strUrl);
        
        if (window.XMLHttpRequest) {
               	try {
					xmlHttpReq = new XMLHttpRequest();
					xmlHttpReq.overrideMimeType('text/xml');
				    }
				catch(err1)
				    {
				    	try {
				    	    xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
				    	    }
				    	catch(err2) {
				    	    xmlHttpReq = new ActiveXObject("Msml2.XMLHTTP");
				    	    }
		    }
        }
        // IE
        else if (window.ActiveXObject) {
                xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
	
		
		xmlHttpReq.open('GET', strUrl, true);
       
        xmlHttpReq.onreadystatechange = function() {
			if (xmlHttpReq.readyState == 4) {
			
			
				if (xmlHttpReq.status == 200) {
				
				//alert(ctrl);
				
				if (ctrl==1) {
				//document.frmBooking.origList.options.length=0
				document.getElementById("origList").options.length=0
				odcomment="origComment"
				odinstruct="origInstruct"
				//odslc=document.frmOrig.origList
				}
				else if (ctrl==2){
				//document.frmBooking.destList.options.length=0
				document.getElementById("destList").options.length=0
				odcomment="destComment"
				odinstruct="destInstruct"
				//odslc=document.frmDest.destList
				}
						
				odlocnodes = xmlHttpReq.responseXML.getElementsByTagName("odloc");
				odidnodes = xmlHttpReq.responseXML.getElementsByTagName("odid");
				oddescnodes = xmlHttpReq.responseXML.getElementsByTagName("oddesc");
				odpostcodenodes = xmlHttpReq.responseXML.getElementsByTagName("odpostcode");
		
					
					if (ctrl==1) {
						document.getElementById("origList").options[0]=new Option("Please select",0, false, false);
						}
					else if (ctrl==2) {
						document.getElementById("destList").options[0]=new Option("Please select",0, false, false);
					}
					
					
		
		
					for(i=0;i<odlocnodes.length;i++) {
					odid = odidnodes[i].childNodes[0].nodeValue;
					oddesc = oddescnodes[i].childNodes[0].nodeValue;
					odpostcode=odpostcodenodes[i].childNodes[0].nodeValue;
					if (odt==15) {
					oddesc=oddesc + " - " + odpostcode;
					}
				    
						if (ctrl==1) {
						//document.frmBooking.origList.options[i]=new Option(oddesc, odid, false, false)
						document.getElementById("origList").options[i+1]=new Option(oddesc, odid, false, false)
						}
						else if (ctrl==2) {
						//document.frmBooking.destList.options[i]=new Option(oddesc, odid, false, false)
						document.getElementById("destList").options[i+1]=new Option(oddesc, odid, false, false)
						}
						
					}
					
				document.getElementById(odcomment).innerHTML = "Please select the " + odtdesc + " from the list below. If your " + odtdesc + " is not on the list, click on postcode and enter the full postcode of the " +  odtdesc + ".";
				document.getElementById(odinstruct).innerHTML = odtdesc;
						
				}
				
			}
		}
        xmlHttpReq.send(null);
}




function getFullAddress(ctrlFrom,ctrlTxt,myid) {
        var xmlHttpReq;
        var strUrl,results,freetext,rst,cnt;
        var organ,line1,line2,line3,line4,town,county,postcode,pcode;
        var organ_nd,line1_nd,line2_nd,line3_nd,line4_nd,town_nd,county_nd,postcode_nd;
        var adid,addesc,adlist,ctrlHidPostcode,ctrlAdid,ctrlAdrTxt,tblList;
        var lblBno,ctrlBno,strt,searchbox,adoid,addid,adcombid,adcombidval;
        var adoid_nd,addid_nd,trip,ctrlhidAdrTxt,ctrlHidPc;
        
        document.frmBooking.hidDistance.value=0;
        
        toggleTblprice (0);
        
        
       // ctrlHidPostcode=document.frmBooking.hidFromPc;
       // ctrlAdid=document.forms.frmBooking.hidFromAdid;
        	lblBno = "lblBnoFrom";
		ctrlBno = "txtBnoFrom";
		strt = "ftfhid";
		searchbox="ftf";
		ctrladoid="hidadoidFrom";
		ctrladdid="hidaddidFrom";
		ctrlAdrTxt="origAdrTxt";
		tblList="tbladlist";
		ctrlhidAdrTxt="hidOrigAdress";
		slcctrl=document.frmBooking.slcAdrec;
		ctrlHidPc="hidOrigPc";
		trip="F";

        if (ctrlTxt == "txtDestination"){
        	trip="T";
		ctrlTxt="txtDestination";
		//ctrlHidPostcode=document.frmBooking.hidToPc;
		//ctrlAdid=document.forms.frmBooking.hidToAdid;
		lblBno = "lblBnoTo";
		ctrlBno = "txtBnoTo";
		strt = "ftthid";
		searchbox="ftt";
		ctrladoid="hidadoidTo";
		ctrladdid="hidaddidTo";
		ctrlAdrTxt="destAdrTxt";
		tblList="tbladlistDest";
		slcctrl=document.frmBooking.slcAdrecDest;
		}
		
	if (ctrlTxt == "txtVia"){
		trip="V";
		//ctrlTxt="txtDestination";
		//ctrlHidPostcode=document.frmBooking.hidToPc;
		//ctrlAdid=document.forms.frmBooking.hidToAdid;
		lblBno = "lblBnoVia";
		ctrlBno = "txtBnoVia";
		strt = "ftvhid";
		searchbox="ftv";
		ctrladoid="hidadoidVia";
		ctrladdid="hidaddidVia";
		ctrlAdrTxt="ViaAdrTxt";
		tblList="tbladlistVia";
		slcctrl=document.frmBooking.slcAdrecVia;
		}
 
		//alert(ctrlFrom.value);
 
		if (myid==0) {
		  freetext=ctrlFrom.value;
		  adid="0";
		  adoid="0";
		  addid="0";
		}
		else {
		  adlist = slcctrl;
		  adcombidval = adlist.options[adlist.selectedIndex].value;
		  freetext = adlist.options[adlist.selectedIndex].text; 
		
		  adcombid = adcombidval.split("|");
		  adid = adcombid[0];
		  adoid = adcombid[1];
		  addid = adcombid[2];
		}
        
        
        strUrl = "getaddressPC.asp?adid=" + adid + "&adoid=" + adoid + "&addid=" + addid + "&ft=" + freetext
        myRand = parseInt(Math.random()*99999999999999);
        strUrl = strUrl +"&mr="+myRand;

		//alert(strUrl);

        if (window.XMLHttpRequest) {
        	
        	try {
			xmlHttpReq = new XMLHttpRequest();
			xmlHttpReq.overrideMimeType('text/xml');
		    }
			catch(err1)
		    {
		    	try {
		    	    xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
		    	    }
		    	catch(err2) {
		    	    xmlHttpReq = new ActiveXObject("Msml2.XMLHTTP");
		    	    }
		    }
                
        }
        // IE
        else if (window.ActiveXObject) {
                xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
		
		
		xmlHttpReq.open('GET', strUrl, true);
		       
		        xmlHttpReq.onreadystatechange = function() {
					if (xmlHttpReq.readyState == 4) {
					
						if (xmlHttpReq.status == 200) {
						
						rst = xmlHttpReq.responseXML.getElementsByTagName("rst")[0].childNodes[0].nodeValue;
						
							if (rst == 1) {
						
							organ_nd = xmlHttpReq.responseXML.getElementsByTagName("organ")[0];
							line1_nd = xmlHttpReq.responseXML.getElementsByTagName("line1")[0];
							line2_nd = xmlHttpReq.responseXML.getElementsByTagName("line2")[0];
							line3_nd = xmlHttpReq.responseXML.getElementsByTagName("line3")[0];
							line4_nd = xmlHttpReq.responseXML.getElementsByTagName("line4")[0];
							town_nd = xmlHttpReq.responseXML.getElementsByTagName("town")[0];
							county_nd = xmlHttpReq.responseXML.getElementsByTagName("county")[0];
							postcode_nd = xmlHttpReq.responseXML.getElementsByTagName("postcode")[0];
							adoid_nd = xmlHttpReq.responseXML.getElementsByTagName("adoid")[0];
							addid_nd = xmlHttpReq.responseXML.getElementsByTagName("addid")[0];
							//alert("rst" + rst);
					
		
							if (organ_nd.childNodes[0]){organ=organ_nd.childNodes[0].nodeValue;}else{organ="";}
							if (line1_nd.childNodes[0]){line1=line1_nd.childNodes[0].nodeValue;}else{line1="";}
							if (line2_nd.childNodes[0]){line2=line2_nd.childNodes[0].nodeValue;}else{line2="";}
							if (line3_nd.childNodes[0]){line3=line3_nd.childNodes[0].nodeValue;}else{line3="";}
							if (line4_nd.childNodes[0]){line4=line4_nd.childNodes[0].nodeValue;}else{line4="";}
							if (town_nd.childNodes[0]){town=town_nd.childNodes[0].nodeValue;}else{town="";}
							if (county_nd.childNodes[0]){county=county_nd.childNodes[0].nodeValue;}else{county="";}
							if (postcode_nd.childNodes[0]){postcode=postcode_nd.childNodes[0].nodeValue;}else{postcode="";}
							if (adoid_nd.childNodes[0]){adoid=adoid_nd.childNodes[0].nodeValue;}else{adoid=0;}
							if (addid_nd.childNodes[0]){addid=addid_nd.childNodes[0].nodeValue;}else{addid=0;}
							
							//alert(line1);
							
							cnt=""
							if (organ != ""){cnt=organ + ", ";}
							if (line1 != ""){cnt=cnt + line1 + ", ";}
							if (line2 != ""){cnt=cnt + line2 + ", ";}
							if (line3 != ""){cnt=cnt + line3 + ", ";}
							if (line4 != ""){cnt=cnt + line4 + ", ";}
							if (town != ""){cnt=cnt + town + ", ";}
							if (county != ""){cnt=cnt + county + ", ";}
							if (postcode != "") {
							pcode = postcode.substring(0,(postcode.indexOf(" ")))
							}
							else{
							pcode="0"
							}
							
							
							
								if (trip == "T") {
								ctrlTxt="txtDestination";
								//ctrlHidPostcode=document.frmBooking.hidToPc;
								//ctrlAdid=document.forms.frmBooking.hidToAdid;
								lblBno = "lblBnoTo";
								ctrlBno = "txtBnoTo";
								strt = "ftthid";
								searchbox="ftt";
								ctrladoid="hidadoidTo";
								ctrladdid="hidaddidTo";
								ctrlAdrTxt="destAdrTxt";
								tblList="tbladlistDest";
								ctrlhidAdrTxt="hidDestAdress";
								slcctrl=document.frmBooking.slcAdrecDest;
								ctrlHidPc="hidDestPc";
								}
							
							
								if (trip == "V") {
								ctrlTxt="txtVia";
								lblBno = "lblBnoVia";
								ctrlBno = "txtBnoVia";
								strt = "ftvhid";
								searchbox="ftv";
								ctrladoid="hidadoidVia";
								ctrladdid="hidaddidVia";
								ctrlAdrTxt="ViaAdrTxt";
								tblList="tbladlistVia";
								ctrlhidAdrTxt="hidViaAdress";
								slcctrl=document.frmBooking.slcAdrecVia;
								
								var tblViaList,newRow,newCell,viaLinkRemove,vn;
									tblViaList=document.getElementById("tblviaList");
									vn=tblViaList.rows.length - 3;
									newRow=tblViaList.insertRow(tblViaList.rows.length);
									newCell = newRow.insertCell(0);
									newCell.innerHTML = vn+1;
									newCell.className="txt4";
									newCell = newRow.insertCell(1);
									newCell.innerHTML = cnt;
									newCell.className="txt4";
									newCell = newRow.insertCell(2);
									newCell.innerHTML = '<a href="javascript:removeVia(' + vn + ');">Remove</a>';
									newCell.className="link1";									
								}
							

								if (trip == "T" || trip == "F") {
								  ////ctrlHidPostcode.value=postcode;
								  ////ctrlAdid.value=adid;
								  document.getElementById(ctrlTxt).value=postcode;
								  document.getElementById(ctrlHidPc).value=postcode;
								  document.getElementById(ctrlAdrTxt).innerHTML=cnt;
								  document.getElementById(ctrlhidAdrTxt).value=cnt;
		
								  ////document.getElementById(ctrladoid).value=adoid;
								  ////document.getElementById(ctrladdid).value=addid;
								}
								else {
								  document.getElementById(ctrlTxt).value=postcode;
								  document.getElementById(ctrlhidAdrTxt).value=cnt;
								}
								
						
							
							dom = findDOM(tblList,1);
							dom.display='none';
							
							//alert("end " + pcode);
		

							//alert(trip);
								if (trip=="F") {
								getPostcodeLatLong(postcode,1);
								}
		
								else if (trip=="T")  {
								getPostcodeLatLong(postcode,2);
								}
		
								else {
								getPostcodeLatLong(postcode,3);
								}
							

						
							}
							
							else if (rst==2) {
							
							//alert(slcctrl);
							
							
							dom = findDOM(tblList,1);
							//dom.visibility='visible';
							dom.display='inline';
							
								
								if (trip=="T") {
								document.frmBooking.slcAdrecDest.options.length=0;
								}
								else if (trip=="F") {
								document.frmBooking.slcAdrec.options.length=0;
								}
								else {
								document.frmBooking.slcAdrecVia.options.length=0;
								}								
							
							//alert(slcctrl);
							
							var adidnodes,i,newad,slcctrl,adoidnodes,addidnodes;
							
							adidnodes = xmlHttpReq.responseXML.getElementsByTagName("adid");
							addescnodes = xmlHttpReq.responseXML.getElementsByTagName("addesc");
							adoidnodes = xmlHttpReq.responseXML.getElementsByTagName("adoid");
							addidnodes = xmlHttpReq.responseXML.getElementsByTagName("addid");
							
		
								for(i=0;i<adidnodes.length;i++)
								{
								adid = adidnodes[i].childNodes[0].nodeValue;
								addesc = addescnodes[i].childNodes[0].nodeValue;
								adoid=adoidnodes[i].childNodes[0].nodeValue;
								addid=addidnodes[i].childNodes[0].nodeValue;
								
								adcombid=adid + "|" + adoid + "|" + addid;
								
								newad=new Option(addesc,adcombid,false,false)
		
									if (trip=="T") {
									document.frmBooking.slcAdrecDest.options[document.frmBooking.slcAdrecDest.options.length]=newad;
									}
									else if (trip=="F") {
									document.frmBooking.slcAdrec.options[document.frmBooking.slcAdrec.options.length]=newad;
									}
									else {
									document.frmBooking.slcAdrecVia.options[document.frmBooking.slcAdrecVia.options.length]=newad;
									}
								
								}							
							
							
								
							}
								
							else {
							document.getElementById(ctrlTxt).value="Not Found";
							}
						} // if 200
					} // if 4
				}  // function
        xmlHttpReq.send(null);
		
		
		
//window.setTimeout('enableQt()',2000);
}



function removeVia(vn) {
//alert("test");

toggleTblprice (0);

var tblViaList,rn,i,viaCells;

waypoints.splice(vn,1);

tblViaList=document.getElementById("tblviaList");
tblViaList.deleteRow(vn+3);

rn=tblViaList.rows.length

//alert("rn is " + rn);

if (rn>3) {
for(var i=1;i<rn-2;i++) {
//alert("i is " + i + " , rn is " + (rn-2));
//viaCells=document.getElementById("tblviaList").rows[i+2].cells;
viaCells=tblViaList.rows[i+2].cells
viaCells[0].innerText=i;
viaCells[2].innerHTML = '<a href="javascript:removeVia(' + (i-1) + ');">Remove</a>';
}
}


assignLatLng(0,0,3);

}



function showVehicle(vid,pid) {

if (vid>0) {

var strUrl,myRand,tdcontent;
var cardtl,results,vid,vdesc,pgrs,scase,bcase,vimg;

 strUrl = "xmlGetVehicle.asp?bi=" + bi + "&vi=" + vid + "&pi=" + pid;
        
        myRand = parseInt(Math.random()*99999999999999);
        strUrl = strUrl +"&mr="+myRand;
        // Mozilla/Safari
       //alert(strUrl);
        
        if (window.XMLHttpRequest) {
               	try {
					xmlHttpReq = new XMLHttpRequest();
					xmlHttpReq.overrideMimeType('text/xml');
				    }
				catch(err1)
				    {
				    	try {
				    	    xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
				    	    }
				    	catch(err2) {
				    	    xmlHttpReq = new ActiveXObject("Msml2.XMLHTTP");
				    	    }
		    }
        }
        // IE
        else if (window.ActiveXObject) {
                xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
	
		
		xmlHttpReq.open('GET', strUrl, true);
       
        xmlHttpReq.onreadystatechange = function() {
			if (xmlHttpReq.readyState == 4) {
			
			
				if (xmlHttpReq.status == 200) {
				
				tdcontent = xmlHttpReq.responseText;
				
				document.getElementById('tdVclDetails').innerHTML = tdcontent;
				dom = findDOM('imgapmsg',1);
				dom.display='inline';
						
				}
				
			}
		}
        xmlHttpReq.send(null);
}
else if (vid==0) {
document.getElementById('tdVclDetails').innerHTML = "";
}
else {
}

if (vid==0) {
showVehicleStatic(pid);
}

}




function showVehicleStatic(pid) {

//alert("hi");
//document.frmBooking.rdVclType

var vid,frmbook;

frmbook = document.getElementById('frmBooking');

 for (var i = 0; i < frmbook.length; i++){
 //alert("hi");
		if (frmbook.rdVclType[i].checked){
		vi=frmbook.rdVclType[i].value;
		//alert(document.frmBooking.rdVclType[i].value);
		break;
		}
		else {
		vi=0;
		}
	}

//alert(vi);
vid=vi;

if (vid>0) {

var strUrl,myRand,tdcontent;
var cardtl,results,vid,vdesc,pgrs,scase,bcase,vimg;

 strUrl = "xmlGetVehicle.asp?bi=" + bi + "&vi=" + vid + "&pi=" + pid ;
        
        myRand = parseInt(Math.random()*99999999999999);
        strUrl = strUrl +"&mr="+myRand;
        // Mozilla/Safari
      // alert(strUrl);
        
        if (window.XMLHttpRequest) {
               	try {
					xmlHttpReq = new XMLHttpRequest();
					xmlHttpReq.overrideMimeType('text/xml');
				    }
				catch(err1)
				    {
				    	try {
				    	    xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
				    	    }
				    	catch(err2) {
				    	    xmlHttpReq = new ActiveXObject("Msml2.XMLHTTP");
				    	    }
		    }
        }
        // IE
        else if (window.ActiveXObject) {
                xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
	
		
		xmlHttpReq.open('GET', strUrl, true);
       
        xmlHttpReq.onreadystatechange = function() {
			if (xmlHttpReq.readyState == 4) {
			
			
				if (xmlHttpReq.status == 200) {
				
				tdcontent = xmlHttpReq.responseText;
				
				document.getElementById('tdVclDetails').innerHTML = tdcontent;
				dom = findDOM('imgapmsg',1);
				dom.display='inline';
						
				}
				
			}
		}
        xmlHttpReq.send(null);
}
else if (vid==0) {
document.getElementById('tdVclDetails').innerHTML = "";
}
else {
}



}


function showGT(showyn) {
//var showyn

//alert (document.getElementById('rdVclType-1').checked);
//showyn=document.getElementById('rdVclType').value;
//alert (document.frmBooking.action);

	if (showyn == 0) {
	dom = findDOM('tblgt',1);
	dom.display='none';
	
	dom = findDOM('btnQuote',1);
	dom.display='inline';
					
	dom = findDOM('btnQuery',1);
	dom.display='none';
	
	document.frmBooking.action="bookd2.asp";
	}
	else {
		if (document.getElementById('rdVclType-1').checked) {
		//alert("true");
		dom = findDOM('tblgt',1);
		dom.display='inline';
		
		dom = findDOM('btnQuote',1);
		dom.display='none';
		
		dom = findDOM('btnQuery',1);
		dom.display='inline';
		
		document.frmBooking.action="bookquery.asp";
		
		//alert(document.getElementById('btnQuery').visibility);
		//document.getElementById('btnQuery').visibility="visible";
		//document.getElementById('btnQuote').visibility="hidden";
		}
		else {
		dom = findDOM('tblgt',1);
		dom.display='none';
			
		dom = findDOM('btnQuery',1);
		dom.display='none';
		
		dom = findDOM('btnQuote',1);
		dom.display='inline';
		
		document.frmBooking.action="bookd2.asp";
		
		//document.getElementById('btnQuery').visibility="hidden";
		//document.getElementById('btnQuote').visibility="visible";
		}
	}
}




function showVia() {

//alert (document.getElementById('chkVia').checked);
//showyn=document.getElementById('rdVclType').value;

toggleTblprice (0);

if (document.getElementById('chkVia').checked) {
dom = findDOM('tblvia',1);
		dom.display='inline';
		}
		else {
		dom = findDOM('tblvia',1);
		dom.display='none';
		}
}


function regvchk () {
	if (tblvclfcs==0) {
	//alert("hi");
	document.getElementById("tdVclDetails").innerHTML = "";
	}
setTimeout("regvchk()",1000);
}



function getPrice() {

 var xmlHttpReq,strUrl,results,carDtl,pgrs,fare,farertn,fare2nd;
 var carnm,bi,vi,oi,di,ctrlFrom,bp,opostcode,dpostcode,d,frmbook;
 var adoidFrom,addidFrom,adoidTo,addidTo;
 var odt,ctrl,dAdr,oAdr,rdbt,cs,strVia,cscost,bdate;  
        
        document.getElementById('txtPrice').innerHTML = " ";
        
        strVia=document.getElementById('txaVia').value;
        
        //d=0;
        //alert("before " + d)
        
        
        bi=document.frmBooking.hidb.value;
        hot=document.frmBooking.hidOrigType.value;
	//alert(hot);

        hdt=document.frmBooking.hidDestType.value;
        //alert(hdt);
        //opostcode=document.frmBooking.hidPostcodeFrom.value;
        //dpostcode=document.frmBooking.hidPostcodeTo.value;
        d=document.frmBooking.hidDistance.value;
        //alert(vi);
        bdate = document.getElementById("hidDate").value;
        
        //alert("after " + d)
        //adoidFrom=document.frm_booking.hidadoidFrom.value;
        //addidFrom=document.frm_booking.hidaddidFrom.value;
        //adoidTo=document.frm_booking.hidadoidTo.value;
        //addidTo=document.frm_booking.hidaddidTo.value;
         //alert(document.frmBooking.rdVclType.value);
        
        frmbook=document.getElementById('frmBooking')
        
        for (var i = 0; i < frmbook.rdVclType.length; i++){
		if (frmbook.rdVclType[i].checked){
		vi=frmbook.rdVclType[i].value;
		//alert(document.frmBooking.rdVclType[i].value);
		break;
		}
		else {
		vi=0;
		}
	}
	
	//alert(vi);
	if (vi==0) {
	alert('Please select a vehicle type');
	}
		
	 for (var i = 0; i < frmbook.rdbt.length; i++){
		   if (frmbook.rdbt[i].checked){
			rdbt=frmbook.rdbt[i].value;
			//break;
			//alert(rdbt);
		   }
	}
		
	cs = frmbook.slcCs.value;
		
		//alert(hot);
		//alert(document.frmBooking.txtFrom.value);
        //alert(document.tblfrmbooking.tblorigctrl.origAdrTxt.value);
       //alert(document.getElementById('origAdrTxt').innerHTML);
        
        if (hot==-1) {
        opostcode = frmbook.txtFrom.value;
        oAdr=document.getElementById('origAdrTxt').innerHTML;
      //alert(rdbt);
       // oi=0;
        }
        else {
        opostcode ="0";
        }
        
        if (hot==3) {
        //opostcode = document.frmBooking.txtOrigPostcode.value;
        opostcode = document.getElementById("txtOrigPostcode").value;
        //alert("got " + opostcode + " and " + hot);
       // oi=0;
        }
        else {
		if (hot!=-1) {opostcode ="0";}
	    }
        
        if (hot!=-1 && hot!=3 && hot!=-5) {
        //ctrl = document.forms.frmBooking.origList;
        //ctrl = document.frmBooking.origList;
        ctrl = document.getElementById("origList");
        oi = ctrl.options[ctrl.selectedIndex].value;
        //opostcode="0"; 
        opostcode=document.getElementById("hidOrigPc").value;
        }
        else if (hot==-5) {
	oi =document.getElementById("hidorigList").value;
	opostcode=document.getElementById("hidOrigPc").value;
        }
        else {
        oi=0;
        }
        
        
        if (strVia != "") {
        opostcode = document.getElementById('hidOrigPc').value;
        oi=0;
        }
        
        
        //alert(opostcode);
        
        if (hdt==-1) {
        dpostcode = frmbook.txtDestination.value;
       // dAdr=document.frmBooking.destAdrTxt.value;
       // di=0;
        }
        else {
        dpostcode="0";
        }
        
        if (hdt==3) {
        //dpostcode = document.frmBooking.txtDestPostcode.value;
        dpostcode = document.getElementById("txtDestPostcode").value
        //di=0;
        }
        else {
		if (hdt!=-1) {dpostcode ="0";}
        }
        
        if (hdt!=-1 && hdt!=3 && hdt!=-5) {
        //ctrl = document.frmBooking.destList;
        ctrl = document.getElementById("destList");
        di = ctrl.options[ctrl.selectedIndex].value;
        //dpostcode="0";
        dpostcode=document.getElementById("hidDestPc").value;
        }
        else if (hdt==-5) {
	di =document.getElementById("hiddestList").value;
	dpostcode=document.getElementById("hidDestPc").value;
        }
        else {
        di=0;
        }
        //alert(di);
        
	if (strVia != "") {
	dpostcode = document.getElementById('hidDestPc').value;
	di=0;
        }
        
        
        ///////// check ad type
      	//if ((hdt==-1 || hdt==3) && (hot==-1 || hot==3)) {
       //	di=document.getElementById("hidDistance").value;
       	//	if (di>0) {
       	//	getPriceDist(di);
       	//	}
       // }
        
       // else {

        strUrl = "xmlGetPrice.asp?bi=" + bi + "&vi=" + vi + "&op=" + opostcode + "&dp=" + dpostcode + "&oi=" + oi + "&di=" + di + "&bt=" + rdbt + "&cs=" + cs  + "&d=" + d + "&bdt=" + bdate
        //strUrl = strUrl +"&foid=" + adoidFrom + "&fdid=" + addidFrom + "&toid=" + adoidTo + "&tdid=" + addidTo
        
        myRand = parseInt(Math.random()*99999999999999);
        strUrl = strUrl +"&mr="+myRand;
        // Mozilla/Safari
        //alert(strUrl);
        
        if (window.XMLHttpRequest) {
               	try {
					xmlHttpReq = new XMLHttpRequest();
					xmlHttpReq.overrideMimeType('text/xml');
				    }
				catch(err1)
				    {
				    	try {
				    	    xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
				    	    }
				    	catch(err2) {
				    	    xmlHttpReq = new ActiveXObject("Msml2.XMLHTTP");
				    	    }
		    }
        }
        // IE
        else if (window.ActiveXObject) {
                xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
	
		
		xmlHttpReq.open('GET', strUrl, true);
       
        xmlHttpReq.onreadystatechange = function() {
			if (xmlHttpReq.readyState == 4) {
			//alert("4");
			
				if (xmlHttpReq.status == 200) {
				carDtl = xmlHttpReq.responseText;
				
				//alert(carDtl);
				
				results = carDtl.split("|");
				carnm = results[0];
				pgrs = results[1];
				fare = results[2];
				fare2nd = results[3];
				farertn = results[4];
				cscost = results[7];
				
				//alert(waypoints.length*3);
				fare=parseFloat(fare)+parseFloat((waypoints.length*3));
				
				if (rdbt=="R") {
				fare2nd=parseFloat(fare2nd)+parseFloat((waypoints.length*3));
				farertn=parseFloat(farertn)+parseFloat((waypoints.length*6));
				}
				//alert(carnm);
				//alert(pgrs);
				//alert(fare);
				
				fare=parseFloat(fare);
				fare=fare.toFixed(2);
				
				fare2nd=parseFloat(fare2nd);
				fare2nd=fare2nd.toFixed(2);
				
				farertn=parseFloat(farertn);
				farertn=farertn.toFixed(2);
				
				//alert(farertn);
				
				//////document.getElementById('txtVehicle').innerHTML = carnm + " (Max " + pgrs + " passengers)<br>( <a target='Vehicle' width='500' class='link1' href='vehiclepage.asp?vid=" + vi + "'>Check the vehicle</a> )";
				////////document.getElementById('txtPassengers').value = pgrs;
					
					if (fare>-1) {
						
						if (fare==0) { 
						fare = "Call"; 
						}
						
							if (fare2nd==0) {
							document.getElementById('txtPrice').innerHTML = "£"+fare;
							document.getElementById('txtPrice1st').innerHTML = "";
							document.getElementById('lblPrice1st').innerHTML = "";
							document.getElementById('txtPrice2nd').innerHTML = "";
							document.getElementById('lblPrice2nd').innerHTML = "";
							document.getElementById('hidPrice').value = fare;
							theprice=fare;
							bdscnt(1);
							}
							else
							{
							document.getElementById('txtPrice').innerHTML = "£"+farertn;
							document.getElementById('txtPrice1st').innerHTML = "£"+fare;
							document.getElementById('lblPrice1st').innerHTML = "1st Journey";
							document.getElementById('txtPrice2nd').innerHTML = "£"+fare2nd;
							document.getElementById('lblPrice2nd').innerHTML = "2nd Journey";
							document.getElementById('hidPrice').value = farertn;
							theprice=farertn;
							bdscnt(1);
							}
							
							if (cscost>0) {
							document.getElementById('txtChildSeat').innerHTML = "<i>Price includes £"+ cscost +" cost of the child seat/s";
							}
						
						dom = findDOM('tblPrice',1);
						dom.display='inline';
					}
						
					else {
						alert("Unfortunately we are unable to provide an online price for your journey. Please contact us for a favourable quote.")
						//document.frmBooking.hidOrigin.value=0;
						//document.frm_booking.hdPostcodeFrom.value="";
						//document.frm_Journey.ftf.value="";
						//document.frm_Journey.ftt.value="";
					}
					
				}
				
			}
		}
        xmlHttpReq.send(null);
        
       // }
        //////// end check ad type
}


function getAddressPC(ctrl) {
var pc,strUrl,address_nd,address;

//alert("hi");
document.frmBooking.hidDistance.value=0;

//alert(document.frmBooking.hidDistance.value);

toggleTblprice (0);

	if (ctrl==1) {
	//pc=document.frmBooking.txtOrigPostcode.value;
	pc=document.getElementById("txtOrigPostcode").value;
	document.getElementById("hidOrigPc").value=pc;
	ctrlAdrTxt="origAdrTxtPc";
	ctrlhidAdrTxt="hidOrigAdress";
	puLat=0;
	puLng=0;
	}
	else {
	//pc=document.frmBooking.txtDestPostcode.value;
	pc=document.getElementById("txtDestPostcode").value;
	document.getElementById("hidDestPc").value=pc;
	ctrlAdrTxt="destAdrTxtPc";
	ctrlhidAdrTxt="hidDestAdress";
	drLat=0;
	drLng=0;
	}
	
	
	//ctrlAdrTxt="origAdrTxt";
	
	//alert(pc + "-" + ctrl);
	
	
	//alert("I am back");
	
	strUrl = "xmlGetPaf.asp?pc=" + pc;
        
        myRand = parseInt(Math.random()*99999999999999);
        strUrl = strUrl +"&mr="+myRand;
        // Mozilla/Safari
        //alert(strUrl);
        
        if (window.XMLHttpRequest) {
               	try {
					xmlHttpReq = new XMLHttpRequest();
					xmlHttpReq.overrideMimeType('text/xml');
				    }
				catch(err1)
				    {
				    	try {
				    	    xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
				    	    }
				    	catch(err2) {
				    	    xmlHttpReq = new ActiveXObject("Msml2.XMLHTTP");
				    	    }
		    }
        }
        // IE
        else if (window.ActiveXObject) {
                xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
	
		
		xmlHttpReq.open('GET', strUrl, true);
       
        xmlHttpReq.onreadystatechange = function() {
			if (xmlHttpReq.readyState == 4) {
			
				if (xmlHttpReq.status == 200) {
				
				address_nd = xmlHttpReq.responseXML.getElementsByTagName("address")[0];
				postcode_nd = xmlHttpReq.responseXML.getElementsByTagName("postcode")[0];

				if (address_nd.childNodes[0]){address=address_nd.childNodes[0].nodeValue;}else{address="";}
				if (postcode_nd.childNodes[0]){pc=postcode_nd.childNodes[0].nodeValue;}
				
				//alert(address);
				
				document.getElementById(ctrlAdrTxt).innerHTML=address;
				document.getElementById(ctrlhidAdrTxt).value=address;
				
				if (ctrl==1) {
					document.getElementById("txtOrigPostcode").value=pc;
					document.getElementById("hidOrigPc").value=pc;
					}
					else {
					document.getElementById("txtDestPostcode").value=pc;
					document.getElementById("hidDestPc").value=pc;
					}
				
				
				//alert("1f" + document.frmBooking.hidDistance.value);
										
				}
				
			}
		}
        xmlHttpReq.send(null);
        
        getPostcodeLatLong(pc,ctrl);
}


function showLgn(ct) {
	if (ct=="e") {
		bookName = findDOM("tblcustexist",1);
		bookName.display='inline';
		bookName = findDOM("tblcustnew",1);
		bookName.display='none';
		bookName = findDOM("qupgr",1);
		bookName.display='inline';
		}
	else if (ct=="n") {
		bookName = findDOM("tblcustexist",1);
		bookName.display='none';
		bookName = findDOM("tblcustnew",1);
		bookName.display='inline';
		bookName = findDOM("qupgr",1);
		bookName.display='inline';
		}	
}



function showBkPgr(yn) {
var bkPgr;
	if (yn==1) {
		bkPgr = findDOM("tblBkPgrDtl",1);
		bkPgr.display='inline';
		}
	else {
		bkPgr = findDOM("tblBkPgrDtl",1);
		bkPgr.display='none';
		}
}





function getUser(myref) {

        var xmlHttpReq;
        var strUrl,results,us,ps,sn,snval,bi,ad,adval,cnt,phn,phnval,mbl,mblval,em,emval,crda,crdaval;
        //alert("hi");
       
        bi=document.frmBooking.hidb.value;
        us=document.frmBooking.txtUser.value;
        ps=document.frmBooking.txtPass.value;
       
        
        strUrl = "xmlhtgetuser.asp?bi=" + bi + "&us=" + us + "&ps=" + ps
        
        myRand = parseInt(Math.random()*99999999999999);
        strUrl = strUrl +"&mr="+myRand;
        
        //alert(strUrl);
        
        if (window.XMLHttpRequest) {
		try {
			xmlHttpReq = new XMLHttpRequest();
			xmlHttpReq.overrideMimeType('text/xml');
		    }
		catch(err1)
		    {
		    	try {
		    	    xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
		    	    }
		    	catch(err2) {
		    	    xmlHttpReq = new ActiveXObject("Msml2.XMLHTTP");
		    	    }
		    };
        }
        // IE
        else if (window.ActiveXObject) {
                xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
		
		xmlHttpReq.open('GET', strUrl, true);
       
        xmlHttpReq.onreadystatechange = function() {
			if (xmlHttpReq.readyState == 4) {
		
				if (xmlHttpReq.status == 200) {
				sn = xmlHttpReq.responseXML.getElementsByTagName("sname")[0];
				ad = xmlHttpReq.responseXML.getElementsByTagName("adr")[0];
				phn = xmlHttpReq.responseXML.getElementsByTagName("phn")[0];
				mbl = xmlHttpReq.responseXML.getElementsByTagName("mbl")[0];
				em = xmlHttpReq.responseXML.getElementsByTagName("em")[0];
				crda = xmlHttpReq.responseXML.getElementsByTagName("crda")[0];
				
				
			
				snval=sn.childNodes[0].nodeValue;
				adval=ad.childNodes[0].nodeValue;
				phnval=phn.childNodes[0].nodeValue;
				mblval=mbl.childNodes[0].nodeValue;
				emval=em.childNodes[0].nodeValue;
				crdaval=crda.childNodes[0].nodeValue;
				
				crdaval=parseInt(crdaval);
				
				cnt=snval + "<br>" + adval + "<br><br>" + "<b>Tel: </b>" + phnval + "<br><b>Tel: </b>" + mblval + "<br><b>Email: </b>" + emval +"<br><br>"
				
				document.getElementById('txtContact').innerHTML = cnt;
				
				bookName = findDOM("tdBookname",1);
				bookName.display='block';
				
				
				//document.frmBooking.txtBookname.value=snval;
				//document.frmBooking.hidBookname.value="";
				//document.frm_booking.submitbp.visibility='visible';
				
				
				dom = findDOM('submitbp',1);
				dom.visibility='visible';
				
				
				var bn="<b>Booking Name: </b>" + snval
				document.getElementById('tdBookname').innerHTML=bn;
				
				//showLabel('lblContact')
				//alert('005');
				
				if (myref==2) {
				//alert('1');
				//alert(document.getElementById('tblpmin').display);
				//document.getElementById('tblpmin').display='inline';
					if(crdaval>0) {
					dom = findDOM('tblpmin',1);
					dom.display='inline';
					}
				}
				
				}
				else {
				}
			}
		}
        xmlHttpReq.send(null);
}



function getPostcodeLatLong(postcode,pickDrop) {

//alert(postcode);

var strTrip;

localSearch.setSearchCompleteCallback(null,
    function() {

      if (localSearch.results[0]) {
        var resultLat = localSearch.results[0].lat;
        var resultLng = localSearch.results[0].lng;
        var point = new GLatLng(resultLat,resultLng);
        
        //alert(resultLat);

        assignLatLng(resultLat,resultLng,pickDrop);

      }
      else{
        //alert("Postcode not found!");
      }
    });

localSearch.execute(postcode + ", UK");

}



function assignLatLng (lat,lng,pickDrop) {

var strTrip,viaList,strVia;
strVia = "";

//alert(lat);

        	if (pickDrop == "1") {
			puLat=lat;
			puLng=lng;
			//alert(puLat);
			
			///////////////////////////////////////
			
			viaList=document.getElementById("txaVia");
			if (viaList.value == "") {
			  //alert("deleting entries");
			   waypoints.splice(0);
			  // alert(waypoints[0].lat);
			}

			else {
				strTrip="";
				for(var i=0;i<waypoints.length;i++) {
				strVia = strVia + " to " + waypoints[i].lat + "," + waypoints[i].lng;
				}
			}


			if (puLat!=0 && drLat!=0){
			   strTrip = puLat + "," + puLng + strVia + " to " + drLat + "," + drLng
			   getDistance(strTrip);
			}	
			
			///////////////////////////////////////
		}

		else if (pickDrop == "2") {
			drLat=lat;
			drLng=lng;
			//writeGeos("drlat",drLat,"drlng",drLng);
			//strTrip = puLat + "," + puLng + " to " + drLat + "," + drLng
			//getDistance(strTrip);
			
			/////////////////////////////////////
			
			viaList=document.getElementById("txaVia");
			
			//alert(drLat);
				if (viaList.value == "") {
				   //alert("deleting entries");
				   waypoints.splice(0);
				   //alert(waypoints[0].lat);
				}

				else {
					strTrip="";
					for(var i=0;i<waypoints.length;i++) {
					strVia = strVia + " to: " + waypoints[i].lat + "," + waypoints[i].lng;
					}
				}

			if (puLat!=0 && drLat!=0){
			   strTrip = "from: " + puLat + "," + puLng + strVia + " to: " + drLat + "," + drLng
			 //alert("passing " + strTrip);
			   getDistance(strTrip);
			}
			
			
			//////////////////////////////////////	
			
		}

		else if (pickDrop == "3") {
		
				var addVia=0;
				var v1Lat=lat;
				var v1Lng=lng;
				var cnt,viaListVal;
				
				
				cnt=document.getElementById("hidViaAdress").value;
				//alert(cnt);
				
				viaList=document.getElementById("txaVia");
				viaListVal="";
				
				var n,lastLat,lastLng;
				n=waypoints.length;

				   if (v1Lat!=0 && v1Lng!=0) {
				   
				   	waypoints[n]={lat:v1Lat,lng:v1Lng,adr:cnt};
				   }
				   
				n=waypoints.length;

					if (n>0 || v1Lat==0 ) {

					strTrip="";
					strVia = "";
					viaList.value="";

						for(var i=0;i<waypoints.length;i++) {

						strVia = strVia + " to: " + waypoints[i].lat + "," + waypoints[i].lng;
						viaList.value=viaListVal+"|"+waypoints[i].adr ;
						//alert(waypoints[i].adr);
						//viaList.value=waypoints[i].adr + "|";
						viaListVal=viaList.value;
						}

					strTrip = "from: " + puLat + "," + puLng + strVia + " to: " + drLat + "," + drLng

					//alert(strVia);

					//alert(strTrip);

					getDistance(strTrip);
					}
					
					
					//if (n=0) {
					//waypoints.splice(0);
					//viaList.value="";
					//}
			   	   
			   
			   
			   /////////////////////////////////////////////////////////////
	
		}
		
}




function getDistance(strTrip) {

//alert(strTrip);

var totalDistance,totalTime

	if (GBrowserIsCompatible()) {
			map = new GMap2(document.getElementById("map"));
			
			directionsPanel = document.getElementById("dirdiv");
			map.setCenter(new GLatLng(puLat, puLng), 3);
			
			directions = new GDirections(map, directionsPanel);
	
			GEvent.addListener(directions, "load", function(){
			durTime = directions.getDuration();
			tripDistance = directions.getDistance();
			//alert(tripDistance.meters);
			
			document.getElementById("hidDistance").value=tripDistance.meters;
			document.getElementById("hidDuration").value=durTime.seconds;
			
			//alert(document.getElementById("hidDistance").value);
			
			
			});
			directions.load(strTrip);
	}
}




function getPostcode(trip) {

var pc,strUrl,postcode_nd,postcode,ctrl,cid,ctrlhidAdrPc,ctrlhidList,ctrlhidAdr,adr,adr_nd;

toggleTblprice (0);

	if (trip==1) {
	  ctrl = document.getElementById("origList");
          cid = ctrl.options[ctrl.selectedIndex].value;
          //alert(cid);
	  ctrlhidAdrPc="hidOrigPc"
	  ctrlhidList="hidorigList";
	  ctrlhidAdr="hidOrigAdress"
	}
	else {
	  ctrl = document.getElementById("destList");
	  cid = ctrl.options[ctrl.selectedIndex].value;
	  ctrlhidAdrPc="hidDestPc";
	  ctrlhidList="hiddestList";
	  ctrlhidAdr="hidDestAdress"
	}
		
	document.getElementById(ctrlhidList).value=cid;

	
	//ctrlAdrTxt="origAdrTxt";
	
	//alert(pc + "-" + ctrl);
	
	//getPostcodeLatLong(pc,ctrl);
	
	//alert("I am back");
	
	strUrl = "xmlGetPostcode.asp?cid=" + cid;
        
        myRand = parseInt(Math.random()*99999999999999);
        strUrl = strUrl +"&mr="+myRand;
        // Mozilla/Safari
        //alert(strUrl);
        
        if (window.XMLHttpRequest) {
               	try {
			xmlHttpReq = new XMLHttpRequest();
			xmlHttpReq.overrideMimeType('text/xml');
		    }
		catch(err1)
		    {
			try {
			    xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
			    }
			catch(err2) {
			    xmlHttpReq = new ActiveXObject("Msml2.XMLHTTP");
			    }
		    }
        }
        // IE
        else if (window.ActiveXObject) {
                xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
	
		
		xmlHttpReq.open('GET', strUrl, true);
       
        	xmlHttpReq.onreadystatechange = function() {
        	
			if (xmlHttpReq.readyState == 4) {
			
				if (xmlHttpReq.status == 200) {
				
				postcode_nd = xmlHttpReq.responseXML.getElementsByTagName("postcode")[0];
				adr_nd = xmlHttpReq.responseXML.getElementsByTagName("adr")[0];

				if (postcode_nd.childNodes[0]){pc=postcode_nd.childNodes[0].nodeValue;}else{pc="";}
				if (adr_nd.childNodes[0]){adr=adr_nd.childNodes[0].nodeValue;}else{adr="";}
				
				  document.getElementById(ctrlhidAdrPc).value=pc;
				  document.getElementById(ctrlhidAdr).value=adr;
				
				  //alert(document.getElementById("hidOrigPc").value);
				
				  if (pc != "") {
				  getPostcodeLatLong(pc,trip);
				  }

				}
				
			}
		}
        xmlHttpReq.send(null);
}


function bdscnt(page) {

//alert("dscnt");

var bdate,bhour,bmnts,bhourCtrl,bmntsCtrl,price,cashprice,cardprice;
//today = new Date();

bdate = document.getElementById("hidDate").value;
//alert(bdate);
if (page==2) {
bhourCtrl = document.getElementById("hidHour");
bhour = bhourCtrl.options[bhourCtrl.selectedIndex].value;
bmntsCtrl = document.getElementById("hidMinute");
bmnts = bmntsCtrl.options[bmntsCtrl.selectedIndex].value;
cardprice=parseFloat(document.getElementById("spancardprice").innerHTML);
}
else
{
bhour = "00"
bmnts = "00"
}

//alert(cardprice);

strUrl = "xmlGetDscnt.asp?bi=" + bi + "&bdate=" + bdate + "&bhour=" + bhour + "&bmnts=" + bmnts
        
        myRand = parseInt(Math.random()*99999999999999);
        strUrl = strUrl +"&mr="+myRand;
        // Mozilla/Safari
        //alert(strUrl);
        
        if (window.XMLHttpRequest) {
               	try {
			xmlHttpReq = new XMLHttpRequest();
			xmlHttpReq.overrideMimeType('text/xml');
		    }
		catch(err1)
		    {
			try {
			    xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
			    }
			catch(err2) {
			    xmlHttpReq = new ActiveXObject("Msml2.XMLHTTP");
			    }
		    }
        }
        // IE
        else if (window.ActiveXObject) {
                xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
	
		
		xmlHttpReq.open('GET', strUrl, true);
       
        	xmlHttpReq.onreadystatechange = function() {
        	
			if (xmlHttpReq.readyState == 4) {
			
				if (xmlHttpReq.status == 200) {
				
				dscamtnode = xmlHttpReq.responseXML.getElementsByTagName("dscamt")[0];
				dscpctnode = xmlHttpReq.responseXML.getElementsByTagName("dscpct")[0];

				if (dscamtnode.childNodes[0]){dscamt=parseFloat(dscamtnode.childNodes[0].nodeValue);}else{dscamt=0;}
				if (dscpctnode.childNodes[0]){dscpct=parseFloat(dscpctnode.childNodes[0].nodeValue);}else{dscpct=0;}
				
				//alert(dscpct);
				//alert(dscamt);
				
					//if (dscamt>0 || dscpct>0) {
					
						price = parseFloat(document.getElementById("hidPrice").value);

						if (price==0) {
						price=theprice;
						}
					
						if(price>0) {
					
							//cashprice=((price-dscamt)*(1-dscpct)).toFixed(2);
							cashprice=price;
							cardprice=((price-dscamt)*(1-dscpct)).toFixed(2);
							
							if (page==2) {
							var buyit=parseInt(document.getElementById("hidbyn").value);
							
							//document.getElementById("tddscntprclbl").innerHTML="Buy Now";
							//document.getElementById("spancashprice").innerHTML= cashprice;
							document.getElementById("spancardprice").innerHTML= cardprice;
							document.getElementById("hidDscntPrice").value= cardprice;
							//document.getElementById("tddscntlbl").innerHTML="Discount";
							//document.getElementById("tddscnt").innerHTML="£" + (dscamt + ((price-dscamt)*dscpct)).toFixed(2);
								if (buyit==1) {
								document.getElementById("tdprice").innerHTML="<b>£" + ((price-dscamt)*(1-dscpct)).toFixed(2) + "</b>";
								}
							}
							else {
							document.getElementById("tddscntprclbl").innerHTML="Buy Now and Save";
							document.getElementById("tdbuynowimg").innerHTML="<img src='images/buynow2.gif'>"
							document.getElementById("btnSubmit").value="Pay Later";
							document.getElementById("btnBuySubmit").style.display="inline";
							document.getElementById("tddscntprc").innerHTML="£" + ((price-dscamt)*(1-dscpct)).toFixed(2);
							document.getElementById("hidDscntPrice").value=((price-dscamt)*(1-dscpct)).toFixed(2);
							}
							
						}
					//}
				
				}
				
			}
		}
        xmlHttpReq.send(null);
        
if (price==0) {
	if (page==1) {
	setTimeout("bdscnt(1)",1000);
	}
	else {
	setTimeout("bdscnt(2)",1000);
	}
}

}


function toggleTblprice (st) {

//alert("clear");

dom = findDOM('tblPrice',1);
//alert(dom.display);
//dom.display='inline';
//alert(dom.display);

//dom = findDOM('tblPrice',1);
//dom = document.getElementById('tblPrice')
//alert(dom.display);
	if (st==1) {
	dom.display='inline';
	}
	else {
		if (dom.display == 'inline') {
		dom.display='none';
		}
	}
}




function validate(form) {
var s,a,e,IError,incomplete,showerror,rdval,k,p;


//alert("valid");

p=0;
	 for (var k = 0; k < frmBooking.rdcustype.length; k++){
		if (frmBooking.rdcustype[k].checked){
		rdval=document.frmBooking.rdcustype[k].value;
		p=1;
		}
	}
	
	
	if(p==0) {
	dom = findDOM("rdcustypeEr",1);
	dom.visibility='visible';
	alert("Please let us know if you are an existing or a new customer.");
	return false;
	}
	else {
	dom = findDOM("rdcustypeEr",1);
	dom.visibility='hidden';
	}
		
	//alert(rdval);
	if (rdval=="e") {
	document.getElementById("nuName").optional="true";
	document.getElementById("nuMobile").optional="true";
	
		if (document.getElementById('txtContact').innerHTML=="") {
		alert("Please enter your email and password and then press Login button");
		return false;
		}
		
	}
	else {
	document.getElementById("nuName").optional="false";
	document.getElementById("nuMobile").optional="false";
	document.getElementById("nuEmail").optional="false";

		if (document.getElementById("nuName").value=="") {
		alert("Please enter your name.");
		dom = findDOM("nuNameEr",1);
		dom.visibility='visible';
		return false;
		}
		else {
		dom = findDOM("nuNameEr",1);
		dom.visibility='hidden';
		}
		
		if (document.getElementById("nuPhone").value=="") {
		alert("Please enter your phone or mobile number.");
		dom = findDOM("nuPhoneEr",1);
		dom.visibility='visible';
		return false;
		}
		else {
		dom = findDOM("nuMobileEr",1);
		dom.visibility='hidden';
		}
		
		if (document.getElementById("nuEmail").value=="") {
		alert("Please enter your Email.");
		dom = findDOM("nuEmailEr",1);
		dom.visibility='visible';
		return false;
		}
		else {
		dom = findDOM("nuEmailEr",1);
		dom.visibility='hidden';
		}
	}
	
	
p=0;	
	for (var k = 0; k < frmBooking.rdbkpgr.length; k++){
		if (frmBooking.rdbkpgr[k].checked){
		rdval=document.frmBooking.rdbkpgr[k].value;
		p=1;
		}
	}


	if(p==0) {
	dom = findDOM("rdbkpgrEr",1);
	dom.visibility='visible';
	alert("Please let us know if you are the passenger.");
	return false;
	}
	else {
	dom = findDOM("rdbkpgrEr",1);
	dom.visibility='hidden';
	}

	if (rdval=="y") {
	document.getElementById("txtPgrName").optional="true";
	document.getElementById("txtPgrPhone").optional="true";
	}
	else {
	document.getElementById("txtPgrName").optional="false";
	document.getElementById("txtPgrPhone").optional="false";
	
		if (document.getElementById("txtPgrName").value=="") {
		alert("Please enter passenger name.");
		dom = findDOM("txtPgrNameEr",1);
		dom.visibility='visible';
		return false;
		}
		else {
		dom = findDOM("txtPgrNameEr",1);
		dom.visibility='hidden';
		}
		
		if (document.getElementById("txtPgrPhone").value=="") {
		alert("Please enter passenger's phone.");
		dom = findDOM("txtPgrPhoneEr",1);
		dom.visibility='visible';
		return false;
		}
		else {
		dom = findDOM("txtPgrPhoneEr",1);
		dom.visibility='hidden';
		}
		
	}


p=0;
	//alert(frmBooking.rdpm.length);
	for (var k = 0; k < frmBooking.rdpm.length; k++){
		//alert(k);
		if (frmBooking.rdpm[k].checked){
		rdval=document.frmBooking.rdpm[k].value;
		p=1;
		}
	}
	
	//rdpm
	if(p==0) {
		dom = findDOM("rdpmEr",1);
		dom.visibility='visible';
		alert("Please select payment type.");
		return false;
		}
		else {
		dom = findDOM("rdpmEr",1);
		dom.visibility='hidden';
	}


for (var j=0; j<form.length;j++) {
	e=form.elements[j];
	if(e.optional || e.type == "submit" || e.type == "hidden" || e.type == "button" || e.type == "radio") continue;
	s=form.elements[j].value;
	a=form.elements[j].id;
	IError = a+'Er';
	//alert(IError);
	//alert(document.getElementById(a).optional)
	showerror=false;

	if (s.length<1) {
		incomplete = true;
		showerror=true;
		}
	else{
		for (var i=0;i<s.length;i++) {
		var c=s.charAt(i);
			if (i==0 && c==' ') {
				s=s.substring(1,s.length);
					if (s.length<1) {
						incomplete=true;
						showerror=true;
					}
				i=-1;
				continue;
			}

			if (c!=' ')break;
			else {
			incomplete = true
			showerror=true;
			}
		}
	}

			if (showerror == true) {
			dom = findDOM(IError,1);
			dom.visibility='visible';
			}
			else{
			dom = findDOM(IError,1);
			dom.visibility='hidden';
			}

}

	if (incomplete == true) {
		alert("you must complete all required fields");
		return false;
	 }
	 

//alert("here");
//alert(document.getElementById('chktc').checked);


if (document.getElementById('chktc').checked==false) {
	dom = findDOM('chktcEr',1);
	dom.visibility='visible';
	alert("Please tick the terms and conditions to confirm your acceptance of our terms before you proceed.");
return false;
}
else {
	dom = findDOM('chktcEr',1);
	dom.visibility='hidden';
}

}


function bdu(tripleg) {

var mntctrl,dayctrl,yearmonth;
var selyear,selmonth,selday;
var thismonth, whichmonth,thisdate;
var newoption,newval,newtext,tbd,tbdctrl;

//mntctrl = findDOM('slcmonth',1);
//dayctrl = findDOM('slcday',1);
if (tripleg=='hidDate') {
mntctrl = document.getElementById("slcmonth");
dayctrl = document.getElementById("slcday");
tbdctrl=document.getElementById("hidDate");
}
else {
mntctrl = document.getElementById("slcmonthFr");
dayctrl = document.getElementById("slcdayFr");
tbdctrl=document.getElementById("hidDateFr");
}


yearmonth = mntctrl.options[mntctrl.selectedIndex].value;
selday = dayctrl.options[dayctrl.selectedIndex].value;
//yearmonth = mntctrl.selectedIndex;
//alert(yearmonth);

selyear = yearmonth.substring(0,4);
selmonth = yearmonth.substring(4);
//selmonth = Number(yearmonth.substring(4));

//tbd=tbdctrl.value;

tbd=selday + "-" + selmonth + "-" + selyear;
tbdctrl.value=tbd;

}

function monthdays(tripleg) {

var mntctrl,dayctrl,yearmonth,seldate,seldw;
var selyear,selmonth,selwdname;
var selday = 1;
var thismonth, whichmonth,thisdate;
var newoption,newval,newtext,tbd,tbdctrl;

//mntctrl = findDOM('slcmonth',1);
//dayctrl = findDOM('slcday',1);
if (tripleg=='hidDate') {
mntctrl = document.getElementById("slcmonth");
dayctrl = document.getElementById("slcday");
}
else {
mntctrl = document.getElementById("slcmonthFr");
dayctrl = document.getElementById("slcdayFr");
}

yearmonth = mntctrl.options[mntctrl.selectedIndex].value;
//yearmonth = mntctrl.selectedIndex;
//alert(yearmonth);

selyear = Number(yearmonth.substring(0,4));
selmonth = Number(yearmonth.substring(4))-1;
//selmonth = Number(yearmonth.substring(4));


//alert(selmonth);

thisdate = new Date();
thismonth = thisdate.getMonth();


if (thismonth == selmonth) {
selday = thisdate.getDate();
}

whichmonth = selmonth;
//alert(selyear);
//alert(selmonth);

seldate = new Date();
//alert(seldate);
seldate.setFullYear(selyear);
seldate.setMonth(selmonth,selday);


dayctrl.options.length = 0;
//start loop
while (selmonth == whichmonth) {

//alert(seldate);

selday = seldate.getDate();
selwd= seldate.getDay();
//alert(selwd);

switch (selwd) {
	case 0 :
		selwdname = "Sun";
		break;
	case 1 :
		selwdname = "Mon";
		break;
	case 2 :
		selwdname = "Tue";
		break;
	case 3 :
		selwdname = "Wed";
		break;
	case 4 :
		selwdname = "Thu";
		break;
	case 5 :
		selwdname = "Fri";
		break;
	case 6 :
		selwdname = "Sat";
	}


//dayctrl.options[0].value = selday;
//dayctrl.options[0].text = selwdname + " " + selday;

newval = selday;
if (newval<10) {newval="0"+newval}
//newtext = selwdname + " " + selday;
newtext = selday;
newoption = new Option(newtext,newval,false,false);
dayctrl.options[dayctrl.options.length]= newoption;

selday++ ;// = selday + 1
seldate.setDate(selday);
whichmonth = seldate.getMonth();
//alert(selday);
//alert(whichmonth);
}
//end loop

}



function updDate(tripleg) {

var dtval,dayval,ymval,i,ctrlday,ctrlym;
//alert("Hello");
//alert(document.forms.booking.hidDate.value);

if (tripleg=='hidDate'){
dtval=document.forms.frmBooking.hidDate.value;
ctrlym=document.forms.frmBooking.slcmonth
ctrlday=document.forms.frmBooking.slcday
}
else {
dtval=document.forms.frmBooking.hidDateFr.value;
ctrlym=document.forms.frmBooking.slcmonthFr
ctrlday=document.forms.frmBooking.slcdayFr
}


dayval=dtval.substr(0,2);
//alert(dayval);

ymval=dtval.substr(6,4) + dtval.substr(3,2)
//alert(ymval);



for(i=0;i<ctrlym.options.length;i++) {
if (ctrlym.options[i].value == ymval) {
	ctrlym.options[i].selected = "selected";
	monthdays(tripleg);
	}
}

//alert(ctrlday.options.length);

for(i=0;i<ctrlday.options.length;i++) {
if (ctrlday.options[i].value == dayval) {
	ctrlday.options[i].selected = "selected";
	}
//else {alert(ctrlday.options[i].value);}
}

//txaUpd(document.frmBooking.hidDate,'txtDate',document.frmBooking.hidDate);

}


function txaUpd(ctrlFrom,ctrlHid) {

var cval,dom,va,i,j,ig,txtTo,hidTo;
cval = ctrlFrom.value;
//txtTo = document.getElementById(ctrlTxt);
//txtTo.innerHTML=cval;
ctrlHid.value=cval;

}


function opwindow(url,wtyp) {
	window.open(url,0,'toolbar=0,directories=0,status=0, menubar=0,scrollbars=0,resizable=1,width=400,height=150,left=250,top=450');
	}


function showPgrOpt() {
//alert("hello");
//alert(document.getElementById("txtContact").innerHTML);
	if (document.getElementById("txtContact").innerHTML != "") {
	//alert("hello");
	//document.getElementById("qupgr").visibility='visible';
	dom = findDOM('qupgr',1);
	dom.display='inline';
	}
}


function buyit(buyind) {
//alert("hi");
if (buyind==1) {
document.getElementById("hidbyn").value="1";
}
else {
document.getElementById("hidbyn").value="0";
}
//alert(document.getElementById("hidbyn").value);
}



function gtAdBk(trip) {

var pc,strUrl,postcode_nd,postcode,ctrl,cid,ctrlhidAdrPc,ctrlhidList,ctrlhidAdr,adr,adr_nd,ai;
var adrid_nd,pcode_nd,adr_id,pcode,odtype_nd,odtype,ctrlhidAdbType;

toggleTblprice (0);

ai=document.getElementById("hidAcntId").value;

	if (trip==1) {
	  ctrl = document.getElementById("origList");
      	  cid = ctrl.options[ctrl.selectedIndex].value;
          //alert(cid);
	  ctrlhidAdrPc="hidOrigPc"
	  ctrlhidList="hidorigList";
	  ctrlhidAdr="hidOrigAdress";
	  ctrlhidAdbType="hidAdbOrigOdtype";
	}
	else {
	  ctrl = document.getElementById("destList");
	  cid = ctrl.options[ctrl.selectedIndex].value;
	  ctrlhidAdrPc="hidDestPc";
	  ctrlhidList="hiddestList";
	  ctrlhidAdr="hidDestAdress";
	  ctrlhidAdbType="hidAdbDestOdtype";
	}
		
	document.getElementById(ctrlhidList).value=cid;

	
	//ctrlAdrTxt="origAdrTxt";
	
	//alert(pc + "-" + ctrl);
	
	//getPostcodeLatLong(pc,ctrl);
	
	//alert("I am back");
	
	strUrl = "xmlGetAdBk.asp?bi=" + bi + "&ai=" + ai + "&cid=" + cid;
        
        myRand = parseInt(Math.random()*99999999999999);
        strUrl = strUrl +"&mr="+myRand;
        // Mozilla/Safari
        // alert(strUrl);
        
        if (window.XMLHttpRequest) {
               	try {
			xmlHttpReq = new XMLHttpRequest();
			xmlHttpReq.overrideMimeType('text/xml');
		    }
		catch(err1)
		    {
			try {
			    xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
			    }
			catch(err2) {
			    xmlHttpReq = new ActiveXObject("Msml2.XMLHTTP");
			    }
		    }
        }
        // IE
        else if (window.ActiveXObject) {
                xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
	
		
		xmlHttpReq.open('GET', strUrl, true);
       
        	xmlHttpReq.onreadystatechange = function() {
        	
			if (xmlHttpReq.readyState == 4) {
			
				if (xmlHttpReq.status == 200) {
				
				adrid_nd = xmlHttpReq.responseXML.getElementsByTagName("odid")[0];
				adr_nd = xmlHttpReq.responseXML.getElementsByTagName("oddesc")[0];
				postcode_nd = xmlHttpReq.responseXML.getElementsByTagName("odpostcode")[0];
				pcode_nd = xmlHttpReq.responseXML.getElementsByTagName("odpcode")[0];
				odtype_nd = xmlHttpReq.responseXML.getElementsByTagName("odtype")[0];
				
				if (adrid_nd.childNodes[0]){adr_id=adrid_nd.childNodes[0].nodeValue;}else{adr_id=0;}
				if (adr_nd.childNodes[0]){adr=adr_nd.childNodes[0].nodeValue;}else{adr="";}
				if (postcode_nd.childNodes[0]){pc=postcode_nd.childNodes[0].nodeValue;}else{pc="";}
				if (pcode_nd.childNodes[0]){pcode=pcode_nd.childNodes[0].nodeValue;}else{pcode="";}
				if (odtype_nd.childNodes[0]){odtype=odtype_nd.childNodes[0].nodeValue;}else{odtype="";}
				
				
				  document.getElementById(ctrlhidAdrPc).value=pc;
				  document.getElementById(ctrlhidAdr).value=adr;
				  document.getElementById(ctrlhidList).value=adr_id;
				  document.getElementById(ctrlhidAdbType).value=odtype;
				  
				  //alert(ctrlhidAdrPc);
				  //alert(document.getElementById(ctrlhidAdbType).value);
				
				  if (pc != "") {
				  getPostcodeLatLong(pc,trip);
				  }

				}
				
			}
		}
        xmlHttpReq.send(null);
}



function pplAdBk(ctrl,odt,odtdesc) {

var odidnodes,oddescnodes,odpostcodenodes,odlocnodes,odid,oddesc,odpostcode,i,odcomment,odinstruct,odslc,ai

ai=document.getElementById("hidAcntId").value;

if (ctrl==1) {
document.getElementById("origComment").innerHTML="<img src='images/status_progress.gif'>";
}
else if (ctrl==2){
document.getElementById("destComment").innerHTML="<img src='images/status_progress.gif'>";
}
 
 strUrl = "xmlGetAdBk.asp?bi=" + bi + "&ai=" + ai + "&cid=0";
        
        myRand = parseInt(Math.random()*99999999999999);
        strUrl = strUrl +"&mr="+myRand;
        // Mozilla/Safari
       //alert(strUrl);
        
        if (window.XMLHttpRequest) {
               	try {
					xmlHttpReq = new XMLHttpRequest();
					xmlHttpReq.overrideMimeType('text/xml');
				    }
				catch(err1)
				    {
				    	try {
				    	    xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
				    	    }
				    	catch(err2) {
				    	    xmlHttpReq = new ActiveXObject("Msml2.XMLHTTP");
				    	    }
		    }
        }
        // IE
        else if (window.ActiveXObject) {
                xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
	
		
		xmlHttpReq.open('GET', strUrl, true);
       
        xmlHttpReq.onreadystatechange = function() {
			if (xmlHttpReq.readyState == 4) {
			
			
				if (xmlHttpReq.status == 200) {
				
				//alert(ctrl);
				
				if (ctrl==1) {
				//document.frmBooking.origList.options.length=0
				document.getElementById("origList").options.length=0
				odcomment="origComment"
				odinstruct="origInstruct"
				//odslc=document.frmOrig.origList
				}
				else if (ctrl==2){
				//document.frmBooking.destList.options.length=0
				document.getElementById("destList").options.length=0
				odcomment="destComment"
				odinstruct="destInstruct"
				//odslc=document.frmDest.destList
				}
						
				odlocnodes = xmlHttpReq.responseXML.getElementsByTagName("odloc");
				odidnodes = xmlHttpReq.responseXML.getElementsByTagName("odid");
				oddescnodes = xmlHttpReq.responseXML.getElementsByTagName("oddesc");
				odpostcodenodes = xmlHttpReq.responseXML.getElementsByTagName("odpostcode");
		
					
					if (ctrl==1) {
						document.getElementById("origList").options[0]=new Option("Please select",0, false, false);
						}
					else if (ctrl==2) {
						document.getElementById("destList").options[0]=new Option("Please select",0, false, false);
					}
					
					
					for(i=0;i<odlocnodes.length;i++) {
					odid = odidnodes[i].childNodes[0].nodeValue;
					oddesc = oddescnodes[i].childNodes[0].nodeValue;
					odpostcode=odpostcodenodes[i].childNodes[0].nodeValue;
					if (odt==15) {
					oddesc=oddesc + " - " + odpostcode;
					}
				    
						if (ctrl==1) {
						//document.frmBooking.origList.options[i]=new Option(oddesc, odid, false, false)
						document.getElementById("origList").options[i+1]=new Option(oddesc, odid, false, false)
						}
						else if (ctrl==2) {
						//document.frmBooking.destList.options[i]=new Option(oddesc, odid, false, false)
						document.getElementById("destList").options[i+1]=new Option(oddesc, odid, false, false)
						}
						
					}
					
				document.getElementById(odcomment).innerHTML = "Please select the " + odtdesc + " from the list below.<br>If your " + odtdesc + " is not on the list, click on postcode<br> and enter the full postcode of the " +  odtdesc + ".";
				document.getElementById(odinstruct).innerHTML = odtdesc;
						
				}
				
			}
		}
        xmlHttpReq.send(null);
}










