	var whspace = " \t\n\r";

        function emailCheck(txt) 
        {
                //should not be empty
                if(!txt.length)
		   return true;

                //first character should not be @ and .        
		if(txt.indexOf("@") == -1 || txt.indexOf(".") == -1)
			return true;

                if(txt.charAt(txt.length - 1) == ".")
                        return true;

		if(txt.lastIndexOf("_") > txt.indexOf("@"))
			return true;
		
		if(txt.indexOf("@") - txt.lastIndexOf("_")==1 || txt.indexOf(".") - txt.indexOf("@")==1)
			return true;
				
                if(txt.indexOf(" ") != -1 )
                        return true;

                iFirst = txt.indexOf("@");
                iNext = txt.lastIndexOf("@");
                if(iFirst != iNext)
                        return true;

                if(isNotAlphabets( txt , "1234567890abcdefghijklmnopqrstuvwxyz._@" ))
                        return true;
                if (txt.indexOf("@")<2) 
                    return true;
             
        }

        function dateValidator(fYear , fMonth , fDate)
        {
		mm=new Date().getMonth()+1;
		if(navigator.appName=="Netscape")
		yy=new Date().getYear()+1900;
		else
			yy=new Date().getYear();
		dd=new Date().getDate();

                yearCheck = (fYear%4 == 0) && ( fYear % 100 != 0 || fYear % 400 == 0);
                if(fYear==yy && fMonth>mm)
			return err_mess();
		
		if((fYear==yy && fMonth>=mm) && (fDate>dd))
			return err_mess();	

		if(((fMonth=="January") || (fMonth=="March") || (fMonth=="May") || (fMonth=="July") || (fMonth=="August") || (fMonth=="October") || (fMonth=="December")) && (fDate > 31))
			return err_mess();

		if(((fMonth=="April") || (fMonth=="June") || (fMonth=="September") || (fMonth=="November")) && (fDate > 30))
			return err_mess();

		if(((fMonth=="February") && fDate > 28) || ((fMonth=="February") && yearCheck && (fDate >29)))
			return err_mess();

        }

        function err_mess()
        {
            alert("Invalid Date");
            return true;
        }

        function removeWhitespace (s)
	{
		var i;
		var finalstr="";
		// Search through string's characters one by one
 	   	// until we find a whitespace character.
 	   	// When we do,elements the whitespace and  return  the string ; if we don't, return string.
 	   	for (i = 0; i < s.length; i++)
 	   	{   
			
 	       		// Check that current character isn't whitespace.
			//remove the whitespace and append the valid characters only
 	       		var c = s.charAt(i);
			if (!(whspace.indexOf(c) == 0  || whspace.indexOf(c) == 1 || whspace.indexOf(c) == 3 )) 
			{
				finalstr+=s.charAt(i);
			}
	   	}
		// No characters are whitespace.
		return finalstr;
 	}

        function  isNotAlphabets(str,alpha)
	{
		str=removeWhitespace(str);
		var i;
		//checking for Alphabets characters
		if(str.length==0 || str==null)
		{
			return true;
		}
	    	// Search through string's characters one by one.
	    	// If character is aplhabets
	    	for (i = 0; i < str.length; i++)
   		{   
        		// Check that current character isn't whitespace.
        		var c = str.charAt(i);
       			if (alpha.indexOf(c) == -1) return true;
    		}
    		return false;
  	}

        function isAnyChecked(formName)
        {
            for(i=0 ; i < document.formName.elements.length ; i++)
            {
                if(document.formName.elements[i].type == "checkbox")
                {
                    alert(document.formName.elements[i].value);
                    if(document.formName.elements[i].checked == true)
                    {
                        return true;
                    }
                    else
                        continue;
                }
            }
            return false;
        }
