/**
 * Functions for the individual ad view
 */

function toggle(fld) {
   var st = document.getElementById(fld);
   if (st.style.display=='none') {
      st.style.display='block';
   }
   else {
      st.style.display='none';
   }
}

/**
 * Open up the form
 */
function showForm(fld) {
   var st = document.getElementById(fld);
   st.style.display='block';
}

/**
 * Validate form fields for contacting seller
 */
function validateContactSeller(theForm) {
   var message = "";

   if (theForm.your_name.value.length==0)
      message += "- Your name is missing\n";

   if (!/^.+@.+\.\w{2,4}$/.test(""+theForm.your_email.value))
      message += "- Your email address is missing or mistyped\n";

   if (theForm.message.value.length < 5)
      message += "- You must type a message to the advertiser\n";

   if (theForm.security_code.value.length!=5)
      message += "- Please verify that you are human by filling in the letters in the image\n";

   if (message != "") {
      alert("Please correct the following errors:\n\n" + message);
      return false;
   }

   return true;
}

/**
 * Validate the tell a friend form
 */
function validateEmailFriend(theForm) {
   var message = "";

   if (theForm.your_name.value.length==0)
      message += "- Your name is missing\n";

   if (!/^.+@.+\.\w{2,4}$/.test(""+theForm.your_email.value))
      message += "- Your email address is missing or mistyped\n";

   if (theForm.friends_name.value.length==0)
      message += "- Your friends name is missing\n";

   if (!/^.+@.+\.\w{2,4}$/.test(""+theForm.friends_email.value))
      message += "- Your friends email address is missing or mistyped\n";

   if (theForm.security_code.value.length!=5)
      message += "- Please verify that you are human by filling in the letters in the image\n";

   if (message != "") {
      alert("Please correct the following errors:\n\n" + message);
      return false;
   }

   return true;
}
