// JScript File
// Get base url
url = document.location.href;
xend = url.lastIndexOf("/") + 1;
var base_url = url.substring(0, xend);

var  http_req;

function funRemoveSubCatoptions(formname)
{
  with(document.forms[formname])
 {   
         if(ddlProgram.options.length>0)
         {
          ddlProgram.removeChild(ddlProgram.firstChild);
          funRemoveSubCatoptions(formname);
         }
     }
}
function funRemoveSubCat(formname)
{
  with(document.forms[formname])
 {   
         if(ddlDestination.options.length>0)
         {
			  ddlDestination.removeChild(ddlDestination.firstChild);
			  funRemoveSubCat(formname);
         }
     }
}

function funCallSubCatAjax(formname,catCtrlName,subCatCtrlName)
{ 	
	 with(document.forms[formname])
	 { 
		var DrpDwnVal = ddlRegion.value;   
	    funRemoveSubCat(formname);
	    funRemoveSubCatoptions(formname);
		if(DrpDwnVal!="")
		{      
		 
		  url="ajax_dest_region.aspx?catid="+DrpDwnVal +"&year="+ document.getElementById("pgmyear").value;;
		  
		  //Does URL begin with http?
		  if(url.substring(0, 4) != 'http') 
		  {
			url = base_url + url;
		  }

		  http_req = null;

		  if (window.XMLHttpRequest)     http_req = new XMLHttpRequest();
		  else if (window.ActiveXObject) http_req = new ActiveXObject("Microsoft.XMLHTTP");
 
		  if (http_req)
		  {     
     			http_req.onreadystatechange = funInsrtSubCat;
				
				http_req.open("GET", url, true);
				http_req.send("");		   
		  }
		}
		else
		{
			var optn = document.createElement("OPTION");
			optn.text = "--- Choose all ---";
			optn.value = "";
			ddlDestination.options.add(optn); 
			
			var optn1 = document.createElement("OPTION");
			optn1.text = "--- Choose all ---";
			optn1.value = "";
			ddlProgram.options.add(optn1);  
		}
	}
}

function funInsrtSubCat()
{ 
	if(http_req.readyState == 4)
	{	 
	  txt = http_req.responseText;
	  
	  f = document.fmfindcruise;
	  var optn = document.createElement("OPTION");
      optn.text = "--- Choose all ---";
      optn.value = "";
      f.ddlDestination.options.add(optn);
        
      g = document.fmfindcruise;
	  var optn1 = document.createElement("OPTION");
      optn1.text = "--- Choose all ---";
      optn1.value = "";
      g.ddlProgram.options.add(optn1);
      
    var arrTxt = txt.split("@");    
    if(trimAll(arrTxt[0])!="")
    {
        var arrSubcatIdsAndNames = arrTxt[0].split("#");

        for(var i=0;i<arrSubcatIdsAndNames.length;i++)
        {  
          if(arrSubcatIdsAndNames[i]!="")
          {
              var arrNames = arrSubcatIdsAndNames[i].split("^");
              var strId = arrNames[0];
              var strNames = arrNames[1];

              optn = document.createElement("OPTION");
              optn.text = strNames;
              optn.value = strId;
              f.ddlDestination.options.add(optn);

          }//arrSubcatIdsAndNames[i]!="" check ends

        }//for loop ends
    }
  }
}

function fncatsubAjax(formname,catCtrlName,subCatCtrlName,loadyear)
{

 with(document.forms[formname])
 {   
    var DrpDwnVal = ddlRegion.value; 
    var DrpDwnValDest = ddlDestination.value;    
	    funRemoveSubCatoptions(formname);
		if(DrpDwnValDest!="")
		{      
		 
		  url="ajax_program.aspx?catid="+DrpDwnVal+"&destid="+DrpDwnValDest+"&year="+ document.getElementById("pgmyear").value + "&type=Cruise";
		  
		  //Does URL begin with http?
		  if(url.substring(0, 4) != 'http') 
		  {
			url = base_url + url;
		  }

		  http_req = null;

		  if (window.XMLHttpRequest)     http_req = new XMLHttpRequest();
		  else if (window.ActiveXObject) http_req = new ActiveXObject("Microsoft.XMLHTTP");
 
		  if (http_req)
		  {     
     			http_req.onreadystatechange = funInsrtSubCatPrg;
				
				http_req.open("GET", url, true);
				http_req.send("");		   
		  }
		}
		else
		{
			var optn = document.createElement("OPTION");
			optn.text = "--- Choose all ---";
			optn.value = "";
			ddlProgram.options.add(optn);   
		}
	}
}

function funInsrtSubCatPrg()
{ 
	if(http_req.readyState == 4)
	{	 
		txt = http_req.responseText;
		
	  f = document.fmfindcruise;
	  var optn = document.createElement("OPTION");
      optn.text = "--- Choose all ---";
      optn.value = "";
      f.ddlProgram.options.add(optn);

    var arrTxt = txt.split("@");    
    if(trimAll(arrTxt[0])!="")
    {
        var arrSubcatIdsAndNames = arrTxt[0].split("#");

        for(var i=0;i<arrSubcatIdsAndNames.length;i++)
        {  
          if(arrSubcatIdsAndNames[i]!="")
          {
              var arrNames = arrSubcatIdsAndNames[i].split("^");
              var strId = arrNames[0];
              var strNames = arrNames[1];

              optn = document.createElement("OPTION");
              optn.text = strNames;
              optn.value = strId;
              f.ddlProgram.options.add(optn);

          }//arrSubcatIdsAndNames[i]!="" check ends

        }//for loop ends
    }
  }
}

