function writeCookie()
{
 var today = new Date();
 var the_date = new Date("December 31, 2023");
 var the_cookie_date = the_date.toGMTString();
 var the_cookie = "users_resolution="+ screen.width +"x"+ screen.height;
 var the_cookie = the_cookie + ";expires=" + the_cookie_date;
 document.cookie=the_cookie; 
}


function isValidPhoneNumber(theField)
{
     var checkOK = "0123456789";
     var checkStr = theField.value;
     var allValid = true;
     var digitsonly = "";

// Create a string with digits only
   for (i = 0;  i < checkStr.length + 1; i++)
       {
         var ch = checkStr.substring(i,i+1);
          for (j = 0;  j < checkOK.length;  j++)
           if (ch == checkOK.charAt(j))
              {
               digitsonly = digitsonly + ch;
               break;
              }
		if (checkStr.length == i)
        {
          break;
        }
       }

// if the length of digits only is not 10 then it is not a valid phone number
   if(digitsonly.length != 10)
      allValid = false;

// if valid then format the phone number for display
   if(allValid)
     {
      var formattedPh = "("
                + digitsonly.substring(0,3)
                + ") "
                + digitsonly.substring(3,6)
                + "-"
                + digitsonly.substring(6,10);
                theField.value = formattedPh;
     }
// in not valid alert the user
   if(allValid==false)
     {
	  if(digitsonly.length > 0)
		{
		 alert("Please enter a valid phone number. Example:(###) ###-####");
		 theField.focus();
		}
     }	
}



function checkform() {
  for (i=0;i<fieldstocheck.length;i++) {
    if (eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].type") == "checkbox") {
      if (document.subscribeform.elements[fieldstocheck[i]].checked) {
      } else {
        alert("Please enter your "+fieldnames[i]);
        eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].focus()");
        return false;
      }
    }
    else {
      if (eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].value") == "") {
        alert("Please enter your "+fieldnames[i]);
        eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].focus()");
        return false;
      }
    }
  }
  for (i=0;i<groupstocheck.length;i++) {
    if (!checkGroup(groupstocheck[i],groupnames[i])) {
      return false;
    }
  }
  
  if(! compareEmail())
  {
    alert("The Email Addresses you entered do not match");
    return false;
  }
  return true;
}

var fieldstocheck = new Array();
var fieldnames = new Array();
function addFieldToCheck(value,name) {
  fieldstocheck[fieldstocheck.length] = value;
  fieldnames[fieldnames.length] = name;
}
var groupstocheck = new Array();
var groupnames = new Array();
function addGroupToCheck(value,name) {
  groupstocheck[groupstocheck.length] = value;
  groupnames[groupnames.length] = name;
}

function compareEmail()
{
  return (document.subscribeform.elements["email"].value == document.subscribeform.elements["emailconfirm"].value);
}
function checkGroup(name,value) {
  option = -1;
  for (i=0;i<document.subscribeform.elements[name].length;i++) {
    if (document.subscribeform.elements[name][i].checked) {
      option = i;
    }
  }
  if (option == -1) {
    alert ("Please enter your "+value);
    return false;
  }
  return true;
}


