function its_empty(string_value) {

  // Check for the empty string and null
  if (string_value == "" || string_value == null) {
  
    // If either, it's empty so return true
    return true
  }
  
  // Otherwise, it's not empty so return false
  return false
}

function validateEmail(string_value)
{ 
  var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
  return emailPattern.test(string_value); 
} 

function checkForm(f)
{	
	var mandatory
	for (var counter = 0; counter < f.length; counter++)
  {
    mandatory=f[counter].getAttribute('mandatory');
    valid_email=f[counter].getAttribute('valid_email');
    //alert("valid_email="+valid_email);
	  if(mandatory)
	    {
	     if(!f[counter].disabled //not disabled
	     &&(f[counter].type=="hidden"||f[counter].offsetWidth>0) //not a display:none element
	     &&!its_empty(mandatory)
	     ) 
	      {
	      	if(f[counter].type=="text"&&its_empty(f[counter].value))
		      {
		       	alert(mandatory);
		        f[counter].focus();
		        return false;
		      }
		      
	      	if(f[counter].type=="textarea"&&its_empty(f[counter].value))
		      {
		       	alert(mandatory);
		        f[counter].focus();
		        return false;
		      }
	      	if(f[counter].type == "select-one"
	      	   &&f[counter][f[counter].selectedIndex].value=="") 
		      {
		       	alert(mandatory);
		        f[counter].focus();
		        return false;
		      }
        
		      else if(f[counter].type=="hidden"&&its_empty(f[counter].value))
		      {
		        alert(mandatory);
		        return false;
		      }
	      }
	  }
  if(mandatory
	     &&!f[counter].disabled //not disabled
	     &&(f[counter].type=="hidden"||f[counter].offsetWidth>0) //not a display:none element // TR: who keeps disabling this?!
	     &&(!its_empty(valid_email)&&!validateEmail(f[counter].value))
	     )
  {
    alert(valid_email);
		return false;  
  }	     
  }
	return true;
}

