





// ##########################################################

	//			BEGIN DEPENDENT VALIDATION FUNCTIONS

// ##########################################################









//----------------------------------------------------------------
//=================PERSON NAMES==========BEGIN=================
//----------------------------------------------------------------


	// cut and paste this script as a standalone function.
	function personnames(fieldvalue, fieldname)
	{
		var str=fieldvalue;
		var field=fieldname;
		var strlen=str.length;
		

		// check if str has a 'space' 
		//if (str.indexOf(" ")!=-1)
		//{
			//alert("Error: The '" + field + "' field does not accept 'Spaces'");
			//return false;
		//}	

		// check if str is a number or not 
		if (isNaN(str)==false)
		{
			alert("This field accepts only Characters, Spaces and Single Quotes.");
			return false;
		}
		
		
		// check for values other than actual alphabets			
		for(i=0;i<strlen;i++)
		{
			if((str.charCodeAt(i) >=65 && str.charCodeAt(i) <= 90) || (str.charCodeAt(i) >=97 && str.charCodeAt(i)<= 122) || (str.charCodeAt(i) ==32 ) || (str.charCodeAt(i) ==39 ))
			
			{
			//do nothing;
			}
			else
			{	
			alert("This field accepts only Characters, Spaces and Single Quotes.");
			return false;
			}
		}

	}
//----------------------------------------------------------------
//=================PERSON NAMES==========END=================
//----------------------------------------------------------------








//----------------------------------------------------------------
//=================ALPHABETS ONLY ==========BEGIN=================
//----------------------------------------------------------------


	// cut and paste this script as a standalone function.
	function alphabets(fieldvalue, fieldname)
	{
		var str=fieldvalue;
		var field=fieldname;
		var strlen=str.length;
		

		// check if str has a 'space' 
		//if (str.indexOf(" ")!=-1)
		//{
			//alert("Error: The '" + field + "' field does not accept 'Spaces'");
			//return false;
		//}	

		// check if str is a number or not 
		if (isNaN(str)==false)
		{
			alert("The '" + field + "' field does not accept numbers");
			return false;
		}
		
		
		// check for values other than actual alphabets			
		for(i=0;i<strlen;i++)
		{
			if((str.charCodeAt(i) >=65 && str.charCodeAt(i) <= 90) || (str.charCodeAt(i) >=97 && str.charCodeAt(i)<= 122))
			
			{
			//do nothing;
			}
			else
			{	
			alert("The '" + field + "' field does not accept special charcters or numbers");
			return false;
			}
		}

	}
//----------------------------------------------------------------
//=================ALPHABETS ONLY ==========END=================
//----------------------------------------------------------------





//----------------------------------------------------------------
//=================EMAIL ONLY ==========BEGIN=================
//----------------------------------------------------------------

function validemail(fieldvalue, fieldname, specialstr)
{

var str=fieldvalue;
var strlen=str.length;
var specialstr=specialstr;	
	// check for blanck entries
	if(str=="")
	{
		alert("You cannot leave email address field  blank");
		checkemail="false";
		return checkemail;
	}
	
	
	//Checking if first character is a number or not.
	if(((isNaN(str.substring(0,1)))==false))
	{
		alert("Please verify your '" + fieldname + "' field, the first character should not be a number");
		checkemail="false";
		return checkemail;
	}
	
	
	//Checking if last character is a number or not
	if ((isNaN(str.substring(strlen-1,strlen)))==false) 
	{
		alert("Please verify your '" + fieldname + "' field, the last character cannot be a 'Number'");
		checkemail="false";
		return checkemail;
	}
			
	//Checking if first character is an '@' 
	escore=(str.substring(0,1))
	if (escore=="@")
	{
		alert("Please verify your '" + fieldname + "', the first character cannot be a '@'");
		checkemail="false";
		return checkemail;
	}
			
	//Checking if first character is an '_' 
	escore=(str.substring(0,1))
	if (escore=="_")
	{
		alert("Please verify your Email address, the first character cannot be a '_'");
		checkemail="false";
		return checkemail;
	}
	
	//checking if last character is an '_'
	var lastscore;
	if (str.substring(strlen-1,strlen)=='_')
	{
		alert("Please verify your Email address, the last character cannot be a '_'");
		checkemail="false";
		return checkemail;
	}

			
	//Checking if first character is a '.'
	edot=(str.substring(0,1))
	if (edot==".")
	{
		alert("Please verify your Email address, the first character cannot be a '.'");
		checkemail="false";
		return checkemail;
	}
	
	//checking if last character is a '.'
	var lastdot;
	if (str.substring(strlen-1,strlen)=='.')
	{
		alert("Please verify your Email address, the last character cannot be a '.'");
		checkemail="false";
		return checkemail;
	}


			
	//Check for no spaces within the mailid
	if (str.indexOf(" ")!=-1)
	{
		alert("Please verify your '" + fieldname + "' field, it should not have spaces");
		checkemail="false";
		return checkemail;
	}
		


	//Check for only one '@' and atleast one '.' in the string
	 if ((str.indexOf("@")< 0 ))
	{
		alert("Please verify your Email address, it should have the '@' symbol" );
		checkemail="false";
		return checkemail;
	}

	
	
	//check for atleast one occurence of '.'
	if ((str.indexOf(".")< 0 ))
	{
		alert("Please verify your Email address, it should have a '.' " );
		checkemail="false";
		return checkemail;
	}
		

	//Check for special Characters
	checkspchar=specialchar(str, specialstr, fieldname)
	if (checkspchar=="false")
	{
		checkemail="false"
		return checkemail;
	}

	

	//checking for more than one non-consecutive '@'s - conat funciton
	conat=at(str)
	if (conat=="false")
	{
		checkemail="false"
		return checkemail;
	}
		
		
		
	//Checks for consecutive occurence of @@ and .. in the string
	checkatat=atat(str)
	if (checkatat=="false")
	{
		checkemail="false";
		return checkemail;
	}



	// check for atleast one '.' after '@' symbol
	
	// this segment of code will check for atleast one '.' after the '@' char and hence this segment has to be placed after the validation of all the '@' related validations.
	
	var posat=0;
	strlen=str.length;
	posat=str.indexOf("@");
	if(str.indexOf(".", posat) < 0)
	{
		alert("Please enter the email address  in xxx@xxx.xxx format");
		checkemail="false";
		return checkemail;
	}
		
	
		
	//checking for length of string before and after ('@' !> 20)
	checklen=beforeandafterat(str)
	if (checklen=="false")
	{
		checkemail="false"
		return checkemail;
	}


//////////////////////////////////////////////////////////////////////////		
//////////  Indivisual Sub functions begins from here ///////////////////
//////////////////////////////////////////////////////////////////////////		
		
		
	// Checks for special characters
	// do not edit any code here
	function specialchar(str, specialstr, fieldname)
	{
	var fieldname=fieldname;
	var str=str;
	var len=str.length;
	var i, strbit, scount=0, no;
	var specialstr=specialstr;
		for (i=0; i<len; i++)
		{
		strbit=str.substring(i,i+1);
		pscount=emailcomp(strbit, specialstr);
			if (pscount > 0)
			{
			alert("Please verify your '" + fieldname + "' address, it cannot contain special characters other than @,_ and .");
			no="false"
			return no;
			}
		
		}
	}// end of special char function.
		
		
		// auxiliary unit of specialchar function
		// do not edit any code here
		function emailcomp(strbit, specialstr)
		{
		var a, scount=0;
		var specialstr=specialstr;
		var slen=specialstr.length;
			for (a = 0; a <= slen; a++)
			{
			
			val=specialstr.substring(a,a+1)
				if (val==strbit)
				{
				scount=scount+1;
				}
			}
		return scount
		}// end of emailcomp function

		
		
		
///Checking for more than one Occurence of '@' in the email string
		// do not edit this code
		function at(str)
		{
		
		var str=str;
		var len=str.length;
		var contat=0,at=0;
		
			for (i=0; i<len; i++)
			{
				for (pos=i+1; pos<i+2; pos++)
				{
					if(str.substring(i,pos)=='@')
					at=at+1;			
				}
			}
					if (at > 1)
					{
						alert("Please verify your Email address, it should have only one '@' sign");
						conat="false";
						return conat;
					}
		}// end of  at function
			

		// function to check the consecutive occurence of @,.,_ and combinations
		//do not edit code from here
		function atat(str)
		{
		var str=str;
		var len=str.length;
		var fieldname=fieldname
		var  i, atat;
		
		
		for (i=0; i<len; i++)
			{
			atat=str.substring(i,i+2);
			
			 if ((atat=="@@") || (atat=="..") || (atat=="@.") || (atat==".@") || (atat=="_@")|| (atat=="@_") || (atat=="__") || (atat=="._") || (atat=="_."))
					{
					alert("Please enter a valid Email address in xxx@xxx.xxx format ");
					checkatat="false"
					return checkatat;
					}// end of if
			}	
		}// end of atat function
		




///Checking for number of chars before and after '@' -- less than 20
		function beforeandafterat(str)
		{
		var str=str;
		var len=str.length;
		var countat=0;
		var posat, pos, beforeat, afterat, no;
		
		
			for(i=0; i<len; i++)
			{
				for (pos = i+1; pos < i+2; pos++)
				{
					strat=str.substring(i,pos);
					if (strat=="@")
					{
					posat=pos;
					}
				}
			}
		
			beforeat=posat-1; //Number of letters before the '@'
			afterat=len-(posat) ;//Number of letters after the '@'
			if ( (beforeat > 49) || (afterat > 49) )
			{
				alert("Please verify your Email address, the number of characters before and after the '@', should not exceed 49 characters");
				checklen="false";
				return checklen;
			}
		}// end of beforeandafterat function



		
///////////////////////////////////////////////////////////////		
}// end of validemail function

//----------------------------------------------------------------
//=================EMAIL ONLY ==========END=================
//----------------------------------------------------------------





//----------------------------------------------------------------
//=================ZIPCODE ==========BEGIN=================
//---------------------------------------------------------------- 

// this function checks for the validity of US-Zipcode
function callzip(str,fieldname)
{
	//check length of zip code.
	if ((str.length!=5) && (str.length!=10))
	{
		alert("Please enter your Zip Code in the proper format. XXXXX or XXXXX-XXXX");
		return false;
	}

	// validations for length = 5
	if(str.length==5)
	{
	//check if they are unsigned integers.
		purenumber=integersonly(str, fieldname)
		if (purenumber==false)
		//alert("Please enter your Zip Code in the proper format. XXXXX or XXXXX-XXXX");
		return false;
	}
	
	
	if(str.length==10)
	{
		// format= part1 'hypen' part2 (xxxxx-xxxx)
		//check if they are unsigned integers.
		var part1=str.substring(0,5)
		var hypen=str.substring(6,5)
		var part2=str.substring(10,6);

		
		//check purity of part1
		purenumber=integersonly(part1, fieldname)
		if (purenumber==false)
		{
			//alert("Please enter your Zip Code in the proper format. XXXXX or XXXXX-XXXX");
			return false;
		}
		
		//check purity of part2
		purenumber=integersonly(part2, fieldname)
		if (purenumber==false)
		{
			//alert("Please enter your Zip Code in the proper format. XXXXX or XXXXX-XXXX");
			return false;
		}

		//check for presence of hypen.
		if (hypen!="-")
		{
			alert("Please enter your Zip Code in the proper format. XXXXX or XXXXX-XXXX");
			return false;
		}

	}// end of if length=10 loop
	
}// END OF CALLZIP FUNCITON


//----------------------------------------------------------------
//=================ZIPCODE ==========END================
//---------------------------------------------------------------- 
	
	
	
//----------------------------------------------------------------
//=================INTEGERSONLY==========BEGIN=================
//----------------------------------------------------------------   


	// this function checks for Integers only
	function integersonly(fieldvalue, fieldname)
	{
		var str=fieldvalue;
		var field=fieldname;
		
		if(str=="")
		{
		alert("This field cannot be blank");
		return false;
		}
		
		// check if str is a number or not 
		if (isNaN(str))
		{
		alert("This field accepts only numbers");
		return false;
		}
		
		// check if str has a 'space' 
		if (str.indexOf(" ")!=-1)
		{
		alert("This field does not accept 'Spaces'");
		return false;
		}

		// check if str has a '+' 
		if (str.indexOf("+")!=-1)
		{
		alert("This field does not accept '+'");
		return false;
		}
		
		// check if str has a '-' 
		if (str.indexOf("-")!=-1)
		{
		alert("This field  does not accept '-'");
		return false;
		}

		// check if str has a '.' 
		if (str.indexOf(".")!=-1)
		{
		alert("This field does not accept '.'");
		return false;
		}		
	}// end of integersonly function
	
//----------------------------------------------------------------
//=================INTEGERSONLY==========END=================
//----------------------------------------------------------------   







//----------------------------------------------------------------
//=================DECIMAL==========BEGIN=================
//----------------------------------------------------------------   




	function decimal(fieldvalue, fieldname)
	{
		var str=fieldvalue;
		var field=fieldname;
	
		
		// check if str is a number or not 
		if (isNaN(str))
		{
			alert("This fild accepts only numbers");
			return false;
		}
		
		// check if str has a 'space' 
		if (str.indexOf(" ")!=-1)
		{
			alert("This field does not accept 'Spaces'");
			return false;
		}	

	}


//----------------------------------------------------------------
//=================DECIMAL==========END=================
//----------------------------------------------------------------    










//----------------------------------------------------------------
//=======REMOVE APOSTROPHE FUNCTION ==========BEGIN==============
//----------------------------------------------------------------     



function remove_apostrophe(contentstring) 
{	
	var stringData=new String(contentstring)
	var contentstring="";
	for(i=0;i<stringData.length;i++)
	{
		if(stringData.charAt(i)!=="'")
		{
			contentstring=contentstring + stringData.charAt(i);
		}		
	}
		
	return contentstring
}


//----------------------------------------------------------------
//=======REMOVE APOSTROPHE FUNCTION ==========END=============
//----------------------------------------------------------------  
















//----------------------------------------------------------------
//=======TRIM ==========BEGIN==============
//----------------------------------------------------------------  

//function to trim preceding and following spaces for text fields
	  function trim(str)
	  {
		temp=" ";
	  	var countspcatfrnt=-1;
	  	var len;
	  	i=0;
	  	len=str.length;
	  	while(temp==" ")
	  	{
	  		temp=str.substring(i,i+1);
	  		countspcatfrnt+=1;//counting front spaces
	  		i+=1;	
	  	}
	  	temp=" ";
	  	var countspcatrear=-1;
	  	var trimvalue=""
	  	i=0;
	  	while(temp==" ")
	  	{
	  		temp=str.substring(((len-i)-1),(len-i));
	  		countspcatrear+=1;//counting rear spaces
	  		i++;
	  	}
	  	i=0;
	  	for(i=countspcatfrnt; i<=(len-countspcatrear-1); i++)
	  		trimvalue=trimvalue + str.substring(i,i+1);
			
	  	return trimvalue;
	  }
	  
//----------------------------------------------------------------
//=======TRIM==========END==============
//----------------------------------------------------------------  



// ##########################################################
	//			END DEPENDENT VALIDATION FUNCTIONS
// ##########################################################


