window.onload = init;
window.onresize = setWindowPositions;

// Array aanmaken waarin de variabelen worden geplaatst
var _get = Array();

// Plaats alle _GET variabelen in de array _get
if (location.href.split("?")[1]) {
    for (i = 0; i < location.href.split("?")[1].split("&").length; i ++) {
        _get[location.href.split("?")[1].split("&")[i].split("=")[0]] = location.href.split("?")[1].split("&")[i].split("=")[1];
    }
}

function init() {
	setWindowPositions();
	if (_get["topItem"]) {
		openTopItem 	= _get["topItem"];
	}
	if (_get["subItem"]) {
		openSubItem		= _get["subItem"];
	}
}

function openSpecificatie(id) {
	if (window.innerWidth) {
		var width = window.innerWidth;
		var height = window.innerHeight;
	} else {
		var width = document.body.clientWidth;
		var height = document.body.clientHeight;
	}

	var windowwidth = 374;
	var windowheight = 400;

	var left = (width - windowwidth) / 2;
	var top = (height - windowheight) / 2;

	var url = "http://linnenplaza.nl/elmts/product_specificatie.php?product_id=" + id;
	var options = "width=" + windowwidth + ", height=" + windowheight + ", top=" + top + ", left=" + left;
	options += ", toolbar=no, location=no, resizable=no, scrollbars=yes, status=no, titlebar=yes";
	window.open (url, "Specificatie", options);
}


// Variabele declaratie
var xmlHttp;
var xmlReturnFunction;
var ajaxEnabled= false;

// Controleren of Ajax ondersteund wordt door de browser
xmlHttp = GetXmlHttpObject();
if (xmlHttp == null) {
	alert ("Uw browser ondersteunt geen HTTP Request");
} else {
	ajaxEnabled = true;
}

// Ajax request uitvoeren
function ajax (url, action) {
	if (ajaxEnabled == true) {
		url = createUrl(url);
		xmlReturnFunction = action;

		xmlHttp = GetXmlHttpObject();
		xmlHttp.onreadystatechange=fetchResult;
		xmlHttp.open ("GET", url, true);
		xmlHttp.send(null);
	}
}

// Het resultaat ophalen en de return functie aanroepen
function fetchResult()  {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		eval (xmlReturnFunction);
	}
}

// HTTP request uitvoeren
function GetXmlHttpObject() {
	var objXMLHttp=null
	if (window.XMLHttpRequest) {
		objXMLHttp=new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp
}

// De url opmaken + random getal toevoegen om caching te voorkomen
function createUrl (url) {
	if (url.match(/\?/) !== null) {
		url += "&";
	} else {
		url += "?";
	}
	url += "sid=" + Math.random();
	return url;
}
