﻿// JScript 文件

//获取对象
function getobj(id)
{
    var obj;
    obj=(document.getElementById?document.getElementById(id):document.all?document.all[id]:document.layers[id]);
    return obj
}
function $(id)
{
    var obj;
    obj=(document.getElementById?document.getElementById(id):document.all?document.all[id]:document.layers[id]);
    return obj
}
//****************************************
//获取cookie
function getCookie(sName)
{
	var aCookie = Cookie("allicc").split("&");
	for (var i=0; i < aCookie.length; i++)
	{
	    // a name/value pair (a crumb) is separated by an equal sign
	    var aCrumb = aCookie[i].split("=");
	    if (sName == aCrumb[0])
	    {
	        return UrlDecode(aCrumb[1]);
	    }
	}
	// a cookie with the requested name does not exist
	return "";
}
//****************************************
//获取allicc的cookie
function Cookie(Name)
{
	// cookies are separated by semicolons
	var aCookie = document.cookie.split("; ");
	for (var i=0; i < aCookie.length; i++)
	{
	    // a name/value pair (a crumb) is separated by an equal sign
	    var aCrumb = aCookie[i].split("=");
	    if (Name == aCrumb[0])
	    {
	        return aCookie[i];
	    }
	}
	// a cookie with the requested name does not exist
	return "";
}
//****************************************
//js实现UrlDecode
function UrlDecode(str)
{
  var s0, i, j, s, ss, u, n, f;
  s0 = "";           // decoded str
  for (i = 0; i < str.length; i++){   // scan the source str
    s = str.charAt(i);
    if (s == "+"){s0 += " ";}     // "+" should be changed to SP
    else {
        if (s != "%"){s0 += s;}   // add an unescaped char
        else{           // escape sequence decoding
          u = 0;       // unicode of the character
          f = 1;       // escape flag, zero means end of this sequence
          while (true) {
            ss = "";   // local str to parse as int
                for (j = 0; j < 2; j++ ) { // get two maximum hex characters to parse
                  sss = str.charAt(++i);
                  if (((sss >= "0") && (sss <= "9")) || ((sss >= "a") && (sss <= "f")) || ((sss >= "A") && (sss <= "F"))) {
                    ss += sss;       // if hex, add the hex character
                  } else {--i; break;}   // not a hex char., exit the loop
                }
            n = parseInt(ss, 16);       // parse the hex str as byte
            if (n <= 0x7f){u = n; f = 1;}   // single byte format
            if ((n >= 0xc0) && (n <= 0xdf)){u = n & 0x1f; f = 2;}   // double byte format
            if ((n >= 0xe0) && (n <= 0xef)){u = n & 0x0f; f = 3;}   // triple byte format
            if ((n >= 0xf0) && (n <= 0xf7)){u = n & 0x07; f = 4;}   // quaternary byte format (extended)
            if ((n >= 0x80) && (n <= 0xbf)){u = (u << 6) + (n & 0x3f); --f;}   // not a first, shift and add 6 lower bits
            if (f <= 1){break;}         // end of the utf byte sequence
            if (str.charAt(i + 1) == "%"){ i++ ;}             // test for the next shift byte
            else {break;}             // abnormal, format error
          }
        s0 += String.fromCharCode(u);       // add the escaped character
        }
    }
  }
  return s0;
}

//****************************************
//js实现UrlEncode
function UrlEncode(str){
  var s0, i, s, u;
  s0 = "";           // encoded str
  for (i = 0; i < str.length; i++){   // scan the source
    s = str.charAt(i);
    u = str.charCodeAt(i);       // get unicode of the char
    if (s == " "){s0 += "+";}     // SP should be converted to "+"
    else {
        if ( u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <= 0x7a))){   // check for escape
          s0 = s0 + s;       // don't escape
        }
        else {               // escape
          if ((u >= 0x0) && (u <= 0x7f)){   // single byte format
            s = "0"+u.toString(16);
            s0 += "%"+ s.substr(s.length-2);
          }
          else if (u > 0x1fffff){   // quaternary byte format (extended)
            s0 += "%" + (oxf0 + ((u & 0x1c0000) >> 18)).toString(16);
            s0 += "%" + (0x80 + ((u & 0x3f000) >> 12)).toString(16);
            s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
            s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
          }
          else if (u > 0x7ff){     // triple byte format
            s0 += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);
            s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
            s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
          }
          else {               // double byte format
            s0 += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);
            s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
          }
        }
    }
  }
  return s0;
}
//****************************************
//打开新窗口
function openwin(url,name,features,replace)
{
    if (url.length>0)
        window.open(url,name,features,replace);
}

//显示层组中的焦点层.
//id为要显示的层组名,index为层序号,total为组中层的个数,bgImage1为默认按钮背景,bgImage2为激活按钮背景
function showdiv(id,index,total,bgImage1,bgImage2)
{    
    var button;
    
    for(i=1;i<=total;i++)
    {
        button=$(id+'button'+i);
        
        if(i==index)
        {
            $(id+i).style.display="block";
            if(button)
                button.style.backgroundImage="url("+bgImage2+")";
        }
        else
        {
            if($(id+i)!=null)
            {
                $(id+i).style.display="none";
                if(button)
                    button.style.backgroundImage="url("+bgImage1+")";
            }
        }
    }
 } 
 
 //在载入时自动根据内页高度调整框架高度  
function dyniframesize(iframename)
{
    var mainframe=(document.getElementById?document.getElementById(iframename):document.all?document.all[iframename]:document.layers[iframename]);
    if (mainframe && !window.opera)
    { 
        //begin resizing iframe 
        mainframe.style.display="block" ;
        
        if (mainframe.contentDocument && mainframe.contentDocument.body.offsetHeight)
            { 
                //ns6 syntax 
                mainframe.height = mainframe.contentDocument.body.offsetHeight; 
            } 
        else if (mainframe.Document && mainframe.Document.body.scrollHeight)
            {
                //ie5+ syntax 
                mainframe.height = mainframe.Document.body.scrollHeight; 
            }
    }
}

//弹出遮罩层和新层
function showZheZhaoDiv(newDivUrl,width)
{//divIndex为弹出层ID序号
 //调用的newDivUrl页面内,要用<script>parent.$('zhezhaoDiv').style.display = 'block';parent.$('newDiv').style.display = 'block';</script>显示出遮罩层和新层

    if($("zhezhaoceng"))
        document.body.removeChild($("zhezhaoceng"));//如果有创建过层,先删除再重建
    
    var divElement;
    divElement=document.createElement("div");
    divElement.id="zhezhaoceng";
    divElement.setAttribute("display","block");
    divElement.style.left=0;
    divElement.style.top=0;
    divElement.style.width=(document.all)?document.body.scrollWidth:innerWidth;
    divElement.style.position="absolute";
    divElement.setAttribute("z-index","1");
    divElement.setAttribute("text-align","center");
           
    divElement.innerHTML+="<div id='zhezhaoDiv' style='position:absolute; z-index:2;filter:alpha(opacity=12);background:#000000;width:990px;height:100px;left:0px;top:0px;display:none;'></div>";
    
    var newDivHtml="";    
    newDivHtml+="<div id='newDiv' style='position:absolute; z-index:3;top:0px;left:0px;width:100%;text-align:center;display:none;'>";
    newDivHtml+="    <iframe id='frame1' name='frame1' width='"+width+"' onload=\"dyniframesize('frame1')\" src='";
    newDivHtml+=newDivUrl;
    newDivHtml+="' frameborder='0' scrolling='no' style='margin-top: 0px; margin-left: 0px; padding-top: 0px; padding-left: 0px;'></iframe>";
    newDivHtml+="</div>";
    
    divElement.innerHTML+=newDivHtml;
    
    document.body.appendChild(divElement);
    
    $("zhezhaoDiv").style.height=(document.all)?document.body.scrollHeight:innerHeight;
    $("zhezhaoDiv").style.width=(document.all)?document.body.scrollWidth:innerWidth;
    
    $("newDiv").style.top=(document.all)? document.body.scrollTop+50:pageYOffset+50;
}

//验证用户输入的手机号是否符合手机规则
//多手机验证，手机之间使用空格隔开。
function validateMobile(NOs)
{
   var regx=/^(?:1[358]\d)-?\d{5}(\d{3}|\*{3})$/;
   var recList=NOs.split(" ");
   for(var i=0;i<recList.length;i++)
   {
      if(recList[i]=="")
         continue;
      if(!regx.test(recList[i]))
      {
         alert("请输入规范的手机号。手机号："+recList[i]+"不匹配。");
         return false;
      }
     
   }
   return true;//全部匹配成功
}

function checkYear(year){
    if(isNaN(parseInt(year)))
        {alert("年份输入有误,请重新输入!");
        return false;
    }
    if(parseInt(year)<1900 || parseInt(year) >2050)
    { 
        alert("年份应该在1900-2050之间!"); 
        return false;
    }
    else return true;
}
function checkMonth(month){
    if(isNaN(parseInt(month,10))){alert("月份输入有误,请重新输入!"); return false;}
    else if(parseInt(month,10)<1 || parseInt(month,10) >12)
    { alert("月份应该在1-12之间!");
    return false;}
    else return true;
}
function checkDateSplit(year,month,date){
    var daysOfMonth=calDays(parseInt(year),parseInt(month));
    if(isNaN(parseInt(date))){alert("日期输入有误,请重新输入!"); return false;}
    else if(parseInt(date)<1||parseInt(date)>daysOfMonth){ alert("日期应该在1-"+daysOfMonth+"之间!"); return false;}
    else return true;
}
function calDays(year,month){
    var date= new Date(year,month,0);
    return date.getDate();
}
function isLeapYear(year){
    if((year %4==0 && year %100!=0) || (year %400==0)) return true;
    else return false;
}

function checkDate(strDate){
    if(strDate.length != 6 && strDate.length != 8){
        alert("日期格式不正确!");
        return false;
    }
    var year;
    var month;
    var date;
    if (strDate.length == 6) {
        year = strDate.substr(0, 2);
        month = strDate.substr(2, 2);
        date = strDate.substr(4, 2);
    } else {
        year = strDate.substr(0, 4);
        month = strDate.substr(4, 2);
        date = strDate.substr(6, 2);
    }
    var year = year.length == 2 ? '19' + year : year;
    if(!checkYear(year)){return false;}
    if(!checkMonth(month)){return false;}
    if(!checkDateSplit(year,month,date)){return false;}
    return true;
}

//验证身份证号
function isIdCardNo(num)
{
    var factorArr = new Array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1); 
    var error; 
    var varArray = new Array(); 
    var intValue; 
    var lngProduct = 0; 
    var intCheckDigit; 
    var intStrLen = num.length; 
    var idNumber = num;    
    // initialize 
    if ((intStrLen != 15) && (intStrLen != 18)) { 
        error = "输入身份证号码长度不对！"; 
        alert(error); 
        return false; 
    }    
    // check and set value 
    for(i=0;i <intStrLen;i++) { 
        varArray[i] = idNumber.charAt(i); 
        if ((varArray[i] < '0' || varArray[i] > '9') && (i != 17)) { 
            error = "错误的身份证号码！."; 
            alert(error); 
            //frmAddUser.txtIDCard.focus(); 
            return false; 
        } else if (i < 17) { 
            varArray[i] = varArray[i]*factorArr[i]; 
        } 
    } 
    if (intStrLen == 18) { 
        //check date 
        var date8 = idNumber.substring(6,14);
        if (checkDate(date8) == false) { 
            error = "身份证中日期信息不正确！."; 
            alert(error); 
            return false; 
        }        
        // calculate the sum of the products 
        for(i=0;i <17;i++) { 
            lngProduct = lngProduct + varArray[i]; 
        }        
        // calculate the check digit 
        intCheckDigit = 12 - lngProduct % 11; 
        switch (intCheckDigit) { 
            case 10: 
                intCheckDigit = 'X'; 
                break; 
            case 11: 
                intCheckDigit = 0; 
                break; 
            case 12: 
                intCheckDigit = 1; 
                break; 
        }        
        // check last digit 
        if (varArray[17].toUpperCase() != intCheckDigit) { 
            error = "身份证效验位错误!正确为： " + intCheckDigit + "."; 
            alert(error); 
            return false; 
        } 
        //document.getElementById("E_TB_Birthday").value = idNumber.substr(6,4) + '-' + idNumber.substr(10,2) + '-' + idNumber.substr(12,2);
    } 
    else{        //length is 15 
        //check date 
        var date6 = idNumber.substring(6,12); 
        if (checkDate(date6) == false) { 
            alert("身份证日期信息有误！."); 
            return false; 
        }
        //document.getElementById("E_TB_Birthday").value = '19' + idNumber.substr(6,4) + '-' + idNumber.substr(10,2) + '-' + idNumber.substr(12,2);
    } 
    //alert ("Correct."); 
    return true; 
}

//验证邮箱格式
function checkEmail(email)
{
    var reg=/^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
    if(reg.test(email))
        return true; 
    else 
        {
            alert("邮箱格式不正确!");
            return false;
        }
}

//验证数字,只允许输入小数＼整数＼负整数＼零
function checkNum(obj)
{
 var re = /^-?[1-9]*(\.\d*)?$|^-?d^(\.\d*)?$/;
     if (!re.test(obj.value))
    {
        if(isNaN(obj.value))
        {
            alert("非法数字");
		    obj.value="";
            obj.focus();
            return false;
        }
     }
}

//显示图片
function showpic(id,src,width,height)
{   
    if(!$(id))
    {
        var imageElement;
        imageElement=document.createElement("image");
        imageElement.id=id;
        imageElement.setAttribute("display","block");
        imageElement.style.width=width;
        imageElement.style.height=height;
        imageElement.style.border=1;
        imageElement.style.position="absolute";
        
        imageElement.src=src;
        imageElement.style.left=event.clientX+document.documentElement.scrollLeft;
        imageElement.style.top=event.clientY+document.documentElement.scrollTop;
        if(document.body.clientWidth-event.clientX-document.documentElement.scrollLeft<width)
        {
            imageElement.style.left=event.clientX+document.documentElement.scrollLeft-width;
        }
        if(document.body.clientHeight-event.clientY-document.documentElement.scrollTop<height)
        {
            imageElement.style.top=event.clientY+document.documentElement.scrollTop-height;
        }
        
        document.body.appendChild(imageElement);//加入页面
    }
    //alert(imageElement.src);
}
function deleteObj(id)
{
    document.body.removeChild($(id));
}

//显示提示层,tishi为提示内容
function showTiShi(tishi)
{
    if($("tishiDIV"))
        document.body.removeChild($("tishiDIV"));//如果有创建过层,先删除再重建
    
    var divElement;
    divElement=document.createElement("div");
    divElement.id="tishiDIV";
    divElement.setAttribute("display","block");
    divElement.style.left=0;
    divElement.style.top=0;
    divElement.style.width=(document.all)?document.body.scrollWidth:innerWidth;
    divElement.style.position="fixed";
    divElement.setAttribute("z-index","1");
    divElement.setAttribute("text-align","center");
    
    var newDivHtml="";    
    newDivHtml+="<div id='infoDiv' style='position:absolute; z-index:9999;top:0px;left:0px;width:100%;text-align:center;'>";
    
    newDivHtml+="<div style='width:300px; z-index:11; text-align:left; position:absolute; background-image:url(/admin/skin/qq/images/title_bg_left.gif); height: 25px; left: 326px; top: 136px;'>";
    newDivHtml+="    <span style='margin-left:5px; z-index:12; font-size:13px; position:absolute; margin-top:5px;'>提示</span>";
    newDivHtml+="</div>";
    newDivHtml+="<div style='width:50px; z-index:13; background-image:url(/admin/skin/qq/images/title_bg_right.gif); position:absolute; left: 626px; top: 136px; height: 25px;'><span style='font-size:12px; position:absolute; margin-top:5px;'><a onclick='document.body.removeChild($(\"tishiDIV\"));' style='cursor:pointer;'><img alt='' src='/admin/skin/qq/images/close.gif' style='position:absolute;' /></a></span></div>";
    newDivHtml+="<div style='width:3px; margin-left:5px; z-index:14; background-image:url(/admin/skin/qq/images/win_l.gif); height:150px; position:absolute; top: 161px; left: 321px;'></div>";
    newDivHtml+="<div style='width:344px; background-color:White; text-align:center; z-index:15; text-align:left; background-image:url(/admin/skin/qq/images/content_bg.gif); height:150px; position:absolute; margin-left:3px; background-repeat:repeat-x; left: 326px; top: 161px;'>";
    newDivHtml+="    <div style=' margin-left:12px;width:320px;z-index:17; margin-top:10px;top: 26px; font-size:12px;'>"+tishi;
    newDivHtml+="    </div>";
    newDivHtml+="    <input id='btn_que' type='button' value='确定' style='background-image:url(/admin/skin/qq/images/btn_bg.gif);width:80px; height:21px; text-align:center;border:0px;margin-left:120px;margin-top:10px;' onclick='document.body.removeChild($(\"tishiDIV\"))'/>";
    newDivHtml+="</div>";
    newDivHtml+="<div style='width:3px; z-index:19; background-image:url(/admin/skin/qq/images/win_r.gif); height:150px; position:absolute; left:673px; top: 161px;'></div>";
    newDivHtml+="<div style='width:345px; z-index:20; background-image:url(/admin/skin/qq/images/win_b.gif); position:absolute; height:3px; left: 328px; top: 309px; background-repeat: repeat-x;' ></div>";
    
    newDivHtml+="</div>";
    
    divElement.innerHTML+=newDivHtml;
    
    document.body.appendChild(divElement);
    
    $("infoDiv").style.top=(document.all)? document.body.scrollTop+50:pageYOffset+50;
    setTimeout("$(\"infoDiv\").style.display='none'",5 *1000);
}

//复制到剪贴板clipBoardContent为要复制的内容,tiShiContent为提示内容
function copyToClipBoard(clipBoardContent,tiShiContent)
{
   if (window.clipboardData){      
      if(window.clipboardData.setData("Text",clipBoardContent)){      
          showTiShi(tiShiContent,3);     
      }      
   }      
   else{      
      showTiShi("您使用的浏览器不支持此功能",3);     
   }
}

function searchKeyTipOnBlur(obj,value,cssStr)
{
   //if(obj.value=="")
    //{
	  // obj.value=value;
	   //obj.className="input_1";
	//}
	if(arguments.length == 2){
		if(obj.value=="")
        {
	       obj.value=value;
	       obj.className="input_1";
	    }
	}
	if(arguments.length == 3){
		if(obj.value=="")
        {
	       obj.value=value;
	       if(typeof(cssStr) == "object" && cssStr != ""){
			  obj.className = cssStr;
		   }
	    }
	}
}
function searchKeyDown(event)
{
	if(!window.event) window.event=event;
	if(window.event.keyCode==13)
	{
		 fastSearcher();
	}
}
function searchKeyTipOnfocus(obj,value,cssStr)
{
	if(arguments.length == 2){
		if(obj.value==value){
	     obj.value="";
	     obj.className="input_1";
	    }
	}
	if(arguments.length == 3){
		if(obj.value==value){
	       obj.value="";
	       if(typeof(cssStr) == "object" && cssStr != ""){
			  obj.className = cssStr;
		   }
	    }
	}

}