function borderRequest(sub_id, product_id, product_afbeelding, item_id, afwerking, afwerking_prijs) {
	var oScript = document.createElement("script");
	oScript.text = "loadLytebox1('" + sub_id + "_" + product_id + "_" + item_id + "_" + afwerking + "_opties_link','lytebox'); document.getElementById('" + sub_id + "_" + product_id + "_img').src = '../img/collection/" + product_afbeelding + "'; document.getElementById('" + sub_id + "_" + product_id + "_" + item_id + "_prijs').innerHTML = '&euro; " + afwerking_prijs + "&nbsp;&nbsp;';";		
	document.body.appendChild(oScript);		
}

function artikelenRequest(type) {
	var oScript = document.createElement("script");
	var aantal = document.getElementById('aantal_artikelen').innerHTML;
	if(aantal.substr(0,3)=="<a>"){
			aantal = aantal.substr(3);
	}
	if(aantal.substr(aantal.length-4,4)=="</a>"){
			aantal = aantal.substr(0,aantal.length-4);
	}
	if(type=='add'){
		aantal = parseInt(aantal) + 1;
	}else{
		aantal = parseInt(aantal) - 1;	
	}
	oScript.text = "document.getElementById('aantal_artikelen').innerHTML = '" + aantal + "';";		
	document.body.appendChild(oScript);	
}

function calculatorRequest(item_id, sub_id, product_id, product_afbeelding) {
	var oScript = document.createElement("script");
	oScript.text = "loadLytebox1('" + item_id + "_calculator_link','lyteframe'); document.getElementById('" + sub_id + '_' + product_id + "_img').src = '../img/collection/" + product_afbeelding + "';";		
	document.body.appendChild(oScript);				
}
	
var timeoutID1 = null;
function loadLytebox1(id, lytetype) {
    if (typeof myLytebox != 'undefined') {
        // if the myLytebox object exists, start it up!
				if(lytetype=="lytebox"){
        	myLytebox.start(document.getElementById(id));
				} else if(lytetype=="lyteslide"){
        	myLytebox.start(document.getElementById(id), true);
				} else if(lytetype=="lyteframe"){
        	myLytebox.start(document.getElementById(id), false, true);
				}
    } else {
        // wait 1/10th of a second and attempt loading again...
        if (timeoutID1) { clearTimeout(timeoutID1); }
        timeoutID1 = setTimeout('loadLytebox1("'+id+'","'+lytetype+'")', 100);
    }
}

var xmlhttp;

function loadXMLDoc(url, element, prijscal)
{
xmlhttp=null;
if (window.XMLHttpRequest)
  {// code for Firefox, Opera, IE7, etc.
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlhttp!=null)
  {
  xmlhttp.onreadystatechange  = function(){ 
		if (xmlhttp.readyState==4){// 4 = "loaded"
			if (xmlhttp.status==200){// 200 = "OK"
				
				if(prijscal=='ja'){
					window.location.href = '../tuinmeubelen/prijscalculatie.php';
				}else{
					document.getElementById(element).innerHTML=xmlhttp.responseText;
					myLytebox.updateLyteboxItems();
				}
				
			} else {
			alert("Problem retrieving data:" + xmlhttp.statusText);
			}
		}
	};
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }
}

function loadXMLDoc2(url, element, postcode, land)
{
xmlhttp=null;
if (window.XMLHttpRequest)
  {// code for Firefox, Opera, IE7, etc.
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlhttp!=null)
  {
  xmlhttp.onreadystatechange  = function(){ 
		if (xmlhttp.readyState==4){// 4 = "loaded"
			if (xmlhttp.status==200){// 200 = "OK"
				document.getElementById(element).innerHTML=xmlhttp.responseText;
				if(postcode!=''&&land!=''){
					if((postcode.length!=6 && postcode.length!=7) && land=='nederland'){
						alert("Vul een geldige Nederlandse postcode in (bv. 1234AA).");
					}else if(postcode.length!=4 && land=='belgie'){
						alert("Vul een geldige Belgische postcode in (bv. 1234).");
					}else if(postcode.length!=5 && land=='duitsland'){
						alert("Bitte geben Sie eine g" + unescape("%FC") + "ltige Postleitzahl ein (z.B. 12345)");
					}else{
						bereken_punt(postcode, land);
					}
				}
			} else {
			alert("Problem retrieving data:" + xmlhttp.statusText);
			}
		}
	};
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }
}

function bereken_punt(postcode, land) {      
                      
	geocoder = new GClientGeocoder()

	geocoder.getLocations (
		postcode + ', ' + land,
		function(result) {
			bezorgkosten = 0;
			if(result.Status.code == G_GEO_SUCCESS && postcode !='' && land !='') {
				//delay = 0;
				var p = result.Placemark[0].Point.coordinates;
				
				lat1 = p[1];
				lng1 = p[0];
				
				
				lat2 = '51.608799';
				lng2 = '5.51309';
				
				coor1 = lat1+","+lng1;
				coor2 = lat2+","+lng2;
				
				
			
				var directions = new GDirections;
        directions.loadFromWaypoints( [coor1,coor2],{ "locale": "nl", "getPolyline":true, "getSteps":false, "preserveViewport": true} );
        GEvent.addListener(directions, "load", function() {
            var distance = directions.getDistance().meters/1000;	
						if(distance<=53.5){
							bezorgkosten = formatCurrency('40');					
						}else{
							var km = distance*0.75;
							bezorgkosten = formatCurrency(km);	
						}
						document.getElementById('afstand').innerHTML='&euro; '+bezorgkosten+',00';
						document.contact.bezorgkosten.value=bezorgkosten+',00';

						var totaalprijs = document.getElementById('totaalprijs_hidden').innerHTML;   
                totaalprijs = totaalprijs.replace(/\./,""); 
                totaalprijs = totaalprijs.replace(/\,/,".");     
                totaalprijs = parseFloat(totaalprijs)+parseFloat(bezorgkosten);  
						    totaalprijs = totaalprijs.toFixed(2);  
						
            if(totaalprijs>=10000 && totaalprijs<100000){							
							totaalprijs1 = totaalprijs.substr(0,2)
							totaalprijs2 = totaalprijs.substr(2)
							totaalprijs2 = totaalprijs2.replace(/\./,",");
							
							totaalprijs = totaalprijs1 + '.' + totaalprijs2;
						}else if(totaalprijs>=1000 && totaalprijs<10000){							
							totaalprijs1 = totaalprijs.substr(0,1)
							totaalprijs2 = totaalprijs.substr(1)
							totaalprijs2 = totaalprijs2.replace(/\./,",");
							
							totaalprijs = totaalprijs1 + '.' + totaalprijs2;
						}else{				
							totaalprijs = String(totaalprijs);								
							totaalprijs = totaalprijs.replace(/\./,",");
						}                                                
						document.getElementById('totaalprijs').innerHTML='&euro; ' + totaalprijs;
						document.contact.totaalprijs.value=totaalprijs;

				});				
			} else {

				if(document.getElementById('afstand')!=null){
					document.getElementById('afstand').innerHTML='';
				}
				if(document.contact!=null){
					document.contact.bezorgkosten.value='';
				}
                                                                                  
        var totaalprijs = document.getElementById('totaalprijs_hidden').innerHTML; 
            totaalprijs = totaalprijs.replace(/\./,"");   
            totaalprijs = totaalprijs.replace(/\,/,".");   
            totaalprijs = parseFloat(totaalprijs);  
            totaalprijs = totaalprijs.toFixed(2);
				if(totaalprijs>=10000 && totaalprijs<100000){							
					totaalprijs1 = totaalprijs.substr(0,2)
					totaalprijs2 = totaalprijs.substr(2)
					totaalprijs2 = totaalprijs2.replace(/\./,",");
					
					totaalprijs = totaalprijs1 + '.' + totaalprijs2;
				}else if(totaalprijs>=1000 && totaalprijs<10000){							
					totaalprijs1 = totaalprijs.substr(0,1)
					totaalprijs2 = totaalprijs.substr(1)
					totaalprijs2 = totaalprijs2.replace(/\./,",");
					
					totaalprijs = totaalprijs1 + '.' + totaalprijs2;
				}else{				
					totaalprijs = String(totaalprijs);								
					totaalprijs = totaalprijs.replace(/\./,",");
				}                    
				                                                                           
				document.getElementById('totaalprijs').innerHTML='&euro; ' + totaalprijs;
				if(document.contact!=null){
					document.contact.totaalprijs.value=totaalprijs;
				}
			}


		}
	);
}	

function formatCurrency(strValue)
{
	strValue = strValue.toString().replace(/\$|\,/g,'');
	dblValue = parseFloat(strValue);

	blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	dblValue = Math.floor(dblValue*100+0.50000000001);
	intCents = dblValue%100;
	strCents = intCents.toString();
	dblValue = Math.floor(dblValue/100).toString();
	if(intCents<10)
		strCents = "0" + strCents;
	for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
		dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+dblValue.substring(dblValue.length-(4*i+3));
		
		dblValue_tmp = Math.round(dblValue*0.1)/0.1;
		restant = dblValue-dblValue_tmp;
		if(restant>=2.5){
			dblValue = dblValue_tmp + 5
		} else if(restant<=-2.5){
			dblValue = dblValue_tmp - 5
		} else {
			dblValue = dblValue_tmp;			
		}
		
		if(dblValue>=10000 && dblValue<100000 ){
			
		}
		
	return (((blnSign)?'':'-') + dblValue);
}

function left_menu_over(div, nr) {
	div.style.backgroundImage = 'url(../img/style/menuleft/2' + nr + '_act.jpg)';
}

function left_menu_out(div) {
	div.style.backgroundImage = '';
}

function bezorgAdres(div){
	if(div.checked==true){
		document.getElementById('bezorgadres_bezorgen2').style.display = '';
		if(document.getElementById('bezorgadres_ophalen2')){
			document.getElementById('bezorgadres_ophalen2').style.display = 'none';
			//document.getElementById('bezorgadres_bezorgen1').style.display = '';
			//document.getElementById('bezorgadres_ophalen1').style.display = 'none';
		}
	}else{
		document.getElementById('bezorgadres_bezorgen2').style.display = 'none';
		if(document.getElementById('bezorgadres_ophalen2')){
			document.getElementById('bezorgadres_ophalen2').style.display = '';
			//document.getElementById('bezorgadres_bezorgen1').style.display = 'none';
			//document.getElementById('bezorgadres_ophalen1').style.display = '';
		}
	}
}

function left_menu_over(div, nr) {
	div.style.backgroundImage = 'url(../img/style/menuleft/2' + nr + '_act.jpg)';
}

function left_menu_out(div) {
	div.style.backgroundImage = '';
}

function product_info_over(div) {	
	div.style.backgroundImage = 'url(../img/style/product_head_active.gif)';
}

function product_info_out(div, selected) {
	if(selected=="sel"){
		div.style.backgroundImage = 'url(../img/style/product_head_sel.gif)';
	}else{
		div.style.backgroundImage = '';		
	}
}

function rand_over(div, sub_id, product_id, image, item_id, price) { 
	document.getElementById(sub_id + '_' + product_id + '_img').src = '../img/opties/' + image + '.jpg';
	document.getElementById(sub_id + '_' + product_id + '_' + item_id +'_prijs').innerHTML = price;
	div.style.backgroundColor = "#5D98D6";
}

function rand_out(div, sub_id, product_id, image, item_id, price, sel) {
	document.getElementById(sub_id + '_' + product_id +'_img').src = '../img/collection/' + image;
	document.getElementById(sub_id + '_' + product_id + '_' + item_id +'_prijs').innerHTML = price;
	
	if(sel=='sel'){
		div.style.backgroundColor = "#5D98D6";		
	} else {
		div.style.backgroundColor = "#A9C9EA";
	}
}

function calculator_over(div, sub_id, product_id, type, language) { 
	if(type=='add'){
	div.style.backgroundImage='url(../img/style/calculator_add_active.gif)';
	document.getElementById(sub_id + '_' + product_id +'_img').src = '../img/style/add_' + language + '.png';
	}else{
	div.style.backgroundImage='url(../img/style/calculator_del_active.gif)';
	document.getElementById(sub_id + '_' + product_id +'_img').src = '../img/style/del_' + language + '.png';		
	}
}

function calculator_out(div, sub_id, product_id, image, type) {
	if(type=='add'){
		div.style.backgroundImage='url(../img/style/calculator_add.gif)';
	}else{
		div.style.backgroundImage='url(../img/style/calculator_add_active.gif)';
	}
	document.getElementById(sub_id + '_' + product_id +'_img').src = '../img/collection/' + image;
}

function chairprop_over(sub_id, product_id, chair) {   
  document.getElementById(sub_id + '_' + product_id +'_img').src = '../img/style/stoelmaten/' + chair + '.jpg';
}

function chairprop_out(sub_id, product_id, image) {
  document.getElementById(sub_id + '_' + product_id +'_img').src = '../img/collection/' + image + '.jpg';
}

function getAddress() {
document.aanvraag.address2.value	= document.aanvraag.address1.value;
document.aanvraag.pc2.value 		= document.aanvraag.pc1.value;
document.aanvraag.location2.value	= document.aanvraag.location1.value;
}

function frameCatching()
{
    // zorgt ervoor dat de pagina niet gevangen zit in een ander frame
    if(parent.frames.length!=0) window.top.location.replace(document.location.href);
}




/*
  De functie telt hoeveel tekens er nog in het betreffende tekstvak 
  mogen worden geplaatst.
  veld = Het veld waarin de tekens worden geplaatst.
  telveld = Het veld dat weergeeft hoeveel tekens er over zijn.
  maximum = Het maximum aantal tekens dat in het tekstvak geplaatst mogen worden geplaatst.
*/
function tekstteller(veld,telveld,maximum) 
{
	if (veld.value.length > maximum) 
		veld.value 		= veld.value.substring(0, maximum);
	else
		telveld.value 	= maximum - veld.value.length;

}



/*
	De functie zorgt ervoor dat de gebruiker een popup scherm ziet met
	daarin de actie te bevestigen.
	bericht = Een vraag aan de gebruiker over bevestiging.
	url = De url die verschijnt na bevestiging.
*/
function bevestig_popup(bericht, url)
{ 
    var bevestigd = confirm(bericht);
    if (bevestigd)
       location = url;
} 

/*
	De functie zorgt ervoor dat het informatieveld altijd zichtbaar
	blijft voor de gebruiker, ook al scrollt de gebruiker helemaal 
	naar beneden.
*/
var old = 0;
function initScroller() 
{
	var old = theTop;
	moveHelpbox(); 
} 

/*
	De functies hieronder tussen START AFBEELDINGSFUNCTIES en EINDE AFBEELDINGSFUNCTIES
	zorgen ervoor dat er een vergrote afbeelding verschijnt als de gebruiker over
	de kleine versie van de afbeelding met de muis beweegt.
	
	START AFBEELDINGSFUNCTIES
*/

// nagaan welk type navigator de gebruiker heeft
var bName = navigator.appName;
var bVer = parseInt(navigator.appVersion);
var NS6 = (bName == "Netscape" && bVer >= 5);
var NS4 = (bName == "Netscape" && bVer >= 4 && bVer < 5);
var IE4 = (bName == "Microsoft Internet Explorer" && bVer >= 4);
var NS3 = (bName == "Netscape" && bVer < 4);
var IE3 = (bName == "Microsoft Internet Explorer" && bVer < 4);
window.onerror = null;
var menuActive = 0
var menuOn = 0
var onLayer
var timeOn = null
 
// nagaan welke code moet worden gebruikt i.v.m. verschillende navigatoren 
if (NS4 || IE4 || NS6) {
	if (navigator.appName == "Netscape" && !document.getElementById){
		layerStyleRef="layer.";
		layerRef="document.layers";
		styleSwitch="";
		layerVis="show";
		layerHid="hide";
	}
	else if (!document.all && document.getElementById) {
		layerStyleRef="layer.style.";
		layerRef="document.getElementById";
		styleSwitch=".style";
		layerVis="visible";
		layerHid="hidden";
	}
	else {
		layerStyleRef="layer.style.";
		layerRef="document.all";
		styleSwitch=".style";
		layerVis="visible";
		layerHid="hidden";
	}
}