//preload menu img
var bufferIsIe = undefined;
var bufferIeVersion = undefined;
function getIsIe() {
	if (bufferIsIe == undefined) {
		if (bufferIsIe = /MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
			bufferIeVersion = new Number(RegExp.$1);
		}
	}
	return bufferIsIe;
}
function getIeVersion() {
	return bufferIeVersion;
}

var IMAGE_PATHS = [];
if (getIsIe()) {
	if (getIeVersion() <= 6) {
		IMAGE_PATHS[0] = "images/home22.png";
		IMAGE_PATHS[1] = "images/products22.png";
		IMAGE_PATHS[2] = "images/contacts22.png";
	} else{
		IMAGE_PATHS[0] = "images/home2.png";
		IMAGE_PATHS[1] = "images/products2.png";
		IMAGE_PATHS[2] = "images/contacts2.png";	
	}
} else{
	IMAGE_PATHS[0] = "images/home2.png";
	IMAGE_PATHS[1] = "images/products2.png";
	IMAGE_PATHS[2] = "images/contacts2.png";
}

var IMAGE_CACHE = [];
for (var i=0; i < IMAGE_PATHS.length; i++) {
	IMAGE_CACHE[i] = new Image();
	IMAGE_CACHE[i].src = IMAGE_PATHS[i];
}

//menu
function showmenu(id, img) {
	if (getIsIe()) {
		if (getIeVersion() <= 6) {
			document.getElementById("img" + id).src = "images/" + img + "22.png";
		} else {
			document.getElementById("img" + id).src = "images/" + img + "2.png";
		}
	} else {
		document.getElementById("img" + id).src = "images/" + img + "2.png";
	}
	document.getElementById("m" + id).style.display = "block";
}
function hiddmenu(id, img) {
	document.getElementById("img" + id).src = "images/" + img + ".png";
	document.getElementById("m" + id).style.display = "none";
	if (getIsIe()) {
		if (getIeVersion() <= 6) {
			correctPNG();
		}
	}
}

function shows(thediv) {
	document.getElementById(thediv).style.display = "block";
}
function hides(thediv) {
	document.getElementById(thediv).style.display = "none";
}

var intDelay = 10;
var intInterval = 5;
function ShowGradient(thediv) {
	if (getIsIe()) {
		document.getElementById(thediv).filters.alpha.opacity = 0;
	} else if (navigator.userAgent.indexOf('Firefox') >= 0) {
		document.getElementById(thediv).style.MozOpacity = 0;
	}
	document.getElementById(thediv).style.display="block";
	GradientShow(thediv);
}
function GradientShow(thediv) { 
	if (getIsIe()) {
		document.getElementById(thediv).filters.alpha.opacity += 5;
		if (document.getElementById(thediv).filters.alpha.opacity < 80) {
			setTimeout("GradientShow('" + thediv + "')", 20);
		}
	}
	if (navigator.userAgent.indexOf('Firefox') >= 0) {
		document.getElementById(thediv).style.MozOpacity = parseFloat(document.getElementById(thediv).style.MozOpacity) + 0.1;
		if (document.getElementById(thediv).style.MozOpacity<0.8) {
			setTimeout('GradientShow("' + thediv + '")', 50);
		}
	}
}

//item.php
function exec(cmd, param) {
	jQuery.getScript("itemCmd.php?cmd=" + cmd + param);
}
function showSeriesInit(id) {
	exec('itemShowSeries', "&id=" + id);
}
function setmodel(id, value, name, models) {
	jQuery('#container,#ie6pagewrap').hide();
	document.getElementById('spanSeriesValue').innerHTML = value;
	document.getElementById('spanSeriesName').innerHTML = name;
	var str = '', divMD = document.getElementById('md');
	if (models.length > 0) {
		for (var i = 0, iMax = models.length; i < iMax; i++) {
			var model = models[i];
			str += "<li><a href=\"javascript:showModelInit("+model[0]+")\">"+model[1]+"</a></li>";
		}
	} else {
		str += 'No available model in this series.';
	}
	divMD.innerHTML = str;
	document.getElementById("bigxz").style.display = "none";
	document.getElementById("smaxz").style.display = "none";
	showInfoClear();
	jQuery('#container,#ie6pagewrap').fadeIn();
}
var modelCurr = -1;
function showModelInit(id) {
	if (modelCurr != id) {
		modelCurr = id;
		if (series_nodiameter) {
			exec('itemShowInfo', "&idnodiameter=" + id);
		} else {
			exec('itemShowModel', "&id=" + id);
		}
	}
}
var diameterStrList = null, selectBigClassRendered = false;
function showWheelDiameterList(list) {
	diameterStrList = list;
	var divBigXZ = document.getElementById("bigxz");
	document.getElementById("smaxz").style.display="none";
	showInfoClear();
	var str = '';
	if (list.length == 0) {
		str += "No product in this model."
	} else {
		str += '<select name="bigclass" id="selectBigClass">';
		str += '<option value="-1">Please select wheel diameter</option>';
		for (var i = 0, iMax = list.length; i < iMax; i++) {
			str += '<option value="' + i + '" >' + list[i] + ' mm</option>';
		}
		str += '</select>';
	}
	jQuery("#bigxz").hide();
	divBigXZ.innerHTML = str;
	selectBigClassRendered = false;
	rSelects();
	jQuery("#bigxz").fadeIn();
}
var diameterCurr = 0;
function showMountingTypeInit(diameterIndex) {
	if (diameterIndex == -1) {
		document.getElementById("smaxz").style.display = "none";
	} else {
		diameterCurr = diameterIndex;
		exec('itemShowMountingType', "&mid=" + modelCurr + "&diameterIndex=" + diameterIndex);
	}
	showInfoClear();
}
var selectSmallClassRendered = false;
function showMountingTypeList(list) {
	var divSMAXZ = document.getElementById("smaxz");
	var str = '';
	if (list.length == 0) {
		str += "Error: no product with diameter " + diameterStrList[diameterCurr] + "mm. <a href=\"javascript:showModelInit(modelCurr)\" style=\"color:#019aea;\">[Refresh]</a>"
	} else {
		str += '<select name="smallclass" id="selectSmallClass">';
		str += '<option value="-1">Please select mounting type</option>';
		for (var i = 0, iMax = list.length; i < iMax; i++) {
			str += '<option value="' + i + '" >' + list[i] + '</option>';
		}
		str += '</select>';
	}
	jQuery("#smaxz").hide();
	divSMAXZ.innerHTML = str;
	selectSmallClassRendered = false;
	rSelects();
	jQuery("#smaxz").fadeIn();
}
function showInfoInit(mountingTypeIndex) {
	if (mountingTypeIndex == -1) {
		showInfoClear();
	} else {
		exec('itemShowInfo', "&mid=" + modelCurr + "&diameterIndex=" + diameterCurr + "&mountingTypeIndex=" + mountingTypeIndex);
	}
}
var showInfoIsFirst = false;
function showInfoClear() {
	document.getElementById('divInfo').innerHTML = "";
	document.getElementById('divInfo').style.display = "none";
	showInfoIsFirst = true;
}
function showInfoCount(count) {
	if (count != 1) {
		var str = "<span style=\"margin:0px 0px 0px 130px;border-bottom:1px #019AEA solid;\">";
		str += count + " items found.";
		if (count > 1) {
			str += " Please scroll down to view more.";
		}
		str += "</span><br />";
		document.getElementById('divInfo').innerHTML += str;
	}
}
function showInfo(id, name, des, paramTitle, paramValue) {
	var str = '';
	if (showInfoIsFirst) {
		showInfoIsFirst = false;
	} else {
		str += "<br /><br />";
	}
	str += "<div>";
	str += '<div class="model2">';
	str += '<div class="left">';
	str += "<span>" + name + "</span><br>";
	str += "TECHNICAL DATA";
	str += "</div>";
	str += '<div class="right">';
	str += des;
	str += "</div>";
	str += "</div>";
	str += '<div class="text">';
	str += '<div class="lbk">';
	for (var i = 0, iMax = paramTitle.length; i < iMax; i++) {
		str += '<div class="lb">';
		str += '<div class="lbbt">' + paramTitle[i] + '</div>';
		str += '<div class="lbbt2">' + paramValue[i] + '</div>';
		str += '</div>';
	}
	str += '</div>';
	str += '<div class="imgk"><img src="image.php?type=item&id='+id+'" /></div>';
	str += '</div>';
	str += '</div>';
	document.getElementById('divInfo').innerHTML += str;
}
function showInfoDone() {
	jQuery('#divInfo').fadeIn();
}

//index.php
var ct = null;
function showcont2(thediv) {
	if (ct != null) {
		window.clearTimeout(ct);
		ct = null;
	}
	document.getElementById("d0").style.display = "none";
	for (var i = 1; i <= 6; i++) {
		if(i != thediv){
			document.getElementById("d" + i).style.display = "none";
		}
    }
    document.getElementById("d" + thediv).style.display = "block";
}
function hiddcont2(thediv){
	document.getElementById("d" + thediv).style.display = "none";
	document.getElementById("d0").style.display = "block";
}

//brandsearch.php
function showcont(id, brands) {
    document.getElementById("p" + id).src = "image.php?id=" + id + "&type=brandselect";
    jQuery("#d" + id).fadeIn();
	for (var i = 0; i < brands.length; i++) {
		var thet=document.getElementById("d" + brands[i]);
		if (brands[i] != id) {
			thet.style.display="none";
			document.getElementById("p" + brands[i]).src = "image.php?id=" + brands[i] + "&type=brandselect0";
		}
    }
}

//assistancesearch.php
function inputblur(div) {
	window.setTimeout(function() {
		document.getElementById(div).style.display = 'none';
	}, 250);
}
function setvalue(idInput, display, idValue, value, div) {
	var objInput = document.getElementById(idInput);
	var objValue = document.getElementById(idValue);
	objInput.value = display;
	objValue.value = value;
	document.getElementById(div).style.display = "none";
}
function showdiv(thediv)
{
  	for (var i=1 ;i<4;i++ )
    {
		var thet=document.getElementById("t"+i);
		if(thet!=null&&thet!=thediv){
		thet.style.display="none";
		}
    }
  	document.getElementById(thediv).style.display="block";
}

