﻿/*JScript File */
var Objcont;var Objdes;var ObjRst;var rstVal;var rsttype;var objcheckin;var objcheckout;var objdur;var objhdnDest;var objhdnRest;var cardestinationval;var countryid;var destinationid;var resortsid;var cntbest;var countryval;				

Init=function() 
{   if (window.XMLHttpRequest)  // Non-IE browsers 
	{	_req = new XMLHttpRequest(); } 
	else if (window.ActiveXObject) // IE 
	{  _req = new ActiveXObject("Microsoft.XMLHTTP"); } 
} 
processStateChangemain=function()
{ 	if (_req.readyState == 4)
	{   if (_req.status == 200) 
		{   if(_req.responseText=="") 
				return false; 
			else{eval(_req.responseText);} 
		} 
	} 
} 	

/* This function  used for Destination*/ 
GetCountry=function(ddlbestid,cnt,cntdes,cntres,cnth,cnthdes,cnthres,hdnDest,hdnRest) 
{  cntbest=ddlbestid;
   var val = document.getElementById(ddlbestid).value;
   if(document.getElementById("hidVAL").value == "H")
   {   Objcont=cnth; 
       Objdes=cnthdes;
       ObjRst=cnthres;
   }
   else
   {    Objcont=cnt; 
        Objdes=cntdes;
        ObjRst=cntres;
   }
   rsttype=document.getElementById("hidVAL").value;
   objhdnDest = hdnDest;
   objhdnRest = hdnRest;
   try
   {if (val!="")
    {var strid = val.split('|')
    if (strid.length>0)
    {   if(strid[0]=='c')
        {   countryid=strid[1];
            destinationid=0;
            resortsid=0;}
        else if(strid[0]=='d')
        {   countryid=strid[1];
            destinationid=strid[2];
            resortsid=0;}
        else
        {   countryid=strid[1];
            destinationid=strid[2];
            resortsid=strid[3];}
        
        var ddlcnt = document.getElementById(Objcont);
        for(i=0;i<ddlcnt.length;i++)
        {   if(ddlcnt.options[i].value.split('|')[0] == countryid)
            {ddlcnt.value = ddlcnt.options[i].value;}
        }
    }
    	if (Objdes !="")
    	{   _ddl = document.getElementById(Objdes);
		    _ddl.disabled=true;
		    while (_ddl.childNodes.length >0)
		    {_ddl.removeChild(_ddl.childNodes[0]); } 
	          var op = document.createElement("Option");op.innerHTML = "Please wait. Loading....";       
              op.value = 0;  _ddl.appendChild(op); 
        }
        
        if (ObjRst !="")
        { ddres=document.getElementById(ObjRst);
          ddres.disabled=true;
          while (ddres.childNodes.length >0) 
          {ddres.removeChild(ddres.childNodes[0]); } 
            var op = document.createElement("Option"); 
            op.innerHTML = "Please Wait. Loading...."; op.value = 0;     
            ddres.appendChild(op);
        }	
    	// Send the Query for destination 
       	SendQuery(ddlcnt.value,'Destination',rsttype); 
  }	 
 }catch (ex){}  
}  

/*This function  used for Destination*/ 
GetDestination=function(contid,cnt,cntres,hdnDest,hdnRest,type,cntbestdest) 
{  Objdes=cnt;
   ObjRst=cntres;
   rsttype=type;
   try{cntbest=cntbestdest;}catch(ex){}
   Objcont=contid;
   countryval=document.getElementById(contid).value;
   objhdnDest = hdnDest;
   objhdnRest = hdnRest;
   try
   {   //Set country in best destination drop down
       if (type=="H" || type=="FH")
       {    var objbest = document.getElementById(cntbestdest);
            try
            {   objbest.selectedIndex=0;
                /******* Set best destination dropdown value according to country dropdown *******/
                for(i=0;i<objbest.length;i++)
                {   if (objbest.options[i].value.split('|')[0]=="c")
                    {   if(objbest.options[i].value.split('|')[1] == countryval.split('|')[0])
                        {objbest.value = objbest.options[i].value;}
                    }
                }
            }
            catch(ex) {}
       }
   }
   catch(ex){}
   
   if (type=="PICK")
   cardestinationval=countryval; 
   try
   {if (countryval!="")
    {   _ddl = document.getElementById(Objdes);
		_ddl.disabled=true;
		while (_ddl.childNodes.length >0)
		{_ddl.removeChild(_ddl.childNodes[0]); } 
	      var op = document.createElement("Option");op.innerHTML = "Please wait. Loading....";       
          op.value = 0;  _ddl.appendChild(op); 
 
        if (ObjRst !=""){ 
          ddres=document.getElementById(ObjRst);
          ddres.disabled=true;
          while (ddres.childNodes.length >0) 
          {ddres.removeChild(ddres.childNodes[0]); } 
            var op = document.createElement("Option"); 
            op.innerHTML = "Please Wait. Loading...."; op.value = 0;     
            ddres.appendChild(op);
        }	
    	// Send the Query for destination 
       	SendQuery(countryval,'Destination',type); 
  }	 
 }catch (ex){}  
}  
/* This function  used for resorts*/   
GetResort=function(contid,cnt,cntdest,hdnDest,hdnRest,type,cntbestdest)  
{   Objcont=contid;
    Objdes=cnt;
    objhdnDest = hdnDest;
   objhdnRest = hdnRest;
   var val=document.getElementById(cntdest).value;
    /* Set first selected destination value to destination hidden - 30 April 2008 */
   var cntd = document.getElementById(cntdest);
   document.getElementById(objhdnDest).value = cntd.options[cntd.selectedIndex].text;
   //Set destination in best seller destination drop down
   if (type=="H" || type=="FH")
   {    var objbest = document.getElementById(cntbestdest);
        try
        {   objbest.selectedIndex=0;
            /******* Set best destination dropdown value according to country dropdown *******/
            for(i=0;i<objbest.length;i++)
            {   if (objbest.options[i].value.split('|')[0]=="c")
                {   if(objbest.options[i].value.split('|')[1] == document.getElementById(Objcont).value.split('|')[0])
                    {objbest.value = objbest.options[i].value;}
                }
            }
            /******* Set best destination dropdown value according to destination dropdown *******/
            for(i=0;i<objbest.length;i++)
            {   if (objbest.options[i].value.split('|')[0]=="d")
                {   if(objbest.options[i].value.split('|')[2] == val.split('|')[0])
                    {objbest.value = objbest.options[i].value;}
                }
            }
        }
        catch(ex) {}
   }
    
   try
   {    if (val!=0)
        {   _ddl = document.getElementById(Objdes);
		    _ddl.disabled=true;
		    while (_ddl.childNodes.length >0)
		    {_ddl.removeChild(_ddl.childNodes[0]); } 
	        var op = document.createElement("Option"); 
            op.innerHTML = "Please Wait. Loading....";       
            op.value = 0;     
            _ddl.appendChild(op);
	  //---------  Send the Query for Resort 
      SendQuery(val,'Resorts',type);
    }
   }catch (ex){}  
 } 
 
 GetCarResort=function(val,cnt,cntdest,hdnDest,hdnRest,type)  
 {  Objdes=cnt;
    objhdnDest = hdnDest;
    objhdnRest = hdnRest;
    /* Set first selected destination value to destination hidden - 30 April 2008 */
    var cntd = document.getElementById(cntdest);
    document.getElementById(objhdnDest).value = cntd.options[cntd.selectedIndex].text;
   try
   {if (val!=0)
    {   _ddl = document.getElementById(Objdes);
		_ddl.disabled=true;
		while (_ddl.childNodes.length >0)
		{_ddl.removeChild(_ddl.childNodes[0]); } 
	    var op = document.createElement("Option"); 
        op.innerHTML = "Please Wait. Loading....";       
        op.value = 0;     
        _ddl.appendChild(op);
	  //---------  Send the Query for Resort 
      SendQuery(val,'DROPOFF','DROPOFF');
    }
   }catch (ex){}  
 } 
   
/*Send the request to the getDestination page with parameters ( value, controls,type)*/
SendQuery=function(val,cnt,type) //get data 
{  Init(); 
   if (val == ""){    
      return;
   }
   if (type=="PICK") 
   cnt =  "PICK";
   var url="getDestination.aspx?val="+val+"&cntid="+cnt+"&type="+type; 
   
    if(_req!=null) 
    {    _req.onreadystatechange = processStateChangemain; 
        _req.open("GET", url, true); _req.send(null); 
    } 
} 

/*Set the Drop down value in Destination dropdown*/
populateDDL = function(v,t)
{   _ddl = document.getElementById(Objdes); 
   _ddl.disabled=false;   
    while (_ddl.childNodes.length >0)
    {_ddl.removeChild(_ddl.childNodes[0]); } 
    var count = v.length; 
    for (var i=0; i<v.length; ++i){ 
      var op = document.createElement("Option"); 
      op.innerHTML = t[i];       
      op.value = v[i]; 
      _ddl.appendChild(op); 
   } 
   
   if(destinationid!=0)
   {var _Objdes = document.getElementById(Objdes);
    for(i=0;i<_Objdes.length;i++)
    {   if(_Objdes.options[i].value.split('|')[0] == destinationid)
        {_Objdes.value = _Objdes.options[i].value;}
    }
   }
 
   /* Add destination id feild in this function */         
     if (rsttype=="PICK")
      GetCarResort(cardestinationval,ObjRst,Objdes,objhdnDest,objhdnRest,rsttype);
      else
      GetResort(Objcont,ObjRst,Objdes,objhdnDest,objhdnRest,rsttype,cntbest);
} 

/*Set the Drop down value in Resorts dropdown*/
populateResDDL = function(v,t)
{  _ddl = document.getElementById(Objdes); 
   _ddl.disabled=false;   
   while (_ddl.childNodes.length >0)
   {_ddl.removeChild(_ddl.childNodes[0]); } 
   
   var o = document.createElement("Option"); 
   o.innerHTML = "[Search All Locations]";
   o.value ="0"; 
   _ddl.appendChild(o); 
   var count = v.length;
   for (var i=0; i<v.length; ++i){ 
      var op = document.createElement("Option"); 
      op.innerHTML = t[i];       
      op.value = v[i];     
      _ddl.appendChild(op); 
   } 
   /******* Set resorts dropdown value according to best destination dropdown *******/
   if(resortsid!=0)
   {for(i=0;i<_ddl.length;i++)
    {   if(_ddl.options[i].value.split('|')[0] == resortsid)
        {_ddl.value = _ddl.options[i].value;}
    }
   }
   /******* Set best destination dropdown value according to resorts dropdown *******/
   try
   {    var objbest = document.getElementById(cntbest);
        for(i=0;i<objbest.length;i++){    
            if (objbest.options[i].value.split('|')[0]=="r")
            {   if(objbest.options[i].value.split('|')[3] == _ddl.value.split('|')[0])
                {objbest.value = objbest.options[i].value;}
            }
        }
    }
    catch(ex){}
   /* Set first selected resorts value to resorts hidden feild */
    var cntr = document.getElementById(Objdes);
    document.getElementById(objhdnRest).value = cntr.options[cntr.selectedIndex].text;
}

populateCarResDDL = function(v,t)
{  _ddl = document.getElementById(Objdes); 
   _ddl.disabled=false;   
   while (_ddl.childNodes.length >0)
   {_ddl.removeChild(_ddl.childNodes[0]); } 
   var count = v.length;
   for (var i=0; i<v.length; ++i){ 
      var op = document.createElement("Option"); 
      op.innerHTML = t[i];       
      op.value = v[i];     
      _ddl.appendChild(op); 
   } 
    var cntr = document.getElementById(Objdes);
    document.getElementById(objhdnRest).value = cntr.options[cntr.selectedIndex].text;
}

GetDDlDate=function ()
{var val1=5;}

/* Set the Default value in Destination (F+H+C)*/
SetDeafult=function (v1,tx1)
{ _ddl = document.getElementById(Objdes); 
  _dres = document.getElementById(ObjRst); 
  while (_ddl.childNodes.length >0)
  {_ddl.removeChild(_ddl.childNodes[0]); } 
   var o = document.createElement("Option"); 
   o.innerHTML = tx1;
   o.value =v1; 
   _ddl.appendChild(o); 
   _ddl.disabled=false;    
   while (_dres.childNodes.length >0)
   {_dres.removeChild(_dres.childNodes[0]); } 
   var o = document.createElement("Option"); 
   o.innerHTML = "[Search All Locations]";
   o.value =v1; 
   _dres.appendChild(o); 
   _dres.disabled=false;
  /* Set destination and resort value when both not found - By bhanwar 30 April 2008 */
    document.getElementById(objhdnDest).value = _ddl.options[_ddl.selectedIndex].text;
    document.getElementById(objhdnRest).value = _dres.options[_dres.selectedIndex].text;
}
/*Set the Default value in Resorts*/
SetResDeafult=function()
{ _dres = document.getElementById(Objdes); 
  while (_dres.childNodes.length >0)
  {_dres.removeChild(_dres.childNodes[0]); } 
   var o = document.createElement("Option"); 
   o.innerHTML = "[Search All Locations]";
   o.value =0; 
   _dres.appendChild(o); 
   _dres.disabled=false;
  /* Set resort value when resort not found - 30 April 2008 */
    var cntr = document.getElementById(Objdes);
    document.getElementById(objhdnRest).value = cntr.options[cntr.selectedIndex].text;
}
