﻿



	
		var X=screen.width/2;
		var Y=screen.height/2;
		
		///对话框

		function Dialog(url,width,height,scroll)
		{
			has="yes";
			if(scroll!=null && scroll==false)
				has="no";
				
			return window.showModalDialog(url,window,"dialogWidth:"+width+"px;dialogHeight:"+height+"px;scroll:"+has+";help:no;");
		}
		
		///弹出式页面

		function Show(url,width,height)
		{
			window.open(url,null,"scrollbars=1,toolbar=0,resizable=1,height="+height+",width="+width+",status=0,left="+(X-width/2)+",top="+(Y-height/2));
		}
		
		///判断某个文本框中输入的文本是否为空

		function	CheckTextBoxValid(id,message)
		{
			obj=document.getElementById(id);
			str=obj.value;
			while(str.indexOf(' ') >= 0)
				str=str.replace(' ','');
			while(str.indexOf('\r') >= 0)
				str=str.replace('\r','');
			while(str.indexOf('\n') >= 0)
				str=str.replace('\n','');
				
			if(str == '')
			{
				alert(message);
				obj.style.backgroundColor='pink';
				obj.focus();
				return false;
			}
			obj.style.backgroundColor='';
			return true;
		}
		
		///判断某个文本框中的文本是否符合正则表达式
//		function	CheckTextBoxValid(id,re,message)
//		{
//			obj=document.getElementById(id);
//				
//			if(! re.test(obj.value))
//			{
//				alert(message);
//				obj.style.backgroundColor='pink';
//				return false;
//			}
//			
//			return true;
//		}
		
		///以某些分割符为分割的字符串绑定到下拉框

		function BindDDL(content,splitChar,ddlID)
		{
			ddl=document.getElementById(ddlID);
			ddl.options.length=0;
			arr=new Array();
			arr=content.split(splitChar);
			for(i=0;i<arr.length;i++)
			{
				id=arr[i].substring(0,arr[i].indexOf(','));
				value=arr[i].substring(arr[i].indexOf(',')+1);
				ddl.options[ddl.options.length]=new Option(value,id);
			}
		}
		
		///在下拉框中找到某个文本并选择
		function RelocateByText(ddlID,text)
		{
			ddl=document.getElementById(ddlID);
			for(i=0;i<ddl.options.length;i++)
			{
				if(ddl.options[i].innerText == text)
				{
					ddl.selectedIndex=i;
					return;
				}
			}
		}
		
		///在下拉框中找到为给定值的选项并选择
		function RelocateByValue(ddlID,value)
		{
			ddl=document.getElementById(ddlID);
			for(i=0;i<ddl.options.length;i++)
			{
				if(ddl.options[i].value == value)
				{
					ddl.selectedIndex=i;
					return;
				}
			}
		}
		//是否为日期
			function CheckIsDate(id)
			{	
			    obj=document.getElementById(id);						
				obj.value=obj.value.replace(/１/g,'1').replace(/２/g,'2').replace(/３/g,'3').replace(/４/g,'4').replace(/５/g,'5').replace(/６/g,'6').replace(/７/g,'7').replace(/８/g,'8').replace(/９/g,'9').replace(/０/g,'0');
				obj.value=obj.value.replace(/[\\,/,－,／]/g,'-').replace(/：/g,":").replace(/　/g,' ').replace(/\s{1}/g,' ');
				var regx=/^(\d{4}-\d{1,2}-\d{1,2})|(\d{4}-\d{1,2}-\d{1,2}|(\s\d{1,2}:(\d{1,2}|(\d{1,2}:\d{1,3}))))|(\d{1,2}:(\d{1,2}|(\d{1,2}:\d{1,3})))$/;
				if(obj.value=="")
				{
					obj.style.backgroundColor='';
					return true;		
				}		
				var x=regx.test(obj.value);				
				if(!x)
				{
					alert("输入正确的日期格式:例：2001-2-23 12:30 或2001-2-23 或 23:30");
					obj.style.backgroundColor='pink';
					obj.focus();
					return false;				
				}
				else
				{
					obj.style.backgroundColor='';
					return true;
				}
					
			}
		//检查一个输入值是不是Email ,如果不是把该输入控件的顏色改变
	    function IsEmail(textbox)
	    {
	        text=textbox.value;	
			if(text=="")
			{
				textbox.style.backgroundColor='';	
				return ;
			}			
			var regx=/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
		    var x=regx.test(text);				
			if(!x)
			{				
				alert('请输入正确的Email地址');
				textbox.style.backgroundColor='pink';
				textbox.focus();
				return false;
			}else
				{
					textbox.style.backgroundColor='';
					return true;
				}	
	    }
	    
	    //检查一个输入值是不是邮政编码 ,如果不是把该输入控件的顏色改变
	    function IsPostCode(Id,message)
	    {
	        var Obj=document.getElementById(Id);
			if(Obj.value.length!=6)
			{
				alert(message);
				Obj.style.backgroundColor='pink';
				return false;
			}
			else
			{
			    Obj.style.backgroundColor='';
			}
						
			return IsNumber(Id,"int",message);		    	
	    }
	    
	    
		function CheckNumeric2(textbox,valueScope_min,valueScope_max) 
		{
			textbox.value=textbox.value.replace(/１/g,'1').replace(/２/g,'2').replace(/３/g,'3').replace(/４/g,'4').replace(/５/g,'5').replace(/６/g,'6').replace(/７/g,'7').replace(/８/g,'8').replace(/９/g,'9').replace(/０/g,'0');
			text=textbox.value;	
			if(text=="")
			{
				textbox.style.backgroundColor='';	
				return true;
			}
			if(isNaN(text.replace(',','')))
			{				
				alert('请输入数字');
				textbox.style.backgroundColor='pink';
				textbox.focus();
				return false;
			}
			else if ( valueScope_min !=null || valueScope_max !=null )
			{				
				if ( (valueScope_min==null ||(valueScope_min !=null && eval(text>=valueScope_min) ) ) && (valueScope_max ==null ||( valueScope_max !=null && eval(text<=valueScope_max) ) )    )
				{
						textbox.style.backgroundColor='';
						return true;
				}
				else
				{
					var xd="",xm="";
					if(valueScope_min !=null )
						xd="大于等于 "+valueScope_min;
					if(valueScope_max !=null )
						xm="小于等于 "+valueScope_max;
					if(xd+xm !="")
						alert("请输入："+xd+xm);
					textbox.style.backgroundColor='pink';
					textbox.focus();
					return false;
				}
			}else
				{
						textbox.style.backgroundColor='';
						return true;
				}	
			
		}
		

var pointAfterLen=2;//精确度
function ToDouble(val)
{
	if(val=="" || val==null || val=="&nbsp;")
		return 0.00
	else
		return Math.round(parseFloat(val) * Math.pow(10,pointAfterLen))/Math.pow(10,pointAfterLen);
	
}
function string4(val)
{
	var x=String(val).split(".");
	if(x.length==2 )
	{
		if(eval(String(x[1]).length<pointAfterLen))
		{
			for(var i=0;i<eval(pointAfterLen-String(x[1].length));i++)
			{
				val+="0";
			}
		}
	}
	else
	if(x.length==1)
	{		
		val+=".0";		
		for(var i=0;i<eval(pointAfterLen-String(x).length-1);i++)
		{
			val+="0";
		}
	}
	return val;
}
		function isnumber(id,message)
		{
			if(id.vlaue !="")
			{
				if(isNaN(id.value))
				{
					alert(message);
					id.style.backgroundColor="red";
				}
				else
				{
					id.style.backgroundColor="";
				}
			}
			else
				id.style.backgroundColor="";
		}
		
		
		//以下部分用于页面有选择器（radio，checkbox）的情况
		var CheckTime=0;
		var SelectedValue=null;//这个字段只适用于radio
		
		//当用户在radio或者checkbox上点击后
		//btn：radio或者checkbox
		function OnCheck(btn)
		{
			if(btn.checked)
			{
				CheckTime++;
				SelectedValue=btn.value;
			}
			else
				CheckTime--;
		}
		
		//判断用户是否已经选择了radio或者checkbox
		//message：当用户没有选择时弹出的提示信息
		function CheckSelect(message)
		{
			if(CheckTime < 1)
			{
				alert(message);
				return false;
			}
			
			return true;
		}
		
		
		//验证某个控件输入的文本是否是数字
		//id：控件ID
		//type：数据类型

		//message：当数据验证失败时的提示信息
		function IsNumber(id,type,message)
		{
			obj=document.getElementById(id);
			val=ReplaceWhite(id);
			
			if(val == "")
			{
				obj.style.backgroundColor="";
				return true;
			}
			
			var reg=null;
			if(type == "int")
				reg=/^\d+$/;
			else if(type == "decimal")
				reg=/^\d+(.\d+)?$/;
				
			if(! reg.test(val))
			{
				alert(message);
				obj.focus();
				obj.style.backgroundColor="pink";
				return false;
			}
			else
				obj.style.backgroundColor="";
			
			return true;
		}
		
		//获取文本框中文本去除空白，\r，\n后的验证文本
		//id：文本框ID
		function ReplaceWhite(id)
		{
			string=document.getElementById(id).value;
			while(string.indexOf(" ") >= 0)
				string=string.replace(" ","");			
			while(string.indexOf("\r") >= 0)
				string=string.replace("\r","");			
			while(string.indexOf("\n") >= 0)
				string=string.replace("\n","");
				
			return string; 
		}
		
		//去除空白，\r，\n后的验证文本
		//string：文本

		function ReplaceWhiteString(string)
		{
			while(string.indexOf(" ") >= 0)
				string=string.replace(" ","");			
			while(string.indexOf("\r") >= 0)
				string=string.replace("\r","");			
			while(string.indexOf("\n") >= 0)
				string=string.replace("\n","");
				
			return string; 
		}
		
		//设置table tr的CSS
		//tabID：table的ID
		function SetFrameCSS(tabID)
		{	
			SetFrameCSSFrom(tabID,0);
		}
		
		//设置table tr的CSS
		//tabID：table的ID
		//index：行索引
		function SetFrameCSSFrom(tabID,index)
		{		
			tb=document.getElementById(tabID);
			var odd=0;
			for(i=index;i<tb.rows.length;i++)
			{
				if(tb.rows[i].style.display == "none")
					continue;
				if(odd%2 == 0)
					tb.rows[i].className="box01";
				else
					tb.rows[i].className="box02";
				
				odd++;
			}
		}
		
		//把字符串的前后空格去除

		//string:字符串

		function Trim(string)
		{
			if(string.length == 0)
				return string;
				
			return string.replace(/(^\s*)|(\s*$)/,'');
		}
		
		//把文本框的前后空格去除

		//id:文本框ID
		function TrimTextBox(id)
		{
			return Trim(document.getElementById(id).value);
		}
		
			
		// ---------- 选择框控制 -------------------------------------------
		
		function checkAll(chkName, flgChecked) //全选，全不选


		{
			if(document.all(chkName)){
				var max = document.all(chkName).length;
				if(max!=null)
				{
					for (var idx = 0; idx < max; idx++)					
						document.all(chkName)[idx].checked=flgChecked;
				}				
				else				
					document.all(chkName).checked=document.all(chkName).checked;
			}
		}
		
		function revCheck(chkName)  //反选


		{
			if(document.all(chkName)){
				var max = document.all(chkName).length;
				if(max!=null)
				{
					for (var idx = 0; idx < max; idx++) 
						document.all(chkName)[idx].checked=!document.all(chkName)[idx].checked;
				}
				else
					document.all(chkName).checked=!document.all(chkName).checked;
			}
		}
		function getCheck(chkName,onlygetfirstvalue)  //取得所选单复选框值
		{
		    var xv="";
			if(document.all(chkName))
			{
			    var obj=document.all(chkName);
				var max = obj.length;
				if(max!=null)
				{
				
					for (var idx = 0; idx < max; idx++) 
					{
						 if(obj[idx].checked)
						 {
						    if(onlygetfirstvalue!=null && onlygetfirstvalue==true )
						        return obj[idx].value;
						    else
						    {
						        if(xv!="") xv+=",";
					            xv+=obj[idx].value;					        
					        }
					      }
					}
				}
				else
				    {
				        if(obj.checked)
					        xv=obj.value;
					}
			}
			return xv;
		}
		function getdropdownlistValue(drpName)
		{
		    if(document.all(drpName))
			{
			    var obj=document.all(drpName);	
				return obj.options[obj.selectedIndex].value;				
			}
		}
		
		function showCheckAllDiv(tdName,chkName) //《tdName：显示内容的网格ID 》《chkName：选择框ID》


		{
			if(document.all(chkName))
				if(document.all(chkName).length > 0)
					document.all(tdName).innerHTML = "<DIV id='checkAllDiv' style='FONT-SIZE: 12px;WIDTH: 120px; FONT-FAMILY: 宋体; HEIGHT: 28px' ms_positioning='FlowLayout'>&nbsp;全选<INPUT id='input_All' onclick=\"document.all('input_Rev').checked=false;checkAll('"+chkName+"',this.checked);\" type='checkbox'>&nbsp;反选<INPUT id='input_Rev' onclick=\"document.all('input_All').checked=false;revCheck('"+chkName+"');\" type='checkbox'></DIV>";
		}
		// -------------------------------------------------------
		
		var WorkFlow=
		{ 
			mustItemcheck:function (mustItem)
			{
				if(mustItem !="")
				{
					var items=mustItem.split(",");						
					
					for(var i=0;i<items.length;i+=2)
					{		
						var obj= document.all(items[i]);
						if(obj !=null)
						{
							obj.focus();	
							var filed=items[i+1];
						
							switch(obj.tagName.toLowerCase())
							{
								case "select":	
									if(obj.options[obj.selectedIndex].value=="0" && obj.options[obj.selectedIndex].text.indexOf('请选')>0 )
										filed='请将*项的 '+filed +' 选取正确项后,再试'
									else
										filed="";	
									break;
								case "span":									
									if(obj.innerText=="")
										filed='请将*项的 '+filed +' 填写完整后,再试'
									else
										filed="";
									break;
								case "textarea":
								case "text":
								case "input":																
									if( (obj.style.width=="0" && (obj.value =="" || obj.value =="0") ) || obj.value =="" )									
									{										 
										if(filed==null)
											filed='请将所有*项添完整后再试';
										else											
											filed='请将*项的 '+filed +' 填写完整后再试'											
									}
									else
										filed="";
									break;
							}
							if(filed!="")
								{								
									alert(filed);										
									return false;
								}
						}//(obj !=null)
					}
				}
				return true;
			}
		}
		
//验证文本框是否包含中文
//Id为控件Id
function IsChineseName(Id)
{
    try
    {
        if(document.getElementById(Id).value.match("^[\u4e00-\u9fa5]+$"))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    catch(ex)
    {
        return false;
    }    
}



//判断两个日期相差的天数
//日期1
//日期2
//返回相差天数
function DateDiff(sDate1,sDate2)
{
    try
    {
        var aDate,oDate1,oDate2,iDays;
        aDate=sDate1.split("-");
        oDate1=new Date(aDate[1]+'-'+aDate[2]+'-'+aDate[0]);//转换为12-18-2002格式
        aDate=sDate2.split("-");
        oDate2=new Date(aDate[1]+'-'+aDate[2]+'-'+aDate[0]);
        iDays=parseInt((oDate1-oDate2)/1000/60/60/24);
        //把相差的毫秒数转换为天数
        return iDays;
    }
    catch(ex)
    {
        return -1;
    } 
}

//判断两个时间大小
//时间1 格式（yyyy-MM-dd mm:ss)
//时间2 格式（yyyy-MM-dd mm:ss)
//返回相差秒数
function DateTimeDiff(DateTime1,DateTime2)
{
	try
	{
		var ADateTime1,Date1,Time1,ADateTime2,Date2,Time2;
		
		ADateTime1=DateTime1.split(" ");
		Date1=ADateTime1[0];
		Time1=ADateTime1[1];

		ADateTime2=DateTime2.split(" ");
		Date2=ADateTime2[0];
		Time2=ADateTime2[1];
		
		var ADate1,oDateTime1,ADate2,oDateTime2;
		ADate1=Date1.split("-");
		oDateTime1 = new Date(ADate1[1]+'-'+ADate1[2]+'-'+ADate1[0]+" "+ Time1);
		ADate2=Date2.split("-");
		oDateTime2 = new Date(ADate2[1]+'-'+ADate2[2]+'-'+ADate2[0]+" "+ Time2);
		var iTimes;
		
		//alert((oDateTime1-oDateTime2)/1000/60/60);
		iTimes=parseInt((oDateTime1-oDateTime2)/1000/60);  //到分
		return iTimes;
	}
	catch(ex)
	{
		return 0;
	}
}

function setParentFrameHeight(frameid,height,width)
{
  	if(	window.parent.document.getElementById(frameid)!=null)
	{	  
	    var stop=false;
	    if(height==null)
	        height=50;
	      if(width==null)
	        width=50;  
	 
	    while( !stop)
	    {	
		    if(document.body.readyState=="complete")
		    {
				   window.parent.document.getElementById(frameid).style.height=document.body.scrollHeight+height;
				   window.parent.document.getElementById(frameid).style.width=document.body.scrollWidth;
				    stop=true;	break;	
    				
		    }	    		
	    }
	    if( window.parent.document.getElementById(frameid).style.width<=0)
	        window.parent.document.getElementById(frameid).style.width=400;
	    if( window.parent.document.getElementById(frameid).style.height<=0)
	        window.parent.document.getElementById(frameid).style.height=400;
    }
        
    
    
    
}


function getvarvalue(ArgName)
{
    try{
        var M_url=document.URLUnencoded;
        var va=M_url.substring(M_url.indexOf("?")+1,M_url.length);
        var vars=va.split("&");
        for(var n=0;n<vars.length;n++)
        {  
	        for(var x=0;x<arguments.length;x++)
	        {
		        var dc=vars[n].split("=");
		        if(ArgName==arguments[x])		
			        return dc[1]; 
	        } 
        }
    }catch(ex){}
}

//
//显示错误控件
//
function ShowErrorTextbox(id)
{
    textbox=document.getElementById(id);
    if(textbox.style.backgroundColor!="")
        textbox.style.backgroundColor='';
    else    
        textbox.style.backgroundColor='pink';
}
//校验手机号码
function isMobile(s,showmsg)
{ 
    if(s=="")
        return false;
  var x= /(^(13|15)[0-9]{9}\s*$)/.test(s);
  if(!x)
  { if(showmsg==1)
    alert('请输入正确的手机号码');
    return false;
  }
  else
  {
    return true;
  }
}
//校验普通电话、传真号码："0”开头，除数字外，可含有“-”
function isTel(s,showmsg)
{
//var patrn=/^\d{3,4}-\d{6,8}$/;
var patrn=/^(\d{3,4}-\d{6,8})|(\d{3,4}-\d{6,8}-\d{1,5})$/;
if (!patrn.test(s))
{
    if(showmsg==1)
    alert("请输入正确的电话号码,如020-8888888或020-8888888-分机号码");
    return false; 
}
return true
}

//身份证检验
function isIdCard2(obj) 
{       
        var num=obj.value;
        var len = num.length, re;
        var a;
        var date;	
	    var msg="";
	    if(num!="")
	    {
            if ( len != 15 && len != 18 )
            {       
			    msg="身份证输入的位数不对";    		
            }
            else if (len == 15)
            {
			    re = new RegExp(/^(\d{6})()?(\d{2})(\d{2})(\d{2})(\d{3})$/);
			    regExp = num.match(re);		
			    if( isNaN(num) )
			    {			       
				    msg= "15位身份证请输入数字";
				 }
			    else if( !validateDate2(num) )
			    {
				    msg= "15位身份证中出生日期不正确";
			    }
		    }
		    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" ) )
				     msg=  "18位身份证中前17位请输入数字，最后一位请输入数字或大写X";
			    else if( !validateDate2(num) )
			    {
				     msg=  "18位身份证中出生日期不正确";
			    }			  
		    }
		   
		} 
		
		 if(msg!="")
		 {
		    alert(msg);
		     x=false;
		    obj.style.backgroundColor='pink';
		    obj.focus();		    
		 }
		 else
		 {
		    x=true;
		    obj.style.backgroundColor='';
		 }
		return x;
}
function validateDate2(num)
{
 if (  num.length == 15  )
        {
			if ( parseInt(num.substring(8,10),10) > 12
			||   parseInt(num.substring(10,12),10) > 31
			 )     
				return false;
			else
				return true;
		}				
        else if ( num.length == 18  )
        {
			if ( parseInt(num.substring(6,10),10) > 2500
			||   parseInt(num.substring(6,10),10) < 1900
			||   parseInt(num.substring(10,12),10) > 12
			||   parseInt(num.substring(12,14),10) > 31
			 )       
				return false;
			else
				return true;
        }  
  return false;
}
