/****************************************
* Copyright 2006 Ex-designz.net & Myasp-net.com
* JavaScript written by: Dexter Zafra
****************************************/

//--------------------------------------------------------//
// Multiple Functions to handle element OnFocus event
function UnameFocus() 
 {
   document.getElementById('username').style.backgroundColor = '#FFF9EC'; //Make the textbox color lightyellow
   document.getElementById('lbluname').style.color = '#000000'; //Make the label text color black
   document.getElementById('lbluname').innerHTML = 'Username:'; //On error raised textbox focus, assign label default text 
   document.getElementById('check').style.display='block';
}
function PassWordFocus() 
 {
   document.getElementById('password').style.backgroundColor = '#FFF9EC'; 
   document.getElementById('lblpass').style.color = '#000000';
   document.getElementById('lblpass').innerHTML = 'Password:';
}
function RetypePassFocus() 
 {
   document.getElementById('password').style.backgroundColor = '#FFF9EC'; 
   document.getElementById('lblretype').style.color = '#000000';
   document.getElementById('lblretype').innerHTML = 'Re-Type Pass:';
   document.getElementById('lblpass').style.color = '#000000';
   document.getElementById('lblpass').innerHTML = 'Password:';
}

function UemailFocus() 
 {
   document.getElementById('email').style.backgroundColor='#FFF9EC';
   document.getElementById('ulemail').style.color = '#000000';
   document.getElementById('ulemail').innerHTML = 'Email:';
}

//--------------------------------------------------------//

//--------------------------------------------------------//
// Handle User Registration Form Validation
function RegValidate(RegForm) 
 {
// Declare Variables - get the textbox value and assign it into the variable
 var Uname = RegForm.elements['username'].value; 
 var Pass = RegForm.elements['password'].value;
 var RepeatPass = RegForm.elements['repass'].value;
// If the first five required fields are empty, then do the textbox color magic
if (Uname == "" && Pass == "" && RepeatPass =="")
  {
     // Change the background color of the textbox,border as well as label text
     document.getElementById('username').style.backgroundColor='#FFF4F4'; 
     document.getElementById('username').style.border = '1px solid #CC0000';
     document.getElementById('lbluname').style.color = '#CC0000';
     document.getElementById('lbluname').innerHTML = 'Empty Field:';
     document.getElementById('password').style.backgroundColor='#FFF4F4'; 
     document.getElementById('password').style.border = '1px solid #CC0000';
     document.getElementById('lblpass').style.color = '#CC0000';
     document.getElementById('lblpass').innerHTML = 'Empty Field:';
     document.getElementById('repass').style.backgroundColor='#FFF4F4';
     document.getElementById('repass').style.border = '1px solid #CC0000'; 
     document.getElementById('lblretype').style.color = '#CC0000';
     document.getElementById('lblretype').innerHTML = 'Empty Field:';
     alert("Please fill in the empty fields.\n- Username\n- Password\n- Password 2");
     return false;
}
// Check Username
 if (Uname == "") // if is empty/blank alert
  {
     alert("You must enter a username");
     document.getElementById('username').style.backgroundColor='#FFF4F4'; //Change the background color of the textbox
     document.getElementById('username').style.border = '1px solid #CC0000';
     document.getElementById('lbluname').style.color = '#CC0000';
     document.getElementById('lbluname').innerHTML = 'Empty Field:';
     return false;
  }
else if (Uname.length < 4) // Check char count, if it is less than 4 alert
 {
     alert ("The username is too short.\n Please enter a username from 4 to 12 characters.");
     document.getElementById('username').style.backgroundColor='#FFF4F4';
     document.getElementById('username').style.border = '1px solid #CC0000';
     document.getElementById('lbluname').style.color = '#CC0000';
     document.getElementById('lbluname').innerHTML = 'Too Short:';
     return false;
}
else if (Uname.length > 12) // Check char count, if it is greater than 12 alert
 {
     alert ("The username is too long.\n Please enter a username from 6 to 12 characters.");
     document.getElementById('username').style.backgroundColor='#FFF4F4';
     document.getElementById('username').style.border = '1px solid #CC0000';
     document.getElementById('lbluname').style.color = '#CC0000';
     document.getElementById('lbluname').innerHTML = 'Too Long:';
     return false;
}
//Check for illegal characters in username - On this field we only allow letters, numbers, and underscores
var illegalCharsUname = /\W/; 
if (illegalCharsUname.test(Uname)) // test the illegalCharsUname variable against Uname variable, it it ecounter invalid char, then alert
  {
     alert ("The username contains illegal characters.\n Please try again.");
     document.getElementById('username').style.backgroundColor='#FFF4F4';
     document.getElementById('username').style.border = '1px solid #CC0000';
     document.getElementById('lbluname').style.color = '#CC0000';
     document.getElementById('lbluname').innerHTML = 'Illegal Char:';
     return false;
} 
// Password
 if (Pass == "")
  {
     alert("You must enter a password");   
     document.getElementById('password').style.backgroundColor='#FFF4F4'; 
     document.getElementById('password').style.border = '1px solid #CC0000';
     document.getElementById('lblpass').style.color = '#CC0000';
     document.getElementById('lblpass').innerHTML = 'Empty Field:';
     return false;
  }
else if (Pass.length < 4)
 {
     alert ("The password is too short.\n Please enter a password from 4 to 10 characters.");
     document.getElementById('password').style.backgroundColor='#FFF4F4';
     document.getElementById('password').style.border = '1px solid #CC0000';
     document.getElementById('lblpass').style.color = '#CC0000';
     document.getElementById('lblpass').innerHTML = 'Too Short:';
     return false;
}
else if (Pass.length > 10)
 {
     alert ("The password is too long.\n Please enter a password from 6 to 10 characters.");
     document.getElementById('password').style.backgroundColor='#FFF4F4';
     RegForm.elements['password'].style.border = '1px solid #CC0000';
     document.getElementById('lblpass').style.color = '#CC0000';
     document.getElementById('lblpass').innerHTML = 'Too Long:';
     return false;
}
//Check for illegal characters in password - allow only letters and numbers
var illegalCharsPass =/[\W_]/; 
if (illegalCharsPass.test(Pass)) 
  {
     alert ("The password contains illegal characters.\n Please try again.");
     document.getElementById('password').style.backgroundColor='#FFF4F4';
     document.getElementById('password').style.border = '1px solid #CC0000';
     document.getElementById('lblpass').style.color = '#CC0000';
     document.getElementById('lblpass').innerHTML = 'Illegal Char:';
     return false;
} 
// Repeat Password
 if (RepeatPass == "")
  {
     alert("Please repeat the password");   
     document.getElementById('repass').style.backgroundColor='#FFF4F4';
     document.getElementById('repass').style.border = '1px solid #CC0000'; 
     document.getElementById('lblretype').style.color = '#CC0000';
     document.getElementById('lblretype').innerHTML = 'Empty:';
     return false;
 }
 if (RepeatPass != Pass)
  {
     alert("Password did not match.\n Please try again");   
     document.getElementById('repass').style.backgroundColor='#FFF4F4';
     document.getElementById('repass').style.border = '1px solid #CC0000'; 
     document.getElementById('password').style.border = '1px solid #CC0000';
     document.getElementById('password').style.backgroundColor='#FFF4F4';
     document.getElementById('lblpass').style.color = '#CC0000';
     document.getElementById('lblpass').innerHTML = 'Did not Match:';
     document.getElementById('lblretype').style.color = '#CC0000';
     document.getElementById('lblretype').innerHTML = 'Did not Match:';
     return false;
 }

// country
 var CheckCountry = RegForm.elements['country'].value;
 if (CheckCountry == "")
  {
     alert("You must enter a country");
     return false;
  }

 // Email
var UserEMail = RegForm.elements['email'].value;
 if (UserEMail == "")
  {
     alert("You must enter an email address");
     document.getElementById('email').style.backgroundColor='#FFF4F4'; 
     document.getElementById('email').style.border = '1px solid #CC0000';
     document.getElementById('ulemail').style.color = '#CC0000';
     document.getElementById('ulemail').innerHTML = 'Empty Field:';
     return false;
  }
else if (!(UserEMail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1))
 {
     alert("E-mail address is not valid.\n Please enter a valid email address.");
     document.getElementById('email').style.backgroundColor='#FFF4F4'; 
     document.getElementById('email').style.border = '1px solid #CC0000';
     document.getElementById('ulemail').style.color = '#CC0000';
     document.getElementById('ulemail').innerHTML = 'Invalid Email:';
    return false ;
}
return true;
}
//--------------------------------------------------------//

//--------------------------------------------------------//

