 $(document).ready(function(){
 	
    $("#form_sign_up").validate(
{
  rules: {
    password: "required",
    password_again: {
      equalTo: "#password"
    }
  }
}	
	);
 	
	validateForm();
	
//When Password click
$("#password").keyup(function (e) {
	$("#password_hint").html("<span class='hint_box'>Your password must be letters or numbers only (no spaces), and between 6 and 12 characters long.</span>");
    });
$("#password").blur(function (e) {
	$("#password_hint").html("");
    });

//When Account Type click
$("#account").change(function (e) {
	if ($("#account").val() == 2){
		$("#account_hint").html("<p><span class='hint_box'>If you have already signup for a free account and wish to signup for the premium edition then simply <a href='index.cfm?JustDoIt=cHome.fHelp#upgrade_premium'>follow those steps.</a></span></p>");
	}
	validateForm();
    });

//When referral click
$("#referral").change(function (e) {
	if ($("#account").val() == 1){
		$("#referral").val('');
		$("#referral_hint").html("<p><span class='hint_box'>Only applicable if you select the Premium Edition.</span></p>");
	}
	else{
		$("#referral_hint").html("");	
	}
    });

/*
On keypress check to validate field (empty or not)
*/
$("#first_name").keyup(function (e) {
	validateForm();
    });

$("#last_name").keyup(function (e) {
	validateForm();
    });

$("#email").keyup(function (e) {
	$("#email_hint").html("<p><span class='hint_box'>Your confirmation will be sent at this address</span></p>");	
    });
	
$("#email").blur(function (e) {
	$("#email_hint").html("");
	validateForm();
    });	

$("#frm_common_country_home").change(function (e) {
	validateForm();
    });

$("#password").keyup(function (e) {
	validateForm();
    });

$("#confirm_password").keyup(function (e) {
	validateForm();
    });

$("#security_q").keyup(function (e) {
	validateForm();
    });
	
$("#security_a").keyup(function (e) {
	validateForm();
    });
	
/*
DESC: Check if all mandatory field are not null.
LOGIC:
if YES then don't disable the submit button
if NO then disable the submit button
*/
function validateForm(){
	var formValid = true;
	
/* account type */
	if ($('#account').val() == ''){
		$("#account").attr("style", "border: 1px red solid; background-color:#ffaaaa;");
		$("#validate_account").html("<img src='images/close_20.png' />");		
		formValid = false;		
	}
	else{
	$("#validate_account").html("<img src='images/ok_20.png' />");
	$("#account").attr("style", "");	
	}	
	
/* first name */
	if ($('#first_name').val() == ''){
		$("#first_name").attr("style", "border: 1px red solid; background-color:#ffaaaa;");
		$("#validate_first_name").html("<img src='images/close_20.png' />");		
		formValid = false;
	}
	else{
	$("#first_name").attr("style", "");		
	$("#validate_first_name").html("<img src='images/ok_20.png' />");	
	}				

/* last name */			
	if ($('#last_name').val() == ''){
		$("#last_name").attr("style", "border: 1px red solid; background-color:#ffaaaa;");
		$("#validate_last_name").html("<img src='images/close_20.png' />");		
		formValid = false;		
	}	
	else{
	$("#last_name").attr("style", "");		
	$("#validate_last_name").html("<img src='images/ok_20.png' />");	
	}
	
/* country */	
	if ($('#frm_common_country_home').val() == ''){
		$("#frm_common_country_home").attr("style", "border: 1px red solid; background-color:#ffaaaa;");
		$("#validate_country").html("<img src='images/close_20.png' />");		
		formValid = false;		
	}
	else{
	$("#frm_common_country_home").attr("style", "");		
	$("#validate_country").html("<img src='images/ok_20.png' />");	
	}
		
/* email */		
	if ($('#email').val() == '' || $("#form_sign_up").validate().element( "#email" ) == false){
		$("#email").attr("style", "border: 1px red solid; background-color:#ffaaaa;");		
		$("#validate_email").html("<img src='images/close_20.png' />");		
		formValid = false;		
	}
	else{
	$("#email").attr("style", "");		
	$("#validate_email").html("<img src='images/ok_20.png' />");	
	}
		
/* password */			
	if ($('#password').val() == ''){
		$("#password").attr("style", "border: 1px red solid; background-color:#ffaaaa;");		
		$("#validate_password").html("<img src='images/close_20.png' />");		
		formValid = false;		
	}	
	else{
	$("#password").attr("style", "");		
	$("#validate_password").html("<img src='images/ok_20.png' />");	
	}

/* confirm password */		
	if ($('#password_again').val() == '' || $("#form_sign_up").validate().element( "#password_again" ) == false){
		$("#password_again").attr("style", "border: 1px red solid; background-color:#ffaaaa;");		
		$("#validate_confirm_password").html("<img src='images/close_20.png' />");		
		formValid = false;		
	}
	else{
	$("#password_again").attr("style", "");		
	$("#validate_confirm_password").html("<img src='images/ok_20.png' />");	
	}
		
/* security question */		
	if ($('#security_q').val() == ''){
		$("#security_q").attr("style", "border: 1px red solid; background-color:#ffaaaa;");		
		$("#validate_security_q").html("<img src='images/close_20.png' />");		
		formValid = false;		
	}
	else{
	$("#security_q").attr("style", "");		
	$("#validate_security_q").html("<img src='images/ok_20.png' />");	
	}
		
/* security answer */
	if ($('#security_a').val() == ''){
		$("#security_a").attr("style", "border: 1px red solid; background-color:#ffaaaa;");		
		$("#validate_security_a").html("<img src='images/close_20.png' />");		
		formValid = false;		
	}	
	else{
	$("#security").attr("style", "");		
	$("#security_a").attr("style", "");	
	$("#validate_security_a").html("<img src='images/ok_20.png' />");	
	}	
			
	if (formValid == true){
		$("#validate_form_field").attr("style", "display:none;");
		$("#by_clicking").html("<cfoutput>By clicking on 'Sign up' bellow, you confirm that you accept the <a href='#myself##XFA.terms#' target='_blank'>Terms of Service.</a></cfoutput>");
		$('#submit1').attr( "disabled", false) ;		
	}
	else{
		$("#validate_form_field").attr("style", "display:block;");
		$("#validate_title").html("Please fill in the mandatory fields:");
		$("#by_clicking").html("");
		$('#submit1').attr( "disabled", true) ;

	}
}

  })
