function toggleDivDisplay(divId) {
	if (document.getElementById(divId).style.display == "none")
		document.getElementById(divId).style.display = "block";
	else
		document.getElementById(divId).style.display = "none";
}

function showDiv(divId) {
	document.getElementById(divId).style.display = "block";
}

function hideDiv(divId) {
	document.getElementById(divId).style.display = "none";
}

var popupWindow = false;
function openPopup(url, w, h) {
	x = screen.width / 2 - w / 2;
	y = screen.height / 2 - h / 2;
	if (popupWindow) popupWindow.close();
	popupWindow = window.open(url, 'ny', 'toolbar=no,copyhistory=no,location=no,' + 'directories=no,status=no,menubar=no,scrollbars=no,' + 'resizable=no,width=' + w + ',height=' + h + ',top=' + y + ',left=' + x);
}

function openPopupPay(url,w,h) {
	x = screen.width/2-w/2;
	y = screen.height/2-h/2;
	if (popupWindow) popupWindow.close();
    popupWindow=window.open(url,'ny','toolbar=no,copyhistory=no,location=yes,' + 'directories=no,status=yes,menubar=no,scrollbars=yes,' +'resizable=no,width=' + w + ',height=' + h + ',top=' + y +',left=' + x);
}

function toggleImage(element) {
	curImg = document.getElementById(element).src
	if (curImg.match("_on.") == "_on.") {
		document.getElementById(element).src = curImg.replace(/_on./i,"_off.")
	}
	else {
		document.getElementById(element).src = curImg.replace(/_off./i,"_on.")
	}
}
function toggleClass(element) {
	curClass = document.getElementById(element).className
	if (curClass == "Off") {
		//document.getElementById(element).src = curImg.replace(/_on./i,"_off.")
		newClass = 'On'
	}
	else {
		//document.getElementById(element).src = curImg.replace(/_off./i,"_on.")
		newClass = 'Off'
	}
	document.getElementById(element).className = newClass 


}

function product_preview(img) {
	document.getElementById('SlideShow').src=img;
	document.getElementById('popupImageLink0b').href=img.replace(/\/b\//,"/c/");
	Lightbox.prototype.updateImageList();
}
function getUpdate(type,parameter1,parameter2) { //flashrotator status function
	if (type == 'item') {
	document.getElementById("imgNr").innerHTML = parameter1+1;
	document.getElementById("popupTextLink").onclick = function() { doImageClick(parameter1) };
  }
}


function getHttpObject() {
	var xmlHttp = null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
	}
	return xmlHttp;
}

function $Ajax(url, returnFunction) {
	this.url = url;
	this.returnFunction = returnFunction;
	this.http = getHttpObject();
	this.lock = false;
	if (this.http == null) { this.useAjax = false; }
	else { this.useAjax = true; }
}
function $ajax_get(query) {
	if (this.useAjax && !this.lock) {
		this.lock = true;
		this.http = getHttpObject();
		var tempUrl = this.url + "?" + query + "&nocache=" + Math.random();
		var referer = this
		this.http.onreadystatechange = function() {
			if (this.readyState == 4) {
				referer.lock = false;
				referer.returnFunction(this);
			}
		}
		this.http.open("GET", tempUrl, true);
		this.http.send(null);
	}
}
$Ajax.prototype.get = $ajax_get;

var getBasketResponse = function(httpResult) {
	var result = httpResult.getResponseHeader("basketResult");
	if (result == "success") {
		var productCount = httpResult.getResponseHeader("basketProductCount").toString();
		var basketAmount = httpResult.getResponseHeader("basketAmount").toString();
		refreshBasketInfo(productCount, basketAmount);
		basketAlert("success");
	} else {
		basketAlert(result,httpResult.getResponseHeader("actualStock"));
	}
}

var basketAjax = new $Ajax("/includes/modules/ajax_update_basket.asp", getBasketResponse);

function updateBasket(siteId, vatFactor, shoppingMode, shoppingQuantity, pageId, productId, variantId) {
	if (basketAjax.useAjax) {
		var query = "siteId=" + siteId + "&vatFactor=" + vatFactor + "&shoppingMode=" + shoppingMode + "&shoppingQuantity=" + shoppingQuantity + "&shoppingPageId=" + pageId + "&shoppingProductId=" + productId + "&shoppingVariantId=" + variantId;
		basketAjax.get(query);
		return false;
	} else {
		return true;
	}
}

var alert_overlay;
var alert_box;
function dwsAlert(w,h,alertMsg,button1text,button2text) {
	var dBody = document.getElementById("contentBody");
	var pageSize = getPageSize();

	var overlay = document.createElement("div");
	dBody.appendChild(overlay);
	overlay.className = "overlay";
	overlay.style.height = pageSize[1]+"px";
	overlay.onclick = new Function("alert_box.parentNode.removeChild(alert_box); alert_overlay.parentNode.removeChild(alert_overlay);");
	
	var alertBox = document.createElement("div");
	dBody.appendChild(alertBox);
	alertBox.className = "alertBox";
	alertBox.style.width = w+"px";
	//alertBox.style.height = h+"px";
	var top = (document.body.offsetHeight - h)/2;
	var left = (pageSize[0] - w)/2;
	top = top + document.documentElement.scrollTop + document.body.scrollTop;
	alertBox.style.top = top+"px";
	alertBox.style.left = left+"px";
	
	var alertBoxContent = document.createElement("div");
	alertBox.appendChild(alertBoxContent);
	alertBoxContent.className = "alertBoxContent";
	alertBoxContent.innerHTML = alertMsg;

	if (button1text) {
		var button1 = document.createElement("div");
		alertBoxContent.appendChild(button1);
		button1.className = "alertBoxButton"
		button1.innerHTML = button1text;
		button1.onmouseover = new Function("this.className = 'alertBoxButton buttonOver';");
		button1.onmouseout = new Function("this.className = 'alertBoxButton';");
		button1.onclick = new Function("alert_box.parentNode.removeChild(alert_box); alert_overlay.parentNode.removeChild(alert_overlay);");
	}
	if (button2text) {
		var button2 = document.createElement("div");
		alertBoxContent.appendChild(button2);
		button2.className = "alertBoxButton"
		button2.innerHTML = button2text;
		button2.onmouseover = new Function("this.className = 'alertBoxButton buttonOver';");
		button2.onmouseout = new Function("this.className = 'alertBoxButton';");
		button2.onclick = new Function("location.href='/sys/module/shopping_display_basket.html';");
	}
	
	alert_overlay = overlay;
	alert_box = alertBox;
}


function getAbsolutePosition(node, subMargin, fixed) {
	var arrPos = new Array();
	if (getStyle(node, "position") == "fixed" || fixed != true) {
		arrPos[0] = 0;
		arrPos[1] = 0;
	} else {
		arrPos[0] = -scrollX();
		arrPos[1] = -scrollY();
	}

	if (subMargin) {
		mleft = getStyle(node, "margin-left");
		if (mleft.substring(mleft.length, mleft.length - 2) == "px") {
			mleft = mleft.substring(0, mleft.length - 2);
			arrPos[0] = arrPos[0] - parseInt(mleft);
		}
		mtop = getStyle(node, "margin-top");
		if (mtop.substring(mtop.length, mtop.length - 2) == "px") {
			mtop = mtop.substring(0, mtop.length - 2);
			arrPos[1] = arrPos[1] - parseInt(mtop);
		}
	}

	var newNode = node;
	while (newNode != document.documentElement && newNode != document.body) {
		arrPos[0] = arrPos[0] + newNode.offsetLeft;
		arrPos[1] = arrPos[1] + newNode.offsetTop;
		if (newNode.offsetParent) {
			newNode = newNode.offsetParent;
		} else { newNode = document.body; }
	}
	return arrPos;
}
function getStyle(oElm, strCssRule) {
	var strValue = "";
	if (document.defaultView && document.defaultView.getComputedStyle) {
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if (oElm.currentStyle) {
		strCssRule = strCssRule.replace(/\-(\w)/g, function(strMatch, p1) {
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}
function scrollX() {
	return document.body.scrollLeft + document.documentElement.scrollLeft;
}
function scrollY() {
	return document.body.scrollTop + document.documentElement.scrollTop;
}
