
//file developed by imtiyaz on date 09/04/07

//function used for checkin the empty string
function str_empty(str,name)
{
		if(str.length==0)
		{
			alert(name +" is empty ");
			return false;
		}
		return true;
}

//function  used for checking the min length of string 
function str_min(str,minlength,name)
{
		if(minlength!=0&&str.length<minlength)
		{
			alert("Please enter minimum length of "+minlength +" characters for "+name);
			return false;
		}
		return true;
}

//function used for checking maximum length for string
function str_max(str,maxlength,name)
{
		if(maxlength!=0&&str.length>maxlength)
		{
			alert("Please enter maximum length of "+maxlength +" characters for "+name);
			return false;
		}
		return true;
}

//function for cheking is number or not
function str_is_num(str,name)
{

					var i;
					var flg=0;
					var flg1=0;
					for (i = 0; i < str.length; i++)
					{   
						// Check that current character is number.
						var c = str.charAt(i);
if(c=='.')
{
	flg=flg+1;
}
if(flg>=1)
{
	flg1++;
}
					if (((c < "0") || (c > "9")) )
						{
							if(flg>1)
							{
						alert("Please enter numarical value for "+name);
						 return false;
							}
						 }
						 if(flg1>4)
						 {
							alert("Please do not enter more than 2 decimal number after decimal point for "+name);
							 return false;

						 }
					}
					// All characters are numbers.
					return true;

}
//function for checkin is sting is contains only characters
function str_is_char(str,name)
{
					var i;
					for (i = 0; i < str.length; i++)
					{   
						// Check that current character is number.
						var c = str.charAt(i);
						
						if (((c < "A") || (c > "z"))&& c!=" ")
						{
						alert("Please enter alphabet value for "+name);
						 return false;
						 }
					}
					// All characters are numbers.
					return true;
}

//function to check string not containing the spacese
function str_space(str,name)
{

				var i;
					for (i = 0; i < str.length; i++)
					{   
						// Check that current character is number.
						var c = str.charAt(i);
						
						if (((c == " ") ))
						{
						alert("Please don't enter space for "+name);
						 return false;
						 }
					}
					// All characters are numbers.
					return true;
}

//function for cheking balank spaces in sting
function str_blank_space(str,name)
{
					var i;
					for (i = 0; i < str.length; i++)
					{   
						// Check that current character is number.
						var c = str.charAt(i);
						
						if (((c == " ")&& ( (i+1)<str.length && str.charAt(i+1)==" ")))
						{
						alert("Please don't enter blank space for "+name);
						 return false;
						 }
					}
					// All characters are numbers.
					return true;
}
//function forchecking ant special characters in string
function str_special(str,name)
{
			var iChars = "!@#$%^&*+=[]\\\';,./{}|\":<>?";
		
		  for (var i = 0; i < str.length; i++) {
		  
			if (iChars.indexOf(str.charAt(i)) != -1) {
			
			alert ("Your "+name+" has special characters. \n Please remove them and try again.");
			return false;
			}
		  }
		  return true;
}

//function for cheking valid email addres

function str_is_email(str,name)
{
var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i

var returnval=emailfilter.test(str)
if (returnval==false){
alert("Please enter a valid email address for "+name)

}
return returnval

}

//function for comparing two string values
function str_is_identical(str1,str2)
{
		if(str1!=str2)
		{
				alert("not identical");
				return false;
		}
		return true;
}

// function  to call all function by in below format
//(stringvalue,name,cheking for email, pass min lenth to chek, pass maximum length,to chek alphbates , cheking for numrical valuse,chekin for space, cheking for special character,cheking for blank spaces
//pass value 1 to any variable for cheking that value otherwise simply pass 0 to avoide cheking of that condition

function form_validation(str,name,email,minlength,maxlength,alpha,number,space,special,blank)
{

		
		if(!str_empty(str,name))
		{
		return false;
		}
		if(email==1)
		{
		if(!str_is_email(str,name))
		return false;
		}
		
		if(!str_min(str,minlength,name))
		{
			return false;
		}
		
		
		
		if(!str_max(str,maxlength,name))
		{
			return false;
		}
	if(alpha==1&&number==1)
	{
		alert("Not Valid format to check  alphabet and number for "+name);
		return false;
	}
		
		if(alpha!=1&&number==1)
		{
			
		if(!str_is_num(str,name))
		return false;
				
		}
	
		
		
		if(number!=1&&alpha==1)
		{
		if(!str_is_char(str,name))
		return false;
				
		}
		
	
		
		
		if(space==1)
		{
		if(!str_space(str,name))
		return false;
		
		}
		
		
		
		if(blank==1)
		{
		if(!str_blank_space(str,name))
		return false;
				
		}
		
		
			
if(special==1)
{	
	
if(!str_special(str,name))
return false;
	
	}	
	
	
	return true;
		
}


