function isIE(){ //ie? 
    return (window.navigator.userAgent.toLowerCase().indexOf("msie")>=1) ;  
} 

if(!isIE()){ //firefox innerText define
   HTMLElement.prototype.__defineGetter__(     "innerText", 
    function(){
     var anyString = "";
     var childS = this.childNodes;
     for(var i=0; i<childS.length; i++) {
      if(childS[i].nodeType==1)
       anyString += childS[i].tagName=="BR" ? '\n' : childS[i].innerText;
      else if(childS[i].nodeType==3)
       anyString += childS[i].nodeValue;
     }
     return anyString;
    } 
   ); 
   HTMLElement.prototype.__defineSetter__(     "innerText", 
    function(sText){ 
     this.textContent=sText; 
    } 
   ); 
}	

/**
 * 计算指定日期后的第几天
 * @param {} strDate
 * @param {} nDay
 */
function AddDate(strDate, nDay){
	//alert("add date begin=" + strDate);
	var arys = new Array(); 
	arys = strDate.split( '-' );
	var myDate = new Date(arys[0],parseInt(arys[1]-1),arys[2]);  
	myDate=myDate.valueOf(); 
	myDate=myDate + nDay   *   24   *   60   *   60   *   1000; 
    myDate =  new  Date(myDate) 
    var str = (myDate.getFullYear()   +   "-"   +   (myDate.getMonth()+ 1) +   "-"   +   myDate.getDate()   );
    //alert("add date = " + str);
    return str ;
}

/**
 * 计算指定日期前的第几天
 * @param {} strDate
 * @param {} nDay
 * @return {}
 */
function DecDate(strDate, nDay){
	//alert("add date begin=" + strDate);
	var arys = new Array(); 
	arys = strDate.split( '-' );
	var myDate = new Date(arys[0],parseInt(arys[1]-1),arys[2]);  
	myDate=myDate.valueOf(); 
	myDate=myDate - nDay   *   24   *   60   *   60   *   1000; 
    myDate =  new  Date(myDate) 
    var str = (myDate.getFullYear()   +   "-"   +   (myDate.getMonth()+ 1) +   "-"   +   myDate.getDate()   );
    //alert("add date = " + str);
    return str ;
}

/**
 * 校验时间的有效性 HH:mm:ss/ HH:mm
 * @param {} strTime
 * @return {Boolean}
 */
function IsTime(strTime){
	try{
		var arys = new Array(); 
		arys = strTime.split( ':' );
		if ((arys == null) || (arys.length < 2))
			return false ;
		return ((parseInt(arys[0]) < 24) && (parseInt(arys[0]) >= 0) && (parseInt(arys[1]) < 60) && (parseInt(arys[1]) >= 0));
	}catch(err){
		return false ;
	}
}

/**
 * 日期格式校验， yyyy-MM-dd
 * @param {} strDate
 * @return {Boolean}
 */
function IsDate(strDate){
    try{
        if(/\-/.test(strDate) && /\//.test(strDate)){
            return false;
        }
        
        strDate = strDate.replace(/\-/g,"/");//必须要用正则来替换，否则只替换第一个出现的字符串
        var tmp = strDate.split("/");
        
        if(tmp.length > 3){
            return false;
        }
        
        var tempDate = new Date(strDate);
        
        var year = tempDate.getYear();
        var month = tempDate.getMonth() + 1;
        var day = tempDate.getDate();
        
        //判断中间不允许有空格
        if(/\s/.test(tmp[0]) || /\s/.test(tmp[1]) || /\s/.test(tmp[2])){
            alert("中间不允许出现空格！");
            return false;
        }
        
        //判断年、月、日位数,可以根据自己需求修改
        if(tmp[0].length < 3 || tmp[0].length > 4){
            return false;
        }
        
        if(tmp[1].length > 2){
            return false;
        }
        
        if(tmp[2].length > 2){
            return false;
        }
        //判断年、月、日位数,可以根据自己需求修改
        
        if(tempDate != null){    
            return year == tmp[0] && month == tmp[1] && day == tmp[2];            
        }else{
            return false;
        }
    }catch(ex){
        //alert(ex.message);
        return false;
    }
}


/**
 * 比较二个日期大小
 * @param {} strDate
 * @param {} strDate2
 * @return  <br/>strDate大于strDate2 = 1<br/>strDate小于strDate2 = 2 <br/>strDate 等于 strDate2 = 0<br/>错误返回-1
 */
function CompateDate(strDate, strDate2){
	try{
		if ((!IsDate(strDate)) || (!IsDate(strDate2)))
			return -1 ;
			
		var arys = new Array(); 
		arys = strDate.split( '-' );
		var myDate = new Date(arys[0],parseInt(arys[1]-1),arys[2]);  
		myDate=myDate.valueOf(); 
		myDate =  new  Date(myDate) 

		var arys2 = new Array(); 
		arys2 = strDate2.split( '-' );
		var myDate2 = new Date(arys2[0],parseInt(arys2[1]-1),arys2[2]);
		myDate2=myDate2.valueOf(); 
		myDate2 =  new  Date(myDate2) 

		if (myDate > myDate2){
			return 1 ;
		}else if (myDate < myDate2){
			return 2;
		}else if (myDate = myDate2){
			return 0;
		}else{
			return -1;
		}
    

	}catch(err){
		return -1 ;
	}
	return -1 ;
}

/**
 * 判断二个日期大小
 * @param {} dTime1 yyyy-MM-dd HH:mm
 * @param {} dTime2 yyyy-MM-dd HH:mm
 * @return {} dTime1 大于 dTime2 返回true ，否则返回false
 */
function CheckDateTime(dTime1, dTime2){
       var temp = new Array()
       dTime1.replace(/(\d+)/g,function(a,b){temp.push(b)});
       
       var temp2 = new Array()
       dTime2.replace(/(\d+)/g,function(a,b){temp2.push(b)});
            
      var varDate = new Date(temp[0],(parseInt(temp[1],10)-parseInt(1)),temp[2],temp[3],temp[4]);
      var varDate2 = new Date(temp2[0],(parseInt(temp2[1],10)-parseInt(1)),temp2[2],temp2[3],temp2[4]);
      //var nowDate=new Date()
      return (varDate >= varDate2);
}

/**
 * 获取当前日期时间 yyyy-MM-dd HH:mm
 * @return {}
 */
function getDateTime(){
	var date=new Date() ;
	return date.getFullYear() + "-" + (date.getMonth()+1) + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes();
}

/**
 * 获取当前日期时间 yyyy-MM-dd
 * @return {}
 */
function getDate(){
	var date=new Date() ;
	var mm = "00" + (date.getMonth()+1) ;
	return date.getFullYear() + "-" + mm.substring(mm.length-2) + "-" + date.getDate();
}

function getDateTimeWeek(){
	var date=new Date() ;
	var nd = date.getDay();
	var st = "";
	if (nd == 0)
		st = "星期日";
	else if (nd == 1)
		st = "星期一";
	else if (nd == 2)
		st = "星期二";
	else if (nd == 3)
		st = "星期三";
	else if (nd == 4)
		st = "星期四";
	else if (nd == 5)
		st = "星期五";
	else if (nd == 6)
		st = "星期六";		
	var str = date.getFullYear() + "-" + (date.getMonth()+1) + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + " " + st;
	date = null ;
	return str ;
}

/**
 * 设置COOKIE值
 * @param {} cookieName
 * @param {} cookieValue
 * @param {} nHours
 */
function SetCookie(cookieName, cookieValue, nHours) { 
	var today = new Date(); 
	var expire = new Date(); 
	if (nHours == null || nHours == 0) 
	nHours = 1; 
	expire.setTime(today.getTime() + 1000 * 60 * 60 * 24 * nHours); 
	document.cookie = cookieName + "=" + escape(cookieValue) + ";expires=" + 
	expire.toGMTString(); 
} 

/**
 * 获取COOKIE值
 * @param {} cookieName
 * @return {String}
 */
function ReadCookie(cookieName){ 
	var theCookie = "" + document.cookie; 
	var ind = theCookie.indexOf(cookieName); 
	if (ind == - 1 || cookieName == "") 
	return ""; 
	var ind1 = theCookie.indexOf(';', ind); 
	if (ind1 == - 1) 
	ind1 = theCookie.length; 
	var vue = unescape(theCookie.substring(ind + cookieName.length + 1, ind1));
	return ((vue == ";")?"":vue);
}

/**
 * 关闭窗口
 */
function CloseWin(){    
	window.opener=null;    
	//window.opener=top;    
	window.open("","_self");    
	window.close();    
} 


/**
 * 生成GUID码
 * @return {}
 */
function getGUID(){
	var   guid   = "";
	//var   n   =  "";
	for   (var   i   =   1;   i   <=   32;   i++){
	  	guid += Math.floor(Math.random()   *   16.0).toString(16);
	  	//guid += n;
	}
	return guid ;
}

/**
 * 检查字符串是否含有中文
 * @param {} str
 * @return {Boolean}
 */
function isCode(str){
  str = str.replace(" ", "");
  for (i=0;i<str.length;i++){ 
     if (str.charCodeAt(i) >= 255)
       return false;

   }
   return true;
}
/**
 * EMAIL格式检查
 * @param {} s
 * @return {Boolean}
 */
function isValidEmail(s) {
		var reg1 = new RegExp('^[a-zA-Z0-9][a-zA-Z0-9@._-]{3,}[a-zA-Z]$');
		var reg2 = new RegExp('[@.]{2}');
		
		if (s.search(reg1) == -1
				|| s.indexOf('@') == -1
				|| s.lastIndexOf('.') < s.lastIndexOf('@')
				|| s.lastIndexOf('@') != s.indexOf('@')
				|| s.search(reg2) != -1)
			return false;
		
		return true;
}

/**
 * 邮政编码检测
 * @param {} s
 * @return {Boolean}
 */
function isPostCode(s){ 
	var patrn=/(^[0-9]{6,6}$)/; 
	return (patrn.exec(s)) ;
} 

/*
			(1)电话号码由数字、"("、")"和"-"构成
　　		(2)电话号码为3到8位
　　		(3)如果电话号码中包含有区号，那么区号为三位或四位
　　		(4)区号用"("、")"或"-"和其他部分隔开
*/
function isTel(s) 
{ 

//var patrn=/(^[0-9]{3,4}\-[0-9]{5,8}$)|(^[0-9]{5,8}$)|(^\([0-9]{3,4}\)[0-9]{5,8}$)|(^[0-9]{3,4}\-[0-9]{5,8}\/[0-9]{3,6}$)|(^[0-9]{5,8}\/[0-9]{3,6}$)|(^\([0-9]{3,4}\)[0-9]{5,8}\/[0-9]{3,8}$)/; 

var patrn=/(^[0-9]{3,4}\-[0-9]{5,8}$)|(^[0-9]{5,8}$)|(^\([0-9]{3,4}\)[0-9]{5,8}$)|(^[0-9]{3,4}\-[0-9]{5,8}\/[0-9]{1,8}$)/; 
if (!patrn.exec(s)) return false 
return true 
} 


//校验普通电话、传真号码：可以“+”开头，除数字外，可含有“-” 
function isMobile(s) 
{ 
	/*
　　		(5)移动电话号码为11或12位，如果为12位,那么第一位为0
　　		(6)11位移动电话号码的第一位和第二位为"13"
　　		(7)12位移动电话号码的第二位和第三位为"13"
	*/
	//var patrn=/(^0{0,0}1[35]{1,1}[0-9]{9}$)/; 
	var patrn=/(^0{0,0}1([35]{1,1}|[88]{1,1})[0-9]{9}$)/; 
	return patrn.exec(s);
} 

/**
 * 检查中英文姓名
 * @param {} tt
 * @return {}
 */
/*
function CheckName(tt) {
var errdetect=true;
var NameSplit ;//= new Array("","");
var hz=0;
       len=tt.length;
       if (len > 0){
              dd = escape(tt.charAt(0));
               if (dd.length<=3){hz=0;}else{hz=1;}
              for (i=0; i<len; i++){
                     dd = escape(tt.charAt(i));
                      if (dd.length<=3){
                             if (hz==0){if(parseInt(dd)){errdetect=false;break;}}
                             if (hz==1){errdetect=false;break;}
                     }
                     else{if (hz==0){errdetect=false;break;}}
              }
              if ( (errdetect) && (hz == 0) ){
					//if(tt.length<5){errdetect=false;return false;}
                     indexg = tt.indexOf("/");
                     if (indexg!=-1){
						NameSplit = tt.split("/");
						if ( NameSplit.length > 2 )
							errdetect=false;
						else
						{							
							if (  NameSplit[0].length < 2 || NameSplit[1].length  < 2 )
								errdetect=false;
							else
								errdetect=true;		
						}			 
                     }
                     else{
						errdetect=false;
					}
              }
       }
       else {errdetect=false;}
	return errdetect;
}
*/
/**
 * 身份证号码检查
 * @param {} num
 * @return {Boolean}
 */
function isIdCardNew(num) {
        var IdeInfor = "";
        var len = num.length, re;
        var a;
        var date;
		//var sdd = "19"+num.substring(6,8)+num.substring(8,10)+num.substring(10,12);
		//return sdd;
        
        
        if ( len != 15 && len != 18 )
        {       
			//alert ("身份证输入的位数不对");
			return false;
        }
        else if (len == 15)
        {
			re = new RegExp(/^(\d{6})()?(\d{2})(\d{2})(\d{2})(\d{3})$/);
			regExp = num.match(re);		
			if( isNaN(num) )
			{	//alert( "15位身份证请输入数字");
				return false;
			}
			else if( !validateDate(num) )
			{
				//alert ("15位身份证中出生日期不正确");
				return false;
			}
			else
				return true;//验证通过
			
		}
		else if ( len == 18 )
		{
			re = new RegExp(/^(\d{6})()?(\d{4})(\d{2})(\d{2})(\d{3})(\d)$/);

			if ( ( len == 18 && isNaN(num.substring(0,17)) ) || (len == 18 && isNaN(num.substring(17,18)) && num.substring(17,18) != "X" && num.substring(17,18) != "x") )
			{	//alert( "18位身份证中前17位请输入数字，最后一位请输入数字或大写X");
				return false;
			}
			else if( !validateDate(num) )
			{
				//alert( "18位身份证中出生日期不正确");
				return false;
			}
			else
				return true;//验证通过
		}
		else
			return true;//验证通过
}

/**
 * 显示提示信息
 * @param {} title
 * @param {} hit
 */
function showHint(title, hit){
	try{
		Dialog.alert(msg, {windowParameters: {className: "alphacube", okLabel:"确定"}});
	}catch(err){
		try {  
			Ext.MessageBox.alert(title, hit);
		}catch(err){
			alert(hit);
		}
	}
}

/**
 * HTML取参数值
 * @param {} param 参数名
 * @return {String}
 */
function getParameter(param){
	var query = window.location.search;
	var iLen = param.length;
	var iStart = query.indexOf(param);
	if (iStart == -1)
	return "";
	iStart += iLen + 1;
	var iEnd = query.indexOf("&", iStart);
	if (iEnd == -1)
		return query.substring(iStart);
	
	return query.substring(iStart, iEnd);
}

/**
 * 清除表格内容
 * @param {} pTableID
 */
function ClearTable(pTableID){
	var tb = document.getElementById(pTableID);
	if (tb == null)
		return ;
		
	while (tb.rows.length > 0)
		tb.deleteRow(0);
}

//系统参数
ID_USER_LIFE = 3 ;
ID_CUSTOMER_UID = "UID";//用户名
ID_CUSTOMER_PD = "PD";  //密码
ID_CUSTOMER_CID = "CID";  //客户编号
ID_CUSTOMER_CNM = "CID";  //客户编号
ID_EMPTY_CID="000000";//空白客户编号
ID_DEFAULT_PD="888888";//默认密码