function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
}

function selectAll(aantal){ 
	for(var i = 1; i <= aantal; i++){
		document.getElementById('chk'+i).checked = true;
	}
	document.getElementById('facet_search').submit();
}

function deselectAll(aantal){
	for(var i = 1; i <= aantal; i++){
		document.getElementById('chk'+i).checked = false;
	}
	document.getElementById('facet_search').submit();
}

function setImage(nr,kaart_id){
	switch(nr){
		case 1:	//document.getElementById('krtimg').src = "kaarten/normaal/"+kaart_id+".gif";
				document.getElementById('kaart1').style.display = "block";
				document.getElementById('kaart2').style.display = "none";
				document.getElementById('kaart3').style.display = "none";
				document.getElementById('img1').style.border = "3px solid #f05b74";
				document.getElementById('img2').style.border = "3px solid #00a0c6";
				document.getElementById('img3').style.border = "3px solid #00a0c6";
				break;
		case 2:	//document.getElementById('krtimg').src = "kaarten/normaal/"+kaart_id+"_2.gif";
				document.getElementById('kaart1').style.display = "none";
				document.getElementById('kaart2').style.display = "block";
				document.getElementById('kaart3').style.display = "none";
				document.getElementById('img1').style.border = "3px solid #00a0c6";
				document.getElementById('img2').style.border = "3px solid #f05b74";
				document.getElementById('img3').style.border = "3px solid #00a0c6";
				break;
		case 3:	//document.getElementById('krtimg').src = "kaarten/normaal/"+kaart_id+"_3.gif";
				document.getElementById('kaart1').style.display = "none";
				document.getElementById('kaart2').style.display = "none";
				document.getElementById('kaart3').style.display = "block";
				document.getElementById('img1').style.border = "3px solid #00a0c6";
				document.getElementById('img2').style.border = "3px solid #00a0c6";
				document.getElementById('img3').style.border = "3px solid #f05b74";
				break;
	}
}

function load_color(color,card) {
	window.open("iframe_demokaart.php?kleur="+color, target="demoKaart");
	window.open("iframe_prijs.php?kaart="+card, target="prijs");
	window.open("iframe_prijs.php?kaart="+card, target="prijs2");
}

function load_font(font,card) {
	window.open("iframe_demokaart.php?fnaam="+font, target="demoKaart");
	window.open("iframe_prijs.php?kaart="+card, target="prijs");
	window.open("iframe_prijs.php?kaart="+card, target="prijs2");
}

function load_logo(bool){
	window.open("iframe_demokaart.php?logo="+bool, target="demoKaart");
}

function load_number(number,card,prijslaag,prijshoog) {
	if (number < 25){
		number = 25;
	}
	window.open("iframe_prijs.php?aantal="+number+"&kaart="+card, target="prijs");
	window.open("iframe_prijs.php?aantal="+number+"&kaart="+card, target="prijs2");
	/*if(number < 250){
		document.getElementById("prijsperstuk").innerHTML = prijshoog;
	}
	else {
		document.getElementById("prijsperstuk").innerHTML = prijslaag;
	}*/
	
	berekenStaatsloten(number);
}

function load_dec(dec,foto,card) {
	window.open("iframe_prijs.php?voorzijde="+dec+"&foto="+foto+"&kaart="+card, target="prijs");
	window.open("iframe_prijs.php?voorzijde="+dec+"&foto="+foto+"&kaart="+card, target="prijs2");
}

function load_goeddoel(id,card){
	window.open("iframe_prijs.php?goeddoel="+id+"&kaart="+card, target="prijs");
	window.open("iframe_prijs.php?goeddoel="+id+"&kaart="+card, target="prijs2");
}

function load_wissel(tekst,card) {
	//document.getElementById("kaartopmakenarea").style.display = "block";
	window.open("iframe_prijs.php?wisseltekst="+tekst+"&kaart="+card, target="prijs");
	window.open("iframe_prijs.php?wisseltekst="+tekst+"&kaart="+card, target="prijs2");
}

function load_aantalkleuren(aantal,card) {
	window.open("iframe_prijs.php?aantal_kleuren="+aantal+"&kaart="+card, target="prijs");
	window.open("iframe_prijs.php?aantal_kleuren="+aantal+"&kaart="+card, target="prijs2");
}

function showAantalKleuren(){
	document.getElementById("aantalkleuren").style.display = "block";
}

function hideAantalKleuren(){
	document.getElementById("aantalkleuren").style.display = "none";
}

function berekenStaatsloten(aantal){
	var tekst = "";
	if(aantal < 50){ tekst += "Geen Staatsloten"; }
	else if(aantal <= 149){ tekst += "<sup>1</sup>&frasl;<sub>5</sub> Staatslot januari 2011"; }
	else if(aantal <= 249){ tekst += "2 x <sup>1</sup>&frasl;<sub>5</sub> Staatslot januari 2011"; }
	else {
		totaal_halve_loten = Math.floor(aantal / 250);
		aantal_hele_loten = Math.floor(totaal_halve_loten / 2);
		aantal_halve_loten = totaal_halve_loten % 2;
		
		if(totaal_halve_loten == 1){ tekst += "<sup>1</sup>&frasl;<sub>2</sub> Oudejaarslot December 2010"; }
		else if(aantal_hele_loten == 1 && aantal_halve_loten == 0){ tekst += "1 Oudejaarslot December 2010"; }
		else{
			tekst += aantal_hele_loten.toString(); 
			tekst += (aantal_halve_loten != 0)?"<sup>1</sup>&frasl;<sub>2</sub> ":" "; 
			tekst +=  "Oudejaarslot"; tekst += (aantal_halve_loten == 0)?"en":""; tekst += " December 2010";
		}
	}
	document.getElementById("ontvangstaatsloten").innerHTML = tekst;
}

function close_eigen_file(){
	document.getElementById("filearea").style.display = "none";
	document.getElementById("filearea").innerHTML = document.getElementById("filearea").innerHTML;
	document.getElementById("tekstarea").style.display = "none";
}
function close_file(){
	document.getElementById("filearea").style.display = "none";
	document.getElementById("filearea").innerHTML = document.getElementById("filearea").innerHTML;
	document.getElementById("tekstarea").style.display = "block";
}
function close_eigen(){
	document.getElementById("filearea").style.display = "block";
	document.getElementById("tekstarea").style.display = "none";
}

function naarVB(tekst, taal, land, offset, limit){
	if(offset == "") offset = 1;
	if(limit == "") limit = 4;
	openVoorbeeld("", tekst, taal, land, 3, offset, limit);
}

function sluitVoorbeeld(){
	document.getElementById('helpContainer').style.display = "none";
	document.getElementById('transparent').style.display = "none";
	document.getElementById('menu4iframe').style.display = "none";
}

function openVoorbeeld(link, tekst_nr, taal, land, soort, offset, limit){
	createXMLHttpRequest();
         
    var myRandom = parseInt(Math.random() * 99999999);
    var url = "ajax/voorbeeld.php?tekst_nr=" + tekst_nr + "%26taal=" + taal + "%26land=" + land + "%26soort=" + soort + "%26offset=" + offset + "%26limit="+ limit + "%26rand=" + myRandom;

    xmlHttp.onreadystatechange = showHelpdesk;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

function showVoorbeeld() {
    // we are only interested in readyState of 4,
    // i.e. "loaded"
    if(xmlHttp.readyState == 4) {
        // if server HTTP response is "OK"
    	//alert(xmlHttp.status);
        if(xmlHttp.status == 200) {
        	// Echo de zoekresultaten
        	document.getElementById('helpContainer').style.display = "block";
        	document.getElementById('transparent').style.display = "block";
        	document.getElementById('menu4iframe').style.display = "block";
			document.getElementById('helpContainer').innerHTML = xmlHttp.responseText;
            // alert("The server said: " + xmlHttp.responseText);
        } else {
            // issue an error message for any
            // other HTTP response
            alert("An error has occurred: " + xmlHttp.statusText);
        }
    }
}

function useTekst(nr, tekst){
	document.getElementById('tekst'+nr).value = tekst;
	sluitVoorbeeld();
}

function sluitHelp(){
	document.getElementById('helpContainer').style.display = "none";
	document.getElementById('transparent').style.display = "none";
	document.getElementById('menu4iframe').style.display = "none";
}

function openHelp(section, taal, land, soort){
	createXMLHttpRequest();
         
    var myRandom = parseInt(Math.random() * 99999999);
    var url = "ajax/helpdesk.php?section=" + section + "%26taal=" + taal + "%26land=" + land + "%26soort=" + soort + "%26rand=" + myRandom;

    xmlHttp.onreadystatechange = showHelpdesk;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

function showHelpdesk() {
    // we are only interested in readyState of 4,
    // i.e. "loaded"
    if(xmlHttp.readyState == 4) {
        // if server HTTP response is "OK"
    	//alert(xmlHttp.status);
        if(xmlHttp.status == 200) {
        	// Echo de zoekresultaten
        	document.getElementById('helpContainer').style.display = "block";
        	document.getElementById('transparent').style.display = "block";
        	document.getElementById('menu4iframe').style.display = "block";
			document.getElementById('helpContainer').innerHTML = xmlHttp.responseText;
            // alert("The server said: " + xmlHttp.responseText);
        } else {
            // issue an error message for any
            // other HTTP response
            alert("An error has occurred: " + xmlHttp.statusText);
        }
    }
}

function stelVraag(link, taal, land, soort){
	createXMLHttpRequest();
         
    var vraag = document.getElementById('stelVraag').value;
    encoded = urlencode(vraag);
    
    var myRandom = parseInt(Math.random() * 99999999);
    var url = "ajax/helpdesk2.php?taal=" + taal + "%26land=" + land + "%26soort=" + soort + "%26rand=" + myRandom + "%26vraag=" + encoded;

    xmlHttp.onreadystatechange = showHelpdesk;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

function urlencode(str) {
	return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '%2b').replace(/%0D%0A/g, '%2b').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
}

function showform(){
	document.getElementById('emailform').style.display = "block";
}

function hideform(){
	document.getElementById('emailform').style.display = "none";
}

function checkForm(link, value, taal, country, errormsg){ 
	var error = false;
	if(document.getElementById('emailControlecode').value.toUpperCase() != value.toUpperCase()){
		error = true;
	}
	if(	document.getElementById('emailNaam').value == "" ||
		document.getElementById('emailBericht').value == "" ||
		document.getElementById('emailEmail').value == ""){
		error = true;
	}
	
	if(error){
		alert(errormsg);
	}
	else {
		stuurMail(link, document.getElementById('emailNaam').value, document.getElementById('emailEmail').value, document.getElementById('emailBericht').value, taal, country);
	}
}

function stuurMail(link, naam, email, bericht, taal, country){
	createXMLHttpRequest();
    
	naam_encoded = urlencode(naam);
	email_encoded = urlencode(email);
    bericht_encoded = urlencode(bericht);
  
    var myRandom = parseInt(Math.random() * 99999999);
    var url = "ajax/helpdesk3.php?naam=" + naam_encoded + "%26email=" + email_encoded + "%26rand=" + myRandom + "%26bericht=" + bericht_encoded;

    xmlHttp.onreadystatechange = function(){
    	if(xmlHttp.readyState == 4) {
            // if server HTTP response is "OK"
            if(xmlHttp.status == 200) {
            	// Echo de zoekresultaten
            	alert(xmlHttp.responseText);
            	
            	document.getElementById('emailNaam').value = "";
        		document.getElementById('emailBericht').value = "";
        		document.getElementById('emailEmail').value = "";
            }
        }
    };
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

function toonDivs(strWelkeDiv, tmpSub, tmpFieldsetOff, tmpFieldsetOn, obj, bInlineAan, bOnlyHide, totaal) {
	var arrAllDIVs = document.getElementsByTagName("div");
	var i=0;
	var  tmpYoffset;
	var div_nr = strWelkeDiv;
	strWelkeDiv = tmpSub + div_nr;
	//Eerste alles uitzetten (incl. de bijbehorende Fieldset i.g.v. tonen resultaat)
	for (i=0; i <= arrAllDIVs.length - 1; i++) {
		if ((arrAllDIVs[i].id.substr(0, tmpSub.length) == tmpSub) && tmpSub != "" ) {
			if (bOnlyHide != true ){
				document.getElementById(arrAllDIVs[i].id).style.display = 'none';
			}		
			document.getElementById(arrAllDIVs[i].id).style.visibility = 'hidden';
		}
	}
	for(i=1; i<=totaal; i++){
		document.getElementById('img_'+i).src = 'images/help_vraagteken.jpg'
		document.getElementById('vraag_'+i).style.display = 'block';
	}
	if (tmpFieldsetOff != "") {
		if (bOnlyHide != true ){
		 document.getElementById(tmpFieldsetOff).style.display = 'none';	
		}
	  document.getElementById(tmpFieldsetOff).style.visibility = 'hidden';
	}
	// En nu het juiste weer aanzetten	
	if (strWelkeDiv != "") {
		//alert(strWelkeDiv);
		if (tmpFieldsetOn != "") {
			document.getElementById(tmpFieldsetOn).style.visibility = 'visible';
			document.getElementById(tmpFieldsetOn).style.display = 'block';
		}
		document.getElementById(strWelkeDiv).style.visibility = 'visible';
		document.getElementById(strWelkeDiv).style.display = 'block';
		div = 'img_'+div_nr;
		document.getElementById(div).src = 'images/help_uitroepteken.jpg';
		document.getElementById('vraag_'+div_nr).style.display = 'none';
		if (bInlineAan==true) { 
			document.getElementById(strWelkeDiv).style.visibility = 'visible';
			document.getElementById(strWelkeDiv).style.display = 'inline';
		}	
		// Nu de helptekst naast het geklikte ? positioneren...
	}
}

function doAntwoordFaq(strWelkeDiv, totaal) {
	if (document.getElementById('antwoord_' + strWelkeDiv).style.display != 'block'){
		toonDivs(strWelkeDiv,'antwoord_','','','','','', totaal);
	} 
	else {
  		doHideFaq(totaal);
	}
}	

function doHideFaq(totaal){
	toonDivs('','antwoord_','','','','','', totaal);
}

function toon(img){
	document.getElementById("img").src = "images/" + img;
}

$(document).ready(function () {	
  $('#menu li').hover(
function () {
  //show its submenu
  $('ul', this).slideDown(100);
}, 
  function () {
//hide its submenu
$('ul', this).slideUp(100);			
  }
  );
});

function setOnbedrukt(){
	document.getElementById("kaartopmakenarea").style.display = "none";
}
