// JavaScript Document
//商品评论表单验证JS
function checkProReviewData(theForm){
	if (Trim(theForm.i_name.value).length == 0){
		alert("标题不能为空!");
		theForm.i_name.focus();
		return false;
	}
	if (Trim(theForm.i_customer.value).length == 0){
		alert("姓名不能为空!");
		theForm.i_customer.focus();
		return false;
	}
	if (Trim(theForm.i_content.value).length == 0){
		alert("内容不能为空!");
		theForm.i_content.focus();
		return false;
	}
	if (Trim(theForm.i_addDate1.value).length == 0){
		alert("评论日期不能为空!");
		theForm.i_addDate1.focus();
		return false;
	}

	return true;
}

//在线问答表单验证JS
function checkGuestbookData(theForm){
	if (Trim(theForm.i_memberId.value).length == 0){
		alert("您还没有登录,不能提问!");
		//location.replace("<?=$rootDirSys?>/login.php?forward=<?=rawurlencode($_SERVER["REQUEST_URI"])?>");
		return false;
	}
	if (Trim(theForm.i_name1.value).length == 0){
		alert("姓名不能为空!");
		theForm.i_name1.focus();
		return false;
	}
	if (Trim(theForm.i_name.value).length == 0){
		alert("标题不能为空!");
		theForm.i_name.focus();
		return false;
	}
	if (Trim(theForm.i_content.value).length == 0){
		alert("留言不能为空!");
		theForm.i_content.focus();
		return false;
	}
	if (Trim(theForm.i_addDate.value).length == 0){
		alert("留言日期不能为空!");
		theForm.i_addDate.focus();
		return false;
	}
	
	return true;
}

//无提交判断文本框是否整数,需先导入 checkInt() 函数
function checkChangeInt(theText){
	//判断数据合法
	if(checkInt(theText.value) == 0 || theText.value <= 0){
		alert("Error\n\nPlease input the correct numeral!");
		theText.focus();
		return false;
	}
	return true;
}

//站内搜索跳转JS
function goSearch(theForm){
	if (Trim(theForm.keywords.value).length == 0){
		alert("关键词不能为空!");
		theForm.keywords.focus();
		return false;
	}
	
	theForm.method	= "get";
	theForm.action	= theForm.targetFile.value;
	return true;
}

//会员注册表单验证JS
function checkRegData(theForm){
	if (Trim(theForm.i_account.value).length == 0){
		alert("用户名不能为空");
		theForm.i_account.focus();
		return false;
	}
	if (false == checkEmail(Trim(theForm.i_account.value))){
		alert("用户名必须是Email账号");
		theForm.i_account.focus();
		return false;
	}
	if (6 > Trim(theForm.i_accountPwd.value).length){
		alert("密码不能小于6位");
		theForm.i_accountPwd.focus();
		return false;
	}
	if (false == checkPassword(theForm.i_accountPwd.value)){
		alert("密码中包括非法字符");
		theForm.i_accountPwd.focus();
		return false;
	}
	if (6 > theForm.c_accountPwd.value.length){
		alert("密码不能小于6位");
		theForm.c_accountPwd.focus();
		return false;
	}
	if (false == checkPassword(theForm.c_accountPwd.value)){
		alert("密码中包括非法字符");
		theForm.c_accountPwd.focus();
		return false;
	}
	if (theForm.c_accountPwd.value != theForm.i_accountPwd.value){
		alert("两次输入的密码不相同");
		theForm.i_accountPwd.focus();
		return false;
	}
	return true;
}

//验证修改密码
function checkPasswordData(theForm){
	if (Trim(theForm.o_accountPwd.value).length == 0){
		alert("旧密码不能为空!");
		theForm.o_accountPwd.focus();
		return false;
	}
	if (6 > Trim(theForm.i_accountPwd.value).length){
		alert("新密码不能小于6位");
		theForm.i_accountPwd.focus();
		return false;
	}
	if (false == checkPassword(theForm.i_accountPwd.value)){
		alert("新密码中包括非法字符");
		theForm.i_accountPwd.focus();
		return false;
	}
	if (6 > theForm.c_accountPwd.value.length){
		alert("新密码确认不能小于6位");
		theForm.c_accountPwd.focus();
		return false;
	}
	if (false == checkPassword(theForm.c_accountPwd.value)){
		alert("新密码确认中包括非法字符");
		theForm.c_accountPwd.focus();
		return false;
	}
	if (theForm.c_accountPwd.value != theForm.i_accountPwd.value){
		alert("两次输入的密码不相同");
		theForm.i_accountPwd.focus();
		return false;
	}
	
	return true;
}

//验证登录框
function checkLoginData(theForm){
	if (Trim(theForm.login_account.value).length == 0){
		alert("会员账号不能为空!");
		theForm.login_account.focus();
		return false;
	}
	if (Trim(theForm.login_accountPwd.value).length == 0){
		alert("密码不能为空!");
		theForm.login_accountPwd.focus();
		return false;
	}
	
	return true;
}

//验证收货人信息表单
function checkAddressData(theForm){
	if (Trim(theForm.i_name.value).length == 0){
		alert("收货人姓名不能为空!");
		theForm.i_name.focus();
		return false;
	}
	if (theForm.i_city3.value == 0){
		alert("你必须选择省份/城市!");
		return false;
	}
	if (Trim(theForm.i_address.value).length == 0){
		alert("详细地址不能为空!");
		theForm.i_address.focus();
		return false;
	}
	if (Trim(theForm.i_telephone.value).length == 0 && Trim(theForm.i_mobile.value).length == 0){
		alert("手机和固定电话至少有一项必填!");
		theForm.i_telephone.focus();
		return false;
	}
	
	return true;
}

//验证发货方式,付款方式,发货时间表单
function checkSendAndPayData(theForm){
	hasSelect = 0;
    for (i = 0 ;  i < theForm.elements.length ; i ++){
    	checkElement = theForm.elements[i];
		//判断是否选择了地区
    	if (checkElement.type.toLowerCase() == "radio" && checkElement.name == "i_sendType"){
        	if (checkElement.checked == true){
            	hasSelect++;
            }
        }
		//判断是否选择了发货方式
    	if (checkElement.type.toLowerCase() == "radio" && checkElement.name == "i_payType"){
        	if (checkElement.checked == true){
            	hasSelect++;
            }
        }
		//判断是否选择了付款方式
    	if (checkElement.type.toLowerCase() == "radio" && checkElement.name == "i_sendTime"){
        	if (checkElement.checked == true){
            	hasSelect++;
            }
        }
    }
	
    if (hasSelect == 3){
    	return true ;
    }else{
		alert("请依次选择送货方式、付款方式、送货时间!");
        return false;
	}
}

