//common Javascript validations
// CODE to be put into xsl to call up this file =   <script language="JavaScript" src="validation.js"></script>

//Date function
var dayName = new Array ("Søndag","Mandag","Tirsdag","Onsdag","Torsdag","Fredag","Lørdag")
var monName = new Array ("januar", "februar", "marts", "april", "maj", "juni", "juli", "august", "september", "oktober", "november", "december")
now = new Date

// Confirm if Checkbox is Checked

function isChecked(theForm, strCtlName)
{
	intIndicator = -1
	for(i=0; i<theForm.elements[strCtlName].length; i++)
	{
		if (theForm.elements[strCtlName][i].checked)
		{
			intIndicator = i
		}
	}

	             
	if (intIndicator == -1)
	{		
		return (false);		
	}
	return (true);
}

// Is this a number check

//function isNum(frame,field,fieldname) {
//	var passedVal = eval("window" + frame.name + ".document.forms[0]." + field.name)
//	if (passedVal == "") {
//	return (false);
//	}
//	for (i=0; i<passedVal.length; i++) {
//	if (passedVal.charAt(i) < "0") {
//	alert("Error in " + fieldname + ". Please enter numbers only.");
//	passedVal.focus();
//	passedVal.select();
//	return (false);
//	}
//	if (passedVal.charAt(i) > "9") {
//	alert("Error in " + fieldname + ". Please enter numbers only."); 
//	passedVal.focus();
//	passedVal.select();
//	return (false);
//	}
//	}
//	return (true);
//	}

function isNum(passedVal,fieldname) {
	if (passedVal == "") {
	return (false);
	}
	for (i=0; i<passedVal.length; i++) {
	if (passedVal.charAt(i) < "0") {
	alert("Error in " + fieldname + ". Please enter numbers only.");  return (false);
	}
	if (passedVal.charAt(i) > "9") {
	alert("Error in " + fieldname + ". Please enter numbers only.");  return (false);
	}
	}
	return (true);
	}
	
// isNum function without error messages
function isNum2(passedVal) {
	if (passedVal == "") {
	return (false);
	}
	for (i=0; i<passedVal.length; i++) {
	if (passedVal.charAt(i) < "0") {
		return (false);
	}
	if (passedVal.charAt(i) > "9") {
		return (false);
	}
	}
	return (true);
	}
	
// Is this a number or a dot check
function isNum3(passedVal,fieldname) {
	if (passedVal == "") {
	return (false);
	}
	for (i=0; i<passedVal.length; i++) {
	if (passedVal.charAt(i) < "0" && passedVal.charAt(i) != ".") {
	alert("Error in " + fieldname + ". Please enter numbers only.");  return (false);
	}
	if (passedVal.charAt(i) > "9" && passedVal.charAt(i) != ".") {
	alert("Error in " + fieldname + ". Please enter numbers only.");  return (false);
	}
	}
	return (true);
	}

// Is this a number or a space check

function isNo(passedVal,fieldname) {
	if (passedVal == "") {
	return (false);
	}
	for (i=0; i<passedVal.length; i++) {
	if (passedVal.charAt(i) < "0" && passedVal.charAt(i) != " ") {
	alert("Error in " + fieldname + ". Please enter numbers or spaces only.");  return (false);
	}
	if (passedVal.charAt(i) > "9" && passedVal.charAt(i) != " ") {
	alert("Error in " + fieldname + ". Please enter numbers or spaces only.");  return (false);
	}
	}
	return (true);
	}

// Is this a number or a dash check

function isNoOrDash(passedVal) {
	if (passedVal == "") {
	return (false);
	}
	for (i=0; i<passedVal.length; i++) {
	if (passedVal.charAt(i) < "0" && passedVal.charAt(i) != "-") {
	return (false);
	}
	if (passedVal.charAt(i) > "9" && passedVal.charAt(i) != "-") {
	return (false);
	}
	}
	return (true);
	}

// Is this a number of a forward slash for dates check

	function isNoOrSlash(passedVal) {
	if (passedVal == "") {
	return (false);
	}
	for (i=0; i<passedVal.length; i++) {
	if (passedVal.charAt(i) < "0" && passedVal.charAt(i) != "/") {
	return (false);
	}
	if (passedVal.charAt(i) > "9" && passedVal.charAt(i) != "/") {
	return (false);
	}
	}
	return (true);
	}
	
// valid Tax Code ?

function validTaxCode(inTaxCode) {
	highDigitsInITTaxCode = 8
	lowDigitsInITTaxCode = 8
	if (inTaxCode == "") {
	return (true);
	}
	if (inTaxCode.length < lowDigitsInITTaxCode) {
	return (false);
	}
	if ((inTaxCode.length != lowDigitsInITTaxCode) && (inTaxCode.length != highDigitsInITTaxCode)){
	return (false);
	}
	if (isNum(inTaxCode)) {
	return (true);
	}
	return (false);
	}


// Valid postcode ?

function validZip(inZip) {
	invalidChars = " /:,;()-+{}"
	digitsInZIPCode1 = 4
	digitsInZIPCode2 = 4
	
	if (inZip == "") {
	return (true);
	}
	if ((inZip.length != digitsInZIPCode1) && (inZip.length != digitsInZIPCode2)){
	return (false);
	}

	if (isNum(inZip)) {// Check if Zip is numeric
	return (true);
	}

	return (false);
	}

// valid Partita IVA number (Personal Tax Code) ?

function validPartitaNumber(inPartitaNumber) {
	invalidChars = " /:,;()+{}"
	digitsInPartitaNumber = 10

	if (inPartitaNumber == "") {
	return (true);
	}
	if (inPartitaNumber.length < digitsInPartitaNumber) {
	return (false);
	}
	if (isNoOrDash(inPartitaNumber)) {
	return (true);
	}
	for (i=0; i<invalidChars.length; i++) {	// does it contain any invalid characters?
	badChar = invalidChars.charAt(i)
	if (inPartitaNumber.indexOf(badChar,0) > -1) {
	return (false);
	}
	}
	return (false);
	}


// valid phone number ?

function validPhoneNumber(inPhoneNumber) {
	invalidChars = "/:,;()-+{}"
	mindigitsInDKPhoneNumber = 8

	if (inPhoneNumber == "") {
	return (true);
	}
	if (inPhoneNumber.length < mindigitsInDKPhoneNumber) {
	return (false);
	}
	if (isNo(inPhoneNumber)) {// Check if Phone Number is numeric
	return (true);
	}
	for (i=0; i<invalidChars.length; i++) {	// does it contain any invalid characters?
	badChar = invalidChars.charAt(i)
	if (inPhoneNumber.indexOf(badChar,0) > -1) {
	return (false);
	}
	}
	return (false);
	}


function validFaxNumber(inFaxNumber) { // Is this a valid Fax Number?
	invalidChars = "/:,;()-+{}"
	mindigitsInDKFaxNumber = 8

	if (inFaxNumber == "") {
	return (true);
	}
	if (inFaxNumber.length < mindigitsInDKFaxNumber) {
	return (false);
	}
	if (isNo(inFaxNumber)) {// Check if Fax Number is numeric
	return (true);
	}
	for (i=0; i<invalidChars.length; i++) {	// does it contain any invalid characters?
	badChar = invalidChars.charAt(i)
	if (inFaxNumber.indexOf(badChar,0) > -1) {
	return (false);
	}
	}
	return (false);
	}



function validEmail(email,fieldname) {
	invalidChars = " /:,;"
	if (email == "") {						// cannot be empty
	return (true);
	}
	for (i=0; i<invalidChars.length; i++) {	// does it contain any invalid characters?
	badChar = invalidChars.charAt(i)
	if (email.indexOf(badChar,0) > -1) {
	alert ("Error in " + fieldname + ". Please enter a valid address.");
	return (false);
	}
	}
	atPos = email.indexOf("@",1)			// there must be one "@" symbol
	if (atPos == -1) {
	alert ("Error in " + fieldname + ". Please enter a valid address.");
	return (false);
	}
	if (email.indexOf("@",atPos+1) != -1) {	// and only one "@" symbol
	alert ("Error in " + fieldname + ". Please enter a valid address.");
	return (false);
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {					// and at least one "." after the "@"
	alert ("Error in " + fieldname + ". Please enter a valid address.");
	return (false);
	}
	if (periodPos+3 > email.length)	{		// must be at least 2 characters after the "."
	alert ("Error in " + fieldname + ". Please enter a valid address.");
	return (false);
	}
	return true
	}


//Function checks for valid dates and does not allow future dates
function isDateWithoutDelimiterFuture(str,fieldname) {
  invalidChars = " :,;()-+{}."
  if ((str.length != 10) || (str.charAt(2) != "/") || (str.charAt(5) != "/")) { alert("Please enter " + fieldname + " in the format DD/MM/YYYY."); 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(4) == "0" ? (str.charAt(7) == "0" ? (str.charAt(8) == "0" ? 9 : 8) : 7) : 6;
  var year = parseInt(str.substring(6, 10));

  var now = new Date();
  var CurMonth = now.getMonth()+1;
  var CurDay = now.getDate();
  var CurYear = now.getFullYear();
 	
  //alert("year=" + year + "CurYear=" + CurYear+"DAY="+CurDay+"MONTH="+CurMonth + "Day=" + day + "month=" + month);
  
  if(( year > CurYear ) || ((year == CurYear) && (month > CurMonth)) ||
	((year == CurYear) && (month == CurMonth) && (day > CurDay)))
       {	
		alert("Error in " + fieldname + ". A future date is not allowed.");
		return false;
	   }
	//Checks if any invalid characters are entered
	for (i=0; i<invalidChars.length; i++) {
	badChar = invalidChars.charAt(i)
	if (str.indexOf(badChar,0) > -1) {
	alert("Error in " + fieldname + ". Invalid characters.")
	return (false);
	}
	}
	//Checks if value is numeric
	if(!isNoOrSlash(str))
	{
	alert("Error in " + fieldname + ". Date can only be comprised of numerical characters or a forward slash.")
	return false;
	}

  if (day == 0) { alert("Error in " + fieldname + ". Day not valid."); return false }
  if (month < 1 || month > 12) { alert("Error in " + fieldname + ". Month not valid."); return false }
  if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
    if (day > 31) { alert("Error in " + fieldname + ". Date can not be more than 31 for the month specified."); return false }
  } else {
    if (month == 4 || month == 6 || month == 9 || month == 11) {
      if (day > 30) { alert("Error in " + fieldname + ". Date can not be more than 30 for the month specified."); return false }
    } else {
      if (year%4 != 0) {
        if (day > 28) { alert("Error in " + fieldname + ". Date can not be more than 28 for the month and year specified."); return false }
      } else {
        if (day > 29) { alert("Error in " + fieldname + ". Date can not be more than 29 for the month and year specified."); return false }
      }
    }
  }
  return true;
}

// checks for MM/YYYY date format
function isMMYYYYDateWithoutDelimiterFuture(str,fieldname) {
  invalidChars = " :,;()-+{}."
  if (str.length != 7) { alert("Please enter " + fieldname + " in the format MM/YYYY."); return false }

  var month = str.charAt(0) == "0" ? parseInt(str.substring(1,2)) : parseInt(str.substring(0,2));
  var year = parseInt(str.substring(3, 7));

  var now = new Date();
  var CurMonth = now.getMonth()+1;
  //var CurDay = now.getDate();
  var CurYear = now.getFullYear();
 	
  //alert("year=" + year + "CurYear=" + CurYear+"DAY="+CurDay+"MONTH="+CurMonth + "Day=" + day + "month=" + month);
  
  if( (year > CurYear)  || ((year == CurYear) && (month > CurMonth)))
       {	
		alert("Error in " + fieldname + ". A future date is not allowed.");
		return false;
	   }
	//Checks if any invalid characters are entered
	for (i=0; i<invalidChars.length; i++) {
	badChar = invalidChars.charAt(i)
	if (str.indexOf(badChar,0) > -1) {
	alert("Error in " + fieldname + ". Invalid characters.")
	return (false);
	}
	}
	//Checks if value is numeric
	if(!isNoOrSlash(str))
	{
	alert("Error in " + fieldname + ". Date can only be comprised of numerical characters or a forward slash.")
	return false;
	}

  if (month < 1 || month > 12) { alert("Error in " + fieldname + ". Month not valid."); return false }

  return true;
}

//**************************************************************************************
//DATE SPECIFIC FUNCTIONALITY
//**************************************************************************************

// Global variable defaultEmptyOK defines default return value
// for many functions when they are passed the empty string.
// By default, they will return defaultEmptyOK.
//
// defaultEmptyOK is false, which means that by default,
// these functions will do "strict" validation.  Function
// isInteger, for example, will only return true if it is
// passed a string containing an integer; if it is passed
// the empty string, it will return false.
//
// You can change this default behavior globally (for all
// functions which use defaultEmptyOK) by changing the value
// of defaultEmptyOK.
//
// Most of these functions have an optional argument emptyOK
// which allows you to override the default behavior for
// the duration of a function call.
//
// This functionality is useful because it is possible to
// say "if the user puts anything in this field, it must
// be an integer (or a phone number, or a string, etc.),
// but it's OK to leave the field empty too."
// This is the case for fields which are optional but which
// must have a certain kind of content if filled in.

var defaultEmptyOK = false;

// whitespace characters
var whitespace = " \t\n\r";

// Attempting to make this library run on Navigator 2.0,
// so I'm supplying this array creation routine as per
// JavaScript 1.0 documentation.  If you're using
// Navigator 3.0 or later, you don't need to do this;
// you can use the Array constructor instead.

function makeArray(n) {
//*** BUG: If I put this line in, I get two error messages:
//(1) Window.length can't be set by assignment
//(2) daysInMonth has no property indexed by 4
//If I leave it out, the code works fine.
//   this.length = n;
   for (var i = 1; i <= n; i++) {
      this[i] = 0
   }
   return this;
}



var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;



// isDate (STRING year, STRING month, STRING day)
//
// isDate returns true if string arguments year, month, and day
// form a valid date.
//

function isDate (year, month, day)
{   // catch invalid years (not 2- or 4-digit) and invalid months and days.
    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;

    // Explicitly change type to integer to make code work in both
    // JavaScript 1.1 and JavaScript 1.2.
    var intYear = parseInt(year, 10);
    var intMonth = parseInt(month, 10);
    var intDay = parseInt(day, 10);

    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth]) return false;

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}

// isYear (STRING s [, BOOLEAN emptyOK])
//
// isYear returns true if string s is a valid
// Year number.  Must be 2 or 4 digits only.
//
// For Year 2000 compliance, you are advised
// to use 4-digit year numbers everywhere.
//
// And yes, this function is not Year 10000 compliant, but
// because I am giving you 8003 years of advance notice,
// I don't feel very guilty about this ...
//
// For B.C. compliance, write your own function. ;->
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isYear (s)
{   if (isEmpty(s))
       if (isYear.arguments.length == 1) return defaultEmptyOK;
       else return (isYear.arguments[1] == true);
    if (!isNonnegativeInteger(s)) return false;
    return (s.length == 4) ||(s.length == 2) ;
}

// isMonth (STRING s [, BOOLEAN emptyOK])
//
// isMonth returns true if string s is a valid
// month number between 1 and 12.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isMonth (s)
{   if (isEmpty(s))
       if (isMonth.arguments.length == 1) return defaultEmptyOK;
       else return (isMonth.arguments[1] == true);
    if (s.length != 2) return false;
    return isIntegerInRange (s, 1, 12);
}


// isDay (STRING s [, BOOLEAN emptyOK])
//
// isDay returns true if string s is a valid
// day number between 1 and 31.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isDay (s)
{   if (isEmpty(s))
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);
    if (s.length != 2) return false;
    return isIntegerInRange (s, 1, 31);
}


// daysInFebruary (INTEGER year)
//
// Given integer argument year,
// returns number of days in February of that year.

function daysInFebruary (year)
{   // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

// Check whether string s is empty.

function isEmpty(s)
{   
	if  ((s == null))
		return true;
	  s = stripWhitespace (s);
	  if (s.length == 0)
		return true;
	return false
}


// Returns true if string s is empty or
// whitespace characters only.

function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    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 whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

// Removes all whitespace characters from s.
// Global variable whitespace (see above)
// defines which characters are considered whitespace.

function stripWhitespace (s)

{   return stripCharsInBag (s, whitespace);
}

// isIntegerInRange (STRING s, INTEGER a, INTEGER b [, BOOLEAN emptyOK])
//
// isIntegerInRange returns true if string s is an integer
// within the range of integer arguments a and b, inclusive.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.


function isIntegerInRange (s, a, b)
{   if (isEmpty(s))
       if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
       else return (isIntegerInRange.arguments[1] == true);

    // Catch non-integer strings to avoid creating a NaN below,
    // which isn't available on JavaScript 1.0 for Windows.
    if (!isInteger(s, false)) return false;

    // Subtract 0 from number to eliminate any leading zeroes.
    // (Because leading zeroes imply an octal number!)
    s = s - 0;
    // Now, explicitly change the type to integer via parseInt
    // so that the comparison code below will work both on
    // JavaScript 1.2 (which typechecks in equality comparisons)
    // and JavaScript 1.1 and before (which doesn't).
    var num = parseInt (s, 10);
    return ((num >= a) && (num <= b));
}

// isNonnegativeInteger (STRING s [, BOOLEAN emptyOK])
//
// Returns true if string s is an integer >= 0.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isNonnegativeInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isNonnegativeInteger.arguments.length > 1)
        secondArg = isNonnegativeInteger.arguments[1];

    // The next line is a bit byzantine.  What it means is:
    // a) s must be a signed integer, AND
    // b) one of the following must be true:
    //    i)  s is empty and we are supposed to return true for
    //        empty strings
    //    ii) this is a number >= 0

    return (isSignedInteger(s, secondArg) && ( (isEmpty(s) && secondArg)  || (parseInt (s, 10) >= 0) ) );
}

// isSignedInteger (STRING s [, BOOLEAN emptyOK])
//
// Returns true if all characters are numbers;
// first character is allowed to be + or - as well.
//
// Does not accept floating point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
//
// EXAMPLE FUNCTION CALL:          RESULT:
// isSignedInteger ("5")           true
// isSignedInteger ("")            defaultEmptyOK
// isSignedInteger ("-5")          true
// isSignedInteger ("+5")          true
// isSignedInteger ("", false)     false
// isSignedInteger ("", true)      true

function isSignedInteger (s)

{   if (isEmpty(s))
       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedInteger.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;
        return (isInteger(s.substring(startPos, s.length), secondArg));
    }
}

// isInteger (STRING s [, BOOLEAN emptyOK])
//
// Returns true if all characters in string s are numbers.
//
// Accepts non-signed integers only. Does not accept floating
// point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// By default, returns defaultEmptyOK if s is empty.
// There is an optional second argument called emptyOK.
// emptyOK is used to override for a single function call
//      the default behavior which is specified globally by
//      defaultEmptyOK.
// If emptyOK is false (or any value other than true),
//      the function will return false if s is empty.
// If emptyOK is true, the function will return true if s is empty.
//
// EXAMPLE FUNCTION CALL:     RESULT:
// isInteger ("5")            true
// isInteger ("")             defaultEmptyOK
// isInteger ("-5")           false
// isInteger ("", true)       true
// isInteger ("", false)      false
// isInteger ("5", false)     true

function isInteger (s)

{   var i;

    if (isEmpty(s))
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (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;
}

// Returns true if character c is a digit
// (0 .. 9).

function isDigit (c)
{   return ((c >= "0") && (c <= "9"));
}

function isValidEuroDate(DateValue)
{
	var MyDate;
	var Month;
	var Year;
	var Day;
	var length;
	var IsADate;
	
	MyDate = DateValue;
	
	if(validate(MyDate))
	{
		//parse out the date
		Month = MyDate.substring(2,4);
		Day = MyDate.substring(0,2);
		Year = MyDate.substring(4,8);
		if(isDate(Year, Month, Day))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
	
}

//Checks for 8 digits and 2 / and makes sure it is numeric.
function validate(MyDate)
{
	if(MyDate.length != 8)
	{	
		return false;
	}
	else
	{
		if(isNum(MyDate)==false)
		{				
			return false;
		}
		else
		{
			return true;
		}
	}
	
}

//function takes in 2 parameters.  The first is the type of currency and the second is the amount.
//It formats the currency based on the currency type and returns the formatted result or false if
//the parameters are incorrect.
function formatCurrency(intAmount,fieldname)
{
	
	var dollars, cents, position, delimiter;

	intAmount = intAmount.toString();
	
	if(!IsValidNumber(intAmount))
	{
		alert ("Error in " + fieldname + ". Please enter a valid amount. e.g. 50000");
		return false;
	}
	
	delimiter = FindDelimiter(intAmount);
	
	//Replace the , in the currency if there is one with a . for function to work.  The value can be 
	//returned with the appropriate delimiter at the bottom of this function.
	if(delimiter != "" && delimiter != ".")
	{
		intAmount = intAmount.replace(delimiter, ".");
	}
	
	//search returns the location of where the . is or -1 if there is no .
	intAmount = intAmount.toString();
	position = intAmount.search(/[.]/); 
	
	//Returns false for an error if there are not 2 digits for the cents only if the cents 
	//separtator was typed in. (this function will still work with more than 2 cents 
	//digits if this code is commented out.  It will round to only 2 digits though.).
	if(position != -1 && (intAmount.length - position) > 3)
	{
		alert ("Error in " + fieldname + ". Please enter only two digits after the decimal point.");
		return false;
	}
	
	//Get the dollar amount without the cents.
	if(position != -1)
	{
		dollars = intAmount.substring(0, position);
	}
	else
	{
		dollars = intAmount;
	}
	
	//Check if there are no cents.  If so it is a whole dollar amount.
	if(position != -1)
	{
		cents = intAmount.substring(position + 1, intAmount.length);
		//Round the cents so it is only 2 digits long.
		if(cents.length != 2)
		{
			//Add a 0 if the cents is only 1 digit to make it become 2 digits.
			if(cents.length == 1)
			{
				cents = cents + "0";
			}
			else
			//Round the cents so it becomes only 2 digits.
			{	
				
				if(cents.charAt(0) == "0" && cents.charAt(1) == "0")
				{
					cents = "0" + Math.round(cents.charAt(0) + cents.charAt(1) + "." + cents.charAt(2));
				}
				else
				{
					cents = Math.round(cents.charAt(0) + cents.charAt(1) + "." + cents.charAt(2));
				}
				//If the cents round to a dollar then add 1 to the dollars and make cents 00. (i.e. .999 should round to 1.00)
				if(cents == 100)
				{
					cents = "00";
					dollars++;
				}
				//If the cents round to 0 cents then set the cents to 00. (i.e. 0001 should round to 00) 
				if(cents == 0)
				{
					cents = "00";
				}
			}
		}
	}
	else
	{
		cents = "00"
	}
	
	//For now the currency must be returned with a . separator for cents regardless of the currency
	//type. Later when this needs to be changed a , or any other separator can be put in the result
	//by simply changing the charater between the quotes below.
//	switch(strCurrType)
//	{
//		case "EUR":
//			return dollars + "." + cents;
//			break;
//		case "DKK":
//			return Math.round(intAmount);
//			break;
//		default: //GBP
			return dollars + "." + cents;
//			break;
//	}
}

function FindDelimiter(expression)
{
	var ch, i, j, checkOK;
	
	checkOK = ".";
	
	for (i = expression.length-1;  i >= 0;  i--) 
	{
		ch = expression.charAt(i);
		for (j = 0;  j < checkOK.length;  j++) 
		{
		  if (ch == checkOK.charAt(j)) 
		  {
				return ch;
		  }  	
	    }
	} 
    return ""; 
}

function IsValidNumber(expression) 
{
	var checkOK = "0123456789.";
    var i;
    var j;
	for (i = 0;  i < expression.length;  i++) 
	{
		ch = expression.charAt(i);
		for (j = 0;  j < checkOK.length;  j++) 
		{
		  if (ch == checkOK.charAt(j)) 
		  {
		    	break;
		  }  	
		  if (j == checkOK.length - 1) 
		  {
		     return false;
		  }
	    }
	} 
    return true; 
}


function round(number,X) 
{
	// rounds number to X decimal places, defaults to 2
	X = (!X ? 2 : X);
	return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}




