
var COUNTRY = 'COUNTRY';
var CITY = 'CITY';
var RESORT = 'RESORT';

  function loadCountries(){


     
     document.Search1.selCountry.remove(0);


     var countryArray = countryListCommonIndex.split(","); 
	 
     for(i=0; i<countryArray.length;i+=2)
	 {
		
     //document.Search1.selCountry.add(new Option(countryArray[i+1],countryArray[i])); on ie
	 
	 
	 var optn = document.createElement("OPTION");
	optn.text = countryArray[i+1] ;//countryArray[i+1];
	optn.value = countryArray[i];
	
	
	 
	 document.Search1.selCountry.options.add(optn);
     }

    document.Search1.selCountry.selectedIndex =  document.Search1.lastCountryIndex.value;	
      


  }

  function selectCity(p_oSelItem){


    var optCount = document.Search1.selCity.options.length ;
    

    for(l = 0 ;l < optCount ;l++){
	document.Search1.selCity.remove(0);
    }

    if(p_oSelItem.value != ""){
      var cityArray = eval(p_oSelItem.value).split(",");
      for(i=0;i<cityArray.length;i+=3){
//       document.Search1.selCity.add(new Option(cityArray[i+1],cityArray[i])); ie

	 var optn = document.createElement("OPTION");
	optn.text = cityArray[i+1];
	optn.value = cityArray[i];
	 document.Search1.selCity.options.add(optn); 


      }


    }
    selectResort(document.Search1.selCity, 'selResort');          
    changeCity(document.Search1.selCity);
    
		
  }

  function selectLastCity(){

       document.Search1.selCity.selectedIndex = document.Search1.lastCityIndex.value;

  }

  function changeCity(p_oSelItem){


   if( p_oSelItem.options.length > 0 )
    {
        var cityOption = p_oSelItem.options[p_oSelItem.selectedIndex];
        if( cityOption.text.indexOf("--Any--") > -1 )
        {
            cityOption = document.getElementById("selCity").options[document.getElementById("selCity").selectedIndex];
        }
        var countryOption = document.getElementById("selCountry").options[document.getElementById("selCountry").selectedIndex];
        //document.Search.selCityA.value = cityOption.text;
        document.getElementById("countryCodeSelected").value = countryOption.value;
        document.getElementById("countrySelected").value = countryOption.text;
        document.getElementById("destinationCodeSelected").value = cityOption.value;
        document.getElementById("destinationSelected").value = cityOption.text;
    }
//    var cityOption = p_oSelItem.options[p_oSelItem.selectedIndex];
//
//
//    var countryOption = document.Search1.selCountry.options[document.Search1.selCountry.selectedIndex];
//
//
//    //document.Search1.selCityA.value = cityOption.text;
//
//
//	document.Search1.countryCodeSelected.value = countryOption.value;
//	document.Search1.countrySelected.value = countryOption.text;
//	document.Search1.destinationCodeSelected.value = cityOption.value;
//	document.Search1.destinationSelected.value = cityOption.text;
     

/* kishantha - 19-10-2006

	var optCount = document.Search1.selCity.options.length ;
	for(l = 0; l < optCount; l++  ){
		document.Search1.selZone.remove(0);
	}	

	//a = document.getElementById("sortAreaTable");

	oZoneRow = document.getElementById("zoneRow");
	try{
           	var aZone = eval(cityOption.value).split(',');
	      for(i= 0; i < aZone.length;i+=2 ){
			document.Search1.selZone.add(new Option(aZone [i+1],aZone [i]));
		}
		oZoneRow.style.display = 'inline';

	}catch(exceptionNoZone){
		oZoneRow.style.display = 'none';
	}
	
	*/
  }


function changeZone(p_oSelItem){
// document.Search1.stateCodeSelected.text = p_oSelItem.options[p_oSelItem.selectedIndex].value;
 document.Search1.areaSelected.text = p_oSelItem.options[p_oSelItem.selectedIndex].value;

}

  /**
   * p_oCity City option object.
   * Id of the Resort option.
   */
  function selectResort( p_oCity, resortId )
  {
      var obj = document.getElementById(resortId);
      obj.length = 0;
      var index = -1;

      if( p_oCity.value != "" )
      {
          var cityArray;
          try
          {
              cityArray = eval(p_oCity.value).split(",");
          }
          catch(err)
          {
          }
          for( var x = 0; x < obj.length; x++ )
          {
              obj.remove(0);
          }
          if( cityArray != null )
          {
              if( cityArray.length > 0 )
              {
                  obj.disabled = false;                                  
                  obj.options[++index] = new Option("--Any--", "");
              }
              else if( cityArray.length == 0 )
              {
                  obj.disabled = true;
              }
              for( var i = 0; i < cityArray.length; i += 2 )
              {
                  obj.options[++index] = new Option(cityArray[i + 1], cityArray[i]);

              }
              changeCity(document.Search1.selResort);
          }
          else
          {
              obj.disabled = true;
              changeCity(document.Search1.selCity);
          }
      }
  }


  /**
   * p_Code Root code of the item. For cities of the france FR.
   * p_SelectId ID of the select option object.
   * type Type of the list to parse, Country, City, or resor.
   * p_ItemCode Code to be selected.
   */
  function loadSelected( p_Code, p_SelectId, type, p_ItemCode )
  {
      var obj = document.getElementById(p_SelectId);
      obj.length = 0;
      var index = -1;
      var oArray = "";
      var selectedIndex = 0;
      var tempIndex = 0;
      var period = 2;
      if( type.indexOf(this.CITY) > -1 )
      {
          period = 3;
      }
      try
      {
          if( type.indexOf(this.COUNTRY) > -1 )
          {
              oArray = eval('countryListCommonIndex').split(",");
              //alert(oArray)
          }
          else
          {
              oArray = eval(p_Code).split(",");
          }
      }
      catch( err )
      {
      }
      for( var x = 0; x < obj.length; x++ )
      {
          obj.remove(0);
      }
      if( oArray != null )
      {
          if (type.indexOf(this.RESORT) > -1 && oArray.length > 0)
          {
              obj.disabled = false;
              obj.options[++index] = new Option("--Any--", "");
              tempIndex++;
          }
          else if (type.indexOf(this.RESORT) > -1 && oArray.length == 0)
          {
              obj.disabled = true;
          }
          for( var i = 0; i < oArray.length; i += period )
          {
              obj.options[++index] = new Option(oArray[i + 1], oArray[i]);
              if( oArray[i] == p_ItemCode )
              {
                  selectedIndex = tempIndex;
              }
              tempIndex++;
          }
      }
      else if(type.indexOf(this.RESORT) > -1 )
      {
          obj.disabled = true;
      }
      obj.selectedIndex = selectedIndex;
      changeCity(obj);
  }

function getOptionIndex(p_Code, p_ElementId)
{
    var obj = document.getElementById(p_ElementId);
    var optionLength = obj.options.length;
    for (var i = 0; i < optionLength; i++)
    {
        if (obj.options[i].value == p_Code )
        {
            return i;
        }
    }
    return 0;
}