/*
function Set_Object_Disabled(Obj)
该函数设置Obj对象是否可用

function Set_Object_Disabled_Control(objChecked,tempNo)
该函数设置Obj对象为不可用，tempNo是比较参数

function isDate(str)
该函数将判断某一变量是否为日期格式
str:被测试的日期变量

function istrueDate(inputyear,inputmonth,inputday)
检测输入日期是否合法

function is_only_space(str)
该函数将判断某一变量是否为空字符串
该函数将被函数is_item_not_null调用
str:被测试的字符串变量

function isEmail(vEMail)
该函数用于检验vEmail
vEmail: 表单中vEmail元素名称，或者vEmail变量名

function is_digital(Item, ItemCaption)
该函数用于检验Item是否整数
Item: 表单中Item元素名称

function is_number(str)
该函数用于检验str是否数字
str: 表单中Item元素名称

function isTel(checkStr)
检测输入字符是否电话

function Count_Checked_Items(objChecked)
统计单选框或复选框的选择数量

function is_item_not_null(Item, ItemCaption);
该函数将判断表单中元素值是否为空
该函数将调用is_only_space
Item:  表单元素名称
ItemCaption:  Item的说明

function check_length(Item, MinLength, MaxLength, ItemCaption)
该函数用于检验某一Item是否长度符合要求
Item: 表单中元素名称，或者变量名
MinLength:最短长度
MaxLength:最大长度
ItemCaption:仅当IsObj = ture时有效,用于出错提示

function check_text(Item, MinLength, MaxLength, ItemCaption)
该函数用于检验文本框

function userNameCheck(userName)
函数userNameCheck可检查登录名是否符合要求，若符合要求则返回1，否则返回0。

function check_postcode(PostCode)
该函数用于检验邮政编码

function check_password(Pass1, Pass2, MinLength, MaxLength)
该函数用于检验密码

function check_idcard(IDCard)
该函数用于检验身份证
*/

function Set_Object_Disabled(objChecked)
{
	if (objChecked.disabled)
	{
		objChecked.disabled=false;
		objChecked.style.backgroundColor="#FFFFFF";
	}
	else
	{
		objChecked.disabled=true;
		objChecked.style.backgroundColor="#EFEFEF";
	}
}

function Set_Object_Disabled_Control(objChecked,tempNo)
{
	if (tempNo=="0")
	{
		objChecked.disabled=false;
		objChecked.style.backgroundColor="#FFFFFF";
	}
	else
	{
		objChecked.disabled=true;
		objChecked.style.backgroundColor="#EFEFEF";
	}
}

function isDate(str)
{
	var reg = /^(\d{4})\/(\d{1,2})\/(\d{1,2})$/
	var r = str.match(reg)
	if(r==null)return false
	r[2]=r[2]-1
	var d= new Date(r[1], r[2],r[3])
	if(d.getYear()!=r[1])return false;
	if(d.getMonth()!=r[2])return false;
	if(d.getDate()!=r[3])return false;
	return true;
}

function istrueDate(inputyear,inputmonth,inputday)
{
	var nowdate=new Date();
	var result;
	var varleap_year;
	result=true;
	if ((inputyear<1850)||(inputyear>2500)||(!isDigital(inputyear)))
	{
		result=false;
	}
	if ((((parseInt(inputyear)%4)==0)&&((parseInt(inputyear)%100)!=0))||((parseInt(inputyear)%400)==0))
	{
		if ((parseInt(inputmonth)==2)&&(parseInt(inputday)>29))
		{
		      result=false;
		}
		switch(parseInt(inputmonth))
		{
			case 4:
			if (parseInt(inputday)>30)
			{
				result=false;break;
			}
			case 6:
			if (parseInt(inputday)>30)
			{
				result=false;break;
			}
			case 9:
			if (parseInt(inputday)>30)
			{
				result=false;break;
			}
			case 11:
			if (parseInt(inputday)>30)
			{
				result=false;break;
			}
		}
	}
	else
	{
		switch(parseInt(inputmonth))
		{
			case 2:
			if (parseInt(inputday)>28)
			{
				result=false;break;
			}
			case 4:
			if (parseInt(inputday)>30)
			{
				result=false;break;
			}
			case 6:
			if (parseInt(inputday)>30)
			{
				result=false;break;
			}
			case 9:
			if (parseInt(inputday)>30)
			{
				result=false;break;
			}
			case 11:
			if (parseInt(inputday)>30)
			{
				result=false;break;
			}
		}
	}
	return result;
}

function is_only_space(str)
{
	for(i=0;i<=str.length-1;i++)
	{
		if (str.charAt(i) != " ")
			return false;
	}
	return true;
}

function isEmail(vEMail)
{
	var regInvalid=/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
	var regValid=/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
	return (!regInvalid.test(vEMail)&&regValid.test(vEMail));
}

function is_digital(Item, ItemCaption)
{
	var pattern = /^([0-9])+$/;
	flag = pattern.test(Item.value);
	if(!flag)
	{
		alert(ItemCaption + "必须是数字！");
		Item.focus();
		return false;
	}
	else
		return true;
}

function is_number(str)
{
	var checkOK = "0123456789-.";
	var checkStr = str;
	var allValid = true;
	var decPoints = 0;
	var allNum = "";

	if(str==""){
		return false;
	}

	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 (ch == ".")
		{
			allNum += ".";
			decPoints++;
		}
		else
			allNum += ch;
	}
	if (!allValid)
	{
		return (false);
	}

	if (decPoints > 1)
	{
		return (false);
	}
	return (true);
}

function isTel(checkStr)
{
	var checkOK = "0123456789-/,()";
	var allValid = true;
	if (checkStr.length<1)
	allValid=false;
	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;
			}
	}
	return allValid;
}

function Count_Checked_Items(objChecked)
{
	var number_Checked=0;
	var box_Count=objChecked.length;
	if (box_Count==null)
	{
		number_Checked=(objChecked.checked==true)?1:0;
	}
	else
	{
		for (var i=0;i<(box_Count);i++)
		{
			if (objChecked[i].checked==true)
				number_Checked++;
		}
	}
	return number_Checked;
}

function is_item_not_null(Item, ItemCaption)
{
	if ((Item.value == "") || is_only_space(Item.value))
	{
		alert(ItemCaption + "不能为空！");
		Item.focus();
		return false;
	}
	return true;
}

function check_length(Item, MinLength, MaxLength, ItemCaption)
{
	if ((MinLength == 0) && (MaxLength == 0))
		return true;

	if (MaxLength < MinLength)
	{
		alert("\"check_length\"函数调用错误。");
		return false;
	}

	if ((Item.value.length < MinLength) || (Item.value.length > MaxLength))
	{
		alert(ItemCaption + "长度不符合要求。"); 
		Item.focus();
		return false;
	}
	else
		return true;
}

function check_text(Item, MinLength, MaxLength, ItemCaption)
{
	if (!is_item_not_null(Item, ItemCaption))
		return false;
	if (!check_length(Item, MinLength, MaxLength, ItemCaption))
		return false;
	return true;
}

function userNameCheck(userName)
{
	var i,j,k,strTemp1,strTemp2;
	strTemp1="0123456789_";
	strTemp2="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	if (userName.length== 0)
		return 0
	j=strTemp2.indexOf(userName.charAt(0));
	if (j==-1)
	{
		return 0;
	}

	for (i=1;i<userName.length;i++)
	{
		j=strTemp1.indexOf(userName.charAt(i));	
		k=strTemp2.indexOf(userName.charAt(i));	
		if (j==-1&&k==-1)
		{
			return 0;
		}
	}
	return 1;
}

function check_postcode(PostCode)
{
	if (!check_length(PostCode, 6, 6, "邮政编码"))
		return false;

	if (!is_digital(PostCode, "邮政编码"))
		return false;
	return true;
}

function check_password(Pass1, Pass2, MinLength, MaxLength)
{
	if (!check_text(Pass1, MinLength, MaxLength, "密码"))
		return false;

	if (!check_text(Pass2, MinLength, MaxLength, "第二次输入的密码"))
		return false;

	if (Pass1.value != Pass2.value)
	{
		alert("两次输入的密码不一致。");
		Pass1.value = "";
		Pass2.value = "";
		Pass1.focus();
		return false;
	}
	return true;
}

function check_idcard(IDCard)
{
	if (!is_item_not_null(IDCard, "身份证号码"))
		return false;

	if (!is_digital(IDCard, "身份证号码"))
		return false;

	if ((IDCard.value.length != 15) && (IDCard.value.length != 18))
	{
		alert("身份证号码长度不对。");
		IDCard.focus();
		return false;
	}
	return true;
}

