
//FORM ON ADMIN LOGIN PAGE



function chooseuser(form) { //This is the name of the function

if (form.thisusername.value == "") { //This checks to make sure the field is not empty
   alert("Please Select a Name to Log-in."); //Informs user of empty field
   form.thisusername.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
   if (form.thispassword.value == "") { //This checks to make sure the field is not empty
   alert("Please type in your password to Log-in."); //Informs user of empty field
   form.thispassword.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
// you may copy the above 5 lines for each form field you wish to validate
// Replace the text "FIELD1" with the name you wish to call the field
}


function backButtonOverride()
{
  // Work around a Safari bug
  // that sometimes produces a blank page
  setTimeout("backButtonOverrideBody()", 1);

}

function backButtonOverrideBody()
{
  // Works if we backed up to get here
  try {
    history.forward();
  } catch (e) {
    // OK to ignore
  }
  // Every quarter-second, try again. The only
  // guaranteed method for Opera, Firefox,
  // and Safari, which don't always call
  // onLoad but *do* resume any timers when
  // returning to a page
  setTimeout("backButtonOverrideBody()", 500);
}

function adduser(form) { //This is the name of the function
   if (form.thispassword.value == "") { //This checks to make sure the field is not empty
   alert("Password cannot be blank or contain spaces."); //Informs user of empty field
   form.thispassword.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
    if (form.thisuser.value == "") { //This checks to make sure the field is not empty
   alert("Name cannot be blank."); //Informs user of empty field
   form.thisuser.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
    if (form.thisuseraddress.value == "") { //This checks to make sure the field is not empty
   alert("Address Cannot be Blank."); //Informs user of empty field
   form.thisuseraddress.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
     if (form.thisusertel.value == "") { //This checks to make sure the field is not empty
   alert("Telephone Cannot be Blank or contain spaces."); //Informs user of empty field
   form.thisusertel.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
     if (form.thisuserstartdate.value == "") { //This checks to make sure the field is not empty
   alert("Date Started Cannot be Blank."); //Informs user of empty field
   form.thisuserstartdate.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
       
// you may copy the above 5 lines for each form field you wish to validate
// Replace the text "FIELD1" with the name you wish to call the field
}

function addtown(form) { //This is the name of the function
   if (form.townname.value == "") { //This checks to make sure the field is not empty
   alert("Town name cannot be blank."); //Informs user of empty field
   form.townname.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
    if (form.telephone.value == "") { //This checks to make sure the field is not empty
   alert("Telephone cannot be blank."); //Informs user of empty field
   form.telephone.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
    if (form.businessaddress.value == "") { //This checks to make sure the field is not empty
   alert("Business Address Cannot be Blank."); //Informs user of empty field
   form.businessaddress.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
     if (form.businesshours.value == "") { //This checks to make sure the field is not empty
   alert("Business Hours Cannot be Blank."); //Informs user of empty field
   form.businesshours.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
     if (form.contactname.value == "") { //This checks to make sure the field is not empty
   alert("Contact Name Cannot be Blank."); //Informs user of empty field
   form.contactname.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
     if (form.contacttelephone.value == "") { //This checks to make sure the field is not empty
   alert("Contact Telephone Cannot be Blank."); //Informs user of empty field
   form.contacttelephone.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
     if (form.startdate.value == "") { //This checks to make sure the field is not empty
   alert("Start Date Cannot be Blank."); //Informs user of empty field
   form.startdate.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
     if (form.shortid.value == "") { //This checks to make sure the field is not empty
   alert("Short ID Cannot be Blank."); //Informs user of empty field
   form.shortid.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
     if (form.townconnname.value == "") { //This checks to make sure the field is not empty
   alert("Town Database name Cannot be Blank or contain spaces."); //Informs user of empty field
   form.townconnname.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
   
       
// you may copy the above 5 lines for each form field you wish to validate
// Replace the text "FIELD1" with the name you wish to call the field
}

function checktel(form) { //This is the name of the function

if (form.telephone.value == "") { //This checks to make sure the field is not empty
   alert("Please Insert a Telephone Number to search."); //Informs user of empty field
   form.telephone.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
// you may copy the above 5 lines for each form field you wish to validate
// Replace the text "FIELD1" with the name you wish to call the field
}
function checkid(form) { //This is the name of the function
   if (form.cusid.value == "") { //This checks to make sure the field is not empty
   alert("Please Insert an ID."); //Informs user of empty field
   form.cusid.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
   // you may copy the above 5 lines for each form field you wish to validate
// Replace the text "FIELD1" with the name you wish to call the field
}
function checkname(form) { //This is the name of the function
   if (form.thisname.value == "") { //This checks to make sure the field is not empty
   alert("Please Insert a Name to Search."); //Informs user of empty field
   form.thisname.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }

// you may copy the above 5 lines for each form field you wish to validate
// Replace the text "FIELD1" with the name you wish to call the field
}
function checkaddress(form) { //This is the name of the function
   if (form.thisaddress.value == "") { //This checks to make sure the field is not empty
   alert("Please Insert an Address to Search."); //Informs user of empty field
   form.thisaddress.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
   if (form.townid.value == "") { //This checks to make sure the field is not empty
   alert("Please select a town to Search."); //Informs user of empty field
   form.townid.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }

// you may copy the above 5 lines for each form field you wish to validate
// Replace the text "FIELD1" with the name you wish to call the field
}
function checkbusiness(form) { //This is the name of the function
   if (form.busid.value == "") { //This checks to make sure the field is not empty
   alert("Please Choose a Business."); //Informs user of empty field
   form.busid.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }

// you may copy the above 5 lines for each form field you wish to validate
// Replace the text "FIELD1" with the name you wish to call the field
}

function checkout(form) { //This is the name of the function
   if (form.driverid.value == "") { //This checks to make sure the field is not empty
   alert("Please Select a Delivery Driver."); //Informs user of empty field
   form.driverid.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }

// you may copy the above 5 lines for each form field you wish to validate
// Replace the text "FIELD1" with the name you wish to call the field
}
function addwebaccount(form) { //This is the name of the function
   if (form.thisusername.value == "") { //This checks to make sure the field is not empty
   alert("Username Cannot be blank."); //Informs user of empty field
   form.thisusername.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }

  if (form.thispassword.value == "") { //This checks to make sure the field is not empty
   alert("Password Cannot be blank."); //Informs user of empty field
   form.thispassword.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
   if (form.thisemail.value == "") { //This checks to make sure the field is not empty
   alert("Email Address Cannot be blank."); //Informs user of empty field
   form.thisemail.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }

      
// you may copy the above 5 lines for each form field you wish to validate
// Replace the text "FIELD1" with the name you wish to call the field
}


function checkproduct(form) { //This is the name of the function
   if (form.thisitem.value == "") { //This checks to make sure the field is not empty
   alert("Product Name Cannot be blank."); //Informs user of empty field
   form.thisitem.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }

  if (form.prodprice.value == "") { //This checks to make sure the field is not empty
   alert("Product Price Cannot be blank."); //Informs user of empty field
   form.prodprice.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
   if (form.thisemail.value == "") { //This checks to make sure the field is not empty
   alert("Email Address Cannot be blank."); //Informs user of empty field
   form.thisemail.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }

      
// you may copy the above 5 lines for each form field you wish to validate
// Replace the text "FIELD1" with the name you wish to call the field
}



function registerbusiness(form) { //This is the name of the function
   if (form.businessname.value == "") { //This checks to make sure the field is not empty
   alert("Business Name Cannot be blank."); //Informs user of empty field
   form.businessname.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }

  if (form.businessaddress.value == "") { //This checks to make sure the field is not empty
   alert("Business Address Cannot be blank."); //Informs user of empty field
   form.businessaddress.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
   if (form.businesstype.value == "") { //This checks to make sure the field is not empty
   alert("Business Type Cannot be blank."); //Informs user of empty field
   form.businesstype.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
   if (form.businesstel.value == "") { //This checks to make sure the field is not empty
   alert("Business Telephone Cannot be blank."); //Informs user of empty field
   form.businesstel.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
   if (form.thisemailaddress.value == "") { //This checks to make sure the field is not empty
   alert("Business Email Address Cannot be blank."); //Informs user of empty field
   form.thisemailaddress.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }

      
// you may copy the above 5 lines for each form field you wish to validate
// Replace the text "FIELD1" with the name you wish to call the field
}

function quickview(form) { //This is the name of the function
   if (form.townid.value == "") { //This checks to make sure the field is not empty
   alert("Please Select a Town."); //Informs user of empty field
   form.townid.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }

// you may copy the above 5 lines for each form field you wish to validate
// Replace the text "FIELD1" with the name you wish to call the field
}


function confirmasap(form) { //This is the name of the function

if (form.orderaddress.value == "") { //This checks to make sure the field is not empty
   alert("Your Delivery Address CANNOT be blank."); //Informs user of empty field
   form.orderaddress.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
   if (form.daydate.value == "") { //This checks to make sure the field is not empty
   alert("Please choose a Day Date you want your delivery."); //Informs user of empty field
   form.daydate.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
   if (form.monthdate.value == "") { //This checks to make sure the field is not empty
   alert("Please choose a Month Date you want your delivery."); //Informs user of empty field
   form.monthdate.focus( ); //This focuses the cursor on the empty field
   return false; //This prevents the form from being submitted
   }
// you may copy the above 5 lines for each form field you wish to validate
// Replace the text "FIELD1" with the name you wish to call the field
}

function checkEmail(emField){ //reference to email field passed as argument

var fieldValue = emField.value // store field's entire value in variable

// Begin Valid Email Address Tests

//if field is not empty
if(fieldValue != ""){ 
var atSymbol = 0

//loop through field value string
for(var a = 0; a < fieldValue.length; a++){ 

//look for @ symbol and for each @ found, increment atSymbol variable by 1
if(fieldValue.charAt(a) == "@"){ 
atSymbol++
}

}

// if more than 1 @ symbol exists
if(atSymbol > 1){ 
// then cancel and don't submit form
alert("Please Enter A Valid Email Address") 
return false
}

// if 1 @ symbol was found, and it is not the 1st character in string
if(atSymbol == 1 && fieldValue.charAt(0) != "@"){ 
//look for period at 2nd character after @ symbol 
var period = fieldValue.indexOf(".",fieldValue.indexOf("@")+2) 

// "." immediately following 1st "." ? 
var twoPeriods = (fieldValue.charAt((period+1)) == ".") ? true : false 

//if period was not found OR 2 periods together OR field contains less than 5 characters OR period is in last position
if(period == -1 || twoPeriods || fieldValue.length < period + 2 || fieldValue.charAt(fieldValue.length-1)=="."){
// then cancel and don't submit form
alert("Please Enter A Valid Email Address") 
return false
}

}
// no @ symbol exists or it is in position 0 (the first character of the field)
else{ 
// then cancel and don't submit form
alert("Please Enter A Valid Email Address")
return false 
}
}
// if field is empty
else{ 
// then cancel and don't submit form
alert("Please Enter A Valid Email Address")
return false 
}

//all tests passed, submit form
alert("VALID EMAIL ADDRESS!")
return true
}


function validateEmpty(fld) {
    var error = "";
  
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        error = "The required field has not been filled in.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;   
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
} 

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

 function maxLength(field,maxChars)
 {
       if(field.value.length >= maxChars) {
          event.returnValue=false;
          return false;
       }
 }  

 function maxLengthPaste(field,maxChars)
 {
       event.returnValue=false;
       if((field.value.length +  window.clipboardData.getData("Text").length) > maxChars) {
         return false;
       }
       event.returnValue=true;
 }

