function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function LTrim(str) {
	if (str.length == 0) {return str};
	intSpaceFound = str.indexOf(" ");
	while (intSpaceFound == 0 ) {
		str = str.substring(1,str.length);
		intSpaceFound = str.indexOf(" ");
	}	
	return str;
}

function RTrim(str) {
	if (str.length == 0) {return str};
	intSpaceFound = str.lastIndexOf(" ");
	while (intSpaceFound > 0 && intSpaceFound == str.length - 1) {
		str = str.substring(0,str.length - 1);
		intSpaceFound = str.lastIndexOf(" ");
	}	
	return str;
}

function Trim(str) {
	str = LTrim(str);
	str = RTrim(str);
	return str;
}


function OpenSmallWindow(url,width,height,windowname) {
	Features = "toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,width=" + width + ",height=" + height + ",resizable=yes"
	eval(windowname+'=window.open("'+url+'","'+windowname+'","'+Features+'");');
}


function sluit(){
	this.window.close();
}


function GetShortMonthName(dtDate) {
	strDate = dtDate.toString();
	arrSplitDate = strDate.split(' ');
	strMontName = arrSplitDate[1];
	return strMontName;
}


function LongYear(nr) {
	intLongYear = nr;
	if (nr < 100) {intLongYear = 1900 + nr;}
	dtTest = new Date(2000,0,1);
	if (dtTest.getYear() == 100 ){intLongYear = 1900 + nr;}
	return intLongYear;
}


function show(ima, nr){
	for (i=0;i<nr;i++){
		document.getElementById(i).style.display = "none";
	}
	document.getElementById(ima).style.display = "";
}


function checkFormTAF(path){

	if (document.forms[0].taal.value == "nl"){
		
			//--- NL teksten
			var tx1 = "Vul s.v.p. een geldig email adres in";
			var tx2 = "Vul s.v.p. uw naam in";
			var tx3 = "Vul s.v.p. een onderwerp in";
	}else{
	
			//--- EN teksten	
			var tx1 = "Please enter a valid e-mail address";
			var tx2 = "Please enter name";
			var tx3 = "Please enter a mail subject";
	}

	if (!emailCheck(document.forms[0].emailS.value)){
			alert(tx1);
			document.forms[0].emailS.focus();
			return false;
		}

		if (Trim(document.forms[0].naam.value) == "") {
			alert(tx2);
			document.forms[0].naam.focus();
			return false;
		}

		if (Trim(document.forms[0].onderwerp.value) == "") {
			alert(tx3);
			document.forms[0].onderwerp.focus();
			return false;
		}

		//--- aparte email check
		if (!emailCheck(document.forms[0].emailR.value)){
			alert (tx1);
			document.forms[0].emailR.focus();
			return false;
		}

		sendRequestTAF(path);
}


function _sendRequestTAF(path) {

	var oForm = document.forms[0];
	oForm.action = path+ "/aj_tellafriend.php";
	var sBody = getRequestBody(oForm);
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("post", oForm.action, true);
	oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	oXmlHttp.send(sBody);
	hideLayer('lay_tellafriend');
	showLayer('lay_thanks');
	
}


function getRequestBody(oForm) {

		var aParams = new Array();
		for (var i=0 ; i < oForm.elements.length; i++) {
			var sParam = encodeURIComponent(oForm.elements[i].name);
			sParam += "=";
			sParam += encodeURIComponent(oForm.elements[i].value);
			aParams.push(sParam);
		}
		return aParams.join("&");
}


function sendRequestTAF(path) {

	var oForm = document.forms[0];
	oForm.action = path+ "/aj_tellafriend.php";
alert(oForm.action);
	oForm.submit();
}


function zelfde(){
	if (document.forms[0].same.checked){
			document.forms[0].Dnaam.value = document.forms[0].Inaam.value;
			document.forms[0].Dadres.value = document.forms[0].Iadres.value;
			document.forms[0].Dplaats.value = document.forms[0].Iplaats.value;
			document.forms[0].Dpc.value = document.forms[0].Ipc.value;
			document.forms[0].Dland.selectedIndex = document.forms[0].Iland.selectedIndex;
			document.forms[0].Dtelefoon.value = document.forms[0].Itelefoon.value;

			//--- update verzendkosten
			if (document.forms[0].Dland.selectedIndex > 0) sendRequest();
	}
}



function FRMafh(){
	if (!document.forms[1].afhalen.checked){
			document.forms[1].afhalen.value = 0;
	}
	if (!document.forms[1].korting.checked){
			document.forms[1].korting.value = 0;
	}
	document.forms[1].action = "cash.php";
	document.forms[1].submit();
}



function emailCheck(email){

	// email check
	if (email.value == ""){
			return false;
	}else{
		var temp     = email;
		var AtSym    = temp.indexOf('@');
		var Period   = temp.lastIndexOf('.')
		var Space    = temp.indexOf(' ')
		var Length   = temp.length - 1   // Array is from 0 to length-1

		if ((AtSym < 1) ||                  // '@' cannot be in first position
			(Period <= AtSym+2) ||            // Must be atleast one valid char btwn '@' and '.'
			(Period == Length ) ||            // Must be atleast one valid char after '.'
			(Space  != -1))                   // No empty spaces permitted
			{
				return false;
			}
	}
	return true;
}


function checkEmailIndex(email){
	if (!emailCheck(email)){
		alert ("Vul a.u.b. een geldig e-mail adres in");
		document.forms[0].email.focus();
		return false;
	}
	return true;
}


function submitForm(jump, action){
	document.forms[0].jumpto.value = jump;
	document.forms[0].action = action;
	document.forms[0].submit();
}


function delfrom(itemid){
	document.forms[0].delitemid.value = itemid;
	document.forms[0].action = "cash.php";
	document.forms[0].submit();
}


function resolutie(){
	var h = screen.height;
	if (h > 770 && h < 1000){
			document.write("<div style='width:100%;height:40px'><br /></div>");
	}else if (h >= 1000 && h < 1200){
			document.write("<div style='width:100%;height:90px'><br /></div>");	
	}else if (h >= 1200){
			document.write("<div style='width:100%;height:110px'><br /></div>");	
	}
}


function opacity(id, opacStart, opacEnd, millisec) {
    //--- speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //--- determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//--- change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}


function next(hide, show){

	if (String(hide).length > 0){
			var Hlayer = "L" +hide;
			hideLayer(Hlayer);
		}
	var Slayer = "L" +show;
	showLayer(Slayer);
	
	if (parseInt(show) > 0){
			var ima = "ima" +show;
			opacity(ima, 0, 100, 800);
			opacity("bot", 0, 50, 0);
	}else{
			opacity("bot", 0, 100, 0);
	}
}
