<!--

function displayDefaultTabContent() {
	if (window.location.hash) {
		// Anchor was passed
		var thisHash = URLDecode((window.location.hash.substring(1)).toLowerCase()); // Strip pound symbol and lowercase, then decode
		if (!isNaN(thisHash)) { // Check an integer was passed
			thisHash = parseInt(thisHash); // Convert to integer type
			if ((thisHash > 0) && (thisHash <= tabCount)) { // Check it is within tab range
				// Hash ok
				displayTabContent(thisHash);
				return true;
			}
		}
	}
	
	// Bad or missing hash - show default tab
	displayTabContent(1);
}

function displayTabContent(id) {
	for (var x=1; x<=tabCount; x++) { // Hide all other tab contents
		if (x!=id) {
			getObject('div_tab'+x+'_content').style.display = 'none';
			imgUnHilite('img_navTab'+x);
		}	
	}
	
	// Ensure select tab content is visible
	imgHilite('img_navTab'+id);
	getObject('div_tab'+id+'_content').style.display = 'block';
}

function isNumeric(x) {
	var myRegExp = /^[-+]?[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)?$/; 
	var result = x.match(myRegExp);

	if (result==null) result=false;

	return result;
}

function imgHilite(imgName) {
	if (document.images[imgName]) {
		document.images[imgName].src = document.images[imgName].src.replace(/_off\.gif$/,'_on.gif');
	}
}

function imgUnHilite(imgName) {
	if (document.images[imgName]) {
		document.images[imgName].src = document.images[imgName].src.replace(/_on\.gif$/,'_off.gif');
	}
}

function customDateString(oneDate) {
	var theDay = dayNames[oneDate.getDay() + 1];
	var theMonth = monthNames[oneDate.getMonth() + 1];
	var theYear = oneDate.getFullYear();
	return theDay.substring(0,3).toUpperCase() + "  |  " + theMonth.toUpperCase() + " " + oneDate.getDate() + ", " + theYear;
}

function DropdownChooser(Product) {
	if (Product != "") {
		window.location = Product;
	}
}

function reselectDropdown(frm,drop,val) {
	if (val != '') {
		var root = document.forms[frm].elements[drop];

		for (var t=0; t<root.length; t++) {
			if (root[t].value == val) {
				root.selectedIndex = t;
			}
		}
	}
}

function openWindow(URL,Name,W,H,L,T,Scrolls,Resize) {
	// Used to control params of pop-ups
	var defProps = 'copyhistory=0,directories=0,fullscreen=0,location=1,menubar=0,status=1,titlebar=1,toolbar=0';
	var poppedProps = '';

	if (W != null) {
		if (Scrolls == true) { W += 16; } // Allow for chrome in IE
		poppedProps += ('width='+W+',');
	}
	if (H != null) { poppedProps += ('height='+H+','); }
	if (L != null) { poppedProps += ('left='+L+','); }
	if (T != null) { poppedProps += ('top='+T+','); }
	poppedProps += 'scrollbars=' + ((Scrolls == true) ? 1 : 0) + ',' ;
	poppedProps += 'resizable=' + ((Resize == true) ? 1 : 0) + ',' ;
	poppedProps += defProps;

//	alert(poppedProps);
	poppedUp = window.open(URL,Name,poppedProps);
	setTimeout("poppedUp.window.focus();",100);
	return poppedUp;
}

function getObject(myid) {
	if ((HM_IE) || (HM_DOM)) {
		// Explorer
		if (HM_IE){
			return (document.all[myid]);
		}
		// DOM Browsers
		else if (HM_DOM) {
			return (document.getElementById(myid));
		}
	}
	else {
		return (false);
	}
}

function makeArray(n) {
//*** BUG: If I put this line in, I get two error messages:
//(1) Window.length can't be set by assignment
//(2) daysInMonth has no property indexed by 4
//If I leave it out, the code works fine.
//   this.length = n;
   for (var i = 1; i <= n; i++) {
      this[i] = 0
   } 
   return this
}

function showItem(myid,mydisplay) {
	if (mydisplay == "none") {
		getObject(myid).style.display = 'none';
		getObject(myid).style.visibility = 'hidden';
		if (SI) { SI.ClearChildren.clear(); } // Reset height
	}
	else if (mydisplay == "block") {
		getObject(myid).style.display = 'block';
		getObject(myid).style.visibility = 'visible';
		if (SI) { SI.ClearChildren.clear(); } // Reset height
	}
}

function toggleItem(myid, blnFade) {
	if (getObject(myid)) {
		var itemState = getObject(myid).style.display;
		if (itemState != 'none') {
			if (blnFade == 1) {
				fadeObj(myid,-1);
			}
			else {
				showItem(myid,'none');		
			}
			return (0);
		}
		else {
			if (blnFade == 1) {
				fadeObj(myid,1);
			}
			else {
				showItem(myid,'block');
			}
			return (1);
		}
	}
}

function toggleTextBoxVal(obj,ev,defVal) {
	if (obj) {
		if (ev == 'focus') {
			if (obj.value == defVal) {
				obj.value = '';
			}
		}
		else if (ev == 'blur') {
			if (obj.value == '') {
				obj.value = defVal;
			}
		}
	}
}

function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99:opacity; // Fixes re-draw bug when opacity = 1
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	if (obj.filters) {obj.filters.alpha.opacity=opacity;}
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
	return opacity;
}

function fadeObj(obj,dir,lim) {
	if (dir == 1) {
		// Fade In
		if (!lim) {
			 // Full fade in
			lim = 100;

			// Set to 0 opacity hidden
			fOp[obj] = setOpacity(getObject(obj),0);
		}
		else {
			fOp[obj] = setOpacity(getObject(obj),lim);
		}

		getObject(obj).style.visibility = 'visible';
		getObject(obj).style.display = 'block';

		// Fade it
		fClr[obj] = setInterval(function() { fadeLoop(obj,10,lim); },25); // always use anonymous fn for intervals
	}
	else if (dir == -1) {
		// Fade Out
		if (!lim) {
			// Full fade out
			lim = 0;
			
			// Set to 100% opacity visible
			fOp[obj] = setOpacity(getObject(obj),100);
		}
		else {
			fOp[obj] = setOpacity(getObject(obj),lim);
		}
			
		getObject(obj).style.visibility = 'visible';
		getObject(obj).style.display = 'block';
		
		// Fade it
		fClr[obj] = setInterval(function() { fadeLoop(obj,-10,lim); },25); // always use anonymous fn for intervals
	}
}

function fadeLoop(obj,inc,lim) {
	if (inc > 0) {
		// Fade In
		if (fOp[obj] >= lim) {
			// Clean up and stop cycle
			clearInterval(fClr[obj]);
			if (SI) { SI.ClearChildren.clear(); }
		}
		else {
			fOp[obj] = setOpacity(getObject(obj),(fOp[obj]+inc));	
		}
	}
	else if (inc < 0) {
		// Fade Out
		if (fOp[obj] <= lim) {
			// Clean up and stop cycle
			if (lim == 0) { showItem(obj,'none'); } // Used to remove object from flow
			clearInterval(fClr[obj]);
			if (SI) { SI.ClearChildren.clear(); }
		}
		else {
			fOp[obj] = setOpacity(getObject(obj),(fOp[obj]+inc));
		}
	}
	else {
		// Catch all
		clearInterval(fClr[obj]);	
		if (SI) { SI.ClearChildren.clear(); }
	}
}

function matchColHeights() {
	var mHeight = 300; // Minimum height
	var elemTallest;
	
	// Set array of column IDs to check in order of loading
	var aCols = new Array();
	aCols[1] = 'div_col1';
	aCols[2] = 'div_col2';
	aCols[3] = 'div_col3';
	
	// Get tallest column
	for(var i=aCols.length; i>0; i--) {
		if (getObject(aCols[i])) {
			elem = getObject(aCols[i]);
			// Last column has loaded - proceed
			if (elem.offsetHeight > mHeight) { mHeight = elem.offsetHeight; elemTallest = elem; }
			elem.style.height = 'auto';
		}
	}
	
	if (mHeight > 0) {
		// Set all columns to tallest height
		for(i=aCols.length; i>0; i--) {
			if (getObject(aCols[i])) {
				elem = getObject(aCols[i]);
				elem.style.height = mHeight+'px';
			}
		}
		
		// Need to refresh footer position
		if (getObject('div_footerCell')) {
			getObject('div_footerCell').className = 'footerCell'; // IE fix
		}
	}

	// Match box heights
	matchBoxHeights(elemTallest);
	
	// Update bleed height for background color
	setPageBleed();

}

function getStyleProp(x,prop){
	if(x.currentStyle)
		return(x.currentStyle[prop]);
	if(document.defaultView.getComputedStyle)
		return(document.defaultView.getComputedStyle(x,'')[prop]);
	return(null);
}

function setPageBleed() {
	var anchorHeight = getObject('div_anchor').offsetHeight; // Total height of content
	var footerCellMinHeight = parseInt(getStyleProp(getObject('div_footerCell'),'minHeight')); // Minimal allowed height
	var footerCellTop = getObject('div_footerCell').offsetTop; // Footer position
	var footerCellHeight = getObject('div_footerCell').offsetHeight; // Footer current height
	var footerCellNewHeight = anchorHeight-footerCellTop; // Height to max window
	if (footerCellNewHeight < footerCellMinHeight) { footerCellNewHeight = footerCellMinHeight; } // Set to default height

	if (footerCellHeight != footerCellNewHeight) {
		getObject('div_footerCell').style.height = footerCellNewHeight + 'px'; // Update height			
	}	
}

function matchBoxHeights(elemTallest) {
	if (blnHomepage) { // Homepage only
		// Get available height
		var elemPadding = getObject(elemTallest.id+'_padding');
		var availHeight = (parseInt(elemPadding.offsetHeight) - (parseInt(getStyleProp(elemPadding,'paddingTop')) + parseInt(getStyleProp(elemPadding,'paddingBottom'))));

		// Set box heights
		getObject('tanBox_HP').style.height = availHeight + 'px';
		getObject('blueBox_HP').style.height = availHeight + 'px';	
	}
}

function showTabContent(TabID,TabLimit,TabSet) {
	for (u=1; u<=TabLimit; u++) {
		showItem('TabBox_'+TabSet+'_Content' + u,"none");
		eval(getObject('TabBox_'+TabSet+'_Tab' + u)).className = "TabBox_Tab";
	}
	showItem('TabBox_'+TabSet+'_Content' + TabID,"block");
	eval(getObject('TabBox_'+TabSet+'_Tab' + TabID)).className = "TabBox_TabOn";
}

function navToFadeOut() {
	if (getObject('div_navToHide')) {
		setOpacity(getObject('div_navToHide'),50);
	}
}

function navToFadeIn() {
	if (getObject('div_navToHide')) {
		setOpacity(getObject('div_navToHide'),100);
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


/* Validations */
// Based on original PHP code by Cal Henderson (http://iamcal.com/publish/articles/php/parsing_email)
// Converted to JS regex
function is_valid_email_address(email) {
	var qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
	var dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
	var atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'+'\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
	var quoted_pair = '\\x5c\\x00-\\x7f';
	var domain_literal = '\\x5b('+dtext+'|'+quoted_pair+')*\\x5d';
	var quoted_string = '\\x22('+qtext+'|'+quoted_pair+')*\\x22';
	var domain_ref = atom;
	var sub_domain = '('+domain_ref+'|'+domain_literal+')';
	var word = '('+atom+'|'+quoted_string+')';
	var domain = sub_domain+'(\\x2e'+sub_domain+')*';
	var local_part = word+'(\\x2e'+word+')*';
	var addr_spec = local_part+'\\x40'+domain;
	var filter = eval('/^' + addr_spec + '$/');
	
	return ((filter.test(email)) ? 1 : 0);
}

// ====================================================================
//       URLEncode and URLDecode functions
//
// Copyright Albion Research Ltd. 2002
// http://www.albionresearch.com/
//
// You may copy these functions providing that 
// (a) you leave this copyright notice intact, and 
// (b) if you use these functions on a publicly accessible
//     web site you include a credit somewhere on the web site 
//     with a link back to http://www.albionresarch.com/
//
// If you find or fix any bugs, please let us know at albionresearch.com
//
// SpecialThanks to Neelesh Thakur for being the first to
// report a bug in URLDecode() - now fixed 2003-02-19.
// ====================================================================
function URLEncode(plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return (encoded == '') ? false : encoded;
};

function URLDecode(encoded)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while

	return (plaintext == '') ? false : plaintext;
};


//-->
