﻿/*
==================================================================
功能：去除输入字符串左边的空格
输入：str：字符串
返回：去除左边空格后的字符串
==================================================================
*/

function LTrim(str)
{
    var whitespace = new String(" \t\n\r");
    var s = new String(str);
    if (whitespace.indexOf(s.charAt(0)) != -1)
    {
        var j=0, i = s.length;

        while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
        {
            j++;
        }
        s = s.substring(j, i);
    }
    return s;
}

/*
==================================================================
功能：去除输入字符串右边的空格
输入：str：字符串
返回：去除右边空格后的字符串
==================================================================
*/

function RTrim(str)
{
    var whitespace = new String(" \t\n\r");
    var s = new String(str);
    if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
    {
        var i = s.length - 1;
        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
        {
            i--;
        }
        s = s.substring(0, i+1);
    }
    return s;
} 

/*
==================================================================
功能：去除输入字符串左右两边的空格
输入：str：字符串
返回：去除左右两边空格后的字符串
==================================================================
*/

function Trim(str)
{
    return RTrim(LTrim(str));
}

/*
================================================================================
功能：将输入字符串替换为目的字符串
输入：strText：原字符串 FindText：需要替换的字符串 ReplaceText：替换成的字符串
返回：如果为空返回true,否则返回false
================================================================================
*/

function Replace(strText,FindText,ReplaceText)
{
      var Pos=0;
      var Len=FindText.length;
      Pos=strText.indexOf(FindText);
      while(Pos!=-1){
         lString=strText.substring(0,Pos);
         rString=strText.substring(Pos+Len,strText.length);
         strText=lString+ReplaceText+rString;
         Pos=strText.indexOf(FindText);
      }
      return strText;
}

/*
==================================================================
功能：验证输入的对象的值是否为空
输入：Obj：对象
返回：如果为空返回true,否则返回false
==================================================================
*/
function isEmpty(Obj)
{
    if(Trim(Obj.value)=="")
    {
        if(Obj.disabled==false && Obj.readOnly==false)
            Obj.focus();
        return true;
    }
    else
        return false;
}
/*
================================================================
功能：验证输入的电话号码的区号是否合法
输入：areaCode：电话号码的区号
返回：如果为合法areaCode返回true,否则返回false
================================================================
*/
function CheckAreaCode(areaCode)
{
   var str=areaCode;
   var reg=/(^0[0-9]{2,3})/
   return reg.test(str);
}

function CheckPhone(phone)
{
    var str = phone;
   // var reg=/(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/
    var reg=/(^[0-9]{7,8}([0-9|/|\-|,|;|\\\\])*$)|(^0{0,1}13[0-9]{9}$)/
    return reg.test(str);
}

function CheckFax(fax)
{
    var str = fax;
    var reg=/(^[0-9]{3,4}\-[0-9]{3,8}((|-|,|\/|;)\d{1,8})*$)|(^[0-9]{3,8}((|-|,|\/|;)\d{1,8})*$)|(^\([0-9]{3,4}\)[0-9]{3,8}((|-|,|\/|;)\d{1,8})*$)/
    return reg.test(str);
}
/*
==================================================================
功能：检测Email地址是否合法
输入：strEmail：电子邮箱地址
返回：如果为合法EMail地址返回true,否则返回false
==================================================================
*/

function CheckEmail( strEmail ) 
{
    if (strEmail.length == 0) 
        return (false);
    reVal = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
    return ( reVal.test(strEmail) );
}


/*
==================================================================
用途：检查输入字符串是否符合正整数格式
输入：str：字符串,n：如果n＝0字符串为空验证不通过，否则字符串为空验证通过
返回：如果通过验证返回true,否则返回false
==================================================================
*/

function isNumber( str,n )
{
    n = n || 0;
    if( n != 0 && str == '' )
        return true;
        
    var regu = "^[0-9]+$";
    var re = new RegExp(regu);
    
    if (str.search(re) != -1)
        return true;
    else
        return false;
}

/*
==================================================================
用途：检查输入字符是否符合正整数格式
参数：str： 如果 n = 0 只能输入数字,n = 1 可以输入小数点; n= 2可以输入空格,_,:
    e = event
返回：如果通过验证返回true,否则返回false
==================================================================
*/
function OnlyNumber(n,e)
{
    if(n == 0)
        event.returnValue = e.keyCode > 47 && e.keyCode < 58
    else if( n == 1 )
        event.returnValue = e.keyCode > 47 && e.keyCode < 58 || e.keyCode == 46
    else if(n == 3)
        event.returnValue = e.keyCode > 47 && e.keyCode < 59 || e.keyCode == 32 || e.keyCode ==95
}

function IsChinese(str)
{ 
    //if( escape(str).indexOf("%u") != -1 )
    objs = str.match( /[\u4e00-\u9fa5]/g )
    if( objs != null )
    {
        objs += "";
        objs = objs.replace( ',',"" )
        alert(objs);
    }
    else
        alert('false');
    //return false; 
}

/*
==================================================================
用途：检查输入字符串是否只由英文字母和数字和下划线组成
输入：str：字符串
返回：如果通过验证返回true,否则返回false
==================================================================
*/

function isNumberOrLetter( str )
{//判断是否是数字或字母
    var regu = "^[0-9a-zA-Z\_]+$";
    var re = new RegExp(regu);
    if (re.test(str))
        return true;
    return false;
}

/*
==================================================================
用途：字符1是否以字符串2开始
输入：str1：字符串；str2：被包含的字符串
返回：如果通过验证返回true,否则返回false
==================================================================
*/

function isStartWith(str1,str2)
{
    var index = str1.indexOf(str2);
    if(index==0)
        return true;
    return false;
}

/*
==================================================================
用途：字符1是否以字符串2结束
输入：str1：字符串；str2：被包含的字符串
返回：如果通过验证返回true,否则返回false
==================================================================
*/

function isEndWith(str1,str2)
{
    var index = str1.lastIndexOf(str2);
    if(str1.length==index+str2.length)
        return true;
    return false;
}

/*
==================================================================
用途：字符1是包含字符串2
输入：str1：字符串；str2：被包含的字符串
返回：如果通过验证返回true,否则返回false
==================================================================
*/
function isMatch(str1,str2)
{ 
    var index = str1.indexOf(str2);
    if(index==-1)
        return false;
    return true;
}

/*
==================================================================
用途：打开模态窗口
输入：Url：Url地址；Width：模态窗口的宽度,Height模态窗口的高度,
==================================================================
*/
function ShowDialog( Url,Width,Height,isScroll)
{
    var scroll = isScroll ==true?"scroll:no":"";
    return  window.showModalDialog(Url,'','dialogWidth='+ Width +';dialogHeight='+ Height +';center:yes;'+ scroll +'');
}

/*
==================================================================
用途：校验ip地址的格式
输入：strIP：ip地址
返回：如果通过验证返回true,否则返回false；
==================================================================
*/

function isIP(strIP)
{ 
    if (isNull(strIP)) return false;
    var re=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/g //匹配IP地址的正则表达式
    if(re.test(strIP))
        if( RegExp.$1 <256 && RegExp.$2<256 && RegExp.$3<256 && RegExp.$4<256)
            return true;
    return false;
}
/*
==================================================================
用途：校验URL地址的格式
输入：strURL：URL地址
返回：如果通过验证返回true,否则返回false；
==================================================================
*/
function CheckURL(strURL)
{
    var regTextUrl = /^(file|http|https|ftp|mms|telnet|news|wais|mailto):\/\/(.+)$/;
    return regTextUrl.test(strURL);
}


/*
==================================================================
关闭Mouse右键
==================================================================
*/

if (window.Event) 
{
	document.captureEvents(Event.MOUSEUP); 
}

function nocontextmenu() 
{ 
	event.cancelBubble = true 
	event.returnvalue = false; 
	return false; 
} 

function norightclick(e) 
{ 
	if (window.Event) 
	{ 
		if (e.which == 2 || e.which == 3) 
		return false; 
	} 
	else if (event.button == 2 || event.button == 3) 
	{ 
		event.cancelBubble = true 
		event.returnvalue = false;
		//alert("欢迎使用该系统!");
		return false; 
	} 
}

//document.oncontextmenu = nocontextmenu; // for IE5+
//document.onmousedown = norightclick; // for all others

function getcookie(name) {
	var cookie_start = document.cookie.indexOf(name);
	var cookie_end = document.cookie.indexOf(";", cookie_start);
	return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
}

function setcookie(cookieName, cookieValue, seconds, path, domain, secure) {
	var expires = new Date();
	expires.setTime(expires.getTime() + seconds);
	document.cookie = escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '/')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');
}


/*
==================================================================
用途：CheckBox全选
输入：FormID：document,chkName：checkBox的Name,checked：是否选中
==================================================================
*/

function CheckAll( FormID,chkName,checked )
{
    var chkBox = FormID.getElementsByName(chkName);
    for(var i=0; i<chkBox.length; i++)
    {
        if( chkBox[i].type == "checkbox" && chkBox[i].disabled== false)
            chkBox[i].checked = checked;  
    }
}

/*
==================================================================
用途：获得checkBox选中的Value值
输入：FormID：document,chkName：checkBox的Name
返回：返回所有checkBox选中的Value值以逗号分隔
==================================================================
*/
function GetCheckBoxValue( FormID,chkName )
{
    var chkBox = FormID.getElementsByName(chkName);
    var chkBoxValue = "";
    for(var i=0; i<chkBox.length; i++)
    {
        if( chkBox[i].type == "checkbox" && chkBox[i].checked == true )
            chkBoxValue += chkBox[i].value + ',';
    }
    return chkBoxValue;
}

/*
==================================================================
用途：获取URL参数值
输入：name：参数名
返回：URL参数值,没找到则返回空
==================================================================
*/
function GetUrlValue(name)
{
 var str=window.location.search.toLowerCase();
 name = name.toLowerCase();
 if (str.indexOf(name)!=-1)
 {
    var pos_start=str.indexOf(name)+name.length+1;
    var pos_end=str.indexOf("&",pos_start);
    if (pos_end==-1)
        return str.substring(pos_start);
    else
        return str.substring(pos_start,pos_end)
 }
 else
      return '';
}
/*
==========================================================================
用途：限制文本长度
输入：要限制长度的对象和最大长度,event对象
==========================================================================
*/
function ValidationTextLength(obj,length,e)
{
    if(obj.value.length>length)
    {
        obj.value = obj.value.substr(0,300);
        e.returnValue = false;
    }
}

/*
==========================================================================
用途：验证文件是否为有效的图片文件
输入：控件对象
==========================================================================
*/
function isImageFile(obj){
        var fileType = Trim(obj.value.match(/^(.*)(\.)(.{1,8})$/)[3]).toUpperCase();
        if(fileType == 'BMP' || fileType == 'GIF' || fileType == 'JPG' || fileType == 'JPEG')
            return true;
        else
            return false;
    }
/*
==========================================================================
用途：判断用户用什么样的浏览器
==========================================================================
*/
function getClientBounds()
{
	var clientWidth;
	var clientHeight;
	switch(Sys.Browser.agent) {
		case Sys.Browser.InternetExplorer:
			clientWidth = document.documentElement.clientWidth;
			clientHeight = document.documentElement.clientHeight;
			break;
		case Sys.Browser.Safari:
			clientWidth = window.innerWidth;
			clientHeight = window.innerHeight;
			break;
		case Sys.Browser.Opera:
			clientWidth = Math.min(window.innerWidth, document.body.clientWidth);
			clientHeight = Math.min(window.innerHeight, document.body.clientHeight);
			break;
		default:  // Sys.Browser.Firefox, etc.
			clientWidth = Math.min(window.innerWidth, document.documentElement.clientWidth);
			clientHeight = Math.min(window.innerHeight, document.documentElement.clientHeight);
			break;
	}

	return new Sys.UI.Bounds(0, 0, clientWidth, clientHeight);
}
/*
==========================================================================
用途：数据加载时和数据保存时,弹出友好提示(用层做的)方法,取得当前窗体的高度和宽度
==========================================================================
*/
function resizeElements()
{
	var clientBounds = getClientBounds();
	var clientWidth = clientBounds.width;
	var clientHeight = clientBounds.height;

	var bg = $get("modalBackground");	
	bg.style.width = Math.max(Math.max(document.documentElement.scrollWidth, document.body.scrollWidth), clientWidth) + 'px';
	bg.style.height = Math.max(Math.max(document.documentElement.scrollHeight, document.body.scrollHeight), clientHeight) + 'px';
}
/*
==========================================================================
用途：当用户刷新所有的选项时,弹出友好提示(用层做的)方法,取得当前窗体的高度和宽度
==========================================================================
*/
function bufferElements()
{
	var clientBounds = getClientBounds();
	var clientWidth = clientBounds.width;
	var clientHeight = clientBounds.height;

	var bg = $get("bufferBackground");	
	bg.style.width = Math.max(Math.max(document.documentElement.scrollWidth, document.body.scrollWidth), clientWidth) + 'px';
	bg.style.height = Math.max(Math.max(document.documentElement.scrollHeight, document.body.scrollHeight), clientHeight) + 'px';
}
/*
==========================================================================
用途：当用户没有被审核时,设置弹出层的高度和宽度(不包括菜单、头部和尾部)
==========================================================================
*/

function divElements()
{
	var divBack = document.all("divBackground");	
	var parentTD=divBack.parentNode;
	var isDIV = false;
	if(divBack.parentNode.tagName.toLowerCase() == 'div'){
	    isDIV = true;
	}
	var clientWidth = Math.max(parentTD.clientWidth,parentTD.scrollWidth);
    var clientHeight =Math.max(parentTD.clientHeight,parentTD.scrollHeight);
    divBack.style.width= clientWidth;
    divBack.style.height = clientHeight+18;
    if(!isDIV){
        divBack.style.left=185;
    }
    
    var  iframe= document.all("iframe");
    iframe.style.width= clientWidth;
    iframe.style.height = clientHeight+18;
    
    if(document.all("ChoiceShow1_ddlShow"))
    {
       divBack.style.top=140;
       divBack.style.height = clientHeight-10;
       iframe.style.height = clientHeight-10;
    }
    else
    {
        if(!isDIV)
            divBack.style.top=112;
    }
    //中间提示信息的样式
    var divPor=document.all("divProgress"); 
    divPor.style.left=clientWidth/2-182;
    if(clientHeight>490) 
        divPor.style.top=(490/2)-95;
    else
        divPor.style.top=(clientHeight+18)/2-95;
}
/*
==========================================================================
用途：弹出友好提示,如果用户在2秒内不关闭,将自动关闭
==========================================================================
*/
var _opacity;
var _time;
var _controlid;
var _isFouse=false;
var _divBack;
var _btnRemind;
var _setIntervalID;
function remindElements(spanMessage,control,isbool)
{
    this._time=10;
    this._opacity=100;
    this._controlid=control.name;
    this._isFouse=isbool;
    
    this._divBack = document.all("divBackground");	
    this._divBack.style.display="";
    this._divBack.style.backgroundColor="White";
    this._divBack.className="remindProgress"; 
    
    this._btnRemind= document.all("btnRemind");
    this._btnRemind.style.display="";
    
    var  iframe= document.all("iframe");
    iframe.style.width= "364px";
    iframe.style.height = "192px";
    iframe.style.zIndex="-1";
    iframe.style.position="absolute";
    iframe.className="";

    var divPro = document.all("divProgress");
    divPro.style.left=_divBack.style.left;
    divPro.style.top=_divBack.style.top;
    divPro.className="";

    var remindSpan = document.all("remindSpan");
    remindSpan.innerHTML=spanMessage;
    
    divBackgroundHidden();
}
/*
==========================================================================
用途：弹出友好提示后,用渐变色来关闭层
==========================================================================
*/

function divBackgroundHidden()
{
    this._divBack.style.filter="alpha(opacity=100)";
    this._time=_time-1;
    this._btnRemind.value="关闭 ["+_time+"]";
    
    if(_time<=1)
    {
        clearInterval(_setIntervalID);
        _setIntervalID = setInterval("ChangeDivOpacity(_opacity);_opacity-=10",100);
    }
    else
        setTimeout("divBackgroundHidden()",1000);
}

function ChangeDivOpacity(opacity)
{
    this._divBack.style.filter="alpha(opacity="+opacity+")";
    if(opacity == 30)
        this._btnRemind.value="关闭 [0]";
    if(opacity <= 0)
    {
        clearInterval(_setIntervalID);
        _divBack.style.display='none';
        if(_isFouse=="true")
          document.all(_controlid).focus();
    }
}
/*
==========================================================================
用途：弹出友好提示后,用户单击关闭层
==========================================================================
*/
function divBackgroundColse()
{
    document.all('divBackground').style.display='none';
     if(_isFouse=="true")
          document.all(_controlid).focus();
}
   
      
/*
=======================================================
用途:验证输入时间格式
========================================================
*/
function isDateTime(txtObj)
{
   var result=true;
   if(txtObj.value == "")
   {
         remindElements("提示: 加入时间不能为空!",document.getElementById(txtObj),"false");
         document.getElementById(txtObj).focus(); 
         result= false;   
   }
   else if(document.getElementById(txtObj).value.length < 8  || document.getElementById(txtObj).value.indexOf(' ')==-1 )
    {       
         remindElements("提示: 时间格式不正确!\n正确的日期时间格式应该为数字和'-'组成如(2007-09-01 12:00:00)",document.getElementById(txtObj),"false");
         document.getElementById(txtObj).focus();  
         result= false;
    }
   else
      {
         var txtDate=document.getElementById(txtObj).value;
         var isChar= txtDate.split(' ');
         var IntutDate=isChar[0].split('-');
         var IntutDate2=isChar[1].split(':'); 
         var CheckedYear=IntutDate[0];
         var CheckedMon=IntutDate[1];
         var CheckedDay=IntutDate[2];
         var ToDate=new Date();
         for(var i = 0; i<IntutDate2.length; i++)
         {
            if(IntutDate2[i].length >2 )
            {
                remindElements("正确的日期时间格式应该为数字和'-'组成如(2007-09-01 12:00:00)",document.getElementById(txtObj),"false");
                result= false;
            }
         }
        if( !isNumber(CheckedYear,0) || !isNumber(CheckedMon,0) ||  !isNumber(CheckedDay,0) || CheckedMon.length > 2 || CheckedDay.length > 2 || CheckedYear < 2000 ||  CheckedYear.length < 4)
        {
             remindElements("正确的日期时间格式应该为数字和'-'组成如(2007-09-01 12:00:00)",document.getElementById(txtObj),"false");
             document.getElementById(txtObj).focus();
             result= false;
        }
        if ( !isNumber(IntutDate2[0],0) || !isNumber(IntutDate2[1],0) || !isNumber(IntutDate2[2],0))
        {
            remindElements("正确的时间格式应该为数字和'-'组成如(2007-09-01 12:00:00)",document.getElementById(txtObj),"false");
            document.getElementById(txtObj).focus();
            result= false;
        }
     }     
   return result;    
}
      
 /*
 ================================================================================================
 用途：用于切换选项卡控件
 参数 tabCount    --选项卡数量
      tabName     --选项卡名称
      tabNum      --要使用新样式的选项卡号码  
      newClassName--新的样式名称
    
      示例 ：请看 Cooperation文件夹下 Spider_EmbodyHistory.aspx
 ================================================================================================
 */
 function TabSelectChange(tabCount,tabName,tabNum,newClassName)
 {
    var tab = null;
    
    for(var i=0 ;i<tabCount ;i++){
        tab = document.getElementById(tabName+i.toString()).className='';
    }

    tab = document.getElementById(tabName+tabNum).className=newClassName;
    
 }
  /*
 ================================================================================================
 用途：用于助手选项卡控件
 参数 tabCount    --选项卡数量
      tabName     --选项卡名称
      tabNum      --要使用新样式的选项卡号码  
      newClassName--新的样式名称
    
      示例 ：请看 Cooperation文件夹下 Spider_EmbodyHistory.aspx
 ================================================================================================
 */
 function TabSelectChange2(tabCount,tabName,tabNum,newClassName)
 {
    var tab = null;
    
    for(var i=0 ;i<tabCount ;i++){
        tab = document.getElementById(tabName+i.toString()).className='';
    }

    tab = document.getElementById(tabName+tabNum).className=newClassName;
    
 }
/*
=============================================================================================
用途:用户评价功能,提示用户先选择评分
=============================================================================================
*/
function GradeSubmit()
{
    if(document.getElementById('UserGrade1_ThaiRating_RatingExtender_ClientState').value=='0')
    {
        document.getElementById('spanGrade').innerText='请您先为本页选择评分！';
        document.getElementById('spanGrade').style.color="Red";
        return false;
    }
    else
    {
        document.getElementById('spanGrade').innerText='我对本页的评价';
        document.getElementById('spanGrade').style.color="Black";
    } 
    return true;
} 



/*
======================================================================================================
用途：菜单弹出注册模态注册页面
======================================================================================================
*/
function ShowRegWindow()
{ 
    ShowDialog();
}