/*Function comments()
*{
* *************************************************************
** FORMVAL.JS - JS Form Validation Library
************************************************************* */

/* *************************************************************
** USAGE
** =====
** Functions to Validata Form-Element Data:
**   isEmpty(s) - true if string s is empty
**   isBlank(s) - true if string s is empty or blank (all whitespace chars)
**   isLetter(c) - true if char c is an English letter 
**   isDigit(c) - true if char c is a digit 
**   isInteger(s) - true if string s is a signed/unsigned number
**   isIntegerInRange(s, a, b) - true if string s (integer) is a <= s <= b
**   isFloat(s) - true if string s is a signed/unsigned floating-point number
**   isAlphanumeric(s, AllowSpace, AllowUnderscore) - true if s is English letters and numbers only
**   isUSPhoneNumber(s) - true if string s is a valid U.S. phone number
**   isZIPCode(s) - true if string s is a valid U.S. ZIP code
**   isStateCode(s) - true if string s is a valid U.S. (2-letter) state code
**   isEmail(s) - true if string s is a valid email address
**   checkURL(sUrl) - true if Valid URl or false for inValid URL
**   checkURLNew(sUrl) - true if Valid URl or false for inValid URL, NEW - use this
**   getCheckedRadioButton(radioSet) - gets index checked radio button in set
**   getCheckedCheckboxes(checkboxSet) - gets index(es) of checked checkboxes in set
**   getCheckedSelectOptions(select) - gets index(es) of checked select options
**
** Functions to Reformat input=text Form-Field Data:
**   stripCharsInBag(s, bag) - removes all chars in string bag from string s
**   stripCharsNotInBag(s, bag) - removes all chars NOT in string bag from string s
**   stripBlanks(s) - removes all blank chars from s
**   stripLeadingBlanks(s) - removes leading blank chars from s
**   stripTrailingBlanks(s) - removes trailing blank chars from s
**   stripLeadingTrailingBlanks(s) - removes lead+trail blank chars from s
**   reformatString(targetStr, str1, int1 [, str2, int2 [, ..., ...]]) - 
**     inserts formatting chars or delimiters in targetStr (see below)
**  formatCurrency(str)-formats input to currency format

** isNumericNegative -- skips the "-" sign and rest validates for numeric
************************************************************* */


/* ********************************************************** */
/* Global Variables and Constants *************************** */
/* ********************************************************** */
//}

var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var blanks = " \t\n\r";  // aka whitespace chars


// decimal point character differs by language and culture
var decimalPointDelimiter = "."

// non-digit characters allowed in phone numbers
var phoneNumberDelimiters = "()- ";

// characters allowed in US phone numbers
var validUSPhoneChars = digits + phoneNumberDelimiters;

// U.S. phone numbers have 10 digits, formatted as ### ### #### or (###)###-####
var digitsInUSPhoneNumber = 10;

// non-digit characters which are allowed in ZIP Codes
var ZIPCodeDelimiters = "-";


// our preferred delimiter for reformatting ZIP Codes
var ZIPCodeDelimeter = "-"

//characters allowed in ZipCode 
var validZipCodeChars = digits + ZIPCodeDelimiters


// U.S. ZIP codes have 5 or 9 digits, formatted as ##### or #####-####
var digitsInZIPCode1 = 5
//var digitsInZIPCode1 = 6
var digitsInZIPCode2 = 9

// Valid U.S. Postal Codes for states, territories, armed forces, etc.
// See http://www.usps.gov/ncsc/lookups/abbr_state.txt
var USStateCodeDelimiter = "|";
var USStateCodes = "AL|AK|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|TX|UT|VT|VI|VA|WA|WV|WI|WY|AE|AA|AE|AE|AP|al|ak|as|az|ar|ca|co|ct|de|dc|fm|fl|ga|gu|hi|id|il|in|ia|ks|ky|la|me|mh|md|ma|mi|mn|ms|mo|mt|ne|nv|nh|nj|nm|ny|nc|nd|mp|oh|ok|or|pw|pa|pr|ri|sc|sd|tn|tx|ut|vt|vi|va|wa|wv|wi|wy|ae|aa|ae|ae|ap"
//var month[] = {"JANUARY", "FEBURARY", "MARCH", "APRIL", "JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"};



/* ********************************************************** */
/* Functions ************************************************ */
/* ********************************************************** */

function isNumericKeyPress()
{
	
	return ((event.keyCode>=48 && event.keyCode <=57));
	
}



function isValidString(s, ValidChars)
{

 //if isBlank(s) return false;
 
 for(var i=0; i<s.length; i++)
 {
  
  if( ValidChars.indexOf(s.substr(i,1)) == -1)
   return false;
 
 }
 
return true;
}


// Returns true if string s is empty
function isEmpty(s)
  {
  return ((s == null) || (s.length == 0));
  }


// Returns true if string s is empty or all blank chars

function isBlank(s)
  {
  var i;

  // Is s empty?
  if (isEmpty(s))
    return true;

  // Search through string's chars one by one until we find first
  // non-blank char, then return false; if we don't, return true
  for (i=0; i<s.length; i++)
    {   
    // Check that current character isn't blank
    var c = s.charAt(i);
    if (blanks.indexOf(c) == -1) 
      return false;
    }
  // All characters are blank
  return true;
  }


// Removes all characters which appear in string bag from string s
function stripCharsInBag (s, bag)
  {
  var i;
  var returnString = "";

  // Search through string's characters one by one;
  // if character is not in bag, append to returnString
  for (i = 0; i < s.length; i++)
    {   
    // Check that current character isn't blank
    var c = s.charAt(i);
    if (bag.indexOf(c) == -1) 
      returnString += c;
    }
  return returnString;
  }


// Removes all characters which do NOT appear in string bag from string s
function stripCharsNotInBag (s, bag)
  {
  var i;
  var returnString = "";

  // Search through string's characters one by one;
  // if character is in bag, append to returnString
  for (i = 0; i < s.length; i++)
    {   
    // Check that current character isn't blank
    var c = s.charAt(i);
    if (bag.indexOf(c) != -1) 
      returnString += c;
    }
  return returnString;
  }


// Removes all blank chars (as defined by blanks) from s

function stripBlanks(s)
  {
  return stripCharsInBag(s, blanks)
  }


// Removes leading blank chars (as defined by blanks) from s

function stripLeadingBlanks(s)
  { 
  var i = 0;
  while ((i < s.length) && (blanks.indexOf(s.charAt(i)) != -1))
     i++;
  return s.substring(i, s.length);
  }


// Removes trailing blank chars (as defined by blanks) from s

function stripTrailingBlanks(s)
  { 
  var i = s.length - 1;
  while ((i >= 0) && (blanks.indexOf(s.charAt(i)) != -1))
     i--;
  return s.substring(0, i+1);
  }


// Removes leading+trailing blank chars (as defined by blanks) from s

function stripLeadingTrailingBlanks(s)
  { 
  s = stripLeadingBlanks(s);
  s = stripTrailingBlanks(s);
  return s;
  }


// Returns true if character c is an English letter (A .. Z, a..z)

function isLetter(c)
  {
  return (((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")));
  }


// Returns true if character c is a digit (0 .. 9)

function isDigit(c)
  {
  return ((c >= "0") && (c <= "9"));
  }


// Returns true if all chars in string s are numbers;
// first character is allowed to be + or -; does not 
// accept floating point, exponential notation, etc.

function isInteger(s)
  {
  //if (isBlank(s))
   // return false;

  // skip leading + or -
  if ((s.charAt(0) == "-") || (s.charAt(0) == "+"))
    var i = 1;
  else
    var i = 0;
  }
  // Search through string's chars one by one until we find a 
  // non-numeric char, then return false; if we don't, return true

function isNumeric(s)
  {
  if (isBlank(s))
    return false;

  // Search through string's chars one by one until we find a 
  // non-numeric char, then return false; if we don't, return true
  for (var i=0; i<s.length; i++)
    { 
      
    // Check that current character is number
    var c = s.charAt(i);
    if (!isDigit(c)) 
      return false;
    }
  // All characters are numbers
  return true;
  }
  

function isNumericNegative(s)
  {
  if (isBlank(s))  
    return false;

  // Search through string's chars one by one until we find a 
  // non-numeric char, then return false; if we don't, return true
  // skip leading + or -
  if ((s.charAt(0) == "-") || (s.charAt(0) == "+"))
    var i = 1;
  else
    var i = 0;
    
  for (i; i<s.length; i++)
    { 
      
    // Check that current character is number
    var c = s.charAt(i);
    if (!isDigit(c)) 
      return false;
    }
  // All characters are numbers
  return true;
  }


// True if string s is an unsigned floating point (real) number; 
// first character is allowed to be + or -; no exponential notation.

function isFloat(s)
  { 
  var j=0;
  if (s == decimalPointDelimiter) 
    return false;

  // skip leading + or -
  if ((s.charAt(0) == "-") || (s.charAt(0) == "+"))
    var i = 1;
  else
    var i = 0;

  // Search through string's chars one by one until we find a 
  // non-numeric char, then return false; if we don't, return true

  for (i; i<s.length; i++)
    {   
    // Check that current character is number
    var c = s.charAt(i);

    if (c == decimalPointDelimiter) 
	  {
	  j++;
	  if(j>1)
	    return false;
	  }
    else if (!isDigit(c)) 
      return false;
    }
    
  // All characters are numbers
  return true;
  }


// Returns true if string s is English letters (A .. Z, a..z) only

function isAlphabetic(s)
  {
  var i;

  if (isBlank(s)) 
     return false;

  // Search through string's chars one by one until we find a 
  // non-alphabetic char, then return false; if we don't, return true

  for (i = 0; i < s.length; i++)
  {   
  // Check that current character is letter
  var c = s.charAt(i);

  if (!isLetter(c))
    return false;
  }

  // All characters are letters
  return true;
  }


// Returns true if string s is English letters (A .. Z, a..z) and numbers only
// s -- String to be validated
// AllowSpace -- if space is allowed(true/false)
//AllowUnderscore -- if underscore is allowed(true/false)

function isAlphanumeric_1(s, AllowSpace, AllowUnderscore)
  {
  var i;
	
  // Search through string's chars one by one until we find a 
  // non-alphanumeric char, then return false; if we don't, return true

  for (i = 0; i < s.length; i++)
    {   
    // Check that current character is number or letter
    var c = s.charAt(i);
		if (!(isLetter(c) || isDigit(c) )){
			switch(c){
				case "_" :
					if(!AllowUnderscore) {
						return false;
					}
					break ;
				case " " :
					if(!AllowSpace){
						return false;
					}
					break ;
				case "-" :
					break;
				default :
					return false;
			}	
		}
    }

	// All characters are numbers or letters
	return true;
  }
  
  //****** Changed Function*********
  
  function isAlphanumeric(s, AllowSpace, AllowUnderscore)
  {
		
		if(s.indexOf("'") > -1){
			return false;
		}
		{
			return true;
		}	
  }
  
  //*******************************
  
  
  
  function isCompanyName(s, AllowSpace, AllowUnderscore, AllowDot)
  {
  var i;

  // Search through string's chars one by one until we find a 
  // non-alphanumeric char, then return false; if we don't, return true

  for (i = 0; i < s.length; i++)
    {   
    // Check that current character is number or letter
    var c = s.charAt(i);
		if (!(isLetter(c) || isDigit(c) )){
			switch(c){
				case "_" :
					if(!AllowUnderscore) {
						return false;
					}
					break ;
				case " " :
					if(!AllowSpace){
						return false;
					}
					break ;
				case "." :
					if(!AllowDot){
						return false;
					}
					break ;	
				default :
					return false;
			}	
		}
    }

	// All characters are numbers or letters
	return true;
  }


// reformatString(targetStr [, str1, int1, str2, int2, ... strN, intN])       
//
// Handy function for arbitrarily inserting formatting characters
// or delimiters of various kinds within targetString.
//
// reformatString() takes one required string argument, targetStr, 
// and 0-N optional string/integer-pair arguments. These optional 
// arguments specify how targetStr is to be reformatted and how/where 
// other strings are to be inserted in it.
//
// reformatString() processes the optional args in order one by one.
// * If the argument is an integer, reformatString() appends that number 
//   of sequential characters from targetStr to the resultString.
// * If the argument is a string, reformatString() appends the string
//   to the resultString.
//
// NOTE: The first argument after targetString must be a string.
// (It can be empty.)  The second argument must be an integer.
// Thereafter, integers and strings must alternate.  This is to
// provide backward compatibility to Navigator 2.0.2 JavaScript
// by avoiding use of the typeof operator.
//
// It is the caller's responsibility to make sure that we do not
// try to copy more characters from s than s.length.
//
// EXAMPLES:
//
// * To reformat a 10-digit U.S. phone number from "1234567890"
//   to "(123)456-7890" make this function call:
//   reformatString("1234567890", "(", 3, ")", 3, "-", 4)
//
// HINT:
//
// If you have a string which is already delimited in one way
// (example: a phone number delimited with spaces as "123 456 7890")
// and you want to delimit it in another way using function reformat,
// call stripCharsNotInBag() or stripBlanks() to remove unwanted 
// characters, THEN call function reformatString to delimit as desired.
//
// EXAMPLE:
//
// reformatString(stripCharsNotInBag ("123 456 7890", digits),
//           "(", 3, ") ", 3, "-", 4)

function reformatString(targetString)
  { 
  var arg;
  var sPos = 0;
  var resultString = "";

  for (var i=1; i<reformatString.arguments.length; i++)
    {
    arg = reformatString.arguments[i];
    if (i%2 == 1) 
      {
      resultString += arg;
      }
    else
      {
      resultString += targetString.substring(sPos, sPos + arg);
      sPos += arg;
      }
    }
  return resultString;
  }


// Returns true if s is valid U.S. phone number (with area code): 10 digits

function isUSPhoneNumber(s)
  { 
  
  var temp = stripCharsNotInBag(s, digits);
  return( (temp.length == digitsInUSPhoneNumber) && isValidString(s, validUSPhoneChars) );
  
  }


// Returns true if string s is a valid U.S. ZIP code: ##### or #####-####

function isZip(s) 
{

     // Check for correct zip code
     reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);

     if (!reZip.test(s)) {
          alert("Zip Code Is Not Valid! (12345 or 12345-6789)");
          return false;
     }

return true;
}

function isZIPCode(s)
  { 
  s = stripLeadingTrailingBlanks(s);

  //alert()
  //return( (stripCharsNotInBag(s, digits).length == digitsInZIPCode1) && (s.indexOf("-") == -1) && isValidString(s, validZipCodeChars) );
  //  return true;

	
  //if (s.indexOf("-") != 5)  // - in wrong place
   // return false;

  s = stripCharsNotInBag(s, digits);
 
  if (s.length == digitsInZIPCode2 || s.length == digitsInZIPCode1)
    return true;   // #####-####
  else
    return false;  // not #####-####
  }


// Returns true if s is valid 2-letter U.S. state abbreviation

function isStateCode(s)
  { 
  if (isBlank(s)) 
    return false;
  return ((USStateCodes.indexOf(s) != -1) &&
          (s.indexOf(USStateCodeDelimiter) == -1))
  }



//function to check valid email address

function isEmail(emailStr) {
/* 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)

// Check for the Email start with number.
if ('0123456789'.indexOf(emailStr.charAt(0)) >= 0) 
{
  alert("Email address seems incorrect.");
   return false; 	
}
if ('!%&\\(\\)<>@,;:\\\\\\\"\\.\\[\\]'.indexOf(emailStr.charAt(0)) >= 0) 
{
  alert("Email address seems incorrect.");
   return false; 	
}

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("Email address seems incorrect (check @ and .'s)");
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    alert("The username doesn't seem to be valid.");
    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!");
		return false;
	    }
    }
    return true;
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.");
    return false;
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   alert("The address must end in a three-letter domain, or two letter country.");
   return false;
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   //var errStr="This address is missing a hostname!"
   //alert(errStr)
   return false;
}

// If we've gotten this far, everything's valid!
//return true;
}


// Returns true if string s is an integer such that a <= s <= b

function isIntegerInRange (s, a, b)
  { 
  if (isBlank(s)) 
    return false;
  if (!isInteger(s)) 
    return false;
  var num = parseInt(s);
  return ((num >= a) && (num <= b));
  }


// Returns index of checked radio button in radio set,
// or -1 if no radio buttons are checked

function getCheckedRadioButton(radioSet)
  { 
  for (var i=0; i<radioSet.length; i++)
    if (radioSet[i].checked)
      return i;
  return -1;
  }


// Returns array containing index(es) of checked checkbox(es) 
// in checkbox set, or -1 if no checkboxes are checked

function getCheckedCheckboxes(checkboxSet)
  {
  var arr = new Array();
  for (var i=0,j=0; i<checkboxSet.length; i++)
    if (checkboxSet[i].checked)
      arr[j++] = i;
  if (arr.length > 0)
    return arr;
  else
    return -1;
  }


// Returns array containing index(es) of checked option(s) 
// in select box, or -1 if no options are selected

function getCheckedSelectOptions(select)
  {
//alert("i am here");

  var arr = new Array();
  for (var i=0,j=0; i<select.length; i++)
    if (select.options[i].selected)
      arr[j++] = i;
  if (arr.length > 0)
    return arr;
  else
    return -1;
  }


// Returns true if sdt1 > sdt2

function DateComp(sdt1,sdt2) {

	if (isDate(sdt1) && isDate(sdt2))
	{
	}
	else
	{
		return false; 
	}

	var day1 = sdt1.charAt(0) == "0" ? parseInt(sdt1.substring(1,2)) : parseInt(sdt1.substring(0,2));
	var month1 = sdt1.charAt(3) == "0" ? parseInt(sdt1.substring(4,5)) : parseInt(sdt1.substring(3,5));
	var begin1 = sdt1.charAt(6) == "0" ? (sdt1.charAt(7) == "0" ? (sdt1.charAt(8) == "0" ? 9 : 8) : 7) : 6;
	var year1 = parseInt(sdt1.substring(begin1, 10));
	var dt1 = new Date(year1,month1,day1)
	
	var day2 = sdt2.charAt(0) == "0" ? parseInt(sdt2.substring(1,2)) : parseInt(sdt2.substring(0,2));
	var month2 = sdt2.charAt(3) == "0" ? parseInt(sdt2.substring(4,5)) : parseInt(sdt2.substring(3,5));
	var begin2 = sdt2.charAt(6) == "0" ? (sdt2.charAt(7) == "0" ? (sdt2.charAt(8) == "0" ? 9 : 8) : 7) : 6;
	var year2 = parseInt(sdt2.substring(begin2, 10));
	var dt2 = new Date(year2,month2,day2)

	if (year1 > year2 ) 
	   return true;
	else
	{
	  if (year1==year2)
	  {
			if (month1 > month2)
			{
				return true;
			}
			else
			{
				if  (month1 == month2)
				{
					if (day1 > day2)
						return true;
					else
						return false ;
				}
				else
				{
					return false;
				}	
			}			
	  }
	  else
	  {
		return false;
	   }	
	}	   
}

function isDate(str) {
  if (str.length != 10) { return false }

  for (j=0; j<str.length; j++) {
   if ((j == 2) || (j == 5)) {
      if (str.charAt(j) != "/") { return false }
    } 
    else 
    {
      if ((str.charAt(j) < "0") || (str.charAt(j) > "9")) { return false }
    }
  }

  var day = str.charAt(0) == "0" ? parseInt(str.substring(1,2)) : parseInt(str.substring(0,2));
  var month = str.charAt(3) == "0" ? parseInt(str.substring(4,5)) : parseInt(str.substring(3,5));
  var begin = str.charAt(6) == "0" ? (str.charAt(7) == "0" ? (str.charAt(8) == "0" ? 9 : 8) : 7) : 6;
  var year = parseInt(str.substring(begin, 10));
  
  if (day == 0) { return false }
  if (month == 0 || month > 12) { return false }
  if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
    if (day > 31) 
    { 
     return false; 
    }
  } else {
    if (month == 4 || month == 6 || month == 9 || month == 11) {
      if (day > 30) { return false }
    } else {
      if (year%4 != 0) {
        if (day > 28) { return false }
      } else {
        if (day > 29) { return false }
      }
    }
  }
  return true;
}

	function chkNumeric(iData)
	{
		// only allow numbers to be entered
		var checkStr = iData;
		var sNewStr = '';
		var ch="";
		var i=0;
		var counter = 0 ;
		for(i=0;;i++)
		{
			ch = checkStr.charAt(i);
			if (ch == "0" || ch =="1"  || ch =="2"  || ch =="3"  || ch =="4"  || ch =="5"  || ch =="6"  || ch =="7"  || ch =="8"  || ch =="9"  || ch == ".")
			{
				if (ch=='.')
				{
					counter++;
					if (counter > 1 )
					{ 
					    return sNewStr ;
					 }	
					    
				}
				sNewStr = sNewStr + ch ;

			}
			else
			{
				 return sNewStr ;
			}
		if (i == checkStr.length-1) break;
		}
		return iData;
	  }			


//function to format value in currency fields

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + '.' + cents);
}

	function checkURLNew(sUrl)
	{
		var url = false ;
		var isNot = "`!@$^*()[{]}\|;'',<> " ;
		if (sUrl.length != 0 )
		{
//			if (sUrl.indexOf('://') != -1)
//			{
				if (sUrl.indexOf('"') == -1)
				{
					url = true ;
					if (sUrl.length <= 7 )
					{
						url = false ;	
					}
					for (i=0;i!=sUrl.length;++i)
					{
						if (isNot.indexOf(sUrl.substring(i,i+1)) != -1)
						{
							url = false ;	
						}
					}
					//Checking for .com, .net, .org	in the URL				
					if (sUrl.indexOf('.com') != -1)
					{
						url = true ;						
					}
					else
					{
						if (sUrl.indexOf('.net') != -1)
						{
							url = true ;
						}
						else
						{
							if(sUrl.indexOf('.org') != -1)
							{
								url = true ;
							}
							else
							{
								url = false ;
							}
						}
					}
					//
				}
//			}
		}
		else{
			url=true;
		}	
		if (url == false )
		{
			alert('In valid URL') ;
			return false;
		}
		else
		{
			//checkURLNew = true ;
			return true ;
		}	
	}

function checkURL(sUrl)
{
	var url = false ;
	var isNot = "`!@$^*()[{]}\|;'',<> " ;
	if (sUrl.length != 0 )
	{
		if (sUrl.indexOf('://') != -1)
		{
			if (sUrl.indexOf('"') == -1)
			{
				url = true ;
				if (sUrl.length <= 7 )
				{
					url = false ;	
				}
				for (i=0;i!=sUrl.length;++i)
				{
					if (isNot.indexOf(sUrl.substring(i,i+1)) != -1)
					{
						url = false ;	
					}
				}
			}
		}
	}	
	if (url == false )
	{
		alert('In valid URL') ;
		return false;
	}
}

function isValidFile(file) 
{
	var extArray = new Array(".gif", ".jpg", ".png", ".jpeg", ".bmp");
	var allowSubmit = false;
	var ext 
	while (file.indexOf("\\") != -1)
	{
		file = file.slice(file.indexOf("\\") + 1);
	}
	ext = file.slice(file.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray.length; i++) 
	{
		if (extArray[i] == ext) 
		{ 
			allowSubmit = true; 
			break; 
		}
	}

	if (allowSubmit)
	{ 
		return true;
	}
	else
	{
		return false;
	}
}

function trimme(strName)
{
  var strTemp = "";
  strTemp = strName;
  var i = 0;

  if(strName.indexOf(" ") == 0)
  {
    for(i=0;i<=strTemp.length;i++)
    {
      if(strName.indexOf(" ") == 0)
      {
       strName = strName.substr(1);
      }  
      else
        break;   
    }
  }
  if(strName == "")
	return false;
  else
	return true;
}


function clearText(str)
{
 var temp;
 var i;	
 for(i=0;i<=str.length-1;i++)
 {
    temp = str.indexOf('\"')
	temp=str.replace('\"'," ");
	
 	str = temp ;
 	
 	temp = str.indexOf("'","`")
 	temp = str.replace("'","`");
 	
 	str = temp ;
 }
 
 return str;
	
}	

function isCurrency(num){
	var pos ;
	var count ;
	if(!isFloat(num))
		return false;
	else{
		for (i=0;i<=num.length-1;i++){
			if (num.charAt(i) == "."){
				pos = i;
			}
		}	

		if(pos >= 0){
			if(eval(num.substring(pos+1)) == 0){
			   
				//return false;
			}
			count = num.length - (pos+1);
		}
		else{
			return true;
		}
		if(count == 1 || count == 2)
			return true;
		else
			return false ;
	}
}
	
//Call this Function to allow Multiple Validations in one Statement



function ValidateMultiple(compname,compulsary,onval,var1,var2)
{
	/*
		compname == this is the component name ex:document.formname.txtText
		compulsary == blank not allowed
		onval == which type of validation ex:isAlphanumeric,isEmail,isUSPhoneNumber
	*/
	if (compulsary == 'Y')
	{
		if(isBlank(compname.value))
		{
			alert(compname.title + " Cannot be blank");
			compname.focus();
			return false;
		}
		else
		{
		
			if (onval == isAlphanumeric)
			{			
				
				if(!onval(compname.value, var1, var2))
				{
					alert(compname.title + " : Invalid Entry");
					compname.focus();				
					return false;
				}
			}
			else
			{
				if(!onval(compname.value))
				{
					alert(compname.title + " : Invalid Entry");
					compname.focus();				
					return false;
				}				
			}
		}
	}
	if (compulsary == 'N')
	{
		if (onval == isAlphanumeric)
		{
			if(!isBlank(compname.value)){
				if(!onval(compname.value, var1, var2))
					{
						alert(compname.title + " : Invalid Entry");
						compname.focus();				
						return false;
					}
			}
		}
		else
		{
			if(!isBlank(compname.value)){
				if(!onval(compname.value))
				{
					alert(compname.title + " : Invalid Entry");
					compname.focus();				
					return false;
				}			
			}	
		}
	}
	return true;		
}

//Function to check the dates
	function isDateGreater(sDate,eDate)
	{
	
		var cnt =0;
		var cnt1 =0;
		var mo="";
		var mo1="";
		var dy="";
		var dy1="";
		var yr="";
		var yr1="";
		for (i=0;i<=sDate.length-1;i++)
		{
			if (sDate.charAt(i) != "/")
			{
				if (cnt == 0)
				{
					mo = mo + sDate.charAt(i);
				}
				if (cnt == 1)
				{
					dy = dy + sDate.charAt(i);
				}				
				if (cnt == 2)
				{
					yr = yr + sDate.charAt(i);
				}							
			}
			else
			{ 
				cnt = cnt+1;
			}
		}
		for (j=0;j<=eDate.length-1;j++)
		{
			if (eDate.charAt(j) != "/" )
			{
				if (cnt1 == 0)
				{
					mo1 = mo1 + eDate.charAt(j);
				}
				if (cnt1 == 1)
				{
					dy1 = dy1 + eDate.charAt(j);
				}
				if (cnt1 == 2)
				{
					yr1 = yr1 + eDate.charAt(j);
				}				
			}
			else
			{ 
				cnt1 = cnt1+1;
			}
		}		
		mo = Number(mo);
		mo1 = Number(mo1);
		dy = Number(dy);
		dy1 = Number(dy1);
		yr = Number(yr);
		yr1 = Number(yr1);
		
		var vDate = new Date(yr, mo, dy, 0, 0, 0)
		var mDate = new Date(yr1, mo1, dy1, 0, 0, 0)
		if(vDate > mDate)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	

	/// checking the Scale of the amount
	function checkCurrency(s){
	var pos, count ,i;
	pos=0;
	
	 count=s.length
	
	for (i=0;i<=count-1;i++){
			if (s.charAt(i) == "."){
				pos = i;
			}
	 }	
	 
	  if(pos==0){
	 
			if(i > 11 ){
				return false;
			}			
	  }
	  else{
		   if(pos >11){
				return false;
		   }	
	  }
	return true;	   
   }




function CheckTime(obj)
{	
	var dateStr = new String(obj.value);
	var timePat = /^(\d{1,2})(\:)(\d{2})$/;
	var matchArray = dateStr.match(timePat); 
	if (matchArray == null) {
		alert("Invalid time format. Please specify it in 00:00 format only");
		return false;
	}
	hour = matchArray[1]; 
	min = matchArray[3];
	if (hour < 0 || hour > 23) { 
		alert("Hours must be between 1 and 24");
		return false;
	}
	if (min < 0 || min > 59) {
	alert("Minutes must be between 0 and 59.");
	return false;
	}
}		



function CheckTimeAMPM(obj)
{	
	var dateStr = new String(obj.value);
	var timePat = /^(\d{1,2})(\:)(\d{2})(\:)(\d{2})(\s)([p|P|a|A])([m|M])$/;
	var matchArray = dateStr.match(timePat); 
	if (matchArray == null) {
		alert("Invalid time format. Please specify it in 00:00:00 AM/PM format only");
		return false;
	}
	hour = matchArray[1]; 
	min = matchArray[3];
	if (hour < 0 || hour > 12) { 
		alert("Hours must be between 0 and 12");
		return false;
	}
	if (min < 0 || min > 59) {
	alert("Minutes must be between 0 and 59.");
	return false;
	}
}		