// Handles Wizard Form
var submitEvent = false;
function validateForm() {
	return true;	
}

function onWindowClose() {
	if(submitEvent == false) {
	}	
}
function trimFormFields(form) {
	var field;
	for(var i = 0; i < form.elements.length; i++) {
		field = form.elements[i];
		clearErrorClass(field);
		if((field.type).toUpperCase() == "TEXT") {
			field.value = trim(field.value);
		}
	}
}

function textCounter(fieldname, maxlimit) {
	var field;
	for(var i = 0; i < document.forms.length; ++i) {
		var obj = document.forms[i].elements[fieldname];
		if (obj) field = obj;
	}
	if (field == null) return false;
	var results = field.value.match(/\{keyword:[^\}]+\}/i);
	if (results) {
		maxlimit += "{keyword:}".length;
	}
	results = field.value.match(/\{keyword\}/);
	if (results) {
		maxlimit += "{keyword}".length - 1;
	}
	if (field.value.indexOf("{") == -1 ) {
		if (field.value.length > maxlimit) {
			field.value = field.value.substring(0, maxlimit);
		}
	} else {
		if (field.value.length > maxlimit) {
			field.style.color = 'red';
		return true;
		} else {
			field.style.color = 'black';
			return false;
		}
	}
}
function modifyText(id, text) {
	if (document.getElementById) {
		obj = document.getElementById(id);
		obj.childNodes[0].data = text;
	}
}
function modifyTextNotClear(id, text) {
	if (document.getElementById && text != '') {
		obj = document.getElementById(id);
		obj.childNodes[0].data = text;
	}
}

// Function list
// error(element, msg)					agumant passed is a form object and a string that is the text for the error message to be displayed in an alert
// isWhitespace()							arguemnt passed is a string. Returns true if it contains only whitespace characters
// isAlphanumeric()						argument passed is a string. Returns true if the string contains only alphanumeric characters
// isLetter()								argument passed is a char. Returns true if char is a-z or A-Z
// isPermitChar(c,permitChars)		arguments passed are a char and an array of "permitted" chars. Returns true if char is in the list of those permitted
// hasPermittedChars(s, okChars		arguments passed are a char and an array of "permitted"chars.  Returns true if char is in the list of those permitted
// isValidPassword(s)					argument passed is a string. Returns false if the string contains & ' "        
// hasSpecialCharOrDigit(s)			argument passed is a string. Returns true if the string contains a character that is either not alphanumeric or is a digit
// isEmail(s)								argument passed is a string. Returns true if string is of the form a@b.c
// parseEmail								parses email address delimited by semi-colons
// isValidEmail(s)						checks the email field to be sure that it is not whitespace and is of the correct form
// hasSpecialChars(s)					argument passed is a string. Returns true if string contains & " ' < >
// charsOutOfRange(s)					argument passed is a string. Returns true if character in the string are not in the ASCII range 32-125
// trim										argument passed is a string. Strips all whitespace and returns true.
// replace_bad_chars	
//argument passed is a string.
/*
function error(el,msg) {
	showAlertDialog(msg);
	try { el.focus(); el.select(); } catch(e){;}
	return false;
}
*/

/*
function error(el,msg,newtitle) {
	var currentError;
	var previousClass;
	var title = "Alert";
	if (arguments.length == 3)
		title = newtitle;
	if(msg)showAlertDialog(msg,title);
	try {
		if(currentError!=null) {
			currentError.className = previousClass;
		}
		if(el.className!=null) {
			currentClass = el.className;
			previousClass = currentClass;
			DHTML.addClass(el, "inputError");
			el.focus();
			currentError = el;
		} else {
			DHTML.addClass(el, "inputError");
			el.focus();
		}
	} catch(e){;}
	return false;
}
*/

function defaultValue(source, def) {
    value = new String(source);
    if (null == source || "null" == value || "undefined" == value || undefined == value)
        return def;
    return source;
}

function setErrorClass(el) {
	var currentClass = defaultValue(el.className,"");
	el.className = currentClass + ' inputError';
}

function clearErrorClass(el) {
	DHTML.removeClass(el,"inputError");
}

var decimalPointDelimiter = '.';
var EmptyOK = true;
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;
// Maximum no of digits in an international and national long-distance phone no. ex: +44-(0)1224-XXXX-XXXX.
var maxDigitsInIPhoneNumber = 15;
// valid white space characters
var whitespace = " \t\n\r";
function isWhitespace (s){
	if((s == null) || (s.length == 0)) {
		return true; 
  	}
  	return false;
}

function isLetter (c) {
	var UNICODE_LETTERS = "\\u0041-\\uffdc";
  var isUnicodeLetter = new RegExp("^[" + UNICODE_LETTERS + "]+$");
	return isUnicodeLetter.test(new String(c)); 	
}

function isDigit (c){return ((c >= "0") && (c <= "9")) }
function isSpace (c){return (whitespace.indexOf(c) != -1)}
function isInteger(s) {
    for (var i = 0; i < s.length; i++) { 
        var c = s.charAt(i);
        if (!isDigit(c))
        return false;
    }
    return true;
}

function isAlphanumeric(s,permitChars) {  
    for (var i = 0; i < s.length; i++) { 
        var c = s.charAt(i);
        if(arguments.length == 2) {
        	if(!(isLetter(c)||isDigit(c)||isSpace(c)||isPermitChar(c,permitChars)))
        		return false;
        } else if (!(isLetter(c)||isDigit(c)||isSpace(c)))
        	return false;
    }
    return true;
}

function isPermitChar(c, permitChars) {
   var isPermitted = false;
   for( var i=0; i < permitChars.length; i++) {
      if(c == permitChars.charAt(i)) {
      	 isPermitted = true;
      	 break;
      }
   }
   return isPermitted;   
}

function hasPermittedChars(s,okChars) {
     var isValidStr = true;
     for(i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((isPermitChar(c,okChars) || isLetter(c) || isDigit(c)) && (isValidStr == true)){ 
           isValidStr = true;
        } 
        else{
           isValidStr = false; 
           break;   
        }
    }
  return isValidStr; 
}

function checkInternationalPhone(strPhone){
	var s = stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber && s.length <= maxDigitsInIPhoneNumber);
}

function isValidPassword(s) {   
	var i;
	var isValid = true;   
	for (i = 0; i < s.length; i++){   
		var c = s.charAt(i);
		if(( c == "\"" ) || (c == "'" ) || ( c == "&")){
			isValid = false;
		}    
	}
	return isValid;
}

function hasSpecialCharOrDigit(s)
{
 	var i;
	var isValid = false;   
	for (i = 0; i < s.length; i++){   
		var c = s.charAt(i);
		if(isDigit(c) || (!(isLetter(c)||isDigit(c)))){
          isValid = true;
        } 
	} 
    return isValid;
}

function isValidEmail(emailStr) {
	
	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */
	
	var checkTLD=1;
	
	/* The following is the list of known TLDs that an e-mail address must end with. */
	
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var knownCountriesPat=/^(ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|az|ax|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$/;
	
	/* 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);
	
	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. */
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	
	// Start by checking that only basic ASCII characters are in the strings (0-127).
	
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			return false;
	   	}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			return false;
	   	}
	}
	
	// See if "user" is valid 
	if (user.match(userPat)==null) {
	// user is not 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) {
				return false;
	   		}
		}
		return true;
	}
	
	// Domain is symbolic name.  Check if it's valid.
	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			return false;
	   	}
	}
	
	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */
	
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
		return false;
	}
	if (checkTLD && domArr[domArr.length-1].length==2 && domArr[domArr.length-1].search(knownCountriesPat)==-1) {
		return false;
	}
	
	// Make sure there's a host name preceding the domain.
	
	if (len<2) {
		return false;
	}
	
	// If we've gotten this far, everything's valid!
	return true;
}
function encodeUnicode(s) 
{
  var string = s.replace(/\r\n/g,"\n");
  var utftext = "";

  for (var n = 0; n < string.length; n++) {
	var c = string.charCodeAt(n);
    if (c < 128) {
    	utftext += String.fromCharCode(c);
    }
    else if((c > 127) && (c < 2048)) {
    	utftext += String.fromCharCode((c >> 6) | 192);
    	utftext += String.fromCharCode((c & 63) | 128);
    }
    else {
      	utftext += String.fromCharCode((c >> 12) | 224);
      	utftext += String.fromCharCode(((c >> 6) & 63) | 128);
      	utftext += String.fromCharCode((c & 63) | 128);
//      	utftext += escape(String.fromCharCode((c >> 12) | 224));
//      	utftext += escape(String.fromCharCode(((c >> 6) & 63) | 128));
//      	utftext += escape(String.fromCharCode((c & 63) | 128));
	}
  }
  return (utftext);
}
function isValidURL(s) {
	var urlParts;
	if(s.indexOf("://") > -1) {
		urlParts = s.split("://");
		s = urlParts[0] + "://" + encodeUnicode(urlParts[1]);
		//s = urlParts[0] + "://" + encodeURI(urlParts[1]);
	}
	//var urlRegexp = /^(http|https){1}:\/\/([\w\-]+)(\.[\w\-]+)*\.(com|coop|cat|name|pro|museum|org|int|mil|edu|gov|net|int|biz|info|jobs|mobi|aero|travel)(\.[a-zA-z]{2})?((:[0-9]+)|(:[0-9]+)\/[\w#!:\.?+=&%@!{}\-\/]*|\/[\w#!:\.?+=&%@!{}\-\/]*|)$/
    var urlRegexp = /^(http|https){1}:\/\/([\w\-]+)(\.[\w\-]+)*\.(com|coop|cat|name|pro|museum|org|int|mil|edu|gov|net|int|biz|info|jobs|mobi|aero|travel)(\.[a-zA-z]{2})?(:[0-9]+)?(\/\?[\w#!:\.+=&%"@!{}\-\/]*|\?[\w#!:\.+=&%"@!{}\-\/]*|\/[\w#!:\.?+=&%"@!{}\-\/]*|\/[\w#!:\.?+=&%"@!{}\-\/]*|)$/
    //Test for common top level domains
    var match = urlRegexp.test(s);
    if(!match) {
    	//Test for country code top level domains
    	urlRegexp = /^(http|https){1}:\/\/([\w\-]+)(\.[\w\-]+)*\.(ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|az|ax|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)((:[0-9]+)|(:[0-9]+)\/[\w#!:\.?+=&%@!{}\-\/]*|\/[\w#!:\.?+=&%@!{}\-\/]*|)$/
    	match = urlRegexp.test(s);
    }
    return match;
}

function isValidYahooShortDescription(s) {
	if(s.charAt(s.length - 1) != '.')
		return false;
	else
		return true;
}

function hasProtocol(s) {
	var urlRegxp = /^(http:\/\/|https:\/\/)/;
    return urlRegxp.test(s);
}

function isValidUSPhoneNumber(s) {
	var j = new RegExp();
    j.compile("[0-9]{3}-[0-9]{3}-[0-9]{4}");
    if (!j.test(s)) 
    	return false;
	return true;
}

function parseEmail(s){
    var emailArr = new Array();
    var j=0;
    emailArr[j] = '';
    for(i=0; i < s.length; i++){
       if (s.charAt(i) != ';'){
          emailArr[j] += s.charAt(i);
       }
       else{
          j++; 
          emailArr[j] = '';
       }
    }   
    return emailArr;
}

function hasSpecialCharsAmpOk(s)
{   
	var isDb = false;   
	for (var i = 0; i < s.length; i++){   
		var c = s.charAt(i);
		if(( c == "\"" ) || (c == "'" ) || (c == "<" ) || ( c == ">")){
			isDb = true;
		}    
	}
	return isDb;
}

function hasSpecialChars(s)
{   
	var isDb = false;   
	for (var i = 0; i < s.length; i++){   
		var c = s.charAt(i);
		if(( c == "\"" ) || (c == "'" ) || ( c == "&")|| (c == "<" ) || ( c == ">")){
			isDb = true;
		}    
	}
	return isDb;
}

function hasSpecialCharswComma(s)
{   
	var isDb = false;   
	for (var i = 0; i < s.length; i++){   
		var c = s.charAt(i);
		if(( c == "\"" ) || (c == "'" ) || ( c == "&")|| (c == "<" ) || ( c == ">") || (c == "," )){
			isDb = true;
		}    
	}
	return isDb;
}
function isCampaignNumberValid(s)
{   
	var isDb = true;   
	for (var i = 0; i < s.length; i++){   
		var c = s.charAt(i);
		if(( c == "\"" ) || (c == "'" ) || ( c == "&")|| (c == "!" ) || ( c == "#") || (c == "$" ) || (c == "%" ) || ( c == "^")|| (c == "*" ) || ( c == ":") || (c == "|") || (c == "\\" ) || ( c == "/")|| (c == ">" ) || ( c == "<") || (c == "~") || ( c == ";") || (c == "=") || (c == "," )){
			isDb = false;
		} 
	}
	return isDb;
}
function hasWhitespace(s){
	for (var i = 0; i < s.length; i++){   
		var c = s.charAt(i);
		if((c == " ") || (c == "\\t") || (c == "\\n") || (c == "\\r")){
		   return true;	
		}	
	}
}
function charsOutOfRange(s){
    for(var j=0; j < s.length; j++)
    {
       var c = s.charCodeAt(j)
       if((c < 32) || (c > 126))
       {
          return true;
       } 
    }
    return false;
}

// isFloat (STRING s [, BOOLEAN emptyOK]) True if string s is an unsigned floating point (real) number. Also returns true for unsigned integers.
function isFloat (s, e_ok) { 
    var i;
	if(e_ok == null || e_ok == 'undefined')
	   e_ok = true;
    var seenDecimalPoint = false;
	if(isWhitespace(s) && (e_ok == true))
	  return true;
    for (i = 0; i < s.length; i++) {   
        // Check that current character is number.
        var c = s.charAt(i);
        if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }
    // All characters are numbers.
    return true;
}
function isInteger (s, e_ok) { 
    var i;
	if(e_ok == null || e_ok == 'undefined')
	   e_ok = true;
    if(isWhitespace(s) && (e_ok == true))
	  return true;
    for (i = 0; i < s.length; i++) {   // Check that current character is number.
        var c = s.charAt(i);
        if ((c == decimalPointDelimiter)) return false;
        else if (!isDigit(c)) return false;
    }
    // All characters are numbers.
    return true;
}

function isWithinMaxMinLimit(input,max,min) {
	return isWithinMaxMinLimit(input,max,min,false);
}

function isWithinMaxMinLimit(input,max,min,isInnerHtml) {
	max = defaultValue(max,null);
	min = defaultValue(min,null);
	value = (isInnerHtml) ? input.innerHTML : input.value; 
	if(isFloat(value, false)) {
		if(max != null && parseFloat(value) > max) {
			return error(input,provide_maximum_value + " " + max + ".");
		}
		if(min != null && parseFloat(value) < min) {
			return error(input,provide_minimum_value + " " + min + ".");
		}
	}
	return true;
}

function trim(s) {
   var retval = "";
   if(s == null || s=="")
      return retval;
   if(s.indexOf(' ') < 0 &&
      s.indexOf('\t') < 0 &&
      s.indexOf('\r') < 0 &&
      s.indexOf('\n') < 0)
      return s;

   var start=0,end=s.length;
   for( var i=0; i<s.length; i++ ) {
      if(' \t\r\n'.indexOf(s.charAt(i))>-1)
         start++;
      else
         break;
   }
   for( var i=s.length-1; i>0; i-- ) {
      if(end>=start&&' \t\r\n'.indexOf(s.charAt(i))>-1)
         end--;
      else
         break;
   }
   return s.substring(start,end);
}

function charInString (c, s){ 
  for (i = 0; i < s.length; i++){
    if (s.charAt(i) == c) return true;
  }
  return false
}
function rTrim(s){
    if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      s = s.substring(0, i+1);
   }
   return s;
}
function lTrim(s) {
var i = 0;
	while ( (i < s.length) && charInString(s.charAt(i), whitespace) )
		i++;
	return s.substring(i, s.length);
}
function trim(s) {
      return lTrim(rTrim(s));
}

function _rpl(s,b,n) {
     var idx = (""+s).indexOf(b);
     var retval='';
     while(idx!=-1){
        retval+=s.substring(0,idx)+n;
        s=s.substring(idx+1,s.length);
        idx=s.indexOf(b);
     } if(retval) {
        return retval + s.substring(0,s.length);
     } else {
        return s;
     }
}
function replace_bad_chars(s) {
   return _rpl(_rpl(_rpl(_rpl(_rpl(_rpl(_rpl(_rpl(_rpl(_rpl(_rpl(_rpl(_rpl(_rpl(
   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. var = whitespace defines which characters are considered whitespace.
function stripWhitespace (s) {
return stripCharsInBag (s, whitespace)
}

function stripBadChs(id,status) {
	var bad = 0
	for (i = 0; i < id.value.length; i++) {
		ch = id.value.substring(i, i + 1);
		if ( status == "letters or numbers" ) { if ( (ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) && (ch < "0" || "9" < ch) ) { bad = 1; } }
		if ( status == "letters" ) { if ( (ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) ) { bad = 1; } }
		if ( status == "dollar value" ) { if ((ch == "$") || (ch == ",")) { bad = 1 } }
		if ( status == "numbers" ) { if (ch < "0" || "9" < ch) { bad = 1 } }
		if ( status == "," ) { if (ch == ",") { bad = 1 } }
		if ( bad == 1 ) {	
			id.value = id.value.substring(0,i)+id.value.substring(i+1,id.value.length);
			i=i-1;
			bad = 0;
		}
	}
}

function isInvalidGoogleVariableSyntax(s,syntax) {
	var invalid = false;
	var str = (new String(s)).toLowerCase();
	var index = str.indexOf(syntax.substring(0,syntax.length-1));
	if(index > -1) {
		var str1 =  getGoogleVariableDefaultText(s,syntax);
		var str2 =  getGoogleVariableDefaultText(s,syntax.substring(0,syntax.length-1));
		if(trim(str1) == "" || trim(str2) == "")
			invalid = true;
	}
	return invalid;
}

function getGoogleVariableDefaultText(s,syntax) {
	var str1, str = (new String(s)).toLowerCase();
	var index = str.indexOf(syntax);
	str = str.substring(index+syntax.length,str.length);
	if(str.indexOf("}") == -1)
		str = s;
	else {
		str1 = s.substring(index+syntax.length,s.length);
		str = str1.substring(0,str1.indexOf("}"));
	} 
	return str;
}

function stripGoogleVariableSyntax(s,syntax) {
	var str1, str2, str3, str = (new String(s)).toLowerCase();
	var index = str.indexOf(syntax);
	if(index > -1) {
		str = str.substring(index+syntax.length,str.length);
		if(str.indexOf("}") == -1)
			str = s;
		else {
			str1 = s.substring(0,index);
			str2 = s.substring(index+syntax.length,s.length);
			str3 = str2.substring(str2.indexOf("}")+1,str2.length);
			str2 = str2.substring(0,str2.indexOf("}"));
			str = str1+str2+str3;
		}
	} else {
		str = s;
	}
	return str;
}

function stripMivaVariableSyntax(s,syntax) {
	var str1, str2, str;
	var index = s.indexOf(syntax);
	if(index > -1) {
		str1 = s.substring(0,index);
		str2 = s.substring(index+syntax.length,s.length);
		str = str1+str2;
	} else {
		str = s;
	}
	return str;
}

var isAddressValid = function() {
	var error = false;	
	var toName = DHTML.getElementById("toName");
	if(isWhitespace(toName.value)) {
		errorInputElement(toName);
		DHTML.display("toNameMsgDv");
		error = true;
 	} else {
   		DHTML.hide("toNameMsgDv");
   		clearErrorInputElement(toName);
   	}
   	var address1 = DHTML.getElementById("address1");
   	if(isWhitespace(address1.value)) {
   		errorInputElement(address1);
   		DHTML.display("address1MsgDv");
   		error = true;
   	} else {
   		DHTML.hide("address1MsgDv");
   		clearErrorInputElement(address1);
   	}
   	var cityName = DHTML.getElementById("cityName");
   	if(isWhitespace(cityName.value)) {
   		errorInputElement(cityName);
   		DHTML.display("cityNameMsgDv");
   		error = true;
   	} else {
  		DHTML.hide("cityNameMsgDv");
   		clearErrorInputElement(cityName);
   	}
   	var postalCode = DHTML.getElementById("postalCode");
   	if(isWhitespace(postalCode.value) || postalCode.value.length < 5) {
   		errorInputElement(postalCode);
   		DHTML.display("postalCodeMsgDv");
   		error = true;
   	} else {
   		DHTML.hide("postalCodeMsgDv");
   		clearErrorInputElement(postalCode);
   	}
	var phoneError = false;
   	var phoneArea = DHTML.getElementById("phoneArea");
   	if(isWhitespace(phoneArea.value) || !isInteger(phoneArea.value) || phoneArea.value.length < 3) {
   		errorInputElement(phoneArea);
   		phoneError = error = true;
   	} else {
   		clearErrorInputElement(phoneArea);
   	}
   	var phoneNmb = DHTML.getElementById("phoneNmb");
   	if(isWhitespace(phoneNmb.value) || phoneNmb.value.length < 7) {
   		errorInputElement(phoneNmb);
   		phoneError = error = true;
   	} else {
   		clearErrorInputElement(phoneNmb);
   	}
   	var phoneExt = DHTML.getElementById("phoneExt");
   	if(!isWhitespace(phoneExt.value) && (!isInteger(phoneExt.value) || phoneExt.value.length < 3)) {
   		errorInputElement(phoneExt);
   		phoneError = error = true;
   	} else {
   		clearErrorInputElement(phoneExt);
   	}
	if(phoneError) {
		DHTML.display("phoneMsgDv");
	} else {
		DHTML.hide("phoneMsgDv");
	}
    	
	return !error;
}

var isIE6 = function() {
	var ieVer = (navigator.appName=='Microsoft Internet Explorer')?parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):-1;
	if(ieVer > 0 && ieVer < 7) {
	    DHTML.display("ie6Msg");
	}
}



