function CheckEmpty(Field, FieldTitle)
{
	if (trim(Field.value) == "")
	{
		alert("请在\“" + FieldTitle + "\”一栏中输入内容!");
		Field.focus();
		return false;
	}

	return true;
}
		 //去掉字串左边的空格

function lTrim(str){
	if (str.charAt(0) == " "){
		//如果字串左边第一个字符为空格
		str = str.slice(1);//将空格从字串中去掉
		//这一句也可改成 str = str.substring(1, str.length);
		str = lTrim(str); //递归调用
	}
	return str;
}


//去掉字串右边的空格
function rTrim(str){
	var iLength;

	iLength = str.length;
	if (str.charAt(iLength - 1) == " ")	{
		//如果字串右边第一个字符为空格
		str = str.slice(0, iLength - 1);//将空格从字串中去掉
		//这一句也可改成 str = str.substring(0, iLength - 1);
		str = rTrim(str); //递归调用
	}
	return str;
}

//去掉字串两边的空格
function trim(str){
	return lTrim(rTrim(str));
}

function CheckMaxLength(Field, MaxLength, FieldTitle)
{
	if (trim(Field.value) != "")
	{
		if (Field.value.length > MaxLength)
		{
			alert("\“" + FieldTitle + "\”中输入的字符请不要超过" + MaxLength + "字符！");
			Field.focus();
			return false;
		}
	}

	return true;
}

function CheckMinLength(Field, MinLength, FieldTitle)
{
	if (trim(Field.value) != "")
	{
		if (Field.value.length < MinLength)
		{
			alert("\“" + FieldTitle + "\”中输入的字符请不要少于" + MinLength + "字符！");
			Field.focus();
			return false;
		}
	}

	return true;
}


function CheckMustLength(Field, MustLength, FieldTitle)
{
	if (trim(Field.value) != "")
	{
		if (Field.value.length != MustLength)
		{
			alert("\“" + FieldTitle + "\”一栏中输入的值必须是" + MustLength + "位！");
			Field.focus();
			return false;
		}
	}

	return true;
}

function CheckPass(field1,field2,FieldTitle)
{
if(field1.value==field2.value){
	return true;
}else{
	alert("两次输入的\""+FieldTitle+"\"不一致!");
	field1.select();
	return false;
}
}


function CheckNum(Field, FieldTitle)
{
		var i,j,strTemp;
		strTemp="0123456789";
		for (i=0;i<Field.value.length;i++)   {
			 j=strTemp.indexOf(Field.value.charAt(i));
			 if (j==-1)   {
				  //说明不是数字
				  alert("“" + FieldTitle + "”一栏中有非法字符!");
				  Field.focus();
				  return false;
			 }
		}
		//说明是数字
		return true;
}
function Compare(FieldOne, FieldOneTitle, FieldTwo, FieldTwoTitle)
{
		if (FieldOne.value < FieldTwo.value){
			alert("“" + FieldOneTitle + "”不能小于" + FieldTwoTitle);
			FieldOne.focus();
			return false;
		  }
		return true;
}

function CheckNumArea(Field, Min, Max, Unit, FieldTitle)
{
	if (trim(Field.value) != "")
	{
		if (parseInt(Field.value) > Max || parseInt(Field.value) <= Min)

		{
			alert("\“" + FieldTitle + "\”一栏中输入的值必须在" + Min + "－" + Max  + "(" + Unit + ")之间");
			Field.focus();
			return false;
		}
	}

	return true;
}

function CheckNumChar(Field, FieldTitle)
{
var i,j,strTemp;
strTemp="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_.-";
for (i=0;i<Field.value.length;i++)  {
	 j=strTemp.indexOf(Field.value.charAt(i));
	 if (j==-1)  {
		 alert("\“" + FieldTitle + "\”一栏中有非法字符！");
		 Field.focus();
		 return false;
	 }
}
return true;
}

function CheckSelect(Field, FieldTitle)
{
	for (i = 0; i < Field.length; i++)
		if (Field[i].checked)
			return true;
	
	alert("请选择\"" + FieldTitle + "\"中的值。");
	return false;
}

function CheckOption(Field, FieldTitle)
{
for (i = 1; i < Field.length; i++)
	if (Field[i].selected)
		return Field[i].value;

alert("请选择\"" + FieldTitle + "\"中的值。");
return false;
} 

function CheckEmail(Field)
{
	// there must be >= 1 character before @, so we
	// start looking at character position 1
	// (i.e. second character)
	var i = 1;
	var len = Field.value.length;
	if (len > 50)
	{
		window.alert("mail地址长度不能超过50位!");
		return false;
	}
	pos1 = Field.value.indexOf("@");
	pos2 = Field.value.indexOf(".");
	pos3 = Field.value.lastIndexOf("@");
	pos4 = Field.value.lastIndexOf(".");
	//check '@' and '.' is not first or last character
	if ((pos1 <= 0)||(pos1 == len-1)||(pos2 <= 0)||(pos2 == len-1))
	{
		window.alert("请输入有效的E-mail地址！");
		Field.focus();
		return false;
	}
	else
	{
		//check @. or .@
		if( (pos1 == pos2 - 1) || (pos1 == pos2 + 1)
		  || ( pos1 != pos3 )  //find two @
		  || ( pos4 < pos3 ) ) //. should behind the '@'
		{
			window.alert("请输入有效的E-mail地址！");
			return false;
		}
	}
	return true;
}

function CheckEmail2(text,Field)
{
	// there must be >= 1 character before @, so we
	// start looking at character position 1
	// (i.e. second character)
	var i = 1;
	var len = text.length;
	if (len > 50)
	{
		window.alert("mail地址长度不能超过50位!");
		return false;
	}
	pos1 = text.indexOf("@");
	pos2 = text.indexOf(".");
	pos3 = text.lastIndexOf("@");
	pos4 = text.lastIndexOf(".");
	//check '@' and '.' is not first or last character
	if ((pos1 <= 0)||(pos1 == len-1)||(pos2 <= 0)||(pos2 == len-1))
	{
		window.alert("请输入有效的E-mail地址！");
		Field.focus();
		return false;
	}
	else
	{
		//check @. or .@
		if( (pos1 == pos2 - 1) || (pos1 == pos2 + 1)
		  || ( pos1 != pos3 )  //find two @
		  || ( pos4 < pos3 ) ) //. should behind the '@'
		{
			window.alert("请输入有效的E-mail地址！");
			return false;
		}
	}
	return true;
}

//检查兑换实物
function checkExchProduct(){
	
	if(!CheckIsStop()) return false;
	
	if ($("#product").val() == "") {
	   alert('请选择兑换物品!');
	   $("#product").focus();
	   return false;
	}
	
	if ($("#product").val() == "100元红包|100" && $("#YpayWay").val() == "") {
	   alert('银行卡号不能为空!');
	   $("#YpayWay").focus();
	   return false;
	}
	
	if ($("#product").val() == "100元红包|100" && $("#BpayWay").val() == "") {
	   alert('开户银行不能为空!');
	   $("#BpayWay").focus();
	   return false;
	}
	
	if ($("#product").val() == "100元红包|100" && $("#NpayWay").val() == "") {
	   alert('开户姓名不能为空!');
	   $("#NpayWay").focus();
	   return false;
	}
	
	if ($("#product").val() == "100元话费卡|100" && $("#TpayWay").val() == "") {
	   alert('手机号码不能为空!');
	   $("#TpayWay").focus();
	   return false;
	}
	
	if ($("#product").val() == "100Q币|100" && $("#QpayWay").val() == "") {
	   alert('QQ号码不能为空!');
	   $("#QpayWay").focus();
	   return false;
	}
	
	if ($("#quantity").val() == "" || $("#quantity").val() == 0) {
	   alert('兑换数量不能为空!');
	   $("#quantity").focus();
	   return false;
	}
	
	if ($("#psw").val() == "" ) {
	   alert('保险箱密码不能为空!');
	   $("#psw").focus();
	   return false;
	}
	
	if (parseInt($("#xfje").val()) > parseInt($("#syxj").val())) {
	   alert('您的剩余现金不足!');
	   return false;
	}
	if(confirm("确定要兑换吗？这将从您的帐号上扣除“"+$("#xfje").val()+"”元现金。")) return true;
	
	return true;
}

//消费金额
function ChangeSpend(){
	
	var product = $("#product").val();
	var quantity = $("#quantity").val();
	var arr = product.split("|");
	
	if (quantity == "" || quantity == 0){
	    $("#xfjeHtml").html("0");
		$("#xfje").val(0);
	}else{
		$("#xfjeHtml").html(arr[1]*quantity);
		$("#xfje").val(arr[1]*quantity);
	}
}

//选择实物
function ChangeProduct(){
	
	var product = $("#product").val();
	var arr = product.split("|");
	
	switch (arr[0]){
		case "100元红包":
		  document.getElementById("RMB").style.display="";
		  document.getElementById("TEL").style.display="none";
		  document.getElementById("QB").style.display="none";
		  break;	
		case "100元话费卡":
		  document.getElementById("RMB").style.display="none";
		  document.getElementById("TEL").style.display="";
		  document.getElementById("QB").style.display="none";
		  break;	
		case "100Q币":
		  document.getElementById("RMB").style.display="none";
		  document.getElementById("TEL").style.display="none";
		  document.getElementById("QB").style.display="";
		  break;	
		
	}

}