function BuyProduct(thisform, MinBuyAmount, MaxBuyAmount) {
	if (parseInt(thisform.amount.value) < parseInt(MinBuyAmount)) {
		thisform.amount.value = MinBuyAmount;
		alert("Antal må ikke være mindre end ( "+MinBuyAmount+" )");
	    return false;
	}
	if (parseInt(MaxBuyAmount) > 0 ) {
		if (parseInt(thisform.amount.value) > parseInt(MaxBuyAmount)) {
			thisform.amount.value = MinBuyAmount;
			alert("Antal må ikke være større end ( "+MaxBuyAmount+" )");
	    	return false;
		}
	}
	return (true);
}
function Form_Validator(theForm) {
	if (theForm.name.value == "") {
		alert("Udfyld venligst feltet med Deres navn");
		theForm.name.focus();
		return (false);
	}
	if (theForm.address.value == "") {
		alert("Udfyld venligst feltet med Deres adresse");
		theForm.address.focus();
		return (false);
	}
	if (theForm.zipcode.value == "") {
		alert("Udfyld venligst feltet med postnr");
		theForm.zipcode.focus();
		return (false);
	}
	if (theForm.city.value == "") {
		alert("Udfyld venligst feltet med by");
		theForm.city.focus();
		return (false);
	}
	if (theForm.country.value == "") {
		alert("");
		theForm.country.focus();
		return (false);
	}
	if (theForm.phone.value == "") {
		alert("Udfyld venligst feltet med Deres telefon nr.");
		theForm.phone.focus();
		return (false);
	}
	if (theForm.email.value == "") {
		alert("Udfyld venligst feltet med Deres e-mail adresse. Adressen bruges udelukkende til udsending af ordrebekræftigelse og annoncering i tilfælde af evt. ændrede leveringstider.");
		theForm.email.focus();
		return (false);
	}
	return (true);
}
function SubmitOrderStep3(theForm) {
	doSubmit = 1;
	if (theForm.acceptTermsBit.checked != true) {
		alert("Du har ikke accepteret vores forretningsbetingelser.\nAccepten er påkrævet for at gennemføre ordren.");
		doSubmit = 0;
	}
	if (doSubmit == 1) {
		theForm.submitorder.disabled = true;
		theForm.submit();
	}
}
var imgWin;

var preImg = new Image();
var preImgUrl;
var preImgTitle;
var imgIsLoad = false;
preImg.onload = markImgLoad;

function markImgLoad() {
	imgIsLoad = true;
}
function showProdPreview(timg,tdesc) {
	imgIsLoad = false;
	preImgUrl=timg;
	preImgTitle=tdesc;
	preImg.src = '/data/prodimg_pre/'+timg;
	status = 'Henter preview';
	setTimeout(waitForMe,500);
	status = '';
	var theight=preImg.height+20;
	var twidth=preImg.width+20;
	if(window.screen){
		var wLeft = (screen.width-twidth)/2;
		var wTop = (screen.height-theight)/3;
	} else {
		var wLeft = 10;
		var wTop = 10;
	}
	if (imgWin){
		imgWin.close();
	}
	imgWin = window.open('preview.asp?img='+preImgUrl+'&title='+preImgTitle,'imgWin','top='+wTop+',left='+wLeft+',scrollbars=no,status=no,resizable=1,width='+twidth+',height='+theight);
	window.onunload = cleanupWindows;
	return false;
}
function waitForMe() {
	if(!preImg.complete) {
		setTimeout(waitForMe,500);
	}
	return true;
}

window.onfocus=cleanupWindows;

function cleanupWindows() {
	if (imgWin){
		if (!imgWin.closed) {
			imgWin.close();
		}
		imgWin=null;
	}
}
