/********************************
 * @File:clientCheck1.js
 * @Description: 通用客户端验证
 * @Date:2007-5-24
 * @version v1.0
 * @Copyright:wish
 * @create:ffw_cn
 ********************************/
String.prototype.trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g,"");
}

  /*函数说明：判断是否为空*/
 function isInput(value)
 {
 	if(value.trim()=="")
 	{
 		return false;
 	}
 	else
 	{
 		return true;
 	}
 }

 
 /*函数说明：判断是否是数字组合*/
function isDigital(value)
{
	var re = /^\d+$/ ;
	if(!value.match(re))
	{
		return false;
	}
	else
	{
		return true;
	}
}

/*函数说明：判断是否为正整数*/
function isPlusInt(value)
{
	var patrn=/^\+?[1-9][0-9]*$/;
	if(!patrn.test(value))
		return false;
	else
		return true;
}

/*函数说明：判断是否为正整数或0....................................................*/
function isZPlusInt(value)
{
	var patrn=/^\d+$/;
	if(!patrn.test(value))
		return false;
	else
	{
		if(value.substring(0,1)=="0" && value!=0)
		{
			return false;
		}
		return true;
	}
}

/*函数说明：判断是否是小数*/
function isDecimal(value)
{
	var arr = value.split(".");
	var z = "";//整数部分
	var p = "";//小数部分
	if(arr.length==1)
	{
		z = value;
		p = "0";
	}
	else if(arr.length==2)
	{
		z = arr[0];
		p = arr[1];
	}
	else
	{
		return false;
	}
	
	//验证整数部分
	if(!isZPlusInt(z))
	{
		return false;
	}
	//验证小数部分
	if(!isDigital(p))
	{
		return false;
	}
	//验证是不是两位小数
	if(p.length > 2)
	{
		return false;
	}
	return true;
}

/*函数说明：获取文件扩展名*/
function getFileExt(filepath)
{
	filepath = filepath.replace("\\","/");
	if(filepath.lastIndexOf("/")!=-1)
	{
		filepath = filepath.substring(filepath.lastIndexOf("/")+1,filepath.length);
		return filepath.substring(filepath.lastIndexOf(".")+1,filepath.length);
	}
	else
	{
		return "";
	}
}

/*判断文件扩展名*/
function chkFileExt(filepath)//传参：控件名称
{	
	var ext = getFileExt(filepath);
	ext = ext.toLowerCase();
	if(ext!="jpg" && ext!="gif" && ext!="bmp")//此处因项目而不同
	{
		alert("Only these file formats are valid,eg: jpg,gif,bmp");
		return false;
	}
	return true;
}

/*函数说明：判断是否为邮箱..........................................................*/
function isEmail(str)
{
	var re=/^[\w-]+(\.*[\w-]+)*@([0-9a-z]+(([0-9a-z]*)|([0-9a-z-]*[0-9a-z]))+\.)+[a-z]{2,3}$/i;
	if(str.match(re))
		return true;
	else
		return false;
}

/*验证开始时间 是否 早于结束时间**********************************************************/
function beginEndCompare(begin,end)
{
	if(begin=="")
	{
		window.alert("The Begin Date can't be empty.");
		return false;
	}
	if(end=="")
	{
		window.alert("The End Date can't be empty.");
		return false;
	}
	begin = Date.parse(begin.replace(/-/g,"/"));
	end = Date.parse(end.replace(/-/g,"/"));
	if((begin - end)<=0)
	{	
		return true;
	}
	else
	{
		window.alert("The Begin Date can't be earlier than the End Date");
		return false;
	}
}
/*验证当前时间 是否 早于开始时间******************************************************/
function currentEndCompare(begin)
{
	var current = new Date();
	current = Date.parse(current);
	begin = Date.parse(begin.replace(/-/g,"/"));
	if((begin - current)>=0)
	{
		return true;
	}
	else
	{
		window.alert("The Begin Date can't be earlier than the current Date");
		return false;
	}
	return true;
}
