/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Eric Poulin (epoulin@decisionplus.com
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


// whitespace characters
var whitespace = " \t\n\r";

var LastError = "";


// Call this member function to trim trailing whitespace characters
// from the string. Removes trailing newline, space, and tab
// characters from the string
function TrimRight( astr )
{
	for( i = astr.length - 1; i >= 0; i = i - 1 )
	{
		// Check that current character isn't whitespace.
		var c = astr.charAt(i);

		if( whitespace.indexOf(c) == -1 )
		{
			// Found non whitespace character, trim string and return
			astr = astr.substring( 0, i+1 );
			return astr;
		}

	}  // end of i loop

	return( "" ); // String contains only whitespace character!
}

// Call this member function to trim leading whitespace characters from
// the string. Removes newline, space, and tab characters.
function TrimLeft( astr )
{
	for( i = 0; i < astr.length; i++ )
	{
		// Check that current character isn't whitespace.
		var c = astr.charAt(i);

		if( whitespace.indexOf(c) == -1 )
		{
			// Found non whitespace character, trim string and return
			astr = astr.substring( i );
			return astr;
		}

	}  // end of i loop

	return( "" ); // String contains only whitespace character!
}



function isIn( astr, nstr, bstrip )
// astr :  item in question
// nstr :  allowable character string; defaults to numbers
// bstrip:  determines whether return is true/false or only allowable characters.  Defaults to false.
{
	//declare and initialize variables to make sure they stay local
	var cc='';
	var dd='';
	var bstr = '';
	var isit;
	var i = 0;

	//force number to a string
	astr = '' + astr;

	//default to checking for a number
	if (nstr== null || nstr == '')
		nstr = '1234567890';

	//just a check to make sure that it quits here
	//if (isit == null) alert('...but I went on anyway!')
	//now that everything is set up, let's get down to business
	isit = false;

	// begin loop which cycles through all of the characters in astr
	for (i = 0 ; i < astr.length ; i++)
	{
		cc = astr.substring(i, i+1);

		// begin loop which cycles through
		// all of the characters in nstr

		for (j =0 ; j< nstr.length ; j++)
		{
			dd = nstr.substring(j, j + 1);

			//alert('i = ' + i + '\n' + 'j = ' + j  +  '\n' + 'cc = ' + cc + '\n' + 'dd = ' +  dd + '\n' + isit)
			isit = false;

			if (cc == dd)      // so far so good
			{
				isit = true;
				bstr += cc;    // accumulate good characters
				break;         // no need to go further
			}

		}  // end of j loop

		//you found a mismatch; disqualify the item immediately
		//unless you are going to strip the string.

		if( isit == false && !bstrip )
			break;
		else
			continue;

	}  // end of i loop

	if( bstrip )
		return bstr;  // return stripped string
	else
		return isit;  // or return true/false (boolean)
}

//-- Shows number in xxx.xx format and pads left side with blanks.
function currency( anynum, width )
{
	anynum = eval(anynum);

	workNum = Math.abs((Math.round(anynum*100)/100));
	workStr = "" + workNum;

	if( workStr.indexOf(".") == -1 )
		workStr+=".00";

	dStr = workStr.substr( 0, workStr.indexOf(".") );

	dNum = dStr - 0;

	pStr = workStr.substr( workStr.indexOf(".") );

	while (pStr.length<3)
	{
		pStr += "0";
	}

	retval = dStr + pStr;

	if( anynum < 0 )
	{
	  retval = retval.substring( 1, retval.length );
	  retval = "(" + retval + ")";
	}

	//--Pad with leading blanks to better align numbers.
	while( retval.length < width )
	{
		retval = " " + retval;
	}

	return retval;
}


// Original JavaScript code by Duncan Crombie: dcrombie@chirp.com.au
// Please acknowledge use of this code by including this header.

// A '#' means that a decimal place is shown if required. A '0' means
// that a decimal place or leading zero is always shown. A comma indicates the number
// should be broken into thousands and a percent or dollar symbol convert the number to that type.
//
// Examples
//
// formatNumber(3, "$0.00") 			= $3.00
// formatNumber(3.14159265, "##0.####") = 3.1416
// formatNumber(3.14, "0.0###%") 		= 314.0%
// formatNumber(314159, ",##0.####") 	= 314,159
// formatNumber(31415962, "$,##0.00") 	= $31,415,962.00
// formatNumber(cat43, "0.####%") 		= null
// formatNumber(.5, "#.00##") 			= .50
// formatNumber(.5, "0.00##") 			= 0.50
// formatNumber(.5, "00.00##") 			= 00.50
// formatNumber(4.44444, "0.00") 		= 4.44
// formatNumber(5.55555, "0.00") 		= 5.56
// formatNumber(9.99999, "0.00") 		= 10.00


// CONSTANTS
var separator = ","; // use comma as 000's separator
var decpoint = "."; // use period as decimal point
var percent = "%";
var currency_char = "$"; // use dollar sign for currency

function strip(input, chars)  // strip all characters in 'chars' from input
{
    var output = ""; // initialise output string
    for (var i=0; i < input.length; i++)
      if (chars.indexOf(input.charAt(i)) == -1)
        output += input.charAt(i);
    return output;
}



function separate(input, separator) // format input using 'separator' to mark 000's
{
    var output = ""; // initialise output string
    for (var i=0; i < input.length; i++) {
      if (i != 0 && (input.length - i) % 3 == 0) output += separator;
      output += input.charAt(i);
    }
    return output;
}



function formatNumber(number, format, print) // use: formatNumber(number, "format")
{
    if (print)
      document.write("formatNumber(" + number + ", \"" + format + "\")<br>");

    if (number - 0 != number) return null; // if number is NaN return null
    var useSeparator = format.indexOf(separator) != -1; // use separators in number
    var usePercent = format.indexOf(percent) != -1; // convert output to percentage
    if (usePercent) number *= 100;
    var useCurrency = format.indexOf(currency_char) != -1; // use currency format
    format = strip(format, separator + percent + currency_char); // remove key characters
    number = "" + number; // convert number input to string

    // split number and format into LHS and RHS using decpoint as divider
    var dec = number.indexOf(decpoint) != -1;
    var nleftEnd = (dec) ? number.substring(0, number.indexOf(".")) : number;
    var nrightEnd = (dec) ? number.substring(number.indexOf(".") + 1) : "";
    dec = format.indexOf(decpoint) != -1;
    var sleftEnd = (dec) ? format.substring(0, format.indexOf(".")) : format;
    var srightEnd = (dec) ? format.substring(format.indexOf(".") + 1) : "";

    // adjust decimal places by cropping or adding zeros to LHS of number
    if (srightEnd.length < nrightEnd.length) {
      var nextChar = nrightEnd.charAt(srightEnd.length) - 0;
      nrightEnd = nrightEnd.substring(0, srightEnd.length);
      if (nextChar >= 5) nrightEnd = "" + ((nrightEnd - 0) + 1); // round up
      if (srightEnd.length < nrightEnd.length) {
        nrightEnd = nrightEnd.substring(1);
        nleftEnd = (nleftEnd - 0) + 1;
      }
    } else {
      for (var i=nrightEnd.length; srightEnd.length > nrightEnd.length; i++) {
        if (srightEnd.charAt(i) == "0") nrightEnd += "0"; // append zero to RHS of number
        else break;
      }
    }

    // adjust leading zeros
    sleftEnd = strip(sleftEnd, "#"); // remove hashes from LHS of format
    while (sleftEnd.length > nleftEnd.length)
      nleftEnd = "0" + nleftEnd; // prepend zero to LHS of number

    if (useSeparator) nleftEnd = separate(nleftEnd, separator); // add separator
    var output = nleftEnd + ((nrightEnd != "") ? "." + nrightEnd : ""); // combine parts
    return ((useCurrency) ? currency_char : "") + output + ((usePercent) ? percent : "");
}



 var InputChars  = "ÇüéâäàåçêëèïîìÄÅÉôöòûùÿÖÜáíóúñÑ";
 var OutputChars = "CueaaaaceeeiiiAAEooouuyOUaiounN";

 function ReplaceSpecialChars( text )
 {
 	var result = "";

    for( var i=0; i < text.length; i++ )
    {
    	var c = text.charAt(i);
    	var p = InputChars.indexOf(c);

      	if( p != -1 )
      	{
      		result += OutputChars.charAt(p);
      	}
      	else
      		result += c;
    }

    return( result );
 }




<!-- Version 1.1:  Sandeep V. Tamhankar (stamhankar@hotmail.com) -->
function emailCheck( 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 represents the range of characters allowed as
	// the first character in a valid username or domain.  I just made it
	// the same as above, but if you want to add a different constraint,
	// you would change it here.
	var firstChars=validChars

	// 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 at atom (basically a series of
	// non-special characters.)
	var atom="(" + firstChars + 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 course 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.
		LastError = "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
		LastError = "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)
			{
				LastError = "Destination IP address is invalid!";
				return false
			}
		}

		return true
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)

	if (domainArray==null)
	{
		LastError = "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).
	// If there's a country code at the end of the address, the full domain
	// must include a hostname and category (e.g. host.co.uk or host.pub.nl).
	// If it ends in a .com or something, make sure there's a hostname.

	// 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.
		LastError = "The address must end in a three-letter domain, or two letter country.";
		return false
	}

	// If it ends in a country code, we want to make sure there are at
	// least 2 atoms preceding it (representing host and category (i.e.
	// com, gov, etc.))

	/* E.P. 02/06/2000: INVALID CHECK BECAUSE "epoulin@sympatico.ca" IS A VALID ADRESS!!!
	if (domArr[domArr.length-1].length==2 && len<3)
	{
		LastError  = "This address ends in two characters, which is a country "
		LastError += "code.  Country codes must be preceded by "
		LastError += "a hostname and category (like com, co, pub, pu, etc.)"
		return false
	}
	*/

	// If it just ends in .com, .gov, etc., make sure there is a host name.
	// This case can never actually happen because earlier checks take
	// care of this implicitly, but we will do it anyway.
	if (domArr[domArr.length-1].length==3 && len<2)
	{
		LastError = "This address is missing a hostname!";
		return false
	}

	// If we have gotten this far, everything is valid!
	return true;
}

function Popup( Url )
{
	window.open( Url, "new", "toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=600,height=200,screenX=0,screenY=30,top=30,left=0" );
}

// Return true of false depending if the input string (astr) contains
// one of the characters in (nstr)
function ContainsOneOf( astr, nstr )
// astr :  input string
// nstr :  list of characters to verify
{
	//declare and initialize variables to make sure they stay local
	var cc='';
	var dd='';
	var bstr = '';
	var isit = false;
	var i = 0;

	//force number to a string
	astr = '' + astr;

	if( nstr != null && nstr != '' )
	{
		// begin loop which cycles through all of the characters in astr
		for (i = 0 ; i < astr.length ; i++)
		{
			cc = astr.substring(i, i+1);

			// begin loop which cycles through
			// all of the characters in nstr

			for (j =0 ; j< nstr.length ; j++)
			{
				dd = nstr.substring(j, j + 1);

				isit = false;

				if( cc == dd )      // find one!
				{
					isit = true;
					break;         // no need to go further
				}

			}  // end of j loop

			if( isit == true )
				break;

		}  // end of i loop
	}

	return isit;
}
