var kita;
var recordCnt;
var m_recordCnt = 70;
var alphabetObj;
var listObj1;
var listObj2;
var navObj;
function kaybol(katman)
{
	if(document.all){
		document.all[katman].style.display = "none";
	}else if(document.layers){
		document.layers[katman].display = "none";
	}else{
		document.getElementById(katman).style.display= "none";
	}
}

function gorun(katman)
{
	if(document.all){
		document.all[katman].style.display = "";
	}else if(document.layers){
		document.layers[katman].display= "";
	}else{
		document.getElementById(katman).style.display= "";
	}
}

function nothing(){}
function putCities(){
	var option = null;
	var cityName = "";
	for(var i=0;i<arguments.length;i++){
		indOf = arguments[i].indexOf("|");
		cityName = arguments[i].substring(indOf+1,arguments[i].length);
		option = new Option(cityName,arguments[i]);
		document.cityListForm.cityList.options[i] = option;
	}
}
function removeCity(){
	var o = document.cityListForm.cityList;
	for(var i=o.options.length-1;i>-1;i--){
		if(o.options[i].selected){
			o.options[i] = null;
		}	
	}
}
function removeForeign(){
	var o = document.addCityForm.optForeignCities;	
	for(var i=o.options.length-1;i>0;i--) o.options[i] = null;
	
	var o = document.addCityForm.optState;
	for(var i=o.options.length-1;i>0;i--) o.options[i] = null;
	kaybol("trstate");
	kaybol("trstatefree");
	
	var o = document.addCityForm.optCountry;
	for(var i=o.options.length-1;i>0;i--) o.options[i] = null;
	
	document.addCityForm.optLocations.selectedIndex=0;
	document.addCityForm.optCountry.selectedIndex=0;
	document.addCityForm.optState.selectedIndex=0;
	document.addCityForm.optForeignCities.selectedIndex=0;
}

function addCity(){
	var oCitylist = document.cityListForm.cityList;
	if(oCitylist.options.length >=5){
		alert("Lütfen en fazla 5 şehir seçiniz");
		return false;
	}
	else{
		var oCities;
		if(document.addCityForm.optCities.selectedIndex != 0) oCities = document.addCityForm.optCities;
		else if(document.addCityForm.optForeignCities.selectedIndex != 0) oCities = document.addCityForm.optForeignCities;
		else{
			alert("Lütfen eklemek istediğiniz şehri seçiniz!");
			return false;
		}
		var cityName = oCities.options[oCities.options.selectedIndex].text;
		var isFound = false;
		for(i=0;i<oCitylist.options.length;i++){
			if(oCitylist.options[i].value == oCities.value+"|"+cityName){
				isFound = true;
				break;
			}
		}
		if(!isFound){
			var option = new Option(cityName,oCities.value+"|"+cityName);
			oCitylist.options[oCitylist.options.length] = option;
		}
		else{
			alert("Bu şehir listenizde zaten var!");
			return false;
		}
	}
}
function done(){
	var o = document.cityListForm.cityList;
	if(o.length < 1){
		alert("Lütfen en az 1 şehir seçiniz.");
		return false;
	}
	
	if(o.length == 0){
		var confirmation = confirm("Şehir eklemeden devam ederseniz  İstanbul, Ankara ve İzmir seçili gelecektir.\nDevam etmek istiyor musunuz?");
		if (confirmation) document.cityListForm.submit();
		else return false;
	}
	else{
		var cities = "";
		for(var i=0;i<o.length;i++){
			cities = cities + o.options[i].value + ";"
		}
		document.cityListForm.cities.value = cities;
		document.cityListForm.submit();
	}
}
function foreignDone(){
	var o;
	for(var i=0;i<countries.length;i++){
		if (countries[i].countryID == document.addCityForm.optCountry.value){
			if(countries[i].countryHAVESTATE == "1")
			{
				if(document.addCityForm.optState.selectedIndex==0)
				{
					getState(document.addCityForm,document.addCityForm.optCountry.value);
					gorun("trstate");
					gorun("trstatefree");
					return;
				}
			}else{
				o = document.addCityForm.optState;
				for(var j=o.options.length-1;j>0;j--) o.options[j] = null;
				kaybol("trstate");
				kaybol("trstatefree");
			}
		}
	}
	
	
	o = document.cityListForm.cityList;
	var cities = "";
	var country="";
	var state="";
	for(var i=0;i<o.length;i++){
		cities = cities + o.options[i].value + ";"
	}
	document.addCityForm.cities2.value = cities;
	document.addCityForm.loccntrl.value = "1";//yurtdışı kombolarını seçili hale getiriyor
	
	o = document.addCityForm.optCountry;
	for(var i=0;i<o.length;i++){
		country = country + o.options[i].value + "|" + o.options[i].text + ";"
	}
	
	o = document.addCityForm.optState;
	for(var i=0;i<o.length;i++){
		state = state + o.options[i].value + "|" + o.options[i].text + ";"
	}
	

	WriteCookie("locidx",document.addCityForm.optLocations.options.selectedIndex,60);
	WriteCookie("countryidx",document.addCityForm.optCountry.options.selectedIndex,60);
	WriteCookie("stateidx",document.addCityForm.optState.options.selectedIndex,60);
	WriteCookie("selcountry",country,60);
	WriteCookie("selstate",state,60);
	
	document.addCityForm.submit();
}
function SelectIdx(locidx,countryidx,stateidx,selcountry,selstate)
{
	var country;
	var state;
	var Name = "";
	var Code = "";
	
	country = selcountry.split(";");
	for(var i=0; i<country.length-1;i++)
	{
		indOf = country[i].indexOf("|");
		Code = country[i].substring(0,indOf);
		Name = country[i].substring(indOf+1,country[i].length);
		
		option = new Option(Name,Code);
		document.addCityForm.optCountry.options[i] = option;
	}
	
	state = selstate.split(";");
	for(var i=0; i<state.length-1;i++)
	{
		indOf = state[i].indexOf("|");
		Code = state[i].substring(0,indOf);
		Name = state[i].substring(indOf+1,state[i].length);
		
		option = new Option(Name,Code);
		document.addCityForm.optState.options[i] = option;
	}

	if(stateidx>0)
	{
		gorun("trstate");
		gorun("trstatefree");
	}


	document.addCityForm.optLocations.options.selectedIndex = locidx;
	document.addCityForm.optCountry.options.selectedIndex = countryidx;
	document.addCityForm.optState.options.selectedIndex = stateidx;
}
function goDetail(cityCode,cityName){
	if(cityCode == "") return false;
	document.location.href = "/expWeather/?cityCode=" + escape(cityCode) + "&cityName=" + escape(cityName);
}
function getForeignCities(o,locationId){
	if(locationId=="--")
		document.location.href="/outhavadurumu.asp";
		
	o.optCities.selectedIndex = 0;
	var o = o.optForeignCities;
	var option;
	var idx = 1;
	for(var i=o.options.length-1;i>0;i--) o.options[i] = null;
	for(var i=0;i<countryCities.length;i++){
		if (countryCities[i].countryID == locationId){
			option = new Option(countryCities[i].cityNAME,countryCities[i].cityID);
			o.options[idx++] = option;
		}
	}
	o.options.selectedIndex = 0;
}

function getCountry(o,locationId){
	o.optCities.selectedIndex = 0;
	o.optCountry.selectedIndex= 0;
	o.optForeignCities.selectedIndex = 0;
	
	
	for(var i=o.optState.options.length-1;i>0;i--) o.optState.options[i] = null;
	for(var i=o.optForeignCities.options.length-1;i>0;i--) o.optForeignCities.options[i] = null;
	kaybol("trstate");
	kaybol("trstatefree");
	
	var o = o.optCountry;
	var option;
	var idx = 1;
	for(var i=o.options.length-1;i>0;i--) o.options[i] = null;
	for(var i=0;i<countries.length;i++){
		if (countries[i].countryCONTINENT == locationId){
			option = new Option(countries[i].countryNAME,countries[i].countryID);
			o.options[idx++] = option;
		}
	}
	o.options.selectedIndex = 0;
}


function getCountryNew(o,locationId){
	o.country.selectedIndex = 0;
	o.state.selectedIndex= 0;
	o.city.selectedIndex = 0;
	document.getElementById("citylayer").innerHTML=  "<select name='city' style='width:155px;'><option value=>Şehir seçiniz</option></select>";

	
	for(var i=o.country.options.length-1;i>0;i--) o.country.options[i] = null;
	for(var i=o.state.options.length-1;i>0;i--) o.state.options[i] = null;
    //for(var i=o.city.options.length-1;i>0;i--) o.city.options[i] = null;
	//kaybol("trstate");
	//kaybol("trstatefree");
	
	var o = o.country;
	var option;
	var idx = 1;
	for(var i=o.options.length-1;i>0;i--) o.options[i] = null;
	for(var i=0;i<countries.length;i++){
     //   if (i<5) {alert(countries[i].countryID);}
        
		if (countries[i].countryCONTINENT == locationId){
			option = new Option(countries[i].countryNAME,countries[i].countryID);
			o.options[idx++] = option;
		}
	}
	o.options.selectedIndex = 0;
}
function getState(o,countryId){
	//o.city.selectedIndex = 0;
	//o.optForeignCities.selectedIndex = 0;
	//document.getElementById("citylayer").innerHTML=  "<select name='city' style='width:155px;'><option value=>Şehir seçiniz</option></select>";

	//for(var i=o.city.options.length-1;i>0;i--) o.city.options[i] = null;
	
	var o = o.state;
	var option;
	var idx = 1;
	for(var i=o.options.length-1;i>0;i--) o.options[i] = null;
	for(var i=0;i<states.length;i++){
		if (states[i].stateCOUNTRY == countryId){
			option = new Option(states[i].stateNAME,states[i].stateID);
			o.options[idx++] = option;
		}
	}
	o.options.selectedIndex = 0;
}

function getStateNew(o,countryId){
	o.state.selectedIndex = 0;
	o.optForeignCities.selectedIndex = 0;
	document.getElementById("citylayer").innerHTML=  "<select name='city' style='width:155px;'><option value=>Şehir seçiniz</option></select>";

	for(var i=o.optForeignCities.options.length-1;i>0;i--) o.optForeignCities.options[i] = null;
	
	var o = o.optState;
	var option;
	var idx = 1;
	for(var i=o.options.length-1;i>0;i--) o.options[i] = null;
	for(var i=0;i<states.length;i++){
		if (states[i].stateCOUNTRY == countryId){
			option = new Option(states[i].stateNAME,states[i].stateID);
			o.options[idx++] = option;
		}
	}
	o.options.selectedIndex = 0;
}

function getContinentName(code)
{
	if(code==1){
		return "Amerika";
	}else if(code==3){
		return "Avrupa";
	}else if(code==4){
		return "Afrika";
	}else if(code==5){
		return "Asya";
	}else{
		return "Avusturalya";
	}
}

function write(aobj,lobj1,lobj2,nobj,loc){
	alphabetObj = aobj;
	listObj1 = lobj1;
	listObj2 = lobj2;
	navObj = nobj;
	recordCnt = m_recordCnt;
	kita = loc;

	document.all[alphabetObj].innerHTML="";
	document.all["captionlinkdiv"].innerHTML=" "+getContinentName(kita);
	document.all["captionlinkdiv2"].innerHTML=" "+getContinentName(kita);
	
	var dizialphabet = new Array("A","B","C","D","E","G","H","I","İ","J","K","L","M","N","O","Ö","P","R","S","Ş","T","U","Ü","V","Y","Z");
	var tmpcountry = new Array();
	var bulundu;
	var withCharacter="";

	tmpcountry = getRelCountry("");
	
	if(tmpcountry.length<=m_recordCnt)
		recordCnt = tmpcountry.length;

	if(tmpcountry.length>recordCnt)
	{
		for(var i=0;i<dizialphabet.length;i++)
		{
			bulundu = false;
			for(var j=0;j<tmpcountry.length;j++){
				if((tmpcountry[j].countryNAME.substring(0,1)).toUpperCase() == dizialphabet[i])
				{
					if(withCharacter=="")
					{
						withCharacter=dizialphabet[i];
					}
					bulundu = true;					
					break;
				}
			}
			if(document.all[alphabetObj].innerHTML != ""){
				document.all[alphabetObj].innerHTML+=" ";
			}
			if(bulundu){
				//document.all[alphabetObj].innerHTML += "<a href='kita.asp?kita="+kita+"&wc="+dizialphabet[i]+"'>"+dizialphabet[i]+"</a>";
				document.all[alphabetObj].innerHTML += "<a href=javascript:CountryList('"+dizialphabet[i]+"',0);>"+dizialphabet[i]+"</a>"
			}else{
				document.all[alphabetObj].innerHTML += dizialphabet[i];
			};
		}
	}
	
	CountryList(withCharacter,0);

}


function writeDropdown(aobj,lobj1,lobj2,nobj,loc){
	alphabetObj = aobj;
	listObj1 = lobj1;
	listObj2 = lobj2;
	navObj = nobj;
	recordCnt = m_recordCnt;
	kita = loc;

	document.all[alphabetObj].innerHTML="";
	document.all["captionlinkdiv"].innerHTML=" "+getContinentName(kita);
	document.all["captionlinkdiv2"].innerHTML=" "+getContinentName(kita);
	
	var dizialphabet = new Array("A","B","C","D","E","G","H","I","İ","J","K","L","M","N","O","Ö","P","R","S","Ş","T","U","Ü","V","Y","Z");
	var tmpcountry = new Array();
	var bulundu;
	var withCharacter="";

	tmpcountry = getRelCountry("");
	
	if(tmpcountry.length<=m_recordCnt)
		recordCnt = tmpcountry.length;

	if(tmpcountry.length>recordCnt)
	{
		for(var i=0;i<dizialphabet.length;i++)
		{
			bulundu = false;
			for(var j=0;j<tmpcountry.length;j++){
				if((tmpcountry[j].countryNAME.substring(0,1)).toUpperCase() == dizialphabet[i])
				{
					if(withCharacter=="")
					{
						withCharacter=dizialphabet[i];
					}
					bulundu = true;					
					break;
				}
			}
			if(document.all[alphabetObj].innerHTML != ""){
				document.all[alphabetObj].innerHTML+=" ";
			}
			if(bulundu){
				//document.all[alphabetObj].innerHTML += "<a href='kita.asp?kita="+kita+"&wc="+dizialphabet[i]+"'>"+dizialphabet[i]+"</a>";
				document.all[alphabetObj].innerHTML += "<a href=javascript:CountryList('"+dizialphabet[i]+"',0);>"+dizialphabet[i]+"</a>"
			}else{
				document.all[alphabetObj].innerHTML += dizialphabet[i];
			};
		}
	}
	
	CountryList(withCharacter,0);

}


function CountryList(withCharacter,pn)
{

	var tmpcountry = new Array();
	var html;
	var stop;
	var start;
	var cnt = 0;

	tmpcountry = getRelCountry(withCharacter);

	html="<tr>";
	for(var i=pn*2;i<(pn+1)*2;i++)
	{
		start = i*(Math.ceil(recordCnt/2));
		if(tmpcountry.length> (i+1)*Math.ceil(recordCnt/2)){
			stop = (i+1)*Math.ceil(recordCnt/2);
		}else{
			stop = tmpcountry.length;
		}

		html+= "<table width='300' border='0' cellspacing='0' cellpadding='0' align='center'>";
		
		for(var j=start; j<stop;j++)
		{
			html += " <tr><td class='sline'>";
			if(tmpcountry[j].countryHAVESTATE=="0")
			{
				html += "<a href=cities.asp?kita="+kita+"&country="+tmpcountry[j].countryID+"&cname=" +tmpcountry[j].countryNAME.replace(" ","-")+ ">"+tmpcountry[j].countryNAME+"</a>";
			}else{
				html += "<a href=kita.asp?kita="+kita+"&country="+tmpcountry[j].countryID+"&cname=" +tmpcountry[j].countryNAME.replace(" ","-")+">"+tmpcountry[j].countryNAME+"</a>";
//				kita.asp?kita="&kita&"&country="&country&
//				"<a href=javascript:WriteState('"+alphabetObj+"','"+listObj1+"','"+listObj2+"','"+navObj+"','"+kita+"','"+tmpcountry[j].countryID+"','"+tmpcountry[j].countryNAME.replace(" ","$").replace(" ","$")+"');>"+tmpcountry[j].countryNAME+"</a>";
			}
			html += " </td></tr>";
		}
		html +=" </table>";
		if(cnt==0){
			document.all[listObj1].innerHTML = html;
			html = "";
		}else{
			document.all[listObj2].innerHTML = html;
		}
		cnt++;
	}

	if(tmpcountry.length>recordCnt){
		writeNavigationCountry(withCharacter,pn);
	}else{
		deleteNavigation();
	};
}

function writeNavigationCountry(withCharacter,pn)
{
	var tmpcountry = new Array();
	var soncnt=0;
	var info = "";
	
	/*tmpcountry = getRelCountry(withCharacter);
	
	soncnt = Math.ceil(tmpcountry.length/recordCnt)-1;
	
	if( ((pn+1)*recordCnt)<recordCnt )
	{
		info = " | <b>"+((pn*recordCnt)+1)+"-"+((pn+1)*recordCnt)+"</b> arası "
	}else{
		info = " | <b>"+((pn*recordCnt)+1)+"-"+recordCnt+"</b> arası "
	}

	if(pn>0){
		document.all[navObj].innerHTML = "<a href=javascript:CountryList('"+withCharacter+"',0)>İlk</a>";
	}else{
		document.all[navObj].innerHTML = "İlk";
	}
	
	if(pn>0){
		document.all[navObj].innerHTML+= " | <a href=javascript:CountryList('"+withCharacter+"',"+(0+pn-1)+")>Geri</a>";
	}else{
		document.all[navObj].innerHTML+= " | Geri";
	}
	
	document.all[navObj].innerHTML+=info;
	
	if(pn<soncnt){
		document.all[navObj].innerHTML+= " | <a href=javascript:CountryList('"+withCharacter+"',"+(0+pn+1)+")>İleri</a>";
	}else{
		document.all[navObj].innerHTML+= " | İleri";
	}
	
	if(pn<soncnt){
		document.all[navObj].innerHTML+= " | <a href=javascript:CountryList('"+withCharacter+"',"+(0+soncnt)+")>Son</a>";
	}else{
		document.all[navObj].innerHTML+= " | Son";
	}*/
}

function deleteNavigation()
{
	document.all[navObj].innerHTML= "";
}

function getRelCountry(withCharacter)
{
	var tmpcountry = new Array();
	var say;
	
	say=0;
	if(withCharacter=="")
	{
		for(var j=0;j<countries.length;j++){
			if(countries[j].countryCONTINENT==kita){
				tmpcountry[say] = new country_Class(countries[j].countryID,countries[j].countryNAME,countries[j].countryCONTINENT,countries[j].countryHAVESTATE);
				say++;
			}
		}
	}else{
		for(var j=0;j<countries.length;j++){
			if(countries[j].countryCONTINENT==kita && withCharacter==(countries[j].countryNAME.substring(0,1)).toUpperCase()){
				tmpcountry[say] = new country_Class(countries[j].countryID,countries[j].countryNAME,countries[j].countryCONTINENT,countries[j].countryHAVESTATE);
				say++;
			}
		}
	}
	
	return tmpcountry;
}
	
function WriteState(aobj,lobj1,lobj2,nobj,loc,countryID,countryNAME){
	alphabetObj = aobj;
	listObj1 = lobj1;
	listObj2 = lobj2;
	navObj = nobj;
	recordCnt = m_recordCnt;
	kita = loc;

	countryNAME=countryNAME.replace("$"," ").replace("$"," ");

	if(countryNAME=="") countryNAME=getCountryNAME(countryID);	
	
	var dizialphabet = new Array("A","B","C","D","E","G","H","I","İ","J","K","L","M","N","O","Ö","P","R","S","Ş","T","U","Ü","V","Y","Z");
	var tmpstate = new Array();
	var bulundu;
	var withCharacter="";
	
	document.all[alphabetObj].innerHTML="";
	document.all["captionlinkdiv"].innerHTML="<a class='kanalReturnLink' style='text-decoration:underline; color : white;'  href=javascript:write('"+alphabetObj+"','"+listObj1+"','"+listObj2+"','"+navObj+"','"+kita+"')>"+getContinentName(kita)+"</a>";
	document.all["captionlinkdiv"].innerHTML+=" > " + countryNAME;
	document.all["captionlinkdiv2"].innerHTML+= countryNAME;
	
	tmpstate = getRelState(countryID,"");

	if(tmpstate.length<=recordCnt)
		recordCnt = tmpstate.length;

	
	if(tmpstate.length>recordCnt)
	{
		for(var i=0;i<dizialphabet.length;i++)
		{
			bulundu = false;
			for(var j=0;j<tmpstate.length;j++){
				if((tmpstate[j].stateNAME.substring(0,1)).toUpperCase() == dizialphabet[i])
				{
					if(withCharacter=="")
					{
						withCharacter=dizialphabet[i];
					}
					bulundu = true;
					break;
				}
			}
			if(document.all[alphabetObj].innerHTML != ""){
				document.all[alphabetObj].innerHTML+=" ";
			}
			if(bulundu){
				//document.all[alphabetObj].innerHTML += "<a href='kita.asp?kita="+kita+"&wc="+dizialphabet[i]+"'>"+dizialphabet[i]+"</a>";
				document.all[alphabetObj].innerHTML += "<a href=javascript:StateList('"+countryID+"','"+dizialphabet[i]+"',0);>"+dizialphabet[i]+"</a>"
			}else{
				document.all[alphabetObj].innerHTML += dizialphabet[i];
			};
		}
	}
	
	StateList(countryID,withCharacter,0);
}

function StateList(country,withCharacter,pn)
{
	var tmpstate = new Array();
	var html;
	var stop;
	var start;
	var cnt = 0;

	tmpstate = getRelState(country,withCharacter);

	html="<tr>";
	for(var i=pn*2;i<(pn+1)*2;i++)
	{
		start = i*(Math.ceil(recordCnt/2));
		if(tmpstate.length> (i+1)*Math.ceil(recordCnt/2)){
			stop = (i+1)*Math.ceil(recordCnt/2);
		}else{
			stop = tmpstate.length;
		}

		html+= " 	<table width='300' border='0' cellspacing='0' cellpadding='0' align='center'>";		
		for(var j=start; j<stop;j++)
		{
			html += " <tr><td class='sline'>";
			html += "<a href=cities.asp?kita="+kita+"&country="+tmpstate[j].stateCOUNTRY+"&state="+tmpstate[j].stateID+">"+tmpstate[j].stateNAME+"</a>";
			html += " </td></tr>";
		}
		html +=" </table>";
		if(cnt==0){
			document.all[listObj1].innerHTML = html;
			html = "";
		}else{
			document.all[listObj2].innerHTML = html;
		}
		cnt++;
	}

	if(tmpstate.length>recordCnt){
		writeNavigationState(country,withCharacter,pn);
	}else{
		deleteNavigation();
	};
}

function writeNavigationState(country,withCharacter,pn)
{
	var tmpstate = new Array();
	var soncnt=0;
	var info = "";
	
	/*tmpstate = getRelState(country,withCharacter);
	
	soncnt = Math.ceil(tmpstate.length/recordCnt)-1;
	
	if( ((pn+1)*recordCnt)<recordCnt )
	{
		info = " | <b>"+((pn*recordCnt)+1)+"-"+((pn+1)*recordCnt)+"</b> arası "
	}else{
		info = " | <b>"+((pn*recordCnt)+1)+"-"+recordCnt+"</b> arası "
	}

	if(pn>0){
		document.all[navObj].innerHTML = "<a href=javascript:StateList('"+country+"','"+withCharacter+"',0)>İlk</a>";
	}else{
		document.all[navObj].innerHTML = "İlk";
	}
	
	if(pn>0){
		document.all[navObj].innerHTML+= " | <a href=javascript:StateList('"+country+"','"+withCharacter+"',"+(0+pn-1)+")>Geri</a>";
	}else{
		document.all[navObj].innerHTML+= " | Geri";
	}
	
	document.all[navObj].innerHTML+=info;
	
	if(pn<soncnt){
		document.all[navObj].innerHTML+= " | <a href=javascript:StateList('"+country+"','"+withCharacter+"',"+(0+pn+1)+")>İleri</a>";
	}else{
		document.all[navObj].innerHTML+= " | İleri";
	}
	
	if(pn<soncnt){
		document.all[navObj].innerHTML+= " | <a href=javascript:StateList('"+country+"','"+withCharacter+"',"+(0+soncnt)+")>Son</a>";
	}else{
		document.all[navObj].innerHTML+= " | Son";
	}*/
}

function getRelState(country,withCharacter)
{
	var tmpstate = new Array();
	var say;
	
	say=0;
	if(withCharacter=="")
	{
		for(var j=0;j<states.length;j++){
			if(states[j].stateCOUNTRY==country){
				tmpstate[say] = new state_Class(states[j].stateID,states[j].stateNAME,states[j].stateCOUNTRY);
				say++;
			}
		}
	}else{
		for(var j=0;j<states.length;j++){
			if(states[j].stateCOUNTRY==country && withCharacter==(states[j].stateNAME.substring(0,1)).toUpperCase()){
				tmpstate[say] = new state_Class(states[j].stateID,states[j].stateNAME,states[j].stateCOUNTRY);
				say++;
			}
		}
	}
	
	return tmpstate;
}

function getCountryNAME(code)
{
	for(var j=0;j<countries.length;j++){
		if(countries[j].countryID==code){
			return countries[j].countryNAME
		}
	}
}

function WriteCookie(name,value,second){
	var expire = "";
	if(second>0){
		expire = new Date((new Date()).getTime() + second * 60000);
		expire = "; expires=" + expire.toGMTString();
	}
	document.cookie = name + "=" + escape(value) + expire;
	return;
}