function validate_empty(field,alerttxt)
{
with (field)
  {
  if (value==null || value=="")
    {alert(alerttxt);
	field.style.background = 'Yellow';
	return false;}
  else {field.style.background = 'White'; return true;}
  }
}

function validate_email(field,alerttxt)
{
with (field)
  {
  apos=value.indexOf("@");
  dotpos=value.lastIndexOf(".");
  
  if (apos<1||dotpos-apos<2)
  {
    alert(alerttxt);
	field.style.background = 'Yellow';
	return false;
  }
  else{field.style.background = 'White'; return true;}
  
  }
}

//-----------------not final!!!!!
function validate_number(field,alerttxt) {
with(field)
 {
    var stripped = field.value.replace(/[\(\)\.\-\ ]/g, '');    

    if (field.value == "") {
	    alert(alerttxt);
		field.style.background = 'Yellow';
		return false;
    } else if (isNaN(stripped)) {
	    alert(alerttxt);
        field.style.background = 'Yellow';
		return false;
    } else if (!(stripped.length == 10)) {
	    alert(alerttxt);
        fld.style.background = 'Yellow';
		return false;
    } else
	{
	    field.style.background = 'White';
		return true;
	}
  }
}

function validate_reference(field)
{
with (field)
  {
  if (value==null || value=="")
    {
	return false;}
  else {return true;}
  }
}




function validate_form(thisform)
{
with (thisform)
  {
  stat=0;
  if (validate_empty(LastName,"Don't Leave Last Name Empty!")==false)
    {stat=1;}
  if (validate_empty(FirstName,"Don't Leave First Name Empty!")==false)
    {stat=1;}
  if (validate_empty(Zip,"Don't Leave Zip Empty!")==false)
    {stat=1;}
  if (validate_empty(Address,"Don't Leave Address Empty!")==false)
    {stat=1;}
  if (validate_empty(City,"Don't Leave City Empty!")==false)
    {stat=1;}
  if (validate_empty(BirthYear,"Fill Up Your Birth Year!")==false)
    {stat=1;}
 if ((BirthMonth.value == 4 || BirthMonth.value ==6 || BirthMonth.value ==9 || BirthMonth.value ==11) && BirthDay.value==31)
    {
		alert("The Month You have chosen only have 30 days!!"); stat=1;
	}
  if ((BirthMonth.value == 2 && (BirthYear.value%4) != 0) && BirthDay.value > 28)
    {
		alert("The Number of Days Is Out Of Bounds!"); stat=1;
	}
  if ((BirthMonth.value == 2 && (BirthYear.value%4) == 0) && BirthDay.value > 29)
    {
		alert("The Number of Days Is Out Of Bounds!"); stat=1;
	}
	
  if (validate_number(Phone,"Invalid Phone Number!")==false)
    {stat=1;}
  if (validate_empty(Skype,"Invalid Skype Contact!")==false)
    {stat=1;}
  if (validate_email(Email1,"Invalid Email Address!")==false)
    {stat=1;}
  if (validate_empty(YearsOfExperience,"Invalid Years Of Experience!")==false)
    {stat=1;}
  if (validate_empty(Password,"Invalid Password!")==false)
    {stat=1;}
  if (validate_empty(Password1,"Repeat Password!")==false)
    {stat=1;}
  if (Password.value!=Password1.value )
    {alert("Password Doesn't Match"); stat=1;}
  
  if(validate_reference(RefName1)==false && validate_reference(RefName2)==false && validate_reference(RefName3)==false)
    {alert("Please Put At Least 1 Reference!"); RefName4.style.background = 'White'; RefName5.style.background = 'White'; RefName6.style.background = 'White';stat=1;}
  if (validate_reference(RefName1)==true)
    {
		if (validate_email(RefName4,"Invalid Email Address For Reference 1!")==false)
		{stat=1;}
	}
  if (validate_reference(RefName2)==true)
    {
		if (validate_email(RefName5,"Invalid Email Address For Reference 2!")==false)
		{stat=1;}
	}
   if (validate_reference(RefName3)==true)
    {
		if (validate_email(RefName6,"Invalid Email Address For Reference 3!")==false)
		{stat=1;}
	}
   if (Ace1.value=='None')
    {alert("Please Choose Ace Specialty!"); stat=1;}
   if (AgreementSigned.checked == false)
    {
		alert("Please Check The Sign Agreement Box!"); stat=1;
	}
   
		
  if(stat==1)
  {
	  return false;
  }
  }
}

