//-----------------------------------------------------------------------------------------------
function removeLeadingSpaces(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1)
    {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)  j++;
      s = s.substring(j, i);
    }
   return s;
}
//-----------------------------------------------------------------------------------------------
function removeTrailingSpaces(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
   {
      var i = s.length - 1;       // Get length of string
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) i--;

      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}
//-----------------------------------------------------------------------------------------------
function removeAllSpaces(str)
{  
   if(str != "")
     str = removeLeadingSpaces(str); //Remove Leading Spaces
   if(str != "")	 
     str = removeTrailingSpaces(str); //Remove Trailing Spaces
   return str;
}
//-----------------------------------------------------------------------------------------------
function checkEmail(email) 
{
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
    return (true);
  else return (false);
}
//-----------------------------------------------------------------------------------------------
function validate()
{  
  if(removeAllSpaces(document.photo_submit.name.value) == "")
  {
	alert("Please enter your NAME");
	document.photo_submit.name.focus();
	return false;
  }	
  
  if(removeAllSpaces(document.photo_submit.email.value)=="")
  {
	alert("Please enter your E-mail Address");
	document.photo_submit.email.focus();
	return false;
  }
  else
  {
	var em = document.photo_submit.email.value;		
    if (!checkEmail(document.photo_submit.email.value))
	{
	  alert("Invalid E-mail Address! Please re-enter.");
	  document.photo_submit.email.focus();
	  return false;
	}
  }
  
  if(removeAllSpaces(document.photo_submit.photo.value) == "")
  {
	alert("Please enter your File name.");
	document.photo_submit.photo.focus();
	return false;
  }
  
  return true;
}
