//function to remove options

function RemoveOptions(objCal)
{
   if (objCal.options.length > 0 )
   {
		for(i=0;objCal.options.length;i++)
		{
			objCal.options[0] = null;
		}
   }
}

function FillCountryCombo(country,city)
{
	
	var ArrayCountry = strcountry.split("~")
	var k =1;
	var pos=0;
	RemoveOptions(document.searchForm.cmbCountry)
	document.searchForm.cmbCountry.options[0] = new Option("-- Select a Country --",0);

	for(i=0;i<ArrayCountry.length;i++)
	{
		if(country==ArrayCountry[i])
			pos=i+1;
			document.searchForm.cmbCountry.options[k] = new Option(ArrayCountry[i],ArrayCountry[i]);
			k+=1;
	}
	document.searchForm.cmbCountry[pos].selected=true;
	if(pos!=0)
	  {	    
	      PopulateCountryCity(city)
	      PopulateCityHotel()	          
	  }
	  
}

function PopulateCountryCity(city)
{  

  RemoveOptions(document.searchForm.cmbHotel)
 document.searchForm.cmbHotel.options[0] = new Option("--Select a Hotel--",0);
	
	var selectedCountry = document.searchForm.cmbCountry.options[document.searchForm.cmbCountry.selectedIndex].value;
	var ArrayCity = strcity.split("||")
	var ArrayCountryCity = strcitycountry.split("~~")
	var k =1;
	var pos=0;
	RemoveOptions(document.searchForm.cmbCity)
	document.searchForm.cmbCity.options[0] = new Option("--Select a City--",0);
       
	for(j=0;j<ArrayCity.length;j++)
	{
		var cc = selectedCountry + "~" +ArrayCity[j];
		for(i=0;i<ArrayCountryCity.length;i++)
		{
		
			if (ArrayCountryCity[i]==cc)
			{
				
				if(city==ArrayCity[i])
				  	pos=k;
				 
				document.searchForm.cmbCity.options[k] = new Option(ArrayCity[i],ArrayCity[i]);
				k+=1;
			}
		}
	}
	
   if(document.searchForm.cmbCity.length==2)
	{
	document.searchForm.cmbCity[1].selected =true;
	PopulateCityHotel();
	}
	else
	{
	document.searchForm.cmbCity[pos].selected =true;
	document.searchForm.cmbHotel[0].selected =true;
	}
	//document.searchForm.cmbCity[pos].selected =true;
}
function PopulateCityHotel()
{    
	var selectedCountry = document.searchForm.cmbCountry.options[document.searchForm.cmbCountry.selectedIndex].value;
	var selectedCity2 = document.searchForm.cmbCity.options[document.searchForm.cmbCity.selectedIndex].value;
	
	var ArrayHotel = strhotel.split("||");
	var ArrayCityHotel = strcityhotel.split("~~");
	var k =1;
		
	RemoveOptions(document.searchForm.cmbHotel)
	document.searchForm.cmbHotel.options[0] = new Option("--Select a Hotel--",0);
	for(j=0;j<ArrayHotel.length;j++)
	{
		var cc = selectedCity2 + "~" +ArrayHotel[j];
		//alert (cc);
		for(i=0;i<ArrayCityHotel.length;i++)
		{
			if (ArrayCityHotel[i]==cc)
			{
				var tryFurther=ArrayCityHotel[i];
				var tryFurtherMore=tryFurther.split("~")
				//alert (tryFurtherMore[1]);
				
				document.searchForm.cmbHotel.options[k] = new Option(tryFurtherMore[1].replace("&#39;","'"),tryFurtherMore[2]);
				
				k+=1;
			}
		}
	}
	if(document.searchForm.cmbHotel.length==2)
	document.searchForm.cmbHotel[1].selected =true;
	else
	document.searchForm.cmbHotel[0].selected =true;
	//document.searchForm.cmbHotel[0].selected =true;
}	
function hotelcount(city)
{
var flg=0;
var hotelname;
  var ArrayCityHotel = strcityhotel.split("~~");
  for(m=0;m<ArrayCityHotel.length;m++)
     {
       var countarray=new Array();
       var ctyhotel=ArrayCityHotel[m];
       countarray=ctyhotel.split("~");
       //alert(countarray[0]);
       if(countarray[0]==city)
        {
        flg++;
        hotelname=countarray[2]+"|"+countarray[1];
        }
        
     }
     if(flg==1)
        {
        return hotelname;
        }
        else
        {
        return "abc";
        }
  
}

function opennewwin(url)
{
window.open(url);
}
