// bookmark script
function CreateBookmarkLink(dn,ai,rc,wl) {
	url = dn;
	title = "MovieMAX - Thuis film kijken is eenvoudig!";   
	
	if (ai!="") {
		url=url+"?ai="+ai;
		if (rc!="") {
			url=url+"&refcode="+rc;
		}
		if (wl!="") {
			title = "Thuis film kijken is eenvoudig!";   	
			url=url+"&version="+wl;
		}
	}

	if (window.sidebar) { 	// Mozilla Firefox Bookmark	
		window.sidebar.addPanel(title, url,"");	
	}
	else if( window.external ) { // IE Favorite		
		window.external.AddFavorite(url,title)
	}	
} 

// show MSN presence
function showpresence(presence)
{
  if(presence.statusText == 'Online'){
	if(document.getElementById("msnchat")){
		document.getElementById("msnchat").style.display = "inline";
	}
	if(document.getElementById("msnchattop")) {
		document.getElementById("msnchattop").style.display = "inline";
	}
  }
  else {
	if(document.getElementById("msnchatoffline")){
		document.getElementById("msnchatoffline").style.display = "inline";
	}
  }
}

//open popups
function popups(pwidth, pheight, url, scrollbars) {
	var left = (window.screen.width/2 - pwidth/2);
	var top = (screen.height/2 - pheight/2);
	newwindow=window.open(''+url+'','','width='+pwidth+',height='+pheight+',left='+left+',top='+top+',scrollbars='+scrollbars+',dependent=yes,alwaysRaised=1');
}


//detect browser
var detect = navigator.userAgent.toLowerCase();  
var OS,browser,version,total,thestring;    

if (checkIt('konqueror'))  {   
	browser = "Konqueror";   
	OS = "Linux";  
}  
else if (checkIt('safari')) 
	browser = "Safari";  
else if (checkIt('omniweb')) 
	browser = "OmniWeb";  
else if (checkIt('opera')) 
	browser = "Opera";  
else if (checkIt('webtv')) 
	browser = "WebTV";  
else if (checkIt('icab')) 
	browser = "iCab";  
else if (checkIt('msie')) 
	browser = "Internet Explorer";  
else if (!checkIt('compatible'))  {   
	browser = "Netscape Navigator";   
	version = detect.charAt(8);  
}  
else browser = "An unknown browser";    

if (!version) version = detect.charAt(place + thestring.length);    if (!OS)  {   if (checkIt('linux')) OS = "Linux";   else if (checkIt('x11')) OS = "Unix";   else if (checkIt('mac')) OS = "Mac";   else if (checkIt('win')) OS = "Windows";   else OS = "an unknown operating system";  }    function checkIt(string)  {   place = detect.indexOf(string) + 1;   thestring = string;   return place;  }  

// creating cookies for favorites
function createCookie(name,value,days) {
		var x = readCookie(name)
		if (x) {
			x = x+","+value;
			arr_value = x.split(",");
			arr_value = unique(arr_value);
			for (var i = 0; i < arr_value.length; i++) {
				if(i == 0){
				value = arr_value[i];
				}
				else{
				value = value+","+arr_value[i];
				}
			} 
		}
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
		if (days !== -1){
			if (name == 'favorites'){
				alert("Deze film is toegevoegd aan je favorieten!");
				}
			else if (name == 'favoritetrailers'){
				alert("Deze trailer is toegevoegd aan je favorieten!");
				}
			else if (name == 'favoritewebcams'){
				alert("Dit model is toegevoegd aan je favorieten!");
				}
			else if (name == 'blockedwebcams'){
				alert("Dit model wordt niet meer getoond!");
				location.reload(true);
				}
			else {
				}
		}
}
	
function changeCookie(name,value,days) {
		var x = readCookie(name)
		if (x) {
			arr_value = x.split(",");
			arr_value = unique(arr_value);
			deleteitem = value;
			$a = 0;
			for (var i = 0; i < arr_value.length; i++) {
					if (arr_value[i] == deleteitem){
						//verwijder
					}
					else{
							if($a == 0){
							value = arr_value[i];
							}
							else{
							value = value+","+arr_value[i];
							}
							$a++;
					}
			} 
		}
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
		if (arr_value.length == 1) {
			eraseCookie(name);
		}
		location.reload(true);
}
	
function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
}
	
function eraseCookie(name) {
		createCookie(name,"",-1);
}

// part of cookie script
function unique(a) {
		tmp = new Array(0);
		for(i=0;i<a.length;i++){
			if(!contains(tmp, a[i])){
				tmp.length+=1;
				tmp[tmp.length-1]=a[i];
			}
		}
		return tmp;
}

// part of cookie script
function contains(a, e) {
		for(j=0;j<a.length;j++)if(a[j]==e)return true;
		return false;
}
	
/////////enkel betaalscherm

function toTop(){
		if (parent) parent.location.hash = '#';
}

// general check if numbers are present in form field
function checkForNumbers(naampje) {
		var nummer = 0;
		for (i=0;i<naampje.length;i++) {
			if (!isNaN(naampje.charAt(i)) && naampje.charAt(i)!=" ") {
				nummer = 1;
			}
		}
		return nummer;
}

// wis de standaard tekst in invoervelden
function clearDefault(el) {
	  if (el.defaultValue==el.value) el.value = ""
}

// validate review
function validate(){
		var form = document.forms.reviewForm;
		var radio = form.rating;
		for (var i=0;i<radio.length;i++)
		{
			if (radio[i].checked)
			var checked = true;
		}
		if(checked == true)
		{
			return true;
		}
		else
		{
			alert('Je dient bij een review tenminste een cijfer te geven.');
			return false;
	
		}
}

// show active channel in topmenu
function myCurrent(wat, subject) {
	//f_banner(wat,subject);		
		if (wat == "klantenservice"){ 
			if (subject == "faq") {
				document.getElementById('faq').style.display="block";
			}
			if (subject == "pctv" || subject == "mce" || subject == "pczapper" || subject == "doehetzelf" || subject == "draadloos") {
				document.getElementById('pctv').style.display="block";
			}
			if (subject == "mijngegevens" || subject == "dezemaand" || subject == "facturen" || subject == "persoonsgegevens" || subject == "abonnementen") {
				document.getElementById('mijngegevens').style.display="block";
			}
		}
}

// check on toegangscodevergeten page
function checkPincodeForm() {

	doorgaan = true;
	var str=document.submitform.emailadres.value;
	var filter=/^.+@.+\..{2,3}$/;

	if (document.submitform.emailadres.value == '') {
		doorgaan = false;
		var foutmelding = "Er is geen e-mailadres ingevuld";
		document.submitform.emailadres.focus();
	} else if (!filter.test(str)) {
		doorgaan = false;
		var foutmelding = "Er is geen geldig e-mailadres ingevoerd.";
		document.submitform.emailadres.value = '';
		document.submitform.emailadres.focus();
	}

	if (doorgaan == true) {
		return true;
	}else {
		alert(foutmelding);
		return false;
	}	
}

// check 'mijn gegevens' form
function checkMijngegevensForm() {
		doorgaan = "true";
	
		//straatnaam check
		if (document.displayform.straatnaam.value.length>0 && checkForNumbers(document.displayform.straatnaam.value)) {
			doorgaan = "false";
			foutmelding = "Straatnaam mag geen cijfers bevatten.";
			document.displayform.straatnaam.focus();
		}else if (document.displayform.straatnaam.value.length>0 && document.displayform.straatnaam.value.length<2) {
			doorgaan = "false";
			foutmelding = "Een straatnaam heeft minimaal 2 karakters.";
			document.displayform.straatnaam.focus();
		//huisnummer check
		}else if (document.displayform.huisnummer.value.length>0 && isNaN(document.displayform.huisnummer.value)) {
			doorgaan = "false";
			foutmelding = "Een huisnummer mag alleen bestaan uit cijfers.";
			document.displayform.huisnummer.focus();
		//telefoonnummer check
		}else if (document.displayform.woonplaats.value.length>0 && checkForNumbers(document.displayform.woonplaats.value)) {
			doorgaan = "false";
			foutmelding = "Een woonplaats mag geen cijfers bevatten.";
			document.displayform.woonplaats.focus();
		}else if (document.displayform.woonplaats.value.length>0 && document.displayform.woonplaats.value.length<2) {
			doorgaan = "false";
			foutmelding = "Een woonplaats heeft minimaal 2 karakters.";
			document.displayform.woonplaats.focus();
		}else if (document.displayform.telefoonnummer.value.length>0 && isNaN(document.displayform.telefoonnummer.value)){
			doorgaan = "false";
			foutmelding = "Een telefoonnummer mag alleen uit cijfers bestaan.";
			document.displayform.telefoonnummer.focus();
		}else if (isNaN(document.displayform.newpin.value.charAt(0)) || isNaN(document.displayform.newpin.value.charAt(1)) || isNaN(document.displayform.newpin.value.charAt(2)) || isNaN(document.displayform.newpin.value.charAt(3))){
			doorgaan = "false";
			foutmelding = "De toegangscode dient uit 4 cijfers te bestaan.";
			document.displayform.newpin.value = '';
			document.displayform.newpincheck.value = '';
			document.displayform.newpin.focus()
		}else if(document.displayform.newpin.value.length>0 && document.displayform.newpin.value.length < 4) {
			doorgaan = "false";
			foutmelding = "De toegangscode dient uit 4 cijfers te bestaan.";
			document.displayform.newpin.value = '';
			document.displayform.newpincheck.value = '';
			document.displayform.newpin.focus()
		}else if(document.displayform.newpin.value != document.displayform.newpincheck.value) {
			doorgaan = "false";
			foutmelding = "De ingevoerde toegangscodes zijn niet gelijk. Voer beide opnieuw in.";
			document.displayform.newpin.value = '';
			document.displayform.newpincheck.value = '';
			document.displayform.newpin.focus();
		}
		//onderscheid NL en BE
		if (document.displayform.land.value == ""){
			doorgaan = "false";
			foutmelding = "Er is geen land ingevuld.";
		}
		if (document.displayform.land.value == "België"){
			if (document.displayform.postcode.value.length>0 && (isNaN(document.displayform.postcode.value))){
				doorgaan = "false";
				foutmelding = "Er is geen nummerieke postcode ingevuld.";
				document.displayform.postcode.focus();
			}else if (document.displayform.postcode.value.length<4 || document.displayform.postcode.value.length>4) {
				doorgaan = "false";
				foutmelding = "Een postcode bestaat uit 4 cijfers.";
				document.displayform.postcode.focus();
			}else if (document.displayform.telefoonnummer.value.length>0 && document.displayform.telefoonnummer.value.length<9){
				doorgaan = "false";
				foutmelding = "Een telefoonnummer moet uit 9 of 10 cijfers bestaan.";
				document.displayform.telefoonnummer.focus();
			}
		}
		else{
			//postcode check
			if (document.displayform.postcode.value.length>0 && document.displayform.postcode.value.length<6) {
				doorgaan = "false";
				foutmelding = "Een postcode heeft 6 posities.";
				document.displayform.postcode.focus();
			}else if (document.displayform.postcode.value.length>0 && (isNaN(document.displayform.postcode.value.charAt(0)) || isNaN(document.displayform.postcode.value.charAt(1)) || isNaN(document.displayform.postcode.value.charAt(2)) || isNaN(document.displayform.postcode.value.charAt(3)) || !isNaN(document.displayform.postcode.value.charAt(4)) || !isNaN(document.displayform.postcode.value.charAt(5)))){
				doorgaan = "false";
				foutmelding = "Een postcode mag alleen bestaan uit vier cijfers gevolgd door twee letters.";
				document.displayform.postcode.focus();
			}else if (document.displayform.telefoonnummer.value.length>0){
				if  (document.displayform.telefoonnummer.value.length<10){
					doorgaan = "false";
					foutmelding = "Een telefoonnummer moet uit 10 cijfers bestaan.";
					document.displayform.telefoonnummer.focus();
				}else if ((document.displayform.telefoonnummer.value.substr(0,4) == "0900") || (document.displayform.telefoonnummer.value.substr(0,4) == "0906") || (document.displayform.telefoonnummer.value.substr(0,4) == "0909")) {
					doorgaan = "false";
					foutmelding = "Het opgegeven telefoonnummer is niet toegestaan.";
					document.displayform.telefoonnummer.focus();
				}else if (document.displayform.telefoonnummer.value.substr(0,1) != "0") {
					doorgaan = "false";
					foutmelding = "Een telefoonnummer moet met een 0 beginnen";
					document.displayform.telefoonnummer.focus();
				}else if (document.displayform.telefoonnummer.value.substr(0,2) == "00") {
					doorgaan = "false";
					foutmelding = "Een telefoonnummer mag niet met 00 beginnen";
					document.displayform.telefoonnummer.focus();
				}
			}
		}
		if (doorgaan=="true") {
			return true;
		}else {
			alert(foutmelding);
			return false;
		}	
}

function checkPostcalCode() {
	doorgaan = "true";
		
	if (isNaN(document.displayform.postcode.value)){
		doorgaan = "false";
		foutmelding = "Er is geen nummerieke postcode ingevuld.";
		document.displayform.postcode.focus();
	}else if (document.displayform.postcode.value.length<4 || document.displayform.postcode.value.length>4) {
		doorgaan = "false";
		foutmelding = "Voer enkel de 4 cijfers van de postcode in";
		document.displayform.postcode.focus();
	}else if (parseInt(document.displayform.postcode.value) < 1000) {
		doorgaan = "false";
		foutmelding = "Voer een geldige postcode in";
		document.displayform.postcode.focus();		
	}

	if (doorgaan=="true") {
		return true;
	}else {
		alert(foutmelding);
		return false;
	}	
}

// Slideshow in details page start

var slideshow2_noFading = false;
var slideshow2_timeBetweenSlides = 3000;	// Amount of time between each image(1000 = 1 second)
var slideshow2_fadingSpeed = 10;	// Speed of fading	(Lower value = faster)
	
var slideshow2_galleryContainer;	// Reference to the gallery div
var slideshow2_galleryWidth;	// Width of gallery
var slideshow2_galleryHeight;	// Height of galery
var slideshow2_slideIndex = -1;	// Index of current image shown
var slideshow2_slideIndexNext = false;	// Index of next image shown
var slideshow2_imageDivs = new Array();	// Array of image divs(Created dynamically)
var slideshow2_currentOpacity = 100;	// Initial opacity
var slideshow2_imagesInGallery = false;	// Number of images in gallery
var Opera = navigator.userAgent.indexOf('Opera')>=0?true:false;

function createParentDivs(imageIndex){
	if(imageIndex==slideshow2_imagesInGallery){			
			showGallery();
	}else{
		var imgObj = document.getElementById('galleryImage' + imageIndex);	
		if(Opera)imgObj.style.position = 'static';
		slideshow2_imageDivs[slideshow2_imageDivs.length] =  imgObj;
		imgObj.style.visibility = 'hidden';	
		imageIndex++;
		createParentDivs(imageIndex);	
	}		
}
	
function showGallery(){
	if(slideshow2_slideIndex==-1)slideshow2_slideIndex=0; else slideshow2_slideIndex++;	// Index of next image to show
	if(slideshow2_slideIndex==slideshow2_imageDivs.length)slideshow2_slideIndex=0;
	slideshow2_slideIndexNext = slideshow2_slideIndex+1;	// Index of the next next image
	if(slideshow2_slideIndexNext==slideshow2_imageDivs.length)slideshow2_slideIndexNext = 0;
	slideshow2_currentOpacity=100;	// Reset current opacity
	// Displaying image divs
	slideshow2_imageDivs[slideshow2_slideIndex].style.visibility = 'visible';
	if(Opera)slideshow2_imageDivs[slideshow2_slideIndex].style.display = 'inline';
	if(navigator.userAgent.indexOf('Opera')<0){
		slideshow2_imageDivs[slideshow2_slideIndexNext].style.visibility = 'visible';
	}
	if(document.all){	// IE rules
		slideshow2_imageDivs[slideshow2_slideIndex].style.filter = 'alpha(opacity=100)';
		slideshow2_imageDivs[slideshow2_slideIndexNext].style.filter = 'alpha(opacity=1)';
	}else{
		slideshow2_imageDivs[slideshow2_slideIndex].style.opacity = 0.99;	// Can't use 1 and 0 because of screen flickering in FF
		slideshow2_imageDivs[slideshow2_slideIndexNext].style.opacity = 0.01;
	}		
	setTimeout('revealImage()',slideshow2_timeBetweenSlides);		
}
	
function revealImage(){
	if(slideshow2_noFading){
		slideshow2_imageDivs[slideshow2_slideIndex].style.visibility = 'hidden';
		if(Opera)slideshow2_imageDivs[slideshow2_slideIndex].style.display = 'none';
		showGallery();
		return;
	}
	slideshow2_currentOpacity--;
	if(document.all){
		slideshow2_imageDivs[slideshow2_slideIndex].style.filter = 'alpha(opacity='+slideshow2_currentOpacity+')';
		slideshow2_imageDivs[slideshow2_slideIndexNext].style.filter = 'alpha(opacity='+(100-slideshow2_currentOpacity)+')';
	}else{
		slideshow2_imageDivs[slideshow2_slideIndex].style.opacity = Math.max(0.01,slideshow2_currentOpacity/100);	// Can't use 1 and 0 because of screen flickering in FF
		slideshow2_imageDivs[slideshow2_slideIndexNext].style.opacity = Math.min(0.99,(1 - (slideshow2_currentOpacity/100)));
	}
	if(slideshow2_currentOpacity>0){
		setTimeout('revealImage()',slideshow2_fadingSpeed);
	}else{
		slideshow2_imageDivs[slideshow2_slideIndex].style.visibility = 'hidden';	
		if(Opera)slideshow2_imageDivs[slideshow2_slideIndex].style.display = 'none';		
		showGallery();
	}
}
	
function initImageGallery(){
	slideshow2_galleryContainer = document.getElementById('imageSlideshowHolder');
	slideshow2_galleryWidth = slideshow2_galleryContainer.clientWidth;
	slideshow2_galleryHeight = slideshow2_galleryContainer.clientHeight;
	galleryImgArray = slideshow2_galleryContainer.getElementsByTagName('IMG');
	for(var no=0;no<galleryImgArray.length;no++){
		galleryImgArray[no].id = 'galleryImage' + no;
	}
	slideshow2_imagesInGallery = galleryImgArray.length;
	createParentDivs(0);		
}

// Slideshow in details page stop

function trim(inputString) {

	if (typeof inputString != "string") {
		return inputString;
	}
	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	while (ch == " ") { // Check for spaces at the beginning of the string
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length-1, retValue.length);
	while (ch == " ") { // Check for spaces at the end of the string
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
	while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
		retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
	}
	return retValue; // Return the trimmed string back to the user
}

	// show png images in IE6 or lower
	function replaceImgpng(img, id){
		if (browser == "Internet Explorer"){ 
		which= img;
		if (id){ which = img + id;}
		document.getElementById(which).src = "/images/blank.gif"; 
		document.getElementById(which).style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/" + img + ".png', sizingMethod='image')"; 
		}
	}

	// less pretty, but needed for some starratings, because no unique ID is present
	function replaceImg(url,target,img,imgblank,title,align,valign){
		if(url){
			document.write('<a href="'+url+'" target="'+target+'">');
		}
			if (browser == "Internet Explorer"){   
				document.write("<img src=\"/images/"+imgblank+"\" alt=\""+title+"\" title=\""+title+"\" border=\"0\" align=\""+align+"\" valign=\""+valign+"\" style=\"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/"+img+"', sizingMethod='image');\" >");  
			}  
			else {   
				document.write('<img src="/images/'+img+'" alt="'+title+'" title="'+title+'" border="0" align="'+align+'" valign="'+valign+'" />');  
			}  
		if(url){
			document.write('</a>');
		}
	
	
	}