var ajaxResult = "";
 
function checkAjax(aForm) {

	if (window.XMLHttpRequest) {              
   		AJAX=new XMLHttpRequest();              
	} else {                                  
		AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (AJAX) {
		AJAX.open("GET", "/personals/signup_ajax.php?emailAddress=" + aForm.email.value + "&screenName=" + aForm.screenName.value+"&securityCode=" + aForm.securityCode.value +"&postalCode=" + aForm.postCode.value+"&country_id=" + aForm.country_id.options[aForm.country_id.selectedIndex].value, false);                             

     		try {
			AJAX.send(null);
     			ajaxResult= eval('('+AJAX.responseText+')');

     		} catch(e) {
			alert(e);
     		}

     		return ajaxResult;
  	} else {
     		return false;
  	}                                             
}
/*
Ooops...
Merci de préciser:

Qui vous êtes 
Qui vous recherchez 
Votre date de naissance 
Votre code postal 
Votre pseudo doit comporter au moins 3 caractères 
Votre pseudo est trop long merci de réduire son nombre de caractères 
Ce pseudonyme est déjà utilisé par un membre, merci d'en créer un autre. 
Votre code sécurité
Déclaration d'être majeur et acceptation des CGU
*/

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   
		    return false
		 }

 		 return true					
	}


function checkLogin(aForm) {
	//alert(aForm.genderType_Id.options[aForm.genderType_Id.selectedIndex].value);
	res = true;
	msg='Ooops...\nYou need to specify the following:\n\n';
	document.getElementById('genderType_IdText').className='fontField';
	document.getElementById('genderSeekingType_IdText').className='fontField';
	document.getElementById('birthDayText').className='fontField';
	document.getElementById('birthMonthText').className='fontField';
	document.getElementById('birthYearText').className='fontField';
	document.getElementById('postCodeText').className='fontField';
	document.getElementById('screenNameText').className='fontField';
	document.getElementById('passwordText').className='fontField';
	document.getElementById('emailText').className='fontField';
	document.getElementById('securityText').className='fontField';
	document.getElementById('adultText').className='fontSubField';
	if (aForm.genderType_Id.options[aForm.genderType_Id.selectedIndex].value=='0') {
		msg +="Your gender\n";
		document.getElementById('genderType_IdText').className='fontError';
		res=false;
	}
	if (aForm.genderSeekingType_Id.options[aForm.genderSeekingType_Id.selectedIndex].value=='0') {
		msg +="Gender of partner\n";
		document.getElementById('genderSeekingType_IdText').className='fontError';
		res=false;
	}
	if (aForm.birthDay.value<1 || aForm.birthDay.value > 31) {
		msg +="Birth date (DD)\n";
		document.getElementById('birthDayText').className='fontError';
		res=false;
	}
	if (aForm.birthMonth.value<1 || aForm.birthMonth.value > 12) {
		msg +="Birth date (MM)\n";
		document.getElementById('birthMonthText').className='fontError';
		res=false;
	}
	if (aForm.birthYear.value<1920 || aForm.birthYear.value > minYear) {
		msg +="Birth date (YYYY)\n";
		document.getElementById('birthYearText').className='fontError';
		res=false;
	}
	if (aForm.postCode.value.length<5) {
		msg +="Your zipcode\n";
		document.getElementById('postCodeText').className='fontError';
		res=false;
	}
	if (aForm.screenName.value.length<3) {
		msg +="Your screen name needs to be minimum 3 characters\n";
		document.getElementById('screenNameText').className='fontError';
		res=false;
	}
	if (aForm.screenName.value.length>12) {
		msg +="Your screen name is too long, please reduce it\n";
		document.getElementById('screenNameText').className='fontError';
		res=false;
	}
	if (aForm.password.value.length<3) {
		msg +="Minimum password length is 3 characters\n";
		document.getElementById('passwordText').className='fontError';
		res=false;
	}

	if (!echeck(aForm.email.value)) {
		msg +="Your email address\n";
		document.getElementById('emailText').className='fontError';
		res=false;
	}
	if (res==true) {

		checkAjax(aForm);
	
		if (ajaxResult.result != "OK") {
			if (ajaxResult.errorEmail==1) {
				msg += "This email address is already in use by a member.\n";
				document.getElementById('emailText').className='fontError';
			}
			if (ajaxResult.errorScreenName==1) {
				msg += "This screen name is alread taken.  Please use a different one.\n";
				document.getElementById('screenNameText').className='fontError';	
			}
			if (ajaxResult.errorSecurityCode==1) {
				msg += "Your verification code.\n";
				document.getElementById('securityText').className='fontError';
			}
			if (ajaxResult.errorPostalCode!="0") {
				msg += ajaxResult.errorPostalCode+"\n";
				document.getElementById('postCodeText').className='fontError';
			}


			res = false;
		}
		
	}
	if (!aForm.isAdult.checked) {
		msg += "Declaration of being and adult and accepting terms and conditions\n";
		document.getElementById('adultText').className='fontError';
		res=false;
	
	}
	if (res==false) {
		alert(msg);
	}
	return res;
}

function animateFlash() {
  el =  document.getElementById('flashblock');
  eltop=parseInt(el.style.top.substr(0,el.style.top.length-2));
  if (eltop < 0) {
    el.style.top = (eltop+20)+'px';
  }
  setTimeout("animateFlash()",50);
}