 
/*Created by :Suresh Babu.
Project Name:Kobian India Support.
Name of the page:kb_editprofile.asp.
Module:For all modules. 
Description: This is the include javascript file for client validations.*/
 
 function alphabets(str,fieldname,minlen,maxlen,dots)
  {	if((minlen>0) ||str.value.length>0 )
	{
		if (str.value==null||str.value=="")
		 {
		  alert(fieldname + "  should not be null or Empty");
		  str.value="";
		  str.focus();
		  return false;     
		 }
   
		if (str.value.length<minlen || str.value.length>maxlen)
		{
			alert(fieldname+ "Length should be between " + minlen + " and " + maxlen);
			return false;
		}
		
		var flag=true;
		dotlen= dots.length;	
		for(j=0;j<dotlen;j++)		
		{
			if ((str.value.charAt(0) == dots.charAt(j)))
				flag=false;
		}			
		if(!flag)
		{
			alert("Invalid character in " + fieldname);
            str.value="";
            str.focus();
			return false;
		}	

		var i;
		for(i=0;i<str.value.length;i++)
		{
			var ch= str.value.charAt(i);
	
			if (!( (ch >= "a"&& ch <= "z") || (ch >= "A"&& ch <= "Z")))
			{	var flag=false;
				for(j=0;j<dotlen;j++)
				{
					if (ch == dots.charAt(j))
						flag=true;
				}			
				if (!flag)
				{
					alert("Invalid character in the field " + fieldname);
                    str.value="";
                    str.focus();
					return false;
				} 
			}			
		}
		}    
    return true;
	}
	
	function numbers1(str,fieldname,minlen,maxlen,dots)
	{	
		alert(fieldname + "  should not be null or Empty");   

		if((minlen>0) || str.value.length >0)
		{
            alert(fieldname + "  should not be null or Empty");   
		/*{
			alert(fieldname + "  should not be null or Empty");
			str.value.length == 0;
		        str.focus();
			return false;
		}
		if (str.value.length<minlen || str.value.length>maxlen)
		{
			alert(fieldname+ "Length should be between " + minlen + " and " + maxlen);
			str.value="";
		        str.focus();
			return false;
		}
        */
      for(i=0;i<str.value.length;i++)
		{	
       		var ch= str.value.charAt(i);
			if ((ch >= "a"&& ch <= "z") || (ch >= "A"&& ch <= "Z"))
			  {	
                alert("Please enter only numbers in " + fieldname);
                str.value="";
                str.focus();
                return false;
               } 
          }


   var flag=true;
		dotlen= dots.length;	

		for(j=0;j<dotlen;j++)
		{
			if ((str.value.charAt(0) == dots.charAt(j)))
				flag=false;
		}			
		if(!flag)
		{
			alert("Invalid First character in " + fieldname);
            		str.value="";
            		str.focus();
			return false;
		}	

		var i;
	 for ( i=0;i<str.value.length;i++)
	  {   
        
        	var ch= str.value.charAt(i);
		if (!(ch>="0" && ch<="9"))
			{	var flag=false;
				for(j=0;j<dotlen;j++)
				{
					if (ch == dots.charAt(j))
						flag=true;
				}	

      if (!flag)
				{
					alert(ch + " is not a valid char in the field " + fieldname);
                    str.value="";
                    str.focus();
					return false;
               }
			}
		}
		}
		return true;
	}

 function alphanumeric(str,fieldname,minlen,maxlen,dots)
	{	
	var flag=true;
	var i,j;
    var limit=100;
		if((minlen>0) || str.value.length>0)
		{
		if (str.value.length<=0 )
		{
			alert(fieldname + "  should not be null or Empty");
			str.focus();   
			return false;
		}
		
		if (str.value.length>maxlen)
		{
			alert(fieldname+ "length should not be greater than "+ maxlen);
			str.focus();   
			return false;
		}	
		if (str.value.length<minlen || str.value.length>maxlen)
		{
			alert(fieldname+ "Length should be between " + minlen + " and " + maxlen);
			str.value="";
			str.focus();   
			return false;
		}
       
		var flag=true;
		dotlen= dots.length;	
		for(j=0;j<dotlen;j++)
		{
			if ((str.value.charAt(0) == dots.charAt(j)))
				flag=false;
		}			
		if(!flag)
		{   
			alert("Invalid First character in " + fieldname);
            str.value="";
            str.focus();
			return false;
		}	
		for(i=0;i<str.value.length;i++)
		{
			var ch= str.value.charAt(i);
			if (!( (ch >= "a"&& ch <= "z") || (ch >= "A"&& ch <= "Z")  || (ch>="0" && ch<="9")))
			{	var flag=false;
				for(j=0;j<dotlen;j++)
				{
					if (ch == dots.charAt(j))
						flag=true;
				}			
				if (!flag)
				{
					alert("Invalid character in the field " + fieldname);
                    str.value="";
                    str.focus();
					return false;
				}				
			}			
		}
		}  
		return true;
	}



<!-- Function emailValidate() for checking email and username -->
function emailValidate(str)
{

	var flag=true;
/*	if(str.value=="" || str == null || str.length==0)
	{
		alert("Enter your Email for Username");
        str.focus();
		return false;
	}
	else
	{
 */
	   	flag = false;
		if(str.value.charAt(0) ==" " || str.value.charAt(0)=="_"|| str.value.charAt(0)=="-")
    	{
		alert("First character should not be a blank or - in Email");
        str.value="";
        str.focus();
		return false;
	    }
		else
        {
			if(str != "")
        	{     
				var len = str.value.length;
                var i;
                for(i=0;i<=len;i++)
                {
                	if(str.value.substring(i,i+1)==" ")
                    {
                    	alert("Blank space not allowed in Email");
                        str.value="";
                        str.focus();
						return false;
                    }
                }
                var a1 = str.value.indexOf("@",0);
			    var a2 = str.value.indexOf(".",0);
				if(a1==-1 || a1==0)
				{
					//alert("@ cannot be first character or u may have missed an @.");
					alert("enter your email id(you might have missed @ or dot).");
                    str.value="";
                    str.focus();
					return false;
                } 
				if(a1==a1 && a2==a1+1)
				{
					alert("dot cannot be after @");
                    str.value="";
                    str.focus();
					return false;
				}	
				 
				if(a1==str.value.length-1)
				{
					alert("@ cannot be last character");
                    str.value="";
                    str.focus();
					return false;
				}
				if(a2==-1 || a2==0)
				{
					alert("Dot (.) cannot be first character or u may have missed it");
                     str.value="";
                     str.focus(); 
					return false;
				}
				if(a2 == len-1)
				{
					alert(" Last Character should not be a Dot");
                     str.value="";
                     str.focus();
					return false;
				}
				if(a1 == len-1)
				{
					alert(" Last Character should not be a @");
                    str.value="";
                    str.focus();
					return false;
				}
				var ats=0;
				for(i=0;i<=len;i++)
                {       
                	var ch = str.value.substring(i,i+1);
					if(ch=="@")
					ats++;
					if(ats>1)
					{
						alert("More than one @ not allowed in Email");
                        str.value="";
                        str.focus();
						return false;
					}					
                    if(ch=="!"||ch=="#"||ch=="$"||ch=="%"||ch=="^"||ch=="&"||ch=="*"|| ch=="'" ||ch=='"' ||
 					ch=="("||ch==")"||ch=="+"||ch=="="||ch=="|" || ch== ">" ||ch=="<"||ch=="?"||ch=="/"
					||ch==":"||ch==";"||ch=="["||ch=="]"||ch=="{"||ch=="}"||ch=="\\"||ch==",")
					{
				 		alert("Invalid Character in your Email id " );
                        str.value="";
                        str.focus();
						return false;
					}
				}
			}		
		}
//	} 
	return true;
}



function isDateValid(dd,mm,yy,ddd)
{	
	var flag=true;
	
	if(dd.selectedIndex==0)
    {
    	alert("Please Select the date .");               
        flag= false;
    }
	if(flag &&(mm.selectedIndex==0))
    {
    	alert("Please select the month.");               
        flag= false;
    }
	if(flag&&(yy.selectedIndex==0))
    {
    	alert("Please select the year.");               
        flag= false;
    }
	
	var dd1=parseInt(dd.selectedIndex );
	var mm1=parseInt(mm.value );
	var yy1=parseInt(yy.value);
	
	if(flag&&((dd1 > 30)&&((mm1 =="Apr")||(mm1=="Jun")||(mm1=="Sep")||(mm1=="Nov"))))
    {
		alert("This month can't have more than 30 days.");		                 
		flag= false;
    }
    else
	{
		if(flag&&((dd1>=30)&&(mm1=="Feb")&& (yy1%4==0)))
        {
			alert("February have only 29 days.");
            flag= false;
        }
        else
		{
			if (flag&&((dd1>=29)&&(mm1=="Feb")&& (yy1%4!=0)) )
			{
				alert("February have only 28 days.");
                flag= false;
             }		
		}
	}
		
		return(flag);
}



  
  
  
  function isListSelected(str,fieldname)
{
	var flag=true;
	if(str.selectedIndex==0)
    {
    	alert("Please Select any "+fieldname); 
     
        flag= false;
    }
	return flag;  
}


	
	function isEmpty(str,fieldname,minlength,maxlength)
	{
		/*var flag=(str.value != "")?true:false;
		if(flag==false)
		{
			alert(fieldname+ " Should Not Be Empty");
			str.focus();
			return flag;
		}*/
		if(str.value.length>maxlength)
		{
			alert(fieldname+ " Should Not Be Morethan  "+ maxlength +" characters");
			str.focus();
			return false;
		}
		if(str.value.length<minlength)
		{
			alert(fieldname+ " Should Not Be Empty");
			//alert(fieldname+ " Should Not Be Lessthan  "+ minlength +" characters");
			str.focus();
			return false;
		}
   return true;
	}



function isEmpty1(str,fieldname,minlength,maxlength)
	{
		/*var flag=(str.value != "")?true:false;
		if(flag==false)
		{
			alert(fieldname+ " Should Not Be Empty");
			str.focus();
			return flag;
		}*/
		if(str.value.length>maxlength)
		{
			alert(fieldname+ " Should Not Be Morethan  "+ maxlength +" characters");
			str.focus();
			return false;
		}
		if(str.value.length<minlength)
		{
			alert(fieldname+ " Should Not Be Empty");
			//alert(fieldname+ " Should Not Be Lessthan  "+ minlength +" characters");
			str.focus();
			return false;
		}


if((minlen>0) || str.value.length>0)
		{
               
		if (str.value.length<=0 )
		{
			alert(fieldname + "  should not be null or Empty");
			str.value="";
		        str.focus();
			return false;
		}
		if (str.value.length<minlen || str.value.length>maxlen)
		{
			alert(fieldname+ "Length should be between " + minlen + " and " + maxlen);
			str.value="";
		        str.focus();
			return false;
		}
        
      for(i=0;i<str.value.length;i++)
		{	
       		var ch= str.value.charAt(i);
			if ((ch >= "a"&& ch <= "z") || (ch >= "A"&& ch <= "Z"))
			  {	
                alert("Please enter only numbers in " + fieldname);
                str.value="";
                str.focus();
                return false;
               } 
          }


   var flag=true;
		dotlen= dots.length;	

		for(j=0;j<dotlen;j++)
		{
			if ((str.value.charAt(0) == dots.charAt(j)))
				flag=false;
		}			
		if(!flag)
		{
			alert("Invalid First character in " + fieldname);
            		str.value="";
            		str.focus();
			return false;
		}	

		var i;
	 for ( i=0;i<str.value.length;i++)
	  {   
        
        	var ch= str.value.charAt(i);
		if (!(ch>="0" && ch<="9"))
			{	var flag=false;
				for(j=0;j<dotlen;j++)
				{
					if (ch == dots.charAt(j))
						flag=true;
				}	

      if (!flag)
				{
					alert(ch + " is not a valid char in the field " + fieldname);
                    str.value="";
                    str.focus();
					return false;
               }
			}
		}
		}




   return true;
	}







	function emptyAlso(str,fieldname,maxlength)
	{
	if(str.value.length>maxlength)
		{
			alert(fieldname+ " Should Not Be Morethan  "+ maxlength +" characters");
			str.focus();
			return false;
		}
	 	 return true;
	}			
	   	

