﻿  var http_request = false;
   function makeRequest(url) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      http_request.onreadystatechange = alertContents;
      http_request.open('GET', url, true);
      http_request.send(null);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('myspan').innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }

    function uname(theform) { 

      if (theform.M_uname.value == "") {
        document.getElementById('myspan').innerHTML="<font color=red>username is required. (max 18chars).</font>";       
        theform.M_uname.focus();
        return;
        }
      if ((theform.M_uname.value.length < 5) || (theform.M_uname.value.length > 19)) {
       document.getElementById('myspan').innerHTML="<font color=red>username is required. (max 18chars)</font>";  
       theform.M_uname.focus();
       return;
      }              	

     document.getElementById('myspan').innerHTML = "<img src='/js/loading.gif'> Requesting content...";                    
     makeRequest("/en/auth/ajax_checkuser.cfm?M_uname="+theform.M_uname.value);
    }       


   function submit_register(theform) {  
       
        function IsNumericBLN(objField) {
	var blnNumeric = true
	
	// SCAN string for non-numeric characters.
	for (var i = 0; i < objField.value.length; i++) {
	
		var strDigit = objField.value.charAt(i)
	
		if (strDigit < "0" || strDigit > "9") {	//non-numeric character has been found.
			blnNumeric = false
			break
		}
	}		
	return blnNumeric	
       }

      function EMailValidBLN(objField) {        	
	if (objField.value.indexOf ('@', 0) == -1 || objField.value.indexOf ('.', 0) == -1) {	// address does not contain the "@" and "." characters.					  
		return false;      
	}	
	else {	// the address is acceptable.
		return true;      
	}   
      }

	  BANNED_PASSWORDS = ["111111","11111111","112233","121212","123123","123456","1234567","12345678","123456789","131313","232323","654321","666666","696969","777777","7777777","aaaaaa","abc123","abc123","abcdef","asdfgh","asdfgh","amystory","password","password","password1","password12","password123","qwerty","qwertyui","xxxxxx","xxxxxxxx","zxcvbn","zxcvbnm","zzzzzz"];

       
        // VALIDATE email address.
        if (!EMailValidBLN(theform.M_email) || (theform.M_email.value.length < 9)) {
        document.getElementById('myspan').innerHTML="<font color=red>email is required.</font>";  
        theform.M_email.focus();
        return;
        }

        if ((theform.M_uname.value == "") || (theform.M_uname.value.length < 5)) {
        document.getElementById('myspan').innerHTML="<font color=red>username is required.</font>";
        theform.M_uname.focus();
        return;
        }
  
        if ((theform.M_pass.value == "") || (theform.M_pass.value.length < 5)) {
        document.getElementById('myspan').innerHTML="<font color=red>password is required.</font>";
        theform.M_pass.focus();
        return;			
        }

      for(i=0; i<33; i++) { 
		if (theform.M_pass.value == BANNED_PASSWORDS[i]) {
        document.getElementById('myspan').innerHTML="<font color=red>invalid password.</font>";
        theform.M_pass.focus();
        return;			
        }
	  }

        if (theform.M_gender[0].checked == false && theform.M_gender[1].checked == false){
        document.getElementById('myspan').innerHTML="<font color=red>gender is required..</font>";
        theform.M_gender.focus();
        return;
        }

       
        if (typeof theform.birthday_year!="undefined" && theform.birthday_year.selectedIndex < 1) {
         document.getElementById('myspan').innerHTML="<font color=red>birthday is required.</font>";       
         theform.birthday_year.focus();
         return;
        }    

        if (typeof theform.birthday_month!="undefined" && theform.birthday_month.selectedIndex < 1) {
         document.getElementById('myspan').innerHTML="<font color=red>birthday is required.</font>";         
         theform.birthday_month.focus();
         return;
         }    

        if (typeof theform.birthday_day!="undefined" && theform.birthday_day.selectedIndex < 1) {
         document.getElementById('myspan').innerHTML="<font color=red>birthday is required.</font>";          
         theform.birthday_day.focus();
         return;
         }             
		 
         if ((theform.M_city.value == "") || (theform.M_city.value.length < 2)) {
        document.getElementById('myspan').innerHTML="<font color=red>city is required.</font>";
        theform.M_city.focus();
        return;
        }
                                                                
         if (typeof theform.M_country!="undefined" && theform.M_country.selectedIndex < 1) {
         document.getElementById('myspan').innerHTML="<font color=red>country is required.</font>";         
         theform.M_country.focus();
         return;
           }    

        if (theform.checkterms.checked == false){
        document.getElementById('myspan').innerHTML="<font color=red>You must be 18+?</font>"; 
        theform.checkterms.focus()
        return;
        }

        theform.action="http://www.amystory.com/en/auth/account_add.cfm?amode=add";
        theform.submit();   
}