	 /*
	  Functions in this document
	    
		(1) minLength(field,val,msg)
		       [ This function check minimum length is giveen or not] 
		(2) maxLength(field,val,msg)
		       [ This function used to limit maximum text] 
	    (3) isZeroLead(field)  
		  	   [ This function check leading zero on the field text]
		(4) isNumber(numberField,fieldString)
		       [ This function check valid number]
        (5) isCNumber(numberField,fieldString)
		       [ This function check valid Integer]
		(6) echeck(str)
		       [ This function check valid email]
		(7) CheckBoxCheck(msg)
		       [ This function check if atleast one check box is checked]
		(8) portionCheckBoxCheck(name,msg)
		       [ This function check if atleast one check box is checked in a given portion]
		(9) checkUncheckAll(field)
			   [ This function is used to check or uncheck all check boxes in a given form]
	    (10) alphabetCheck(fieldToCheck)		
			  [ This function is used to check alphabetic charcters]
	    (11) validTextMaker(textField)
	          [ This function is used to restrict special charcters in some text field]
		(12) finalCheck(finalField)
	          [ This function is used to restrict special charcters ]
        (13) removeLeadingAndTrailingChar (fieldToRemoveChar, removeChar)	
			  [ This function is used to erase special charcters from beginning and end of field ]
	    (14) yearCheck(yearField)  
	          [ This function is used to check for valid year ] 
	*/ 
	
	//var mikExp = /[$\\@\\\#%\^\&\*\(\)\[\]\+\{\}\`\~\=\|\'\"\<\>]/;
	// Special Charcters that are restricted to user
	var mikExp=/[\\\\^\&\*\`\~\=\|\"]/; 

	/** (1)
	*  This method is used to check if 
	*  the text length of a field is meeting
	*  the minimum range of requirements
	*/
	function minLength(field,val,msg) {
		if ( field.value.length < val) {
			alert(msg);
			field.select();
			field.focus();
			return false;
		}
		return true;
	}
	
	/** (2)
	*  This function is used to check if  
	*  text is not exceeding the maximum
	*  limit
	*/
	function maxLength(field,val,msg) {
		if ( field.value.length > val ) {
			alert(msg);
			field.select();
			field.focus();
			return false;
		}
		return true;
	}

	/** (3)
	*  This Function is used to check if  
	*  ther is a zero charcter in the 
	*  very first position of field 
	*/
	function isZeroLead(field){
		var a = "";
		a = field.value.charAt(0);
		if (a=="0") {
		   alert('There is zero in starting position');
		   field.select();
	  	   field.focus();
		   return false;
		} 
		return true;
	} 

	/** (4)
	*  This field is used to check if
	*  the given field text is a valid
	*  number 
	*/
	function isNumber(inputString,fieldString) {
	     flag = true;
		 //inputString=inputString.trim();
  		 for (i=0; i< inputString.length; i++) {	
   			if (isNaN(parseInt(inputString.charAt(i)))) { 
				 if(inputString.charAt(i)!=".") {
				  	 flag=false;
	    	  	 }
			}
	 	 }//end for
	   for (i=0; i< inputString.length; i++) {	
   			 if(inputString.charAt(i)==".") {
				flag=false;
	   	     } // end if 
		 }//end for
	   if(flag == false ) {
	    alert(fieldString);
	     return false;
	   }
	 return true;
	}
	
	/** (5)
	*  This field is used to check if
	*  the given field text is a valid
	*  number not float 
	*/
	function isCNumber(inputString,fieldString) {
	   // alert(inputString);
		flag = true;
		 //inputString=inputString.trim();
  		 for (i=0; i< inputString.length; i++) {	
   			if (isNaN(parseInt(inputString.charAt(i)))) { 
				 if(inputString.charAt(i)!=".") {
				  	 flag=false;
	    	  	 }
			}
	 	 }//end for
	  if(flag == false ) {
	    alert(fieldString);
	     return false;
	   }
	 return true;
   }
   
   /** (6)
	*  This method is used to checked 
	*  for the validity of the Email 
	*/
	function echeck(str) {
		emailStr = str.value;
		/* The following variable tells the rest of the function whether or not
		to verify that the address ends in a two-letter country or well-known
		TLD.  1 means check it, 0 means don't. */
		var checkTLD=1;
		/* The following is the list of known TLDs that an e-mail address must end with. */
		var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
		/* The following pattern is used to check if the entered e-mail address
		fits the user@domain format.  It also is used to separate the username
		from the domain. */
		var emailPat=/^(.+)@(.+)$/;
		/* The following string represents the pattern for matching all special
		characters.  We don't want to allow special characters in the address. 
		These characters include ( ) < > @ , ; : \ " . [ ] */
		var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
		/* The following string represents the range of characters allowed in a 
		username or domainname.  It really states which chars aren't allowed.*/
		var validChars="\[^\\s" + specialChars + "\]";
		/* The following pattern applies if the "user" is a quoted string (in
		which case, there are no rules about which characters are allowed
		and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
		is a legal e-mail address. */
		var quotedUser="(\"[^\"]*\")";
		/* The following pattern applies for domains that are IP addresses,
		rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
		e-mail address. NOTE: The square brackets are required. */
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
		/* The following string represents an atom (basically a series of non-special characters.) */
		var atom=validChars + '+';
		/* The following string represents one word in the typical username.
		For example, in john.doe@somewhere.com, john and doe are words.
		Basically, a word is either an atom or quoted string. */
		var word="(" + atom + "|" + quotedUser + ")";
		// The following pattern describes the structure of the user
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
		/* The following pattern describes the structure of a normal symbolic
		domain, as opposed to ipDomainPat, shown above. */
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
		/* Finally, let's start trying to figure out if the supplied address is valid. */
		/* Begin with the coarse pattern to simply break up user@domain into
		different pieces that are easy to analyze. */
		var matchArray=emailStr.match(emailPat);
		if (matchArray==null) {
			/* Too many/few @'s or something; basically, this address doesn't
			even fit the general mould of a valid e-mail address. */
			alert("Your email address is not correct ");
			str.select();
			str.focus();
			return false;
		}
		var user=matchArray[1];
		var domain=matchArray[2];
		// Start by checking that only basic ASCII characters are in the strings (0-127).
		for (i=0; i<user.length; i++) {
			if (user.charCodeAt(i)>127) {
				alert("Ths username contains invalid characters.");
				str.select();
				str.focus();
				return false;
			}
		}
		for (i=0; i<domain.length; i++) {
			if (domain.charCodeAt(i)>127) {
				alert("Ths domain name contains invalid characters.");
				str.select();
				str.focus();
				return false;
			}
		}
		// See if "user" is valid 
		if (user.match(userPat)==null) {
			// user is not valid
			alert("The username doesn't seem to be valid.");
			str.select();
			str.focus();
			return false;
		}
		/* if the e-mail address is at an IP address (as opposed to a symbolic
		host name) make sure the IP address is valid. */
		var IPArray=domain.match(ipDomainPat);
		if (IPArray!=null) {
			// this is an IP address
			for (var i=1;i<=4;i++) {
				if (IPArray[i]>255) {
					alert("Destination IP address is invalid!");
					str.select();
					str.focus();
					return false;
				}
			}
			return true;
		}
		// Domain is symbolic name.  Check if it's valid.
		var atomPat=new RegExp("^" + atom + "$");
		var domArr=domain.split(".");
		var len=domArr.length;
		for (i=0;i<len;i++) {
			if (domArr[i].search(atomPat)==-1) {
				alert("The domain name does not seem to be valid.");
				str.select();
				str.focus();
				return false;
			}
		}
		/* domain name seems valid, but now make sure that it ends in a
		known top-level domain (like com, edu, gov) or a two-letter word,
		representing country (uk, nl), and that there's a hostname preceding 
		the domain or country. */
		if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
			alert("The address must end in a well-known domain or two letter " + "country.");
			str.select();
			str.focus();
			return false;
		}
		// Make sure there's a host name preceding the domain.
		if (len<2) {
			alert("This address is missing a hostname!");
			str.select();
			str.focus();
			return false;
		}
		// If we've gotten this far, everything's valid!
		return true;
	}
	
	/** (7)
	*  This method is used to check if 
	*  there is at least one check box 
	*  is checked in the page 
	*/ 
	function CheckBoxCheck(msg) {
		flag = true;
		for	(i=0;i<document.form1.elements.length; i++) {
			if (document.form1.elements[i].type=="checkbox") {
			   if (document.form1.elements[i].checked) {
				  flag = false;
			   }//end if
			}//end if outer
		}//end for
		if (flag) {
		    alert(msg);
			return false;
		} else {
			return true;
		}
	}//end deleteMe
	
	/** (8)
	*  This method is used to check if 
	*  there is at least one check box 
	*  is checked in the given portion 
	*/ 
	function portionCheckBoxCheck(name,msg) {
		bol = true;
		for	(i=0; i<document.form1.elements.length; i++) {
			if (document.form1.elements[i].type == "checkbox") {
				if(document.form1.elements[i].name==name){
			    	if (document.form1.elements[i].checked) {
				  	  bol = false;
			   		}//end if
				}//end if center
			}//end if outer
		}//end for
		if (bol) {
		    alert(msg);
			return false;
		} else {
			return true;
		}
	}//end deleteMe
	
	/** (9)
	*  This method is used to check or 
	*  uncheck all the check boxes in 
	*  the page against the check or 
	*  uncheck state of some particulat check box
	*/
	function checkUncheckAll(field) {
		if (document.form1.field.checked) {
			for (i=0; i<document.form1.elements.length; i++) {
				if (document.form1.elements[i].type=="checkbox") {
					document.form1.elements[i].checked=true;
				}//end if outer
			}//end for
		} else {
			for (i=0; i<document.form1.elements.length; i++) {
				if (document.form1.elements[i].type=="checkbox") {
					document.form1.elements[i].checked=false;
				}//end if inner
			}//end for
		} // end of else
	}//end deleteMe

	/** (10)
	*  This method is used to check  
	*  if the given text in the field 
	*  is only alphabetic charcters or 
	*  space
	*/
	function alphabetCheck(fieldToCheck) {
		var box = fieldToCheck;//document.frm1.box;
		re=/^[a-zA-Z\ ]*$/;
		if(!re.exec(box.value)) {
			alert("Only alphabetic characters or space allowed!");
			box.select();
			box.focus();
			return false;
		}//end name if
	  return true;
	}
	
    /** (11)
	*  This function is used to check 
	*  for charcter validity at current 
	*  time and remove invalid charcter
	*  from string 
	*/
	function validTextMaker(textField) {
		/*var strPass = textField.value;
		var strLength = strPass.length;
		var lchar = textField.value.charAt((strLength) - 1);
		if (lchar.search(mikExp) != -1) {
			var tst = textField.value.substring(0, (strLength) - 1);
			textField.value = tst;
		}*/
	} 
	/** (12)
	*  This method is used to check 
	*  if all text in given field is
	*  valid
	*/
	function finalCheck(finalField) {
		/*if (finalField.value.search(mikExp) == -1) {
		return true;
		}	else {
		 alert("Following characters\n\r\n\r ^\&\*\`\~\=\|\'\" \n\r\n\rare not allowed!\n");
		  finalField.select();
		  finalField.focus();
		  return  false;
		}*/
		return true;
	}
	
	/** (13)
	*  This method is used to remove 
	*  leading and ending charcters .eg space
	*  from the given text field text 
	*/
	function removeLeadingAndTrailingChar (fieldToRemoveChar, removeChar) {
		var returnString = fieldToRemoveChar.value;
		if (removeChar.length)
		{
		  while(''+returnString.charAt(0)==removeChar)
			{
			  returnString=returnString.substring(1,returnString.length);
			}
			while(''+returnString.charAt(returnString.length-1)==removeChar)
		  {
			returnString=returnString.substring(0,returnString.length-1);
		  }
		}
		return returnString;
	}

	
	/** (14)
	*  This Function is used to restrict
	*  the user to give year input in a
	*  given range
	*/
	function yearCheck(yearField) {
		var year = yearField.value;
		myyear = parseInt(year);
		if (myyear<1947||myyear>2004) {
		   alert("Given year is not valid");
		   yearField.select();
		   yearField.focus();
		   return false;
		}
		return true;
	}
   ////////////////////////////////////////////////////////////////////////////////////
     function isEmpty(form,msg) {
	  if (form.value.length < 1) {
		  alert(msg);
   		  form.select();
		  form.focus();
		  return false ; 
	  }
	  if (form.value.search(mikExp) == -1) {
	  	return true;
	  }	else {
 alert("Following characters\n\r\n\r ^\&\*\`\~\=\|\'\" \n\r\n\rare not allowed!\n");
		  form.focus();
		  return  false;
     }
	 return true;
 }
 
 ////////////////////////////////////////////////////////////////////////////////////////
 /** (14)
	*  This Function is used to Compare 
	*  the values of two fields 
	*  for equalance
	*/
	function equalityCheck(firstField,secondField,msg) {
		if (firstField.value!=secondField.value) {
		   alert(msg);
		   secondField.select();
		   secondField.focus();
		   return false;
		}
		return true;
	}
//////////////////////////////////////////////////////////////////////////////////////////////////
/** (15)
	*  This method is used to check if 
	*  there is at least one check box 
	*  is checked in the page 
	*/ 
	function RadioBoxCheck(msg) {
		flag = true;
		for	(i=0;i<document.form1.elements.length; i++) {
			if (document.form1.elements[i].type=="radio") {
			   if (document.form1.elements[i].checked) {
				  flag = false;
			   }//end if
			}//end if outer
		}//end for
		if (flag) {
		    alert(msg);
			return false;
		} else {
			return true;
		}
	}//end deleteMe
	

//////////////////////////////////////////////////////////////////////////////////////////////////
/** (1)
	*  This method is used to check if 
	*  there is at least one check box 
	*  is checked in the page 
	*/ 
	function getRadioBox() {
		for	(i=0;i<document.form1.elements.length; i++) {
			if (document.form1.elements[i].type=="radio") {
			   if (document.form1.elements[i].checked) {
				  return document.form1.elements[i].value;
			   }//end if
			}//end if outer
		}//end for
	}//end deleteMe
	
//////////////////////////////////////////////////////////////////////////////////////////////////

   /*
       var field = form.email; // email field
	   var str = field.value; // email string
  	   var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
  	   var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
  	   if (!(!reg1.test(str) && reg2.test(str)))
      		{ 
       			alert("\"" + str + "\" is an invalid e-mail!"); // this is also optional
       			form.email.focus();
	   			return false;
	  		}

   */
	
	function IsNotNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.'!''@''#'$''%''&''*''+''-''";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }
   
    function alphabetCheck(fieldToCheck) {
		var box = fieldToCheck;//document.frm1.box;
		re=/^[a-zA-Z\ ]*$/;
		if(!re.exec(box.value)) {
			alert("Your name is not correct");
			//box.select();
			box.focus();
			return false;
		}//end name if
	  return true;
	}
	
	/*function isNumeric(strString) {
// check for valid numeric strings 
var strValidChars = "0123456789.-";
var strChar;
var blnResult = true;

if (strString.length == 0) return false;

// test strString consists of valid characters listed above
for (i = 0; i < strString.length && blnResult == true; i++)
{
strChar = strString.charAt(i);
if (strValidChars.indexOf(strChar) == -1)
{
blnResult = false;
}
}
return blnResult;
}*/
	function isFloat(strString,field,fieldString) {
	// check for valid numeric strings
	flag = true;
	//var strValidChars = "0123456789.-";
	var strValidChars = "0123456789.";
	var strChar;
	var blnResult = true;
	
	//if (strString.length == 0) return false;
	
	// test strString consists of valid characters listed above
		for (i = 0; i < strString.length && blnResult == true; i++)
			{
				strChar = strString.charAt(i);
				if (strValidChars.indexOf(strChar) == -1)
					{
	
						blnResult = false;
						flag = false
					}
			}
	 if(flag == false ) {
			alert(fieldString);
			//field.select();
		   	field.focus();
			 return false;
		   }
	return blnResult;
	}


function isNumaric(strString,field,fieldString) {
	// check for valid numeric strings
	flag = true;
	//var strValidChars = "0123456789.-";
	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;
	
	//if (strString.length == 0) return false;
	
	// test strString consists of valid characters listed above
		for (i = 0; i < strString.length && blnResult == true; i++)
			{
				strChar = strString.charAt(i);
				if (strValidChars.indexOf(strChar) == -1)
					{
	
						blnResult = false;
						flag = false
					}
			}
	 if(flag == false ) {
			alert(fieldString);
			//field.select();
		   	field.focus();
			 return false;
		   }
	return blnResult;
	}
	
	
// this function check the numbers. give error msg except numbers
function check_Number(field_value,msg,field) {
	   // alert(inputString);
		flag = true;
		 //inputString=inputString.trim();
  		 for (i=0; i< field_value.length; i++) {	
   			if (isNaN(parseInt(field_value.charAt(i)))) { 
				 if(field_value.charAt(i)!=".") {
				  	 flag=false;
	    	  	 }
			}
	 	 }//end for
	  if(flag == false ) {
	    alert(msg);
		field.select();
		field.focus();
	     return false;
	   }
	 return true;
   }
