var resized = "false";
var pop = null;

function contact() {
	var str = "mailto:"
	str += "contact";
	str += String.fromCharCode(8 * 8);
	str += "peptalks";
	str += ".";
	str += "nl";
	document.location = str;
	return;
}

function duolijstWissel(lijst, selectnaam, enkelekeuze) {
//alert("wissel: " + lijst);
	var van, vanlijst;
	var naar, naarlijst;
	var naam = selectnaam.split("_");
	var naarjalijst = false;
	

	if (naam[1] == "nee") {
		naarjalijst = true;
		vanlijst = document.forms[lijst].elements[naam[0] + "_nee"];
		naarlijst = document.forms[lijst].elements[naam[0]];
	} else {
		vanlijst = document.forms[lijst].elements[naam[0]];
		naarlijst = document.forms[lijst].elements[naam[0] + "_nee"];
	}

	//eerst nieuwe element uit vanlijst weghalen en parkeren in optXXX
	idx = vanlijst.selectedIndex;
	var opttxt = vanlijst.options[idx].text;
	var optval = vanlijst.options[idx].value;
	verwijderUitSelectOptions(vanlijst.options, idx);

	if ((enkelekeuze == "true") && (naarjalijst) && (naarlijst.options.length > 0)) { // element uit jalijst halen en in vanlijst terugstoppen
		voegInInSelectOptions(vanlijst.options, naarlijst.options[0].text, naarlijst.options[0].value);
		verwijderUitSelectOptions(naarlijst.options, 0);
	}

 	voegInInSelectOptions(naarlijst.options, opttxt, optval);

}

function getStory(id) {
	getHetApplet("boek").getStory(id);
}

function getLosArtikel(id) {
	var app = getHetApplet("boek");
	if (app != navigator.plugins) {
		app.getStory(id);
	}
}

function getArtikel(id) {
	var app = getHetApplet("boek");
	if (app != navigator.plugins) {
		app.getStory(id);
		lijst.show("lijst", false);
		lijst.show("boek", true);
	}
}

function getArtikellijst() {
	lijst.show("boek", false);
	getSet("lijst", -1, 0);
}

function getArtikelVanGodLos(id) {
	var app = getHetApplet("boek");
	if (app != navigator.plugins) {
		app.getStory(id);
		lijst.show("txt", false);
		lijst.show("boek", true);
	}
}

function getArtikelOverOns(id) {
	var app = getHetApplet("boek");
	if (app != navigator.plugins) {
		app.getStory(id);
		for (i = 0; i < 3; i++) lijst.show("lijst" + i, false);
		lijst.show("boek", true);
	}
}

function getBasispagina() {
	lijst.show("boek", false);
	lijst.show("txt", true);
}


function getOveronsTeksten() {
	lijst.show("boek", false);
	for (i = 0; i < 3; i++) getSet("lijst" + i, -1, 0);
}

function getXYvanHetApplet() {
//dit is een stoplap voor Locator in BoekApplet, om het MSIE6- probleem met de achtergrond op te lossen
	obj = alsObjekt("applet_boek");
	return obj.left + ";" + obj.top;
}

function getHetApplet(naam) {
 	if (navigator.platform == "MacPPC") {
		hetapplet = window.document.boek;
		if (hetapplet.toString().indexOf("BookApplet") >= 0) return hetapplet;
		else {
			alert("Sorry, Applegebruiker.\nHet archief is met uw OS/browsercombinatie niet toegankelijk.\nHet gaat in elk geval wel met Safari vanaf versie 1.2.2 met OSX1.3.4. en Java plugin 1.4.2");
			return navigator.plugins;
		}
	} else if (typeof document.layers != "undefined") {
		return document.layers["applet"].document.applets[naam]
	} else if (typeof document.all != "undefined") {
		return document.all[naam];
	} else if (typeof document.getElementsByName != "undefined") {
		return document.getElementsByName(naam)[0];
	} else {
		alert("Uw browser is te oud of te exotisch");
		return navigator.plugins;
	}
}

function getSet(reeksnaam, interval, intervallengte) {
	lijst.runInterval(reeksnaam, interval, intervallengte);
}

function sluitPop() {
	if (pop !=null) {
		if (navigator.platform != "MacPPC") { //stomme mac wil geen close-operatie ondersteunen
			pop.close();
			pop = null;
		}
	}
}

function openPop(titel) {
	var w = 550;
	var h = 100;
	var x = (screen.availWidth / 2)- (w / 2);
	var y = (screen.availHeight /2) - (h / 2); 
	var features = "screenX=" + x + ",screenY=" + y + ",width=" + w + ",height=" + h;
	features = features + ",dependent=yes,directories=no,menubar=no,titlebar=no,toolbar=no,scrollbars=no,resizable=no,location=no,status=no";
	if (pop != null) {
		pop.close();
		pop = null;
	}

	pop = window.open("","pop",features);
	pop.moveTo(x,y);

	pop.document.write("<html><head>");
	pop.document.write("<title>");
	pop.document.write(titel);
	pop.document.write("</title><style>");
	pop.document.write("body {color: #000088; font-size: 12px; font-weight: normal; font-family: Verdana, Lucida, Arial, Helvetica, sans-serif;} input {font-size: 12px; font-family: Verdana, Arial; height: 22px;}</style>");
	pop.document.write("</style><script language='Javascript'>function website(url){window.open(url,'extra','menubar=no,scrollbars=yes,resizable=yes,status=no,width=780,height=540');}</script></head><body bgcolor='#FFFFFF'>");
}

function popLinktekst(spec) {
	pop.document.write("<center>Kopieer onderstaande link:<br><br><font color=black>");
	pop.document.write("&lt;a href=\"http://www.peptalks.nl/index.jsp?");
	pop.document.write(spec);
	pop.document.write("\"&gt; UW LINKTEKST &lt;/a&gt;<br><br><input type='button' value='sluiten' onClick='window.close()'>");
	pop.document.write("</body></html>");
}

function linkNaarPagina(naam) {
	openPop("Peptalks: link naar pagina");
	popLinktekst("linkpag=" + naam);
}

function linkNaarArtikel() {
	openPop("Peptalks: link naar artikel");
	popLinktekst("linkart=" + getHetApplet("boek").getArtikelId());
}

function linkNaarBestellen(adresbol, adresbruna) {
	openPop("Peptalks: bestellen");
	popBesteltekst(adresbol, adresbruna);
}

function popBesteltekst(adresbol, adresbruna) {
	pop.document.write("Bestellen bij:<center>");
	pop.document.write("<a href=\"javascript:website('");
	pop.document.write(adresbol);
	pop.document.write("')\">Bol.com</a><br>");
	pop.document.write("<a href=\"javascript:website('");
	pop.document.write(adresbruna);
	pop.document.write("')\">Bruna</a><br>");
	pop.document.write("<br><input type='button' value='sluiten' onClick='window.close()'>");
	pop.document.write("</body></html>");

}

function naarArt(id) {
	setHidden("peptalks", "forward", "dieplink");
	setHidden("peptalks", "rubriek", id);
	document.forms["peptalks"].submit();
}

function naarPag(pagina) {
	var elementen = pagina.split(";");
	setHidden("peptalks", "forward", elementen[0]);
	if (elementen.length > 1) setHidden("peptalks", "rubriek", elementen[1]);
	document.forms["peptalks"].submit();
}

function naarTaal(pagina) {
	setHidden("peptalks", "taal", pagina);
	document.forms["peptalks"].submit();
}

function prepareerSubmit(formulier, element, waarde) {
	setHidden(formulier, element, waarde);
	elms = document.forms[formulier].elements;
	for (i = 0; i < elms.length; i++) {
		if ((elms[i].type == "select-one") || (elms[i].type == "select-multiple")) {
			len = elms[i].name.length;
			if ((len > 7) && (elms[i].name.substring(0,7) == "dlijst-") && (elms[i].name.substring(len - 4, len) != "_nee")) {
				for (j = 0; j < elms[i].options.length; j++) elms[i].options[j].selected = true;
			} 
		}
	}
} 

function resizeBrowser() {
	if (resized = "false") {
	 	if ((navigator.platform != "MacPPC") || (navigator.appName != "Microsoft Internet Explorer")) {
			h = Math.min(768, screen.availHeight);
			w = Math.min(1024, screen.availWidth);
			x = Math.floor((screen.availWidth - w) / 2);
			y = Math.floor((screen.availHeight - h) / 2);
			window.moveTo(x,y);
			window.resizeTo(w,h);
		}
		resized = "true";
	}
}

function setForward(formulier, waarde) {
	document.forms[formulier].elements["forward"].value = waarde;
}

function setHidden(formulier, element, waarde) {
	document.forms[formulier].elements[element].value = waarde;
}

function verwijderUitSelectOptions(sopt, idx) {
	for (i = idx; i < sopt.length - 1; i++) {
		sopt[i] = new Option(sopt[i + 1].text, sopt[i + 1].value);
	}
	sopt[sopt.length - 1] = null;
}

function voegInInSelectOptions(sopt, tekst, waarde) {
	sopt[sopt.length] = new Option("dummy","dummy");
	idx = sopt.length - 2;
	while ((idx >= 0) && (sopt[idx].text > tekst)) {
		sopt[idx + 1] = new Option(sopt[idx].text, sopt[idx].value);
		idx--;
	}
	sopt[idx + 1] = new Option(tekst, waarde);
}

function website(url){
	window.open(url,"extra","menubar=no,scrollbars=yes,resizable=yes,status=no,width=780,height=540");
}

function pdfvenster(url){
	window.open(url,"LetterKunst","menubar=no,scrollbars=yes,location=no,toolbar=no,status=no,resizable=yes,width=780,height=540");
}
