// JScript 文件

var objTemp = null;
var vProvince = "",vCity = "";
//===================================================================
function SetProvince(name,str)
{
    var obj = document.getElementById(name);
	if (!obj || typeof(INC_Pro) == "undefined"){return;}
	var j = 0;
	if (typeof(str) != "undefined" && str != ""){obj.options[0] = new Option(str,""); j = 1;}
	var inx = -1;
	for (var i=0; i< INC_Pro.length; i++)
	{
	    obj.options[i+j] = new Option(INC_Pro[i].name,INC_Pro[i].id);
	    if (vProvince == INC_Pro[i].id) {inx = i+j;}
	}
	if (inx >= 0){ obj.selectedIndex = inx;obj.onchange();}
	
	
}

function GetProIndex(id)
{
    if (typeof(INC_Pro) == "undefined"){return -1;}
	for (var i=0; i< INC_Pro.length; i++)
	{
	    if (INC_Pro[i].id == id){return i;}
	}
	return -1;
}

function GetProvinceName(code)
{
    if (typeof(INC_Pro) == "undefined" || code=="" || code.length != 2 ){return "";}
	for (var i=0; i< INC_Pro.length; i++)
	{
	    if (INC_Pro[i].id == code){return INC_Pro[i].name.replace(/[A-Z]/g,"");}
	}
	return "";
}

function GetCity(v,name,str)
{
	var obj = document.getElementById(name);
	obj.options.length = 0;
	if (v == "" || v == "0") {
	    var def = new Option('所有城市', '');
	    obj.options.add(def);
	    return;
	}
	 
	var ik = GetProIndex(v);
	if (ik < 0 ){return;}
	var objRow = INC_City[ik];
	var j = 0;
	if (typeof(str) != "undefined" && str != ""){obj.options[0] = new Option(str,""); j = 1;}
	
	
	var L = objRow.length;
	var defId = 0;
    for (var i=0; i< L ;i++)
	{
		var v = objRow[i].id;
		var n = objRow[i].name;
		obj.options[i+j] = new Option(n,v);
		if (vCity != "" )
		{
			if (vCity == objRow[i].id){  defId = i+1;}
		}
		else if (objRow[i].idefault)
		{
		   defId = i+1;
		}
	}
	if ( j == 1 ){  if (vCity != "" ) obj.selectedIndex = defId;}
	else obj.selectedIndex = defId;
}

function GetCityName(inx,code)
{
    if (inx < 0 ){return "";}
    var objRow = INC_City[inx];
	var L = objRow.length;
	var defId = code;
    for (var i=0; i< L ;i++)
	{
		if (objRow[i].id == code) {  return objRow[i].name.replace(/[A-Z]/g,"");}
	}
	return "";
}

function SetAreacode(acode)
{
    var e = document.getElementById("sAreaCode1");
	if (e){e.value = acode;}
	e = document.getElementById("sAreaCode2");
	if (e){e.value = acode;}
	e = document.getElementById("sAreaCode3");
	if (e){e.value = acode;}
	e = document.getElementById("sAreaCode4");
	if (e){e.value = acode;}
}

function ProvinceSetValue()
{
    if (vProvince == ""){return;}
	var e = document.getElementsByName("iProvince");
	vProvince = ","+vProvince+","
	for (var i=0; i< e.length; i++)
	{
	    if (vProvince.indexOf(","+e[i].value+",")>=0){ e[i].click();}
	}
}



function JsBindCity(name)
{
    var n = "CityValue";
    if (typeof(name) != "undefined" ){  n = name;}
    var objs = document.getElementsByName(n)   ;
    if (!objs || typeof(INC_Pro) == "undefined"){return;} 
    for(var i= objs.length - 1; i>=0; i--)
    {
        var e = objs[i];
        if (e.value == ""){continue; }
        if (e.value.length == 4)
        {
            e.outerHTML = GetCityName(GetProIndex(e.value.substring(0,2)),e.value);
        }
        else if (e.value.length == 2)
        {
            e.outerHTML = GetProvinceName(e.value);
        }
    }
}