/**
 *  手机充值提交信息验证
*/

//验证手机号码
function isMobile(mobile){
	var validator = /^(\s)*((1[35]\d{9})|((0\d{2,3}\-){1}[1-9]{1}\d{6,7}(\-\d{1,4})?))(\s)*$/;
	return validator.exec(mobile.trim());
}

//判断是否为数字
function isNum(nm){
	var validator = /\d/;
	return validator.exec(nm);
}

//页面验没有通过,返回
function noPass(vForm,obj,str){
	alert(str);
	obj.focus();
	vForm.submitButton.disabled = false;
	//$E('submitButton').disabled = false;
	return;
}

//判断一致性
function sameMobile(str1,str2){
	return str1 == str2 && str1 != '' && str2 != '';
}

//检查Email是否合法
function isEmail(s){
    if (s.length<7||s.length > 50){
            return false;
    }
     var regu = "^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2}|net|NET|com|COM|gov|GOV|mil|MIL|org|ORG|edu|EDU|int|INT)$"
     var re = new RegExp(regu);
     if (s.search(re) != -1) {
           return true;
     } else {
           return false;
     }
}

//页面验证手机
function checkMobile(mobile){
	if('' != mobile && !isMobile(mobile)){
		$E('mobileMsg').style.display = '';
	}else{
		$E('mobileMsg').style.display = 'none';
	}
}

//验证手机是否一致
function doubleCheck(vForm){
	if('' !=vForm.remob.value && !sameMobile(vForm.mob.value,vForm.remob.value)){
		$E('doubleCheck').style.display = '';
	}else{
		$E('doubleCheck').style.display = 'none';
	}
}

//个人直充输入充值金额验证
function validateAmount(amount){
	
	return amount % 50 == 0 && amount != 0 && amount <= 500;
}

//提交时验证form元素
function checkSubmit(vForm){

	//vForm.submitButton.disabled = true;
	//$E('submitButton').disabled = true;
	
	if($E('validRecord') != null){
		if(parseInt(vForm.validRecord.value)==0){
			alert('核对正确笔数为0!');
			return false;
		}
	}
	
	if($E('mob') != null){
		var mob = vForm.mob.value;
		if('' == mob){
			return noPass(vForm,vForm.mob,'手机不能为空!');
		}
		if(!isMobile(mob)){
			return noPass(vForm,vForm.mob,'请输入正确的手机号码!');
		}
	}
	
	if($E('remob') != null){
		if(vForm.mob.value != vForm.remob.value || vForm.remob.value == ''){
			return noPass(vForm,vForm.remob,'手机必须一致!');
		}
	}
	
	if($E('mail') != null && vForm.mail.value != "请输入有效E-mail"){
		if(!isEmail(vForm.mail.value)){
			return noPass(vForm,vForm.mail,'请输入正确的电子邮件地址!');
		}
	}
	
	if($E('memberAcctcode') != null){
		if('0' == vForm.memberAcctcode.value){
			return noPass(vForm,vForm.memberAcctcode,'请选择支付账户!');
		}
	}

	if($E('szx_rand') != null && $E('szx_rand').style.display != 'none'){
		if(''== vForm.rand.value){
			return noPass(vForm,vForm.rand,'验证码不能为空!');
		}
	}
	
	if($E('szx_pwd') != null && $E('szx_pwd').style.display != 'none'){
		if(''== vForm.password.value){
			return noPass(vForm,vForm.password,'请输入密码!');
		}
	}
	
	if($E('amount') != null){
		if(vForm.amount.type == 'text'){
			if(!isNum(vForm.amount.value) || !validateAmount(vForm.amount.value)){
				return noPass(vForm,vForm.amount,'请输入正确的金额!');
			}
		}
	}
	
	if($E('file') != null){
		if('' == $E('file').value){
			return noPass(vForm,vForm.file,'请选择要上传的文件!');
		}
	}
	vForm.submit();
}

//动态更改账户余额显示
function changeAcct(value){
	if('0' == value){
		showOrHidden(false,false,false);
	}else {
		for(i=0;i<arry.length-2;i++){
			if(value == arry[3*i]){
				if(arry[i*3+2] == '1'){
					showOrHidden(true,false,true);
				}else{
					showOrHidden(true,true,false);
				}
				$E('balance').innerText = arry[i*3+1]
			}
		}
	}
}

//根据参数判断页面元素显示或隐藏
function showOrHidden(b_acctBalance,b_rand,b_pwd){

	if(b_acctBalance){
		$E('acctBalance').style.display = '';
	}else{
		$E('acctBalance').style.display = 'none';
	}
	
	if(b_rand){
		$E('szx_rand').style.display = '';
	}else{
		$E('szx_rand').style.display = 'none';
	}
	
	if(b_pwd){
		$E('szx_pwd').style.display = '';
	}else{
		$E('szx_pwd').style.display = 'none';
	}
}

function setPayAmount(discount,value,obj){
$E(obj).innerText = discount*10000*value/10000;
}

//去掉字符串首尾空格
String.prototype.trim = function() 
{ 
	return this.replace(/(^\s*)|(\s*$)/g, ""); 
}
