function save(title){
	var ver = navigator.appName
	var num = parseInt(navigator.appVersion)
	var txt = ""
	var url = location.href
	var who = "Your route: "+title
	if((ver == "Microsoft Internet Explorer")&&(num >= 4)){
	  accept=window.external.AddFavorite(url,who);
	  if(accept){ txt="This route has been saved as one of your \"Favourites\" Folder.  To get the Route back select the favourite in your Internet Explorer." }
	  }
	else{
	  txt="To save this route add it to you bookmarks by clicking \"Bookmarks\" then \"Add bookmark\"."
	  }
	if(txt!=""){ alert(txt) }
	}

function getObj(div){
  if(document.getElementById){obj=document.getElementById(div) }
  else if(document.all){obj=document.all[div] }
  else if (document.layers){obj=document.layers[div] }
  return obj }
function showObj(obj){
  document.layers?rv=obj.visibility='show':obj.style.visibility='visible'}
function hideObj(obj){
  document.layers?rv=obj.visibility='hide':obj.style.visibility='hidden'}


function changeCountryDropDowns(){
  o_one=getObj("AD4_O")
  o_two=getObj("AD4_D")
  o_a=getObj("AD4_1")
  o_b=getObj("AD4_2")
  o_s=getObj("AD4")
	if(o_one){
		for(n=0;n<o_one.options.length;n++){
			if(o_one.options[n].value==""){
				o_one.selectedIndex=n
				}
			}
		}
	if(o_two){
		for(n=0;n<o_two.options.length;n++){
			if(o_two.options[n].value==""){
				o_two.selectedIndex=n
				}
			}
		}
	if(o_a){
		for(n=0;n<o_a.options.length;n++){
			if(o_a.options[n].value==""){
				o_a.selectedIndex=n
				}
			}
		}
	if(o_b){
		for(n=0;n<o_b.options.length;n++){
			if(o_b.options[n].value==""){
				o_b.selectedIndex=n
				}
			}
		}
	if(o_s){
		for(n=0;n<o_s.options.length;n++){
			if(o_s.options[n].value==""){
				o_s.selectedIndex=n
				}
			}
		}
	}


function showVia(){
  getObj('via')
  obj.style.display=='block'?obj.style.display='none':obj.style.display='block'
//  getObj('AD2_1').value=''
//  getObj('AD3_1').value=''
//  getObj('AD2_2').value=''
//  getObj('AD3_2').value=''
  getObj('addviapoints')
  hideObj(obj)
  }

function hideVia(){
  getObj('via')
  obj.style.display=='none'?obj.style.display='block':obj.style.display='none'
	clearLocation('1')
	clearLocation('2')
  getObj('addviapoints')
  showObj(obj)
  }

function clearLocation(which){
  eval('document.forms.rpform.AD2_'+which+'.value=\"\";')
  eval('document.forms.rpform.AD3_'+which+'.value=\"\";')
  }

 function getLocation(){
  loc=document.urlform.urlfield.value.substring(0,document.urlform.urlfield.value.indexOf("?"))
  return loc
  }

 function getQS(){
  qs=document.urlform.urlfield.value.substring(document.urlform.urlfield.value.indexOf("?")+1,document.urlform.urlfield.value.length)
  return qs
  }

 function getQSvalue(which){
   qs=getQS()
//   if(qs.indexOf(which)==-1){alert("01:ERROR: "+which+" not found in Query String"); }
   sqs=qs.substring(0,qs.indexOf(which))
   eqs=qs.substring(qs.indexOf(which),qs.length)
   eqs.indexOf("&")!=-1?fqs=eqs.substring(eqs.indexOf("&")+1,eqs.length):fqs=''
   eqs.indexOf("&")!=-1?valStrg=qs.substring(sqs.length,qs.indexOf(fqs)-1):valStrg=qs.substring(sqs.length,qs.length)
   val=valStrg.substring(which.length+1,valStrg.length)
   return val
   }

 function changeQSvalue(which,newValue,reld){
   qs=getQS()
   if(qs.indexOf(which)!=-1){
	   loc=getLocation()
	   sqs=qs.substring(0,qs.indexOf(which))
	   eqs=qs.substring(qs.indexOf(which),qs.length)
	   eqs.indexOf("&")!=-1?fqs=eqs.substring(eqs.indexOf("&")+1,eqs.length):fqs=''
	   eqs.indexOf("&")!=-1?valStrg=qs.substring(sqs.length,qs.indexOf(fqs)-1):valStrg=qs.substring(sqs.length,qs.length)
	   newQs=loc+"?"+sqs+fqs+"&"+which +"="+newValue
	   if(newQs.indexOf("&&")!=-1){newQs=loc+"?"+sqs+fqs+which +"="+newValue}
	   document.urlform.urlfield.value=newQs
	   if(reld){location.href=document.urlform.urlfield.value}
	   }
	 else{
     addQSvalue(which,newValue,reld) ; 
     }
   }

 function addQSvalue(newField,newValue,reld){
   loc=getLocation()
   qs=getQS()
   newQs=loc+"?"+qs+"&"+newField +"="+newValue
   if(newQs.indexOf("&&")!=-1){newQs=loc+"?"+qs+newField +"="+newValue}
   document.urlform.urlfield.value=newQs
   if(reld){location.href=document.urlform.urlfield.value}
   }

 function removeQSfield(which,reld){
   loc=getLocation()
   qs=getQS()
   if(qs.indexOf(which)==-1){  
//  alert("02:ERROR: "+which+" not found in Query String"); 
   }
   else{
	   sqs=qs.substring(0,qs.indexOf(which))
	   eqs=qs.substring(qs.indexOf(which),qs.length)
	   eqs.indexOf("&")!=-1?fqs=eqs.substring(eqs.indexOf("&")+1,eqs.length):fqs=''
	   eqs.indexOf("&")!=-1?valStrg=qs.substring(sqs.length,qs.indexOf(fqs)-1):valStrg=qs.substring(sqs.length,qs.length)
	   newQs=loc+"?"+sqs+fqs
	   document.urlform.urlfield.value=newQs
	   }
   if(reld){location.href=document.urlform.urlfield.value}
   }

 function editJourney(){
   reld=true
   loc=getLocation()
   qs=getQS()
   newLoc=loc.substring(0,loc.indexOf("directions.asp"))
   qs="AD2_O"+"="+getQSvalue("AD2_O")+"&"+"AD3_O"+"="+getQSvalue("AD3_O")+"&"+"AD2_D"+"="+getQSvalue("AD2_D")+"&"+"AD3_D"+"="+getQSvalue("AD3_D")+"&"+"AD2_1"+"="+getQSvalue("AD2_1")+"&"+"AD3_1"+"="+getQSvalue("AD3_1")+"&"+"AD2_2"+"="+getQSvalue("AD2_D")+"&"+"AD3_2"+"="+getQSvalue("AD3_2")+"&"+"AD4_O"+"="+getQSvalue("AD4_O")+"&"+"AD4_D"+"="+getQSvalue("AD4_D")+"&"+"AD4_1"+"="+getQSvalue("AD4_1")+"&"+"AD4_2"+"="+getQSvalue("AD4_2")
//   if(getQSvalue("AD3_1")!=''){ qs=qs+"&AD2_1"+"="+getQSvalue("AD2_1")+"&"+"AD3_1"+"="+getQSvalue("AD3_1")+"&"+"AD4_1"+"="+getQSvalue("AD4_1") }
//   if(getQSvalue("AD3_2")!=''){ qs=qs+"&AD2_2"+"="+getQSvalue("AD2_2")+"&"+"AD3_2"+"="+getQSvalue("AD3_2")+"&"+"AD4_2"+"="+getQSvalue("AD4_2") }
   newQs=newLoc+"index.asp?"+qs
   document.urlform.urlfield.value=newQs
   if(reld){location.href=document.urlform.urlfield.value}
   }

 function reverseJourney(){
   reld=true
   loc=getLocation()
   qs="AD2_D"+"="+getQSvalue("AD2_O")+"&"+"AD3_D"+"="+getQSvalue("AD3_O")+"&"+"AD2_O"+"="+getQSvalue("AD2_D")+"&"+"AD3_O"+"="+getQSvalue("AD3_D")+"&"+"AD4_O"+"="+getQSvalue("AD4_D")+"&"+"AD4_D"+"="+getQSvalue("AD4_O")+"&"+"AD2_1"+"="+getQSvalue("AD2_2")+"&"+"AD3_1"+"="+getQSvalue("AD3_2")+"&"+"AD2_2"+"="+getQSvalue("AD2_1")+"&"+"AD3_2"+"="+getQSvalue("AD3_1")+"&"+"AD4_2"+"="+getQSvalue("AD4_1")+"&"+"AD4_1"+"="+getQSvalue("AD4_2")
   newQs=loc+"?"+qs+"&PCT="+getQSvalue("PCT")+"&DU="+getQSvalue("DU")+"&driveStyle="+getQSvalue("driveStyle")+"&PDT="+getQSvalue("PDT")
   document.urlform.urlfield.value=newQs
   if(reld){location.href=document.urlform.urlfield.value}
   }

function rpform_submit(){
  sub=true
  tip=""
  if(document.forms.rpform.AD3_O.value=="" && document.forms.rpform.AD3_D.value==""){
    sub=false
    }
  else if(document.forms.rpform.AD3_O.value==""){
    sub=false; 
    tip+="A start location does not have to be exact.  It can be a City or Town name, eg Bradford, that will produce a route starting from the best road to exit your starting location from.";
    }
  else if(document.forms.rpform.AD3_D.value==""){
    sub=false; 
    tip+="A destination does not have to be exact.  It can be a City or Town name, eg Bradford, that will produce a route that ends at your destination.";
    }
  if(sub){
    document.rpform.submit()
    }
  else{
    alert("You must enter a City or Post Code for both your starting point and your destination to use the Routeplanner.  "+tip)
    }
  }

function printable(){
  reld=true
  qs=getQS()
  newQs="directions_print.asp"+"?"+qs
  document.urlform.urlfield.value=newQs
  if(reld){location.href=document.urlform.urlfield.value}
 }

function email(){
 qs=getQS()
 newQs="directions_email.asp"+"?"+qs
// +"&AD4_O=GBR&AD4_D=GBR&PCT="+getQSvalue("PCT")+"&DU="+getQSvalue("DU")+"&driveStyle="+getQSvalue("driveStyle")+"&PDT="+getQSvalue("PDT")
// alert(newQs)
  location.href=newQs
 }

function mapInstruction(newField,newValue,reld){
  removeQSfield("scale",false)
  removeQSfield("ZM",false)
  removeQSfield("PN",false)
  changeQSvalue(newField,newValue,true)
  }

document.write('<form name=\"urlform\" id=\"urlform\"><input type=\"hidden\" name=\"urlfield\" id=\"urlfield\" size=\"90\" /></form>')
document.urlform.urlfield.value=location.href.substring(0,location.href.indexOf("?"))+"?"+location.href.substring(location.href.indexOf("?")+1,location.href.length)
