function selectdate(select1,select2,n,str){
	
	var arr =showModalDialog('../js/Calendar.htm', '', 'dialogWidth:148px; dialogHeight:228px; status:0;help: No;');
	if(arr!=null) {
		
		if((n==2&&new Date(arr.replace(/\-/g, '/'))>=new Date(select2.value.replace(/\-/g, '/')))||(n==1&&new Date(arr.replace(/\-/g, '/'))<=new Date(select2.value.replace(/\-/g, '/')))){
			select1.value=arr;
		}else{
			if(str)
			alert(str);
		}
	}
}
function ClientValidate_radio(arguments,str)
{
for(i=0;i<arguments.length;i++)
{
if(arguments[i].checked)
return true
}
if(str)
alert("请选择"+str+"。");
return false
}

function ClientValidate_CheckChinese(arguments,str) {
var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@. _-,";
  var checkStr = arguments.value;
	checkStr = checkStr.replace(/^\s*/g,"");
	checkStr = checkStr.replace(/\s*$/g,"");
  var allValid = true;

  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    if(str)
	alert(str);
    arguments.value="";
	if(arguments.style.display=='')
	arguments.focus();
    return false;
  }
return true;
}

function ClientValidate_nonull(arguments,str,n1,n2){
var checkStr = arguments.value;
checkStr = checkStr.replace(/^\s*/g,"");
checkStr = checkStr.replace(/\s*$/g,"");
	if(!n1){
	var n1=1;
	}
	if((n2&&checkStr.length>=n1&&checkStr.length<=n2)||(!n2&&checkStr.length>=n1)){
	return true;
	}else{
		if(str)alert(str);
		if(arguments.style.display=='')
		arguments.focus();
		return false;
	
	}
}
function ClientValidate_email(i,arguments,str){
var checkStr = arguments.value;
checkStr = checkStr.replace(/^\s*/g,"");
checkStr = checkStr.replace(/\s*$/g,"");
var isgo=true;
if(i==0){
if(checkStr=="")
isgo=false;
}
if(isgo){
		var filter=/^.+@.+\..{2,3}$/;
		if (filter.test(checkStr)){
		return true;
		}else{
		if(str)alert(str);
		//arguments.IsValid = false;
		if(arguments.style.display=='')
		arguments.focus();
		return false;
		}
}else{
	return true;
}
}
function ClientValidate_select(arguments,str){
	if(arguments.selectedIndex==-1){
	if(str)alert(str);
	if(arguments.style.display=='')
	arguments.focus();
	return false;
	}else{
	return true;
	}
}
function h(str){
var ret=""
for(i=0;i<str.length;i++)
if(str.charCodeAt(0)>0xff00)
ret+=String.fromCharCode(str.charCodeAt(i)-0xfee0)
else
ret+=str.charAt(i)
return ret;
}
function ClientValidate_number(i,arguments,n,str){

var  checkStr= h(arguments.value);
checkStr = checkStr.replace(/^\s*/g,"");
checkStr = checkStr.replace(/\s*$/g,"");

if(i==0){
if(checkStr=="")
return true;
}
var isgo=true;


if(checkStr.length < 1) //空字符串
isgo=false;
if(n>=1&&isNaN(checkStr)) //不是数值
isgo=false;
if(n>=2&&parseInt(checkStr) < 0) //不是正数
isgo=false;
if(n>=3&&parseFloat(checkStr) > parseInt(checkStr)) //不是整数 
isgo=false;
if(n>=4&&parseInt(checkStr) < 1) //大于等于1
isgo=false;



if(!isgo){
		
		if(str)alert(str);
		//arguments.IsValid = false;
		if(arguments.style.display=='')
		arguments.focus();
		return false;
		
}else{
	return true;
}
}
function ClientValidate_date(i,arguments,str){
var checkStr = arguments.value;
checkStr = checkStr.replace(/^\s*/g,"");
checkStr = checkStr.replace(/\s*$/g,"");
var isgo=true;
if(i==0){
if(checkStr=="")
isgo=false;
}



if(isgo){


		if (fnCheckDate(checkStr,0)){
		return true;
		}else{
		
		if(str)alert(str);
		//arguments.IsValid = false;
		if(arguments.style.display=='')
		arguments.focus();
		return false;
		}
}else{
	return true;
}
}
function ChkStr(str)
		{
			str=replace(str,";","；");
			str=replace(str,"'","＇");
			str=replace(str,"#","＃");
			str=replace(str,"<","＜");
			str=replace(str,">","＞");
			str = str.replace(/^\s*/g,"");
			str = str.replace(/\s*$/g,"");
			str=replace(str,"\r\n"," ");
			
			return str;
			
		}
function replace(strSource,strFrom,strTo){
    var pattern,re;
	var s = strSource;
	pattern = new RegExp(strFrom,"ig");
	re = s.replace(pattern,strTo);

      return re;
    }    
function ChkAll(n){
	
	for(i=0;i<document.forms[n].elements.length;i++){

	if(document.forms[n].elements[i].type=="text"||document.forms[n].elements[i].type=="textarea")
	document.forms[n].elements[i].value=ChkStr(document.forms[n].elements[i].value);
	}
	
	
}


function fnIsIntNumCheck(strNum,i)
{
var strCheckNum = strNum + "";
if(strCheckNum.length < 1) //空字符串
return false;
else if(isNaN(strCheckNum)) //不是数值
return false;
else if(parseInt(strCheckNum) < 0) //不是正数
return false; 
else if(parseFloat(strCheckNum) > parseInt(strCheckNum)) //不是整数 
return false;

return true;
}


//**********************************************************************************************************
//功能：日期检查函数，支持3种年、月、日之间的分隔符 "-"、"."和"/"可以选择年、月、日是否应该完整。
// 正确的日期格式为：2001-2-13 2001 2001-2 2001.2.13 2001.2 2001/2/3，日期范围为 1-1-1 到 9999-12-31 
// 同时，对当前年当前月的天数也做了判断，如：2001-2-29 2001-4-31 都是非法的日期
//参数：strDate ---- 需要判断的日期字符串
// intFlag: 1 ---- 可以没有日 2 ---- 可以没有日和月 0 ---- 年月日必须齐全
//返回值：true ---- 日期合法 false ---- 日期不合法
function fnCheckDate(strDate,intFlag)
{
var strCheckDate = strDate + ""; //进一步确认哪来判断的肯定是一串字符串

//if(strCheckDate == "") //空字符串,不是合法的日期字符串，返回false
//{
//return false;
//} 

//判断传进来的数据是那种格式写成日期
var intIndex = -1; //利用正则表达式，查找字符串中是否包含某个字符，没找到为-1,否则为 （0 - String.length - 1）
var arrDate; //分别存储年月日
var regExpInfo = /\./; //正则表达式，匹配第一个出现 "."的位置

//在这里，我之所以不使用replace函数把所有的"."和"/"换成"-",然后分别存储年月日，是因为用户有可能输入 2001/3-2,就判断不出它是不合法日期了
intIndex = strCheckDate.search(regExpInfo); //查找是否含有 "."
if(intIndex == - 1) //不包含 
{
regExpInfo = /-/;
intIndex = strCheckDate.search(regExpInfo);

if(intIndex == -1)
{
regExpInfo = /\//; //查找是否含有 "/"
intIndex = strCheckDate.search(regExpInfo); 

if(intIndex == -1)
{
arrDate = new Array(strCheckDate); //只包含年
}
else
{
arrDate = strCheckDate.split("/"); //2001/3/7 型
}
}
else
{
arrDate = strCheckDate.split("-"); //2001-3-7 型
}
}
else
{
arrDate = strCheckDate.split("."); //2001.3.7 型
}

if(arrDate.length > 3) //如果分离出来的项超过3，除了年月日还有其它的，不合法日期，返回false
{
return false;
}
else if(arrDate.length > 0) 
{
//判断年是否合法
if(fnIsIntNum(arrDate[0])) //是正整数
{
if(parseInt(arrDate[0]) < 1 || parseInt(arrDate[0]) > 9999) //年范围为1 - 9999
{
return false;
} 
}
else
{
return false; //年不是正整数，错误
}

//判断月是否合法
if(arrDate.length > 1)
{
if(fnIsIntNum(arrDate[1])) //是正整数
{
if(parseInt(arrDate[1]) < 1 || parseInt(arrDate[1]) > 12)
{
return false;
} 
}
else
{
return false;
}
}
else //没有月
{
if(intFlag != 2) //必须得有月
{
return false;
}
}

//判断日是否合法
if(arrDate.length > 2)
{
if(fnIsIntNum(arrDate[2])) //是正整数
{
var intDayCount = fnComputerDay(parseInt(arrDate[0]),parseInt(arrDate[1]));
if(intDayCount < parseInt(arrDate[2]))
{
return false;
} 
}
else
{
return false;
}
}
else
{
if(intFlag == 0) //必须得有日
{
return false;
}
}
}
return true;
}

//**********************************************************************************************************
//判断一个数是否为正整数
//参数：strNum ---- 需要判断的字符串
//返回值：true ---- 整数 false ---- 非整数
function fnIsIntNum(strNum)
{
var strCheckNum = strNum + "";
if(strCheckNum.length < 1) //空字符串
return false;
else if(isNaN(strCheckNum)) //不是数值
return false;
else if(parseInt(strCheckNum) < 1) //不是正数
return false; 
else if(parseFloat(strCheckNum) > parseInt(strCheckNum)) //不是整数 
return false;

return true;
}

//**********************************************************************************************************
//功能：判断intYear年intMonth月的天数
//返回值：intYear年intMonth月的天数
function fnComputerDay(intYear,intMonth)
{
var dtmDate = new Date(intYear,intMonth,-1);
var intDay = dtmDate.getDate() + 1;

return intDay; 
}



function DateDemo(datetime,n){
   var  s = "";           // 声明变量。
   if(!n)n=0;
   var d=new Date(datetime.getTime()+60000*60*24*n);
   s += d.getYear() + "-";            // 获取月份。
   s += (d.getMonth() + 1) + "-";                   // 获取日。
   s += d.getDate();                         // 获取年份。
   return(s);                                // 返回日期。
}
