﻿/*
#   信息: 
#	city for esales province  selected       
#	作者:
#   郭挺   2006-01-09 
#	接口:document.form.select_Province_name
# 	showProvince(select_Province_name); onChange="showCity(select_Province_name,select_Province_name.value,select_City_name);"---显示列表
# 	selectProvince(select_Province_name,value,select_City_name);---选择列表，同时刷新select_City
# 	selectCity(select_City_name,value);---选择列表select_City  returnProvince();returnCity();
*/
  Province = new Array;
  ProVal = new Array;
  City = new Array;  
  CityVal = new Array;

Province=GetAreaParentNames();
ProVal=GetAreaParentIDs();

 function showCity(objous,selectvalue,obj)
 { 
   if(selectvalue=="")
   {
	   SFclear(obj);
   		return 0;
   }
   SFSelectareaLoc(objous,selectvalue,obj);   
   if(obj.length==0) SFfullup(obj, "--请选择--");
 }
 function addCity(obj,val)
 {
	 val=val+"";
	for(II=0;II<ProVal.length;II++)
	   {
		if(ProVal[II]==val.substring(0,2))
		{
			if(val.length==2)
			{
				SFwrite_option(obj,Province[II],ProVal[II]);	
				return 0;
			}
			else
			{
				CityVal=getAreaIDs(ProVal[II]);
				City=getAreaNames(ProVal[II]);
				for(J=0;J<CityVal.length;J++)
				{
					if(CityVal[J]==val)
					{
						SFwrite_option(obj,City[J],CityVal[J]);	
						return 0;
					}
				}
			}
		}
	   }
 }
  function SFclear(obj1)
  {
  	len=obj1.length;  	
  	for(II=len-1;II>=0;II--)
  	  obj1.options[II]=null;
  }

  function SFfullup_P(obj1,val1,val2)
  {
  	var vn = new Option(val1,val2); 
  	obj1.add(vn);
  }
  //增加一个apption
  function SFfullup(obj1,val,val1)
  {
  	var vn = new Option(val,val1);   	
  	obj1.add(vn); 
  }

  function SFsel(val,obj1)
  {
  	for(II=0;II<obj1.length;II++)
  	{
  		if(obj1[II]==val)
  		{
  			return II;
  		}
  	}
  	if (II==obj1.length)
  	{
  		return 0;
  	}
  }
 
function returnProvince(theProvinceVal)
{
	for(II=0;II<Province.length;II++)
	{
		if(ProVal[II]==theProvinceVal)
		{
			document.write (Province[II]);
			return 0;
		}
	}
}
function returnOnlyCity(theCityVal)
{
	if(theCityVal.length==2 || theCityVal=='2907')
	{//如果长度为2
		returnProvince(theCityVal);
		return 0;
	}
	else
	{
	for(II=0;II<Province.length;II++)
	{
		if(ProVal[II]==theCityVal.substring(0,2)|| ProVal[II]==theCityVal.substring(0,4))
		{
			CityVal=getAreaIDs(ProVal[II]);
			City=getAreaNames(ProVal[II]);
			for(j=0;j<City.length;j++)
			{
				if(CityVal[j]==theCityVal)
				{
					document.write (City[j].replace("- ",""));
					return 0;
				}
			}
		}
	}
	}
}
function returnCity(theCityVal)
{
	if(theCityVal.length==2 || theCityVal=='2901')
	{//如果长度为2
		returnProvince(theCityVal);
		return 0;
	}
	else
	{
	//returnProvince(left(theCityVal,2));
	for(II=0;II<Province.length;II++)
	{
		if(ProVal[II]==theCityVal.substring(0,2) || ProVal[II]==theCityVal.substring(0,4))
		{
			document.write (Province[II]);
			CityVal=getAreaIDs(ProVal[II]);
			City=getAreaNames(ProVal[II]);
			for(j=0;j<City.length;j++)
			{
				if(CityVal[j]==theCityVal)
				{
					document.write ("·"+City[j].replace("- ",""));
					return 0;
				}
			}
		}
	}
	}
}

  function SFSelectareaLoc(objous,selectvalue,obj)
  {
  	var cbox=obj;
  	var k; 
  		for(k=0;k<objous.length;k++)
  		{
			if(objous.options[k].value==selectvalue)
			{
  			SFclear(cbox);
			CityVal=getAreaIDs(ProVal[k]);
			City=getAreaNames(ProVal[k]);
  			for (II=0;II<City.length;II++)
  			 {
  				SFfullup(cbox,City[II],CityVal[II]);
  			 }
			return 1;
			}
  		} 
  }
 
 function SFwrite_option(obj,txt,val)
 {
     var opt = new Option();
     opt.text = txt;
     opt.value = val;
     obj.add(opt);
 }
 
 function showProvince(obj)
 {
   for(II=0;II<Province.length;II++)
   {
     SFwrite_option(obj,Province[II],ProVal[II]);          
   }
 }
 


 function selectProvince(theProvince,selectProvince,theCity)
 {
	for(II=0;II<theProvince.options.length;II++)
	{   
	   if(theProvince.options[II].value==selectProvince)
	   {
		theProvince.options[II].selected=true;
		CityVal=getAreaIDs(ProVal[II]);
		City=getAreaNames(ProVal[II]);
		for(j=0; j<City.length; j++)
	     {
		 theCity.options[j]=new Option(City[j], CityVal[j]);
	     }
		return 0;
	   }
	}
 }
 
function selectCity(theCity, CityValue)
{
    for(II=0; II<theCity.options.length; II++)
	if(theCity.options[II].value == CityValue)
	{
		theCity.options[II].selected=true;
	}
 }

