var submitted2 = "first";
function Form1_Validator(theForm, reset, submitted)
{
if (submitted == "reset"){
submitted2 = "first";
submitted = "";
document.all.error.innerHTML = "";
document.getElementById('firstname').style.backgroundColor="#FFFFFF";
document.getElementById('lastname').style.backgroundColor="#FFFFFF";
document.getElementById('username').style.backgroundColor="#FFFFFF";
document.getElementById('password').style.backgroundColor="#FFFFFF";
document.getElementById('confirm').style.backgroundColor="#FFFFFF";
document.getElementById('email').style.backgroundColor="#FFFFFF";
document.all.error.innerHTML = "";
return (false);
}
if (submitted2 != "first" && submitted == "box"){
submitted = "submitted";
submitted2 = "";
}
if (submitted2 == "first" && submitted == "box"){
submitted = "";
}
else if (submitted2 == "first"){
submitted2 = "";
//submitted = "";
}
if (submitted == "submitted"){
if (reset == '1'){
var error = false;
document.all.error.innerHTML = "";
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  	if (theForm.firstname.value == "")
  {
   	document.all.error.innerHTML += "*Firstname field can not be empty.<br>";
	document.getElementById('firstname').style.backgroundColor="#FCDFFF";
    theForm.firstname.focus();
    error = true;
  }
    else if (isNaN(theForm.firstname.value))
  {
    document.getElementById('firstname').style.backgroundColor="#FFFFFF";
  }
	if(!isNaN(theForm.firstname.value) && theForm.firstname.value != "")
  {
	document.all.error.innerHTML += "*Only letters for the Firstname field.<br>";
	document.getElementById('firstname').style.backgroundColor="#FCDFFF";	
    theForm.firstname.focus();	
    error = true;    
        if(isNaN(theForm.firstname.value))
  	  {
    	document.getElementById('firstname').style.backgroundColor="#FFFFFF";
  	  }
  }
//////////////////////////////////////////////////
  	if (theForm.lastname.value == "")
  {
   	document.all.error.innerHTML += "*Lastname field can not be empty.<br>";
	document.getElementById('lastname').style.backgroundColor="#FCDFFF";
    theForm.lastname.focus();
    error = true;
  }
    else if (isNaN(theForm.lastname.value))
  {
    document.getElementById('lastname').style.backgroundColor="#FFFFFF";
  }
  	if(!isNaN(theForm.lastname.value) && theForm.lastname.value != "")
  {
	document.all.error.innerHTML += "*Only letters for the Lastname field.<br>";
	document.getElementById('lastname').style.backgroundColor="#FCDFFF";	
    theForm.lastname.focus();	
    error = true;    
        if(isNaN(theForm.lastname.value))
  	  {
    	document.getElementById('lastname').style.backgroundColor="#FFFFFF";
  	  }  
  }
	if (theForm.username.value == "")
  {
   	document.all.error.innerHTML += "*Username field can not be empty<br>";	
   	document.getElementById('username').style.backgroundColor="#FCDFFF";	
    theForm.firstname.focus();
    error = true;    
  }
    else
  {
    document.getElementById('username').style.backgroundColor="#FFFFFF";
  }
	if (theForm.email.value == "")
  {
    document.all.error.innerHTML += "*Email field can not be empty<br>";	
    document.getElementById('email').style.backgroundColor="#FCDFFF";	
    theForm.email.focus();
    error = true;    
  }
    else if (!filter.test(theForm.email.value)) 
  {
    document.all.error.innerHTML += "*Invalid Email Address<br>";
    document.getElementById('email').style.backgroundColor="#FCDFFF";	    	
	theForm.email.focus();
	error = true;
  }	
    else
  {
    document.getElementById('email').style.backgroundColor="#FFFFFF";
  }  
  	if (theForm.password.value == "")
  {
    document.all.error.innerHTML += "*Password field can not empty.<br>";	
    document.getElementById('password').style.backgroundColor="#FCDFFF";	
    theForm.email.focus();
	error = true;
  }
    else
  {
    document.getElementById('password').style.backgroundColor="#FFFFFF";
    document.getElementById('confirm').style.backgroundColor="#FFFFFF";
  }  
  if (theForm.password.value.length < 5 || theForm.password.value.length > 10)
  {
    var wronglen = false;
	document.all.error.innerHTML += "*5 to 10 characters for Password.<br>";
	document.getElementById('password').style.backgroundColor="#FCDFFF";
	document.getElementById('confirm').style.backgroundColor="#FCDFFF";	
    error = true;	
		if (theForm.password.value != "" && theForm.password.length < 5 || theForm.password.length > 10)
	  {
	    document.getElementById('password').style.backgroundColor="#FFFFFF";
	    document.getElementById('confirm').style.backgroundColor="#FFFFFF";
	  }
  }
	if (theForm.password.value != theForm.confirm.value || wronglen)
  {
	document.all.error.innerHTML += "*Wrong confirmation password.<br>";
	document.getElementById('password').style.backgroundColor="#FCDFFF";
	document.getElementById('confirm').style.backgroundColor="#FCDFFF";	
	theForm.confirm.focus();
    error = true;
		if (theForm.password.value != "" && theForm.password.value == theForm.confirm.value)
	  {
	    document.getElementById('password').style.backgroundColor="#FFFFFF";
	    document.getElementById('confirm').style.backgroundColor="#FFFFFF";
	  }  

  }
  	if (error)
  {
  	return (false);
  }
  }
  else{
  document.getElementById('firstname').style.backgroundColor="#FFFFFF";
  document.getElementById('lastname').style.backgroundColor="#FFFFFF";
  document.getElementById('username').style.backgroundColor="#FFFFFF";
  document.getElementById('password').style.backgroundColor="#FFFFFF";
  document.getElementById('confirm').style.backgroundColor="#FFFFFF";
  document.getElementById('email').style.backgroundColor="#FFFFFF";
  document.all.error.innerHTML = "";
  }
  }
  else{
    return (false);
  }
}

