// JavaScript Document

//Place cursor in first form field
function placecursor(){
document.appForm.First_Name.focus();
}

//Start form validation (Check for name and email)
function check_form(f) {
var checked = false; 
var buttons = f.elements.Over21; 

if(f.First_Name.value.length < 1){
alert("Error! please enter your first name field blank.");
f.First_Name.focus(); 
f.First_Name.style.background = "#e8f1fa";
return false;
}
if(f.Last_Name.value.length < 1){
alert("Error! please enter your last name.");
f.Last_Name.focus(); 
f.Last_Name.style.background = "#e8f1fa";
return false;
}
if(f.Address.value.length < 1){
alert("Error! you have left the address field blank.");
f.Address.focus(); 
f.Address.style.background = "#e8f1fa";
return false;
}
if(f.City.value.length < 1){
alert("Error! you have left the city field blank.");
f.City.focus(); 
f.City.style.background = "#e8f1fa";
return false;
}
if(f.Area_Code.value.length < 3){
alert("Please check the area code");
f.Area_Code.focus(); 
f.Area_Code.style.background = "#e8f1fa";
return false;
}
if(f.Prefix.value.length < 3){
alert("Please check the phone number prefix");
f.Prefix.focus(); 
f.Prefix.style.background = "#e8f1fa";
return false;
}
if(f.Tel_Number.value.length < 4){
alert("Please check the phone number");
f.Tel_Number.focus(); 
f.Tel_Number.style.background = "#e8f1fa";
return false;
}
if(!check_email(f.Email.value)){
alert("Invalid email detected.");
f.Email.focus(); 
f.Email.style.background = "#e8f1fa";
return false;
}
for (var i=0; i<buttons.length; i++)  
  {  
    if (buttons[i].checked) {  
      checked = true; 
      break;  
    }  
   } 
   if(!checked) 
   alert("Please indicate if you are over 21 or not");
	 return checked;
}

// Email Validation. Written by PerlScriptsJavaScripts.com

function check_email(e) {
ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

for(i=0; i < e.length ;i++){
if(ok.indexOf(e.charAt(i))<0){ 
return (false);
}	
} 
if (document.images) {
re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (!e.match(re) && e.match(re_two)) {
return (-1);		
} 
}
}

function autotab(original,destination){
if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
destination.focus()
}
