// -- JavaScript Library

// - search form check
function checkForm(f)
{	
	if (f.wilwoord.value.replace(/ /g,"") == ""){		
		f.wilwoord.value = "";
		alert ("Vult u a.u.b. een zoekterm in");
		f.wilwoord.focus();
	} else {				
		f.keywords.value = '"' + f.wilwoord.value + '"';
		f.submit();
	}
}


// - browserCheck
function browserCheck()
{
	if (parseInt(navigator.appVersion) >= 4) {
		if (navigator.appName == "Netscape") return "NS";
		if (navigator.appName.indexOf("Microsoft") != -1) return "IE";
	} 
}


// - Quicktime plugin check, plugin must be > 6 for the MP4 format
function QuickTimePluginCheck()
{
	var browser;
	var i_quicktime = false;
	var v_quicktime = 0;

	if (document.all) {
		browser = "Microsoft Internet Explorer";
	}else if (document.layers) {
		browser = "Netscape Communicator";
	}else if (document.getElementById) {
		browser = "Netscape 6 or higher";
	}else {
		browser = "unknown";
	}

	var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;

	if(isIE && isWin){
		v_quicktime = -1;

		document.writeln('<SCR'+ 'IPT LANGUAGE=VBScript\> \n');

	    document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
	    document.writeln('detectableWithVB = False');
	    document.writeln('If ScriptEngineMajorVersion >= 2 then');
	    document.writeln('  detectableWithVB = True');
	    document.writeln('End If');

	    document.writeln('\'this next function will detect most plugins');
	    document.writeln('Function detectActiveXControl(activeXControlName)');
	    document.writeln('  on error resume next');
	    document.writeln('  detectActiveXControl = False');
	    document.writeln('  If detectableWithVB Then');
	    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
	    document.writeln('  End If');
	    document.writeln('End Function');

	    document.writeln('\'and the following function handles QuickTime');
	    document.writeln('Function detectQuickTimeActiveXControl()');
	    document.writeln('   on error resume next');
	    document.writeln('   detectQuickTimeActiveXControl = False');
	    document.writeln('   If detectableWithVB Then');
	    document.writeln('      detectQuickTimeActiveXControl = False');
	    document.writeln('      hasQuickTimeChecker = false');
	    document.writeln('      Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
	    document.writeln('      If IsObject(hasQuickTimeChecker) Then');
	    document.writeln('         i_quicktime = IsObject.IsQuickTimeAvailable(0)');
		// Helaas, de versie wordt hier niet doorgegeven, werkt niet ...
//		document.writeln('         v_quicktime = hex(IsObject.QuickTimeVersion)');
	    document.writeln('      End If');
	    document.writeln('   End If');
	    document.writeln('End Function');

	    document.writeln('</scr'+ 'ipt>');
		return v_quicktime;
	}


	if (browser=="Netscape Communicator" || browser=="Netscape 6 or higher") {
		for(i=0; i<navigator.plugins.length; i++) {

			if (navigator.plugins[i].name.indexOf("QuickTime") >= 0) {
				var ValidChars = "0123456789";
				var IsNumber=true;
				var Char;
				v_quicktime = navigator.plugins[i].name;
				//v_quicktime = "sfdasdfasdf versie 5.1";
				for(i=0; i<v_quicktime.length;i++){
			    	Char = v_quicktime.charAt(i);
			  		if (ValidChars.indexOf(Char) == -1){
			        	IsNumber = false;
					}else if (Char < 6) {
						return v_quicktime;
					}else{
						return 0;
					}
				}
			}
		}
	}
}


// -- Open Window in popup
function openWindow(URL, width, height, scroll)
{
	var winl = (screen.width - width) / 2;
	var wint = (screen.height - height) / 2;
	var naam = new Date();
	naam = naam.getTime();
	var winop = window.open(URL, naam, "width="+width+", height="+height+", top=" +wint+ ", left=" +winl+ ", resizable=yes, scrollbars="+scroll+", menubar=no, toolbar=no, directories=no, location=no, status=0", false);
}


// -- Rollover
function changeImages() {
	d = document;
	if (d.images) {
		var img;
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			img = null;
			if (d.layers) {img = findElement(changeImages.arguments[i],0);}
			else {img = d.images[changeImages.arguments[i]];}
			if (img) {img.src = changeImages.arguments[i+1];}
		}
	}
}


// -- Return from popup
function CSClickReturn ()
{
	var bAgent = window.navigator.userAgent; 
	var bAppName = window.navigator.appName;
	if ((bAppName.indexOf("Explorer") >= 0) && (bAgent.indexOf("Mozilla/3") >= 0) && (bAgent.indexOf("Mac") >= 0))
		return true; // dont follow link
	else return false; // dont follow link
}


var clockTimer;
// -- Play een geluidsfragment
function playIt(anObj, secVan, secTot)
{
	var i = anObj.GetTime();
	if (i < secTot-secVan) i = secVan;
	startAtTime(anObj, i, secVan, secTot);
	document.playerform.start.value="";
}


// -- Stop een geluidsfragment
function stopIt(anObj)
{
	anObj.Stop();
	window.clearTimeout(clockTimer);
}


// -- Start op een ingegeven tijdspunt
function startAtTime(anObj, tijdstip, secVan, secTot)
{
	anObj.Stop();
	anObj.SetTime(tijdstip);
	anObj.Play();
	window.clearTimeout(clockTimer);
	clock(tijdstip, 1, secVan, secTot);
}


// -- Spoel terug
function playBack(anObj, field, secVan, secTot)
{
	window.clearTimeout(clockTimer)
	var i = anObj.GetTime() - (field * 600);
	if (i < secVan) i = secVan;
	startAtTime(anObj, i, secVan, secTot);
}


// -- Spoel vooruit
function playForward(anObj, field, secVan, secTot)
{
	window.clearTimeout(clockTimer)
	//get seconds (* number of units of time per second in the movie = int GetTimeScale() = 600)
	var i = anObj.GetTime() + (field * 600);
	if (i >= secTot) i = secTot;
	startAtTime(anObj, i, secVan, secTot);
}

// -- Klok
function clock(tijdstip, ind, secVan, secTot)
{
	if (ind > 0){
		//aangeroepen van buiten deze functie
		tijdstip = tijdstip - secVan;
	}
	//get seconds (= divide by number of units of time per second in the movie = int GetTimeScale() = 600)
	waarde = parseInt(tijdstip/600);
	//Get hours
	hours = parseInt(((waarde)/60)/60);
	if (hours > 0) {
		waarde = waarde - (hours*3600);
	}
	minutes = parseInt((waarde)/60);
	//Get minute
	if (minutes > 0) {
		waarde = waarde - (minutes*60);
	}
	//Rest = seconds
	seconds = parseInt(waarde);

	var t = new Date();
	var h = t.getHours() - (t.getHours() - hours);
	var m = t.getMinutes() - (t.getMinutes() - minutes);
	var s = t.getSeconds() - (t.getSeconds() - seconds);

	if (m < 10) m = "0" + m;
	if (s < 10) s = "0" + s;
	document.playerform.time.value = h + ":" + m + ":" + s + " " + status;

	hours = (hours*3600);
	minutes = (minutes*60);
	seconds = seconds;
	tijdstip = (hours + minutes + seconds)*600;

	tijdstip = parseInt(tijdstip) + 600;

	// -- Check of het einde van het verhaal al bereikt is, zo ja STOP
	if (tijdstip > secTot-secVan){
		stopIt(document.verhaal);
	} else {
		clockTimer = window.setTimeout("clock(" +tijdstip+ ",-1," +secVan+ "," +secTot+ ")", 1000);
	}
}


// -- Convert dbTime to starttime at embedding a document
function convertTime(tijdstip)
{
	//get seconds (= divide by number of units of time per second in the movie = int GetTimeScale() = 600)
	waarde = tijdstip/600;
	//Get hours
	hours = parseInt(((waarde)/60)/60);
	if (hours > 0) {
		waarde = waarde - (hours*3600);
	}
	minutes = parseInt((waarde)/60);
	//Get minute
	if (minutes > 0) {
		waarde = waarde - (minutes*60);
	}
	//Rest = seconds
	seconds = parseInt(waarde);
	return hours + ":" + minutes + ":" + seconds + ":0";
}


// -- Toonindex pagina
function zoek(wat, waarde)
{
	//create sql statement
	switch (wat) {
		case "trefwoord" :
			var	sql = "SELECT ID, beschrijving FROM trefwoord order by beschrijving";
			break;
		case "collectie" :
			var	sql = "SELECT ID, naam FROM project WHERE type = 2 order by naam";
			break;
		case "project" :
			var	sql = "SELECT ID, naam FROM project WHERE type = 1 order by naam";
			break;
		case "plaats" :
			var	sql = "SELECT ID, plaats from lijst_plaatsverhaal ORDER BY plaats";
			break;
		case "periode" :
			var sql = "SELECT waarde FROM invoerlijst WHERE tabel = 'verhaal' AND veld = 'periode' ORDER BY waarde" ;
			break;
		case "reporter" :
			var	sql = "SELECT ID, CONCAT(voornaam, \" \", achternaam) as 'naam' from persoon WHERE rol=2 and actief = 1 ORDER BY achternaam";
			break;
		case "verteller" :
			var	sql = "SELECT ID, CONCAT(voornaam, \" \", achternaam) as 'naam' from persoon WHERE rol=8 and actief = 1 ORDER BY achternaam";
			break;
	}

	openWindow("../popups/list.php?sql=" +escape(sql)+ "&mode=" +wat, 400, 500, "yes")
}

// EOF
