//  Cookie Functions -- "Night of the Living Cookie" Version (25-Jul-96)
//
//  Written by:  Bill Dortch, hIdaho Design <bdortch@hidaho.com>
//  The following functions are released to the public domain.
//
//  This version takes a more aggressive approach to deleting
//  cookies.  Previous versions set the expiration date to one
//  millisecond prior to the current time; however, this method
//  did not work in Netscape 2.02 (though it does in earlier and
//  later versions), resulting in "zombie" cookies that would not
//  die.  DeleteCookie now sets the expiration date to the earliest
//  usable date (one second into 1970), and sets the cookie's value
//  to null for good measure.
//
//  Also, this version adds optional path and domain parameters to
//  the DeleteCookie function.  If you specify a path and/or domain
//  when creating (setting) a cookie**, you must specify the same
//  path/domain when deleting it, or deletion will not occur.
//
//  The FixCookieDate function must now be called explicitly to
//  correct for the 2.x Mac date bug.  This function should be
//  called *once* after a Date object is created and before it
//  is passed (as an expiration date) to SetCookie.  Because the
//  Mac date bug affects all dates, not just those passed to
//  SetCookie, you might want to make it a habit to call
//  FixCookieDate any time you create a new Date object:
//
//    var theDate = new Date();
//    FixCookieDate (theDate);
//
//  Calling FixCookieDate has no effect on platforms other than
//  the Mac, so there is no need to determine the user's platform
//  prior to calling it.
//
//  This version also incorporates several minor coding improvements.
//
//  **Note that it is possible to set multiple cookies with the same
//  name but different (nested) paths.  For example:
//
//    SetCookie ("color","red",null,"/outer");
//    SetCookie ("color","blue",null,"/outer/inner");
//
//  However, GetCookie cannot distinguish between these and will return
//  the first cookie that matches a given name.  It is therefore
//  recommended that you *not* use the same name for cookies with
//  different paths.  (Bear in mind that there is *always* a path
//  associated with a cookie; if you don't explicitly specify one,
//  the path of the setting document is used.)
//
//  Revision History:
//
//    "Toss Your Cookies" Version (22-Mar-96)
//      - Added FixCookieDate() function to correct for Mac date bug
//
//    "Second Helping" Version (21-Jan-96)
//      - Added path, domain and secure parameters to SetCookie
//      - Replaced home-rolled encode/decode functions with Netscape's
//        new (then) escape and unescape functions
//
//    "Free Cookies" Version (December 95)
//
//
//  For information on the significance of cookie parameters, and
//  and on cookies in general, please refer to the official cookie
//  spec, at:
//
//      http://www.netscape.com/newsref/std/cookie_spec.html
//
//******************************************************************
//
// "Internal" function to return the decoded value of a cookie
//
function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
//
//  Function to correct for 2.x Mac date bug.  Call this function to
//  fix a date object prior to passing it to SetCookie.
//  IMPORTANT:  This function should only be called *once* for
//  any given date object!  See example at the end of this document.
//
function FixCookieDate (date) {
	var base = new Date(0);
	var skew = base.getTime(); // dawn of (Unix) time - should be 0
	if (skew > 0)  // Except on the Mac - ahead of its time
		date.setTime (date.getTime() - skew);
}
//
//  Function to return the value of the cookie specified by "name".
//    name - String object containing the cookie name.
//    returns - String object containing the cookie value, or null if
//      the cookie does not exist.
//
function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}
//
//  Function to create or update a cookie.
//    name - String object containing the cookie name.
//    value - String object containing the cookie value.  May contain
//      any valid string characters.
//    [expires] - Date object containing the expiration data of the cookie.  If
//      omitted or null, expires the cookie at the end of the current session.
//    [path] - String object indicating the path for which the cookie is valid.
//      If omitted or null, uses the path of the calling document.
//    [domain] - String object indicating the domain for which the cookie is
//      valid.  If omitted or null, uses the domain of the calling document.
//    [secure] - Boolean (true/false) value indicating whether cookie transmission
//      requires a secure channel (HTTPS).
//
//  The first two parameters are required.  The others, if supplied, must
//  be passed in the order listed above.  To omit an unused optional field,
//  use null as a place holder.  For example, to call SetCookie using name,
//  value and path, you would code:
//
//      SetCookie ("myCookieName", "myCookieValue", null, "/");
//
//  Note that trailing omitted parameters do not require a placeholder.
//
//  To set a secure cookie for path "/myPath", that expires after the
//  current session, you might code:
//
//      SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);
//
function SetCookie (name,value,expires,path,domain,secure) {
	document.cookie = name + "=" + escape (value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}

//  Function to delete a cookie. (Sets expiration date to start of epoch)
//    name -   String object containing the cookie name
//    path -   String object containing the path of the cookie to delete.  This MUST
//             be the same as the path used to create the cookie, or null/omitted if
//             no path was specified when creating the cookie.
//    domain - String object containing the domain of the cookie to delete.  This MUST
//             be the same as the domain used to create the cookie, or null/omitted if
//             no domain was specified when creating the cookie.
//
function DeleteCookie (name,path,domain) {
	if (GetCookie(name)) {
		document.cookie = name + "=" +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

/* check form functions */

// cross-browser "this" finder
function getTargetElement(evt) {
	var elem;
	if (evt.target) {
		elem = (evt.target.nodeType == 3) ? evt.target.parentNode : evt.target;
	}
	else {
		elem = evt.srcElement;
	}
	return elem;
}

function checkNumeric(field_str) {
	var num_pattern = /^[0-9]+$/;
	if (field_str.match(num_pattern)) {
		return true;
	}
	else {
		return false;
	}
}

function checkSize(field_str, min, max) {
	if ((field_str.length >= min) && (field_str.length <= max)) {
		return true;
	}
	else {
		return false;
	}
}

function formatPhone(evt) {
	var key_num;
	var key_char;
	var num_check;
	var char_check;
	evt = (evt) ? evt : ((window.event) ? window.event : "");
	if (evt) {
		var elem = getTargetElement(evt);
		if (elem) {
			key_num = (window.event) ? evt.keyCode : ((evt.which) ? evt.which : "");
			key_char = String.fromCharCode(key_num);
			num_check = /\d/;
			if (num_check.test(key_char)) {
				if ((elem.value.length == 3) || (elem.value.length == 7)) {
					elem.value = elem.value + "-";
				}
				if (elem.value.length < 12) {
					elem.value = elem.value + key_char;
				}
				return false;
			}
			char_check = /[\x00\x08\x0D]/;
			if (char_check.test(key_char)) {
				return true;
			}
			return false;
		}
	}
}

function formatDate(evt) {
	var key_num;
	var key_char;
	var num_check;
	var char_check;
	evt = (evt) ? evt : ((window.event) ? window.event : "");
	if (evt) {
		var elem = getTargetElement(evt);
		if (elem) {
			key_num = (window.event) ? evt.keyCode : ((evt.which) ? evt.which : "");
			key_char = String.fromCharCode(key_num);
			num_check = /\d/;
			if (num_check.test(key_char)) {
				if ((elem.value.length == 2) || (elem.value.length == 5)) {
					elem.value = elem.value + "\/";
				}
				if (elem.value.length < 10) {
					elem.value = elem.value + key_char;
				}
				return false;
			}
			char_check = /[\x00\x08\x0D]/;
			if (char_check.test(key_char)) {
				return true;
			}
			return false;
		}
	}
}

function getCursorPos(elem) {
	if (elem.createTextRange) {
		var range = document.selection.createRange().duplicate();
		range.moveEnd("character", elem.value.length);
		if (range.text == "") {
			return elem.value.length;
		}
		return elem.value.lastIndexOf(range.text);
	}
	else {
		return elem.selectionStart;
	}
}

function setCursorPos(elem, start, end) {
	if (elem.createTextRange) {
		var range = elem.createTextRange();
		range.collapse(true);
		range.moveEnd('character', end);
		range.moveStart('character', start);
		range.select();
	}
	else if (elem.setSelectionRange) {
		elem.selectionStart = start;
		elem.selectionEnd = end;
	}
}

function captureBackIE(elem) {
	var key_code = window.event.keyCode;
	if ((key_code == 8) && (getCursorPos(elem) == (elem.value.indexOf('.') + 1))) {
		setCursorPos(elem, getCursorPos(elem) - 1, getCursorPos(elem) - 1);
		return false;
	}
}

function formatCurrency(evt) {
	var key_num;
	var key_char;
	var num_check;
	var char_check;
	var len;
	evt = (evt) ? evt : ((window.event) ? window.event : "");	
	if (evt) {
		var elem = getTargetElement(evt);
		if (elem) {
			len = elem.value.length;
			key_num = (window.event) ? evt.keyCode : ((evt.which) ? evt.which : "");
			key_char = String.fromCharCode(key_num);
			num_check = /\d/;
			if (num_check.test(key_char)) {
				tmp = elem.value.split(".");
				if (len == 0) {
					elem.value = key_char + ".00";
					setCursorPos(elem, 1, 1);
				}
				else if ((tmp[0].length == 0) && (tmp[1].length == 0)) {
					if (getCursorPos(elem) == len) {					
						elem.value =  "." + key_char;
						setCursorPos(elem, len + 1, len + 1);
					}
					if (getCursorPos(elem) == (len - 1)) {					
						elem.value = key_char + ".00";
						setCursorPos(elem, 1, 1);
					}
				}
				else if (getCursorPos(elem) < (len - 2)) {
					tmp[0] = tmp[0] + key_char + "." + tmp[1];
					elem.value = tmp[0];
					setCursorPos(elem, len - 2, len - 2);
				}
				else if (getCursorPos(elem) == (len - 2)) {
					tmp[0] = tmp[0] +  "." + key_char + tmp[1].substring(1, 2);
					elem.value = tmp[0];
					setCursorPos(elem, len - 1, len - 1);
				}
				else if (getCursorPos(elem) == (len - 1)) {
					tmp[0] = tmp[0] +  "." + tmp[1].substring(0, 1) + key_char;
					elem.value = tmp[0];
					setCursorPos(elem, len, len);
				}
				else if (tmp[1].length == 0) {
					tmp[0] = tmp[0] +  "." + key_char;
					elem.value = tmp[0];
					setCursorPos(elem, len + 1, len + 1);
				}
				else if (tmp[1].length == 1) {
					if (getCursorPos(elem) == len) {
						tmp[0] = tmp[0] +  "." + tmp[1] + key_char;
						elem.value = tmp[0];
						setCursorPos(elem, len + 1, len + 1);
					}
					if (getCursorPos(elem) == (len - 1)) {
						tmp[0] = tmp[0] +  "." + key_char + tmp[1] ;
						elem.value = tmp[0];
						setCursorPos(elem, len, len);
					}
				}
				return false;
			}
			char_check = /[\b]/;			
			if ((char_check.test(key_char)) && (getCursorPos(elem) == (elem.value.indexOf('.') + 1))) {
				setCursorPos(elem, getCursorPos(elem) - 1, getCursorPos(elem) - 1);
				return false;
			}
			char_check = /[\x00\x08\x0D]/;
			if (char_check.test(key_char)) {
				return true;
			}
			return false;
		}
	}
}

function onlyNumbers(evt) {
	var key_num;
	var key_char;
	var num_check;
	evt = (evt) ? evt : ((window.event) ? window.event : "");
	if (evt) {
		key_num = (window.event) ? evt.keyCode : ((evt.which) ? evt.which : "");
		key_char = String.fromCharCode(key_num);
		num_check = /[\d\x00\x08\x0D]/;
		return num_check.test(key_char);
	}
}

function clearError(field_id) {
	if (document.getElementById(field_id + "Error")) {
		document.getElementById(field_id + "Error").style.display = "none";
	}
	if (document.getElementById(field_id + "ErrorMsg")) {
		document.getElementById(field_id + "ErrorMsg").style.display = "none";
		document.getElementById(field_id + "ErrorMsg").innerHTML = "";
	}
	if (document.getElementById(field_id + "Req")) {
		document.getElementById(field_id + "Req").style.display = "inline";
	}
}

function errorMsg(field_id, error_num) {
	errorText = new Array("Required&#160;Field", "Invalid Email Address Format", "Invalid Phone Format", "Invalid Zip Code", "Password Must Be At Least 5 Characters", "Password Cannot Be The Same As Username", "Passwords Do Not Match", "State&#160;Or&#160;Province&#160;Required", "Invalid Website Format", "Invalid Date Format", "Enter Your Request");
	if (document.getElementById(field_id + "Req")) {
		document.getElementById(field_id + "Req").style.display = "none";
	}
	if (document.getElementById(field_id + "Error")) {
		document.getElementById(field_id + "Error").style.display = "inline";
	}
	if (document.getElementById(field_id + "ErrorMsg")) {
		document.getElementById(field_id + "ErrorMsg").innerHTML = errorText[error_num];
		document.getElementById(field_id + "ErrorMsg").style.display = "inline";
	}
}

function checkPassword(passwd, vpasswd, username) {
	if (document.getElementById(passwd).value.length < 5) {
		errorMsg(passwd, 4);
		return false;
	}
	if (document.getElementById(passwd).value == document.getElementById(username).value) {
		errorMsg(passwd, 5);
		return false;
	}
	if (document.getElementById(passwd).value != document.getElementById(vpasswd).value) {
		errorMsg(passwd, 6);
		return false;
	}
	return true;
}

function checkZipcodePlus4(field) {
	if (field_str != "") {
		var zip_pattern = /^[0-9]{4}/;
		if (field.match(zip_pattern)) {
			return true;
		}
		return false;
	}
	else {
		return false;
	}
}

function checkZipcode(field) {
	if (field != "") {
		var zip_pattern = /^[0-9]{5}/;
		if (field.match(zip_pattern)) {
			return true;
		}
		return false;
	}
	else {
		return false;
	}
}

function checkPhone(field) {
	if (field != "") {
		var phone_pattern = /^[0-9]{3}-[0-9]{3}-[0-9]{4}$/;
		if (field.match(phone_pattern)) {
			return true;
		}
		return false;
	}
	else {
		return false;
	}
}

function checkEmail(field) {
	if (field != "") {
		// check if the address fits the user@domain format. It also is used to separate the username from the domain
		var email_pattern = /^(.+)@(.+)$/;
		// pattern for matching all special characters...don't allow special characters in the address...includes ( ) < > @ , ;  : \ " . [ ]
		var special_chars = "\\(\\)<>@,; :\\\\\\\"\\.\\[\\]";
		// range of characters allowed in a  username or domainname....states which chars aren't allowed
		var valid_chars = "\[^\\s" + special_chars + "\]";
		// 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. "yak boy"@disney.com is a legal address.
		var quoted_user = "(\"[^\"]*\")";
		// pattern for domains that are IP addresses, rather than symbolic names...e.g. joe@[123.124.233.4] is a legal address...square brackets are required
		var ip_domain_pattern = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
		// an atom (basically a series of non-special characters.)
		var atom = valid_chars + "+";
		// one word in the typical username...e.g. in yak.boy@somewhere.com, yak and boy are words....a word is either an atom or quoted string
		var word = "(" + atom + "|" + quoted_user + ")";
		// pattern for structure of the use
		var user_pattern = new RegExp("^" + word + "(\\." + word + ")*$");
		// pattern for structure of a normal symbolic domain, as opposed to ip_domain_pattern, shown above
		var domain_pattern = new RegExp("^" + atom + "(\\." + atom +")*$");

		// coarse pattern to break up user@domain into different pieces that are easy to analyze
		var match_array = field.match(email_pattern);
		if (match_array == null) {
		// Too many/few @'s or something;  basically, this address doesn't fit the general form of a valid address
			return false;
		}
		var user = match_array[1];
		var domain = match_array[2];
		// See if "user" is valid
		if (user.match(user_pattern) == null) {
			// user is not valid
			return false;
		}
		// if the address is at an IP make sure the IP  is valid
		var ip_array = domain.match(ip_domain_pattern);
		if (ip_array != null) {
			// an IP address
			for (var i = 1; i <= 4; i++) {
				if (ip_array[i] > 255) {
					return false;
				}
			}
			// IP ok
			return true;
		}
		// domain is symbolic name
		var domain_array = domain.match(domain_pattern);
		if (domain_array == null) {
			return false;
		}
		// break up the domain to get a count of how many atoms it consists of
		var atom_pattern = new RegExp(atom,"g");
		var dom_arr = domain.match(atom_pattern);
		var len = dom_arr.length;
		if ((dom_arr[dom_arr.length-1].length < 2) || (dom_arr[dom_arr.length-1].length > 4)) {
			// address doesn't end in a 2 - 4 letter top level domain
			return false;
		}
		// make sure there's a host name preceding the domain
		if (len < 2) {
			return false;
		}
		// all's well
		return true;
	}
	else {
		return false;
	}
}

function checkURL(field_id, field_val) {
	if (field_val != "") {
		field_val = field_val.toLowerCase();
		var url_pattern = /^((ftp|https?):\/\/)?([a-z0-9]([-a-z0-9]*[a-z0-9])?\.)+(ac|ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|asia|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cat|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|info|int|io|iq|ir|is|it|je|jm|jo|jobs|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mil|mk|ml|mm|mn|mo|mobi|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tel|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|travel|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|xn|ye|yt|yu|za|zm|zw)((\/)?([a-z0-9]([-a-z0-9]*[a-z0-9])?\.))?/;
		if (field_val.match(url_pattern)) {
			var scheme_pattern = /^ftp|https?:\/\//;
			if (!field_val.match(scheme_pattern)) {
				document.getElementById(field_id).value = "http:\/\/" + field_val;
			}
			return true;
		}
		return false;
	}
	else {
		return false;
	}
}

function checkDate(field) {
	if (field != "") {
		var url_pattern = /^([0-9]){2}(\/|-){1}([0-9]){2}(\/|-)([0-9]){4}$/;
		if (field.match(url_pattern)) {
			return true;
		}
		return false;
	}
	else {
		return false;
	}
}

function checkGroup(thisform, field) {
	var aElem = new Array();
	var type_str;
	var group_check = true;
	aElem = thisform.elements;
	for (i = 0; i < aElem.length; i++) {
		type_str = String(aElem[i].type).toLowerCase();
		if ((type_str == "radio")  || (type_str == "checkbox")) {
			if (aElem[i].name == field) {
				group_check = false;
				group = aElem[aElem[i].name];
				for (j = 0; j < group.length; j++) {				
					if (group[j].checked) {
						return true;
					}
				}
				if (!group_check) {
					errorMsg(field, 0);
					return false;
				}
			}
		}
	}
}

function checkForm(thisform) {
	var aFields= new Array();
	var fields_str;
	var field_str;
	var field;
	var field_id;
	var field_type;
	var check = true;
	if ((!document.getElementById) || (!document.createTextNode)) {
		return;
	}
	if ((!document.getElementById("required_fields")) && (!document.getElementById("format_fields"))) {
		return;
	}
	if (document.getElementById("required_fields")) {
		aFields = document.getElementById("required_fields").value.split(", ");
		fields_str = aFields;
		fields_str = fields_str.toString();
		for (var i = 0; i < aFields.length; i++) {
			field_str = aFields[i].toString();
			if (field_str.indexOf("_0") > -1) {
				check = checkGroup(thisform, field_str.substring(0, field_str.length - 2));
			}
			else {
				field  = document.getElementById(aFields[i]);
				field_id = field.id;
				if (!field) {
					continue;
				}
				clearError(field_id);
				switch(field.type.toLowerCase()) {
					case "hidden":
						changeClassName(field_id + "Frame", "");
						if (field.value == "") {
							check = false;
							errorMsg(field_id, 10);
							changeClassName(field_id + "Frame", "error");
							break;
						 }
						break;
					case "text":
						changeClassName(field_id, "text");
						if (field_id.toString().indexOf("province") > -1) {
							break;
						}
						if (field_id.toString().indexOf("Field4398609") > -1) {
							break;
						}
						if ((field.value == "") && (field_id.toString().indexOf("zip") == -1) && (field_id.toString().indexOf("Field4398611") == -1)) {
							check = false;
							errorMsg(field_id, 0);
							changeClassName(field_id, "textError");
							break;
						 }
						 else if ((field_id.toString().indexOf("email") > -1) && (!checkEmail(field.value))) {
							check = false;
							errorMsg(field_id, 1);
							changeClassName(field_id, "textError");
							break;
						}
						else if ((field_id.toString().indexOf("phone") > -1) && (!checkPhone(field.value))) {
							check = false;
							errorMsg(field_id, 2);
							changeClassName(field_id, "textError");
							break;
						}
						else if ((field_id.toString().indexOf("zip") > -1) && ((document.getElementById("country")[document.getElementById("country").selectedIndex].value == "AU") || (document.getElementById("country")[document.getElementById("country").selectedIndex].value == "BE") || (document.getElementById("country")[document.getElementById("country").selectedIndex].value == "CA") || (document.getElementById("country")[document.getElementById("country").selectedIndex].value == "CZ") || (document.getElementById("country")[document.getElementById("country").selectedIndex].value == "FI") || (document.getElementById("country")[document.getElementById("country").selectedIndex].value == "FR") || (document.getElementById("country")[document.getElementById("country").selectedIndex].value == "DE") || (document.getElementById("country")[document.getElementById("country").selectedIndex].value == "GR") || (document.getElementById("country")[document.getElementById("country").selectedIndex].value == "HU") || (document.getElementById("country")[document.getElementById("country").selectedIndex].value == "IS") || (document.getElementById("country")[document.getElementById("country").selectedIndex].value == "IT") || (document.getElementById("country")[document.getElementById("country").selectedIndex].value == "LI") || (document.getElementById("country")[document.getElementById("country").selectedIndex].value == "LT") || (document.getElementById("country")[document.getElementById("country").selectedIndex].value == "LU") || (document.getElementById("country")[document.getElementById("country").selectedIndex].value == "MK") || (document.getElementById("country")[document.getElementById("country").selectedIndex].value == "MC") || (document.getElementById("country")[document.getElementById("country").selectedIndex].value == "NL") || (document.getElementById("country")[document.getElementById("country").selectedIndex].value == "NO") || (document.getElementById("country")[document.getElementById("country").selectedIndex].value == "PL") || (document.getElementById("country")[document.getElementById("country").selectedIndex].value == "PT") || (document.getElementById("country")[document.getElementById("country").selectedIndex].value == "ES") || (document.getElementById("country")[document.getElementById("country").selectedIndex].value == "SE") || (document.getElementById("country")[document.getElementById("country").selectedIndex].value == "CH") || (document.getElementById("country")[document.getElementById("country").selectedIndex].value == "GB") || (document.getElementById("country")[document.getElementById("country").selectedIndex].value == "US")) && (!checkZipcode(field.value))) {
							check = false;
							if (field.value == "") {
								errorMsg(field_id, 0);
							}
							else {
								errorMsg(field_id, 3);
							}
							changeClassName(field_id, "textError");
							break;
						}
						else if ((field_id.toString().indexOf("Field4398611") > -1) && ((document.getElementById("Field4398612")[document.getElementById("Field4398612").selectedIndex].value == "AU") || (document.getElementById("Field4398612")[document.getElementById("Field4398612").selectedIndex].value == "BE") || (document.getElementById("Field4398612")[document.getElementById("Field4398612").selectedIndex].value == "CA") || (document.getElementById("Field4398612")[document.getElementById("Field4398612").selectedIndex].value == "CZ") || (document.getElementById("Field4398612")[document.getElementById("Field4398612").selectedIndex].value == "FI") || (document.getElementById("Field4398612")[document.getElementById("Field4398612").selectedIndex].value == "FR") || (document.getElementById("Field4398612")[document.getElementById("Field4398612").selectedIndex].value == "DE") || (document.getElementById("Field4398612")[document.getElementById("Field4398612").selectedIndex].value == "GR") || (document.getElementById("Field4398612")[document.getElementById("Field4398612").selectedIndex].value == "HU") || (document.getElementById("Field4398612")[document.getElementById("Field4398612").selectedIndex].value == "IS") || (document.getElementById("Field4398612")[document.getElementById("Field4398612").selectedIndex].value == "IT") || (document.getElementById("Field4398612")[document.getElementById("Field4398612").selectedIndex].value == "LI") || (document.getElementById("Field4398612")[document.getElementById("Field4398612").selectedIndex].value == "LT") || (document.getElementById("Field4398612")[document.getElementById("Field4398612").selectedIndex].value == "LU") || (document.getElementById("Field4398612")[document.getElementById("Field4398612").selectedIndex].value == "MK") || (document.getElementById("Field4398612")[document.getElementById("Field4398612").selectedIndex].value == "MC") || (document.getElementById("Field4398612")[document.getElementById("Field4398612").selectedIndex].value == "NL") || (document.getElementById("Field4398612")[document.getElementById("Field4398612").selectedIndex].value == "NO") || (document.getElementById("Field4398612")[document.getElementById("Field4398612").selectedIndex].value == "PL") || (document.getElementById("Field4398612")[document.getElementById("Field4398612").selectedIndex].value == "PT") || (document.getElementById("Field4398612")[document.getElementById("Field4398612").selectedIndex].value == "ES") || (document.getElementById("Field4398612")[document.getElementById("Field4398612").selectedIndex].value == "SE") || (document.getElementById("Field4398612")[document.getElementById("Field4398612").selectedIndex].value == "CH") || (document.getElementById("Field4398612")[document.getElementById("Field4398612").selectedIndex].value == "GB") || (document.getElementById("Field4398612")[document.getElementById("Field4398612").selectedIndex].value == "US")) && (!checkZipcode(field.value))) {
							check = false;
							if (field.value == "") {
								errorMsg(field_id, 0);
							}
							else {
								errorMsg(field_id, 3);
							}
							changeClassName(field_id, "textError");
							break;
						}
						break;
					case "password":
						if (field.value == "") {
							check = false;
							errorMsg(field_id, 0);
							changeClassName(field_id, "textError");
						}
						else if (!checkPassword("Password", "VerifyPassword", "LoginName")) {
							check = false;
							changeClassName(field_id, "textError");
							break;
						}
						break;
					case "textarea":
						changeClassName(field_id, "textarea");
						if (field.value == "") {
							check = false;
							errorMsg(field_id, 0);
							changeClassName(field_id, "textareaError");
						}
						break;
					case "checkbox":
						if (!field.checked) {
							check = false;
							errorMsg(field_id, 0);
						}
						break;
					case "select-one":
						if ((field_id.toString().indexOf("state") > -1) && (document.getElementById(field_id)[document.getElementById(field_id).selectedIndex].value == "")) {
							if ((fields_str.indexOf("province") > -1) && (document.getElementById("province").value != "")) {
								break;
							}
							else {
								check = false;
								errorMsg(field_id, 7);
								break;
							}
						}
						else if ((field_id.toString().indexOf("Field4398608") > -1) && (document.getElementById(field_id)[document.getElementById(field_id).selectedIndex].value == "")) {
							if ((fields_str.indexOf("Field4398609") > -1) && (document.getElementById("Field4398609").value != "")) {
								break;
							}
							else {
								check = false;
								errorMsg(field_id, 7);
								break;
							}
						}
						else if (document.getElementById(field_id)[document.getElementById(field_id).selectedIndex].value == "") {
							check = false;
							errorMsg(field_id, 0);
						}
						break;
				}
			}
		}
	}
	if (document.getElementById("format_fields")) {
		aFields = document.getElementById("format_fields").value.split(", ");
		fields_str = aFields;
		fields_str = fields_str.toString();
		for(var i = 0; i < aFields.length; i++) {
			field  = document.getElementById(aFields[i++]);
			field_type  = aFields[i];
			field_id = field.id;
			if ((!field) || (field.value == "")) {
				continue;
			}
			clearError(field_id);
			changeClassName(field_id, "text");
			switch(field_type) {
				case "[email]":
					if (!checkEmail(field.value)) {
						check = false;
						errorMsg(field_id, 1);
						changeClassName(field_id, "textError");
					}
					break;
				case "[phone]":
					if (!checkPhone(field.value)) {
						check = false;
						errorMsg(field_id, 2);
						changeClassName(field_id, "textError");
					}
					break;
				case "[zipcode]":
					if (!checkZipcode(field.value)) {
						check = false;
						errorMsg(field_id, 3);
						changeClassName(field_id, "textError");
					}
					break;
				case "[url]":
					if (!checkURL(field_id, field.value)) {
						check = false;
						errorMsg(field_id, 8);
						changeClassName(field_id, "textError");
					}
					break;
				case "[date]":
					if (!checkDate(field.value)) {
						check = false;
						errorMsg(field_id, 9);
						changeClassName(field_id, "textError");
					}
					break;
				default:
					continue;
			}
		}
	}
	if (!check) {
		document.getElementById("errorPrompt").style.display = "inline";
		return false;
	}
	else {
		document.getElementById("errorPrompt").style.display = "none";
		document.getElementById("processing").style.display = "inline";
		return true;
	}
}

/* window popup functions */
var l_popup_win;

function popupWinClosePopup() {
	if (l_popup_win) {
		l_popup_win.close();
		l_popup_win = null;
	}
}

function jsTools_popup2(url, winParams) {
	l_popup_win = window.open(url, "KinteraSphere", winParams);
	l_popup_win.focus();
}
window.onfocus = popupWinClosePopup;

function popupStickyWindow(url, width, height, b_has_top_bars) {
	var bar_str = b_has_top_bars ? "yes" : "no";
	var curr_time = new Date();
	w_popup = window.open(url, "KinteraSphere" + curr_time.getHours() + curr_time.getMinutes() + curr_time.getSeconds(), "width=" + width + ",height=" + height + ", scrollbars, resizable, menubar=" + bar_str + ", toolbar=" + bar_str);
	if (window.focus) {
		w_popup.focus();
	}
	return false;
}

function popupVolatileWindow(url, width, height, b_has_top_bars) {
	popupWinClosePopup();
	l_popup_win = popupStickyWindow(url, width, height, b_has_top_bars);
	return l_popup_win;
}

function jsTools_popup_calendar2(root_path, element, name, type) {
	var esc;
	if (type == 1) { //input box in a form
		esc = escape(element.value) + "&inp=" + name;
	}
	else if (type == 100) {
		esc = escape(element.value) + "&inp=" + name + "&cs=1";
	}
	else if (type == 200) {
		esc = escape(element.start_month.value + "/" + element.start_day.value + "/" + element.start_year.value) + "&form=" + name + "&inp=" + type;
	}
	else if (type == 300) {
		esc = escape(element.end_month.value + "/" + element.end_day.value + "/" + element.end_year.value) + "&form=" + name + "&inp=" + type;
	}
	else {
		esc = escape(element.month.value + "/" + element.day.value + "/" + element.year.value) + "&form=" + name;
	}
	jsTools_popup(root_path + "/common/asp/calendar_popup.asp?date=" + esc, 240, 265);
}

function jsTools_popup_calendar3(root_path, element, name, type, winParams) {
	var esc;
	if (type == 1)	{ //input box in a form
		esc = escape(element.value) + "&inp=" + name;
	}
	else if (type == 100) {
		esc=escape(element.value) + "&inp=" + name + "&cs=1";
	}
	else if (type == 400) {
		esc = escape(element.value) + "&inp=" + type;
	}
	else {
		esc=escape(element.month.value + "/" + element.day.value + "/" + element.year.value) + "&form=" + name;
	}
	jsTools_popup2(root_path + "/common/asp/calendar_popup.asp?date=" + esc, "width=240, height=265," + winParams);
	return l_popup_win;
}

function jsTools_popup_calendar(element, name, type) {
	jsTools_popup_calendar2("../..", element, name, type);
}

function popUp(url, win, w, h, scrollbar, stat, resize, tools, menu, loc) {
	var newWindow;
	newWindow = window.open(url, win, "height = " + h + ", width = " + w + ", scrollbars = " + scrollbar + ", status = " + stat + ", resizable = " + resize + ", toolbar = " + tools + ", menubar = " + menu + ", location = " + loc);
	if (window.focus) {
		newWindow.focus();
	}
	return false;
}

function closeFrameWin() {
	parent.window.close();
}

function getElementsByClass(searchClass, node, tag) {
	var classElements = new Array();
	if ( node == null ) {
		node = document;
	}
	if ( tag == null ) {
		tag = '*';
	}
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

/* link toggle functions */

function cancelLink() {
	return false;
}

function disableLink(link) {
	if (link.onmouseover) {
		link.oldOnMouseOver = link.onmouseover;
	}
	link.onmouseover = cancelLink;
	if (link.onmouseout) {
		link.oldOnMouseOut = link.onmouseout;
	}
	link.onmouseout = cancelLink;
	if (link.onclick) {
		link.oldOnClick = link.onclick;
	}
	link.onclick = cancelLink;
	if (link.style) {
		link.style.cursor = "default";
	}
	link.className = "disabled";
}

function enableLink(link) {
	link.onmouseover = link.oldOnMouseOver ? link.oldOnMouseOver : null;
	link.onmouseout = link.oldOnMouseOut ? link.oldOnMouseOut : null;
	link.onclick = link.oldOnClick ? link.oldOnClick : null;
	if (link.style) {
		link.style.cursor = document.all ? "hand" : "pointer";
	}
	link.className = "";
}

function toggleLink(link) {
	if (link.disabled) {
		enableLink(link);
	}
	else {
		disableLink(link);
	}
	link.disabled = !link.disabled;
}

function toggleImg(img_id, img_src_enabled, img_src_disabled) {
	src_string = new String("");
	if (document.getElementById(img_id)) {
		src_string = String(document.getElementById(img_id).src);
		 if (src_string.indexOf("Disabled.gif") > 0 ) {
			document.getElementById(img_id).src = img_src_enabled;
		}
		else {
			document.getElementById(img_id).src = img_src_disabled;
		}
	}
}

function changeClassName(btn_id, class_name) {
	document.getElementById(btn_id).className = class_name;
}

/* misc form functions */

function displayOff(elem) {
	if (document.getElementById(elem)) {
		document.getElementById(elem).style.display = "none";
	}
}

function confirmThis(ask) {
	return confirm(ask);
}

function fillDate(date_id) {
	today = new Date();
	date_str = new String();
	date_str = (today.getMonth() + 1) < 10 ? "0" + String(today.getMonth() + 1) : String(today.getMonth() + 1);
	date_str = today.getDate() < 10 ? date_str + "\/0" + String(today.getDate()) : date_str + "\/" + String(today.getDate());
	date_str = date_str + "\/" + String(today.getFullYear());
	document.getElementById(date_id).value = date_str;
}

function toggleDivOn(div1) {
	if (document.getElementById(div1).style.display == "none") {
		document.getElementById(div1).style.display = "block";
	}
}

function toggleDivOff(div1) {
	if (document.getElementById(div1).style.display == "block") {
		document.getElementById(div1).style.display = "none";
	}
}

function characterLimit(formName, fieldName, charLimit, remainingCharField) {
	var charCount = document.getElementById(fieldName).value;
	var charsUsed = charCount.length;
	var remainingChars;
	if (charsUsed >= charLimit) {
		document.getElementById(remainingCharField).value = "0";
		// truncate characters after charLimit
		 document.getElementById(fieldName).value = charCount.substring(0, charLimit);
	}
	else	{
		// update available characters
		remainingChars = (charLimit - charsUsed);
		document.getElementById(remainingCharField).value = remainingChars;
	}
}

function stripNewlines(thisform, textarea_id, prompt_id, warning_id, limit_id, limit) {
	var browser = navigator.appName;
	var b_version = navigator.appVersion;
	var version = parseFloat(b_version);
	textarea_str = new String(document.getElementById(textarea_id).value);
	if ((browser == "Microsoft Internet Explorer") || (browser == "Opera")) {
		var new_textarea_str = textarea_str.replace(new RegExp( "[\r\n]{2}", "g" ), "~" );
	}
	else if (browser == "Netscape") {
		var new_textarea_str = textarea_str.replace(new RegExp( "\\n", "g" ), "~" );
	}
	document.getElementById(span_id).innerHTML = "<span style=\"display: none;\"><textarea name=\"" + textarea_id + "\" id=\"" + textarea_id + "\" rows=\"13\" cols=\"117\">" +  new_textarea_str + "<\/textarea><\/span><textarea rows=\"13\" cols=\"117\" onKeyUp=\"checkDisabled();  characterLimit('" + thisform + "', '" + textarea_id + "', '" + limit + "', '" + limit_id + "')\" >" +  textarea_str + "<\/textarea>";
}

function replaceNewlines(thisform, textarea_id, prompt_id, warning_id, limit_id, limit) {
	var browser = navigator.appName;
	var b_version = navigator.appVersion;
	var version = parseFloat(b_version);
	textarea_str = new String(document.getElementById(textarea_id).value);
	var new_textarea_str = textarea_str.replace(new RegExp( "~", "g" ), "\n");
	document.getElementById(span_id).innerHTML = "<textarea name=\"" + textarea_id + "Field3150919\" id=\"" + textarea_id + "\" rows=\"13\" cols=\"117\" onKeyUp=\"checkDisabled(); characterLimit('" + thisform + "', '" + textarea_id + "', '" + limit + "', '" + limit_id + "')\" >" +  new_textarea_str + "<\/textarea>";
}

function textAreaSetup(thisform, textarea_id, prompt_id, warning_id, limit_id, limit) {
	replaceNewlines(thisform, textarea_id, prompt_id, warning_id, limit_id, limit);
	characterLimit(thisform, textarea_id, limit, limit_id);
}

function expandCollapseDiv(div1, img1) {
	if (document.getElementById(div1).style.display=="none") {
		document.getElementById(div1).style.display="block";
		document.getElementById(img1).src = "/atf/cf/{83b8cbf4-2aec-4bd0-a721-d9dd7ce7fcbb}/CollapseIcon.gif";
	}
	else if (document.getElementById(div1).style.display=="block") {
		document.getElementById(div1).style.display="none";
		document.getElementById(img1).src = "/atf/cf/{83b8cbf4-2aec-4bd0-a721-d9dd7ce7fcbb}/ExpandIcon.gif";
	}
}

/* processing bar */
var progressEnd = 9;		// set to number of progress <span>'s.
var progressColor = "#999999";	// set to progress bar color
var progressInterval = 500;	// set to time between updates (milli-seconds)
var progressAt = progressEnd;
var progressTimer;

function progress_clear() {
	for (var i = 1; i <= progressEnd; i++) {
		document.getElementById("progress" + i).style.backgroundColor = "transparent";
	}
	progressAt = 0;
}

function progress_update() {
	progressAt++;
	if (progressAt > progressEnd) {
		 progress_clear();
	}
	else {
		document.getElementById("progress"+progressAt).style.backgroundColor = progressColor;
	}
	progressTimer = setTimeout("progress_update()",progressInterval);
}

function progress_stop() {
	clearTimeout(progressTimer);
	progress_clear();
}

/* misc utility */
function swapImg(img_id, new_src) {
	document.getElementById(img_id).src = new_src;
}

function getCellValue (cellOrId) {
	var cell =  typeof cellOrId == 'string' ? (document.all ? document.all[cellOrId] : document.getElementById(cellOrId)) : cellOrId;
	return cell.innerHTML;
}

function traverseNodes(root) {
	var str = '';
	var node = root,
	next_node = null;
	var i = 0;
	do {
		// check for a child
		next_node = node.firstChild;
		// if no child, just visit node
		if (next_node == null) {
			// visit node if it's an element
			if (node.nodeType == 1) {
				alert("");
			}
			// check for next node
			next_node = node.nextSibling;
		}
		// if no next node
		if (next_node == null) {
			// go to the last node's level
			var tmp = node;
			do {
				// go up one level
				next_node = tmp.parentNode;
				// stop if at the top
				if (next_node == root) {
					break;
				}
				// visit node if it's an element
				if (next_node.nodeType == 1) {
					alert("");
				}
				// go to the last node's level
				tmp = next_node;
				// check for the next node
				next_node = next_node.nextSibling;
			} while (next_node == null) // there's no next node
		}
		// if there is a child, make it the new node or if we're at the following node
		node = next_node;
	} while (node != root); // not back at the top
	return false;
}

/* gradients */
function createGradient() {
	var x, y;
	var i;
	// if not a DOM browser
	if (!document.getElementById) {
		return;
	}
	objArray = getGradientObjects();
	if (!objArray.length) {
		return;
	}
	for (i = 0; i < objArray.length; i++) {
		params = objArray[i].className.split(" ");
		// if it's IE or Opera, use the MS gradient function
		if (document.all && !window.opera) {
			// take care of some alignment goofiness
			w = objArray[i].offsetWidth + 1;
			objArray[i].style.width = w + "px";
			objArray[i].style.borderRight="1px solid #ffffff";
			// set the gradient orientation
			params[3] == "horizontal" ? gType = 1 : gType = 0;
			objArray[i].style.filter = "progid:DXImageTransform.Microsoft.Gradient(GradientType=" + gType + ",StartColorStr=\"#00" + params[1] + "\",EndColorStr=\"#99" + params[2] + "\")";
		}
		else { // Mozilla
			colorArray = createColorPath(params[1], params[2]);
			// set the first color bar location
			if (objArray[i].parentNode.id == "searchForm") {
				x = 1;
				y = -1;
			}
			else {
				x = 3;
				y = 0;
			}
			if (params[3] == "horizontal") {
				// set the width of the color bar
				w = Math.round(objArray[i].offsetWidth/colorArray.length);
				if (!w) {
					w=1;
				}
				// set height
				h = objArray[i].offsetHeight;
			}
			else { // vertical
				// set height of the color bars
				h = Math.ceil(objArray[i].offsetHeight/colorArray.length);
				if (!h) {
					h =1;
				}
				// set width
				w = objArray[i].offsetWidth;
			}
			// make a new parent node that will sit on top to the gradient element
			makeGrandParent(objArray[i]);
			// make a "light" document object to place the color bars
			tmpDOM = document.createDocumentFragment();
			for(k = 0; k < colorArray.length; k++) {
				// make the color bar
				color_bar = document.createElement("div");
				color_bar.setAttribute("style","position:absolute;z-index:0;top:" + y + "px;left:" + x + "px;height:" + h + "px;width:" + w + "px;background-color:rgb(" + colorArray[k][0] + "," + colorArray[k][1] + "," + colorArray[k][2] + ");");
				// increment the color bar location
				params[3] == "horizontal" ? x+=w : y+=h;
				tmpDOM.appendChild(color_bar);
				// stop making bars if at the end of the gradient object
				if (y >= objArray[i].offsetHeight || x >= objArray[i].offsetWidth) {
					break;
				}
			}
			// add the gradient object to the document
			objArray[i].appendChild(tmpDOM);
			// plug memory leak
			tmpDOM = null;
		}
	}
}

function getGradientObjects() {
	a = document.getElementsByTagName("*");
	objs = new Array();
	for(i = 0; i < a.length; i++) {
		class_name = a[i].className;
		if (class_name != "") {
			if (class_name.indexOf("gradient") == 0) {
				objs[objs.length] = a[i];
			}
		}
	}
	return objs;
}

function createColorPath(color1,color2) {
	// make a color array for the color bars
	colorPath = new Array();
	// set the color delta
	color_pct = 1.0;
	do {
		// convert from hex to decimal rgb and fill color array
		colorPath[colorPath.length] = setColorHue(longHexToDec(color1), color_pct,longHexToDec(color2));
		// decrement the color delta
		color_pct -= .01;
	} while (color_pct > 0);
	return colorPath;
}

function setColorHue(origin_color,opacity_percent,mask_rgb) {
	// adjust the r, g & b according to the color delta...each time this function is called the startcolor gets closer to the end color
	returnColor = new Array();
	for (w = 0; w < origin_color.length; w++) {
		returnColor[w] = Math.round(origin_color[w] * opacity_percent) + Math.round(mask_rgb[w] * (1.0 - opacity_percent));
	}
	return returnColor;
}

function longHexToDec(longHex) {
	// conver the hex rgb channels to decimal
	return new Array(toDec(longHex.substring(0,2)), toDec(longHex.substring(2,4)), toDec(longHex.substring(4,6)));
}

function toDec(hex) {
	return parseInt(hex, 16);
}

function makeGrandParent(obj) {
	disp = document.defaultView.getComputedStyle(obj,'').display;
	// if the gradient object is a block element make a div, otherwise make a span
	disp == "block" ? nSpan = document.createElement("div") : nSpan = document.createElement("span");
	// save the contents of the gradient object
	mHTML = obj.innerHTML;
	// clear out the contents of the gradient object
	obj.innerHTML = "";
	// put the saved contents into the new div or span
	nSpan.innerHTML = mHTML;
	// put the new div or span on top of the gradient object
	nSpan.setAttribute("style", "position:relative; z-index:10;");
	obj.appendChild(nSpan);
}

function adjustGradient(root) {
	var node = document.getElementById(root).firstChild;
	var ht = document.defaultView.getComputedStyle(node, "").height.toString();
	first_gradient_bar = node.nextSibling;
	node = first_gradient_bar;
	do {
		if (node.nodeName == "DIV") {
			node.style.display = "none";
		}
		node = node.nextSibling;
	} while (node != document.getElementById(root).lastChild);
	node = first_gradient_bar;
	var bar_ht = document.defaultView.getComputedStyle(node, "").height.toString();
	for (i = 0; i < (Math.floor(Number(ht.substring(0, ht.length -2)) / Number(bar_ht.substring(0, bar_ht.length -2)))); i++) {
		if (node.nodeName == "DIV") {
			node.style.display = (node.style.display == "none") ? "block" : "none";
		}
		node = node.nextSibling;
	}
}

function toggleSiblings(root, btn1, btn2) {
	var node = document.getElementById(root);
	while (node) {
		node = node.nextSibling;
		if (node == null) {
			break;
		}
		if (node.nodeType == 1) {
			if ((node.getAttribute("id") != btn1) && (node.getAttribute("id") != btn2)) {
				node.style.display = (node.style.display == "none") ? "block" : "none";
			}
		}
	}
}

/* custom search */
function toggleSearch(search_id, gradient_id, hide_id, show_id) {
	document.getElementById(hide_id).style.display = (document.getElementById(hide_id).style.display == "none") ?  "block" : "none";
	document.getElementById(show_id).style.display = (document.getElementById(show_id).style.display == "block") ?  "none" : "block";
	document.getElementById(search_id).style.display = (document.getElementById(search_id).style.display == "none") ?  "block" : "none";
	if (!(document.all && !window.opera)) {
		adjustGradient(gradient_id);
	}
}

function toggleFieldset(set_id, gradient_id, hide_id, show_id) {
	document.getElementById(hide_id).style.display = (document.getElementById(hide_id).style.display == "none") ?  "block" : "none";
	document.getElementById(show_id).style.display = (document.getElementById(show_id).style.display == "block") ?  "none" : "block";
	toggleSiblings(set_id, hide_id, show_id);
	if (!(document.all && !window.opera)) {
		adjustGradient(gradient_id);
	}
}

function radioGroups(thisform) {
	var i;
	var j;
	var group;
	var field;
	var aElem = thisform.elements;
	for (i = 0; i < aElem.length; i++) {
		if (aElem[i].type == "radio") {
			group = aElem[aElem[i].name];
			for (j = 0; j < group.length; j++) {
				if (group[j].checked) {
					field = "fiel" + group[j].name;
					document.getElementById(field).value = group[j].value;
				}
			}
		}
	}
}

function checkboxes(thisform) {
	var i;
	var j;
	var use_group;
	var group;
	var field;
	var aElem = thisform.elements;
	for (i = 0; i < aElem.length; i++) {
		if (aElem[i].type == "checkbox") {
			use_group = false;
			group = aElem[aElem[i].name];
			if (i > 0) {
				if (aElem[aElem[i].name] != aElem[aElem[i-1].name]) {
					if (group.length) {
						for (j = 0; j < group.length; j++) {
							field = "fiel" + group[j].name;
							if (group[j].checked) {
								use_group = true;
								document.getElementById(field).value = document.getElementById(field).value + group[j].value;
							}
							else {
								document.getElementById(field).value = document.getElementById(field).value + "No" + group[j].value;
							}
						}
						document.getElementById(field).value = (use_group) ? document.getElementById(field).value : "";
					}
					else {
						field = "fiel" + group.name;
						if (group.checked) {
							document.getElementById(field).value = group.value;
						}
					}
				}
			}
		}
	}
}

function selectOnes(thisform) {
	var i;
	var elem;
	var aElem = thisform.elements;
	for (i = 0; i < aElem.length; i++) {
		if (aElem[i].type == "select-one") {
			list = aElem[i].name.toString();
			if ((list.indexOf("op") != 0) && (list.indexOf("state") != 0)) {
				elem = list.substring(0, list.length - 1);
				document.getElementById(elem).value = document.getElementById(list)[document.getElementById(list).selectedIndex].value;
			}
		}
	}
}

function submitSearch(thisform) {
	displayProcessing();
	if (document.getElementById("field_4506122")) {
		document.getElementById("field_4506122").value = "";
	}
	if (document.getElementById("field_4506123")) {
		document.getElementById("field_4506123").value = "";
	}
	if (document.getElementById("field_4506124")) {
		document.getElementById("field_4506124").value = "";
	}
	if (document.getElementById("field_4506125")) {
		document.getElementById("field_4506125").value = "";
	}
	if (document.getElementById("field_4506126")) {
		document.getElementById("field_4506126").value = "";
	}
	if (document.getElementById("field_4506127")) {
		document.getElementById("field_4506127").value = "";
	}
	if (document.getElementById("field_4342339")) {
		document.getElementById("field_4342339").value = "";
	}
	if (document.getElementById("field_4367316")) {
		document.getElementById("field_4367316").value = "";
	}
	if (document.getElementById("field_4367317")) {
		document.getElementById("field_4367317").value = "";
	}
	if (document.getElementById("field_4367318")) {
		document.getElementById("field_4367318").value = "";
	}
	if (document.getElementById("field_4367319")) {
		document.getElementById("field_4367319").value = "";
	}
	if (document.getElementById("field_4367320")) {
		document.getElementById("field_4367320").value = "";
	}
	if (document.getElementById("field_4367321")) {
		document.getElementById("field_4367321").value = "";
	}
	if (document.getElementById("field_4367323")) {
		document.getElementById("field_4367323").value = "";
	}
	if (document.getElementById("field_4367325")) {
		document.getElementById("field_4367325").value = "";
	}
	if ((document.getElementById("field_4388583")) && (document.getElementById("d_4388583")) && (location.href.indexOf("3944071") == -1)) {
		document.getElementById("field_4388583").value = "";
	}
	if ((document.getElementById("country")) && (document.getElementById("country_"))) {
		document.getElementById("country").value = "";
	}
	radioGroups(thisform);
	checkboxes(thisform);
	selectOnes(thisform);
	if (document.getElementById("field_4506122")) {
		thisform.field_4506122.value = document.getElementById("field_4506122").value;
	}
	if (document.getElementById("field_4506123")) {
		thisform.field_4506123.value = document.getElementById("field_4506123").value;
	}
	if (document.getElementById("field_4506124")) {
		thisform.field_4506124.value = document.getElementById("field_4506124").value;
	}
	if (document.getElementById("field_4506125")) {
		thisform.field_4506125.value = document.getElementById("field_4506125").value;
	}
	if (document.getElementById("field_4506126")) {
		thisform.field_4506126.value = document.getElementById("field_4506126").value;
	}
	if (document.getElementById("field_4506127")) {
		thisform.field_4506127.value = document.getElementById("field_4506127").value;
	}
	if (document.getElementById("field_4342339")) {
		thisform.field_4342339.value = document.getElementById("field_4342339").value;
	}
	if (document.getElementById("field_4367316")) {
		thisform.field_4367316.value = document.getElementById("field_4367316").value;
	}
	if (document.getElementById("field_4367317")) {
		thisform.field_4367317.value = document.getElementById("field_4367317").value;
	}
	if (document.getElementById("field_4367318")) {
		thisform.field_4367318.value = document.getElementById("field_4367318").value;
	}
	if (document.getElementById("field_4367319")) {
		thisform.field_4367319.value = document.getElementById("field_4367319").value;
	}
	if (document.getElementById("field_4367320")) {
		thisform.field_4367320.value = document.getElementById("field_4367320").value;
	}
	if (document.getElementById("field_4367321")) {
		thisform.field_4367321.value = document.getElementById("field_4367321").value;
	}
	if (document.getElementById("field_4367323")) {
		thisform.field_4367323.value = document.getElementById("field_4367323").value;
	}
	if (document.getElementById("field_4367325")) {
		thisform.field_4367325.value = document.getElementById("field_4367325").value;
	}
	if ((document.getElementById("field_4388583")) && (document.getElementById("d_4388583")))  {
		thisform.field_4388583.value = document.getElementById("field_4388583").value;
	}
	if ((document.getElementById("country")) && (document.getElementById("country_"))) {
		thisform.country.value = document.getElementById("country").value;
	}
	return true;
}

function clearForm(thisform) {
	var i;
	var j;
	var elem;
	var aElem = thisform.elements;
	for (i = 0; i < aElem.length; i++) {
		if (aElem[i].type == "radio") {
			elem = aElem[aElem[i].name];
			for (j = 0; j < elem.length; j++) {
				elem[j].checked = false;
			}
		}
		if (aElem[i].type == "checkbox") {
			elem = aElem[aElem[i].name];
			if (elem.length) {
				for (j = 0; j < elem.length; j++) {
					elem[j].checked = false;
				}
			}
			else {
				elem.checked = false;
			}
		}
		if (aElem[i].type == "select-one") {
			elem = aElem[i].name.toString();
			if (elem.indexOf("op") != 0) {
				document.getElementById(elem).selectedIndex = 0;
			}
		}
		if (aElem[i].type == "text") {
			elem = aElem[i].name.toString();
			document.getElementById(elem).value = "";
		}
	}
}

function getAll(thisform) {
	displayProcessing();
	if (thisform.field_4342339) {
		thisform.field_4342339.value = "";
	}
	if (thisform.field_4367316) {
		thisform.field_4367316.value = "";
	}
	if (thisform.field_4367317) {
		thisform.field_4367317.value = "";
	}
	if (thisform.field_4367318) {
		thisform.field_4367318.value = "";
	}
	if (thisform.field_4367319) {
		thisform.field_4367319.value = "";
	}
	if (thisform.field_4367320) {
		thisform.field_4367320.value = "";
	}
	if (thisform.field_4367321) {
		thisform.field_4367321.value = "";
	}
	if (thisform.field_4367323) {
		thisform.field_4367323.value = "";
	}
	if (thisform.field_4367325) {
		thisform.field_4367325.value = "";
	}
	if ((thisform.field_4388583) && (location.href.indexOf("3944071") == -1) ) {
		thisform.field_4388583.value = "";
	}
	if ((document.getElementById("country")) && (document.getElementById("country_"))) {
		thisform.country.value = "";
	}
	clearForm(thisform);
	radioGroups(thisform);
	checkboxes(thisform);
	selectOnes(thisform);
	document.getElementById("Submit").click();
}

function clearSearch(thisform) {
	displayProcessing();
	if (thisform.field_4342339) {
		thisform.field_4342339.value = "";
	}
	if (thisform.field_4367316) {
		thisform.field_4367316.value = "";
	}
	if (thisform.field_4367317) {
		thisform.field_4367317.value = "";
	}
	if (thisform.field_4367318) {
		thisform.field_4367318.value = "";
	}
	if (thisform.field_4367319) {
		thisform.field_4367319.value = "";
	}
	if (thisform.field_4367320) {
		thisform.field_4367320.value = "";
	}
	if (thisform.field_4367321) {
		thisform.field_4367321.value = "";
	}
	if (thisform.field_4367323) {
		thisform.field_4367323.value = "";
	}
	if (thisform.field_4367325) {
		thisform.field_4367325.value = "";
	}
	if ((thisform.field_4388583) && (location.href.indexOf("3944071") == -1)) {
		thisform.field_4388583.value = "";
	}
	if (thisform.country) {
		thisform.country.value = "";
	}
	clearForm(thisform);
	thisform.getElementById("company").style.color = "#ffffff";
	thisform.company.value = "()$Gt5zzO87@!";
	SetCookie("clearSearch", 1, null, "/");
	document.getElementById("Submit").click();
}

function showDetails(id_num, radio) {
	var i;
	rl = radio.length;
	if (!(rl > 1)) {
		radio.checked = true;
	}
	else {
		for (var i = 0; i < rl; i++) {
			if (id_num == radio[i].value) {
				radio[i].checked = true;
			}
		}
	}
	SetCookie("goToDetails", 1, null, "/");
	document.docForm.Select.click();
	return false;
}

function getGoToPage(contents) {
	aContents = new Array();
	aTemp = new Array();
	var i = 0;
	var contents = contents.toLowerCase();
	aContents = contents.split("&nbsp;");
	if (aContents[aContents.length - 2].indexOf("10") > -1) {
		aContents[aContents.length - 2] = aContents[aContents.length - 2].replace(new RegExp( "\"\>(?!next)", "gi"), "&nbsp;");
		aTemp = aContents[aContents.length - 2].split("&nbsp;");
		aContents.pop();
		aContents.pop();
		aContents = aContents.concat(aTemp);
	}
	else {
		aContents.splice((aContents.length - 1), 1)
	}
	aContents[0] = aContents[0].replace(new RegExp( "prev"), "<img src=\"\/atf\/cf\/{8712CBAB-0EA9-444F-9B5D-35B87FB672ED}\/PreviousArrow.gif\" width=\"6\" height=\"11\" border=\"0\" alt=\"Previous\" \/>" );
	if (aContents[0].indexOf("<a") > -1) {
		aTemp = aContents[0].split("<a ");
		aContents[0] = "<a class=\"prev\" " + aTemp[1];
	}
	aContents[(aContents.length - 1)] = aContents[(aContents.length - 1)].replace(new RegExp( "next"), "<img src=\"\/atf\/cf\/{8712CBAB-0EA9-444F-9B5D-35B87FB672ED}\/NextArrow.gif\" width=\"6\" height=\"11\" border=\"0\" alt=\"Next\" \/>" );
	aContents[(aContents.length - 1)] = (aContents[(aContents.length - 1)].indexOf("<a") == -1) ? aContents[(aContents.length - 1)].substring((aContents[(aContents.length - 1)].lastIndexOf("<\/font>") + 8), aContents[(aContents.length - 1)].length) : aContents[(aContents.length - 1)].substring((aContents[(aContents.length - 1)].indexOf("<\/a>") + 4), aContents[(aContents.length - 1)].length);
	if (aContents[(aContents.length - 1)].indexOf("<a") > -1) {
		aTemp = aContents[(aContents.length - 1)].split("<a ");
		aContents[(aContents.length - 1)] = "<a class=\"next\" " + aTemp[1];
	}
	for (i = 1; i < aContents.length - 1; i++) {
		if ((aContents[0].indexOf("<a") > -1) && (i == 1)) {
			aContents[i] = aContents[i] + i + "<\/a>";
		}
		else if (aContents[i].indexOf("<\/font") == 2) {
			aContents[i] = aContents[i].substring(10, aContents[i].length) + "\"\>" + i + "<\/a>";
		}
		else if (aContents[i].indexOf("<\/font") == 1) {
			aContents[i] = aContents[i].substring(9, aContents[i].length) + i + "<\/a>";
		}
		else if ((aContents[i].indexOf("<\/a") == 1) && (aContents[i].indexOf("10") > - 1) && (aContents[i].indexOf("background-color") == -1)) {
			aContents[i] = aContents[i].substring(6, aContents[i].length) + "\">" + i + "<\/a>";
		}
		else if ((aContents[i].indexOf("<\/a") == 1) && (aContents[i].indexOf("background-color") == -1)) {
			aContents[i] = aContents[i].substring(6, aContents[i].length) + i + "<\/a>";
		}
		else if ((aContents[i].indexOf("<\/a") == 2) && (aContents[i].indexOf("background-color") == -1)) {
			aContents[i] = aContents[i].substring(7, aContents[i].length) + "\">" + i + "<\/a>";
		}
		else if (aContents[i].indexOf("background-color") > -1) {
			aContents[i] = "<span class=\"noLink\">" + i + "<\/span>";
		}
	}
	return contents = aContents;
}

function getNumShowing(contents) {
	return contents =  (contents.indexOf("Showing 1-1 of 1 Record (1 page)") > -1) ? ("Showing 1-1 of 1 Result") : (contents.substring(contents.indexOf("Showing"), contents.indexOf("Records")) + "Results");
}

function cleanCell(contents) {
	aContents = new Array(3);
	if (contents.indexOf("<a") > -1) {
		aContents[0] = contents.substring(contents.indexOf("<a"), contents.indexOf("<\/a>") + 4);
	}
	else {
		aContents[0] = contents.substring(contents.indexOf("<A"), contents.indexOf("<\/A>") + 4);
	}
	aContents[0] = aContents[0].replace(new RegExp( "FulfillmentStatus", "i" ), "Status" );
	aContents[0] = aContents[0].replace(new RegExp( "Address Line 1", "i" ), "Address" );
	aContents[0] = aContents[0].replace(new RegExp( "ZIP/Postal Code", "i" ), "Zip" );
	aContents[0] = aContents[0].replace(new RegExp( "PriorityLevel", "i" ), "Priority" );
	aContents[0] = aContents[0].replace(new RegExp( "RequestDate", "i" ), "Date" );
	aContents[0] = aContents[0].replace(new RegExp( "RequestStatus", "i" ), "Status" );
	aContents[1] = (contents.indexOf("\/Spherelite\/Images\/sort_asc_arrow.gif") > -1) ?  "<img src=\"\/atf\/cf\/{8712CBAB-0EA9-444F-9B5D-35B87FB672ED}\/SortAsc.gif\" width=\"7\" height=\"7\" border=\"0\" alt=\"Sort\">" : "";
	if (aContents[1] == "") {
		aContents[1] = (contents.indexOf("\/Spherelite\/Images\/sort_desc_arrow.gif") > -1) ?  "<img src=\"\/atf\/cf\/{8712CBAB-0EA9-444F-9B5D-35B87FB672ED}\/SortDesc.gif\" width=\"7\" height=\"7\" border=\"0\" alt=\"Sort\">" : "";
	}
	return aContents;
}


function formatResults2() {
	aContents = new Array(3);
	var contents = "";
	var i, j, k;
	var new_row, new_cell, new_html;
	var id_pattern = /[A-Za-z0-9]{10,}/;
	var supporter_id;
	var old_pagination = document.getElementById("CLpaginationArea");
	var aTables = old_pagination.getElementsByTagName("TABLE");
	var old_tbl = aTables[1];

	top_pagination = document.createElement("div");
	num_showing = document.createElement("div");
	num_showing.setAttribute("id", "numShowing");
	new_html  = document.createTextNode(getNumShowing(getCellValue(old_tbl.rows[0].cells[0])));
	num_showing.appendChild(new_html);
	top_pagination.appendChild(num_showing);
	go_to_page = document.createElement("div");
	go_to_page.setAttribute("id", "goToPage");
	new_html  = document.createTextNode("");
	go_to_page.appendChild(new_html);
	aContents = getGoToPage(getCellValue(old_tbl.rows[1].cells[0]));
	for (i = 0; i < aContents.length; i++) {
		contents = contents + aContents[i];
	}
	go_to_page.innerHTML = contents;
	contents = "";
	top_pagination.appendChild(go_to_page);
	var mark = document.getElementById("topPaginationMarker");
	var parent_node = mark.parentNode;
	parent_node.insertBefore(top_pagination, mark);
	bottom_pagination = document.createElement("div");
	num_showing = document.createElement("div");
	num_showing.setAttribute("id", "numShowingBot");
	new_html  = document.createTextNode(getNumShowing(getCellValue(old_tbl.rows[0].cells[0])));
	num_showing.appendChild(new_html);
	bottom_pagination.appendChild(num_showing);
	go_to_page = document.createElement("div");
	go_to_page.setAttribute("id", "goToPageBot");
	new_html  = document.createTextNode("");
	go_to_page.appendChild(new_html);
	aContents = getGoToPage(getCellValue(old_tbl.rows[1].cells[0]));
	for (i = 0; i < aContents.length; i++) {
		contents = contents + aContents[i];
	}
	go_to_page.innerHTML = contents;
	contents = "";
	bottom_pagination.appendChild(go_to_page);
	var mark = document.getElementById("bottomPaginationMarker");
	var parent_node = mark.parentNode;
	parent_node.insertBefore(bottom_pagination, mark);
	var old_results = document.getElementById("CLsearchResultsArea");
	aTables = old_results.getElementsByTagName("TABLE");
	old_tbl = aTables[1];
	result_list = document.createElement("div");
	result_list.setAttribute("id", "customList");
	gradient = document.createElement("div");
	gradient.setAttribute("id", "resultsGradient");
	gradient.setAttribute("class", "set");
	result_list.appendChild(gradient);
	result_tbl = document.createElement("table");
	result_tbl.setAttribute("cellspacing", "0");
	result_tbl.cellSpacing = "0";
	// header row
	new_row = result_tbl.insertRow(0);
	new_cell  = new_row.insertCell(0);
	new_cell.setAttribute("class", "header");
	new_cell.className = "header";
	result_list.setAttribute("width", "auto");
	for (i = 1; i < old_tbl.rows[0].cells.length; i++) {
		new_cell  = new_row.insertCell(i);
		aContents = cleanCell(getCellValue(old_tbl.rows[0].cells[i]));
		if (aContents[1] == "") {
			new_cell.setAttribute("class", "header");
			new_cell.className = "header";
		}
		else {
			new_cell.setAttribute("class", "sort");
			new_cell.className = "sort";
		}
		new_html  = document.createTextNode("");
		new_cell.appendChild(new_html);
		contents = "<a href=\"\" onClick=\"return showDetails('" + supporter_id + "', document.docForm.supporter_id);\">" + contents + "<\/a>"
		new_cell.innerHTML = aContents[0] + aContents[1];
		if ((i == old_tbl.rows[0].cells.length - 1) && (aContents[1] !="")) {
			new_row.cells[new_row.cells.length - 1].innerHTML = new_row.cells[new_row.cells.length - 1].innerHTML+ aContents[1];
		}
	}
	// results list
	for (i = 3; i < old_tbl.rows.length; i++) {
		new_row = result_tbl.insertRow(i - 2);
		new_cell  = new_row.insertCell(0);
		// get the value of the supporter_id
		link_cell = getCellValue(old_tbl.rows[i].cells[0]);
		aMatch = id_pattern.exec(link_cell);
		if (aMatch) {
			supporter_id = aMatch[0];
		}
		for (j = 1; j < old_tbl.rows[i].cells.length; j++) {
			new_cell  = new_row.insertCell(j);
			new_html  = document.createTextNode(getCellValue(old_tbl.rows[i].cells[j]));
			new_cell.appendChild(new_html);
			if (j == 1) {
				contents = getCellValue(new_cell);
				contents = contents.replace(new RegExp( "&amp;", "i" ), "&" );
				// turn the org name cell into a link to select the org as looked up contact
				new_cell.innerHTML = "<a href=\"\" onClick=\"return showDetails('" + supporter_id + "', document.docForm.supporter_id);\">" + contents + "<\/a>";
			}
		}
	}
	gradient.appendChild(result_tbl);
	mark = document.getElementById("resultsMarker");
	parent_node = mark.parentNode;
	parent_node.insertBefore(result_list, mark);
}


function formatResults() {
	aContents = new Array(3);
	var contents = "";
	var i, j, k;
	var new_row, new_cell, new_html;
	var id_pattern = /[A-Za-z0-9]{10,}/;
	var supporter_id;
	var old_pagination = document.getElementById("CLpaginationArea");
	var aTables = old_pagination.getElementsByTagName("TABLE");
	var old_tbl = aTables[1];

	top_pagination = document.createElement("div");
	num_showing = document.createElement("div");
	num_showing.setAttribute("id", "numShowing");
	new_html  = document.createTextNode(getNumShowing(getCellValue(old_tbl.rows[0].cells[0])));
	num_showing.appendChild(new_html);
	top_pagination.appendChild(num_showing);
	go_to_page = document.createElement("div");
	go_to_page.setAttribute("id", "goToPage");
	new_html  = document.createTextNode("");
	go_to_page.appendChild(new_html);
	aContents = getGoToPage(getCellValue(old_tbl.rows[1].cells[0]));
	for (i = 0; i < aContents.length; i++) {
		contents = contents + aContents[i];
	}
	go_to_page.innerHTML = contents;
	contents = "";
	top_pagination.appendChild(go_to_page);
	var mark = document.getElementById("topPaginationMarker");
	var parent_node = mark.parentNode;
	parent_node.insertBefore(top_pagination, mark);
	bottom_pagination = document.createElement("div");
	num_showing = document.createElement("div");
	num_showing.setAttribute("id", "numShowingBot");
	new_html  = document.createTextNode(getNumShowing(getCellValue(old_tbl.rows[0].cells[0])));
	num_showing.appendChild(new_html);
	bottom_pagination.appendChild(num_showing);
	go_to_page = document.createElement("div");
	go_to_page.setAttribute("id", "goToPageBot");
	new_html  = document.createTextNode("");
	go_to_page.appendChild(new_html);
	aContents = getGoToPage(getCellValue(old_tbl.rows[1].cells[0]));
	for (i = 0; i < aContents.length; i++) {
		contents = contents + aContents[i];
	}
	go_to_page.innerHTML = contents;
	contents = "";
	bottom_pagination.appendChild(go_to_page);
	var mark = document.getElementById("bottomPaginationMarker");
	var parent_node = mark.parentNode;
	parent_node.insertBefore(bottom_pagination, mark);
	var old_results = document.getElementById("CLsearchResultsArea");
	aTables = old_results.getElementsByTagName("TABLE");
	old_tbl = aTables[1];
	result_list = document.createElement("div");
	result_list.setAttribute("id", "customList");
	gradient = document.createElement("div");
	gradient.setAttribute("id", "resultsGradient");
	gradient.setAttribute("class", "set");
	result_list.appendChild(gradient);
	result_tbl = document.createElement("table");
	result_tbl.setAttribute("cellspacing", "0");
	result_tbl.cellSpacing = "0";
	// header row
	new_row = result_tbl.insertRow(0);
	new_cell  = new_row.insertCell(0);
	new_cell.setAttribute("class", "header");
	new_cell.className = "header";
	result_list.setAttribute("width", "auto");
	for (i = 1; i < old_tbl.rows[0].cells.length; i++) {
		if ((i != old_tbl.rows[0].cells.length - 1) && (i != old_tbl.rows[0].cells.length - 2) && (i != old_tbl.rows[0].cells.length - 3)) {
			new_cell  = new_row.insertCell(i);
		}
		aContents = cleanCell(getCellValue(old_tbl.rows[0].cells[i]));
		if (aContents[1] == "") {
			if ((i != old_tbl.rows[0].cells.length - 1) && (i != old_tbl.rows[0].cells.length - 2) && (i != old_tbl.rows[0].cells.length - 3)) {
				new_cell.setAttribute("class", "header");
				new_cell.className = "header";
			}
		}
		else {
			if ((i != old_tbl.rows[0].cells.length - 1) && (i != old_tbl.rows[0].cells.length - 2) && (i != old_tbl.rows[0].cells.length - 3)) {
				new_cell.setAttribute("class", "sort");
				new_cell.className = "sort";
			}
		}
		if ((i != old_tbl.rows[0].cells.length - 1) && (i != old_tbl.rows[0].cells.length - 2) && (i != old_tbl.rows[0].cells.length - 3)) {
			new_html  = document.createTextNode("");
			new_cell.appendChild(new_html);
			contents = "<a href=\"\" onClick=\"return showDetails('" + supporter_id + "', document.docForm.supporter_id);\">" + contents + "<\/a>"
			new_cell.innerHTML = aContents[0] + aContents[1];
		}
		if ((i == old_tbl.rows[0].cells.length - 1) && (aContents[1] !="")) {
			new_row.cells[new_row.cells.length - 1].innerHTML = new_row.cells[new_row.cells.length - 1].innerHTML+ aContents[1];
		}
	}
	// results list
	for (i = 3; i < old_tbl.rows.length; i++) {
		new_row = result_tbl.insertRow(i - 2);
		new_cell  = new_row.insertCell(0);
		// get the value of the supporter_id
		link_cell = getCellValue(old_tbl.rows[i].cells[0]);
		aMatch = id_pattern.exec(link_cell);
		if (aMatch) {
			supporter_id = aMatch[0];
		}
		for (j = 1; j < old_tbl.rows[i].cells.length; j++) {
			if ((j != old_tbl.rows[i].cells.length - 1) && (j != old_tbl.rows[i].cells.length - 2) && (j != old_tbl.rows[i].cells.length - 3)) {
				new_cell  = new_row.insertCell(j);
				new_html  = document.createTextNode(getCellValue(old_tbl.rows[i].cells[j]));
				new_cell.appendChild(new_html);
				if (j == 1) {
					contents = getCellValue(new_cell);
					contents = contents.replace(new RegExp( "&amp;", "i" ), "&" );
					// turn the org name cell into a link to select the org as looked up contact
					new_cell.innerHTML = "<a href=\"\" onClick=\"return showDetails('" + supporter_id + "', document.docForm.supporter_id);\">" + contents + "<\/a>";
				}
				if (j == old_tbl.rows[i].cells.length - 5) {
					new_cell.className = "centered";
					contents = getCellValue(new_cell);
					switch (contents) {
						case "1" :
							new_cell.innerHTML = "<img class=\"flag\" src=\"/atf/cf/{8712CBAB-0EA9-444F-9B5D-35B87FB672ED}/FlagHigh.gif\" width=\"13\" height=\"12\" border=\"0\" alt=\"High Priority\" \/>";
							break;
						case "2" :
							new_cell.innerHTML = "<img class=\"flag\" src=\"/atf/cf/{8712CBAB-0EA9-444F-9B5D-35B87FB672ED}/FlagNormal.gif\" width=\"13\" height=\"12\" border=\"0\" alt=\"Normal Priority\" \/>";
							break;
						case "3" :
							new_cell.innerHTML = "<img class=\"flag\" src=\"/atf/cf/{8712CBAB-0EA9-444F-9B5D-35B87FB672ED}/FlagLow.gif\" width=\"13\" height=\"12\" border=\"0\" alt=\"Low Priority\" \/>";
							break;
						case "4" :
							new_cell.innerHTML = "<img class=\"flag\" src=\"/atf/cf/{8712CBAB-0EA9-444F-9B5D-35B87FB672ED}/Blacklist.gif\" width=\"13\" height=\"13\" border=\"0\" alt=\"Blacklist Country\" \/>";
							break;
						default:
							new_cell.innerHTML = "<img class=\"flag\" src=\"/atf/cf/{8712CBAB-0EA9-444F-9B5D-35B87FB672ED}/FlagNormal.gif\" width=\"13\" height=\"12\" border=\"0\" alt=\"Normal Priority\" \/>";
					}
				}
			}
		}
	}
	gradient.appendChild(result_tbl);
	mark = document.getElementById("resultsMarker");
	parent_node = mark.parentNode;
	parent_node.insertBefore(result_list, mark);
}

function sizePage() {
	document.getElementById("__pagesize").selectedIndex = document.getElementById("pageSize").selectedIndex;
	gosize();
}

function getPageSize(contents) {
	 document.getElementById("pageSize").selectedIndex = document.getElementById("__pagesize").selectedIndex;
}

function goBack(num) {
	window.history.go(Number(num));
}

/* frames */
function toggleFrame(frame_id_collapse, frame_id_expand, ht1, ht2, hide_id, show_id) {
	document.getElementById(frame_id_collapse).style.height = ht1;
	document.getElementById(frame_id_expand).style.height = ht2;
	document.getElementById(hide_id).style.display = (document.getElementById(hide_id).style.display == "none") ?  "block" : "none";
	document.getElementById(show_id).style.display = (document.getElementById(show_id).style.display == "block") ?  "none" : "block";
}

/* calendar */
function positionInfo(object) {
  var p_elm = object;
  this.getElementLeft = getElementLeft;
  function getElementLeft() {
    var x = 0;
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    while (elm != null) {
      x+= elm.offsetLeft;
      elm = elm.offsetParent;
    }
    return parseInt(x);
  }

  this.getElementWidth = getElementWidth;
  function getElementWidth(){
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    return parseInt(elm.offsetWidth);
  }

  this.getElementRight = getElementRight;
  function getElementRight(){
    return getElementLeft(p_elm) + getElementWidth(p_elm);
  }

  this.getElementTop = getElementTop;
  function getElementTop() {
    var y = 0;
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    while (elm != null) {
      y+= elm.offsetTop;
      elm = elm.offsetParent;
    }
    return parseInt(y);
  }

  this.getElementHeight = getElementHeight;
  function getElementHeight(){
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    return parseInt(elm.offsetHeight);
  }

  this.getElementBottom = getElementBottom;
  function getElementBottom(){
    return getElementTop(p_elm) + getElementHeight(p_elm);
  }
}

function CalendarControl() {

  var calendarId = 'CalendarControl';
  var currentYear = 0;
  var currentMonth = 0;
  var currentDay = 0;

  var selectedYear = 0;
  var selectedMonth = 0;
  var selectedDay = 0;

  var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
  var dateField = null;

  function getProperty(p_property){
    var p_elm = calendarId;
    var elm = null;

    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    if (elm != null){
      if(elm.style){
        elm = elm.style;
        if(elm[p_property]){
          return elm[p_property];
        } else {
          return null;
        }
      } else {
        return null;
      }
    }
  }

  function setElementProperty(p_property, p_value, p_elmId){
    var p_elm = p_elmId;
    var elm = null;

    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    if((elm != null) && (elm.style != null)){
      elm = elm.style;
      elm[ p_property ] = p_value;
    }
  }

  function setProperty(p_property, p_value) {
    setElementProperty(p_property, p_value, calendarId);
  }

  function getDaysInMonth(year, month) {
    return [31,((!(year % 4 ) && ( (year % 100 ) || !( year % 400 ) ))?29:28),31,30,31,30,31,31,30,31,30,31][month-1];
  }

  function getDayOfWeek(year, month, day) {
    var date = new Date(year,month-1,day)
    return date.getDay();
  }

  this.clearDate = clearDate;
  function clearDate() {
    dateField.value = '';
    hide();
  }

  this.setDate = setDate;
  function setDate(year, month, day) {
    if (dateField) {
      if (month < 10) {month = "0" + month;}
      if (day < 10) {day = "0" + day;}

      var dateString = month+"/"+day+"/"+year;
      dateField.value = dateString;
      hide();
    }
    return;
  }

  this.changeMonth = changeMonth;
  function changeMonth(change) {
    currentMonth += change;
    currentDay = 0;
    if(currentMonth > 12) {
      currentMonth = 1;
      currentYear++;
    } else if(currentMonth < 1) {
      currentMonth = 12;
      currentYear--;
    }

    calendar = document.getElementById(calendarId);
    calendar.innerHTML = calendarDrawTable();
  }

  this.changeYear = changeYear;
  function changeYear(change) {
    currentYear += change;
    currentDay = 0;
    calendar = document.getElementById(calendarId);
    calendar.innerHTML = calendarDrawTable();
  }

  function getCurrentYear() {
    var year = new Date().getYear();
    if(year < 1900) year += 1900;
    return year;
  }

  function getCurrentMonth() {
    return new Date().getMonth() + 1;
  } 

  function getCurrentDay() {
    return new Date().getDate();
  }

  function calendarDrawTable() {

    var dayOfMonth = 1;
    var validDay = 0;
    var startDayOfWeek = getDayOfWeek(currentYear, currentMonth, dayOfMonth);
    var daysInMonth = getDaysInMonth(currentYear, currentMonth);
    var css_class = null; //CSS class for each day

    var table = "<table cellspacing='0' cellpadding='0' border='0'>";
    table = table + "<tr class='header'>";
    table = table + "  <td colspan='2' class='previous'><a href='javascript:changeCalendarControlMonth(-1);'>&lt;</a> <a href='javascript:changeCalendarControlYear(-1);'>&laquo;</a></td>";
    table = table + "  <td colspan='3' class='title'>" + months[currentMonth-1] + "<br>" + currentYear + "</td>";
    table = table + "  <td colspan='2' class='next'><a href='javascript:changeCalendarControlYear(1);'>&raquo;</a> <a href='javascript:changeCalendarControlMonth(1);'>&gt;</a></td>";
    table = table + "</tr>";
    table = table + "<tr><th>S</th><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th></tr>";

    for(var week=0; week < 6; week++) {
      table = table + "<tr>";
      for(var dayOfWeek=0; dayOfWeek < 7; dayOfWeek++) {
        if(week == 0 && startDayOfWeek == dayOfWeek) {
          validDay = 1;
        } else if (validDay == 1 && dayOfMonth > daysInMonth) {
          validDay = 0;
        }

        if(validDay) {
          if (dayOfMonth == selectedDay && currentYear == selectedYear && currentMonth == selectedMonth) {
            css_class = 'current';
          } else if (dayOfWeek == 0 || dayOfWeek == 6) {
            css_class = 'weekend';
          } else {
            css_class = 'weekday';
          }

          table = table + "<td><a class='"+css_class+"' href=\"javascript:setCalendarControlDate("+currentYear+","+currentMonth+","+dayOfMonth+")\">"+dayOfMonth+"</a></td>";
          dayOfMonth++;
        } else {
          table = table + "<td class='empty'>&nbsp;</td>";
        }
      }
      table = table + "</tr>";
    }

    table = table + "<tr class='header'><th colspan='7' style='padding: 3px;'><a href='javascript:hideCalendarControl();'>Close</a></td></tr>";
    table = table + "</table>";

    return table;
  }

  this.show = show;
  function show(field) {
    can_hide = 0;
  
    // If the calendar is visible and associated with
    // this field do not do anything.
    if (dateField == field) {
      return;
    } else {
      dateField = field;
    }

    if(dateField) {
      try {
        var dateString = new String(dateField.value);
        var dateParts = dateString.split("-");
        
        selectedMonth = parseInt(dateParts[0],10);
        selectedDay = parseInt(dateParts[1],10);
        selectedYear = parseInt(dateParts[2],10);
      } catch(e) {}
    }

    if (!(selectedYear && selectedMonth && selectedDay)) {
      selectedMonth = getCurrentMonth();
      selectedDay = getCurrentDay();
      selectedYear = getCurrentYear();
    }

    currentMonth = selectedMonth;
    currentDay = selectedDay;
    currentYear = selectedYear;

    if(document.getElementById){

      calendar = document.getElementById(calendarId);
      calendar.innerHTML = calendarDrawTable(currentYear, currentMonth);

      setProperty('display', 'block');

      var fieldPos = new positionInfo(dateField);
      var calendarPos = new positionInfo(calendarId);

      var x = fieldPos.getElementLeft();
      var y = fieldPos.getElementBottom();

      setProperty('left', x + "px");
      setProperty('top', y + "px");
 
      if (document.all) {
        setElementProperty('display', 'block', 'CalendarControlIFrame');
        setElementProperty('left', x + "px", 'CalendarControlIFrame');
        setElementProperty('top', y + "px", 'CalendarControlIFrame');
        setElementProperty('width', calendarPos.getElementWidth() + "px", 'CalendarControlIFrame');
        setElementProperty('height', calendarPos.getElementHeight() + "px", 'CalendarControlIFrame');
      }
    }
  }

  this.hide = hide;
  function hide() {
    if(dateField) {
      setProperty('display', 'none');
      setElementProperty('display', 'none', 'CalendarControlIFrame');
      dateField = null;
    }
  }

  this.visible = visible;
  function visible() {
    return dateField
  }

  this.can_hide = can_hide;
  var can_hide = 0;
}

var calendarControl = new CalendarControl();

function showCalendarControl(textField) {
  // textField.onblur = hideCalendarControl;
  calendarControl.show(textField);
}

function clearCalendarControl() {
  calendarControl.clearDate();
}

function hideCalendarControl() {
  if (calendarControl.visible()) {
    calendarControl.hide();
  }
}

function setCalendarControlDate(year, month, day) {
  calendarControl.setDate(year, month, day);
}

function changeCalendarControlYear(change) {
  calendarControl.changeYear(change);
}

function changeCalendarControlMonth(change) {
  calendarControl.changeMonth(change);
}
document.write("<iframe id='CalendarControlIFrame' src='javascript:false;' frameBorder='0' scrolling='no'></iframe>");
document.write("<div id='CalendarControl'></div>");

function getDateToday(date_field) {
	today = new Date();
	date_str = new String();
	date_str = (today.getMonth() + 1) < 10 ? "0" + String(today.getMonth() + 1) : String(today.getMonth() + 1);
	date_str = today.getDate() < 10 ? date_str + "\/0" + String(today.getDate()) : date_str + "\/" + String(today.getDate());
	date_str = date_str + "\/" + String(today.getFullYear());
	document.getElementById(date_field).value = date_str;
	if (document.getElementById("date_text")) {
		document.getElementById("date_text").innerHTML = date_str + "<img id=\"edit\" class=\"btn\" src=\"\/atf\/cf\/{8712CBAB-0EA9-444F-9B5D-35B87FB672ED}\/Edit.gif\" width=\"26\" height=\"14\" border=\"0\" alt=\"Edit\" onMouseOver=\"swapImg('edit', '\/atf\/cf\/{8712CBAB-0EA9-444F-9B5D-35B87FB672ED}\/EditHover.gif');\" onMouseOut=\"swapImg('edit', '\/atf\/cf\/{8712CBAB-0EA9-444F-9B5D-35B87FB672ED}\/Edit.gif');\" onClick=\"editDate('shipDate')\"\/>";
	}
}
function editDate() {
	document.getElementById("date_text").className = "noDisplay";
	document.getElementById("date_field").className = "inline";
}

/* processing */
var cycle_timer;
var cycle_state = 0;
var cycle_end = 6;
var update_interval = 70;

function displayProcessing() {
	document.getElementById("processing").style.display = "inline";
	startProcessing();
}
	
function startProcessing() {
	cycle_state++;
	if (cycle_state > cycle_end) {
		cycle_state = 0;
	}
	else {
		document.getElementById("processing_img").src = "\/atf\/cf\/{8712CBAB-0EA9-444F-9B5D-35B87FB672ED}\/Processing" + cycle_state + ".gif";
	}
	cycle_timer = setTimeout("startProcessing()", update_interval);
}

function stopProcessing() {
	clearTimeout(cycle_timer);
	document.getElementById("processing").style.display = "none";
}