<!--
	function ValidateNo( NumStr, String ) 
	{
 		for( var Idx = 0; Idx < NumStr.length; Idx ++ )
 		{
			 var Char = NumStr.charAt( Idx );
			 var Match = false;

				for( var Idx1 = 0; Idx1 < String.length; Idx1 ++) 
				{
					 if( Char == String.charAt( Idx1 ) ) 
					 Match = true;
				}

				if ( !Match ) 
					return false;
 		}
        	return true;
	}

	// email validate

	function ValidateEmail(emailStr) {
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
  	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
  	var validChars="\[^\\s" + specialChars + "\]";
  	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {

	alert( "Invalid Email " + MatriForm.EMAIL.value );
	return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
	alert("Invalid Email id");
	return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
	alert("Invalid Email id");
	return false;
	   }
	}
 
	if (user.match(userPat)==null) {
	alert("Invalid Email id");
	return false;
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {

	// this is an IP address

	for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
	alert("Invalid Email id");
	return false;
	   }
	}
	return true;
	}

	// Domain is symbolic name.  Check if it's valid.
	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
	alert("Invalid Email id");
	return false;
	   }
	}

	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */

	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
	alert("Invalid Email id");
	return false;
	}

	// Make sure there's a host name preceding the domain.

	if (len<2) {
	alert("Invalid Email id");
	return false;
	}

	// If we've gotten this far, everything's valid!
	return true;
	}

	//  End -->


	function InitArray()
	{
	  this.length = InitArray.arguments.length
        for (var i = 0; i < this.length; i++)
        this[i+1] = InitArray.arguments[i]
	  }
	// Function to validate all the inputs
	function validate(  )
	{
		var MatriForm = this.document.MatriForm;

		if ( MatriForm.NAME.value == "" || MatriForm.NAME.value == "Name")
		{
			alert( "Please Enter Name" );
			MatriForm.NAME.focus( );
			return false;}

		if ( MatriForm.AGE.value == "" || MatriForm.AGE.value == "Age")
		{
			alert( "Please Enter Age" );
			MatriForm.AGE.focus( );
			return false;
		}
		var age =parseInt( MatriForm.AGE.value );
		if ( age < 21 && MatriForm.GENDER[0].checked == true)
			{
				alert( "Invalid Age " +  MatriForm.AGE.value + ".  Minimum age allowed is 21" );
				MatriForm.AGE.focus( );
			return false;
			} 
		if ( age < 18 && MatriForm.GENDER[1].checked == true)
			{
				alert( "Invalid Age " +  MatriForm.AGE.value + ".  Minimum age allowed is 18" );
				MatriForm.AGE.focus( );
			return false;
			}
		if ( age < 18 && !(MatriForm.GENDER[1].checked == true) && !(MatriForm.GENDER[1].checked == true))
			{
				alert( "Invalid Age " +  MatriForm.AGE.value + ".  Minimum age allowed is 18" );
				MatriForm.AGE.focus( );
			return false;
			} 

		// Check Age 
		if( !ValidateNo( MatriForm.AGE.value, "0123456789" ) )
		{
			alert("Invalid Age " + MatriForm.AGE.value);
			MatriForm.AGE.focus( );
			return false;
		}
		else  
		{
			var age = parseInt( MatriForm.AGE.value );
			if ( age < 18 )
			{
				alert( "Invalid Age " +  MatriForm.AGE.value + ".  Minimum age allowed is 18" );
				MatriForm.AGE.focus( );
				return false;
			} 
			if ( age > 70 )
			{
				alert( "Invalid Age " +  MatriForm.AGE.value + ".  Maximum age allowed is 70" );
				MatriForm.AGE.focus( );
				return false;
			} 
		}
		
		if ( !MatriForm.GENDER[0].checked && !MatriForm.GENDER[1].checked)
		{
			alert( "Please select Gender" );
			MatriForm.GENDER[0].focus( );
			return false;
		}

		if ( MatriForm.GENDER[0].checked && MatriForm.AGE.value < 21)
		{
			alert( "You must be atleast 21 yrs old to register" );
			MatriForm.AGE.focus( );
			return false;
		}
		
		if ( MatriForm.RELIGION.selectedIndex == 0 )
		{
			alert( "Please select Religion" );	
			MatriForm.RELIGION.focus( );
			return false;
		}

		// Check E-mail 
		if (MatriForm.EMAIL.value == '')
		{
			alert ('Please enter Email id');
			MatriForm.EMAIL.focus();
			return false;

		}
		if (ValidateEmail(MatriForm.EMAIL.value) == false)
		{
			MatriForm.EMAIL.focus();
			return false;
		}
	}
//  -->

function chkgender(g)
{ 
if (g=="f")   { document.MatriForm.STAGE.value="18"; document.MatriForm.ENDAGE.value="30"; }
if (g=="m") {  document.MatriForm.STAGE.value="21"; document.MatriForm.ENDAGE.value="33"; }
}

function setagegroup()
{ if (document.MatriForm.GENDER[0].checked==true)
{ document.MatriForm.STAGE.value="18"; document.MatriForm.ENDAGE.value="30"; }
else
{ document.MatriForm.STAGE.value="21"; document.MatriForm.ENDAGE.value="33"; }	
}