﻿  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>ユーザ名が必要です. (最大15文字).</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>ユーザ名が必要です. (最大15文字)</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;      
	}   
      }
       
        // VALIDATE email address.
        if (!EMailValidBLN(theform.M_email) || (theform.M_email.value.length < 9)) {
        document.getElementById('myspan').innerHTML="<font color=red>メールが必要です.</font>";  
        theform.M_email.focus();
        return;
        }

        if ((theform.M_uname.value == "") || (theform.M_uname.value.length < 5)) {
        document.getElementById('myspan').innerHTML="<font color=red>ユーザ名が必要です.</font>";
        theform.M_uname.focus();
        return;
        }
  
        if ((theform.M_pass.value == "") || (theform.M_pass.value.length < 5)) {
        document.getElementById('myspan').innerHTML="<font color=red>パスワードが必要です.</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>性別が必要です.</font>";
        theform.M_gender.focus();
        return;
        }

       if ((theform.M_seekinggender[0].checked == false) && (theform.M_seekinggender[1].checked == false)){
        document.getElementById('myspan').innerHTML="<font color=red>相手の性別が必要です.</font>";
        theform.M_seekinggender.focus();
        return;
        }

        if (typeof theform.birthday_year!="undefined" && theform.birthday_year.selectedIndex < 1) {
         document.getElementById('myspan').innerHTML="<font color=red>誕生日が必要です.</font>";       
         theform.birthday_year.focus();
         return;
        }    

        if (typeof theform.birthday_month!="undefined" && theform.birthday_month.selectedIndex < 1) {
         document.getElementById('myspan').innerHTML="<font color=red>誕生日が必要です.</font>";         
         theform.birthday_month.focus();
         return;
         }    

        if (typeof theform.birthday_day!="undefined" && theform.birthday_day.selectedIndex < 1) {
         document.getElementById('myspan').innerHTML="<font color=red>誕生日が必要です.</font>";          
         theform.birthday_day.focus();
         return;
         }             
		 
         if ((theform.M_city.value == "") || (theform.M_city.value.length < 2)) {
        document.getElementById('myspan').innerHTML="<font color=red>市町村が必要です.</font>";
        theform.M_city.focus();
        return;
        }
                                                                
         if (typeof theform.M_country!="undefined" && theform.M_country.selectedIndex < 1) {
         document.getElementById('myspan').innerHTML="<font color=red>国が必要です.</font>";         
         theform.M_country.focus();
         return;
           }    

        if (theform.checkterms.checked == false){
        document.getElementById('myspan').innerHTML="<font color=red>私は18歳以上独身ですか?</font>"; 
        theform.checkterms.focus()
        return;
        }

        theform.action="http://www.amystory.com/jp/auth/account_add.cfm?amode=add";
        theform.submit();   
}