/* Trim Function */
function trim(value)
 {
  temp=value;
  return temp.replace(/^\s*(\b.*\b|)\s*$/, "$1");
 }

/* Input Emphasis Function */
function input_emphasis(cell)
 {
  emphasis="document.all."+cell+".style.backgroundColor='#ffffff'";
  eval(emphasis);
  return true;
 }

/* Cell Emphasis Function */
function cell_emphasis(question, field, number_of_fields)
  {
   for (i=0; i<number_of_fields; i++)
	{
	 if (field==i)
	  {
	   emphasis="document.all."+question+"_"+i+".style.backgroundColor='#ff0000'";
	   eval(emphasis);
	  }
	 else
	  {
	   emphasis="document.all."+question+"_"+i+".style.backgroundColor='#ffffcc'";
	   eval(emphasis);
	  }
	}
  }

/* Checkbox Emphasis Function */
function checkbox_emphasis(cell)
 {
  cell_="document.all."+cell+".checked";
  if (eval(cell_ ))
     {
      emphasis="document.all."+cell+".style.backgroundColor='#ff0000'";
      eval(emphasis);
     }
  else
    {
     emphasis="document.all."+cell+".style.backgroundColor='#ffffcc'";
     eval(emphasis);
    }
 }
 
/* validContactForm Function */
function validContactForm(passForm)
 {
  // Beginning of Regular Expressions Creating
  regular_phones=/^([0-9\-\+]{9,})$/;
  regular_email_address=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  // End of Regular Expressions Creating

  /*
  // Beginning of Full Name Checking
  temp=trim(passForm.full_name.value);
  passForm.full_name.value=temp;
  if (temp=="")
     {
      alert("Please write your full name.");
      passForm.full_name.focus();
      return false;
     }
  // End of Full Name Checking

  // Beginning of Phone Number Checking
  temp=trim(passForm.phone_number.value);
  passForm.phone_number.value=temp;
  if (!(regular_phones.test(temp)))
     {
      alert("Please write your phone number using digits, separating lines, + or - only.");
      passForm.phone_number.focus();
      return false;
     }
  // End of Phone Number Checking

  // Beginning of E-mail Address Checking
  temp=trim(passForm.email_address.value);
  passForm.email_address.value=temp;
  if (temp!="")
     {
      if (!(regular_email_address.test(temp)))
	  {
          alert("Please write your E-mail address in a valid pattern.");
          passForm.email_address.focus();
          return false;
	  }
     }
  // End of E-mail Address Checking

  // Beginning of Message Subject Checking
  temp=trim(passForm.message_subject.value);
  passForm.message_subject.value=temp;
  if (temp=="")
     {
      alert("Please write the subject of the message.");
      passForm.message_subject.focus();
      return false;
     }
  // End of Message Subject Checking
  */

  // Beginning of Message Content Checking
  temp=trim(passForm.message_content.value);
  passForm.message_content.value=temp;
  if (temp=="")
     {
      alert("Please write the content of the message.");
      passForm.message_content.focus();
      return false;
     }
  // End of Message Content Checking
  return true;
 }

 /* validUpdatesForm Function */
function validUpdatesForm(passForm)
 {
  // Beginning of Regular Expressions Creating
  regular_phones=/^([0-9\-\+]{9,})$/;
  regular_email_address=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  // End of Regular Expressions Creating

  // Beginning of Update Title Checking
  temp=trim(passForm.update_title.value);
  passForm.update_title.value=temp;
  if (temp=="")
     {
      alert("Please write the title of the update.");
      passForm.update_title.focus();
      return false;
     }
  // End of Update Title Checking

  // Beginning of Update Content Checking
  temp=trim(passForm.update_content.value);
  passForm.update_content.value=temp;
  if (temp=="")
     {
      alert("Please write the content of the update.");
      passForm.update_content.focus();
      return false;
     }
  // End of Update Content Checking

  // Beginning of Update Language Checking
  o1=passForm.update_language_0.checked;
  o2=passForm.update_language_1.checked;

  if ((!(o1)) && (!(o2)))
     {
      alert("Please choose the language of the update.");
      return false;
     }
  // End of Update Language Checking

  // Beginning of Update Status Checking
  o1=passForm.update_status_0.checked;
  o2=passForm.update_status_1.checked;

  if ((!(o1)) && (!(o2)))
     {
      alert("Please choose the status of the update.");
      return false;
     }
  // End of Update Status Checking
   
  // Beginning of Update Image Checking
  temp=trim(passForm.update_image.value);
  passForm.update_image.value=temp;

  if (passForm.page_type.value!="modification")
     {
      if (temp=="")
	  {
	   alert("Please choose a file to upload as the update's image.");
	   passForm.update_image.focus();
	   return false;
	  }
     }

  if (temp!="")
     {
      temp=temp.substring((temp.length-3),(temp.length));
      temp=temp.toLowerCase();
      if ((temp!="jpg") && (temp!="jpeg") && (temp!="gif") && (temp!="png"))
	  {
	   alert("The file you have chosen as the update's image must be in one of the following formats: JPG, JPEG, GIF or PNG.");
	   passForm.update_image.focus();
	   return false;
	  }
     }
  // End of Update Image Checking
  return true;
 }