<!--
/* $Id: f_checkout_common.js,v 1.1 2008/06/09 14:57:17 georger Exp $ */

/*
	javascript functions common in several checkout pages.
	these functions are:
	- isValidLen
	- isAlphanum
	- isAlpha
	- isNum
	- illegalChars
	- removeSpaces
	- trimWhitespace
	- dispErr
	- setErrorStyle
*/

  // Check that the number of characters in a string is between a max and a min
  isValidLen = function (str, min, max) {
  	if (str.length < min || str.length > max) return false;
  	else return true;
  }; // close is ValidLen();
  
  // Check that a string contains only letters and numbers
  isAlphanum = function (str, ignWS) {
  	if (str.search) {
  		if ((ignWS && str.search(/[^\w\s]/) != -1) || (!ignWS && str.search(/\W/) != -1)) return false;
  	}
  	return true;
  }; // close isAlphanum();
  
  // Check that a string contains only letters
  isAlpha = function (str, ignWS) {
  	if (str.search) {
		if ((ignWS && str.search(/[^a-zA-Z\-\,\.\s]/) != -1) || (!ignWS && str.search(/[^a-zA-Z,\-\.]/) != -1)) return false;
  	}
  	return true;
  }; // close isAlpha();
  
  // Check that a string contains only numbers
  isNum = function (str, ignWS) {
  	if (str.search) {
  		if ((ignWS && str.search(/[^\d\s]/) != -1) || (!ignWS && str.search(/\D/) != -1)) return false;
  	}
  	return true;
  }; // close isNum();
  
  // Flag characters that might cause security problems from a string 
  illegalChars = function (str) {
  	if (str.search) {
  		if (str.search(/[\<\>\,\;\:\=\&\"\[\]\'\~\?\!\$]/) != -1) return false;
  	}
  	return true;
  }; // close illegalChars();
  
  // Remove all spaces from a string
  removeSpaces = function (str) {
  	var newStr = '';
  	for (var i = 0; i < str.length; i++) {
  		if (str.charAt(i) != ' ') newStr += str.charAt(i);
  	}
  	return newStr;
  }; // close removeSpaces();
  
  // Remove leading and trailing whitespace from a string
  trimWhitespace = function (str) {
  	var newStr  = '';
  	var substr  = '';
  	begin = false;
  	// retain whitespace characters if they are between other characters
  	for (var i = 0; i < str.length; i++) {
  		// copy non-whitespace characters
  		if (str.charAt(i) != ' ' && str.charCodeAt(i) != 9) {
  			// if the temporary string contains some whitespace characters, copy them first
  			if (substr != '') {
  				newStr += substr;
  				substr = '';
  			}
  			newStr += str.charAt(i);
  			if (begin == false) begin = true;
  		}
  		// hold whitespace characters in a temporary string if they follow a non-whitespace character
  		else if (begin == true) substr += str.charAt(i);
  	}
  	return newStr;
  }; // close trimWhitespace(); 
  
  // outputs the errors
  dispErr = function (str) {
  	var elm = AE_GetElementById('error');
  	AE_SetInnerHTML(elm, str);
  	return true;
  };//close dispErr()
  
  // sets the background for error fields
  setErrorStyle = function (elm, color) {
  	var inputError = new AE_CSS(elm);
  	inputError.setBackgroundColor(color);
  };//close setErrorStyle()
//-->
