
var msg = "";
var Email_registered = "The email is already registered";
var Email_Banned ;
$$$(function(){
	if (document.getElementById('email')) {
		Email_Banned = "Unfortunately, you cannot register with the domain "+ document.getElementById('email').value.toString().split("@")[1]+".<br /><br />Please enter a new email address."
	}
	
	/*  -------------------------------------------------------------------
		Google Analytics -------------------------------------------------- */
		_uacct = "UA-717960-2";
		urchinTracker();
});
var User_registered = "The Username is already registered";

var Server_error = "The server is experiencing technical difficulties please try again later";
var bad_request = "Bad request - Server Error - try again later"
var auth_req = "Authentication is needed to request tunnel"
var http_request_too_large = "HTTP request is too large"


var missing_user_pwd = "Both username and email need to be supplied";
var redirect = "Your profile was updated<br />You will be redirected in 5 seconds";
var match_pwd = "The confirmed password does not match";
var min_pwd = "The password must be atleast 8 characters";
var CAPTCHA = "The verification code you entered was typed incorrectly. Please re-type the new code.";
var CAPTCHA_what_is_this = "This is an abuse-prevention mechanism designed to help prevent spam-generating automated robots from creating profiles and sending emails. This feature also reduces system loads, which improves site performance.<br /><br />Type the characters you see in the image into the box provided. If you do not see an image, make sure your browser is set to display images and try again. If you aren't sure what the characters are, make your best guess (it is not necessary to match uppercase or lowercase letters). If you guess incorrectly, you'll get another chance to enter a different code when the page refreshes. Or, you can click \"Try another code\" to view a different set of characters."

var pwd_invalid_dash = "The password can not start or end with -";
var pwd_invalid = "The password can only contain a-z A-Z and -";
var pwd_empty = "Please enter a password";


var valid_email = "Please enter a valid email";
var user_invalid_dash = "The user name can not start or end with -";
var user_invalid = "The user name can only contain a-z A-Z and -";
var user_empty = "Please enter a user name";
var last_name_empty = "Please enter your last name";
var first_name_empty = "Please enter your first name";

function selectOther()
{
    if(document.getElementById('howdidyoulearn').selectedIndex == 3 )
    {
        document.getElementById('div_other').style.display = 'block';
    }
    else
    {
        document.getElementById('div_other').style.display = 'none';
    }
}

function validateForm()
{
    var go = true;
    
    if(document.getElementById('password').value != document.getElementById('confirmpassword').value )
    {
        document.getElementById('l_confirmpassword').className = "error"; go = false;
        msg = match_pwd;
        document.getElementById('l_confirmpassword').focus();
    }
    else
    {
        document.getElementById('l_confirmpassword').className = "";
    }
    
    if( document.getElementById('password').value.length < 8)
    {
        document.getElementById('l_password').className = "error";go = false;
        document.getElementById('password').focus();
        msg = min_pwd
    }
    else
    {
        document.getElementById('l_password').className = "";
    }
    
    
    //check the password for valid characters
    switch(checkFQDN(document.getElementById('password').value))
    {
        case 3:
            msg = pwd_invalid_dash;
            document.getElementById('l_password').className = "error"; go = false;
			document.getElementById('password').focus();
            break;
      
        case 2:
            msg = pwd_invalid;
            document.getElementById('l_password').className = "error"; go = false;
			document.getElementById('password').focus();
            break;
        case 1:
            msg = pwd_empty;
            document.getElementById('l_password').className = "error"; go = false;
			document.getElementById('password').focus();
            break;
            
        default:
            document.getElementById('l_password').className = "";
        
    }
    
    //check the email
    if( checkEmail(document.getElementById('email').value) == false)
    {
        document.getElementById('l_email').className = "error"; go = false;
        msg = valid_email;
        document.getElementById('email').focus();
    }
    else
    {
        document.getElementById('l_email').className = "";
    } 
    
    
    //check the username for valid characters
    switch(checkFQDN(document.getElementById('username').value))
    {
        case 3:
            msg = user_invalid_dash;
            document.getElementById('l_username').className = "error"; go = false;
			document.getElementById('username').focus();
            break;
      
        case 2:
            msg = user_invalid;
            document.getElementById('l_username').className = "error"; go = false;
			document.getElementById('username').focus();
            break;
        case 1:
            msg = user_empty;
            document.getElementById('l_username').className = "error"; go = false;
			document.getElementById('username').focus();
            break;
            
        default:
            document.getElementById('l_username').className = "";
        
    }
        
        
    
    //check for a full name

    if( document.getElementById('lname').value == "")
    {
        document.getElementById('l_lname').className = "error"; go = false;
        msg = last_name_empty
			document.getElementById('lname').focus();
    }
    else
    {
        document.getElementById('l_lname').className = "";
    }


    if( document.getElementById('fname').value == "")
    {
        document.getElementById('l_fname').className = "error"; go = false;
        msg = first_name_empty
			document.getElementById('fname').focus();
    }
    else
    {
        document.getElementById('l_fname').className = "";
    }
    if ( go ) { document.regform.submit(); } else { displayError(msg); window.location = "#error_archor"; }
       
}


function checkEmail(to_check) {

	if (/^\w+([\+\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,5})+$/.test(to_check)){

	return (true)} else { return (false)}

}

function checkFQDN(to_check) {


    if(!to_check.length)
    {
        return (1);
    }

	if (/^([0-9a-zA-Z\-]{0,61})$/.test(to_check))
	{
       
    }
    else
    {
       return (2);
    }
    if (/^([0-9a-zA-Z]{1})+([0-9a-zA-Z\-]{0,61})+([0-9a-zA-Z]{1})$/.test(to_check))
    {
        
       return (0);
    }
    else
    {
       return (3);
    }

    

}

/*-------------------------------------------------------------
	Function openLogin
	Toggle visible the login popin
---------------------------------------------------------------*/

function openLogin(){
	positionneDiv("div_login", 282, 250);
	document.getElementById("div_login").style.display="block";
}



/*-------------------------------------------------------------
	Function closeLogin
	Toggle invisible the login popin
---------------------------------------------------------------*/


function closeLogin(){
	document.getElementById("div_login").style.display="none";
}



/*-------------------------------------------------------------
	Function openDiv
	Toggle visible the defined div (theId)
---------------------------------------------------------------*/


function openDiv(theId) {
	positionneDiv(theId, 250, 282);
	document.getElementById(theId).style.display="block";
}


/*-------------------------------------------------------------
	Function closeDiv
	Toggle invisible the defined div (theId)
---------------------------------------------------------------*/


function closeDiv(theId) {
    Element.hide('ForgotBTNS');
	document.getElementById(theId).style.display="none";

}







function validateLogin(){		
	if (document.getElementById("login_username").value.length && document.getElementById("login_password").value.length){	
		login_username = document.getElementById("login_username").value;
		login_password = document.getElementById("login_password").value;
        http.open('post', 'db_login.asp');
        http.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
        http.setRequestHeader("Referer","login.asp");
        http.onreadystatechange = handleLogin;
        http.send('login_username='+login_username+'&login_password='+login_password);		
	}
	else
	{
	    displayError("Please enter a username and password");
	}			
}

function validateLogout(){		
	    http.open('get', 'db_logout.asp');
        http.onreadystatechange = handleLogout;
        http.send(null);		
			
}

function logout(){		
        http.open('get', 'db_logout.asp');
         http.onreadystatechange = handleLogout;
         http.send(null);		
			
}

function handleLogin() {
	if(http.readyState == 4){
		var myVars = http.responseText;
		if(myVars.indexOf('invalid') != -1)
		{
		   displayError('The username and/or password is invalid.Please try again. ');
		}
		else
		{
	    document.location =  "home.asp";
		}
	}
}

function handleLogout() {
	if(http.readyState == 4){
		var myVars = http.responseText;
		document.location =  "home.asp";
	    document.getElementById('m_login_li').innerHTML = "<a href=\"/4105/login.asp\" onmouseover=\"rollOver('m_login','','/4105/images/m_login_over.gif',1)\" onmouseout=\"rollOut()\" ><img alt=\"Login\" title=\"Login\" src=\"/4105/images/m_login.gif\" id=\"m_login\" /></a>";
	    document.getElementById('liLogin').innerHTML = "<a href=\"javascript:validateLogin();\" onmouseover=\"rollOver('btn_login','','/4105/images/login_btn_over.gif',1)\" onmouseout=\"rollOut()\" ><img alt=\"Login\" title=\"Login\" src=\"/4105/images/login_btn.gif\" id=\"btn_login\" /></a>";
	}
}


function forgotPWD(mssg)
{
	Element.show('ForgotBTNS');
	displayError(mssg);
	
}

function SendEmail()
{
	if ($("emailForgot").value.length && checkEmail($("emailForgot").value)  ){	
		Element.hide('error_login','ForgotBTNS');
		login_username = $("emailForgot").value;
		http.open('post', 'db_forgot_pwd.asp');
        http.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
        http.setRequestHeader("Referer","login.asp");
        http.onreadystatechange = handleForgotPWD;
        http.send('login_username='+login_username);		
	}
	else
	{
	   forgotPWD("<span style=' color: #ff0000'>Please enter a valid Email</span>");
	}
}

function handleForgotPWD() {
	if(http.readyState == 4){
		var myVars = http.responseText;
        displayError(myVars);
	}
}

function displayError(msg)
{
    
    var errorDiv = document.getElementById("error_login");
    document.getElementById("error_message").innerHTML = msg;
    positionneDiv("error_login", 300, 100 );
    errorDiv.style.display = "block";
    
}

$$$(document).ready(function(){
    Element.hide('ForgotBTNS');
});

//Generates another CAPTACHA
var qte_code = 0;
function tryAnotherCode(){
    document.getElementById('verif_code').src += ++qte_code
};
