var isBusy;

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();
}

var arImages = new Array();

function loadImages()
{
	var i = 0, key, ELdiv, img;

	for( key in arImages)
	{
		if( arImages[key] == 1  )
		{
			ELdiv = document.getElementById('imgdiv'+key);
			ELdiv.innerHTML = ""; 

			img = document.createElement('img');
			img.style.display = 'none';
			img.id = "img"+key;
			img.onload = function(){ resize_image(this, 100, 100); };
			img.src = "webshop_showimage.asp?plaatjeid="+arItemIDs[key];
			img.name = "img"+key;
//			img.onerror = function(){ this.src='images/trans.gif'; };		
			img.border = "0";

			ELdiv.appendChild(img);	
		}		
		i++;	
	}
		
}

function resize_image(img, maxwidth, maxheight){

	//for IE display should be "" to get the measures.
	img.style.display = ""
	
		var oldwidth = img.width;
		var oldheight = img.height;
			
		if (oldwidth > maxwidth || oldheight > maxheight){
			if ((oldwidth / maxwidth) > (oldheight / maxheight)){
			
			img.width = maxwidth;
			img.height = oldheight / (oldwidth / maxwidth);
			}
			else{
				
			img.height = maxheight;
			img.width = oldwidth / (oldheight / maxheight);
			}
		}
}

function pause (numberMillis) 
{
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) 
	{
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}

function jumpto(zoek, assort, page, maxpage, id){
	var ELjump = document.getElementById(id);
	gotopage = ELjump.value;
	if(ELjump.value > maxpage) 
		gotopage = maxpage;
	if(ELjump.value < 0) 
		gotopage = 1;
	
	if(gotopage != page){		
		direction = "next";
		if(gotopage < page) 
			direction = "back";		
		navigeer(gotopage, zoek, assort, direction);
	}
}

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;
}


//var winPopup;

function popDetail(url){
	var winPopup = window.open(url, "winPopup", 'width=500, height=400, location=no, status=yes, menubar=no, directories=no, toolbar=no, resizable=yes');
/*	
	1. width de breedte van het venster wanneer het geopend wordt
	2. height de hoogte van het venster wanneer het geopend wordt
	3. location de adresbalk van het venster (waar de URL van de pagina altijd in staat)
	4. status de statusbalk van het venster (staat bij IE standaard onderin het scherm)
	5. menubar de menubalk van het venster
	6. directories andere directory-knoppen van de browser
	7. toolbar hier staan de verschillende knoppen op: vorige, home, print, etcetera
	8. resizable geeft aan of de bezoeker de grootte van het venster mag aanpassen
	9. scrollbars het venster krijgt schuifbalken als de inhoud groter is dan de vensterafmetingen
*/	
}

function isNumber (input)
{
	if(input.value.length > 0 && !input.value.match(/^[0-9.,]+$/g))
	{
	   input.value = input.value.replace(/[^0-9.,]*/g,'');
	}
}

function submitall()
{
	for (i=0; i < document.forms.length; i++) 
	{
		if (document.forms[i].name.indexOf("formadj") >= 0) 
		{
			var code = document.forms[i].product.value;
			var sess = document.forms[i].session.value;
			var qty  = document.forms[i].amount.value;

			if (xmlhttp && code != "" && qty != "" && sess != "")
			{
				if (isBusy)
				{
					xmlhttp.onreadystatechange = function () {}
					xmlhttp.abort();
				}
				var locarray = window.location.href.split("/");
				locarray.pop();		
				var path = locarray.join("/");
				url = path+"/webshop_adjustamount.asp?productid="+ code +"&amount="+qty+"&session="+sess;				
				//alert(url);
				
				xmlhttp.open("GET", url, true);
				isBusy = true;
				
				xmlhttp.onreadystatechange = function () {
					if(xmlhttp.readyState == 4){
						isBusy = false;				
					}
				}
				xmlhttp.send(null);
				pause(500);
				//exea\bha 2008-11-21 added to clear values
				document.forms[i].amount.value = '';
			}
		}
		window.location.reload();
	}
}

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 changeHTA (value) 
{
	if (xmlhttp)
	{		
		var url = "./webshop_ww.asp?methode=15&value=" + 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;
	}
}
