﻿function trim(inputString) {
	if (typeof inputString != "string") { return inputString; }
	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	while (ch == " ") {
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length-1, retValue.length);
	while (ch == " ") {
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
	while (retValue.indexOf("  ") != -1) {
		retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
	}
	return retValue;
}

function cc(theForm) { 

	if (trim(theForm.linkman.value)=="")
	{
		alert("請填寫聯繫人");
		theForm.linkman.focus();
		theForm.linkman.select();
		return false;
	}
	if (trim(theForm.address.value)=="")
	{
		alert("請填寫聯繫地址");
		theForm.address.focus();
		theForm.address.select();
		return false;
	}
	if (trim(theForm.phone.value)=="")
	{
		alert("請填寫聯繫電話");
		theForm.phone.focus();
		theForm.phone.select();
		return false;
	}
	if (trim(theForm.email.value)=="")
	{
		alert("請填寫電子郵件");
		theForm.email.focus();
		theForm.email.select();
		return false;
	}
	var str1 = theForm.email.value
	if(str1.indexOf("@") == -1 || str1.indexOf(".") == -1)
	{
		alert("電子郵件格式不正確,請重新填寫");
		theForm.email.focus();
		theForm.email.select();
		return false;
	}
	if (trim(theForm.content.value)=="")
	{
		alert("請填寫留言内容");
		theForm.content.focus();
		theForm.content.select();
		return false;
	}
	if (trim(theForm.verifycode.value)=="")
	{
		alert("請填寫驗證碼");
		theForm.verifycode.focus();
		theForm.verifycode.select();
		return false;
	}
	theForm.submit();
return true;
}

function ChkReg(theForm) { 
	if (trim(theForm.userid.value)=="")
	{
		alert("請填寫賬號");
		theForm.userid.focus();
		theForm.userid.select();
		return false;
	}
	if (trim(theForm.pass.value)=="")
	{
		alert("請填寫密碼");
		theForm.pass.focus();
		theForm.pass.select();
		return false;
	}
	var x = /[0-9a-zA-Z]{4,20}/;
	if (!x.test(theForm.userid.value))
	{
		alert("賬號請用4-20位英文或數字組成");
		theForm.userid.focus();
		theForm.userid.select();
		return false;
	}
	if (!x.test(theForm.pass.value))
	{
		alert("密碼請用4-20位英文或數字組成");
		theForm.pass.focus();
		theForm.pass.select();
		return false;
	}

	if (trim(theForm.pass.value)!=trim(theForm.pass1.value))
	{
		alert("兩次輸入的密碼不符，請檢查后重新輸入");
		theForm.pass.focus();
		theForm.pass.select();
		return false;
	}
	if (trim(theForm.linkman.value)=="")
	{
		alert("請填寫聯繫人");
		theForm.linkman.focus();
		theForm.linkman.select();
		return false;
	}
	if (trim(theForm.company.value)=="")
	{
		alert("請填寫公司名稱");
		theForm.company.focus();
		theForm.company.select();
		return false;
	}
	if (trim(theForm.phone.value)=="")
	{
		alert("請填寫聯繫電話");
		theForm.phone.focus();
		theForm.phone.select();
		return false;
	}
	if (trim(theForm.email.value)=="")
	{
		alert("請填寫電子郵件");
		theForm.email.focus();
		theForm.email.select();
		return false;
	}
	var str1 = theForm.email.value
	if(str1.indexOf("@") == -1 || str1.indexOf(".") == -1)
	{
		alert("電子郵件格式不正確,請重新填寫");
		theForm.email.focus();
		theForm.email.select();
		return false;
	}
	if (trim(theForm.verifycode.value)=="")
	{
		alert("請填寫驗證碼");
		theForm.verifycode.focus();
		theForm.verifycode.select();
		return false;
	}
	theForm.submit();
return true;
}

