﻿// JScript File
var pCityNameArr = new Array();
buildCountryList(countrycitydet);

function buildCountryList(countrycitySTR)
{   //alert(countrycitySTR)
	if (countrycitySTR!="")
	{
		var CountryCityARR = countrycitySTR.split("|");	//long string
		for (var i=0;i<CountryCityARR.length;i++)
		{
			var cityArr = CountryCityARR[i].split("~");	//join of country and city
			
			pCityNameArr[i]	=	new Array();
			
			for (var j=0;j<cityArr.length;j++)
			{
				//if (j==0) alert(cityArr[j]);
				
				pCityNameArr[i][j] = cityArr[j];
			}
			//alert(CountryCityARR[i]);
			
			/*alert(pCityNameArr[i][0]);
			alert(pCityNameArr[i][1]);
			alert(pCityNameArr[i][2]);*/
			// alert(pCityNameArr[i].length);
		}
	}
} 


function buildCitySelection(objCountry,objCity, objCityCode)
{  
	var aCity;
	var countryval = objCountry.options[objCountry.selectedIndex].value;	//the selected country
	var oCity =  objCity;//document.form1.city;					//the city object
	oCity.length=0;
	oCity.options[0]=new Option('-- Select --  ','');
	var cVal = objCityCode.value;
    //alert(countryval)
    //alert(cVal)
	if (countryval!='')
	{
		//alert(obj.options[obj.selectedIndex].value)
		
		//refresh the city drop down 
		for (k=0;k<pCityNameArr.length;k++)
		{
			//if ((pCityNameArr[k][0])==countryval)
			
			var pCountryCity = pCityNameArr[k][0];			

			if (pCountryCity.toUpperCase()==countryval.toUpperCase())
				{ 
					//alert(pCityNameArr[k].length) 
					for (c=1;c<pCityNameArr[k].length;c++)
					{
						oCityArr = pCityNameArr[k][c].split("+");//split for location(supplier or h2h)
						oCity.options[c]=new Option(oCityArr[1],oCityArr[0]);
						
						if (cVal==oCityArr[0]){
							oCity.options[c].selected=true;
						}
					}
				}			
		}
		
	}


if (objCountry.options[objCountry.selectedIndex].value=="")
	{objCity.options[0].text="(Select country first)";}
else
	{objCity.options[0].text="-- Select --";}
}

