﻿
function expandDiv(ctrl) {
	var ctl = eval(ctrl);
	if (ctl.style.display == "none") 
		ctl.style.display = "";
	else
		ctl.style.display = "none";
}

// 鏁板€兼娴?
function IsNumber(number)	{	
	if(number.length == 0)
		return false;
	for(i = 0; i < number.length; i++) {
		if(number.charAt(i) < '0' || number.charAt(i) > '9')
			return false;
	}
	return true;
}


function LTrim(str) {
	if (str == null) {
		return "";
	}	
	var len = 0;
	while(str.charAt(len) == " ")
		len++;
	return str.substring(len);
}


function RTrim(str) {
	if (str == null) {
		return "";
	}
	var len = str.length;
	while(str.charAt(len-1) == " ")
		len--;
	return str.substring(0,len);
}	


function Trim(str) {		
	return LTrim(RTrim(str));
}

// 鏄惁浠ュ瓧绗﹀紑澶?
function IsBeginChar(str)	{	
	if(str.length == 0)
		return false;		
	if((str.charAt(0) >= 'A' && str.charAt(0) <= 'Z') || (str.charAt(0) >= 'a' && str.charAt(0) <= 'z'))
			return true;		
	return false;
}

// Email楠岃瘉
function IsEmail(email) {
	var patrn=/^\w[0-9a-zA-Z-_\.]*@(\w[0-9a-zA-Z-]*\.)+\w{2,}$/;
	if (!patrn.exec(email)) 
		return false;
	return true;
} 

// 鍥哄畾鐢佃瘽楠岃瘉
function IsTel(tel) {
	if(tel.length < 7 || tel.length > 20)
		return false;
	for(i = 0;i<tel.length;i++)
	{
		if((tel.charAt(i)>='0' && tel.charAt(i)<='9') || tel.charAt(i) == '-') {
			if(tel.charAt(i) == '-' && (i <=2 || i >= (tel.length -3)))
				return false;
		}
		else			
			return false;
	}
	return true;

} 

// 鎵嬫満楠岃瘉
function IsMobile(mobile) {
	if (mobile.length = 11 && IsNumber(mobile)) {
		return true;
	}
	return false;
} 

// 閭斂缂栫爜楠岃瘉
function IsPostCode(postCode)	{	
	if(postCode.length != 6 || !IsNumber(postCode))
		return false;		
	return true;
}


function GetParastr(strname) {// 鑾峰彇鍦板潃鍙傛暟
	var hrefstr
	hrefstr = window.location.href;		
	return GetParastrByUrlAndParaName(hrefstr,strname);
}


function GetParastrByUrlAndParaName(hrefstr,strname) {// 鑾峰彇鍦板潃鍙傛暟
	var pos,parastr,para,tempstr;		
	pos = hrefstr.indexOf("?")
	parastr = hrefstr.substring(pos+1);
	para = parastr.split("&");
	tempstr="";
	for(i=0;i<para.length;i++) {
		tempstr = para[i];
		pos = tempstr.indexOf("=");
		if(tempstr.substring(0,pos) == strname)
			return tempstr.substring(pos+1);
	}
	return null;
}	

// Find element x,y location
function findPosition( oLink ) {
	var posX = null;
	var posY = null;
	if( oLink.offsetParent ) {
	for( posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent ) {
		posX += oLink.offsetLeft;
		posY += oLink.offsetTop;
	}
	return [ posX, posY ];
	} else {
	posX = oLink.x;
	posY = oLink.y;
	return [ posX, posY ];
	}
}

function locationAddParam(url, paramName, paramValue) {
	paramValue = encodeURIComponent(paramValue)
	if (url == "" || url.length == 0) {
		url = window.location.href;
	}
	if (url.substring(url.length-1,url.length) == "#") {
		url = url.substring(0,url.length-1);
	}
	var pos = url.indexOf("&"+paramName+"=");
	if (pos == -1) {
		pos = url.indexOf("?"+paramName+"=");
	}
	if (pos != -1) {
		if (url.indexOf("&",pos+1) == -1) {
			url = url.substring(0,url.indexOf("=",pos+1)+1)+paramValue;
		}
		else {
			var tempStr = url.substring(url.indexOf("&",pos+1),url.length);
			url = url.substring(0,url.indexOf("=",pos+1)+1)+paramValue+tempStr;
		}
	}
	else {
		if (url.indexOf("?") != -1) {
			url = url+"&"+paramName+"="+paramValue;
		}
		else {
			url = url+"?"+paramName+"="+paramValue;
		}
	}
	return url;
}

function locationDelParam(url, paramName) {
	if (url == "" || url.length == 0) {
		url = window.location.href;
	}
	var pos = url.indexOf("&"+paramName+"=");
	if (pos == -1) {
		pos = url.indexOf("?"+paramName+"=");
	}
	if (pos != -1) {
		if (url.indexOf("&",pos+1) == -1) {
			url = url.substring(0,pos);
		}
		else {
			var tempStr = url.substring(url.indexOf("&",pos+1)+1,url.length);
			url = url.substring(0,pos+1)+tempStr;
		}
	}
	return url;
}

function ReadCookie(name)
{
	var mycookie = document.cookie; 
	var start1 = mycookie.indexOf(name + "=");
	if (start1== -1)
		return "";
	else
	{
		start=mycookie.indexOf("=",start1)+1; 
		var end = mycookie.indexOf(";",start);
		if (end==-1)
		{
			end=mycookie.length;
		}
		var value=unescape(mycookie.substring(start,end));
		return value;
	}
}

function isNull(obj){
	if (typeof(obj) == "undefined")
	  return true;
	  
	if (obj == undefined)
	  return true;
	  
	if (obj == null)
	  return true;
	 
	return false;
}

function replaceAll(str1,str2,str3) {
		
	if(str1 == null || str1 == "")
		return null;
	while(str1.indexOf(str2) != -1) {
		str1 = str1.replace(str2,str3);
	}
	return str1;    
}
function XMLHttpFactory() {
		
		var XmlHttp = null; 
		try { 
			XmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); 
		} 
		catch(e) { 
			try { 
				XmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
			}
			catch(oc) { 
					XmlHttp = null; 
			} 
		} 
		if ( !XmlHttp && typeof XMLHttpRequest != "undefined" ) { 
			XmlHttp = new XMLHttpRequest();
		} 
		return XmlHttp
    }
	
	function ValidateMustFill(eventType,srcID,strSelectedMsg,strWrongMsg) {	
		   
		var srcElement = document.getElementById(srcID);
		var srcValue = Trim(srcElement.value);				 	
		var spanID = "span" + srcID; 
		var span = document.getElementById(spanID);	
		var result = false;				
		switch(eventType) {
			case "OnBlur" :  				
				if(srcValue.length <= 0) {
					span.innerHTML = "&nbsp;" + strWrongMsg + "&nbsp;";					
					span.className = "validate_wrong";
				}				
				else {
						span.innerHTML = "";
						span.className = "validate_right";
						result = true;	
					}								
				break;
			case "OnFocus" :  
				span.innerHTML = "&nbsp;" + strSelectedMsg + "&nbsp;";				
				if(strSelectedMsg.length > 0)
					span.className = "validate_select";
				else
					span.className = "validate_noselect";
				break;
			default:
				break;
		}
		return result;
	} 
	
	function copyToClipBoard(objID){
		
	    var obj = document.getElementById(objID);
		var rng = document.body.createTextRange();
		rng.moveToElementText(obj);
		rng.scrollIntoView();
		rng.select();
		rng.execCommand("Copy");
		rng.collapse(false);
		DisplayMessageCenter(true,"该地址已经复制到剪贴板!");
	}	
	
	function getDateString() {
		
		var today = new Date();
		var x = new Array("星期日","星期一","星期二","星期三","星期四", "星期五","星期六");
		var day = today.getDay();
		var month = today.getMonth() + 1;
		return today.getYear() + "年" + month + "月" + today.getDate() + "日 " + x[day]; 
	}
	
	// 计算天数差的函数，通用  
	function  getDateDiff(sDate1,  sDate2){    //sDate1和sDate2是2006-12-18格式  
	
	   var  aDate,  oDate1,  oDate2,  iDays;  
	   aDate  =  sDate1.split("-");  
	   oDate1  =  new  Date(aDate[1]  +  '-'  +  aDate[2]  +  '-'  +  aDate[0]);    //转换为12-18-2006格式  
	   aDate  =  sDate2.split("-");  
	   oDate2  =  new  Date(aDate[1]  +  '-'  +  aDate[2]  +  '-'  +  aDate[0]);  
	   iDays  =  parseInt(Math.abs(oDate1  -  oDate2)  /  1000  /  60  /  60  /24);    //把相差的毫秒数转换为天数  
	   return iDays; 
	} 
	
   function dateAdd(olddate,day) {
	   
	  var T = new Date();		  
	  var t = Date.parse(olddate)+day*1000*3600*24;
	  T.setTime(t);
	  var year = T.getYear();
	  var month = T.getMonth()+1; 
	  var date = T.getDate(); 
	  return year + "-" + month + "-" + date; 
   }