﻿function addOption(selectbox,text,value )
{
if(!ValueExist(selectbox,value)){
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}
}

function ValueExist(output,value){
	for(var i=0;i<output.length;i++) {
    if(output[i].value.indexOf(value)==0){
      return true;
		}
	  }
	return false;
}

function FillDropDowns(){
	/* Read Prices*/
	var xmlDoc;
	// code for IE
	if (window.ActiveXObject)
	{
	xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	}
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation.createDocument)
	{
	xmlDoc=document.implementation.createDocument("","",null);
	}
	else
	{
	alert('Your browser cannot handle this script');
	}
	xmlDoc.async=false;
	xmlDoc.load("note.xml");
	
	var x=xmlDoc.documentElement.childNodes;
	
	for (var i=0;i<x.length;i++)
	{ 
	if (x[i].nodeType==1)
	  { 
	  //Process only element (nodeType 1) nodes
	  //document.write(x[i].nodeName + ": ");
	  //alert(x[i].childNodes[0].nodeValue);
	  //alert(x[i].getAttribute("from"));
	  addOption(document.theForm.From,x[i].getAttribute("from"),x[i].getAttribute("from"));
	  addOption(document.theForm.From,x[i].getAttribute("to"),x[i].getAttribute("to"));
	  addOption(document.theForm.To,x[i].getAttribute("to"),x[i].getAttribute("to"));
  	  addOption(document.theForm.To,x[i].getAttribute("from"),x[i].getAttribute("from"));
	  addOption(document.theForm.Car,x[i].getAttribute("car"),x[i].getAttribute("car"));
	  } 
	}
}

function GetPrice(){
	var price = document.getElementById('estPrice');
	if(document.theForm.From.value==document.theForm.To.value)
		price.innerHTML = "Please select a different destination";
	else{
	
	/* Read Prices*/
	var xmlDoc;
	// code for IE
	if (window.ActiveXObject)
	{
	xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	}
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation.createDocument)
	{
	xmlDoc=document.implementation.createDocument("","",null);
	}
	else
	{
	alert('Your browser cannot handle this script');
	}
	xmlDoc.async=false;
	xmlDoc.load("note.xml");
	
	var x=xmlDoc.documentElement.childNodes;
	
	for (var i=0;i<x.length;i++)
	{ 
	if (x[i].nodeType==1)
	  { 
	  //Process only element (nodeType 1) nodes
	  //document.write(x[i].nodeName + ": ");
	  //alert(x[i].childNodes[0].nodeValue);
	  //alert(x[i].getAttribute("from"));
		  if((x[i].getAttribute("from")==document.theForm.From.value && x[i].getAttribute("to") == document.theForm.To.value && x[i].getAttribute("car") == document.theForm.Car.value) || (x[i].getAttribute("from")==document.theForm.To.value && x[i].getAttribute("to") == document.theForm.From.value && x[i].getAttribute("car") == document.theForm.Car.value))
		  {
			  price.innerHTML = x[i].childNodes[0].nodeValue;
			  return 0;
		  }
	  } 
	}
	}
}