/*功能:		输出省份、城市、区域
  参数说明：
*/
function SetDistrict(DistrictInfo,OutputType,strControl,infoID,selectedID,strText) {
	var last,found,info,temp;
	//alert(DistrictInfo);
	var Control = eval(strControl);
	Control.length = 0;
	Control.options[Control.length++].value = "";
	Control.options[Control.length-1].text = strText == "" ? "--请选择--" : strText;
	if(DistrictInfo == "") {return;}
	switch(OutputType) {
		case "Province" :
			last = null;
			info = DistrictInfo.split("■");
			for(var i = 0; i < info.length; i++) {
				temp = info[i].split("□")[0].split("▲");
				if(last != temp[0]) {
					last = temp[0];
					if(temp[0] != "") {
						Control.options[Control.length++].value = temp[0];
						Control.options[Control.length-1].text = temp[1];
						//if(temp[0] == selectedID) {Control.selectedIndex = Control.length-1;}
						if( (","+selectedID+",").indexOf(","+temp[0]+",") != -1 ) {Control.options[Control.length-1].selected = true;}
					}
				}
			}
			break;
		case "City" :
			last = null;
			found = false;
			info = DistrictInfo.split("■");
			for(var i = 0; i < info.length; i++) {
				temp = info[i].split("□")[0].split("▲");
				if( infoID == temp[0] && last != info[i].split("□")[1].split("▲")[0]) {
					last = info[i].split("□")[1].split("▲")[0];
					found = true;
					if(info[i].split("□")[1].split("▲")[0] != "") {
						Control.options[Control.length++].value = info[i].split("□")[1].split("▲")[0];
						Control.options[Control.length-1].text = info[i].split("□")[1].split("▲")[1];
						if( (","+selectedID+",").indexOf(","+info[i].split("□")[1].split("▲")[0]+",") != -1 ) {Control.options[Control.length-1].selected = true;}
					}
				}
				else if(infoID != temp[0] && found) {
					break;
				}
			}
			break;
		case "District" :
			found = false;
			info = DistrictInfo.split("■");
			for(var i = 0; i < info.length; i++) {
				temp = info[i].split("□")[1].split("▲");
				if( infoID == temp[0]) {
					found = true;
					if(info[i].split("□")[2].split("▲")[0] != "") {
						Control.options[Control.length++].value = info[i].split("□")[2].split("▲")[0];
						Control.options[Control.length-1].text = info[i].split("□")[2].split("▲")[1];
						if( (","+selectedID+",").indexOf(","+info[i].split("□")[2].split("▲")[0]+",") != -1 ) {Control.options[Control.length-1].selected = true;}
					}
				}
				else if(infoID != temp[0] && found) {
					break;
				}
			}
			break;
		default :
		
	}
}
//日期有效性检查函数
function VerifyDate(dtDate)
{	var dtReg = /^(\d{4})(\/|-)(\d{1,2})(\/|-)(\d{1,2})$/;
	var temp = dtReg.exec(dtDate);
	if(temp == null) return false;
	var date = new Date(temp[1],temp[3]-1,temp[5]);
	return date.getFullYear() == temp[1] && date.getMonth() == (temp[3]-1) && date.getDate() == temp[5];
}
//邮件有效性检查函数
function VerifyEmail(email) {
	var reg = /^([a-zA-Z0-9_\.-]+)@(([a-zA-Z0-9_-]+)\.)+[a-zA-Z]{2,3}$/;
	if( reg.test(email) ) {	return true;}
	return false;
}
//电话有效性检查函数
function VerifyTelephone(telephone) {
	var reg = /^((((\(|（){0,1}[0-9]{3,4}(\)|）|-| ){0,1}){0,1}[0-9]{7,8}((-| ){1}[0-9]+)*)|(0{0,1}13[0-9]{9})){1}$/;
	if( reg.test(telephone) ) {	return true;}
	return false;
}
//邮政编码有效性检查函数
function VerifyZip(zip){
	var reg = /^\d{6}$/;
	if (reg.test(zip)){	return true;}
	return false;
}
//图片显示的缩放比例(低IE版本不支持style="zoom:30%")
function showImage(image,validWidth,validHeight)
{
	var img = new Image();
	img.src = image.src;
	var zoom = validWidth * 100 / img.width;
	if(zoom > validHeight * 100 / img.height)
		zoom = validHeight * 100 / img.height;
	//zoom = zoom > 100 ? 100 : zoom;
	image.width = parseInt(img.width * zoom / 100, 10);
	image.height = parseInt(img.height * zoom / 100, 10);
}
function ShowOrderID(OrderID) {
	var temp = OrderID;
	if(temp.toString().length < 6) {
		temp = "000000" + temp.toString();
		temp = temp.substr(temp.length - 6);
	}
	return temp;
}

var http_request = false;
function makeRequest(url,params) {
    http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
        }
    }
    else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
    if (!http_request) {
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
    http_request.open('POST', url, false);
    http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http_request.send(params);
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
        	return http_request.responseText;
            //alert(http_request.responseText);
            //parent.document.write(http_request.responseText);
        } 
        else {
            alert('There was a problem with the request.');
        }
    }
    return null;
}

//======联动函数======
//info:联动信息
//parentID:父ID,调取该父ID下所有子选项加入指定的对象
//obj:接受赋值的对象
//showLabel:是否显示标签
//label:标签文本
function SetValue(info,parentID,obj,selectedID,showLabel,label) {
	var found = false;
	obj.length = 0;
	if(showLabel) {obj.options[obj.length++] = new Option(label,"");}
	for(var i = 0; i < info.length; i++) {
		if(info[i][0] == parentID) {
			obj.options[obj.length++] = new Option(info[i][2],info[i][1]);
			if(info[i][1] == selectedID) {obj.selectedIndex = obj.length - 1}
				found = true;
		}
		else if(info[i][0] != parentID && found) {
			break;
		}
	}
}