var _className;
var _backgroundColor;
var ignore = false;

function MouseOverBlock(td) {
	_className = td.className;
	_backgroundColor = td.style.backgroundColor;
	td.className = 'td-block-hover';
	td.style.backgroundColor = _backgroundColor;
}

function MouseOutBlock(td) {
	td.className = _className;
	td.style.backgroundColor = _backgroundColor;
}

function SelectProductItem(num, total) {
	var div = null;
	var span = null;
	var arrow = null;
	
	for (var x = 0; x <= total; x++) {
		div = document.getElementById('product-details-' + x);
		span = document.getElementById('product-nav-' + x);
		arrow = document.getElementById('product-nav-arrow-' + x);

		if (div) 
			div.style.display = 'none';
		if (span && x !== 0)
			span.className = 'product-nav-item-normal';
		if (arrow && x !== 0)
			arrow.className = 'product-nav-arrow-normal';
	}
	
	div = document.getElementById('product-details-' + num);
	div.style.display = 'block';
	
	if (num !== 0) {
		span = document.getElementById('product-nav-' + num);
		if (span)
			span.className = 'product-nav-item-selected';
	
		arrow = document.getElementById('product-nav-arrow-' + num);
		if (arrow)
			arrow.className = 'product-nav-arrow-selected';
	}
	if(_className) ignore = true;
}

function MouseOverProductItem(h) {	
	_className = h.className;
	if (_className.indexOf('product-nav-title') > -1 || _className == 'product-nav-item-selected') {
		ignore = true;
		return 0; }
	else {
		h.className = 'product-nav-item-highlight'; }
}

function MouseOutProductItem(h) {
	if (!ignore) h.className = _className;
	ignore = false;
}
	
// get any txt file from server
function getFile(pURL) {
	if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc
		xmlhttp=new XMLHttpRequest();
		xmlhttp.open("GET", pURL, true); // leave true for Gecko
		xmlhttp.send(null);
	}
	else if (window.ActiveXObject) { //IE
		xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
		if (xmlhttp) {
			xmlhttp.open('GET', pURL, false);
			xmlhttp.send();
		}
	}
}

function WriteMetaKeywords() {
	getFile('http://www.iesgroup.ca/version1/keywords.txt');
	var tmpArr=xmlhttp.responseText.split('\n');
	
	var keywords = '';
	for (var x=0; x < tmpArr.length; x++) {
		if (keywords !== '') 
			keywords = keywords + ',';
		keywords += tmpArr[x];
	}
	return keywords;
}

function QueryString(ji) {
	hu = window.location.search.substring(1);
	gy = hu.split("?");
	for (i=0;i<gy.length;i++) {
	ft = gy[i].split("=");
	if (ft[0] == ji) {
		return ft[1];
		}
	}
}

function LoadRequestedItem() {
	var qs = QueryString('item');
	if (!qs) {
		return;	
	}
	if (qs !== '') {
		var items = qs.split('-');
		SelectProductItem(eval(items[1]), eval(items[2]));
	}
}

