﻿function goToDealer(strDealer) {
	var strDestUrl = getDealerLocationUrl(strDealer);
	window.location.href = strDestUrl;
}
function getDealerLocationUrl(strDealer) {
	var strPageId = document.strPageId;
	var arySource = new Array("20", "38", "37");
	var strDestId = "0";
	strDest = ".flagstangseksperten.dk/";
	if (document.strDestCategory == "flagstang") {strPageId="20";}
	if (document.strDestCategory == "flag") {strPageId="38";}
	if (document.strDestCategory == "tilbehoer") {strPageId="37";}
	switch(strDealer)
	{
	case "jo":
		aryDest = new Array("98", "99", "100");
		strDest = "jo" + strDest;
		break;    
	case "vj":
		aryDest = new Array("220", "221", "222");
		strDest = "vj" + strDest;
		break;
	case "bfi":
		aryDest = new Array("136", "137", "138");
		strDest = "bfi" + strDest;
		break;
	case "ff":
		aryDest = new Array("192", "193", "194");
		strDest = "ff" + strDest;
		break;
	case "dahls":
		aryDest = new Array("164", "165", "166");
		strDest = "dahls" + strDest;
		break;
	case "aalborg":
		aryDest = new Array("320", "321", "322");
		strDest = "aalborg" + strDest;
		break;
	default:
		aryDest = new Array("98", "99", "100");
		strDest = "jo" + strDest;
	}
	var intIndex = -1;
	for (var i=0; i<arySource.length; i++) {
		if (arySource[i] == strPageId) {
			intIndex = i;
		}
	}
	if (intIndex != -1) {
		strDestId = aryDest[intIndex];
	}

	if (strDestId != "0") {
		strDest += "Default.aspx?id=" + strDestId;
	}
	strDest = "http://" + strDest;
	return strDest;
}
function dealerPop(strCategory) {
	document.strDestCategory = "";
	if (strCategory != "") {
		document.strDestCategory = strCategory;
	}
	popOverlay("show");
	document.getElementById("dealerPop").style.top = calculateYpos("252") + "px";
	document.getElementById("dealerPop").style.display = "block";
}
function dealerPopClose() {
	popOverlay("hide");
	document.getElementById("dealerPop").style.display = "none";
}
function productPop(strURL) {
	popOverlay("show");
	document.getElementById("productPop").style.top = calculateYpos("402") + "px";
	document.getElementById("productPop").style.display = "block";
	document.getElementById("productPopImage").src= strURL;
}
function productPopClose() {
	document.getElementById("productPopImage").src= "x.gif";
	popOverlay("hide");
	document.getElementById("productPop").style.display = "none";
}
function popOverlay(strMode) {
	var objOverlay = document.getElementById("popOverlay");
	if (strMode == "hide") {
		objOverlay .style.display = "none";
	} else {
		objOverlay .style.display = "block";
		objOverlay .style.height = getDocHeight() + "px";
	}
}
function calculateYpos(strHeight) {
	var intYpos = 0;
	var intHeight = parseInt(strHeight);
	var intWinHeight = winHeight();
	if ( intWinHeight > intHeight ) {
		intYpos = Math.round( ( intWinHeight - intHeight ) / 2);
	}
	var intScroll = getScrollY();
	intYpos = intYpos + intScroll;
	return intYpos;
}
function winHeight() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerHeight ) == 'number' ) {
		//Non-IE
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientHeight ) ) {
		//IE 4 compatible
		myHeight = document.body.clientHeight;
	}
	return myHeight;
}
function getScrollY() {
	var scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
	} else if( document.body && ( document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
	} else if( document.documentElement && ( document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
	}
	return scrOfY;
}
function getDocHeight() {
	var D = document;
	return Math.max(
		Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
		Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
		Math.max(D.body.clientHeight, D.documentElement.clientHeight)
	);
}
function addToCartDropdown(objAnchor) {
	var objSelect = objAnchor.parentNode.getElementsByTagName("select")[0];
	var objOptions = objSelect.options;
	var intSelected = objSelect.selectedIndex;
	var strProductId = objOptions[intSelected].value;
	var strAddURL = "";
	strAddURL += "/default.aspx?id=" + document.strPageId + "&";
	strAddURL += "productid=" + strProductId + "&";
	strAddURL += "cartcmd=add&";
	strAddURL += "redirect=Indkobskurv-" + document.strCartId + ".aspx";
	window.location.href = strAddURL;
}
function makeLink(strAnchorText, strId) {
	document.write('<a href="/default.aspx?id=' + strId + '">' + strAnchorText + '</a>');
}
