
function open_window(link,w,h) //opens new window
{
	var win = "width="+w+",height="+h+",menubar=no,location=no,scrollbars=no";
	newWin = window.open(link,'newWin',win);
	newWin.focus();
}
function open_window2(link,w,h) //opens new window
{
	var win = "width="+w+",height="+h+",menubar=no,location=no,scrollbars=no,resizable=Allow";
	newWin = window.open(link,'newWin',win);
	newWin.focus();
}
function check(vraag,locatie)
{
  if(confirm(vraag))
  {
  document.location.href=locatie;
  }
}
function toonmenu(elmnt)
{
	document.all(elmnt).style.visibility="visible";
}
function verstopmenu(elmnt)
{
	document.all(elmnt).style.visibility="hidden";
}

function newImage(arg) 
{
	if (document.images) 
	{
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() 
{
	if (document.images) 
	{
		for (var i=0; i<changeImages.arguments.length; i+=2) 
		{
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

// version: beta
// created: 2005-08-30
// updated: 2005-08-31
// mredkj.com
//http://www.mredkj.com/tutorials/validate2.html
function extractNumber(obj, decimalPlaces, allowNegative)
{
	var temp = obj.value;
	
	// avoid changing things if already formatted correctly
	var reg0Str = '[0-9]*';
	if (decimalPlaces > 0) {
		reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
	} else if (decimalPlaces < 0) {
		reg0Str += '\\.?[0-9]*';
	}
	reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
	reg0Str = reg0Str + '$';
	var reg0 = new RegExp(reg0Str);
	if (reg0.test(temp)) return true;

	// first replace all non numbers
	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
	var reg1 = new RegExp(reg1Str, 'g');
	temp = temp.replace(reg1, '');

	if (allowNegative) {
		// replace extra negative
		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		var reg2 = /-/g;
		temp = temp.replace(reg2, '');
		if (hasNegative) temp = '-' + temp;
	}
	
	if (decimalPlaces != 0) {
		var reg3 = /\./g;
		var reg3Array = reg3.exec(temp);
		if (reg3Array != null) {
			// keep only first occurrence of .
			//  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
			reg3Right = reg3Right.replace(reg3, '');
			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
		}
	}
	
	obj.value = temp;
}

function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}


/////



	// ==================================
	// General JavaScript functions
	// ==================================
	// (c) EasyApps
	// ==================================


	var isNS = 0;
	var isNS4 = 0;
	var isIE = 0;
	var isIE4 = 0;
	var isIE5 = 0;
	var isOP = 0;
	var isKONQ = 0;
	var isSAF = 0;
	var isFF = 0;
	var isIE5mac = 0;
	var isIE5win = 0;
	var isWin = 0;
	var isMac = 0;
	var isLin = 0;

	var d, dom;
	
	d = document;
	n = navigator;
	na = n.appVersion.toLowerCase();
	nua = n.userAgent.toLowerCase(); 

	isWin = ( na.indexOf( 'win' ) != -1 );
	isMac = ( na.indexOf( 'mac' ) != -1 );
	isLin = ( nua.indexOf( 'linux' ) != -1 );
	
	if ( !d.layers ){
		dom = ( d.getElementById );
		isOP = ( nua.indexOf( 'opera' ) != -1 );
		isKONQ = ( nua.indexOf( 'konqueror' ) != -1 );
		isSAF = ( nua.indexOf( 'safari' ) != -1 );
		isFF = ( nua.indexOf( 'gecko' ) != -1 && !isSAF && !isKONQ);
		isIE = ( d.all && !isOP );
		isIE4 = ( isIE && !dom );
	
		/*
		ie5x tests only for functionality. ( dom||ie5x ) would be default settings. 
		Opera will register true in this test if set to identify as IE 5
		*/
	
		isIE5 = ( d.all && dom );
		isIE5mac = ( isMac && isIE5 );
		isIE5win = ( isWin && isIE5 );
	}
	


	function openPictureWindowURL(URL, w, h) {

		w = 860; // 760;
		h = 670; // 760;
		// ************************************************************************************************************************************************
		// w += 32;
		// h += 96;
		
		wleft = (screen.width - w) / 2;
		wtop = (screen.height - h) / 2;
		
		var win = window.open(URL, name, 'width=' + w + ', height=' + h + ', ' + 'left=' + wleft + ', top=' + wtop + ', ' + 'location=no, menubar=no, ' +  'status=no, toolbar=no, scrollbars=no, resizable=no');
		
		// Just in case width and height are ignored
		win.resizeTo(w, h);
		
		// Just in case left and top are ignored
		win.moveTo(wleft, wtop);
		
		win.focus();
		
	}

	
	function openLocationPopUp(intMessageId) {
		locationPopUp = window.open("/site/index.php?page=locationpopup&intMessageId="+intMessageId, 'locationPopUp','width=1, height=1, toolbar = 0,scrolling = yes,scrollbars = yes,directories = no,menubar = no,location = no,resizable = yes,personalbar = no,status = yes');
	}



	function findPosX(obj) {
		var curleft = 0;
		if (obj.offsetParent) 	{
			while (obj.offsetParent) {
				curleft += obj.offsetLeft;
				obj = obj.offsetParent;
			}
		} else if (obj.x) {
			curleft += obj.x;
		}
		return curleft +'px';
	}

	function findPosY(obj) {
		var curtop = 0;
		if (obj.offsetParent) 	{
			while (obj.offsetParent) {
				curtop += obj.offsetTop;
				obj = obj.offsetParent;
			}
		} else if (obj.x) {
			curtop += obj.x;
		}
		return curtop+'px';
	}

	function checkEmail(str) {
		return (/^[a-zA-Z0-9_\.-]+@[a-zA-Z0-9_\.-]+\.(\w{2,4})+$/.test(str));
	}

	function HighlightAll(theField) {
		var tempval=eval(theField);
		tempval.focus();
		tempval.select();
		if (document.all){
			therange=tempval.createTextRange();
			therange.execCommand("Copy");
			// alert("De berichttekst wordt nu voor de veiligheid ook gekopieerd naar het klembord.\nToets CTRL-V om het bericht eventueel in een document te plakken.");
			//window.status="Contents highlighted and copied to clipboard!";
			//setTimeout("window.status=''",2400);
		}
	}
	function rnd() {
			rnd.seed = (rnd.seed*9301+49297) % 233280;
			return rnd.seed/(233280.0);
	};

	function rand(number) {
			return Math.ceil(rnd()*number);
	};


	function ss(w){window.status=w;return true;}
	function cs(){window.status='';}



	function setSelect(id, val) {
	  for(index = 0; index < $(id).length; index++) {
	   if($(id)[index].value == val)
	     $(id).selectedIndex = index;
	   }
	}			
	
	function checkAllCheckBoxes(FormName, FieldName, val) {


		if(!document.forms[FormName]) {
			return;
		}

		
		var objCheckBoxes = document.forms[FormName].elements[FieldName];
		if(!objCheckBoxes) {
			return;
			
		}
		var countCheckBoxes = objCheckBoxes.length;
		
		
		if(!countCheckBoxes)
			objCheckBoxes.checked = val;
		else
			// set the check value for all check boxes
			for(var i = 0; i < countCheckBoxes; i++)
				objCheckBoxes[i].checked = val;
		

	}
	


	function isHTML(string) {
		var a = string.split(/<[^>]+>/g); 
		if (a.length>1) {
			return true;
		} else {
			return false;
		}
	}
	
	function isBBMarkup(string) {
		var a = string.split(/\[[^\]]+\]/g); 
		if (a.length>1) {
			return true;
		} else {
			return false;
		}
	}
		
		
	function resizeTextarea(t) {
		a = t.value.split('\n');
		b=1;
		for (x=0;x < a.length; x++) {
		 if (a[x].length >= t.cols) b+= Math.floor(a[x].length/t.cols);
		 }
		b+= a.length;
		if (b > t.rows && nua.indexOf('opera') == -1) t.rows = b;
	}	

	function checkMinMax(FormName, FieldName, intMin, intMax) 
	{
		val = 0;
		if(!document.forms[FormName]) {
			return;
		}
		var objCheckBoxes = document.forms[FormName].elements[FieldName];
		if(!objCheckBoxes)
			return;
		var countCheckBoxes = objCheckBoxes.length;
		
		if(!countCheckBoxes)
			val=0;
		else
			// set the check value for all check boxes
			for(var i = 0; i < countCheckBoxes; i++)
				if (objCheckBoxes[i].checked) val++;
			
		if ((intMin==0 || val>=intMin) && (intMax==0 || val<=intMax)) {
			return true;
		}
	}
	
	function getCookie(name) {
	  var cookies = document.cookie;
	  var start = cookies.indexOf(name + '=');
	  if (start == -1) return null;
	  var len = start + name.length + 1;
	  var end = cookies.indexOf(';',len);
	  if (end == -1) end = cookies.length;
	  return unescape(cookies.substring(len,end));
	}
	
	function setCookie(name, value, expires, path, domain, secure) {
	  value = escape(value);
	  expires = (expires) ? ';expires=' + expires.toGMTString() :'';
	  path    = (path)    ? ';path='    + path                  :'';
	  domain  = (domain)  ? ';domain='  + domain                :'';
	  secure  = (secure)  ? ';secure'                           :'';
	
	  document.cookie =
	    name + '=' + value + expires + path + domain + secure;
	}
	
	function deleteCookie(name, path, domain) {
	  var expires = ';expires=Thu, 01-Jan-70 00:00:01 GMT';
	  (path)    ? ';path='    + path                  : '';
	  (domain)  ? ';domain='  + domain                : '';
	
	  if (getCookie(name))
	    document.cookie = name + '=' + expires + path + domain;
	}
	
	function isCookieEnabled() {
	  if (document.all) {
	    if (!navigator.cookieEnabled) {
	      return false;
	    }
	    else return true;
	  }
	  else {
	    setCookie('temp','temp');
	    var temp = getCookie('temp');
	    if (!temp) {
	      return false;
	    }
	    else return true;
	  }
	}
	
	function setCoords(intX, intY) {
		// cursor verplaatsen naar 
		document.getElementById('cursorLayer').style.left = document.getElementById('mapLayer').offsetLeft + intX - 30; // - X-correctie voor afbeelding
		document.getElementById('cursorLayer').style.top = document.getElementById('mapLayer').offsetTop + intY - 60; // - Y-correctie voor afbeelding
	
		// ev. nog verborgen cursor weergeven 
		document.getElementById('cursorLayer').style.display = 'inline';
	
		return;
	}
	

	
	function reportAjaxError() {
		alert('Javascript-Ajax-error');
	}

	function changeTab(objTab, boolWide)
	{
		var extraCss = boolWide?"_wide":"";
		intMaxTabs = 5; // Maximum amount of tabs in document (sorry, don't know a better way to calculate)
		arrStr = objTab.id.toString().split("_");
		if (arrStr[0] == "tabHeader" && arrStr.length == 3)
		{		
			for (i=0; i < intMaxTabs; i++)
			{
				if (document.getElementById("tabHeader_"+arrStr[1]+"_"+i))
					document.getElementById("tabHeader_"+arrStr[1]+"_"+i).className = "tabHeader"+extraCss;
				
				if (document.getElementById("tabContent_"+arrStr[1]+"_"+i))
					document.getElementById("tabContent_"+arrStr[1]+"_"+i).className = "tabContent tcNA";			
					
			} 
			document.getElementById("tabHeader_"+arrStr[1]+"_"+arrStr[2]).className = "tabHeader"+extraCss+" thA"+extraCss;
			document.getElementById("tabContent_"+arrStr[1]+"_"+arrStr[2]).className = "tabContent tcA";
		}
		else
			alert('Script error:\n\nPlease give your header div an id like:\n\'tabHeader_<block>_<numeric-id>\'\n\n and your tab content:\n\'tabContent_<block>_<numeric-id>\'');
	}
			


	function showDetails(objImg)
	{
		strImg = objImg.id.toString().split("_", 2); //Extract ID (available under strImg[1])
		document.getElementById('detailPic').src = objImg.src;
		moveLayerToMouseLoc('pictureDetailDiv', 5, 5)
	}
	
	
	function getScrollXY() {
	  var scrOfX = 0, scrOfY = 0;
	  if( typeof( window.pageYOffset ) == 'number' ) {
	    //Netscape compliant
	    scrOfY = window.pageYOffset;
	    scrOfX = window.pageXOffset;
	  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	    //DOM compliant
	    scrOfY = document.body.scrollTop;
	    scrOfX = document.body.scrollLeft;
	  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
	    //IE6 standards compliant mode
	    scrOfY = document.documentElement.scrollTop;
	    scrOfX = document.documentElement.scrollLeft;
	  }
	  return [ scrOfX, scrOfY ];
	}	
	
	
	function backToTop() {
	    var x1 = x2 = x3 = 0;
	    var y1 = y2 = y3 = 0;
	
	    if (document.documentElement) {
	        x1 = document.documentElement.scrollLeft || 0;
	        y1 = document.documentElement.scrollTop || 0;
	    }
	
	    if (document.body) {
	        x2 = document.body.scrollLeft || 0;
	        y2 = document.body.scrollTop || 0;
	    }
	
	    x3 = window.scrollX || 0;
	    y3 = window.scrollY || 0;
	
	    var x = Math.max(x1, Math.max(x2, x3));
	    var y = Math.max(y1, Math.max(y2, y3));
	
	    window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));
	
	    if (x > 0 || y > 0) {
	        window.setTimeout("backToTop()", 25);
	    }
	}
	


	// intOffset 
	function openSlideshow(intOffset) {
		
		strURL="/site/index.php?page=picturesFullscreen&intOffset="+intOffset.toString();
		intMessageId = document.getElementById("currentPicture").myMessageId;
		if (intMessageId) strURL = strURL+"&intMessageId="+intMessageId.toString();

		w = screen.width;
		h = screen.height;  
		wleft=(screen.width/2) - (w/2);
		wtop=(screen.height/2) - (h/2);
		
		var win = window.open(strURL, "slideshow", 'width=' + w + ', height=' + h + ', ' + 'left=' + wleft + ', top=' + wtop + ', ' + 'location=no, menubar=no, ' +  'status=no, toolbar=no, scrollbars=no, resizable=yes');
		
		// Just in case width and height are ignored
		win.resizeTo(w, h);
		
		// Just in case left and top are ignored
		win.moveTo(wleft, wtop);
		
		win.focus();
		
		
	}	
		
	var myWidth = 0, myHeight = 0;
	
	function getMyWindowSize() {
	  
	  if( typeof( window.innerWidth ) == 'number' ) {
	  	//var myWidth = 0, myHeight = 0;
	    //Non-IE
	    myWidth = window.innerWidth;
	    myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth;
	    myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myWidth = document.body.clientWidth;
	    myHeight = document.body.clientHeight;
	  }
	}
	
		
	// ================================================================================================				
		
	// Picture functions
	// Pieter - 03-01-07
	var currentPicture;
	var pictures=new Array();
	var arrHiddenHTML = new Array();

   
	function showPicture(intId)	{
		
		if (pictures[intId])
		{
			currentPicture = intId;


			document.getElementById("preloadPicture").style.width = '0px';
			document.getElementById("preloadPicture").style.height = '0px';
			document.getElementById("preloadPicture").src = pictures[intId][5];
			document.getElementById("preloadPicture").myW = pictures[intId][3];
			document.getElementById("preloadPicture").myH = pictures[intId][4];
			document.getElementById("preloadPicture").myTitle = pictures[intId][6];
			document.getElementById("preloadPicture").myOffset = intId;
			document.getElementById("preloadPicture").onload = switchPreload;
			


			
		}
	}

	function switchPreload() {
		
		document.getElementById("currentPicture").style.visibility = 'hidden';

		//pausecomp(100);
		
		
		document.getElementById("currentPicture").style.width = '10px';
		document.getElementById("currentPicture").style.height = '10px';
		document.getElementById("currentPicture").src = document.getElementById("preloadPictureSpacer").src;

		document.getElementById("currentPicture").myOffset = document.getElementById("preloadPicture").myOffset;
		document.getElementById("currentPicture").onclick = function() { if (pictures[this.myOffset][7]) eval(pictures[this.myOffset][7]); }; 
		
		
		//pausecomp(100);
		
		document.getElementById("currentPicture").style.width = this.myW+'px';
		document.getElementById("currentPicture").style.height = this.myH+'px';
		document.getElementById("currentPicture").src = document.getElementById("preloadPicture").src;

		pausecomp(100);

		document.getElementById("currentPicture").style.visibility = 'visible';
		document.getElementById("currentTitle").innerHTML = this.myTitle;
		
	}
	
	function openslide() {
		openSlideshow(currentPicture);
	}

	function next() {
		
		if (currentPicture >= pictures.length-1)
			showPicture(0);
		else
			showPicture(currentPicture + 1);
	}
	
	function prev() {
		
		if (currentPicture == 0)
			showPicture(pictures.length-1);
		else
			showPicture(currentPicture - 1);
	}
	
	function sendPictureAsPostcard() {
		newWindow = window.open("/site/index.php?page=picture&action=send&id="+pictures[currentPicture][0]);
	}
	



// Video functions
	function showVideo(id) {
		 currentVideo = id;
		 var soVideo = new SWFObject("/images/video/flvplayer.swf", "flashVideo", 400, 300, "8");
		 soVideo.addParam("wmode", "transparent");
		 soVideo.addVariable("file", "/images/stream.php?strFile="+videos[id][3]);
		 soVideo.addVariable("autostart", "false");
		 soVideo.write("flashVideoFrame");
		 
		 document.getElementById('videoDescription').innerHTML = videos[id][4];
		 //document.write(videos[id][4]);
	}	


	function nextVideo() {
		if (currentVideo >= videos.length-1)
			showVideo(0);
		else
			showVideo(currentVideo + 1);
	}
	
	function previousVideo() {
		if (currentPicture == 0)
			showVideo(videos.length-1);
		else
			showVideo(currentVideo - 1);
	}

// End video functions

	function showFileId(intFileId) {
		i = getPosFromFileId(intFileId);
		showPicture(i);
	}
	
	function getPosFromFileId(intFileId) {
		intFileId = intFileId.toString(); 
		
		var fileFound = false;
		var i = -1;
		while(!fileFound) {
			i++;
			if(pictures[i][0] == intFileId)
				fileFound = true;			
		}
		return i;
		
	}
	

	function showHiddenThumbnails(intMessageId) {
		document.getElementById("layerShowHiddenThumbnails"+intMessageId).style.visibility = "hidden";
		document.getElementById("hiddenThumbnails"+intMessageId).innerHTML = arrHiddenHTML[intMessageId];
	} 
	

	function pausecomp(millis) {
		var date = new Date();
		var curDate = null;
		
		do { 
			curDate = new Date(); 
		}  while(curDate-date < millis);
	} 
	
	
