window.onload = function()
{
	initOrderButton();
	initCountFields();
	sessionPopUp();
}

function pop(url, width, height)
{
	window.open(url,'','width='+width+', height='+height+', menubar=no, status=no, location=no, toolbar=no, scrollbars=no, resizable=no', false);
}

function poppage(url, width, height)
{
	window.open(url,'','width='+width+', height='+height+', menubar=no, status=no, location=no, toolbar=no, scrollbars=yes, resizable=yes', false);
}

function initOrderButton()
{
	var loBtn = document.getElementById("cmd_OrderNow");
	if(loBtn != null)
	{
		loBtn.onclick = function()
		{
			this.value= "Order wordt verwerkt...";
			this.onclick = function()
			{
				return false;
			}
		}
	}
}

function showWebgroups(cFilter, cCluster)
{
	if(window.location.href.toLowerCase().indexOf("default.asp?") > 1)
	{
		var cHref = window.location.href;
		cHref = cHref.replace(/webgroupfilter\=[0-9,-]+\&?/gi,"");
		cHref = cHref.replace(/artdetail\=[^\&]+\&?/gi, "");
		cHref = cHref.replace(/clusterfilter\=[^\&]+\&?/gi, "");
		cHref = cHref.replace("?","?alstart=&webgroupfilter="+cFilter+"&");
		window.location.href = cHref;
	}
	else
	{
		window.location.href = "/default.asp?alstart=0&webgroupfilter="+cFilter;
	}
}

function initCountFields()
{
	var loFields = document.getElementsByTagName("input");
	for(var i=0; i<loFields.length; i++)
	{
		loF = loFields.item(i);
		if(loF.name.indexOf("txtCount_")== 0 || loF.name.indexOf("txt_BasketCount_")== 0 )
		{
			loF.onchange = function()
			{
				roundFieldValue(this);
			}
		}
	}
}

function roundFieldValue(oF)
{
                var val = oF.value;
                val = parseInt(val,10);
                if(isNaN(val) || val < 0)
                               val = 0;
                val = Math.round(val);
                oF.value = val;
}

var  sessionPopDoc = null;
var  sessionPopUrl = null;

function initsessionPopUp(docid, url)
{
	sessionPopDoc = docid;
	sessionPopUrl = url;
}


function sessionPopUp()
{
	if(sessionPopDoc == null || sessionPopUrl == null)
		return;

	// cookie test
	var cookieName = "sessionPopup" + sessionPopDoc ;
	var curcookie = readCookie(cookieName);

	if(curcookie != String(sessionPopDoc ))
	{
		$.fancybox(
			{
				'width'		: 600,
				'height'		: 400,
				'type': 'iframe',
				'href': sessionPopUrl 
			}
		);
		createCookie(cookieName, String(sessionPopDoc), 1);
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


