﻿//四舍五入函数
function ForDight(Dight,How) 
{
   return Math.round(Dight*Math.pow(10,How))/Math.pow(10,How); 
}   
//选项背景颜色控制
function SelectItem(Values,Flag,Objs)
{
    if(ObjsTd!=null)ObjsTd.style.backgroundColor="";
    ObjsTd=document.getElementById(Objs);
    ObjsTd.style.backgroundColor="#DDDDDD";
}
//region设置选择---------------------------------------------
CheckFlag=false;
function CheckSelect()
{
	return CheckSelect_ForVarNames("SelectId"); 
}
function CheckSelect_ForVarNames(Names)
{
    var Obj=document.getElementsByName(Names); 
	if(CheckFlag==false)
	{ 
		  for(var i=0;i<Obj.length;i++)Obj[i].checked=true;
		  CheckFlag=true;
    }
	else
    {
		  for(var i=0;i<Obj.length;i++)Obj[i].checked=false;
		  CheckFlag=false;	 
    } 
}
function GetCheckSelectValue(ObjName)
{
   Temp="";
   Obj=document.getElementsByName(ObjName);
   for(var i=0,j=Obj.length;i<j;i++)
   {
      if(Obj[i].checked==true)Temp+=Obj[i].value+",";
   }
   return Temp.substring(0,Temp.length-1);
}
function GetCheckSelectStates(ObjName) {
    Obj = document.getElementsByName(ObjName);
    for (var i = 0,j = Obj.length;i < j;i++) {
        if (Obj[i].checked == true)return true;
    }
    return false;
}
//endregion--------------------------------------------------------
//region验证是否为邮件---------------------------------------------
function IsEmail(Obj)
{
	return IsEmail(Obj,"提示：请输入正确的邮箱地址！");
}
function IsEmail(Obj,Alert)
{
    var Email=Obj.value
    var Pattern=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
    Flag=Pattern.test(Email);
    if (Flag)
    {return true;}
    else
    {
           if(Alert!="")alert(Alert);
           return false;
     }
}
//endregion--------------------------------------------------------
//复制信息到剪贴板上-----------------------------------------------
function CopyToClipBoard(thisvalue)
{
var clipBoardContent="";
clipBoardContent+=thisvalue;
window.clipboardData.setData("Text",clipBoardContent);
alert("复制成功，您复制的信息为：'"+clipBoardContent+"'");
} 
//endregion--------------------------------------------------------
//确认检测函数-------------------------------------------------------
function SetformCheck(FromList,Alerts)
{
	return SetformCheck(FromList,Alerts,"","Focus");
}
function SetformCheck(FromList,Alerts,Panel,PromptFlag)
{
   i=0;
   Flag=1;
   FromList=FromList.split('|');
   while (Flag==1)
   {
      if((i+1)<FromList.length)
      {
         if(document.getElementById(FromList[i])!=null)
         {
             if(document.getElementById(FromList[i]).value=="")
             {
                Flag=0;
             }
             else
             {
                switch(FromList[i])
                {
                   case "Account":
                       if (document.getElementById(FromList[i]).value.length < 4 || document.getElementById(FromList[i]).value.length > 16) Flag = 0;
                       if (CheckString(document.getElementById(FromList[i]).value) == false) Flag = 0;
                       break;
                   case "Mobile":
                       if(document.getElementById(FromList[i]).value.length!=11) Flag=0;
                       break;
                   break;
                   case "Email":
                       if(IsEmail(document.getElementById(FromList[i]),"")==false) Flag=0;
                       break;
                   break;
				   case "Pwd":
				       if (document.getElementById(FromList[i]).value.length < 4 || document.getElementById(FromList[i]).value.length > 16) Flag = 0;
				       if (CheckString(document.getElementById(FromList[i]).value) == false) Flag = 0;
				       break;
				   break;
				   case "CheckConfigPwd":
				       if(document.getElementById("Pwd").value!=document.getElementById("ConfigPwd").value) Flag=0;
				   break;
                }
             }
         }
         i++;
      }
      else
      {
          Flag=2;
      }
  } 
   if(Flag==0)
   {
      if(Alerts!="")alert(Alerts);
      try
      {
		  if(PromptFlag==undefined || PromptFlag=="Focus")
		  {
             document.getElementById(FromList[i-1]).focus();
		  }
		  else {
			 document.getElementById(Panel+FromList[i-1]).style.display="";
		  }
      }
      catch(err)
      {
         alert("ISDDP：原始数据处理失败，请重新提交...");
      }
      return false;
   }
   else
   {
      return true;
   }
}
function SetformCheck_ForInt(FromList,Alerts)
{
   i=0;
   Flag=1;
   FromList=FromList.split('|');
   while (Flag==1)
   {
      if((i+1)<FromList.length)
      {
         if(document.getElementById(FromList[i])!=null)
         {
              if(document.getElementById(FromList[i]).value!="")
              {
                  rgx=/^[1-9]+[0-9]*$/;
                  if(!rgx.test(document.getElementById(FromList[i]).value)) Flag=0;
              }
         }
         i++;
      }
      else
      {
          Flag=2;
      }
   }
   if(Flag==0)
   {
      if(Alerts!="")alert(Alerts);
      document.getElementById(FromList[i-1]).focus();
      return false;
   }
   else
   {
      return true;
   }
}
function SetformCheck_ForInt_WithReturn(Value)
{
   rgx=/^[1-9]+[0-9]*$/;
   if(!rgx.test(Value)) return false;
   return true;
}
//endregion--------------------------------------------------------
function SetformCheck_ForFloat(FromList,Alerts)
{
   i=0;
   Flag=1;
   FromList=FromList.split('|');
   while (Flag==1)
   {
      if((i+1)<FromList.length)
      {
          if(document.getElementById(FromList[i]).value!="")
          {
              rgx=/^[0-9]+(.?)[0-9]*$/;
              if(!rgx.test(document.getElementById(FromList[i]).value)) Flag=0;
          }
          i++;
      }
      else
      {
          Flag=2;
      }
   }
   if(Flag==0)
   {
      if(Alerts!="")alert(Alerts);
      try
      {
         document.getElementById(FromList[i-1]).focus();
         document.getElementById(FromList[i-1]).value="";
      }
      catch(err)
      {
      
      }
      return false;
   }
   else
   {
      return true;
   }
}
function SetformCheck_ForFloat_WithReturn(Values)
{
   rgx=/^[0-9]+(.?)[0-9]*$/;
   if(!rgx.test(Values))//不为数值
   {
      return false;
   }
   else
   {
      return true;
   }
}
//endregion--------------------------------------------------------
//确认日期正确性-------------------------------------------------------
function SetformCheck_ForDate_Null(FromList, Alerts) {
    i = 0;
    Flag = 1;
    FromList = FromList.split('|');
    while (Flag == 1) {
        if ((i + 1) < FromList.length) {
            if (document.getElementById(FromList[i]).value.length > 0 && CheckDT(document.getElementById(FromList[i]).value) == false)  Flag = 0;
            i++;
        }
        else {
            Flag = 2;
        }
    }
    if (Flag == 0) {
        if (Alerts != "")alert(Alerts);
        document.getElementById(FromList[i - 1]).focus();
        return false;
    }
    else {
        return true;
    }
}
function SetformCheck_ForDate(FromList,Alerts)
{
   i=0;
   Flag=1;
   FromList=FromList.split('|');
   while (Flag==1)
   {
      if((i+1)<FromList.length)
      {
          if(CheckDT(document.getElementById(FromList[i]).value)==false) Flag=0;
          i++;
      }
      else
      {
          Flag=2;
      }
   }
   if(Flag==0)
   {
      if(Alerts!="")alert(Alerts);
      document.getElementById(FromList[i-1]).focus();
      return false;
   }
   else
   {
      return true;
   }
}
function SetformCheck_ForDate_WithReturn(Value)
{
   if(CheckDT(Value)==false)
   {
      return false;
   }
   else
   {
      return true;
   }
}
function CheckFDT(ObjName,Alerts)
{
    if(CheckDT(document.getElementById(ObjName).value)==false)
    {
      if(Alerts!="")alert(Alerts);
      document.getElementById(ObjName).focus();
      return false;
    }
    else
    {
      return true;
    }
}
function CheckString(Value) {

    var Str = /^\w+$/;
    if (Str.test(Value))return true;
    return false;
}   

////判断输入的日期是否正确
//function CheckDate(INDate)
//{ 
//if (INDate=="")
//    {return true;}
// subYY=INDate.substr(0,4)
// alert(subYY);
// alert(isNaN(subYY));
// if(isNaN(subYY) || subYY<=0){
//	 alert(1);
//  return true;
// }
// //转换月份
// if(INDate.indexOf('-',0)!=-1){ separate="-"}
// else{
//  if(INDate.indexOf('/',0)!=-1){separate="/"}
//  else {
//	  alert(2);
//	  return true;
//	  }
//  }
//  area=INDate.indexOf(separate,0)
//  subMM=INDate.substr(area+1,INDate.indexOf(separate,area+1)-(area+1))
//  if(isNaN(subMM) || subMM<=0){
//	  alert(3);
//  return true;
// }
//  if(subMM.length<2){subMM="0"+subMM}
// //转换日
// area=INDate.lastIndexOf(separate)
// subDD=INDate.substr(area+1,INDate.length-area-1)
// if(isNaN(subDD) || subDD<=0){
//	 alert(4);
//  return true;
// }
// if(eval(subDD)<10){subDD="0"+eval(subDD)}
// NewDate=subYY+"-"+subMM+"-"+subDD
// if(NewDate.length!=10){
//	 alert(5);
//	 return true;}
//    if(NewDate.substr(4,1)!="-"){
//		alert(6);
//		return true;}
//    if(NewDate.substr(7,1)!="-"){
//		alert(7);
//		return true;}
// var MM=NewDate.substr(5,2);
// var DD=NewDate.substr(8,2);
// if((subYY%4==0 && subYY%100!=0)||subYY%400==0){ //判断是否为闰年
//  if(parseInt(MM)==2){
//   if(DD>29){
//	   alert(8);
//	   return true;}
//  }
// }else{
//  if(parseInt(MM)==2){
//   if(DD>28){
//	   alert(9);
//	   return true;}
//  } 
// }
// var mm=new Array(1,3,5,7,8,10,12); //判断每月中的最大天数
// for(i=0;i< mm.length;i++){
//  if (parseInt(MM) == mm[i]){
//   if(parseInt(DD)>31){
//	   alert(10);
//	   return true;}
//  }else{
//   if(parseInt(DD)>30){
//	   alert(11);
//	   return true;}
//  }
// }
// if(parseInt(MM)>12){
//	 alert(12);
//	 return true;}
//   return false;}
function CheckDT(Str)     
 {     
     var r = Str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);     
     if(r==null)
     {
         return false;     
     }
     else
     {
        var d= new Date(r[1], r[3]-1, r[4]);     
        return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]); 
    }    
}
//验证时间
//YYYY-MM-DD HH:MM:SS  
function CheckDateTime(stValue)  
{   
    var checkValue = new RegExp ("^\[0-2]{1}\[0-6]{1}:\[0-5]{1}\[0-9]{1}:\[0-5]{1}\[0-9]{1}") ; 
    //
    return (!(checkValue.test(stValue)));  
}  
//endregion--------------------------------------------------------
//获取JSURL参数------------------------------------------------------
//window.location.href // var str =http://www.114study.com?subject=1001&channel=1200&module=3002; //alert(str.getQuery("subject"));
//String.prototype.getQuery = 
function Get_Para(names)
{
　　thishref=window.location.href;
    if(thishref.indexOf(names)==-1)
	{
	   return "";
	}
	else
	{
	   str=thishref.substring(thishref.indexOf(names));
	   str=str.substring(str.indexOf("=")+1);
	   if(str.indexOf("&")!=-1)str= str.substring(0,str.indexOf("&"));
	   return str;
	}
} 
function Get_LikeUrlPara(Thishref,names)
{
    if(Thishref.indexOf(names)==-1)
	{
	   return "";
	}
	else
	{
	   str=thishref.substring(thishref.indexOf(names));
	   str=str.substring(str.indexOf("=")+1);
	   if(str.indexOf("&")!=-1)str= str.substring(0,str.indexOf("&"));
	   return str;
	}
} 
function Get_LikeUrlArry(thishref,names)
{
    if(thishref.indexOf(names)==-1)
	{
	   return "";
	}
	else
	{
	   str=thishref.substring(thishref.indexOf(names));
	   if(str.indexOf("&")!=-1)str= str.substring(0,str.indexOf("&"));
	   return str;
	}
} 
//endregion--------------------------------------------------------
//验证自由格式------------------------------------------------------
//rgx=/^[1-9]+[0-9]*$/;
function Regs(Id,Alerts)
{
   Obj=document.getElementById(Id);
   if(Obj.value=="" || !rgx.test(Obj.value))
   {   
       Obj.focus();
       Obj.value="";
       return false;
   }
   else
   {
       return true;
   }
}
//endregion--------------------------------------------------------
//操作cookies------------------------------------------------------
function setCookie(name,value)
{
var Days = 30;
var exp = new Date(); 
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
return getCookie(name);
}
//读取cookies
function getCookie(name)
{
var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
if(arr=document.cookie.match(reg)) return unescape(arr[2]);
else return null;
}
//删除cookies
function delCookie(name)
{
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval=getCookie(name);
if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}

//Ajax
function createXmlhttp() {
    var request = null;
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (ex) {
            xmlhttp = null;
        }
    }
    if (!request && typeof XMLHttpRequest != "undefined") {
        xmlhttp = new XMLHttpRequest();
    }

    return xmlhttp;
}
//endregion--------------------------------------------------------
//行列隐藏运算------------------------------------------------------
function HiddenTbsCell(TbsId,HiddenField) 
{
    if(HiddenField!="")
    {
        Obj=document.getElementById(TbsId);
        for (i=0; i < Obj.rows(0).cells.length; i++)
        {
          if(HiddenField.indexOf(","+Obj.rows(0).cells(i).name+",")>-1)
          {
              for (m=0; m < Obj.rows.length; m++) Obj.rows(m).cells(i).style.display = "none"; 
          }
        }
    }
}

