// form validation
	function submenu(param)
	{
	window.location = param;
	}
	
	function checkIsEmpty(value)
	{
	return isEmpty(trim(value));
	}



function IsEmpty(v)
{
  if( v.length > 0 )
       return false;
  return true;
}


function IsCorrectName(o,msg)
{
var val = o.value;
val = val.replace(/^\s+|\s+$/g,"");
if(  val.length != 0 )
  {
   val= val.match(/[^A-Za-z\s]+/g);
     if(val == null)
	 {return true;}

  }
    alert(msg);
    o.focus();
  return false;
}

function IsCorrectInfo(o,msg)
{
var val = o.value;
val = val.replace(/^\s+|\s+$/g,"");
if(  val.length != 0 )
  {
   val= val.match(/[^A-Za-z]+/g);
     if(val == null)
	 {return true;}

  }
    alert(msg);
    o.focus();
  return false;
}

function SetFocusIsEmpty(o,msg)
{
		// if object's value is empty
		// set input focus to that object
		// and return false
		//
		var val = o.value;
		val = val.replace(/^\s+|\s+$/g,"");
		if(  val.length == 0 )
		  {
			alert(msg);
			o.focus();
			return false;
		  }
		return true;
}

function IsValidZip(z,notValidMsg)
{
var val = z.value;
var r;
	try{
		val = val.replace(/^\s+|\s+$/g,"");
		if(  val.length <= 5 )  
		    r = val.match(/\d{5}/);
		else
		    r = val.match(/\d{5}-\d{4}/);

		if( r == null ) // did not find valid ZIP
		  {
			alert(notValidMsg);
			z.focus();
		    return false;
		  }
	}
	catch(exception)
	{
	  alert(exception.description);
	}
return true;  
}

function IsValidPhone(ph,notValidMsg)
{
var val = ph.value;
var r;
	try{
		val = val.replace(/^\s+|\s+$/g,"");
		// the format is 999-999-9999
		r = val.match(/\d{3}-\d{3}-\d{4}/);

		if( r == null ) // did not find valid phone
		  {
			alert(notValidMsg);
			ph.focus();
		    return false;
		  }
	}
	catch(exception)
	{
	  alert(exception.description);
	}
return true;  
}



function IsValidEmail(o,notValidMsg)
{
  var e;
    try{
    e = o.value;
	if (e.length > 0)
	  {  if(  e.indexOf("@")==-1 
	         || e.indexOf(".")==-1 
	         || e.indexOf(" ")!=-1 
	         || e.length<6)
	     {
			alert(notValidMsg);
			o.focus();
	       return false;
	     }
	     return true;
	  }
	  }
	  catch(exception)
	  {
	    alert("IsValidEmail" + exception.description );
	  }
	alert(notValidMsg);
	o.focus();
	return false;
}



function isLeapYear(yy)
{
//If the year is divisible by 100, it's not a leap year UNLESS it is also divisible by 400. 

  if( yy % 4 != 0 )
  {
       return false;
  }
  if( yy % 100 == 0 )
  {
     if( yy	 % 400 != 0 )
	 {
	     return false;
		 }
  }		 
  return true;		   
}

function IsDateValid(d,notValidMsg)
{
var val = d.value;
var r;
var mm;
var dd;
var yy;
var dd_limit;
	try{
		val = val.replace(/^\s+|\s+$/g,"");
		if(  val.length <= 8 )  
		    r = val.match(/(\d{2})\/(\d{2})\/(\d{2})/);
		else
		    r = val.match(/(\d{2})\/(\d{2})\/(\d{4})/);

		if( r == null ) // did not find valid ZIP
		  {
			alert(notValidMsg);
			d.focus();
		    return false;
		  }
		  mm = new Number(r[1]);
		  dd = new Number(r[2]);
		  yy = new Number(r[3]);
		 // alert("month->"+mm);
		 // alert("day->"+dd);
		//  alert("year->"+yy);
		  if( yy < 10 )
		      yy +=2000;
		   if( yy < 2005 )
		   {
		     alert("Wrong year" + yy );
			 return false;
		   }	  
		   if( mm > 12  || mm <= 0)
		   {
		     alert("Wrong month " + mm );
			 return false;
		   }
		   dd_limit = 0;
		   if( mm == 1  ||  mm == 3 ||  mm == 5 ||  mm == 7 ||  mm == 8 ||  mm == 10 ||  mm == 12 )
		   {
			      dd_limit = 31;
		   }
		   if( mm == 4  ||  mm == 6 ||  mm == 9 ||  mm == 11  )
		   {
			      dd_limit = 30;
		   }
		   if( mm == 2  )
		   {
			      if( isLeapYear(yy) == true )
				    {
			          dd_limit = 29;
					}
				  else
				    {
			          dd_limit = 28;
					}
		   }
		  // alert("dd_limit ->"+ dd_limit);
			      if( dd > dd_limit || dd <= 0 )
				     {
		               alert("Wrong day " + dd );
					   return false;
					 }
		   
	}
	catch(exception)
	{
	  alert(exception.description);
	}
return true;  
}

function IsValidNumber(n,notValidMsg)
{
var val = n.value;
var r;
	try{
		val = val.replace(/^\s+|\s+$/g,"");
		if(  val.length < 2 )  
	        r = val.match(/\d{1}/);
		else
		    r = val.match(/\d{2}/);
		if( r == null ) // did not find valid num
		  {
			alert(notValidMsg);
			n.focus();
		    return false;
		  }
	}
	catch(exception)
	{
	  alert(exception.description);
	}
return true;  
}
