/*
* Author:mz
* Date:  9/29/07
* Desc:  Used on the start page, validates that a valid email was entered before
*        allowing the user to proceed.
*/
function fValidateEmailBeforeStarting()
{
   var enteredEmail = document.forms['frmStart'].txtEmail.value;

   if(isValidEmail(enteredEmail) == true)
   {
      document.forms['frmStart'].submit();
   }
   else
   {
      document.getElementById('emailRequiredMsg').style.visibility='visible';
   }
}

/*
* Author:mz
* Date:  9/29/07
* Desc:  Used on the guidelines page, validates that the user agreed to
*        the guidelines (via checkbox) before allowing the user to proceed.
*/
function fValidateGuidelineAgreement()
{
   if(document.forms['frmAgree'].chkAgreedToTerms.checked == true)
   {
      document.forms['frmAgree'].submit();
   }
   else
   {
      document.getElementById('agreeErrorMsg').style.visibility='visible';
   }
}


/*
* Author:mz
* Date:  9/29/07
* Desc:  Displays a popup window
*/
function fPopup(pURL)
{   
   window.open(pURL, "newWwindow","location=1,toolbar=1,menubar=1,status=1,scrollbars=1,width=810,height=450,resizable=1");   
}

/*
* Author:mz
* Date:  10/8/07
* Desc:  Validates that all fields were filled in on the tell a friend 
*        form.  If not, a msg is displayed to the user, else the form
*        is submitted.
*/
function fValidateTellAFriend()
{
   var form = document.forms['frmTellAFriend'];
   var errorDivId = 'msg';
   var topPlacedSuccessMsgID = 'topPlacedSuccessMsg';
   var senderName = form.txtName.value;

   if(senderName == '')
   {
      fHideDiv(topPlacedSuccessMsgID);
      fShowErrorDiv(errorDivId, 'Sorry, Your Name is a required field.');
      return false;
   }

   var senderEmail = form.txtEmail.value;
   if(senderEmail == '')
   {
      fHideDiv(topPlacedSuccessMsgID);
      fShowErrorDiv(errorDivId, 'Sorry, Your email is a required field.');
      return false;
   }
   else if(isValidEmail(senderEmail) == false)
   {
      fHideDiv(topPlacedSuccessMsgID);
      fShowErrorDiv(errorDivId, 'Sorry, you must enter a valid email address before proceeding.');      
      return false;
   }

   var recipientEmail = form.txtRecipientEmail.value;
   if(recipientEmail == '')
   {
      fHideDiv(topPlacedSuccessMsgID);
      fShowErrorDiv(errorDivId, 'Sorry, Recipient email is a required field.');
      return false;
   }
   else if(isValidEmail(recipientEmail) == false)
   {
      fHideDiv(topPlacedSuccessMsgID);
      fShowErrorDiv(errorDivId, 'Sorry, you must enter a valid recipient email address before proceeding.');      
      return false;
   }
   return true;
}

/*
* Author:mz
* Date:  10/3/07
* Desc:  Id's a div and sets it's innerHTML to the msg specified
*/
function fShowErrorDiv(pDivId, pErrorText)
{
   document.getElementById(pDivId).innerHTML=pErrorText;
   document.getElementById(pDivId).className='small-red-text';
}

/********************
* utility functions *
*********************/
/*
* Author:kp
* Date:  ???
* Desc:  accepts a string and validates for proper email format.  - mz
*/
function isValidEmail(emailStr)
{
	var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
	
	if (re.test(emailStr))
   {
		return true;
	}
   else
   {
      return false;
   }
}

/*
* Author:mz
* Date:  10/5/07
* Desc:  ids a div and shows it by enabling it's visibility attribute.
*/
function fShowDiv(pDivId)
{
   document.getElementById(pDivId).style.visibility='visible';
}

/*
* Author:mz
* Date:  10/5/07
* Desc:  ids a div and hides it by emptying it's visibility attribute.
*/
function fHideDiv(pDivId)
{
   document.getElementById(pDivId).style.visibility='hidden';
}
