function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function hoverRecipes() {
	if (document.all&&document.getElementById) {
		recipesRoot = document.getElementById("hoverAll");
		if (recipesRoot) {
			for (i=0; i<recipesRoot.childNodes.length; i++) {
				node = recipesRoot.childNodes[i];
				if (node.nodeName=="LI") {
					node.onmouseover=function() { this.className+=" over"; }
					node.onmouseout=function() { this.className=this.className.replace(" over", ""); }
				}
			}
		}	
	}
}

function flash(){
	movieDiv = document.getElementById("flashmovie");
	if(movieDiv) {
		movie = movieDiv.title;
		var fo = new FlashObject("/flashmovieplayer/flashmovie.swf?movie="+movie, "MoviePlayer", "439", "296", "8", "#651E14");
		fo.addParam("wmode", "transparent");
		fo.write("flashmovie");
	}
}

function flash2(){
	movieDiv = document.getElementById("flashmovie2");
	if(movieDiv) {
		movie = movieDiv.title;
		var fo = new FlashObject("/flashmovieplayer/flashmovie2.swf?movie="+movie, "MoviePlayer", "360", "272", "8", "#651E14");
		fo.addParam("wmode", "transparent");
		fo.write("flashmovie2");
	}
}

function printpage() {
	var printlnk = document.getElementById("printlink");
	if(printlnk) {
		printlnk.onclick = function() {
			print();
			return false;
		}
	}
}

function fullScreenMovie(movie) {
	var fs = window.open( "/fullscreen.dhtml?movie="+movie ,
		   "FullScreenVideo", "toolbar=no,width=640,height=370"
		 + ",status=no,resizable=yes,fullscreen=no,scrollbars=no");
	fs.focus();
}	

function fullScreenMovie2(movie) {
	var fs = window.open( "/fullscreen2.dhtml?movie="+movie ,
		   "FullScreenVideo", "toolbar=no,width=500,height=410"
		 + ",status=no,resizable=yes,fullscreen=no,scrollbars=no");
	fs.focus();
}	


function doSlideShow() {
	var testlink = document.getElementById("slidelink");
	if (testlink) {
		runSlideShow();
	}	
}

function runSlideShow(){
	document.getElementById("slidelink").href = Link[j];
	document.images.SlideShow.src = preLoad[j].src;
	

	j = j + 1
	if (j > (picslength-1)) j=0
		t = setTimeout('runSlideShow()', slideShowSpeed)
}

	
function doScrollbar() {
	var scrollbar = document.getElementById("block");
	if (scrollbar) {
		$('#block').jScrollPane({showArrows:true,scrollbarWidth:15, arrowSize: 12});
	}
	var scrollbar2 = document.getElementById("block2");
	if (scrollbar2) {
		$('#block2').jScrollPane({showArrows:true,scrollbarWidth:15, arrowSize: 12, fromTop: 15, fromBottom: 5});
	}
}

function show_bigimage(url) {
	theWidth = 800;
	theHeight = 600;
	theTop = (screen.height-theHeight*1.5)/2;
	theLeft = (screen.width-theWidth)/2;
	winopts = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,copyhistory=0,width="+theWidth+",height="+theHeight+",top="+theTop+",left="+theLeft;
	smallwindow=window.open(url,"Detail",winopts);
	smallwindow.focus();
}

function imagepopups() {
	var links=document.getElementsByTagName("a");
	for(i=0;i<links.length;i++) {
		if (links[i].className.indexOf("zoomfoto") >= 0) {
			links[i].onclick=function() {
				show_bigimage(this.href);
				return false;
			}
		}
	}	
}

function ambassadors() {
	var lnk = document.getElementById("ambassadorslink");
	if (lnk) {
		lnk.onclick= function() {
			var divke = document.getElementById("countries");
			if (divke) {
				divke.style.display = "block";
			}
			return false;
		}
	}
}

var clipwidth = 630;
var scrollerspeed=2; // (larger is faster 1-10)
var pauseit=1;
var copyspeed=scrollerspeed;
var actualwidth='';
var pausespeed=(pauseit==0)? copyspeed: 0;

function initialiseScroller(){
	var scrollerContainer = document.getElementById("scrollerContainer");
	if(scrollerContainer) {
		scrollerContainer.onmouseover = function() {
			copyspeed = pausespeed;
		}
		scrollerContainer.onmouseout = function() {
			copyspeed = scrollerspeed;
		}
		var scrollerwidth = scrollerContainer.style.width;
		var scrollerheight = scrollerContainer.style.height;
	}

	var rightScroller = document.getElementById("rightScroller");
	if (rightScroller) {
		rightScroller.onmouseover = function() {
			lefttime2 = setInterval('scrollLeft()',20);
		}
		rightScroller.onmouseout = function() {
			clearTimeout(lefttime2);
		}
	}
	
	var leftScroller = document.getElementById("leftScroller");
	if (leftScroller) {
		leftScroller.onmouseover = function() {
			lefttime=setInterval('scrollRight()',20);
		}
		leftScroller.onmouseout = function() {
			clearTimeout(lefttime);
		}
	}
	
	var scroller=document.getElementById("scroller");
	if(scroller) {
		scroller.style.left="0px";
		actualwidth=scroller.offsetWidth;
	}
}
function scrollRight(){
	var scroller=document.getElementById("scroller");		
	if(scroller) {
		if (parseInt(scroller.style.left)>(actualwidth*(-1)+clipwidth)) {
			scroller.style.left=parseInt(scroller.style.left)-copyspeed+"px";
		}
	}
}
function scrollLeft(){
	var scroller=document.getElementById("scroller");
	if(scroller) {
		if (parseInt(scroller.style.left)<0) {
			scroller.style.left=parseInt(scroller.style.left)+copyspeed+"px";
		}
	}
}

function showIt() {
	var scrollwindow = document.getElementById("scroller");
	if (scrollwindow) {
		var scrollLinks = scrollwindow.getElementsByTagName("a");
		for(i=0;i<scrollLinks.length;i++) {
			scrollLinks[i].onclick=function() {
				scrollIntoView(this.href);
			}
		}
	}
}

// bij recipes, zet de breedte van iedere table op 400px en de breedte van de eerste td op 150px
function recipeTableAdjust() {
	var recipes = getElementsByClass("recipeblock");
	if(recipes) {
		for(i=0;i<recipes.length;i++) {
			var recipeTable = recipes[i].getElementsByTagName("table");
			if(recipeTable) {
				for(j=0;j<recipeTable.length;j++) {
					recipeTable[j].style.width="400px";
					var recipeTR = recipeTable[j].getElementsByTagName("tr");
					var recipeTD = recipeTR[0].getElementsByTagName("td");
					recipeTD[0].setAttribute("width","150");
				}
			}
		}
	}
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function moviescheck() {
	var form = document.wachtwoordform;
	if (form) {
		form.onsubmit = function() {
			return (validateWachtwoord(this)) ;
		}		
	}
	var form2 = document.loginform;
	if (form2) {
		form2.onsubmit = function() {
			return (validateLogin(this)) ;
		}		
	}
	var form3 = document.inscriptform;
	if (form3) {
		form3.onsubmit = function() {
			return (validateInscription(this)) ;
		}		
	}
	var lnk = document.getElementById("registermovielink");
	if(lnk) {
		lnk.onclick = function() {
			doSend();
			return false;
		}
	}
	
}

function doSend(){
	if (validateInscription(this.document.inscriptform)){
		this.document.inscriptform.submit();
	}
}

function validateInscription (form){
	var msg = "";
	var error = 0;
	var str = form.email.value;
	
	
	if (form.firm.value.length == 0){
		error++;
		msg += "\n- " + lbl_film_firm;
	}//if
	if (form.lastname.value.length == 0){
		error++;
		msg += "\n- " + lbl_film_name;
	}//if
	if (form.country.value.length == 0){
		error++;
		msg += "\n- " + lbl_film_country;
	}//if
	if(!checkemail()){
		error++;
		msg += "\n- " + lbl_film_email;
	}//if
	if (form.password.value.length == 0){
		error++;
		msg += "\n- " + lbl_film_password;
	}//if
	if(error) {
		alert(lbl_film_fillout + ": " + msg);
		return false;
	}//if
	return true ;
}

function contact() {
	var form = document.contactform;
	if (form) {
		form.onsubmit = function() {
			return (checkContact(this)) ;
		}		
	}
	var lnk = document.getElementById("contactlink2");
	if(lnk) {
		lnk.onclick = function() {
			if (checkContact(document.contactform)){
				document.contactform.submit();
			}//if
			return false;
		}
	}
	var lnk2 = document.getElementById("contactlink");
	if(lnk2) {
		lnk2.onclick = function() {
			document.contact_country_form.submit();
			return false;
		}
	}
	var lnka = document.getElementById("contactlinka");
	if(lnka) {
		lnka.onclick = function() {
			document.contact_country_form1.submit();
			return false;
		}
	}
	var lnkb = document.getElementById("contactlinkb");
	if(lnkb) {
		lnkb.onclick = function() {
			document.contact_country_form2.submit();
			return false;
		}
	}
	var lnkb = document.getElementById("contactlinkc");
	if(lnkb) {
		lnkb.onclick = function() {
			document.contact_country_form3.submit();
			return false;
		}
	}
	var lnkc = document.getElementById("contactlinkd");
	if(lnkc) {
		lnkc.onclick = function() {
			document.contact_country_form4.submit();
			return false;
		}
	}
}

function checkContact (form){
	var msg = "";
	var error = 0;
	var str = form.email.value;
	
	if(!checkemail2(str)){
		error++;
		msg += "\n- " + lbl_contact_perso_email;
	}//if
	if (form.jobtype.value.length == 0){
		error++;
		msg += "\n- " + lbl_contact_jobtype;
	}//if
	if (form.tel.value.length == 0){
		error++;
		msg += "\n- " + lbl_contact_perso_telephone;
	}//if
	if (form.country.value.length == 0){
		error++;
		msg += "\n- " + lbl_contact_perso_pays;
	}//if
	if(error) {
		alert(lbl_contact_fillout + ": " + msg);
		return false;
	}//if
	return true ;
}

function stages() {
	var form = document.registerform;
	if (form) {
		form.onsubmit = function() {
			return (checkform(this)) ;
		}		
	}
	var lnk = document.getElementById("registerlink");
	if(lnk) {
		lnk.onclick = function() {
			if (checkform(document.registerform)){
				document.registerform.submit();
			}//if
			return false;
		}
	}
}

function checkform (form){
		var msg = "";
		var error = 0;
		var str = form.email.value;
		
		if(!checkemail2(str)){
			error++;
			msg += "\n- " + lbl_stage_email;
		}//if
		if (form.firstname.value.length == 0){
			error++;
			msg += "\n- " + lbl_stage_prenom;
		}//if
		if (form.lastname.value.length == 0){
			error++;
			msg += "\n- " + lbl_stage_nom_famille;
		}//if
		if (form.company.value.length == 0){
			error++;
			msg += "\n- " + lbl_stage_societe;
		}//if
		if (form.birthdate.value.length == 0){
			error++;
			msg += "\n- " + lbl_stage_naissance;
		}//if
		if (form.nationality.value.length == 0){
			error++;
			msg += "\n- " + lbl_stage_nationalite;
		}//if
		if (form.languages.value.length == 0){
			error++;
			msg += "\n- " + lbl_stage_language;
		}//if
		if (form.gender.value.length == 0){
			error++;
			msg += "\n- " + lbl_stage_sexe;
		}//if
		if (form.address.value.length == 0){
			error++;
			msg += "\n- " + lbl_stage_adresse_perso;
		}//if
		if (form.city.value.length == 0){
			error++;
			msg += "\n- " + lbl_stage_localite;
		}//if
		if (form.postalcode.value.length == 0){
			error++;
			msg += "\n- " + lbl_stage_codepostal;
		}//if
		if (form.country.value.length == 0){
			error++;
			msg += "\n- " + lbl_stage_pays;
		}//if
		if (form.fax.value.length == 0){
			error++;
			msg += "\n- " + lbl_stage_fax;
		}//if
		if (form.tel.value.length == 0){
			error++;
			msg += "\n- " + lbl_stage_tel;
		}//if
		if (form.vat.value.length == 0){
			error++;
			msg += "\n- " + lbl_stage_tva;
		}//if
		if (form.expectations.value.length == 0){
			error++;
			msg += "\n- " + lbl_stage_attentes;
		}//if
		if(error) {
			alert(lbl_stage_form_fillout + ": " + msg);
			return false;
		}//if
		return true ;
	}

function checkemail(){
	var str=this.document.inscriptform.email.value
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str)) return true; else return false;
}//checkemail

function checkemail2(str){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str)) return true; else return false;
}//checkemail


function validateLogin(theForm) {
	if(theForm.gebruikersnaam.value=="" || theForm.wachtwoord.value=="") {
		alert(lbl_film_filloutemailandpassword);
		return false;
	}
	return true;
}

function validateWachtwoord(form) {
	var msg;
	msg = "";
	if (form.email.value == ""){
		msg += "- " + lbl_film_email + "\n";
	}
	if (msg != ""){
		msg = lbl_film_fillout +" : \n" + msg;
		alert(msg);
		return false;
	}
	return true;
}

function presse() {
	var lnk = document.getElementById("pselectButton");
	if(lnk) {
		lnk.onclick = function() {
			document.selectPress.submit();
			return false;
		}
	}
	var lnk2 = document.getElementById("psearchButton");
	if(lnk2) {
		lnk2.onclick = function() {
			document.searchPress.submit();
			return false;
		}
	}

}

var home1_offsetwidth, home2_offsetwidth,home,home2;

function do_homepage() {
	home.style.left = parseInt(home.style.left) - 1 + "px";
	home2.style.left = parseInt(home2.style.left) - 1 + "px";
	if (parseInt(home.style.left) < (home1_offsetwidth * -1)) {
		home.style.left = parseInt(home2.style.left) + home2_offsetwidth + "px";
	}
	if (parseInt(home2.style.left) < (home2_offsetwidth * -1)) {
		home2.style.left = parseInt(home.style.left) + home1_offsetwidth + "px";
	}
}

function homepage() {
	home = document.getElementById("scroller_part1");
	home2 = document.getElementById("scroller_part2");
	if(home && home2) {
		home1_offsetwidth = home.offsetWidth;
		home2_offsetwidth = home2.offsetWidth;
		home.style.left = "0px";
		home2.style.left = home1_offsetwidth + "px";
		setInterval('do_homepage()',20);
	}
}

function readMap () {
	var map, i;
	// get array of map area tags
	map=document.getElementsByTagName('area');
	for(i=0;i<map.length;i++) {
		//add onmouseover and onmouseout event functions
		map[i].onmouseover=function(){shift(this);};
		map[i].onmouseout=function(){shift(this);};
	}
}
function shift (o) {
	var mapbg, id;
	//set id  variable to the 'id' of the area on the map where the mouse is positioned
	id = o.id;
	//the master object where the image map is used in this case a clear gif with the id 'mapimg'
	mapbg = document.getElementById('mapimg');
	//if the className and the id match reset the class to the default state -or- shift the background image to the correct position by using the new class value
	if(id == mapbg.className) {
		mapbg.className='mapbase'; 
	} else {
		mapbg.className=id;
	}
}

addLoadEvent(homepage);
addLoadEvent(presse);
addLoadEvent(contact);
addLoadEvent(stages);
addLoadEvent(moviescheck);
addLoadEvent(recipeTableAdjust);
addLoadEvent(showIt);
addLoadEvent(initialiseScroller);
addLoadEvent(ambassadors);
addLoadEvent(imagepopups);	
addLoadEvent(doScrollbar);						
addLoadEvent(doSlideShow);
addLoadEvent(printpage);
addLoadEvent(flash);
addLoadEvent(flash2);
addLoadEvent(hoverRecipes);
addLoadEvent(readMap);
