// ********************************************************
// ************ Toggle Foreground/Background **************
// ********************************************************
function toggleIt(element,act) {
   if (act == "on") {
      element.style.background='#65945A';
      element.style.color='#ffffff'; }
   else {
      element.style.background='';
      element.style.color='#006633';
   }
}

// ********************************************************
// *************** Link to Requested Page *****************
// ********************************************************
function clickIt(item) {
   if ( item == "home") {
      window.location.href='index.html'; }
   else if ( item == "services") {
      window.location.href='services.html'; }
   else if ( item == "plans") {
      window.location.href='plans.html'; }
   else if ( item == "estimates") {
      window.location.href='estimates.html'; }
   else if ( item == "rewards") {
      window.location.href='rewards.html'; }
   else if ( item == "newsletter") {
      window.location.href='newsletter.html'; }
   else if ( item == "contact") {
      window.location.href='contact.html'; }
}

// ********************************************************
// ************ Trim Leading/Trailing Spaces **************
// ********************************************************
function TrimSpaces(EnteredStr) {
// this will get rid of leading spaces
   while (EnteredStr.substring(0,1) == ' ')
      EnteredStr = EnteredStr.substring(1, EnteredStr.length);
// this will get rid of trailing spaces
   while (EnteredStr.substring(EnteredStr.length-1, EnteredStr.length) == ' ')
      EnteredStr = EnteredStr.substring(0, EnteredStr.length-1);
   return EnteredStr;
}
// ********************************************************
// ************ Check for valid email address *************
// ********************************************************
function CheckEmail(EnteredStr){
     var str=EnteredStr;
//   var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
     var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
     var ValidEmail = true;

   if (filter.test(str))
      ValidEmail = true;
   else
      ValidEmail = false;

   return (ValidEmail);
}

function FormValidation() {
// *** Trim leading and trailing spaces
   document.frmCriteria.name.value = TrimSpaces(document.frmCriteria.name.value);
   document.frmCriteria.email.value = TrimSpaces(document.frmCriteria.email.value);

   if (document.frmCriteria.name.value == "") {
      alert("A name is required.");
      document.frmCriteria.name.focus();
      return; }
   else if (document.frmCriteria.email.value == "") {
      alert("An email address is required.");
      document.frmCriteria.email.focus();
      return; }
   
   ValidEmail = CheckEmail(document.frmCriteria.email.value); 
   if (!ValidEmail) {               
      alert("An unrecognized email address format was entered.");  
      document.frmCriteria.email.focus();
      return; }
      
   document.frmSubmit.name.value = document.frmCriteria.name.value;
   document.frmSubmit.email.value = document.frmCriteria.email.value;
   document.frmCriteria.name.value = "";
   document.frmCriteria.email.value = "";
   popWin();
   document.frmSubmit.submit();
}

// ********************************************************
// ************* Pop New Window w/ Attributes *************
// ********************************************************
function popWin() {
   var pURL='email.asp';
   var pTitle='Results';
   var pInfo='toolbar=0,';
       pInfo+='location=0,';
       pInfo+='directories=0,';
       pInfo+='status=0,';
       pInfo+='menubar=0,';
       pInfo+='scrollbars=0,';
       pInfo+='resizable=1,';
       pInfo+='width=400,';
       pInfo+='height=225,';
       pInfo+='top=0';

   if (screen) {
      if (screen.width < 400)
         pInfo+=',left=0';
      else
         pInfo+=',left=' + ((screen.width/2)-200);
   }
   window.open(pURL,pTitle,pInfo);
}

