//函数名：checkspace
//功能介绍：检查是否为空
//参数说明：要检查的字符串
//返回值：0：是  1：不是
function checkspace(checkstr) {
  var str = '';
  for(i = 0; i < checkstr.length; i++) {
    str = str + ' ';
  }
  return (str == checkstr);
}
//-->

//函数名：chkspc
//功能介绍：检查是否含有空格
//参数说明：要检查的字符串
//返回值：0：是  1：不是
function chkspc(a)
{
	var i = a.length;
	var j  =  0;
	var k  =  0;
	while (k<i)
	{
		if (a.charAt(k) !=  " ")
			j  =  j+1;
		k  =  k+1;
	}
	if (j == 0)
	{
		return 0;
	}
	
	if (i!= j)
	{ return 2; }
	else
	{
		return 1;
	}
}

//函数名：fucCheckTEL
//功能介绍：检查是否为电话号码
//参数说明：要检查的字符串
//返回值：1为是合法，0为不合法
function fucCheckTEL(TEL)
{
	var i,j,strTemp;
	strTemp = "0123456789-()# ";
	for (i = 0;i<TEL.length;i++)
	{
		j = strTemp.indexOf(TEL.charAt(i));	
		if (j == -1)
		{
		//说明有字符不合法
			return 0;
		}
	}
	//说明合法
	return 1;
}


//函数名：fucCheckQQ
//功能介绍：检查是否为电话号码
//参数说明：要检查的字符串
//返回值：1为是合法，0为不合法
function fucCheckQQ(QQ)
{
	var i,j,strTemp;
	strTemp = "0123456789";
	for (i = 0;i<QQ.length;i++)
	{
		j = strTemp.indexOf(QQ.charAt(i));	
		if (j == -1)
		{
		//说明有字符不合法
			return 0;
		}
	}
	//说明合法
	return 1;
}


function check()
{   
 if(checkspace(document.userinfo.user_id.value)) {
	document.userinfo.user_id.focus();
    alert("請填寫用戶名");
	return false;
  }
  if(checkspace(document.userinfo.user_pw.value)) {
	document.userinfo.user_pw.focus();
    alert("請填寫密碼");
	return false;
  }
  if(checkspace(document.userinfo.user_pw2.value)) {
	document.userinfo.user_pw2.focus();
    alert("請確認密碼");
	return false;
  }
  
  if((document.userinfo.user_pw.value !== document.userinfo.user_pw2.value)) {
	document.userinfo.user_pw.focus();
    alert("兩次密碼輸入不同");
	return false;
  }
  if(checkspace(document.userinfo.user_name.value)) {
	document.userinfo.user_name.focus();
    alert("請填寫真實姓名");
	return false;
  }
  
  if(checkspace(document.userinfo.question.value)) {
	document.userinfo.question.focus();
    alert("請選擇問題提示");
	return false;
  } 
  if(checkspace(document.userinfo.answer.value)) {
	document.userinfo.answer.focus();
    alert("請輸入問題答案");
	return false;
  } 

 if(document.userinfo.user_email.value.length!=0)
  {
    if (document.userinfo.user_email.value.charAt(0)=="." ||        
         document.userinfo.user_email.value.charAt(0)=="@"||       
         document.userinfo.user_email.value.indexOf('@', 0) == -1 || 
         document.userinfo.user_email.value.indexOf('.', 0) == -1 || 
         document.userinfo.user_email.value.lastIndexOf("@")==document.userinfo.user_email.value.length-1 || 
         document.userinfo.user_email.value.lastIndexOf(".")==document.userinfo.user_email.value.length-1)
     {
      alert("Email有誤");
      document.userinfo.user_email.focus();
      return false;
      }
   }
 else
  {
   alert("Email不能為空");
   document.userinfo.user_email.focus();
   return false;
   }
   
 if ((document.userinfo.mobile_phone.value!=="") &&  (document.userinfo.mobile_phone.value.length>11)||(fucCheckTEL(document.userinfo.mobile_phone.value) == 0))
	{
		alert("您的手機號碼填寫有誤");
		document.userinfo.mobile_phone.focus();
		return false;
	}
     
if(checkspace(document.userinfo.user_tel1.value)) {
	document.userinfo.user_tel1.focus();
    alert("請填寫常用電話號碼");
	return false;
  }
  
if ((document.userinfo.user_tel1.value == '') || (chkspc(document.userinfo.user_tel1.value) == 0) || (document.userinfo.user_tel1.value.length>30)||(fucCheckTEL(document.userinfo.user_tel1.value) == 0)||(document.userinfo.user_tel1.value.length < 7))
	{
		alert("電話號碼有誤");
		document.userinfo.user_tel1.focus();
		return false;
	}
	
	
if ((document.userinfo.fax.value!=="") && (document.userinfo.fax.value.length>30)||(fucCheckTEL(document.userinfo.fax.value) == 0))
	{
		alert("您的傳真號碼填寫有誤");
		document.userinfo.fax.focus();
		return false;
	}
 if(checkspace(document.userinfo.UProvince.value)) {
	document.userinfo.UProvince.focus();

    alert("請正確填寫你的省份");
	return false;
  }
  if(checkspace(document.userinfo.UCity.value)) {
	document.userinfo.UCity.focus();
    alert("請正確填寫你的城市");
	return false;
  }

  if ((document.userinfo.code.value!=="") && (document.userinfo.code.value.length>30)||(fucCheckTEL(document.userinfo.code.value) == 0))
	{
		alert("您的郵編填寫有誤");
		document.userinfo.code.focus();
		return false;
	}
	
	if(checkspace(document.userinfo.user_address.value)) {
	document.userinfo.user_address.focus();
    alert("請正確填寫你的收貨地址！");
	return false;
  }
	
}


