
//
// BadEmail - Check for unreasonable Email address 
//
   function BadEmail(obj, objname)
   {
     TrimAll(obj);
     x=obj
     L =x.value.length;
 	 if (x.value.charAt(L-1)=="."){alert("'" + objname + "' may not have a period as its last character");x.focus();return -1}
	 At=x.value.indexOf("@");
	 if (At==-1){alert("'" + objname + "' is missing an @ sign");x.focus();return -1}
	 if (At==0){alert("'" + objname + "' may not have @-sign as first character");x.focus();return -1}
	 if (At==(L-1)){alert("'" + objname + "' may not have @-sign as last character");x.focus();return -1}
	/// A=x.value.indexOf("@",At+1);	 
	//if (A !=-1){alert("'" + objname + "' may not have more than one @-sign");x.focus();return -1}
	 P =x.value.indexOf(".");
	 if (P==-1){alert("'" + objname + "' must have at least one period");x.focus();return -1}
	 if (P==0){alert("'" + objname + "' may not have period as first character");x.focus();return -1}
	 P =x.value.indexOf(".",At+1);
 	 if (P==-1){alert("'" + objname + "' must have at least one period after @-sign");x.focus();return -1}
	 if (At+1==P){alert("'" + objname + "' must have characters between @sign and period");x.focus();return -1}
	 y=x.value.substring(L-3,L); // last three characters
	 z=x.value.substring(L-2,L); // last two characters
	 z=z.toLowerCase();
	 if (y.charAt(0)=="." && z=="us") {y=x.value.substring(L-6,L-3)}
 	 if (y.charAt(0)!=".")
	     {
    	 y=y.toLowerCase();
	 //    if (y!="com" && y!="edu" && y!="net" && y!="org" && y!="gov" && y!="mil" && y!="int"){alert("'" + objname + "' must be .com, .edu, .net, .org, .gov, .mil, or .int ");x.focus();return -1};
		 }
	// if (P==(L-3)){alert("'" + objname + "' may not have only one period and end in just two letters");x.focus();return -1}
	// if (x.value.indexOf(",")!=-1){alert("'" + objname + "' may not contain a comma");x.focus();return -1}
	// if (x.value.indexOf(" ")!=-1){alert("'" + objname + "' may not contain a space");x.focus();return -1}
	 if (x.value.indexOf("*")!=-1){alert("'" + objname + "' may not contain a asterisk");x.focus();return -1}
	 if (x.value.indexOf(")")!=-1){alert("'" + objname + "' may not contain a close parenthesis");x.focus();return -1}
	 if (x.value.indexOf("(")!=-1){alert("'" + objname + "' may not contain a open parenthesis");x.focus();return -1}
	 if (x.value.indexOf(">")!=-1){alert("'" + objname + "' may not contain a greater than sign");x.focus();return -1}
	 if (x.value.indexOf("<")!=-1){alert("'" + objname + "' may not contain a less than sign");x.focus();return -1}
	 if (x.value.indexOf(":")!=-1){alert("'" + objname + "' may not contain a colon");x.focus();return -1}
	 if (x.value.indexOf(";")!=-1){alert("'" + objname + "' may not contain a semi-colon");x.focus();return -1}
	 if (x.value.indexOf('"')!=-1){alert("'" + objname + "' may not contain a quotation mark");x.focus();return -1}
	 return false;
	}
//
//   TrimAll - Trim leading and trailing blanks from an input field  
//
   function TrimAll(obj) {
      var startpos = 0, endpos = obj.value.length - 1;
      if (endpos == -1) { //--- null string 
        return;
      }
      while (startpos <= obj.value.length && obj.value.substring(startpos, startpos + 1) == " ") {
 	      startpos++; //-- find start position of string 
      }
      while (endpos >= 0 && obj.value.substring(endpos, endpos + 1) == " ") {
	      endpos--; //--- find end position of string 
      }
      if (startpos > endpos) { //--- trim the object ---
         obj.value = "";
      } else {
         obj.value = obj.value.substring(startpos, endpos + 1);
      }
   }
//
// BadText - Check for the presence of any illegal character
//
   function BadText(obj, objname) {
      TrimAll(obj);
      c = '|';
      if (obj.value.indexOf(c) != -1) {
         alert("'" + objname + "' contains an illegal '" + c + "' character");
		 obj.focus();
		 return true;
      }
      return false;
   }
//
// WhiteText - Check for the presence of any spaces for usernames
//
   function WhiteText(obj, objname) {
      TrimAll(obj);
      c = ' ';
      if (obj.value.indexOf(c) != -1) {
         alert("'" + objname + "' cannot contain whitespaces");
		 obj.focus();
		 return true;
      }
      return false;
   }
//
//   IsAbsent - check for the presence of any character besides a blank
//
   function IsAbsent(obj, objname) {
      var retval = -1;
      for (var i = 0; i < obj.value.length; i++) {
         if (obj.value.substring(i, i + 1) != " ") {
            retval = 0;
            break;
         }
      }
      if (retval && (objname != "")) {
         alert("'" + objname + "' may not be left empty");
		 obj.focus();
      }
      return retval;
   }

function checkUsernameAndEmail()
{
    var e_mail =document.regist.email;
    var usrname = document.regist.Username;
   
   TrimAll(e_mail);
   TrimAll(usrname);


   if (e_mail.value == usrname.value)
   {
	alert("Username cannot be same as Email"); 
	return -1;
  }   
}

function checkUserName(obj, objname)
   {
     TrimAll(obj);
     x=obj
     L =x.value.length;
	 if (x.value.charAt(L-1)=="."){alert("'" + objname + "' may not have a period as its last character");x.focus();return -1}
	 At=x.value.indexOf("@");	 
	 if ((At==0) || (At>0) ){alert("'" + objname + "' may not have @-sign in the username");x.focus();return -1}

}

function checkPassword(obj, objname)
   {
     TrimAll(obj);
     x=obj
     L =x.value.length;
     if (L < 8){alert("'" + objname + "' must be 8 or more characters");x.focus();return -1}	 
}

function checkEmpty()
{
   
   var e_mail =document.regist.email;
   var usrname = document.regist.Username;
   
   TrimAll(e_mail);
   TrimAll(usrname);
   if ((e_mail.value || usrname.value)==0)
   {
	alert("Fields Required: First Name, E-mail address");
	 
	return -1
  }
}

function refreshCAPTCHA()
{
	
	document.regist.action="/Register/Regis.cfm";
	document.regist.submit(); 

}


function CheckItRegistration()
  {
	  
	 document.regist.action="/Register/Thanks.cfm";

	 //checkEmpty();
         //checkUsernameAndEmail();

	 var i1, i2, fld;

	 fld=document.regist.FirstName;
     	 TrimAll(fld);
	 if(BadText(fld,"First Name"))    {return;}
	 if(WhiteText(fld,"First Name"))  {return;}
	 if(IsAbsent(fld,"First Name"))   {return;}
	
	 fld=document.regist.LastName;
     	 TrimAll(fld);
	 if(BadText(fld,"Last Name"))  	 {return;}
	 if(WhiteText(fld,"Last Name"))  {return;}
	 if(IsAbsent(fld,"Last Name")) 	 {return;}

 	 fld=document.regist.Username;
     	 TrimAll(fld);
	 if(BadText(fld,"Username"))  	{return;}
	 if(WhiteText(fld,"Username"))  {return;}
	 if(IsAbsent(fld,"Username")) 	{return;}
	 if(checkUserName(fld,"Username")) 	{return;}

	 fld=document.regist.password;
     	 TrimAll(fld);
	 if(IsAbsent(fld,"Password")) 	{return;}
	 if(checkPassword(fld,"password")) 	{return;}

	 fld=document.regist.email;
     	 TrimAll(fld);
	 if(BadText(fld,"Email"))  	{return;}
	 if(IsAbsent(fld,"Email")) 	{return;}
	 if(BadEmail(fld,"Email"))	{return;} 
	
	
	 if (document.regist.Hint.value=='Select one'){alert("Please select your Lost Password Question"); x.focus(); return -1}
	
	
	 if (document.regist.Hint.value=='Create your own')
	 {
	 	fld=document.regist.CreateQuestion;
	 	TrimAll(fld);
	 	if(BadText(fld,"Create your own question"))    {return;}
	 	if(IsAbsent(fld,"Create your own question"))   {return;}
	 }
	
	 
	 fld=document.regist.Hintanswer;
     	 TrimAll(fld);
	 if(BadText(fld,"Hint Answer"))    { return;}
	 if(WhiteText(fld,"Hint Answer"))  { return;}
	 if(IsAbsent(fld,"Hint Answer"))   { return;}

	 if (document.regist.visitor.value==0){alert("Please select your visitor description"); x.focus(); return -1}
	 if (document.regist.gender.value==0){alert("Please select your gender"); x.focus(); return -1}
	 if (document.regist.agerange.value==0){alert("Please select your age range"); x.focus(); return -1}
	 
	 fld=document.regist.postalcode;
	 TrimAll(fld);
	 if(BadText(fld,"Zip Code"))    {return;}
	 if(WhiteText(fld,"Zip Code"))  {return;}
	 if(IsAbsent(fld,"Zip Code"))   {return;}
	 
	 if (document.regist.insurance.value==0){alert("Please select insurance you use."); x.focus(); return -1}
	 
	 if (document.regist.confirm.checked==false){alert("Please confirm that you have read and agree to the Body1 privacy policy"); x.focus(); return -1}
	 if (document.regist.encryptedcaptchatext.value!=hex_md5(document.regist.captchatext.value).toUpperCase()){
	  alert("Code you entered is not correct. Try again."); return -1}
	 document.regist.submit();  

}

