<!--
var whitespace = " \t\n\r";
var HEX = '0123456789abcdef';

function do_submit(form, action){
	form.action.value=action;
	form.submit();
}

function FocusColour(strColour)
{
	var intDelta = -16;
	var intRed = Math.min(255, Math.max(0, parseInt(strColour.substr(1, 2), 16) + intDelta));
	var intGreen = Math.min(255, Math.max(0, parseInt(strColour.substr(3, 2), 16) + intDelta));
	var intBlue = Math.min(255, Math.max(0, parseInt(strColour.substr(5, 2), 16) + intDelta));

	return dec2hex(intRed) + dec2hex(intGreen) + dec2hex(intBlue);
}

function dec2hex(INT)
{
	if (Math.floor(INT) < 16)
	{
		return HEX.charAt(Math.floor(INT));
	}
	else
	{
		return(dec2hex(Math.floor(INT/16)) + dec2hex(Math.floor(INT%16)));
	}
}


function isEmpty(s) {
	return ((s == null) || (s.length == 0))
}

function isWhitespace (s) {
    var i;

    if (isEmpty(s)) return true;

    for (i = 0; i < s.length; i++) {   
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    return true;
}

function stripCharsInBag (s, bag) {
    var i;
    var returnString = "";

    for (i = 0; i < s.length; i++) {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

function stripCharsNotInBag (s, bag) {
    var i;
    var returnString = "";

    for (i = 0; i < s.length; i++) {   
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }

    return returnString;
}

function stripWhitespace (s) {
	return stripCharsInBag (s, whitespace)
}

function stripInitialWhitespace (s) {
    var i = 0;

    while ((i < s.length) && (whitespace.indexOf(s.charAt(i)) != -1))
       i++;
    
    return s.substring (i, s.length);
}

function isLetter (c) {
	return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

function isDigit (c) {
	return ((c >= "0") && (c <= "9"))
}

function isLetterOrDigit (c) {
	return (isLetter(c) || isDigit(c))
}

function isInteger (s, emptyOk) {
    var i;

    if (isEmpty(s)) 
       return emptyOk

    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }

    return true;
}

function isSignedInteger (s, emptyOk) {
    if (isEmpty(s)) 
       return emptyOk

    var startPos = 0;
    var secondArg = false;

    if (isSignedInteger.arguments.length > 1)
        secondArg = isSignedInteger.arguments[1];

    if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
       startPos = 1;    
    return (isInteger(s.substring(startPos, s.length), secondArg))
}

function isPositiveInteger (s, emptyOk) {
    return (isSignedInteger(s, emptyOk) && ( (isEmpty(s) && emptyOk)  || (parseInt (s) > 0) ) );
}

function isNonnegativeInteger (s, emptyOk) {
    return (isSignedInteger(s, emptyOk) && ( (isEmpty(s) && emptyOk)  || (parseInt (s) >= 0) ) );
}

function isNegativeInteger (s, emptyOk) {
    return (isSignedInteger(s, emptyOk) && ( (isEmpty(s) && emptyOk)  || (parseInt (s) < 0) ) );
}

function isNonpositiveInteger (s, emptyOk) {
    return (isSignedInteger(s, emptyOk) && ( (isEmpty(s) && emptyOk)  || (parseInt (s) <= 0) ) );
}

function isFloat (s, emptyOk) {
    var i;
    var seenDecimalPoint = false;

    if (isEmpty(s)) 
	    return emptyOk

    if (s == ".") return false;

    for (i = 0; i < s.length; i++) {   
        var c = s.charAt(i);

        if ((c == ".") && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

    return true;
}

function isSignedFloat (s, emptyOk) {
    if (isEmpty(s)) 
	    return emptyOk

    var startPos = 0;
    if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
       startPos = 1;    
    return (isFloat(s.substring(startPos, s.length), emptyOk))
}

function isAlphabetic (s, emptyOk) {
    var i;

    if (isEmpty(s)) 
       return emptyOk

    for (i = 0; i < s.length; i++) {   
        var c = s.charAt(i);

        if (!isLetter(c)) return false;
    }

    return true;
}

function isAlphanumeric (s, emptyOk) {
    var i;

    if (isEmpty(s)) 
       return emptyOk

    for (i = 0; i < s.length; i++) {   
        var c = s.charAt(i);

        if (! (isLetter(c) || isDigit(c) ) ) return false;
    }

    return true;
}

function reformat (s, emptyOk) {
    var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}

function isPhoneNumber (s, emptyOk) {
    if (isEmpty(s)) 
	    return emptyOk

    var i;
    for (i = 0; i < s.length; i++) {   
        var c = s.charAt(i);

        if (c != '-' && c != '+' && !isDigit(c) ) return false;
    }

    return true;
}

function isEmail (s, emptyOk) {
    if (isEmpty(s)) 
	    return emptyOk
   
    if (isWhitespace(s)) return false;
    
    var i = 1;
    var sLength = s.length;

    while ((i < sLength) && (s.charAt(i) != "@"))
	    i++

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    while ((i < sLength) && (s.charAt(i) != "."))
	    i++

    return  !((i >= sLength - 1) || (s.charAt(i) != "."))
}

function isYear (s, emptyOk) {
    if (isEmpty(s)) 
	    return emptyOk
    if (!isNonnegativeInteger(s)) return false;
    return ((s.length == 2) || (s.length == 4));
}

function isTime (s, emptyOK){
    if (isEmpty(s))
	return emptyOK
    return ((s.length >= 5) && (isNonnegativeInteger(s.substring(0,2))) && (s.substring(0,2)>=0) && (s.substring(2,3)==':') && isNonnegativeInteger(s.substring(3,5)) && (s.substring(3,5)>=0) && (s.substring(3,5)<=59) && (s.substring(0,2)<=23) || (s.length == 4) && (isNonnegativeInteger(s.substring(0,1))) && (s.substring(0,1)>=0) && (s.substring(1,2)==':') && isNonnegativeInteger(s.substring(2,4)) && (s.substring(2,4)>=0) && (s.substring(2,4)<=59) && (s.substring(0,1)<=9)); 
}

function isIntegerInRange (s, a, b, emptyOk) {
    if (isEmpty(s)) 
	    return emptyOk

    var num = parseInt (s);
    return ((num >= a) && (num <= b));
}

function isMonth (s, emptyOk) {
    if (isEmpty(s)) 
	    return emptyOk
    return isIntegerInRange (s, 1, 12);
}

function isDay (s, emptyOk) {
    if (isEmpty(s)) 
	    return emptyOk
    return isIntegerInRange (s, 1, 31);
}

function daysInFebruary (year) {
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

function makeArray(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;

function DateOk (year, month, day, cy, cm, cd) {
    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;

    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

    var intCY = parseInt(cy);
    var intCM = parseInt(cm);
    var intCD = parseInt(cd);

    if(intDay <= intCD) return false;

    return false;
}

function isDate (year, month, day) {
    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;

    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

    if (intDay > daysInMonth[intMonth]) return false; 

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}

/* FUNCTIONS TO NOTIFY USER OF INPUT REQUIREMENTS OR MISTAKES. */

function matchPasswords(first,second,s){
	if( first.value != second.value )
		return warnInvalid(first,s);
	return true;
}

function count_checkbox(form, field,  s) {
	var number=0;
	for (var i=0; i < form.length; i++) {
		var element = form.elements[i];
		if (element.type == 'checkbox' && element.name.substr(0,field.length)==field) {
			if (element.checked ) {
				number++;
			}
		}
	}
	if(number==0)
		alert(s);
	return number;
}

function checkSubmit (form) {
	for (var i=0; i < form.length; i++) {
		var element = form.elements[i];
		if (element.name != "country" && element.name != "city") {
			if (element.onchange && !element.onchange()) {
				return false;
			}
		}
	}
	return true;
}

function warnEmpty (theField, s) {
    theField.focus()
    alert(s)
    return false
}

function warnInvalid (theField, s) {
    theField.focus()
    theField.select()
    alert(s)
    return false
}

function checkString (theField, s, emptyOK) {
	if ((emptyOK == true) && (isEmpty(theField.value))) return true;
	if (isWhitespace(theField.value)) 
		return warnEmpty (theField, s);
	return true;
}

function checkFloat (theField, s, emptyOK) {
	if (!isFloat(theField.value, emptyOK))
		return warnInvalid (theField, s);
	return true;
}

function checkInteger (theField, s, emptyOK) {
	if (!isInteger(theField.value, emptyOK))
		return warnInvalid (theField, s);
	return true;
}

function checkPhone (theField, s, emptyOK) {
	if (!isPhoneNumber(theField.value, emptyOK)) 
		return warnInvalid (theField, s);
	return true;
}

function checkEmail (theField, s, emptyOK) {
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isEmail(theField.value, false)) 
       return warnInvalid (theField, s);
    return true;
}

function checkYear (theField, s, emptyOK) {
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isYear(theField.value, false)) 
       return warnInvalid (theField, s);
    if (theField.value < 100) 
	    theField.value = parseInt(theField.value) + 2000;
    return true;
}

function checkTime(theField, s, emptyOK) {
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isTime(theField.value, false))
	return warnInvalid (theField, s);
    return true;
}

function checkMonth (theField, s, emptyOK) {
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isMonth(theField.value, false)) 
       return warnInvalid (theField, s);
    return true;
}

function checkDay (theField, s, emptyOK) {
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isDay(theField.value, false)) 
       return warnInvalid (theField, s);
    return true;
}

function checkDate (yearField, monthField, dayField, s, OKtoOmitDay) {
    if(!isYear(yearField.value) && !isMonth(monthField.value) && !isDay(dayField.value) && OKtoOmitDay==true) return true;
    if (!isYear(yearField.value)) return warnInvalid (yearField, s);
    if (yearField.value < 50) 
	    yearField.value = parseInt(yearField.value) + 2000;
    else if (yearField.value < 100)
	    yearField.value = parseInt(yearField.value) + 1900;
    if (!isMonth(monthField.value)) return warnInvalid (monthField, s);
    if ( (OKtoOmitDay == true) && isEmpty(dayField.value) ) return true;
    if (!isDay(dayField.value)) 
       return warnInvalid (dayField, s);
    if (isDate (yearField.value, monthField.value, dayField.value))
       return true;
    dayField.focus();
    alert(s);
    return false;
}

function getRadioButtonValue (radio) {
    for (var i = 0; i < radio.length; i++) 
	if (radio[i].checked) { break }
    return radio[i].value
}

function checkCreditCard (radio, s, theField, emptyOK) {
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    var cardType = getRadioButtonValue (radio)
    var creditCardDelimiters = " "
    var normalizedCCN = stripCharsInBag(theField.value, creditCardDelimiters)
    if (!isCardMatch(cardType, normalizedCCN)) 
       return warnInvalid (theField, s);
    theField.value = normalizedCCN
    return true
}


function isCreditCard(st) {
  if (st.length > 19)
    return false;

  sum = 0; mul = 1; l = st.length;
  for (i = 0; i < l; i++) {
    digit = st.substring(l-i-1,l-i);
    tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul--;
  }
  return ((sum % 10) == 0)
}

function isVisa(cc) {
  if (((cc.length == 16) || (cc.length == 13)) && (cc.substring(0,1) == 4))
    return isCreditCard(cc);
  return false;
}

function isMasterCard(cc) {
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if ((cc.length == 16) && (firstdig == 5) && ((seconddig >= 1) && (seconddig <= 5)))
    return isCreditCard(cc);
  return false;

}

function isAmericanExpress(cc) {
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if ((cc.length == 15) && (firstdig == 3) && ((seconddig == 4) || (seconddig == 7)))
    return isCreditCard(cc);
  return false;

}

function isDinersClub(cc) {
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if ((cc.length == 14) && (firstdig == 3) && ((seconddig == 0) || (seconddig == 6) || (seconddig == 8)))
    return isCreditCard(cc);
  return false;
}

function isCarteBlanche(cc) {
  return isDinersClub(cc);
}

function isDiscover(cc) {
  first4digs = cc.substring(0,4);
  if ((cc.length == 16) && (first4digs == "6011"))
    return isCreditCard(cc);
  return false;

}

function isEnRoute(cc) {
  first4digs = cc.substring(0,4);
  if ((cc.length == 15) && ((first4digs == "2014") || (first4digs == "2149")))
    return isCreditCard(cc);
  return false;
}

function isJCB(cc) {
  first4digs = cc.substring(0,4);
  if ((cc.length == 16) &&
      ((first4digs == "3088") ||
       (first4digs == "3096") ||
       (first4digs == "3112") ||
       (first4digs == "3158") ||
       (first4digs == "3337") ||
       (first4digs == "3528")))
    return isCreditCard(cc);
  return false;
}

function isAnyCard(cc) {
  if (!isCreditCard(cc))
    return false;
  return (isMasterCard(cc) || isVisa(cc) || isAmericanExpress(cc) || isDinersClub(cc) || isDiscover(cc) || isEnRoute(cc) || isJCB(cc));
}

function isCardMatch (cardType, cardNumber) {
	cardType = cardType.toUpperCase();

	if (cardType == "VISA") return isVisa(cardNumber);
	if (cardType == "MASTERCARD") return isMasterCard(cardNumber);
	if ( (cardType == "AMERICANEXPRESS") || (cardType == "AMEX") ) return isAmericanExpress(cardNumber);
	if (cardType == "DISCOVER") return isDiscover(cardNumber);
	if (cardType == "JCB") return isJCB(cardNumber);
	if (cardType == "DINERS") return isDinersClub(cardNumber);
	if (cardType == "CARTEBLANCHE") return isCarteBlanche(cardNumber);
	if (cardType == "ENROUTE") return isEnRoute(cardNumber);
	return false;
}
//-->

