window.onload = function()
{
	initOrderButton();

	if(document.getElementById('txtDefaultPaymentMethod'))
	{
		fPaymentManager(document.getElementById('txtDefaultPaymentMethod').value);	
	}
	initCountToMax();

	var obj = document.getElementById("custx_address1");
	if(obj != null)
	{
		obj .onchange=function(){fCheckAddress(this)};
	}
}
function fCheckAddress(o)
{
	if(o.value != "")
	{
		lOk = false;
		if(o.value.search(/\s\d/) > 3)
		{
			lOk = true;
		}
		if(! lOk)
		{
			o.style.backgroundColor= "FFCC99";
			alert("Heeft u uw huisnummer juist ingevuld?")
		}
		else
		{
			o.style.backgroundColor= "#FFFFFF";
		}
	}
}
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 fPaymentManager(cName)
{
	payments = new Array("rembours","bill","ideal","payfirst");
	for(var i=0; i<payments.length; i++)
	{
		div = document.getElementById('Payment_' + payments[i]);
		if(div != null)
		{
			if(cName == payments[i])
			{
				div.style.display = 'block'
			}
			else
			{
				div.style.display = 'none'
			}
		}
	}
	return;
}

function initCountToMax()
{
	a = document.getElementsByTagName("input");
	for(var i=0; i<a.length; i++)
	{
		b=a[i];
		c = b.name;
		d = Math.max(c.indexOf("txt_BasketCount_"), c.indexOf("txtCount_"));
		if(d == 0 && b.type=="text")
		{
			b.onchange = CountToMax;
			b.onkeyup = CountToMax;
		}
	}

}
function CountToMax()
{
	var newvalue = "";
	var oldvalue = this.value;
	if(oldvalue == "")
		return;

	oldvalue = oldvalue.replace(/\,/g,".");


	if(isNaN(oldvalue ))
	{
		newvalue= 1;
	}
	else
	{
		newvalue= Math.ceil(oldvalue);
	}

	if(newvalue != this.value)
	{
		this.style.borderColor = "#fa7701";
	}
	else
	{
		this.style.borderColor = "";
	}

	this.value = newvalue;

}

function showWebgroups(cFilter, cPage)
{

	lcHref = "/default.asp?pageid="+ cPage+"&webgroupfilter=" + cFilter ;

	window.location.href = lcHref ;
}

function fShowClusters(tcWebgroupfilter,tcClusterfilter,tcPageID)
{
	if(typeof tcWebgroupfilter == undefined)
		return;
	if(typeof tcClusterfilter == undefined)
		return;
	if(typeof tcClusterfilter == undefined)
		return;

	var lcHref = '/default.asp?pageid='+tcPageID+'&docid=33';
	lcHref += '&webgroupfilter='+tcWebgroupfilter;
	lcHref += '&clusterfilter='+tcClusterfilter;

	window.location.href = lcHref;
}

function onThumbClick(thumb)
{
	cT = thumb.id;
	cI = cT.replace('thumb_','big_');
	oI = document.getElementById(cI);

	if(oI != null)
	{
		for(var i=0; i<oI.parentNode.childNodes.length; i++)
		{
			oCI = oI.parentNode.childNodes[i];
			if(oCI == null)
				continue;

			if(! oCI.style)
				continue;

			if(oCI.id.substr(0,4) != "big_")
				continue;
		
			if(oCI == oI)
				oCI.style.display = "block";
			else
				oCI.style.display = "none";
			
		}
	}
}

var iBoxMin = 0;
var iGrow = 15;
var CurrentBox = null;


function initwebgroupmenu(menu)
{
	if(menu.className.indexOf("groupsubmenu") == -1)
		return;

	if(CurrentBox == null)
	{
		divs = document.getElementsByTagName("div");
		for(var i=0; i<divs.length; i++)
		{
			ch = divs[i];

			if( ch.className.indexOf("groupsubmenuactive") > 0)
				CurrentBox = ch ;

		}
	}
	if (menu.scrollHeight) // all but Explorer Mac
	{
		menu.maxheight = menu.scrollHeight;
		menu.minheight = iBoxMin ;
	}
	else 
	{
		menu.maxheight = menu.offsetHeight;
		menu.minheight = iBoxMin;
	}

	menu.grow = (menu.className == "groupsubmenu");

	menu.iheight = menu.grow ? menu.minheight:menu.maxheight ;
	
}

function togglewebgroupmenu(tcMenuId)
{
	var loMenu = document.getElementById(tcMenuId);

	if(! loMenu.maxheight)
		initwebgroupmenu(loMenu);

	if(! loMenu.maxheight)
		return;

	if(loMenu.grow)
	{
		if(CurrentBox != null && CurrentBox.id != loMenu.id)
		{
			initGrowWebgroupbox(CurrentBox, - iGrow)	
			CurrentBox.grow = ! CurrentBox.grow;
		}

		initGrowWebgroupbox(document.getElementById(tcMenuId), iGrow);

		loMenu.grow = ! loMenu.grow;
		CurrentBox = loMenu;
	}
	else
	{
		initGrowWebgroupbox(document.getElementById(tcMenuId), 0 - iGrow);
		loMenu.grow = ! loMenu.grow;
		CurrentBox = null;
	}
}

function initGrowWebgroupbox(box, tiGrow)
{
	if(! box.maxheight)
		initwebgroupmenu(box);
	if(! box.maxheight)
		return;

	clearBoxTimer(box);
	box.igrow = tiGrow;
	box.iInterval = window.setInterval("growWebgroupbox(document.getElementById('"+box.id+"'))", 10);
}


function clearBoxTimer(box)
{
	if(box.iInterval)
	{
		if(box.iInterval > 0)
		{
			window.clearInterval(box.iInterval)
		}
	}
}


function growWebgroupbox(box)
{
	var iNewheight = box.iheight + box.igrow;

	if(box.igrow < 0 && iNewheight <  box.minheight )
	{
		iNewheight = 0;
//		return;
	}
	else if(box.igrow > 0 && iNewheight >  box.maxheight + iGrow )
	{
		iNewheight = box.maxheight ;
		clearBoxTimer(box)
//		return;	
	}

	box.style.height = String(iNewheight ) + "px";
	box.iheight = iNewheight ;
}

function sendartbymail_toggle(artid, wgid)
{
	if(typeof(wgid) != "string")
		wgid="-";

	oA = document.getElementById("sendartbymail_area");
	if(oA != null)
	{
		oF = document.getElementById("sendartbymail_frame");
		if(oA != null)
		{
			oA.style.display = (oA.style.display=="block")?"none":"block";
			oF.src = "/default.asp?pageid=71&webgroupfilter="+wgid+"&artdetail=" + artid;
		}	

	}
}

function initOrderButton()
{
	var loBtn = document.getElementById("cmd_OrderNow");
	if(loBtn != null)
	{
		history.go(1);

		loBtn.onclick = function()
		{
			this.value= "Order wordt verwerkt...";
			this.onclick = function()
			{
				return false;
			}
		}
	}
}

