

function isCharsInBag (s, bag)
{  
    var i;
    for (i = 0; i < s.length; i++)
    {   
       
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) return false;
    }
    return true;
}	
function isEmail (s)
	{
	    var i = 1;
	    var j=0;
	    var ar=0;
	    var m=0;
	    var sLength = s.length;
	    
	    while (i < sLength)
	    {
			if (s.charAt(i) == "@")j++;			
			i++;
	    }
	    i=1;
	    while (i < sLength)
	    {
			if (s.charAt(i) == ".")ar++;			
			i++;
	    }
		m=sLength-1;
	    if (j==0) return false;
	    if (ar==0) return false;
	    if (j>1) return false;
	    if (s.charAt(1) == "@")  return false;
	    if (s.charAt(1) == ".")  return false;
	    if (s.charAt(m) == "@") return false;
	    if (s.charAt(m) == ".") return false;
	 		return true;
	 }

function trimString (str)
{
	str = this != window? this : str;
	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
function chkadd()
       {
				if(trimString(document.frmreg.enounid.value)=="")
                        {
                                alert( "Enoun id should not be blank" );
                                document.frmreg.enounid.focus();
                                  return false;
                         }
               if (!isCharsInBag(document.frmreg.enounid.value, "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" ))
		           {
			         alert("Invalid characters in\"Enoun id \" field " );
			         document.frmreg.enounid.focus();
			         return false;
                }
              if(document.frmreg.enounid.value.length>200)
                   {  
					  alert("Maximum character length should be 200  in the \"Enoun id \" field.");
					  document.frmreg.enounid.focus();
					  return false;
                    }

                if(trimString(document.frmreg.password.value)=="")
                        {
                                alert( "Password should not be blank" );
                                document.frmreg.password.focus();
                                  return false;
                         }
               if(document.frmreg.password.value.length>200)
                   {  
					  alert("Maximum character length should be 200  in the \"Password \" field.");
					  document.frmreg.password.focus();
					  return false;
                    }

         if (!isCharsInBag(document.frmreg.password.value, "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" ))
		     {
			alert("Invalid characters in\"Password \" field " );
			document.frmreg.password.focus();
			return false;
                }
         if(trimString(document.frmreg.cpassword.value)=="")
                       {
                                alert( "Confirm password should not be blank" );
                                document.frmreg.cpassword.focus();
                                  return false;
                         }
      if(document.frmreg.cpassword.value.length>200)
                   {  
					  alert("Maximum character length should be 200  in the \"Confirm password \" field.");
					  document.frmreg.cpassword.focus();
					  return false;
                    }

         if (!isCharsInBag(document.frmreg.cpassword.value, "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" ))
		     {
			alert("Invalid characters in\"Confirm password \" field " );
			document.frmreg.cpassword.focus();
			return false;
                }

                if (document.frmreg.cpassword.value!=document.frmreg.password.value)
						{
							alert("Password and Confirm password does not match");
							document.frmreg.cpassword.focus();
							return false;
						}      


				if(trimString(document.frmreg.e_mail.value)=="")
                        {
                                alert( "E-mail should not be blank" );
                                document.frmreg.e_mail.focus();
                                  return false;
                        }


					if ((document.frmreg.e_mail.value!=""))
					{
					if(document.frmreg.e_mail.value.length>50)
					{
					alert("Maximum character length should be 50 in the \"  Email Id \" field.");
					document.frmreg.e_mail.focus();
					return(false);
					}
					if ((document.frmreg.e_mail.value=="")||((isCharsInBag(document.frmreg.e_mail.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_@.0123456789"))&&(document.frmreg.e_mail.value.length>9)&&(document.frmreg.e_mail.value.length<50)&&(isEmail(document.frmreg.e_mail.value)))) advemail=0;
					else advemail=1;
					if (advemail==1) 
					{
					alert("Enter the valid Email Id.");
					document.frmreg.e_mail.focus();
					return(false);
					}

					}


               if(document.frmreg.checkbx.checked==false)
		              {
			            alert("You have to agree the terms and conditions of this site to register. ");
			            document.frmreg.checkbx.focus();
		            	return false;
		           }

                  	   return true;
     }
