var historyBackCount = -1;

function gotoURL(location) {
	window.location=location;
	return true;
}

function Browser() {

	var ua, s, i;

	this.isIE    = false;  // Internet Explorer
	this.isOP    = false;  // Opera
	this.isNS    = false;  // Netscape
	this.version = null;

	ua = navigator.userAgent;

	s = "Opera";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isOP = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}

	s = "Netscape6/";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}

	// Treat any other "Gecko" browser as Netscape 6.1.

	s = "Gecko";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;
		this.version = 6.1;
		return;
	}

	s = "MSIE";
	if ((i = ua.indexOf(s))) {
		this.isIE = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}
}

var browser = new Browser();

function getSubMenuDiv(currentTd) {
	hideSubMenus();
	var currentSubMenuDiv = document.getElementById(currentTd.id+"Div");
	currentSubMenuDiv.style.left  = (getPageOffsetLeft(currentTd)+155) + "px";
	currentSubMenuDiv.style.top  = getPageOffsetTop(currentTd) + "px";
	currentSubMenuDiv.style.display = 'block';
}

function getPageOffsetLeft(el) {
	var x;

	// Return the x coordinate of an element relative to the page.
	x = el.offsetLeft;
	if (el.offsetParent != null) x += getPageOffsetLeft(el.offsetParent);

	return x;
}

function getPageOffsetTop(el) {
	var y;

	// Return the x coordinate of an element relative to the page.
	y = el.offsetTop;
	if (el.offsetParent != null) y += getPageOffsetTop(el.offsetParent);
	return y;
}

function checkSubMenuDiv(event) {
    if ($(event.target).is('.menuProductTd')||$(event.target).is('.menuProductTdHover')) return;
	hideSubMenus();
}

function hideSubMenus() {
    for (var i = 0; divArray.length>i;i++) {
    	$("#col"+divArray[i]+"Div").hide();
   }
}

function selectType(obj, type) {
	form = document.forms['producten'];
	form.elements['type'].value = type;
	getScalesDiv(obj);
}
function selectScale(type) {
	form = document.forms['producten'];
	form.elements['scale'].value = type;
	form.submit();
}

function addToCartInline(productId) {
	document.getElementById('postOrderFrame').src = "/catalog&localaction=addToCartJs&id="+productId;
    historyBackCount -= 1;
}
function removeProduct(productId) {
	document.confirmCart["cart["+productId+"]"].value="";
	document.confirmCart.action='/cart&localaction=updateCart';
	document.confirmCart.submit();
}

$(document).ready(function() {
	$('body').click(checkSubMenuDiv);
});