
// String Format
// City Code_Country Code_City Name_Country Name

//Tehran Country City
var str21 = "2151_21_Azadi (5 Star)_Tehran*2152_21_Esteghlal (5 Star)_Tehran*2153_21_Laleh (5 Star)_Tehran*2154_21_Homa (5 Star)_Tehran*2141_21_Enghelab (4 Star)_Tehran*2142_21_Howeyzeh (4 Star)_Tehran*2143_21_Simorgh (4 Star)_Tehran*2143_21_Grand Hotel (4 Star)_Tehran*2144_21_Kowsar (4 Star)_Tehran*2145_21_Ferdossi Grand (4 Star)_Tehran*2131_21_Mashad (3 Star)_Tehran*2121_21_Parastoo (2 Star)_Tehran"
// Isfahan Country City
var str311 = "31151_311_Abbasi (5 Star)_Isfahan*31152_311_Kowsar (5 Star)_Isfahan*31141_311_Aseman (4 Star)_Isfahan*31142_311_Zohreh (4 Star)_Isfahan*31143_311_Aliqapu (4 Star)_Isfahan*31144_311_Sadaf (4 Star)_Isfahan*31144_311_Safir (4 Star)_Isfahan*31145_311_Piroozy (4 Star)_Isfahan*31131_311_Suite (3 Star)_Isfahan*31132_311_Isfahan (3 Star)_Isfahan*31133_311_Azady (3 Star)_Isfahan*31134_311_Tourist (3 Star)_Isfahan*31121_311_Julfa (4 Star)_Isfahan"
// Shiraz Country City
var str711 = "71151_711_Homa (5 Star)_Shiraz*71152_711_Pars (5 Star)_Shiraz*71141_711_Aryo Barzan (4 Star)_Shiraz*71131_711_Parsian (3 Star)_Shiraz*71132_711_Eram (3 Star)_Shiraz*71121_711_Sadra (2 Star)_Shiraz*"

//str711 + '*' + 

var strcountrycity = str21 + '*' + str311 + '*' + str711

function loadCountry(country, countryID){
	
	var country
	var country_list
	var arrTemp2			= strcountrycity.split ("*");
	var cnt2				= arrTemp2.length;
	var ArrcountryList		= new Array ();
	var i = 0;
		
	ArrcountryList = arrTemp2[0].split("_")
			
	countryMakeOnchange(country, countryID);

	j=0;
	var arrSelectOptions = new Array();
	for (i = 0; i < cnt2; i++)
	{		
		ArrcountryList = arrTemp2[i].split("_");
		countryOption = new SelectOption(ArrcountryList[1], ArrcountryList[3]);
		
		if (AlreadyInArray(arrSelectOptions, countryOption, j) == false)
			arrSelectOptions[j++] = countryOption;
	}
	CreateControl("var_country", arrSelectOptions, j, country);	
}

/////////////////////////////////////////////////////////////////

function CreateControl(pControlName, arrSelectOptions, size, selected_value)
{
	var control = document.forms["asiatravel"].elements[pControlName];
	control.length = (size + 1);
	var j = 1;
	for (i=0; i<size; i++)
	{					
		control.options[0].value = 0;
		control.options[0].text = "select City";
		control.options[j].value = arrSelectOptions[i].value;
		control.options[j].text = arrSelectOptions[i].text;
		if (arrSelectOptions[i].value == selected_value)
		control.options[j].selected = 1;
		j++;		
	}
}

/////////////////////////////////////////////////////////////////

function SelectOption(pValue, pText)
{	
	this.value=pValue;
	this.text=pText;
}

/////////////////////////////////////////////////////////////////

function AlreadyInArray(arrSelectOptions, Option, size)
{
	for(i=0;i<size;i++)
		if(arrSelectOptions[i].value == Option.value)
			return true;
	return false;
}

/////////////////////////////////////////////////////////////////

function countryMakeOnchange(country, countryID){
	
	var arrTemp2			= strcountrycity.split ("*");
	var cnt2				= arrTemp2.length;
	var ArrcountryList	    = new Array ();
	var j = 1; 
	var i = 0;
	var city_value = new Array();
	var city_text = new Array();				
	var cityList = "";
	
	if (countryID == 0){
		if (country == 16){
			countryID = 10;
		}else if(country == 146){
			countryID = 282;
		}else if(country == 150){
			countryID = 338;
		}else if(country == 144){
			countryID = 331;
		}else if(country == 1){
			countryID = 2;
		}else if(country == 17){
			countryID = 11;
		}else if(country == 147){
			countryID = 283;
		}else if(country == 176){
			countryID = 611;
		}else if(country == 184){
			countryID = 666;
		}else if(country == 196){
			countryID = 731;
		}else if(country == 183){
			countryID = 660;
		}else if(country == 188){
			countryID = 680;
		}else if(country == 175){
			countryID = 619;
		}else if(country == 195){
			countryID = 718;
		}else if(country == 'AU'){
			countryID = 'Sydney';
			document.asiatravel.OfficeID.value = '2'
			document.asiatravel.CountryInCharge.value = 'Singapore'
			document.asiatravel.RsvOfcr.value = 'jojo'
			document.asiatravel.action = 'http://www.instantrooms.com/xmlPro/xmlPro_00.aspx'
		}		
	}	
			
	if (country != 0){	
				
		for (i = 0; i < cnt2; i++){
			ArrcountryList = arrTemp2[i].split("_")
					
			if (ArrcountryList[1]  == country){
									
				city_value[j]  = ArrcountryList[0];
				city_text[j++] = ArrcountryList[2];
			}			
		}		

		document.forms["asiatravel"].var_city.length = j;
					
		for (i = 1; i < j; i++){
												
			document.forms["asiatravel"].var_city.options[i].value = city_value[i];
			document.forms["asiatravel"].var_city.options[i].text = city_text[i];
			
			if (city_value[i] == countryID){
				document.asiatravel.var_city.options[i].selected = 1;
			}
						
			if (i < j - 1){
				cityList = cityList + city_text[i] + '#' +	city_value[i] + '$'
			}else{
				cityList = cityList + city_text[i] + '#' +	city_value[i] 
			}	
		}

	}	
	
	else{
		
	    document.asiatravel.var_country.options[0] = new Option("select City", "-");
		document.asiatravel.var_country.options[0].selected = 1;
		document.asiatravel.var_country.selectedIndex = 0;
		document.asiatravel.var_country.length = 1;
		
        document.asiatravel.var_city.options[0] = new Option("Select Hotel", "-");
		document.asiatravel.var_city.options[0].selected = 1;
		document.asiatravel.var_city.selectedIndex = 0;
		document.asiatravel.var_city.length = 1;				
	}	
	
	document.forms["asiatravel"].var_citylist.value = cityList;
	
}
