function ValidateForm()
{
    var ret=true;
    if (requireLength('first_name', 1)==false)
        ret= false;
    if (requireLength('last_name', 1)==false)
        ret= false;

    var e = document.getElementById('email');
    if (requireLength('email', 7)==false)
        ret= false;
    if(!checkEmail(e.value))
        ret= false;    
        
   if (!ret)
   {
        document.getElementById('errMsg').style.visibility = 'visible';
        return false;
   }
}        


function isRadioChecked(buttons)
{   

    var i = 0;
    for(i=0;i<buttons.length;i++)
    {

        if (buttons[i].checked)
        {
            return true;
        }
    }
    return false;
}

function requireLength(ctlName, minLen)
{
    var e = document.getElementById(ctlName);
    return (e.value.length >= minLen);
}

function isNumbericInput(r)
{
    var valid =  r.value.length > 0
    valid = valid && (r.value.match(/^\d+$/) != null);
    return valid;
}

function show_and_return(controlName,visible)
{
    if (visible)
    {
        document.getElementById(controlName).style.display = 'block';
        document.getElementById(controlName).style.visibility = 'visible';
        return false;
    }
    else
    {
        document.getElementById(controlName).style.display = 'none';
        document.getElementById(controlName).style.visibility = 'hidden';
        return true;
    }
}

function show(controlName,visible)
{
    if (visible)
    {
        document.getElementById(controlName).style.display = 'block';
        document.getElementById(controlName).style.visibility = 'visible';
        //return false;
    }
    else
    {
        document.getElementById(controlName).style.display = 'none';
        document.getElementById(controlName).style.visibility = 'hidden';
        //return true;
    }
}

function checkEmail(who) {
	var email=/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i;
	return(email.test(who));
}

/*
function checkEmail(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}
*/

function checkDate(day,month,year){
var leap = 0;
var err = 0;
var i;
   err = 0;

   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == 01) || (month == 03) || (month == 05) || (month == 07) || (month == 08) || (month == 10) || (month == 12))) {
      err = 25;
   }
   if ((day > 30) && ((month == 04) || (month == 06) || (month == 09) || (month == 11))) {
      err = 26;
   }

   if (err == 0) {
      return true;
   }
   else {
      //alert("Date is incorrect! " + err);
      return false;
   }
}
