///*********************************************基础用法***开始*****************************************************//
var $=document.getElementById;var $n=document.getElementsByName;var $f=function(id){return $(id).value.trim();}
var $v=function(name){var n = $n(name).length;for(i=0;i<n;i++){if($n(name)[i].checked){return $n(name)[i].value.trim();}}}
String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); }
///*********************************************基础用法***结束*****************************************************//
 
///*********************************************ajax用法***开始*****************************************************//
//返回xml
function getRequest( url )
{
	var xmlhttp = "";    //将ajax对象实例写在函数外，便于多个ajax函数共用    
          //处理多种浏览器   
     if   (window.XMLHttpRequest)   {   //   Mozilla,   Safari,...   
       xmlhttp =new XMLHttpRequest();               
     }   
   	else if(window.ActiveXObject)   {   //   IE    
         xmlhttp =new ActiveXObject("Msxml2.XMLHTTP");    
     } 
	
	xmlhttp.open( "GET", url, false );
	try{
    	xmlhttp.send();
	}
	catch( e ){
		alert( "ajax error" );
		top.close();
		return;
	}

	var xmldoc = new ActiveXObject( "Microsoft.XMLDOM" );
	xmldoc = xmlhttp.responseXML;
	var root = xmldoc.documentElement;
	return root;
}

//返回text
function getRequestText( url ){
	 var xmlhttp = "";    //将ajax对象实例写在函数外，便于多个ajax函数共用    
          //处理多种浏览器   
     if   (window.XMLHttpRequest)   {   //   Mozilla,   Safari,...   
       xmlhttp =new XMLHttpRequest();               
     }   
   	else if(window.ActiveXObject)   {   //   IE    
         xmlhttp =new ActiveXObject("Msxml2.XMLHTTP");    
     }   
	
	xmlhttp.open( "GET", url, false );
	try{
       	xmlhttp.send();
	}
	catch( e ){
		return;
	}
	return xmlhttp.responseText;
}

///*********************************************ajax用法***结束*****************************************************//

///*********************************************基础验证用法***开始**************************************************//
	
//保留两位小数
function formatFloat(src, pos){
    return Math.round(src*Math.pow(10, pos))/Math.pow(10, pos);
}


// javascript验证不能输入特殊字符
function regSpecial(value){
		var p = /[\.\,\/\?\`\~\!\@\#\$\%\^\&\*\(\)\-\_\=\+\;\:\'\"]+/g;
		return p.test(value);
	}

// 判断字符串是否符合长度
function strLength(str,length){
	return str.trim().length <= length;
}

// 判断邮编
function isZipcode(str){
	var reg = /^[0-9]{1}(\d){5}$/;
	return reg.test(str.trim());
}

// 手机、固话验证
function isPhone(str){
	var reg = /(^(\d{3,4}-)?\d{7,8})$|(1[3-9]{10})/;
	return reg.test(str.trim());
}
  
// 电子邮箱验证
function isEmail(str){
	var reg = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
	return reg.test(str.trim());
}

// 验证字段是否为空
function isEmpty(str){
	return (str.trim().length==0 || str.trim()=="") ? true : false;
}
///*********************************************基础验证用法***结束**************************************************//
	
///*********************************************三级联动用法***开始**************************************************//
// 区域列表
// random=1 取得城市 random=2 取得郡县
function findDistict(pid){
	var districId = null;
	var ctx = $f("ctx");
	if(typeof(pid)=="undefined") districId = $f("province");
	else districId = pid;
	var url = ctx + "/order/order!load4District.action?districId=" + districId + "&random=1&rad=" + Math.random();
	var xmlreq = getRequestText(url);
	$("district1").innerHTML = xmlreq;
	

	districId = $f("city");
	var url = ctx + "/order/order!load4District.action?districId=" + districId + "&random=2&rad=" + Math.random();
	var xmlreq = getRequestText(url);
	$("district2").innerHTML = xmlreq;
	
}

// 郡县
 function findCountry(ctx,cid){
 	var districId = null;
 	var ctx = $f("ctx");
 	if(typeof(cid)=="undefined") districId = $f("city");
 	else districId = cid;
	var url = ctx + "/order/order!load4District.action?districId=" + districId + "&random=2&rad=" + Math.random();
	var xmlreq = getRequestText(url);
	$("district2").innerHTML = xmlreq;		 
 }
 
 // 修改时根据传递参数赋值
 // 修改省市赋值
function setValue(){
	var array = getValue();
	$("province").value = array[0];
	findDistict(array[0]);
	$("city").value = array[1];
	findCountry(array[1]);
	$("country").value = array[2];
}
///*********************************************三级联动用法***结束**************************************************//