/*
作者：卢华泰
公司：杭州萧何广告有限公司
Author : Chufeng Lu
Copyright VaChina Inc.
			2009-1-15
-----------------------------*/
var $=function(Id){
	return document.getElementById(Id)?document.getElementById(Id):null;
};
var $N=function(Name){
	return document.getElementsByName(Name)?document.getElementsByName(Name):Name;
};
var $createTag=function(tagName){
	return document.createElement(tagName);
};
var $removeTag=function(obj){
	document.body.removeChild(obj);
};
var $getTop=function(obj){
	var offset=obj.offsetTop;
	if(obj.offsetParent!=null) offset +=$getTop(obj.offsetParent);
	return offset;
};
var $getLeft=function(obj){
	var offset=obj.offsetLeft;
	if(obj.offsetParent!=null) offset +=$getLeft(obj.offsetParent);
	return offset;
};
var $httpRequest=function(){
	var xmlHttp=false;
	try{
		xmlHttp = new XMLHttpRequest();
	}
	catch(trymicrosoft){
		try{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}//No.1
		catch(othermicrosoft){
			try{xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")}
			catch(failed){}
		}//No.1
	}
   return xmlHttp;
};
var $ajaxGet=function(url,functionCallback){
	var xmlHttp = $httpRequest();
	xmlHttp.open("get",url,true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4&&xmlHttp.status == 200){
			functionCallback(xmlHttp);
		}
	};
	xmlHttp.send(null);
};
var $ajaxPost=function(url,postData,functionCallback){
	var xmlHttp = $httpRequest();
	xmlHttp.open("POST",url,true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4&&xmlHttp.status == 200){
			functionCallback(xmlHttp);
		}
	};
	xmlHttp.setRequestHeader("content-type","application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("content-length",postData.length);
	xmlHttp.send(postData);
};
var ltrim=function(val){return val.replace(/(^\s*)/g,"");} ;
var rtrim=function(val){return val.replace(/(\s*$)/g,"");}; 
var trim=function trim(val){return rtrim(ltrim(val));};

var isTruename=function(val){
	var reg=/^(\w{3,20})|(?:[\u4e00-\u9fa5]{2,8})$/;
	if(!reg.test(val)){
		return false;
	}else{
		return true;
	}
};
//检测密码格式
var isPassword=function(val){
	var reg=/^(?!^\d+$|^[a-zA-Z]+$)(?:[\w,\.@#\!\$\-]{6,16})$/;
	if(!reg.test(val)) return false;
	else return true;
}

var isEmail=function(val){
	var reg=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	if(!reg.test(val)){
		return false;
	}else{
		return true;
	}
};
//设置cookie
function setCookie(name,value) {
    var Days = 1;
    var exp  = new Date();
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
//获取cookie
function getCookie(name) {
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
    if(arr=document.cookie.match(reg)) return unescape(arr[2]);
    else return "";
}
//删除cookie
var removeCookie=function(name) {
  document.cookie = name+"=;expires="+(new Date(0)).toGMTString();
};
var getScroll=function(){
	var _this=this;
	_this.x = 0;
	_this.y = 0;
	if(document.all){ 
		if(!document.documentElement.scrollLeft)
			_this.x=document.body.scrollLeft;
		else
			_this.x=document.documentElement.scrollLeft;
		if(!document.documentElement.scrollTop)
			_this.y=document.body.scrollTop;
		else
			_this.y=document.documentElement.scrollTop;
	}
	else{
		_this.x=window.pageXOffset;
		_this.y=window.pageYOffset;
	}
};
var initArea=function(uiObj,pid,tagId,doFunction){
	$ajaxGet("/tools/msconn.asp?pid=" + parseInt(pid),
		function(xmlHttp){
			xmldoc = xmlHttp.responseXML;
			var keynodes=xmldoc.getElementsByTagName("key");
			for(var i=0;i<keynodes.length;i++){
				uiObj.append(keynodes[i].getAttribute("AreaID"),
										keynodes[i].getAttribute("value"));
			}
			uiObj.init(document.getElementById(tagId));//加载
			if(doFunction!=undefined) doFunction();
		}
	);
};
//
var resetArea=function(uiObj,pid,tagId,doFunction){
	$ajaxGet("/tools/msconn.asp?pid=" + parseInt(pid),
		function(xmlHttp){
			uiObj.clear();
			xmldoc = xmlHttp.responseXML;
			var keynodes=xmldoc.getElementsByTagName("key");
			for(var i=0;i<keynodes.length;i++){
				uiObj.append(keynodes[i].getAttribute("AreaID"),
										keynodes[i].getAttribute("value"));
			}
			uiObj.resetOption();
			if(doFunction!=undefined) doFunction();
		}
	);
};