


function change()
{
	init=1;

	document.getElementById("squery").options.length=null;
     var cityarr=new Array();
     var cnt=0;
                                   

	if (document.getElementById("mquery").options[document.getElementById("mquery").selectedIndex].value == "0")
	   {
	      document.getElementById("squery").options[0]=new Option("SELECT","0");
	   }

	   else
	   {
	                 
                  if (window.XMLHttpRequest)  {
                  xhttp=new window.XMLHttpRequest();
                 }
                 else {// Internet Explorer 5/6
                 xhttp=new ActiveXObject("Microsoft.XMLHTTP");
                  }
                  xhttp.open("GET","js/airrates.xml",false);
                  xhttp.send("");
                  xmlDoc1=xhttp.responseXML;
                  var xmlCity=xmlDoc1.getElementsByTagName("tajairrates");
              var xmlCity1=xmlCity[0].getElementsByTagName("Flight");
           
                   for(f=0;f<xmlCity1.length;f++)
                    {
                   
                        if(xmlCity1[f].getAttribute("Enable")==1)
                         {

                            xmlItm1=xmlCity1[f].getElementsByTagName("item")
                              for(m=0;m<xmlItm1.length;m++)
                              {
                            
                                if(xmlItm1[m].getElementsByTagName("from")[0].childNodes[0].nodeValue.toLowerCase()==document.getElementById("mquery").options[document.getElementById("mquery").selectedIndex].value.toLowerCase())
                                  {
                                  
                                    
                                    if(cityarr.length>0)
                                    {
                                   
                                             if(cityarr.valueOf().toString().indexOf(xmlItm1[m].getElementsByTagName("to")[0].childNodes[0].nodeValue)==-1)
                                             {
                                                   cityarr[cnt]=xmlItm1[m].getElementsByTagName("to")[0].childNodes[0].nodeValue;        
                                                    cnt++;
                                              }
                                         
                                    }
                                   else
                                   {
                                   cityarr[cnt]=xmlItm1[m].getElementsByTagName("to")[0].childNodes[0].nodeValue;
                                   cnt++;
                                   } 
                                  
                                
                                
                                    
                                  }
                             }
                         }
                     } 
                       cityarr.sort();
		                      for(f=0;f<cityarr.length;f++)
                                   {
                                    var cmb=document.getElementById('squery');
                                    cmb.options[0]=new Option("SELECT","SELECT");
                                  
                                    cmb.options[init]=new Option(cityarr[f].toUpperCase(),cityarr[f].toUpperCase());
                                    init++;
                                    }
                                    cmb.options[0].selected = true;             
    
	   }	
		          
		        
}

function validateMe()
    {
       
        if(document.getElementById("mquery").options[document.getElementById("mquery").selectedIndex].value == "0")
        {
            alert("Please select the origin and destination to get a quick quote");
            document.getElementById("mquery").focus();
            return false
        }
    
       
    
        if(document.getElementById("squery").options[document.getElementById("squery").selectedIndex].text == "SELECT" || document.getElementById("squery").options[document.getElementById("squery").selectedIndex].value == "0")
        {
            alert("Please select the destination to get a quick quote");
            document.getElementById("squery").focus();
            return false
        }
       //getFlightDetails(document.getElementById("mquery").options[document.getElementById("mquery").selectedIndex].value,document.getElementById("squery").options[document.getElementById("squery").selectedIndex].value,"INR");
       setTimeout("getFlightDetails('"+document.getElementById("mquery").options[document.getElementById("mquery").selectedIndex].value+"','"+document.getElementById("squery").options[document.getElementById("squery").selectedIndex].value+"','INR');",500);
       return true;
	//var winname1 = "loadme.asp?" + "mquery=" + document.getElementById("mquery").options[document.getElementById("mquery").selectedIndex].value + "&squery=" + document.getElementById("squery").options[document.getElementById("squery").selectedIndex].value + "&rdJourney=" + document.support.rdJourney.value + "&rdPay"

	//window.open()

    }
   
   
   
   
   var strResf=null;
     var strRes=null;
     function getFlightDetails()
     {
 
     strRes=null;
  
      if (window.XMLHttpRequest)  {
      xhttp=new window.XMLHttpRequest();
     }
     else {// Internet Explorer 5/6
     xhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      xhttp.open("GET","js/airrates.xml",false);
      xhttp.send("");
      xmlDoc=xhttp.responseXML;
      var xmlItem1=xmlDoc.getElementsByTagName("tajairrates");
      var xmlItem=xmlItem1[0].getElementsByTagName("Flight");
   
           for(f=0;f<xmlItem.length;f++)
            {
           
                if(xmlItem[f].getAttribute("Enable")==1)
                 {

                    xmlItm=xmlItem[f].getElementsByTagName("item")
                      for(m=0;m<xmlItm.length;m++)
                      {
                         
                      
                          if(xmlItm[m].getElementsByTagName("from")[0].childNodes[0].nodeValue.toLowerCase()==arguments[0].toLowerCase() && xmlItm[m].getElementsByTagName("to")[0].childNodes[0].nodeValue.toLowerCase()==arguments[1].toLowerCase())
                          {
                            
                                if(arguments[2]=="INR")
                                {
                                 if(strRes!=null)
                                 strRes+="<div class=\"inr\"><div class=\"div1\">"+xmlItem[f].getAttribute("name")+"<br /><span>INR "+calculateAmt(xmlItm[m].getElementsByTagName("rupees")[0].childNodes[0].nodeValue,xmlItm[m].getElementsByTagName("mins")[0].childNodes[0].nodeValue,xmlItm[m].getElementsByTagName("from")[0].childNodes[0].nodeValue.toLowerCase(),xmlItm[m].getElementsByTagName("to")[0].childNodes[0].nodeValue.toLowerCase(),xmlItm)+"</span></div>";
                                 else
                                 strRes="<div class=\"inr\"><div class=\"div1\">"+xmlItem[f].getAttribute("name")+"<br /><span>INR "+calculateAmt(xmlItm[m].getElementsByTagName("rupees")[0].childNodes[0].nodeValue,xmlItm[m].getElementsByTagName("mins")[0].childNodes[0].nodeValue,xmlItm[m].getElementsByTagName("from")[0].childNodes[0].nodeValue.toLowerCase(),xmlItm[m].getElementsByTagName("to")[0].childNodes[0].nodeValue.toLowerCase(),xmlItm)+"</span></div>";
                                }
                                else
                                {
                                 if(strRes!=null)
                                 strRes+="<div class=\"inr\"><div class=\"div1\">"+xmlItem[f].getAttribute("name")+"<br /><span>USD "+calculateAmt(xmlItm[m].getElementsByTagName("rupees")[0].childNodes[0].nodeValue,xmlItm[m].getElementsByTagName("mins")[0].childNodes[0].nodeValue,xmlItm[m].getElementsByTagName("from")[0].childNodes[0].nodeValue.toLowerCase(),xmlItm[m].getElementsByTagName("to")[0].childNodes[0].nodeValue.toLowerCase(),xmlItm)+"</span></div>";
                                 else
                                 strRes="<div class=\"inr\"><div class=\"div1\">"+xmlItem[f].getAttribute("name")+"<br /><span>USD "+calculateAmt(xmlItm[m].getElementsByTagName("rupees")[0].childNodes[0].nodeValue,xmlItm[m].getElementsByTagName("mins")[0].childNodes[0].nodeValue,xmlItm[m].getElementsByTagName("from")[0].childNodes[0].nodeValue.toLowerCase(),xmlItm[m].getElementsByTagName("to")[0].childNodes[0].nodeValue.toLowerCase(),xmlItm)+"</span></div>";
                                } 
                                
                                  strRes+="<div class=\"div2\">"+xmlItm[m].getElementsByTagName("description")[0].childNodes[0].nodeValue+"</div>";
                                 strRes+="</div>";
                          }
                         
                      }
                             
                 }
             
            }
 
   if(strRes!=null)
   document.getElementById("resultDiv").innerHTML=strRes;
   else
   document.getElementById("resultDiv").innerHTML="No results found for searched criteria.";
      
     }
   function calculateAmt()
   {
   var amt=arguments[0];
   var hrs=arguments[1];
   var from=arguments[2];
   var to=arguments[3];
   var xmlIt=arguments[4];
   var valmins=parseInt(hrs)+parseInt(hrs)
   var calculatedAmt;
 // if(document.getElementById("oneRadio").checked)
     if(from=="mumbai")
     {
       if(valmins<60)
        valmins=60;
        //alert(valmins);
       // alert(parseInt(amt)/ 60);
      calculatedAmt= Math.floor(valmins * (parseInt(amt)/ 60))
      }
     else if(to=="mumbai")
      {
       if(!document.getElementById("returnRadio").checked)
       {
           if(valmins<60)
             valmins = 60
           else
             valmins = hrs
           calculatedAmt= Math.floor(valmins * ((parseInt(amt)*2)/ 60))   
            //  strResult = "INR " & clng((cdbl(valmins) * cdbl(objHdl.childNodes(3).text) * 2) / 60)
                                              
       }
       else
       {
             if((parseInt(hrs)*4)<60)
                 valmins = 60;
             else
                 valmins =parseInt(hrs);
          calculatedAmt= Math.floor(valmins * ((parseInt(amt)*4)/ 60))   
                                              
                            
                              //  strResult = "INR " & clng((cdbl(valmins) * cdbl(objHdl.childNodes(3).text) * 4) / 60)
       } 
      
      }
      
     else
      {
           var getminutes=null;//Get the traveling time between mumbai and selected city
           var getminutes1=null;
         
           for(g=0;g<xmlIt.length;g++)
            {
              if(xmlIt[g].getElementsByTagName("from")[0].childNodes[0].nodeValue.toLowerCase()=="mumbai" && xmlIt[g].getElementsByTagName("to")[0].childNodes[0].nodeValue.toLowerCase()==from)
               {
                 getminutes=xmlIt[g].getElementsByTagName("mins")[0].childNodes[0].nodeValue
                 break;
               }
               
            }
            
            for(g=0;g<xmlIt.length;g++)
            {
              
              if(xmlIt[g].getElementsByTagName("from")[0].childNodes[0].nodeValue.toLowerCase()=="mumbai" && xmlIt[g].getElementsByTagName("to")[0].childNodes[0].nodeValue.toLowerCase()==to)
               {
                 getminutes1=xmlIt[g].getElementsByTagName("mins")[0].childNodes[0].nodeValue
                 break;
               }
               
            }
      

          if(!document.getElementById("returnRadio").checked)
           {
         
             valmins=parseInt(getminutes)+parseInt(hrs)+parseInt(getminutes1);
             if(valmins<60)
             valmins=60;
             calculatedAmt= Math.floor((valmins * parseInt(amt))/ 60)
           }
           else
           {
              valmins=(parseInt(getminutes)+parseInt(hrs))*2;
             
              if(valmins<60)
              valmins=60;
              else
              valmins=parseInt(getminutes)+parseInt(hrs);
               calculatedAmt= Math.floor(((valmins * parseInt(amt))*2)/ 60)   
              
           
           }
      
      }
     //alert("'"+calculatedAmt+".00'");
     var ammt=calculatedAmt.toString()+".00";
    // alert(ammt);
     calculatedAmt=CommaFormatted(ammt);
     //alert(calculatedAmt);
     return calculatedAmt;
   
   } 
    
function Resetfn()
{

document.getElementById("squery").options.length=0;
  document.getElementById("squery").options[0]=new Option("SELECT","0");
  document.getElementById("mquery").selectedIndex=0;//new Option("-------Select---------","0");
  document.getElementById("returnRadio").checked=false;
  document.getElementById("oneRadio").checked=true;
  document.getElementById("resultDiv").innerHTML="";
}



function CommaFormatted(amount)
{

	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n ; }
	amount = minus + amount;
	return amount;
}
