// function for accepting numbers only
function IntValidate()
{
	if(((window.event.keyCode < 48) || (window.event.keyCode > 57)) && (window.event.keyCode != 46))
		window.event.returnValue=0
}

// function for accepting numbers, alphabets but not special characters
function userValidate()
{
	if( ((window.event.keyCode <48)||(window.event.keyCode >57))  && ((window.event.keyCode <65) || (window.event.keyCode >91)) &((window.event.keyCode <97) || (window.event.keyCode > 122)) )
		window.event.returnValue=0
}

// function for accepting numbers, small alphabets but not special characters
function pwdValidate()
{
	if( ((window.event.keyCode <48) || (window.event.keyCode >57)) && ((window.event.keyCode <97) ||(window.event.keyCode >122)) )
		window.event.returnValue=0
}

// function for not accepting space character
function mailValidate()
{
  if(window.event.keyCode <=32)
	window.event.returnValue=0
}

/* Function for email address validation 
function isEmail(string) 
{
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) != -1)
        return true;
    else
        return false;
}
*/

// function for verification of checked radio button
function checkradio(rname) 
{
	var j;
	for(j=0; j<document.regfrm.elements.length;j++) 
	{
		var e;
		e=document.regfrm.elements[j];
		if (e.type=='radio')
		{
			e.checked = (e.name==rname) ? true:false;
		}
	}
}	

// function for validating DOB
function checkDOB()
{   
    var eMonth
    var eDay
    var eYear
    var curDate;
    var curYear;
    var diffYear;
    
    eMonth = document.regfrm.month1.options[document.regfrm.month1.selectedIndex].value; 
    eDay = document.regfrm.day1.options[document.regfrm.day1.selectedIndex].value; 
    eYear = document.regfrm.year1.options[document.regfrm.year1.selectedIndex].value;

   	curDate=new Date();
	curYear=curDate.getYear();
	
	diffYear=curYear-eYear;
	
	if(diffYear<18)
	{
		alert("Invalid date. Below 18 years old are not eligile for registration.");
		return false;
	}	
    
	if ((eMonth==4 || eMonth==6 || eMonth==9 || eMonth==11) && eDay==31)
    {
        alert("Month "+eMonth+" doesn't have 31 days!");
        document.regfrm.month1.options[document.regfrm.month1.selectedIndex].focus();
        return false;
    }
    
    if (eMonth == 2)  // check for february 29th
    {    
        var isleap1 = (eYear % 4 == 0 && (eYear % 100 != 0 || eYear % 400 == 0));
        if (eDay>29 || (eDay==29 && !isleap1))
        {
            alert("February " + eYear + " doesn't have " + eDay + " days as it is a leap year!");
            document.regfrm.day1.options[document.regfrm.day1.selectedIndex].focus();
            return false;
        }
    }
    return true;  // date is valid
}

// function for verifying the fields are entered properly or not
  function fun()
  {
    if (!checkDOB()) return false;
    //checkDOB();
  	var i
	var msg;
    var uname;
   
	msg="Please Enter:\n";
	if ((document.regfrm.emailid.name="emailid") && (document.regfrm.emailid.value!="")) 
	{
		if ((document.regfrm.emailid.value.indexOf("@")<=0)  || (document.regfrm.emailid.value.lastIndexOf(".")<=0))
		{
		    alert("Please Enter a valid Email address.");
			myErrors="true";
			document.regfrm.emailid.focus();
	        return false;
		}
	}
   
  	for(i=0;i<document.regfrm.elements.length;i++)
	{
		var e;
        e=document.regfrm.elements[i];
	
		//alert(e.name + "type=" + e.type);	
		if (e.type=="text")
		{
			 var v=e.value;
			 if (v=="")
				{
					if ((e.title != "FAX") && (e.title != "Work Phone") && (e.title !="Cell Phone"))
			             msg += e.title + " \n";  	
				}
		 } //if type
	
	} // for 
	
	if (msg!="Please Enter:\n")
	{
		alert(msg);
		return false;
	}
	if(document.regfrm.month1.options[document.regfrm.month1.selectedIndex].value=="MM")
    {
        alert("Please select the proper DOB-Month");
        document.regfrm.month1.options[document.regfrm.month1.selectedIndex].focus();
        return false;
    } 
    if(document.regfrm.day1.options[document.regfrm.day1.selectedIndex].value=="DD")
    {
        alert("Please select the proper DOB-Day");
        document.regfrm.day1.options[document.regfrm.day1.selectedIndex].focus();
        return false;
    } 
    if(document.regfrm.year1.options[document.regfrm.year1.selectedIndex].value=="YYYY")
    {
        alert("Please select the proper DOB-Year");
        document.regfrm.year1.options[document.regfrm.year1.selectedIndex].focus();
        return false;
    } 
    //code for converting the string to lower case leletters 	   
    if( (document.regfrm.username.name="username")&& (document.regfrm.username.value != "") )
    { 
       document.regfrm.username.focus();
       document.regfrm.username.value=(document.regfrm.username.value).toLowerCase();
    }
   
    if(document.regfrm.username.value.length<4)
    {
      alert("The username should not be less than 4 characters.Please Enter a valid User name");  
      document.regfrm.username.focus();
      return false;
   }     
  
   if(document.regfrm.password1.value.length<4)	
   {
      alert("The password should not be less than 4 characters.Please Enter a valid Password");           
	  document.regfrm.password1.focus();
      return false;
   }
   
   if(document.regfrm.hintquestion.options[document.regfrm.hintquestion.selectedIndex].value=="Hint Question")
   {
     alert("Please select the proper hint question");
     document.regfrm.hintquestion.options[document.regfrm.hintquestion.selectedIndex].focus();
     return false;
   } 
   //upto here the new code

	if (document.regfrm.password1.value!= document.regfrm.password2.value) 
	{
		alert("Please retype the password correctly.");
		document.regfrm.password2.focus();
		return false;
	} 
	return tccheck();	
 
} // end of function 

