function validateSubmission(){
    if (document.getElementById('textfield').value == ''){
        alert('Please enter your first and last name.');
        return false;
      }
      
      if (document.getElementById('textfield3').value == ''){
         alert('Please enter your phone number.');
         return false;
      }  
      
      if (!validatePhone('textfield3')){      
          alert('Please provide a valid phone number.');
          return false;
      }
      
      if (document.getElementById('textfield4').value == ''){
         alert('Please enter your email address.');
         return false;
      }      
      
      if (!validateEmail(document.getElementById('textfield4').value)){
         alert('Please provide a vaild email address.');
         return false;
      }
      
      if (document.getElementById('textarea2').value == ''){
         alert('Please enter a comment.');
         return false;
      }
      
      return true;
}

function validateEmail(email){
	email = String( email );
	var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
	var regex = new RegExp( emailReg );
	return regex.test( email );
}

function validatePhone(fldName) {
  var okay=1;
  var theNewVal="(";
  var theFldVal=document.all[fldName].value;
  var theVal="";
  for (i=0; i<theFldVal.length; i++) {
     theChar=theFldVal.charAt(i);
     if (!isNaN(theChar)&&theChar!=" ") theVal+=theChar;
  }
  if (theVal.length<10||theVal.length>14) okay=0;
  if (okay) {
     for (var i=0; i<theVal.length; i++) {
	    theNewVal+=theVal.charAt(i);
	    if (i==2) theNewVal+=") ";
	    else if (i==5) theNewVal+="-";
	    else if (i==9&&theVal.length>10) theNewVal+=" ext ";
     }
     document.all[fldName].value=theNewVal;
  }

  return okay;
}



function showErr(){
	document.getElementById('errMessage').style.display = ( window.location.search.indexOf( "err=" ) > -1 ? "block" : "none" );
}

function postLogin(){

	var usr = document.getElementById('textfield').value;
	var pwd = document.getElementById('textfield2').value;
	var chk = document.getElementById('checkbox');

	if( usr.toLowerCase() == "rfs" && pwd.toLowerCase() == "rfs" ){
	     if( chk.checked ){
	    	document.cookie = 'user=rfs; expires=Thu, 5 Jan 2012 20:47:11 UTC; path=/';
	     }else{
		document.cookie = 'user=rfs';
	     }
	    location.href = '/current/index.shtml';
	}else{
	    location.href = 'login.shtml?err=authentication_failed';	
	}


	return false;

}