// 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(ddlTourCruises.options.length>0)
         {
          ddlTourCruises.removeChild(ddlTourCruises.firstChild);
          funRemoveSubCatoptions(formname);
         }
     }
}
function funRemoveSubCat(formname)
{
  with(document.forms[formname])
 {   
         if(ddlTourCruises.options.length>0)
         {
			 
			  ddlTourCruises.removeChild(ddlTourCruises.firstChild);
			  funRemoveSubCat(formname);
         }
     }
}

function funCallSubCatAjax(formname,catCtrlName,subCatCtrlName)
{ 
 with(document.forms[formname])
 {   
    var DrpDwnVal = ddlDestination.value;   
   
    if(formname=="frmPassengerMemories")
    {
    funRemoveSubCat(formname);
    hdnSubcat.value="";
    }
    else
    funRemoveSubCatoptions(formname);
    
    if(DrpDwnVal!="")
    {      
	 
      url="ajax_loadsubcat.aspx?catid="+DrpDwnVal;
   
      //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)
      {     
        if(formname=="frmManageInstaAdImages")
       {      
        http_req.onreadystatechange = funInsrtSubCat;
       }
       else if(formname=="frmPassengerMemories")
       {
         http_req.onreadystatechange = funInsrtSubCatlist;
       }	 
       else 
       {     
        http_req.onreadystatechange = funInsrtSubCatview;
       }
       http_req.open("GET", url, true);
       http_req.send("");
       
      }
  }
  else
  {
    var optn = document.createElement("OPTION");
          optn.text = "--- Select Tour/Cruise ---";
          optn.value = "";
          f.ddlTourCruises.options.add(optn);   
  }
 }
}


function funInsrtSubCatlist()
{ 
  if(http_req.readyState == 4)
  {
    txt = http_req.responseText;
	
    f = document.frmPassengerMemories;
    // alert("===view images ====="+txt);
	
      var optn = document.createElement("OPTION");
      optn.text = "--- Select Tour/Cruise ---";
      optn.value = "";
      f.ddlTourCruises.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.ddlTourCruises.options.add(optn);

          }//arrSubcatIdsAndNames[i]!="" check ends

        }//for loop ends
    }

  }
}
function funInsrtSubCatview()
{ 
  if(http_req.readyState == 4)
  {
    txt = http_req.responseText;
   //alert("===add edit delete cat ====="+txt);
     
    f = document.frmManageSportsCategories;

      var optn = document.createElement("OPTION");
      optn.text = "--- Select Tour/Cruise ---";
      optn.value = "";
      f.ddlTourCruises.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.ddlTourCruises.options.add(optn);

          }//arrSubcatIdsAndNames[i]!="" check ends

        }//for loop ends
    }

  }
}

function funInsrtSubCat()
{ 
  if(http_req.readyState == 4)
  {
    txt = http_req.responseText;
    //alert("===images====="+txt);
    f = document.frmManageInstaAdImages;

      var optn = document.createElement("OPTION");
      optn.text = "--- Select Tour/Cruise ---";
      optn.value = "";
      f.ddlTourCruises.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.ddlTourCruises.options.add(optn);

          }//arrSubcatIdsAndNames[i]!="" check ends

        }//for loop ends
    }
  }
}

function fncatsub()
{
	with(document.forms["frmPassengerMemories"])
	{   
		var DrpDwnVal = ddlTourCruises.value; 
	    hdnSubcat.value=  DrpDwnVal;
		
    }
}
