
f_getElement = document.all ?
	function (s_id) { return document.all[s_id] } :
	function (s_id) { return document.getElementById(s_id) };

// dropdown menu script
function f_initMenu() {

	// determine active root category in drop down menu
	var e_menu = f_getElement('dropdownmenu');
	if (!e_menu) return;
	var a_links = e_menu.getElementsByTagName('A');
	var e_navLink, e_currentElement;

	var submenu;
	var anchor;
	var oldAnchor;
	var showInterval;
	var hideInterval;
	var inDropDown;
	
	var ddm = f_getElement('dropdownmenu');
	ddm.onmouseover = function() {
		inDropDown = true;
		clearInterval(hideInterval);
	}
	ddm.onmouseout = function() {
		inDropDown = false;
		anchor = null;
		hideInterval = setTimeout(function(){f_hideSubmenu();},250);
	}
	var items = document.getElementsByName('toplevelmenuitem');
	
	var len = items.length;
	for (var i = 0; i < len; i++) {
		items[i].onmouseover = function() {
			anchor = this;
			var tmpAnchor = anchor;
//			this.style.backgroundColor = "#ffffff";
			if (submenu != undefined) {
				f_hideSubmenu();
			}
			if (hasActiveCategory() && (this != f_getElement("activeCategory"))) {
//				document.getElementById('activeCategory').style.backgroundColor = '#cccccc';
			}
			var childlen = this.parentNode.childNodes;

			for (var k = 0; k < childlen.length; k++) {
				if (childlen[k].nodeName != "TABLE")
					continue;

				submenu = childlen[k];
				submenu.onmouseover = function() {
					
					inDropDown = true;
					anchor = tmpAnchor;
					clearInterval(hideInterval);
//						anchor.style.backgroundColor = "#ffffff";
					if (hasActiveCategory()) {
						if(anchor != f_getElement("activeCategory")) {
//								document.getElementById('activeCategory').style.backgroundColor = '#cccccc';
						}
					}
				}
				submenu.onmouseout = function() {
					if (window.event && window.event.fromElement && window.event.fromElement.tagName != 'TABLE')
						return;
					
					inDropDown = false;
					hideInterval = setTimeout(function(){f_hideSubmenu();}, 250);
//						anchor.style.backgroundColor = "#cccccc";
					if (hasActiveCategory()) {
//							document.getElementById('activeCategory').style.backgroundColor = "#ffffff";
					}
				}
				showInterval = setTimeout(function(){f_showSubmenu(submenu, anchor);}, 250);
			}
		}
		items[i].onmouseout = function() {
			oldAnchor = this;
//			this.style.backgroundColor = "#cccccc";
			if (hasActiveCategory()) {
//				document.getElementById('activeCategory').style.backgroundColor = '#ffffff';
			}
			clearInterval(showInterval);
			hideInterval = setTimeout(function(){f_hideSubmenu();},250);
		}
	}
	
	function f_showSubmenu(node, e_rootItem) {
		
		var e_root = f_getElement('rootLevel');
		if (!e_root) return;

		var n_left = f_getPosition(e_root, 'Left');
		var n_top  = f_getPosition(e_root, 'Top');

		var s_location = String(window.location).toLowerCase().replace(/\#.*$/, '');


		if (b_ie7 && (s_location.indexOf('screen=') != -1)) {
			n_left += 1;
			n_top  += 1;
		}

		var n_offset = 0;
		if (node.className == 'submenuright') {
			n_offset = e_root.offsetWidth - node.offsetWidth + 4;
			node.style.left = (n_left + n_offset) + 'px'
		}
		else if (node.className == 'submenucenter') {
//			n_offset = (e_root.offsetWidth - node.offsetWidth) / 2 - 25;
		}
		else {
			n_offset = -18;
			node.style.left = (n_left + n_offset) + 'px'
		}
		
		node.style.top  = (n_top  + e_root.offsetHeight + 12) + 'px';
		node.style.visibility = 'visible';
		if (document.all) {
			var sf = f_getElement("selectfix");
			sf.style.display = "block";
			sf.width = node.offsetWidth;
			sf.height = node.offsetHeight;
			sf.style.top = node.offsetTop;
			sf.style.left = node.offsetLeft;
		}
		var e_shade = f_getElement('menuShade');
		if (e_shade) {
			f_customShade2(e_shade, node.offsetWidth - 1, node.offsetHeight - 1, node.offsetLeft, node.offsetTop + 1);
			e_shade.style.visibility = 'visible';
		}
		
		var e_arrow = f_getElement('menu-arrow');
		if (e_arrow) {
			e_arrow.style.top = (node.offsetTop - 26) + 'px';
			var n_itemLeft = f_getPosition(e_rootItem.parentNode, 'Left');
			e_arrow.style.left = (n_itemLeft + e_rootItem.parentNode.offsetWidth / 2 - 15) + 'px';
			e_arrow.style.visibility = 'visible';
		}
		
	}
	function f_hideSubmenu() {
		if(anchor == oldAnchor) return;
		if(inDropDown) return;
		f_getElement("selectfix").style.display = "none";
		
		var e_shade = f_getElement('menuShade');
		if (e_shade)
			e_shade.style.visibility = 'hidden';

		var e_arrow = f_getElement('menu-arrow');
		if (e_arrow)
			e_arrow.style.visibility = 'hidden';

		if(submenu)
			submenu.style.visibility = 'hidden';
	}
	function hasActiveCategory() {
		return (f_getElement("activeCategory") != undefined);
	}
}

// Title: Tigra Hints
// Version: 2.1 (custom)
function THints (a_items, a_cfg) {

	if (!a_items) a_items = [];
	if (!a_cfg) a_cfg = [];
	this.a_cfg = a_cfg;

	this.a_elements = [];
	this.a_hints = [];

	this.show  = f_hintShow;
	this.showD = f_hintShowNow;
	this.hide  = f_hintHide;
	this.hideD = f_hintHideNow;

	// register the object in global collection
	this.n_id = A_HINTS.length;
	A_HINTS[this.n_id] = this;
	
	if (!b_ie5 && !b_ie6)
		a_cfg.IEfix = false;

/*
	// generate HTML
	for (var s_id in a_items) {
		s_id = String(s_id).replace(/\W/g,'');
		document.write(
			'<div style="position:absolute;left:0;top:0;visibility:hidden;z-index:',
			((a_cfg['z-index'] == null ? 2 : a_cfg['z-index']) + (a_cfg.IEfix ? 1 : 0)), ';',
			(a_cfg.IEtrans ? 'filter:' + a_cfg.IEtrans.join(' ') : '') ,
			(a_cfg.opacity ? ' alpha(opacity=' + a_cfg.opacity + '); -moz-opacity:' + (a_cfg.opacity / 100) + ';opacity:' + (a_cfg.opacity / 100) + '' : ''), '" id="h', this.n_id, '_', s_id,
			'" class="', (this.a_cfg.css ? this.a_cfg.css : 'tigraHint'),
			'" onmouseover="A_HINTS[', this.n_id + '].show(\'', s_id, '\')" onmouseout="A_HINTS[',
			this.n_id, '].hide(\'', s_id, '\')" onmousemove="f_onMouseMove(event)">',
			a_items[s_id], '</div>'
		);
		if (a_cfg.IEfix) document.write(
			'<iframe style="position:absolute;left:0;top:0;visibility:hidden;z-index:',
			(a_cfg['z-index'] == null ? 2 : a_cfg['z-index']), ';filter:alpha(opacity=0);" id="h',
			this.n_id, '_', s_id, '_if" frameborder="0" scrolling="No"></iframe>'
		);
	}*/
	// assign mouseover event	
	if (document.addEventListener) {
		document.addEventListener('mousemove', f_onMouseMove, false);
		window.addEventListener('scroll', f_onwindowChange, false);
		window.addEventListener('resize', f_onwindowChange, false);
	}
	if (window.attachEvent) {
		document.attachEvent('onmousemove', f_onMouseMove);
		window.attachEvent('onscroll', f_onwindowChange);
		window.attachEvent('onresize', f_onwindowChange);
	}
	else {
		document.onmousemove = f_onMouseMove;
		window.onscroll = f_onwindowChange;
		window.onresize = f_onwindowChange;
	}
}
var n_flag = false;

function f_hintShow(s_id, e_element) {

	// cancel previous delay
	if (this.e_timer) {
		clearTimeout(this.e_timer);
		this.e_timer = null;
	}

	var s_id = String(s_id).replace(/\W/g,'');
	if (!this.a_hints[s_id])
		this.a_hints[s_id] = f_getElement('h' + this.n_id + '_' + s_id);
	if (!this.a_hints[s_id])
		this.a_hints[s_id] = f_getElement(s_id);
	if (!this.a_hints[s_id])
		throw new Error('001', 'Can not find the hint with ID=' + s_id);

	this.a_elements[s_id] = e_element;

	var n_showDelay = this.a_cfg.show_delay == null ? 200 : this.a_cfg.show_delay;
	if (!n_showDelay)
		return this.showD(s_id, e_element);

	this.e_timer = setTimeout('A_HINTS[' + this.n_id + '].showD("' + s_id + '")', n_showDelay);
}

function f_hintShowNow(s_id, e_element) {
	if (s_id == this.o_lastHintID)
		return;

	if (e_element)
		this.a_elements[s_id] = e_element;
	if (this.o_lastHintID != null)
		this.hideD(this.o_lastHintID);

	this.o_lastIframe = f_getElement('h' + this.n_id + '_' + s_id + '_if');
	if (this.o_lastIframe)
		this.o_lastIframe.style.visibility = 'visible';

	// Transition in IE
	f_hintPosition(this.a_elements[s_id], this.a_hints[s_id], this.a_cfg);
	if (this.a_cfg.IEtrans && this.a_cfg.IEtrans[0]) {
		try {
			var e_currTrans = this.a_hints[s_id].filters.item(0);
			e_currTrans.apply();
			this.a_hints[s_id].style.visibility = 'visible';
			e_currTrans.play();
		} catch(e) {
			this.a_hints[s_id].style.visibility = 'visible';
		};
	}
	else
		this.a_hints[s_id].style.visibility = 'visible';

	this.o_lastHintID = s_id;
}

function f_hintHide(s_id) {

	if (this.e_timer) {
		clearTimeout(this.e_timer);
		this.e_timer = null;
	}

	if (s_id != null)
		s_id = String(s_id).replace(/\W/g,'');
	else if (this.o_lastHintID)
		s_id = this.o_lastHintID;
	else
		return;
	
	if (!this.a_hints[s_id])
		throw new Error('001', 'Can not find the hint with ID=' + s_id);

	var n_hideDelay = this.a_cfg.hide_delay == null ? 200 : this.a_cfg.hide_delay;
	if (!n_hideDelay)
		return this.hideD(s_id);

	this.e_timer = setTimeout('A_HINTS[' + this.n_id + '].hideD("' + s_id + '")', n_hideDelay);
}

function f_hintHideNow(s_id) {
	// Transition in IE
	if (this.a_cfg.IEtrans && this.a_cfg.IEtrans[1]) {
		try {
			var e_currTrans = this.a_hints[s_id].filters.item(this.a_cfg.IEtrans[0] ? 1 : 0);
			e_currTrans.apply();
			this.a_hints[s_id].style.visibility = 'hidden';
			e_currTrans.play();
		} catch(e) {
			this.a_hints[s_id].style.visibility = 'hidden';
		};
	}
	else
		this.a_hints[s_id].style.visibility = 'hidden';

	this.o_lastHintID = null;
	if (this.o_lastIframe) {
		this.o_lastIframe.style.visibility = 'hidden';
		this.o_lastIframe = null;
	}
}


function f_hintPosition (e_element, e_hint, a_params) {
	// validate params
	if (!e_hint) throw new Error('001', 'hint object reference is missing in parameters');
	if (!a_params) a_params = [];
	
	var a_ = {
		n_elementWidth: e_element ? e_element.offsetWidth : 0,
		n_elementHeight: e_element ? e_element.offsetHeight : 0,
		n_elementLeft: e_element ? f_getPosition(e_element, 'Left') : n_mouseX,
		n_elementTop: e_element ? f_getPosition(e_element, 'Top') : n_mouseY,
		n_hintWidth: e_hint.offsetWidth,
		n_hintHeight: e_hint.offsetHeight,
		n_hintLeft: 0,
		n_hintTop : 0,
		n_clientWidth: f_clientWidth(),
		n_clientHeight: f_clientHeight(),
		n_scrollTop: f_scrollTop(),
		n_scrollLeft: f_scrollLeft(),
		s_align: a_params.align ? a_params.align : 'tlbl',
		n_gap: a_params.gap == null ? 5 : a_params.gap,
		n_margin: a_params.margin == null ? 10 : a_params.margin
	};

	f_applyAlign(a_);
	if (a_.n_hintLeft == 0)
		a_.n_hintLeft = -10000;
	// smart positioning is on by default
	else if (a_params.smart || a_params.smart == null)
		f_checkFit(a_);

	e_hint.style.left = a_.n_hintLeft + 'px';
	e_hint.style.top = a_.n_hintTop + 'px';

	// synchronize iframe if exists	
	var e_iframe = f_getElement(e_hint.id + '_if');
	if (e_iframe) {
		e_iframe.style.left = a_.n_hintLeft + 'px';
		e_iframe.style.top = a_.n_hintTop + 'px';
		e_iframe.style.width = a_.n_hintWidth + 'px';
		e_iframe.style.height = a_.n_hintHeight + 'px';
	}
}

/* corrects hints positioning to maximize the visibility */			
function f_checkFit (a_) {

	// check if correction is required
	if (a_.n_spaceT >= 0 && a_.n_spaceR >= 0 && a_.n_spaceB >= 0 && a_.n_spaceL >= 0)
		return;

	// determine if hint clears element for horisontal shifting
	var b_horShift =
		(a_.n_hintTop + a_.n_hintHeight + a_.n_gap <= a_.n_elementTop) ||
		(a_.n_elementTop + a_.n_elementHeight + a_.n_gap <= a_.n_hintTop);
	
	// resolve by horizontal shifting
	if (b_horShift) {
		if (a_.n_spaceL < 0 || (a_.n_spaceL + a_.n_spaceR < 0))
			a_.n_hintLeft = a_.n_scrollLeft + a_.n_margin;
		else if (a_.n_spaceR < 0)
			a_.n_hintLeft = a_.n_scrollLeft + a_.n_clientWidth - a_.n_margin - a_.n_hintWidth;
	}
	// determine if hint clears element for vertical shifting
	var b_verShift =
		(a_.n_hintLeft + a_.n_hintWidth + a_.n_gap <= a_.n_elementLeft) ||
		(a_.n_elementLeft + a_.n_elementWidth + a_.n_gap <= a_.n_hintLeft);

	// resolve by vertical shifting
	if (b_verShift) {
		if (a_.n_spaceT < 0 || (a_.n_spaceT + a_.n_spaceB < 0))
			a_.n_hintTop = a_.n_scrollTop + a_.n_margin;
		else if (a_.n_spaceB < 0)
			a_.n_hintTop = a_.n_scrollTop + a_.n_clientHeight - a_.n_margin - a_.n_hintHeight;
	}

	// resolve horisontal collision by mirroring
	if (!b_horShift && (a_.n_spaceL < 0 || a_.n_spaceR < 0)) {
		// save current overlap
		var n_overlap  = a_.n_spaceL + a_.n_spaceR,
			n_hintLeft = a_.n_hintLeft,
			n_hintTop  = a_.n_hintTop;

		// mirror the align
		a_.s_align = a_.s_align.replace('r', '-');
		a_.s_align = a_.s_align.replace('l', 'r');
		a_.s_align = a_.s_align.replace('-', 'l');
		f_applyAlign(a_);

		// restore old coordinate if mirrored hint is less visible
		if (Math.min(a_.n_spaceL, a_.n_spaceR) < n_overlap)
			a_.n_hintLeft = n_hintLeft;
		a_.n_hintTop = n_hintTop;
	}
	// resolve vertical collision by mirroring
	if (!b_verShift && (a_.n_spaceT < 0 || a_.n_spaceB < 0)) {
		var n_overlap  = Math.min(a_.n_spaceT, a_.n_spaceB),
			n_hintLeft = a_.n_hintLeft,
			n_hintTop  = a_.n_hintTop;

		// mirror the align
		a_.s_align = a_.s_align.replace('t', '-');
		a_.s_align = a_.s_align.replace('b', 't');
		a_.s_align = a_.s_align.replace('-', 'b');
		f_applyAlign(a_);

		// restore old coordinate if mirrored hint is less visible
		if (Math.min(a_.n_spaceT, a_.n_spaceB) < n_overlap)
			a_.n_hintTop = n_hintTop;
		a_.n_hintLeft = n_hintLeft;
	}
}

/* decodes the align parameter and calculates the coordinates of the hint */
function f_applyAlign (a_) {

	if (!re_align.exec(a_.s_align))
		throw new Error('001', 'Invalid format of align parameter: ' + a_.s_align);
	
	// decode alignment
	var n_align = RegExp.$1,
		n_top = a_.n_elementTop;

	// element vertical align
	if (n_align == 'm')
		n_top += Math.round(a_.n_elementHeight / 2);
	else if (n_align == 'b')
		n_top += a_.n_elementHeight + a_.n_gap;
	else
		n_top -= a_.n_gap;

	// hint vertical align
	n_align = RegExp.$3;
	if (n_align == 'm')
		n_top -= Math.round(a_.n_hintHeight / 2);
	else if (n_align == 'b')
		n_top -= a_.n_hintHeight;
		
	// element horizontal align
	var n_left = a_.n_elementLeft;
	n_align = RegExp.$2;
	if (n_align == 'c')
		n_left += Math.round(a_.n_elementWidth / 2);
	else if (n_align == 'r')
		n_left += a_.n_elementWidth + a_.n_gap;
	else
		n_left -= a_.n_gap;

	// hint horisontal align
	n_align = RegExp.$4;
	if (n_align == 'c')
		n_left -= Math.round(a_.n_hintWidth / 2);
	else if (n_align == 'r')
		n_left -= a_.n_hintWidth;

	a_.n_spaceT = n_top - a_.n_scrollTop - a_.n_margin,
	a_.n_spaceB = a_.n_clientHeight + a_.n_scrollTop - a_.n_margin - n_top - a_.n_hintHeight,
	a_.n_spaceL = n_left - a_.n_scrollLeft - a_.n_margin,
	a_.n_spaceR = a_.n_clientWidth + a_.n_scrollLeft - a_.n_margin - n_left - a_.n_hintWidth;

	a_.n_hintLeft = n_left;
	a_.n_hintTop  = n_top;
}

function f_onMouseMove(e_event) {
	if (!e_event && window.event)
		e_event = window.event;
	if (!e_event)
		return true;
	n_mouseX = e_event.pageX ? e_event.pageX : e_event.clientX + f_scrollLeft();
	n_mouseY = e_event.pageY ? e_event.pageY + 2 : e_event.clientY + f_scrollTop();
	return f_onwindowChange();
}

function f_onwindowChange() {
	var o_hint;
	for (var i = 0; i < A_HINTS.length; i++) {
		o_hint = A_HINTS[i];
		if (o_hint.a_cfg.follow && o_hint.o_lastHintID)
			f_hintPosition(o_hint.a_elements[o_hint.o_lastHintID], o_hint.a_hints[o_hint.o_lastHintID], o_hint.a_cfg);
	}
	return true;
}

// global variables
var A_HINTS = [],
	n_mouseX = 0,
	n_mouseY = 0,
	re_align = /^([tmb])([lcr])([tmb])([lcr])$/;










// browser abstraction layer
function f_getPosition (e_elemRef, s_coord) {

	var n_pos = 0, n_offset,
		e_elem = e_elemRef;

	while (e_elem) {
		n_offset = e_elem["offset" + s_coord];
		n_pos += n_offset;
		e_elem = e_elem.offsetParent;
	}

	// margin correction in some browsers
	if (b_ieMac)
		n_pos += parseInt(document.body[s_coord.toLowerCase() + 'Margin']);
	else if (b_safari)
		n_pos -= n_offset;
	
	e_elem = e_elemRef;
	while (e_elem != document.body) {
		n_offset = e_elem["scroll" + s_coord];
		if (n_offset && e_elem.style.overflow == 'scroll')
			n_pos -= n_offset;
		e_elem = e_elem.parentNode;
	}
	return n_pos;
}

function f_clientWidth() {
	if (typeof(window.innerWidth) == 'number')
		return window.innerWidth;
	if (document.documentElement && document.documentElement.clientWidth)
		return document.documentElement.clientWidth;
	if (document.body && document.body.clientWidth)
		return document.body.clientWidth;
	return null;
}
function f_clientHeight() {
	if (typeof(window.innerHeight) == 'number')
		return window.innerHeight;
	if (document.documentElement && document.documentElement.clientHeight)
		return document.documentElement.clientHeight;
	if (document.body && document.body.clientHeight)
		return document.body.clientHeight;
	return null;
}
function f_scrollLeft() {
	if (typeof(window.pageXOffset) == 'number')
		return window.pageXOffset;
	if (document.body && document.body.scrollLeft)
		return document.body.scrollLeft;
	if (document.documentElement && document.documentElement.scrollLeft)
		return document.documentElement.scrollLeft;
	return 0;
}
function f_scrollTop() {
	if (typeof(window.pageYOffset) == 'number')
		return window.pageYOffset;
	if (document.body && document.body.scrollTop)
		return document.body.scrollTop;
	if (document.documentElement && document.documentElement.scrollTop)
		return document.documentElement.scrollTop;
	return 0;
}

function f_customShade (e_container, n_width, n_height, n_left, n_top) {
	if (!e_container) return;
	if (n_width != null) e_container.style.width = (n_width + 8) + 'px';
	if (n_left != null) e_container.style.left = (n_left - 1) + 'px';
	e_container.style.top = (n_top - 1) + 'px';
	e_container.innerHTML = '&nbsp;';
}

function f_customShade2 (e_container, n_width, n_height, n_left, n_top) {
	if (!e_container) return;
	e_container.style.left = (n_left - 7) + 'px';
	e_container.style.top = (n_top - 10) + 'px';
	e_container.style.width = (n_width + 16) + 'px';
	e_container.style.height = (n_height + 12) + 'px';
	e_container.innerHTML = '&nbsp;';
}

var s_userAgent = navigator.userAgent.toLowerCase();
var b_mac = s_userAgent.indexOf('mac') != -1,
	b_ie5    = s_userAgent.indexOf('msie 5') != -1,
	b_ie6    = s_userAgent.indexOf('msie 6') != -1 && s_userAgent.indexOf('opera') == -1,
	b_ie7    = s_userAgent.indexOf('msie 7') != -1,
	b_ie8    = s_userAgent.indexOf('msie 8') != -1,
	b_ieMac  = b_mac && b_ie5,
	b_safari = b_mac && s_userAgent.indexOf('safari') != -1;


// arrow for drop down menu
document.write(b_ie5 || b_ie6
	? '<img src="/images/pixel.gif" alt="" id="menu-arrow" width="32" height="18"  style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/menu-arrow.png\', sizingMethod=\'scale\');" />'
	: '<img src="/images/menu-arrow.png" alt="" id="menu-arrow" />'
);










// product selector wizard
var a_wizardSelects = ['category', 'finish', 'brand', 'isize', 'format', 'color', 'weight', 'boxcount'];
function f_updateWizard(b_reset, b_noTrack) {
	var e_select,
		a_elements = document.forms['pwizard'].elements
		e_reset = f_getElement('pw-reset');
	
	f_setWizardProduct();

	// reset everything
	if (b_reset) {
		e_reset.style.visibility = '';
		for (var i = 1; i < a_wizardSelects.length; i++) {
			e_select = a_elements[a_wizardSelects[i]];
			e_select.options.length = 0;
			e_select.options[0] = new Option('-', '');
			e_select.disabled = true;
		}
		if (!b_noTrack) {
			f_trackLink('HOME-PWIZ','Start');
			f_pauseSlideShow();
		}
	}
	// collect selections and send request
	if (a_elements['category'].selectedIndex != 0) {
		e_reset.style.visibility = 'visible';
		var s_url = 'http://www.lcipaper.com/php/product-wizard.php?' + f_wizardGetQuery();
		
		window.o_http = f_getHTTPObject();
		window.o_http.onreadystatechange = f_updateWizardHandler;
		window.o_http.open('GET', s_url, true);
		window.o_http.send(null);
	}
}

function f_wizardGetQuery() {
	var e_select, s_value, a_params = [], a_elements = document.forms['pwizard'].elements;
	for (var i = 0; i < a_wizardSelects.length; i++) {
		e_select = a_elements[a_wizardSelects[i]];
		s_value = e_select.options[e_select.selectedIndex].value;
		if (s_value == '')
			continue;
		a_params[a_params.length] = a_wizardSelects[i] + '=' + escape(s_value);
	}
	return a_params.join('&');
}

function f_updateWizardHandler() {
	if (!window.o_http)
		return;

	if (window.o_http.readyState != 4) return;
	if (window.o_http.status != 200 && o_http.status != 304)
		throw 'AJAX response error';

	var e_select, a_options, s_value, s_savedValue,
		a_elements = document.forms['pwizard'].elements,
		a_response = eval('(' + window.o_http.responseText + ')');

	if (a_response['m']) {
		alert(a_response['m']);
		return;
	}

	var a_selects = a_response['s'];
	for (var i = 0; i < a_selects.length; i++) {
		e_select = a_elements[a_selects[i]['n']];
		if (!e_select) continue;
		s_savedValue = e_select.options[e_select.selectedIndex].value;
		e_select.options.length = 0;
		a_options = a_selects[i]['o'];
		
		if (a_options.length == 1) {
			s_value = a_options[0]['v'];
			s_text = a_options[0]['t'] == null ? s_value : a_options[0]['t'];
			if (s_savedValue != '' && s_savedValue == s_value) {
				e_select.options[0] = new Option('- Show All -', '');
				e_select.options[1] = new Option('Selected: ' + s_text, s_value);
				e_select.selectedIndex = 1;
				e_select.disabled = false;
			}
			else {
				e_select.options[0] = new Option(s_text, '');
				e_select.disabled = true;
			}
		}
		else {
			e_select.options[0] = new Option('- Select -', '');
			for (var n = 0; n < a_options.length; n++) {
				s_value = a_options[n]['v'];
				s_text = a_options[n]['t'] == null ? s_value : a_options[n]['t'];
				e_select.options[e_select.options.length] = new Option(s_text + ' (' + a_options[n]['c'] + ')', s_value);
			}
			e_select.disabled = false;
		}
	}

	f_setWizardProduct(a_response);
}

function f_updatePreviewHandler () {
	var e_elemBoxes = f_getElement('home-boxes-liner'),
		e_elemPreview = f_getElement('prod-preview');

	if (!e_elemBoxes) return;

	if (!window.o_http)
		return;

	if (window.o_http.readyState != 4) return;
	if (window.o_http.status != 200 && o_http.status != 304)
		throw 'AJAX response error';

	e_elemPreview.innerHTML = window.o_http.responseText;
	e_elemBoxes.style.display = 'none';
	e_elemPreview.style.display = 'block';
	
	initLightbox();
}

function f_resetWizard(b_noTrack) {
	document.forms['pwizard'].elements['category'].selectedIndex = 0;
	f_updateWizard(true, b_noTrack);
}

function f_setWizardProduct (a_response) {
	
	var e_elemProd = f_getElement('pwizard-prod'),
		e_elemBoxes = f_getElement('home-boxes-liner'),
		e_elemPreview = f_getElement('prod-preview');

	if (a_response && a_response['p']) {
		var a_product = a_response['p'];
		e_elemProd.innerHTML = 'You found it!<br />Place your order<br />on the right <img src="/images/icon-right-arrow.png" class="pw-arrow" alt="" />';
		e_elemProd.style.display = 'block';
		f_trackLink('HOME-PWIZ','One Product');

		var s_url = 'http://www.lcipaper.com/catalog/specialty.paper?Screen=I-PROD&Product_Code=' + escape(a_product['c']);
		window.o_http = f_getHTTPObject();
		window.o_http.onreadystatechange = f_updatePreviewHandler;
		window.o_http.open('GET', s_url, true);
		window.o_http.send(null);
	}
	else {
		if (a_response && a_response['c']) {
			e_elemProd.innerHTML = a_response['c'] + ' matching products<br />[<a href="http://www.lcipaper.com/search.html?section=retail&' + f_wizardGetQuery() + '" onclick="f_trackLink(\'HOME-PWIZ\',\'Search\');">view all</a>]';
			e_elemProd.style.display = 'block';
		}
		else {
			e_elemProd.style.display = '';
			e_elemProd.innerHTML = '';
		}
		e_elemBoxes.style.display = '';
		e_elemPreview.style.display = '';
	}
}

function f_wizSelectKey (e_event) {
	if (!window.A_WIZSELECTS) return;
	if (!e_event && window.event)
		e_event = window.event;
	var o_select;
	for (n = 0; n < A_WIZSELECTS.length; n++) {
		o_select = A_WIZSELECTS[n];
		if (o_select.f_visible())
			o_select.f_handleKey(e_event);
	}
}

// product and category previews
function f_hidePreview () {
	if (window.o_previewTimer) {
		window.clearTimeout(window.o_previewTimer);
		window.o_previewTimer = null;
	}
	if (o_preview) o_preview.hide();
}
function f_showPreview (s_code, s_name, e_origin, s_type) {
	var e_elem = document.getElementById('preview');
	if (!e_elem || !o_preview) return;

	if (window.o_previewTimer) {
		window.clearTimeout(window.o_previewTimer);
		window.o_previewTimer = null;
	}

	if (s_type == 'PROD')
		e_elem.innerHTML = '<img src="/catalog/graphics/prods/' + s_code + 'med.jpg" /><div>' + s_name + '</div>';
	else {
		e_elem.update('Loading...');
		new Ajax.Updater('preview', 'http://www.lcipaper.com/php/category-preview.php?c=' + escape(s_code));
	}
	window.o_previewTimer = window.setTimeout(function () { o_preview.show('preview', e_origin) }, 300);
}

// autocomplete script
function tautocomp (a_cfg) {

	// register in global collections
	if (!window.A_TACOMPLST)
		window.A_TACOMPLST = [];
	
	if (!window.A_TACOMPIDX)
		window.A_TACOMPIDX = [];
	
	var s_id = this.s_id = a_cfg['id'] ? a_cfg['id'] : A_TACOMPLST.length;
	window.A_TACOMPLST[window.A_TACOMPLST.length] = this;
	window.A_TACOMPIDX[this.s_id] = this;
	
	this.a_cache = [];
	this.b_active = false;
	
	// assign methods
	this.f_onKeyDown = f_acompKeyDown;
	this.f_onKeyUp   = f_acompKeyUp;
//	this.f_onKeyPress= f_acompKeyPress;
	this.f_onReceive = f_acompReceive;
	this.f_onBlur    = f_acompBlur;
	this.f_show      = f_acompShow;
	this.f_hide      = f_acompHide;
	this.f_select    = f_acompSelect;
	this.f_highlight = f_acompHighlight;

	// attach to input box
	if (!a_cfg['control-name'])
		throw("TAC: control name is not specified");
	if (a_cfg['form-name']) {
		var e_form = document.forms[a_cfg['form-name']];
		if (!e_form)
			throw("TAC: form '" + a_cfg['form-name'] + "' can not be found");
		this.e_input = e_form.elements[a_cfg['control-name']];
	}
	else
		this.e_input = f_getElement(a_cfg['control-name']);

	if (!this.e_input || !this.e_input.tagName || this.e_input.tagName != 'INPUT')
		throw("TAC: element '" + a_cfg['control-name'] + "' does not exist in "
			+ (a_cfg['form-name'] ? "form '" + a_cfg['control-name'] + "'" : 'this document'));

	// create elements
	this.e_div = f_getElement('tac-box');
	if (!this.e_div) {
		this.e_div = document.createElement("DIV");
		this.e_div.id = 'tac-box';
		this.e_div.innerHTML = '<div id="tac-list"></div>';
		document.body.appendChild(this.e_div);
	}
	this.e_list = f_getElement('tac-list')
	this.e_iframe =  f_getElement('tac-iframe')
	if (b_ieFix && !this.e_iframe) {
		this.e_iframe = document.createElement("IFRAME");
		this.e_iframe.style.filter = 'alpha(opacity=0)';
		this.e_iframe.id = 'tac-iframe';
		this.e_iframe.src = '/images/pixel.gif';
		document.body.appendChild(this.e_iframe);
	}

	// attach events to input box
	this.e_input.onblur     = function () { window.A_TACOMPIDX[s_id].f_onBlur() };
	this.e_input.onkeyup    = function () { window.A_TACOMPIDX[s_id].f_onKeyUp() };
	this.e_input.onkeydown  = function (e_event) { window.A_TACOMPIDX[s_id].f_onKeyDown(e_event) };
//	this.e_input.onkeypress = function (e_event) { return window.A_TACOMPIDX[s_id].f_onKeyPress(e_event) };

	// init properties
	this.a_cfg = a_cfg;
	this.o_http = f_getHTTPObject();
}

function f_acompKeyPress (e_event) {
	if (!e_event && window.event)
		e_event = window.event;
	return (e_event.keyCode != 13);
}

function f_acompKeyDown (e_event) {

	if (!this.b_active)
		return true;

	if (!e_event && window.event)
		e_event = window.event;

	n_keyCode = e_event.keyCode;
	
	// down
	if (n_keyCode == 40)
		return this.f_highlight(this.n_activeOption + 1);
	// up
	else if (n_keyCode == 38)
		return this.f_highlight(this.n_activeOption - 1);
	// home
	else if (n_keyCode == 36)
		return this.f_highlight(1);
	// end
	else if (n_keyCode == 35)
		return this.f_highlight(this.a_options.length);
	// escape
	else if (n_keyCode == 27) {
		return this.f_highlight(0);
	}
	// enter
	else if (n_keyCode == 13 && this.n_activeOption)
		return this.f_select(this.n_activeOption - 1);

	return true;
}


function f_acompKeyUp () {

	var s_value = this.e_input.value.toLowerCase();
	if (this.s_value == s_value)
		return true;
	
	this.s_value = s_value;
	
	// minimum length of the text to autocomplete
	if (s_value.length < this.a_cfg['min-length'])
		return this.b_active ? this.f_hide() : false;

	// see if value is already cached
	if (this.a_cache[s_value])
		return this.f_show();
	
	if(!this.a_cfg['ajax-url'])
		return;
	
	// send ajax request
	var s_id = this.s_id;
	this.o_http.abort();
	this.o_http.onreadystatechange = function () { window.A_TACOMPIDX[s_id].f_onReceive(s_value) };
	this.o_http.open("GET", this.a_cfg['ajax-url'] + '?value=' + escape(s_value), true);
	this.o_http.send(null);
}

function f_acompReceive (s_value) {

	// process ajax response
	if (!this.o_http)
		return;
		
	if (this.o_http.readyState != 4) return;
	if (this.o_http.status != 200 && this.o_http.status != 304) return;

	var s_options = this.o_http.responseText;

	var s_option, a_optionsClean = [];
	var a_options = s_options.split("\n");
	for (var i = 0; i < a_options.length; i++) {
		if (!a_options[i].match(/^\s*(.*)[\s\r]*$/) || RegExp.$1 == '')
			continue;
			
		s_option = RegExp.$1;

		if (s_option.match(/^(.+)\|(.+)$/))
			s_option = RegExp.$1 + ' (' + RegExp.$2 + ')';
		
		a_optionsClean[a_optionsClean.length] = s_option;
	}
	this.a_cache[s_value] = a_optionsClean;

	if (s_value == this.e_input.value.toLowerCase())
		this.f_show();
}

function f_acompHighlight (n_number) {
	
	if (n_number < 0)
		n_number = this.a_options.length;
	else if (n_number > this.a_options.length)
		n_number = 1;
	
	var a_divs = this.e_list.getElementsByTagName('DIV');
	for (var i = 0; i < a_divs.length; i++)
		a_divs[i].id = (i == (n_number - 1) ? 'ac-active' : null);

	this.n_activeOption = n_number;
	return false;
}

function f_acompSelect (n_number) {
	var s_value = this.a_options[n_number];
	if (s_value.match(/^(\S+)\s\(/)) {
		window.location = 'http://www.lcipaper.com/' + RegExp.$1 + '.html';
		return;
	}
	
	this.e_input.value = s_value;
	this.s_value = this.e_input.value.toLowerCase();
	this.f_hide();
	if (this.a_cfg['submit-form'])
		this.e_input.form.submit();
	return false;
}

function f_acompBlur () {
	setTimeout('window.A_TACOMPIDX[\'' + this.s_id + '\'].f_hide()', 100);
}

function f_acompShow () {

	if (!this.a_cache[this.s_value])
		return false;

	if (!this.a_cache[this.s_value].length)
		return this.f_hide();

	// generate list of options
	this.a_options = this.a_cache[this.s_value];
	var s_html = '';
	for (var i = 0; i < this.a_options.length; i++)
		s_html += '<div onmousedown="window.A_TACOMPIDX[\'' + this.s_id + '\'].f_select(' + i + ')" onmouseover="window.A_TACOMPIDX[\'' + this.s_id + '\'].f_highlight(' + (i + 1) +')">' + this.a_options[i] + '</div>';

	this.e_list.innerHTML = s_html;
	this.n_activeOption = 0;
	
	// display options
	var n_top  = f_getPosition (this.e_input, 'Top') + this.e_input.offsetHeight + 1;
	var n_left = f_getPosition (this.e_input, 'Left');
	if (n_left < 0) n_left = 0;
	
	// adjust positioning
	this.e_div.style.left = n_left + 'px';
	this.e_div.style.top  = n_top + 'px';
//	this.e_div.style.width = (this.e_input.offsetWidth + 7) + 'px';

	if (this.b_active)
		return;

//	if (b_ie) {
		this.e_div.style.visibility = 'visible';
		if (this.e_iframe) {
			this.e_iframe.style.left = n_left + 'px';
			this.e_iframe.style.top  = n_top + 'px';
			this.e_iframe.style.width = (this.e_div.offsetWidth + 20) + 'px';
			this.e_iframe.style.height = (this.e_div.offsetHeight + 17) +'px';
			this.e_iframe.style.visibility = 'visible';
		}
//	}
//	else
//		f_fadeIn(null, this.e_div);

	this.b_active = true;
}

function f_acompHide () {

	this.b_active = false;

	if (window.e_inTransition)
		return;

	if (this.e_iframe)
		this.e_iframe.style.visibility = 'hidden';

//	if (this.a_cfg['submit-form'] || b_ie) 
		this.e_div.style.visibility = 'hidden';
//	else
//		f_fadeOut(null, this.e_div);
}



function f_fadeOut (n_opacity, e_elem) {

	// end of transition
	if (n_opacity < 0) {
		e_inTransition.style.visibility = 'hidden';
		e_inTransition = null;
		o_tabTimerFO = null;
		return;
	}
	// new transition
	if (n_opacity == null) {
		window.e_inTransition = e_elem;

		if (window.o_timerFO)
			clearTimeout(o_timerFO);
		n_opacity = 99;
	}

	f_setOpacity(e_inTransition, n_opacity);
	n_opacity -= 10;

	// cycle
	o_tabTimerFO = setTimeout('f_fadeOut(' + n_opacity + ')', 10);
}

function f_fadeIn (n_opacity, e_elem) {

	// end of transition
	if (n_opacity > 100) {
		f_setOpacity(e_inTransition, 100);
		o_timerFI = null;
		e_inTransition = null;
		return;
	}

	// new transition
	if (n_opacity == null) {
		if (window.o_timerFI)
			clearTimeout(o_timerFI);

		f_setOpacity(e_elem, 1);
		e_elem.style.visibility = 'visible';
		window.e_inTransition = e_elem;
	}
	else 
		f_setOpacity(e_inTransition, n_opacity);

	n_opacity += 10;

	// cycle
	o_timerFI = setTimeout('f_fadeIn(' + n_opacity + ')', 20);
}

var s_userAgent = navigator.userAgent.toLowerCase(),
	re_webkit = /WebKit\/(\d+)/i;
var b_mac = s_userAgent.indexOf('mac') != -1,
	b_ie = s_userAgent.indexOf('msie') != -1,
	b_ie5 = s_userAgent.indexOf('msie 5') != -1,
	b_ie6 = s_userAgent.indexOf('msie 6') != -1 && s_userAgent.indexOf('opera') == -1;
var b_ieFix = b_ie5 || b_ie6,
	b_ieMac  = b_mac && b_ie5,
	b_safari = b_mac && re_webkit.exec(s_userAgent) && Number(RegExp.$1) < 500;

if (s_userAgent.indexOf('opera') != -1 || s_userAgent.indexOf('safari') != -1)
	window.f_setOpacity = function (e_elem, n_opacity) {
		e_elem.style.opacity = n_opacity / 100;
	};
else if (s_userAgent.indexOf('gecko') != -1)
	window.f_setOpacity = function (e_elem, n_opacity) {
		e_elem.style.MozOpacity = n_opacity / 100;
	};
else if (s_userAgent.indexOf('msie') != -1) {
	window.b_IE = true;
	window.f_setOpacity = function (e_elem, n_opacity) {
		try {
			e_elem.filters.alpha.opacity = n_opacity;
		} catch (e) {};
	};
}
else
	window.f_setOpacity = null;

function f_getHTTPObject() {
	var o_http;
	if (typeof XMLHttpRequest != 'undefined') {
		try { o_http = new XMLHttpRequest(); }
		catch (e) { o_http = false; }
	}
	if (!o_http && typeof ActiveXObject != "undefined") {
		try { o_http = new ActiveXObject("MSXML2.XMLHTTP"); }
		catch (e) { o_http = false; }
		if (!o_http) {
			try { o_http = new ActiveXObject("Microsoft.XMLHTTP"); }
			catch (e) { o_http = false; }
		}
	}
	return o_http;
}

function f_getPageSize() {
	
	var n_xScroll, n_yScroll, n_yScrollPos;

	if (self.pageYOffset)
		n_yScrollPos = self.pageYOffset;
	else if (document.documentElement && document.documentElement.scrollTop)
		n_yScrollPos = document.documentElement.scrollTop;
	else if (document.body)
		n_yScrollPos = document.body.scrollTop;
	
	if (window.innerHeight && window.scrollMaxY) {	
		n_xScroll = document.body.scrollWidth;
		n_yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight) {
		n_xScroll = document.body.scrollWidth;
		n_yScroll = document.body.scrollHeight;
	}
	else {
		n_xScroll = document.body.offsetWidth;
		n_yScroll = document.body.offsetHeight;
	}
	
	var n_windowWidth, n_windowHeight;
	if (self.innerHeight) {
		n_windowWidth = self.innerWidth;
		n_windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) {
		n_windowWidth = document.documentElement.clientWidth;
		n_windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body) {
		n_windowWidth = document.body.clientWidth;
		n_windowHeight = document.body.clientHeight;
	}
	
	n_pageHeight = Math.max(n_yScroll, n_windowHeight);
	n_pageWidth  = Math.max(n_xScroll, n_windowWidth);

	return (new Array(n_pageWidth, n_pageHeight, n_windowWidth, n_windowHeight, n_yScrollPos));
}
// end of autocomplete script





// misc scripts and utility functions
function f_showBaskMessage() {
	var e_elem = f_getElement('cartMessageOverlay');
	if (!e_elem) return;
	
	var a_pageSize = f_getPageSize();
	e_elem.style.height = a_pageSize[1] + 'px';
	e_elem.style.display = 'block';

	e_elem = f_getElement('cartMessageBox');
	e_elem.style.left = ((a_pageSize[0] - e_elem.offsetWidth) / 2) + 'px';
	e_elem.style.top  = a_pageSize[4] + ((a_pageSize[3] - e_elem.offsetHeight) / 2) + 'px';
	e_elem.style.visibility = 'visible';
}

function f_hideBaskMessage() {
	var e_elem = f_getElement('cartMessageBox');
	if (!e_elem) return;
	e_elem.style.visibility = '';
	e_elem = f_getElement('cartMessageOverlay');
	e_elem.style.display = '';
}

function f_showBasket () {
	document.write(window.n_BaskCount
		? '<a href="http://www.lcipaper.com/catalog/specialty.paper?Screen=BASK&Store_Code=LPC"><strong>basket (<span id="basket-count">' + window.n_BaskCount + '</span>)</strong></a>' +
			'<a href="http://www.lcipaper.com/catalog/specialty.paper?Screen=BASK&Store_Code=LPC" id="cart-link"><img src="/images/header/basket.gif" alt="Check Out" /></a>' +
			'<a href="http://www.lcipaper.com/catalog/specialty.paper?Screen=BASK&Store_Code=LPC"><strong>checkout</strong></a>'
		: '<a href="http://www.lcipaper.com/catalog/specialty.paper?Screen=BASK&Store_Code=LPC"><strong>basket (<span id="basket-count">0</span>)</strong></a>' +
			'<a href="http://www.lcipaper.com/catalog/specialty.paper?Screen=BASK&Store_Code=LPC" id="cart-link"><img src="/images/header/basket.gif" alt="Check Out" /></a>'
	);
}

function showLCIPlayer(id, width, height, video, preview) {
	var flashvars = "file=" + encodeURIComponent(video);
	
	var s_domain = document.location.protocol + '//static.lcipaper.com';
	if (preview) flashvars += "&image=" + encodeURIComponent(preview);
	var el = f_getElement(id);
	if (!el) return;
	var html = '<object type="application/x-shockwave-flash" width="' + width + '" height="' + height + '" data="' + s_domain + '/videos/player.swf">' +
		'<param name="movie" value="' + s_domain + '/videos/player.swf">' +
		'<param name="allowfullscreen" value="true">' +
		'<param name="allowscriptaccess" value="always">' +
		'<param name="FlashVars" value="' + flashvars + '">' +
		'<param name="wmode" value="transparent">' +
	'</object>';
	
	el.innerHTML = '<div style="width:' + width + '">' + html + '<div>Embed: <input type="text" id="' + id + 'input" style="width:' + (width - 60) + 'px;color:gray;"/></div></div>';
	f_getElement(id + 'input').value = html;
}

function f_videoDescr (s_name) {
	window.open('/video/' + s_name + '.html','vd','location=1,status=0,scrollbars=0,width=600,height=550');
	f_trackLink('VDESCR',s_name);
}

function f_validateSignup(e_form) {
	if (!e_form) return;
	var s_email = e_form.elements['email_address'].value;
	if (s_email == '' || s_email == 'Enter Email') {
		alert('Email is required field');
		return false;
	}
	var s_name = e_form.elements['first_name'].value;
	if (s_name == '' || s_name == 'Enter Name') {
		alert('Name is required field');
		return false;
	}
	if (!s_email.match(/^[\w-\.]+\@[\w\.-]+\.[a-z]{2,4}$/)) {
		alert('Invalid format of email address');
		return false;
	}
	return true;
}

function f_showPopup (s_blockId, s_contentTag, e_source) {

	if (!window.o_thint)
		window.o_thint = new THints (null, {'wise':true,'margin':10,'gap':0,'align':'tcbc','show_delay':0,'hide_delay':200});

	var e_elem = f_getElement(s_blockId);
	if (!e_elem) {
		e_elem = document.createElement('DIV');
		e_elem.id = s_blockId;
		e_elem.className = 'prodpopup';
		e_elem.onmouseover = function () {	
			if (window.o_thint.e_timer) {
				clearTimeout(window.o_thint.e_timer);
				window.o_thint.e_timer = null;
			}
		}
		e_elem.onmouseout = function () { window.o_thint.hide() }
		document.body.appendChild(e_elem);
	}
	
	f_loadBlock (s_blockId, s_contentTag);

	window.o_thint.show(s_blockId, e_source);
}

function f_hidePopup () {
	if (window.o_thint)
		window.o_thint.hide();
}

function f_loadBlock (s_blockID, s_contentTag, s_onUpdate) {
		var e_elem = f_getElement(s_blockID);
		if (!e_elem || (e_elem.innerHTML && e_elem.innerHTML.indexOf('msg-loading') == -1)) return;
	
		window.o_httpBlock = f_getHTTPObject();
		window.o_httpBlock.onreadystatechange = f_loadBlockHandler;
		window.o_httpBlock.open("GET",
			(String(window.location).indexOf('http:') == 0 ? 'http' : 'https')
			+ '://www.lcipaper.com/php/blog-includes.php?type=ajax-content&tag='
			+ escape(s_contentTag), true);

		window.s_blockID = s_blockID;
		window.s_onUpdate = s_onUpdate;
		e_elem.innerHTML = '<div class="msg-loading">Loading...</div>';
		window.o_httpBlock.send(null);
}

function f_loadBlockHandler () {
	if (!window.o_httpBlock || !window.s_blockID)
		return;

	if (o_httpBlock.readyState != 4) return;
	if (o_httpBlock.status != 200 && o_httpBlock != 304)
		throw 'AJAX response error';

	var e_elem = f_getElement(s_blockID);
	e_elem.innerHTML = o_httpBlock.responseText;
	
	if (window.s_onUpdate)
		eval (s_onUpdate);
}

function f_trackLink (s_source, s_pcode) {
	try {
		
		if (String(document.cookie).match(/clicktrack\=yes/))
			return;
		
		// set new source cookie
		var d_exp = new Date();
		d_exp.setTime(d_exp.getTime() + (8 * 3600)); // 8 hours to keep
		document.cookie = 'clicktrack=yes;;expires=' + d_exp.toGMTString();
		
		pageTracker._trackEvent('LINK-CLICK', s_source, s_pcode);
	} catch(err) {}
}

function f_trackSource () {

	var s_location = String(window.location).toLowerCase();
	if (!s_location.match(/source=(\w+)/) && !s_location.match(/utm_source=(\w+)/))
		return;
	var s_source = RegExp.$1;

	// source cookies is already set
	if (String(document.cookie).match(/source=(\w+)/))
		return;

	// set new source cookie
	var d_exp = new Date();
	d_exp.setTime(d_exp.getTime() + (30 * 24 * 3600)); // 30 days to keep
	document.cookie = 'source=' + s_source + ';;expires=' + d_exp.toGMTString();
}

f_trackSource();

// page onload handling
function f_initPage () {
	// initialize menu
	f_initMenu();
	
	// initialize search autocomplete
	window.o_myAC = new tautocomp({
		'control-name' : 'query',
		'img-path'     : '/images/',
		'min-length'   : 1,
		'submit-form'  : true,
		'ajax-url'     : '/php/search-autocomplete.php'
	});
}

// assign mouseover event	
if (document.addEventListener)
	window.addEventListener('load', f_initPage, false);
if (window.attachEvent)
	window.attachEvent('onload', f_initPage);
else
	window.onload = f_initPage;



