function setFormField(f, text) {
	if (f.value == text) 
		f.value = '';
}

function resetFormField(f, text) {
	if (f.value == '')
		f.value = text;
}

function setOutlines() {
	var content = document.getElementById('content');
	var middle = document.getElementById('middleContent');
	// Marvin: -40px is de padding die er nog vanaf moet;
	middle.style.height = (content.offsetHeight-40) + 'px';
}

/*function showPhoto(pg_id, file, photoablumid, photografer, message) {
	if(photografer != ""){
		photografer = 'Foto gemaakt door: ' + photografer;
	}
	
	document.getElementById('photoHolder_' + photoablumid).innerHTML = '<img src="/inc/upload/photos/' + pg_id + '/photo_' + file + '" border="0" title="' + photografer + '" />';
	if(message != undefined){
		document.getElementById('textHolder_' + photoablumid).innerHTML = message;
	}
}*/

function submitOnEnter(frm) {
	if (window.event && window.event.keyCode == 13)
		frm.submit();
	else
		return true;
}

function highlightSearch(action){
	var tags = getElementsByClassName("searchField");
	if(!tags[1]){
		if(action=="over")tags[0].style.backgroundImage = "url(/inc/img/bg_search_over.png)";
		else tags[0].style.backgroundImage = "url(/inc/img/bg_search.png)";
	}
}

function getElementsByClassName(clss){
	var returnTags = new Array();	
	var tags = document.getElementsByTagName("*");
	for(var i=0;i<tags.length;i++){
		if(tags[i].className&&tags[i].className==clss)returnTags.push(tags[i]);
	}
	return returnTags;
}

function photoAlbum(arrPhotos, photoPath){
	
	this.arrPhotos = arrPhotos;
	this.photoPath = photoPath;
	
	this.showPhoto = function(id, photoUuid){
		var photoHolder = document.getElementById('photoholder_' + photoUuid);	
		console.log(photoHolder);
		photoHolder.src = this.photoPath+ 'photo_' + this.arrPhotos[id-1][1];
		
	}
}

function getTargetId(event){
	
	if(event.target) { // FF
		return event.target.id;
	} else if(window.attachEvent) { // IE
		return event.srcElement.id;
	} else return false;
}

function addListener(element, type, expression, bubbling){
	bubbling = bubbling || false;
	
	if(window.addEventListener) { // Standard
		element.addEventListener(type, expression, bubbling);
		return true;
	} else if(window.attachEvent) { // IE
		element.attachEvent('on' + type, expression);
		return true;
	} else return false;
}

function getTargetId(event){
	
	if(event.target) { // FF
		return event.target.id;
	} else if(window.attachEvent) { // IE
		return event.srcElement.id;
	} else return false;
}

/* Photoalbum */
function photoAlbum(arrPhotos, photoPath, pa_id){
	
	/* Constructor : Photoalbum instellingen */
	this.arrPhotos = arrPhotos;
	this.photoPath = photoPath;
	this.photosPerPage = 9;
	this.paId = pa_id;	
	
	// FUNCTIE | Foto groot tonen
	this.showPhoto = function(id){
		var photoHolder = document.getElementById('photoholder_' + this.paId);	
		var photoInfo = document.getElementById('photoinfo_' + this.paId);	
		
		photoHolder.src = this.photoPath+ 'photo_' + this.arrPhotos[id][1];
		
		var photoInfoText = "";
		if(this.arrPhotos[id][2] != ''){
			photoInfoText += this.arrPhotos[id][2];
		}
		if(this.arrPhotos[id][2] != '' && this.arrPhotos[id][3] != ''){
			photoInfoText += " - ";	
		}
		if(this.arrPhotos[id][3] != ''){
			photoInfoText += this.arrPhotos[id][3];
		}
		photoInfo.innerHTML = photoInfoText;
	}
	
	// FUNCTIE | Thumbnails tonen
	this.showThumbs = function(pageId){
		
		// Standaard pagina
		pageId = pageId || 1;
		var loopTo;
		
		var pageCount = Math.ceil(this.arrPhotos.length / this.photosPerPage);

		var photoStrip = document.getElementById('photostrip_'+this.paId);
		
		// Foto strip leegmaken
		photoStrip.innerHTML = "";
		
		// Pagina bereik uitrekenen
		if(this.arrPhotos.length > this.photosPerPage){
			loopFrom = (this.photosPerPage * pageId) - (this.photosPerPage - 1);
			if(pageCount == pageId && (this.arrPhotos.length % this.photosPerPage > 0)){
				loopTo = loopFrom + (this.arrPhotos.length % this.photosPerPage)-1;
			} else {
				loopTo = loopFrom + (this.photosPerPage - 1);								   
			}
		} else {
			loopFrom = 1;
			loopTo = this.arrPhotos.length;
		}

		// Thumbs uitloopen en afdrukken
		var objAlbum = new photoAlbum(this.arrPhotos, this.photoPath, this.paId);

		for(var i = loopFrom; i <= loopTo; i++){
			
			
			
			var photoThumb = document.createElement('img');
			photoThumb.id = "thumb_"+(i-1);
			photoThumb.className = "thumb";
			photoThumb.src = photoPath+'thumb_' + arrPhotos[i-1][1];
			photoThumb.style.cursor = "pointer";
			addListener(photoThumb, 'click', function(e){ 
				photoId = getTargetId(e).split("_");
				photoId = photoId[1];
				objAlbum.showPhoto(photoId); 
			});
			
			photoStrip.appendChild(photoThumb);
		}
		
		// Pagina's uitlopen
		var photoPagesHolder = document.getElementById('photopages_holder_' + this.paId);
		var photoPages = document.getElementById('photopages_' + this.paId);	
		
		// Pagina's Leegmaken
		photoPages.innerHTML = "";
		
		// Checken of er wel pagina's zijn
		if(pageCount > 1){
			for(var i = 1; i <= pageCount; i++){
				var pageLink = document.createElement('span');
				pageLink.id = "link_"+i;
				pageLink.innerHTML = i+" ";
				if(i != pageId){
					pageLink.className = "pageLink";
					pageLink.style.cursor = "pointer";
					addListener(pageLink, 'click', function(e){ 
						pageId = getTargetId(e).split("_");
						pageId = pageId[1];
						objAlbum.showThumbs(pageId); 
					});
				} else {
					pageLink.className = "pageLink selected";
				}
				photoPages.appendChild(pageLink);
			}
		} else { // Anders uitzetten
			photoPagesHolder.style.display = "none";
		}
	}
}

function showPopup(ru_id) {
	document.body.style.height = "100%";
	var overlayDiv = document.createElement('div');
	overlayDiv.id = "overlay";
	
	var version = navigator.userAgent;
	var findFirefox = version.indexOf('Firefox');
	var findIE6 = version.indexOf('MSIE 6');


	if (findIE6 != -1){
		overlayDiv.style.position = "absolute";
		overlayDiv.style.height = document.body.clientHeight;
		overlayDiv.style.width = document.body.clientWidth;
	} else {
		overlayDiv.style.height = "100%";
		overlayDiv.style.position = "fixed";
		overlayDiv.style.width = "100%";
	}
	
	document.body.style.overflow = "visible";
	
	overlayDiv.style.background = "#e5e5e5 none repeat scroll 0 0";
	overlayDiv.style.top = "0";
	overlayDiv.style.left = "0";
	overlayDiv.style.right = "0";
	overlayDiv.style.bottom = "0";
	overlayDiv.style.opacity = ".70";
	overlayDiv.style.filter = "alpha(opacity=70)";
	overlayDiv.style.zIndex = "10";
	
	document.body.appendChild(overlayDiv);
	
	var popUpDiv = document.getElementById('privatemessage');
	popUpDiv.style.display = "block";
	popUpDiv.style.position = "fixed";
	popUpDiv.style.top = "50%";
	popUpDiv.style.marginTop = "-160px";
	popUpDiv.style.left= "50%"; 
	popUpDiv.style.marginLeft = "-260px";
	popUpDiv.style.zIndex = "11";
	
	document.getElementById('ru_id_to').value = ru_id;
	
}

function hidePopup(){
	document.body.removeChild(document.getElementById('overlay'));
	document.getElementById('privatemessage').style.display = 'none';
}




function setLang(lang, mn_id) {
	var setLangObj = new ajax();
	
	var url = setLangObj.setLang(lang, mn_id);
	self.location = url;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function popUp(URL, WinWidth, WinHeight) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width='" + WinWidth + "',height='" + WinHeight +");");
}


/* HOTELIERS */

var curDate = new Date();
var hEngine = 'http://www.hoteliers.com/wlpEngine.php?lang=en&ID='; 
function dInM(mon)
	{           

    	if (mon == 2)
        	{
             Year = curDate.getFullYear();
             if(Math.round(Year/4) == Year/4)
            	{
              		if(Math.round(Year/100) == Year/100)
              		{
       					if(Math.round(Year/400) == Year/400)
        				return 29;
       					else return 28;
      				}
      			else return 29;
     			}
    		return 28;
            }
            else if (mon == 4 || mon == 6 || mon == 9 || mon == 11)
            {
             return 30;
            }
            return 31;
	}
 
function getNDay()
{
theMonth = document.hcomForm.am.options.selectedIndex;
theDay = parseInt(document.hcomForm.ad.options.selectedIndex);
 
 if (! theMonth == 0 && ! theDay == 0)
 {
  dInMonth = dInM(theMonth);
  if (theDay > dInMonth)
  {
	document.hcomForm.ad.options.selectedIndex = theDay = dInMonth;
  }
  newDay = theDay + 1;
  newMonth = theMonth;
  if (newDay > dInMonth)
  {
            newDay = 1;
            newMonth = theMonth + 1;
            if (newMonth > 12)
            {
				newMonth = 1;
            }
  }
 
document.hcomForm.dd.selectedIndex = newDay;
document.hcomForm.dm.selectedIndex = newMonth;
 }
}
 
 
function doCheckForm()
{
 
el = document.getElementById('hoteliers');
if (el)
{
el.innerHTML = '<iframe name="' + document.hcomForm.hTarget.value + '" src="" width="100%" height="400" frameborder="0">';
}
document.hcomForm.target = document.hcomForm.hTarget.value;
document.hcomForm.action = 'http://www.hoteliers.com/wlpEngine.php?ID=' + document.hcomForm.hotelID.value + '&lang=en';
document.hcomForm.submit();
 
}
 
function checkDDate()
{
 theMonth = document.hcomForm.dm.options.selectedIndex;
 theDay = parseInt(document.hcomForm.dd.options.selectedIndex);
 dInMonth = dInM(theMonth);
 
 if (theDay > dInMonth)
 {
  document.hcomForm.dd.options.selectedIndex = theDay = dInMonth;
 }
}


function loadIFrame(url){
	el = document.getElementById('content');
	if (el){	
		el.innerHTML = '<iframe name="frame" src="' + url + '" frameborder="0">';
	}
	var titleBar = document.getElementById('titleBar');
	titleBar.innerHTML = '';

	return false;
}

window.onload = function(){
	var tags = document.getElementsByTagName('A');
	var i=tags.length;
	do{
		if(tags[i] && tags[i].title=="frame"){
			tags[i].onclick=function(){return loadIFrame(this);};
		}
	}while(--i);
}


// SuckerFish Menu
//sfHover = function() {
//	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
//	for (var i=0; i<sfEls.length; i++) {
//		sfEls[i].onmouseover=function() {
//			this.className+=" sfhover";
//		}
//		sfEls[i].onmouseout=function() {
//			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
//		}
//	}
//}
//if (window.attachEvent) window.attachEvent("onload", sfHover);
