var xmlhttp = false;

try {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
	try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
		xmlhttp = false;
	}
}

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	xmlhttp = new XMLHttpRequest();
}

function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;

	while (true) 
	{
	    now = new Date();
	    if (now.getTime() > exitTime)
	        return;
	}
}

function addArticle (debtor, artcode, aantal) 
{
	if (xmlhttp) 
	{
		var url = './webshop_ww.asp?methode=2&debtor=' + debtor + '&artcode=' + URLencode(artcode) + '&aantal=' + aantal;
		//alert(url);
		if (xmlhttp.readyState >= 1 && xmlhttp.readyState <= 3) {
			xmlhttp.abort();
		}
		xmlhttp.open("GET", url, true);	

		xmlhttp.onreadystatechange = function () {
		        if(xmlhttp.readyState == 4)
			{
				response = xmlhttp.responseText;
	        	}
		}
		xmlhttp.send(null);

		// systeem even de tijd geven om database-werk te doen
		pause(200);

		return true;
	}
	else	
		return false;
}

function AddFavorite (ctp, artcode) 
{
	if (xmlhttp) 
	{
		var url = './webshop_ww.asp?methode=13&ctp=' + ctp + '&artcode=' + URLencode(artcode);
		//	alert(url);
		if (xmlhttp.readyState >= 1 && xmlhttp.readyState <= 3) {
			xmlhttp.abort();
		}
		xmlhttp.open("GET", url, true);	

		xmlhttp.onreadystatechange = function () {
		        if(xmlhttp.readyState == 4)
				{
					response = xmlhttp.responseText;
	        	}
		}
		xmlhttp.send(null);

		// systeem even de tijd geven om database-werk te doen
		pause(200);

		return true;
	}
	else	
		return false;
}

function changeData (session, section, field, value) 
{
	if (xmlhttp)
	{		
		var url;

		url = "./webshop_ww.asp?methode=3&debtor=" + session + "&section=" + section + "&field=" + field + "&value="+value;// + URLencode(value);
		//alert(url);
		if (xmlhttp.readyState >= 1 && xmlhttp.readyState <= 3)
		{
			xmlhttp.abort();
		}
		xmlhttp.open("GET", url, true);	
		xmlhttp.onreadystatechange = function () {
            if(xmlhttp.readyState == 4){
				response = xmlhttp.responseText;
            }
		}
		xmlhttp.send(null);

		return true;
	}
	else
	{	
		return false;
	}
}

function updateResource (session, id, resource) 
{
	if (xmlhttp)
	{		
		var url = "./webshop_ww.asp?methode=14&session=" + session + "&id=" + id + "&res=" + resource; // + URLencode(value);
		//alert(url);
		if (xmlhttp.readyState >= 1 && xmlhttp.readyState <= 3)
		{
			xmlhttp.abort();
		}
		xmlhttp.open("GET", url, true);	
		xmlhttp.onreadystatechange = function () {
            if(xmlhttp.readyState == 4){
				response = xmlhttp.responseText;
            }
		}
		xmlhttp.send(null);
		return true;
	}
	else
		return false;
}

function URLencode(sStr) 
{
    return escape(sStr).replace(/\&/g, '%2B').replace(/\"/g,'%22').replace(/\'/g, '%27').replace(/\//g,'%2F');
}

function bestelRefresh (artcode, aantal, sessie)
{
	if ( addArticle(sessie, artcode, aantal) )
	{
//		alert('Winkelwagen bijgewerkt.');	
		location.reload();
	}
}

function bestellen(artcode, aantal, sessie)
{
	
//changes also to be done in bestellentocart
	if ( addArticle(sessie, artcode, aantal) )
	{
		location.href='webshop_Catalog.asp';
	}
}

function bestellentocart(artcode, aantal, sessie)
{

//same as bestellen only return to cart instead of catalog
	if ( addArticle(sessie, artcode, aantal) )
	{
		//alert('<%=Term.String(88895,"shoppingcart") & " " & Term.String(26605,"updated") %>');	
		location.href='webshop_Cart.asp';
	}
}

function is_getal()
{
	if (((window.event.keyCode>=48)&&(window.event.keyCode<=57))||((window.event.keyCode>=96)&&(window.event.keyCode<=105))||(window.event.keyCode==110)||(window.event.keyCode==46)||(window.event.keyCode==37)||(window.event.keyCode==39)||(window.event.keyCode==8)||(window.event.keyCode==35)||(window.event.keyCode==190)||(window.event.keyCode==13)||(window.event.keyCode==9)) 
	{
		window.event.returnValue=true;
	}
	else{
		window.event.returnValue=false;	
	}
}

function show_image(IMG)
{
	// specify window parameters
	photoWin = window.open( "", "photo", "status=no,scrollbars=no,resizable=no,menubar=no,location=no,screenX=20,screenY=40,left=20,top=40");

	// write content to window
	photoWin.document.write('<html>\n<head>\n<title>Close up</title>\n</head>\n<BODY OnClick="self.close();">\n');	
	//photoWin.document.write('<img src="webshop_showimage.asp?plaatjeid=' + IMG + '" onload="window.resizeTo(document.image.width,document.image.height)">\n');
	photoWin.document.write('<img src="webshop_showimage.asp?plaatjeid=' + IMG + '">\n');
	photoWin.document.write('</body>\n</html>\n');
	photoWin.document.close();	
		
	// If we are on NetScape, we can bring the window to the front
	if (navigator.appName.substring(0,8) == "Netscape") photoWin.focus();
}

function checkEnter(e)
{ //e is event object passed from function invocation
	var characterCode; // literal character code will be stored in this variable

	if(e && e.which)
	{ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	}
	else
	{
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}

	if (characterCode == 13)
	{ //if generated character code is equal to ascii 13 (if enter key)
		//document.forms[0].submit() //submit the form
		return false;
	}
	else
	{
		return true;
	}
}

var navClicked = false;
function nav(page, keywords, params, direction, totalItems, sort){
	if(navClicked == false){
		navClicked = true;
		if (document.getElementById('btnNext')) document.getElementById('btnNext').disabled = true;
		if (document.getElementById('btnBack')) document.getElementById('btnBack').disabled = true;
		url = "./webshop.asp?act=catalog&page="+page+"&direction="+direction+"&keywords="+keywords+""+params+"&totalItems="+totalItems+"&sort="+sort;
	
		document.location.href = url;
	}
}

function go(url){
	document.location.href=url;
}

function checkConditions()
{
	var el = document.getElementById('agree');
	if (el.checked)
	{
		window.location = 'webshop.asp?act=paymentselection';
	}
	else
	{
		alert('U dient eerst akkoord te gaan met onze voorwaarden.');
	}
}