var oldElement = null;
var objProductZoom = null;

function onSubMenu(id)
{
	element = document.getElementById(id);
	if (element != null)
	{
		element.style.display = 'block';
	}

	oldElement = element;
}

function offSubMenu(id)
{
	element = document.getElementById(id);
	if (oldElement != null)
	{
		oldElement.style.display = 'none';
	}
}


function init()
{
	objProductZoom = document.getElementById('container_productzoom');
	document.body.oncontextmenu = evtContextMenu;
}

evtContextMenu = function (e)
{
	return false;
}

var curPartId = 0;

function vakoShowPart(partid)
{
	if (!holdPart)
	{
		curPartId = partid;

		document.getElementById('partthumbnail').src = url + arrParts[partid].image;
		//document.getElementById('maintitle').innerHTML = arrParts[partid].title;
		//document.getElementById('maindescription').innerHTML = arrParts[partid].description;
		
		el = document.createElement('select');
		el.id = 'vakoPartNrSelect';
		el.style.height = '20px';
		
		if (document.all)
		{
			el.attachEvent('onchange',vakoEventShowPartNr);
		}
		else
		{
			el.addEventListener('change',vakoEventShowPartNr,false);
		}

		for (var i = 0; i < arrParts[partid].partnrs.length; i++)
		{
			opt = document.createElement('option');
			opt.value = i;
			opt.appendChild(document.createTextNode(arrParts[partid].partnrs[i].partnumber));
			el.appendChild(opt);
		}

		document.getElementById('partnumbers').appendChild(el);


		vakoShowPartNr('vakoPartNrSelect');

		//situation
		/*
		arrCoords = arrParts[partid].coords.split(',');
		newDiv = document.createElement('div');
		newDiv.id = 'vakoPartUplight';
		newDiv.style.position = 'absolute';
		newDiv.style.top = arrCoords[1] + 'px';
		newDiv.style.left = arrCoords[0] + 'px';
		newDiv.style.height = (arrCoords[3] - arrCoords[1]) + 'px';
		newDiv.style.width = (arrCoords[2] - arrCoords[0]) + 'px';
		//newDiv.style.backgroundImage = 'url(http://www.vako.com/_img/transparent.png)';
		//newDiv.style.border = '1px solid red';
		*/


		if (arrParts[partid].situation)
		{
			for (var i = 0; i < arrParts[partid].situation.length; i++)
			{
				arrCoords = arrParts[partid].situation[i].coords.split(',');
				newDiv = document.createElement('div');
				newDiv.id = 'vakoPartUplightLoc' + i;
				newDiv.style.position = 'absolute';
				newDiv.style.top = arrCoords[1] + 'px';
				newDiv.style.left = arrCoords[0] + 'px';
				newDiv.style.height = (arrCoords[3] - arrCoords[1]) + 'px';
				newDiv.style.width = (arrCoords[2] - arrCoords[0]) + 'px';
				//newDiv.style.backgroundImage = 'url(http://www.vako.com/_img/transparent.png)';
				newDiv.style.border = '2px solid red';

				document.getElementById('vakoImageDiv').appendChild(newDiv);
			}
		}
	}
}

vakoEventShowPartNr = function(e)
{
	var id = '';
	document.all ? id = event.srcElement.id : id = e.target.id;

	vakoShowPartNr(id);
}

function vakoShowPartNr(id)
{
	tempVal = document.getElementById(id).value;

	//document.getElementById('parttitle').innerHTML = arrParts[curPartId].partnrs[tempVal].title;
	document.getElementById('partdescription').innerHTML = '<div style="height:21px;overflow:hidden;">' + arrParts[curPartId].partnrs[tempVal].description + '</div>';
	//document.getElementById('partsize').innerHTML = arrParts[curPartId].partnrs[tempVal].size;
	document.getElementById('partcolor').innerHTML = arrParts[curPartId].partnrs[tempVal].color;
	document.getElementById('partamount').innerHTML = arrParts[curPartId].partnrs[tempVal].amount;
	document.getElementById('pdcode').value = arrParts[curPartId].partnrs[tempVal].partnrid;
	
	document.getElementById('orderfield').style.visibility = 'visible';
}

function vakoResetParts()
{
	if (!holdPart)
	{
		/*element = document.getElementById('vakoImageDiv');
		toRemEl = document.getElementById('vakoPartUplight')
		element.removeChild(toRemEl);*/


		if (arrParts[curPartId].situation)
		{
			element = document.getElementById('vakoImageDiv');

			for (var i = 0; i < arrParts[curPartId].situation.length; i++)
			{
				toRemEl = document.getElementById('vakoPartUplightLoc' + i)
				element.removeChild(toRemEl);
			}
		}

		curPartId = 0;

		document.getElementById('partthumbnail').src = baseurl + 'catalogue-logo.jpg';
		//document.getElementById('maintitle').innerHTML = '';
		//document.getElementById('maindescription').innerHTML = '';
		document.getElementById('partnumbers').innerHTML = '';
		//document.getElementById('parttitle').innerHTML = '';
		document.getElementById('partdescription').innerHTML = '';
		//document.getElementById('partsize').innerHTML = '';
		document.getElementById('partcolor').innerHTML = '';
		document.getElementById('partamount').innerHTML = '';
		document.getElementById('pdcode').value = '';

		document.getElementById('orderfield').style.visibility = 'hidden';
	}
}

var holdPart = false;


vakoHoldPart = function(e)
{
	if (!holdPart)
	{
		holdPart = true
	}
	else
	{
		holdPart = false;
	}

	if (document.all)
	{
		if (!e) var e = window.event;
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
	}
}


function vakoSetHoldParts(value)
{
	holdPart = value;
}


function pageScroll()
{
	if (objProductZoom)
	{
		var scrOfX = 0, scrOfY = 0;

		if (typeof(window.pageYOffset) == 'number')
		{
			//Netscape, FF, Chrome compliant
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		}
		else if (document.body && (document.body.scrollLeft || document.body.scrollTop))
		{
			//DOM compliant
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		}
		else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
		{
			//IE6 standards compliant mode
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
		}

		objProductZoom.style.top = (scrOfY + 216) + 'px';
	}
}


// Webshop functions
function delFromBasket(pdcode)
{
	if (confirm("Weet u zeker dat u dit artikel wilt verwijderen?"))
	{
		window.location.href = 'http://www.vako.com/wp-content/vako-webshop/delFromBasket.php?l=nl&p='+pdcode;
	}
}

function cngAmount(pdcode,amount)
{
	if (nAmount = prompt("Geef het aantal op:",amount))
	{
		window.location.href = 'http://www.vako.com/wp-content/vako-webshop/cngAmount.php?l=nl&p='+pdcode+'&a='+nAmount;
	}
}

function flipFlopAflever(obj)
{
	if (obj.checked != false)
	{
		obj.value = 1;
		document.getElementById('aflevergegevens').style.visibility = 'visible';
	}
	else
	{
		obj.value = 2;
		document.getElementById('aflevergegevens').style.visibility = 'hidden';
	}
}

function sendForm()
{
	with (window.document.clientdata)
	{
		if (firm.value == "")
		{
			alert("Vul uw bedrijfsnaam in.");
			return;
		}
		if (cnr.value == "")
		{
			alert("Vul uw klantnummer in.");
			return;
		}
		if (vat.value == "")
		{
			alert("Vul uw BTW nr. in.");
			return;
		}
		if (cname.value == "")
		{
			alert("Vul uw naam in.");
			return;
		}
		if (street.value == "")
		{
			alert("Vul de straat in.");
			return;
		}
		if (nr.value == "")
		{
			alert("Vul het straatnummer in.");
			return;
		}
		if (place.value == "")
		{
			alert("Vul de plaats in.");
			return;
		}
		if (country.value == "")
		{
			alert("Vul het land in.");
			return;
		}
		if (tnr.value == "")
		{
			alert("Vul uw telefoonnummer in.");
			return;
		}
		if (email.value == "")
		{
			alert("Vul uw emailadres in.");
			return;
		}

		if (afleveradres.checked != false)
		{
			if (aflcname.value == "")
			{
				alert("Vul de aflever contactpersoon naam in.");
				return;
			}
			if (aflstreet.value == "")
			{
				alert("Vul de aflever straat in.");
				return;
			}
			if (aflnr.value == "")
			{
				alert("Vul het aflever straatnummer in.");
				return;
			}
			if (aflplace.value == "")
			{
				alert("Vul de aflever plaats in.");
				return;
			}
			if (aflcountry.value == "")
			{
				alert("Vul het aflever land in.");
				return;
			}
		}

		submit();
	}
}

function sendOrderForm()
{
	with (window.document.orderform)
	{
		if (p.value == "")
		{
			alert("Kies eerst een artikel.");
			return;
		}
		if (a.value == "")
		{
			alert("Vul het aantal in.");
			return;
		}
		if (s.value == "0")
		{
			alert("Kies de soort hoeveelheid.");
			return;
		}

		submit();
	}
}