function replace(strSource,strFrom,strTo){
    var pattern,re;
	var s = strSource;
	pattern = new RegExp(strFrom,"ig");
	re = s.replace(pattern,strTo);

      return re;
}
function ChkStrreg(str)
{
	str=replace(str,"'","＇");
	str=replace(str,"\"","＂");
	str=replace(str,"#","＃");
	str=replace(str,"&", "＆");
	str=replace(str,"<","＜");
	str=replace(str,">","＞");
	str=replace(str,";","；");
	return str;
}
function returnhaschinese(objText){
var haschinese=false;
var rowCnt =5;
 for(var i=0;i<objText.length/rowCnt;i++){
  for(var j=0;j<rowCnt;j++){
  var firstcharnum=Number(objText.charAt(j+i*rowCnt));
  var firstchar=objText.charAt(j+i*rowCnt);
   if((firstchar>="a"&firstchar<="z")|(firstchar>="A"&firstchar<="Z")|(firstcharnum>=0&firstcharnum<=9)|returnhasspachar(firstchar)){
   }else haschinese=true;
  }
 }

return haschinese;
}
function returnhasspachar(char){
var b=false;
var charList = '.-_';
for (var i=0;i<charList.length;i++)
{
  if(char==charList.charAt(i))b=true;
}
return b;
}
function checkdata(){
	var codestr=document.form2.code.value;//alert(document.form2.pwd.value);
	//alert("fdsfs");
	
	if(codestr==""){
		window.alert(regedit_js_alert_inputcodetoregedit);
		form2.code.focus();
		return false;
	}else{
	  if(!returnhaschinese(codestr)){
	    if(returnhasspachar(codestr.substring(0,1))|returnhasspachar(codestr.substring(codestr.length-1))){
	      alert(regedit_js_alert_startandendwith);
		  form2.code.focus();
		  return false;
	    }
	  }else{
		 alert(regedit_js_alert_codeerror);
		 form2.code.focus();
		 return false;
	  }
	}
	/*if(document.form2.customerName.value==""){
		window.alert("請輸入您真實姓名!");
		form2.customerName.focus();
		return false;
	}*/
    if (document.form2.pwd.value=="")
    {
       alert(regedit_js_alert_pwdisnull);
       document.form2.pwd.select();
       return false;
    }else if(document.form2.pwd.value.length<6){
	   alert(regedit_js_alert_pwdtooshort);
       document.form2.pwd.select();
       return false;
	}else if(document.form2.pwd.value.length>30){
	   alert(regedit_js_alert_pwdtoolong);
       document.form2.pwd.select();
       return false;
	}else if(document.form2.pwd.value=="111111"){
	   alert(regedit_js_alert_pwdtoosimple);
       document.form2.pwd.select();
       return false;
	}else{
		document.form2.pwd.value=ChkStrreg(document.form2.pwd.value);
	}
  if (document.form2.pwd2.value==""||document.form2.pwd2.value.length>30)
  {
       alert(regedit_js_alert_pwd2error);
       document.form2.pwd2.select();
       return false;
  }else{
		document.form2.pwd2.value=ChkStrreg(document.form2.pwd2.value);
	}
    if(document.form2.pwd.value!=document.form2.pwd2.value){
	   alert(regedit_js_alert_pwdnotthesame);
	   document.form2.pwd2.value="";
	   document.form2.pwd.select();
	   return false;
    }
    /*if(document.form2.contact1.value==""){
	   alert("請填寫聯系人姓名!");
	   document.form2.contact1.select();
	   return false;
    }*/
	if(document.form2.question.options[0].selected){
	   alert(regedit_js_alert_selectquestion);
	   //document.form2.question.select();
	   return false;
  }else if(document.form2.question.value=="defined"){
		if(document.form2.myquestion.value==""){
			alert(regedit_js_alert_inputquestion);
			document.form2.myquestion.select();
	        return false;
		}else{
		   document.form2.myquestion.value=ChkStrreg(document.form2.myquestion.value);
	  }
	}
	if(document.form2.answer.value==""){
			alert(regedit_js_alert_inputanswer);
			document.form2.answer.select();
	        return false;
	}else{
		document.form2.answer.value=ChkStrreg(document.form2.answer.value);
	}
    /*if(document.form2.tel1.value==""){
	   alert("請填寫聯系人電話!");
	   document.form2.tel1.select();
	   return false;
    }*/
  if(document.form2.email1.value==""){
	  alert(regedit_js_alert_inputemail);
	  document.form2.email1.select();
	  return false;
  }else if(!isEmail(document.form2.email1.value)){
      alert(regedit_js_alert_inputrightemail);
      document.form2.email1.select();
      return false;
  }
  if(document.form2.customerName.value.length>0){
			document.form2.customerName.value=ChkStrreg(document.form2.customerName.value);
	}
  if(document.form2.customerNameEn.value.length>0){
			document.form2.customerNameEn.value=ChkStrreg(document.form2.customerNameEn.value);
	}
  if(document.form2.contact1.value.length>0){
			document.form2.contact1.value=ChkStrreg(document.form2.contact1.value);
	}
  if(document.form2.tel1.value.length>0){
			document.form2.tel1.value=ChkStrreg(document.form2.tel1.value);
	}
  if(document.form2.fax1.value.length>0){
			document.form2.fax1.value=ChkStrreg(document.form2.fax1.value);
	}
  if(document.form2.mobile1.value.length>0){
			document.form2.mobile1.value=ChkStrreg(document.form2.mobile1.value);
	}
	if(!checkcodehaveused())return false;
	if(!checkemailhaveused())return false;
	if(document.getElementById("regeditbutton"))document.getElementById("regeditbutton").disabled=true;
	return true;
}
function isEmail(S) {
var pass=0; 
if (window.RegExp) { 
var tempS="a"; 
var tempReg=new RegExp(tempS); 
if (tempReg.test(tempS)) pass=1; 
} 
if (!pass) 
return (S.indexOf(".") > 2) && (S.indexOf("@") > 0); 
var r1=new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)"); 
var r2=new RegExp("^[a-zA-Z0-9\\.\\!\\#\\$\\%\\&\\’\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\}\\~]*[a-zA-Z0-9\\!\\#\\$\\%\\&\\’\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\}\\~]\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"); 
return (!r1.test(S) && r2.test(S)); 
}