

function loadBody()
{

if (document.cookie.indexOf("l") >= 0)
{
  var val = document.cookie.charAt(6);
  document.forms["contactForm"]["whitePapers"].selectedIndex = val;
}

}

function writeCookie(selec) 
{

document.cookie = "selec=" + selec + "; path=/";

}



function validateForm()
{

// Variables referencing the name and email input fields and their respective alert icons

var nameField = document.forms["contactForm"]["realname"];
var nameIco = document.getElementById("nameAlert");

var emailField = document.forms["contactForm"]["email"];
var emailIco = document.getElementById("emailAlert");


// Sets all fields to their default

nameField.style.backgroundColor = "#FFFFFF";
nameIco.style.visibility = "hidden";
emailField.style.backgroundColor = "#FFFFFF";
emailIco.style.visibility = "hidden";
document.getElementById("alertField").innerHTML = "";


var alertMsg = "";    // String containing the alert message to be displayed in the instance of an input error
var error = false;    // Defines whether or not an input error occurred, default false
var cursor = nameField;    // Defines where the cursor should be focused, default on nameField

var atpos = emailField.value.indexOf("@");    // Position of the 'at' symbol
var dotpos = emailField.value.lastIndexOf(".");    // Last instance of a period


if (nameField.value == "")    // If the name field is blank
{
  error = true;    // Indicates that an input error has occurred

  alertMsg += "*Please enter your full name<br>";    // Appends text to the alert message that will be displayed
 
  nameIco.style.visibility = "visible";    // Display the alert icon    *REMOVE IF UNNECESSARY*
}


if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= emailField.value.length)    // If the email address is not in the correct format
{
  if (!error)    // If the name field does not have an error
    cursor = emailField;    // Places cursor focus on emailField

  
  error = true;    // Indicates that an input error has occurred
  
  alertMsg += "*Please enter a valid email address";    // Appends text to the alert message that will be displayed
   emailIco.style.visibility = "visible";    // Display the alert icon    *REMOVE IF UNNECESSARY*
}


if (error)    // If an input error has occurred
{
  document.getElementById("alertField").innerHTML = alertMsg;    // Displays the error message above the form    *REMOVE IF UNNECESSARY*
  cursor.focus();    // Places cursor focus on the incorrect field (if both are incorrect, priority is given to the name field)    *REMOVE IF UNNECESSARY*
  return false;    // Does not allow for the submission of the form
}


// The following statement has been commented out, but allows for a simple javascript alert box displaying the message
// ***Please note: you must change '<br>' to '\n' (without quotes) in the alert text in line 35 to ensure proper display, and of course remove the if statement above

/*
if (error)
{
  alert(alertMsg);    // Displays a javascript alert specifying the input error(s)
}
*/


}

