﻿/********************************************
给字符串增加截空格的方法
********************************************/
String.prototype.Trim = function() 
{ 
    return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 

String.prototype.LTrim = function() 
{ 
    return this.replace(/(^\s*)/g, ""); 
} 

String.prototype.RTrim = function() 
{ 
    return this.replace(/(\s*$)/g, ""); 
}

/********************************************
获取窗口尺寸（窗口显示区域的尺寸）
********************************************/
var winWidth = 0;
var winHeight = 0;
function GetWindowSize() 
{
    //获取窗口宽度
    if (window.innerWidth)
    {
        winWidth = window.innerWidth;
    }
    else if ((document.body) && (document.body.clientWidth))
    {
        winWidth = document.body.clientWidth;
    }
    //获取窗口高度
    if (window.innerHeight)
    {
        winHeight = window.innerHeight;
    }
    else if ((document.body) && (document.body.clientHeight))
    {
        winHeight = document.body.clientHeight;
    }
    //通过深入Document内部对body进行检测，获取窗口大小
    if (document.documentElement  && document.documentElement.clientHeight && document.documentElement.clientWidth)
    {
        winHeight = document.documentElement.clientHeight;
        winWidth = document.documentElement.clientWidth;
    }
}

/********************************************
打开关闭窗口
********************************************/
function CloseCenterDiv(div)
{
    var oDiv = document.getElementById(div);
    oDiv.style.display = "none";
}

function CenterDiv(div)
{
    var oDiv = document.getElementById(div); 
    GetWindowSize();
    oDiv.style.display = "block";
    if(typeof div != 'undefined')
    {
        oDiv.style.position='absolute';
        oDiv.style.left = (winWidth - oDiv.clientWidth)/2;
        oDiv.style.top = (winHeight - oDiv.clientHeight)/2;
    }
}

function OpenDiv(div)
{
    var oDiv = document.getElementById(div);
    GetWindowSize();
    oDiv.style.display = "block";
}
/********************************************
常用的验证函数
********************************************/
//真实姓名
function checkNameN(getO)
{
    re=  /^[^\'\,\;\$\|\@\*]{2,10}$/gi
    msg = "真实姓名格式错误"
    xx = regExpCheck(re,getO,msg)
    if (xx==true)
    {
        re = /[^ -}]/gi
        gV = getO.value
        if( gV.match(re)== null)
            return true
        else
        {
            gV_c = (gV.match(re)).length
            gV_e = gV.length-gV_c
            gv_len = gV_c*2 + gV_e
            if (gv_len>20)
            {
                alert("不能长于10个字符")
                return false;
            }
            else
                return true
        }
    }
    else
        return false;
}
//验证身份证号码
function checkIdCard(getO)
{
    re= /^(([0-9]{15})|([0-9a-z]{18}))$/gi;
    msg = "身份证格式错误"
    return regExpCheck(re,getO,msg)
}
//验证电子邮件
function checkEmail(getO)
{
    re= /^([\.\w-]){2,30}@([\w-]){3,30}(\.([\w]){2,4}){1,2}/gi
    msg = "邮箱格式错误"
    return regExpCheck(re,getO,msg)
}
//验证邮政编码
function checkZipCode(getO)
{
    re= /^([0-9]{6})$/gi
    msg = "邮政编码格式为：6位  数字(0-9)"
    return regExpCheck(re,getO,msg)
}
//验证电话号码
function checkPhone(getO)
{
    re= /^([\d]){2,5}-([\d]){3,14}/gi
    msg = "电话格式错误\r\n\r\n区域号码和电话号码中间请用“-”格开，例如：029-82303721"
    return regExpCheck(re,getO,msg)
}
//验证手机号码
function checkMobile(getO)
{
    re= /^(\+?[0-9]{0,3}13[0-9]{9})$/gi
    msg = "手机格式错误"
    return regExpCheck(re,getO,msg)
}

/********************************************
自定义控件
********************************************/
var ShowddlVocabulary1 = true;
var ShowddlVocabulary2 = false;
function ViewddlVocabulary(valueID)
{
    valueID = valueID.substring(0,15);
    document.getElementById(valueID+"Tr1").style.display = (ShowddlVocabulary1) ? "none" : "block";
    document.getElementById(valueID+"Tr2").style.display = (ShowddlVocabulary2) ? "none" : "block";
    ShowddlVocabulary1 = !ShowddlVocabulary1;
    ShowddlVocabulary2 = !ShowddlVocabulary2;

    if(!ShowddlVocabulary1)
    {
        var drp = document.getElementById(valueID+"ddlVocabulary");

        var Text = drp.options[drp.selectedIndex].innerText; 

        if(Text=="")
        {  
            document.getElementById('<%=Tr3.ClientID%>').style.display = "none";
        }
        else
        {
            document.getElementById(valueID+"Tr3").style.display = "block";
            document.getElementById(valueID+"txtVocabulary").value = Text;
        }
    }
}

/********************************************
验证长度
********************************************/
String.prototype.len=function()
{ 
    return this.replace(/[^\x00-\xff]/g,"**").length; 
} 

function CheckLength(source, arguments) 
{ 
    var ValidStrLength=200;                  
    if (arguments.Value.len()<=ValidStrLength) 
        arguments.IsValid = true; 
    else 
        arguments.IsValid = false; 
} 
function CheckLength4000(source, arguments) 
{ 
    var ValidStrLength=3500;                  
    if (arguments.Value.len()<=ValidStrLength) 
        arguments.IsValid = true; 
    else 
        arguments.IsValid = false; 
} 

/********************************************
背景变黑的提示框
********************************************/
function $id(id){
	return document.getElementById(id);
	}
function ShowMsg(){
	document.writeln("<div id=\"msgdiv\" style=\"position:absolute;display:none;border:2px solid #AFCEF9;\"><\/div>");
	document.writeln("<div id=\"overdiv\" style=\"position:absolute;display:none;\">");
	document.writeln("<\/div>");
	//回调函数
	this.ok_callback=function(){};
	this.cancel_callback=function(){};
	this.msgobjname=""
	this.show=function(msgtitle,msgcontent,selecttype,width){
		var tempobj1=$id("msgdiv");
		var tempobj2=$id("overdiv");
		var msgobj=this.msgobjname;
  		tempobj2.style.filter="alpha(opacity=75)";
  		tempobj2.style.MozOpacity = 75/100;
    	tempobj2.style.backgroundColor = "#FFFFFF";
	  	tempobj2.style.display = '';
    	tempobj2.style.zIndex= 100;
    	tempobj2.style.height= document.documentElement.clientHeight+"px";
    	tempobj2.style.width= document.documentElement.clientWidth+"px";
			tempobj2.style.left=0;
			tempobj2.style.top=0;
			tempobj1.style.display="none";
//    	tempobj1.style.left= (document.documentElement.clientWidth)/3+"px";
//    	tempobj1.style.top= (document.documentElement.scrollTop+(document.documentElement.clientHeight)/3)+"px";
    	tempobj1.style.left= "30px";
    	tempobj1.style.top= "30px";
    	tempobj1.style.display= '';
    	tempobj1.style.width=width+"px";
    	tempobj1.style.height=0+"px";
    	tempobj1.style.zIndex= 200;
    	tempobj1.style.backgroundColor = "#CDDAF1";
    	var OutStr;
    	OutStr="<div style=\"font-weight:bolder;text-align:center;height:20px;font-size:14px;background-color:#6088D2;cursor:move\" canmove=\"true\" forid=\"msgdiv\"><div style=\"float:left;\">"+msgtitle+"</div><div style=\"float:Right;\"><%--<a href=\"#\" onclick=\""+msgobj+".cancel()\">【关闭】</a>--%></div></div>"
    	OutStr=OutStr+"<div style=\"text-align:center;font-size:12px;\">"+msgcontent+"</div>"
   		if(selecttype==1){
    		OutStr=OutStr+"<div style=\"text-align:center;font-size:12px;\"><input type=\"button\" value=\"确 定\" onclick=\""+msgobj+".ok()\">    <input type=\"button\" value=\"取 消\" onclick=\""+msgobj+".cancel()\"></div>"
    	}
   	 	else if(selecttype==2){
    		OutStr=OutStr+"<div style=\"text-align:center;font-size:12px;\"><input type=\"button\" class=\"input\" value=\"确 定\" onclick=\""+msgobj+".ok()\"></div>"
    	}
    	
    	tempobj1.innerHTML=OutStr;
    	var md=false,mobj,ox,oy
     	document.onmousedown=function(ev)
     	{
			var ev=ev||window.event;
			var evt=ev.srcElement||ev.target;
         	if(typeof(evt.getAttribute("canmove"))=="undefined")
         	{
            	 return;
         	}
         	if(evt.getAttribute("canmove"))
         	{
             	md = true;
             	mobj = document.getElementById(evt.getAttribute("forid"));
             	ox = mobj.offsetLeft - ev.clientX;
             	oy = mobj.offsetTop - ev.clientY;
         	}
     	}
     	document.onmouseup= function(){md=false;}
     	document.onmousemove= function(ev)
     	{
			var ev=ev||window.event;
         	if(md)
         	{
             	mobj.style.left= (ev.clientX + ox)+"px";
             	mobj.style.top= (ev.clientY + oy)+"px";
         	}
     	}
		}
		this.ok = function()
		{
			$id('msgdiv').style.display='none';
			$id('overdiv').style.display='none';
			this.ok_callback();
		}
		this.cancel=function(){
			$id('msgdiv').style.display='none';
			$id('overdiv').style.display='none';
			this.cancel_callback();
		}
	}
var ShowMsg=new ShowMsg();
//设置对象名,供内部引用
ShowMsg.msgobjname="ShowMsg";
//定义回调函数
ShowMsg.ok_callback=function(){
	return true;
	}
ShowMsg.cancel_callback=function(){
	return false;
	}

	
    function openSendMSG(nameAndPath)
    {
        var iframe="<iframe id=\"main1\" name=\"main1\" src=\"" + nameAndPath + "\" scrolling=\"no\" width=\"250px\" height=\"120px\" frameborder=\"no\"></iframe>"
       
        ShowMsg.show("",iframe,2,260);
    }

/********************************************
多选框操作
********************************************/
function OppositeCheck()
{
    var frm = document.forms[0];
    for(var i=0;i<frm.elements.length;i++)
    {
      var e = frm.elements[i];
      if(e.type == 'checkbox')
      {
         e.checked = !e.checked;
      }
    }
}
function OppositeCheckfalse()
{
    var frm = document.forms[0];
    for(var i=0;i<frm.elements.length;i++)
    {
      var e = frm.elements[i];
      if(e.type == 'checkbox')
      {
         e.checked = false;
      }
    }
}
function OppositeCheckTrue()
{
    var frm = document.forms[0];
    for(var i=0;i<frm.elements.length;i++)
    {
      var e = frm.elements[i];
      if(e.type == 'checkbox')
      {
         e.checked = true;
      }
    }
}

/********************************************
导出excel格式
********************************************/
function tableToExcel(tblName)   
{

  function String.prototype.Trim() {return this.replace(/(^\s*)|(\s*$)/g,"");}
  try
  {
    var e = document.getElementById(tblName);
    var s = ""
    for (var j=0; j<e.rows.length; j++)
    {
      if (e.rows[j].style.display != "none")
      {
        for (var i=1; i<e.rows[j].cells.length; i++)
        {
          if (e.rows[j].cells[i].style.display != "none") 
            s += e.rows[j].cells[i].innerText.Trim() +"\t";
        }
        s += "\r\n";
      }
    }
    var xlsWindow = window.open("","_blank","width=100,height=100");
    xlsWindow.document.write(s);
    xlsWindow.document.execCommand('Saveas',true,'%homeDrive%\\Data.xls');
    xlsWindow.close();
  }
  catch(e)
  {}
}
