var confirmMsg  = 'Weet u zeker dat u deze wilt verwijderen?';

function confirmLink(theLink)
{
    if (confirmMsg == '') {
        return true;
    }
    var is_confirmed = confirm(confirmMsg);
    if (is_confirmed) {
        theLink.href += '&confirmed=1';
    }
    return is_confirmed;
}

var popupCount = Math.round(Math.random() * 100);

function openPopup(fileID, width, height) {
	openPopup(fileID, width, height, '0');
}

function openPopup(fileID, width, height, scroll) {
	width += 6;
	height += 5;
 	popupCount ++;
	window.open(fileID , 'fly'+popupCount, "menubar=0,scrollbars=" + scroll + ",toolbar=0,location=0,directories=0,status=0,resizable=0,width=" + width + ",height=" + height + "left=10, top=10");
}

function checkCount(veld, aantal, volgende) {
	if(veld.value.length >= aantal) {
		volgende.focus();
	}
}

function onlyNumbers(obj) {
	var checked = "", replace = false;
	for (i = 0; i < obj.value.length; i++)
	if (isNumber(obj.value.substr(i, 1))) checked += obj.value.substr(i, 1);
		else replace = true;
	if (replace) obj.value = checked;
}

function isNumber(c){
	if (c==0||c==1||c==2||c==3||c==4||c==5||c==6||c==7||c==8||c==9||c=='.'||c==',') return true;
		else return false;
}

function goMonth(d) {
	window.location = "?go=finished&month="+d;
}

function confirmMssg(theLink, confirmMssg)
{
    if (confirmMssg == '') {
        return true;
    }
    var is_confirmed = confirm(confirmMssg);
    if (is_confirmed) {
        theLink.href += '&confirmed=1';
    }
    return is_confirmed;
}

weekdays = new arr("Sun.","Mon.","Tue.","Wed.","Thu.","Fri.","Sat.");
weekdagen = new arr("zon","maa","din","woe","don","vrij","zat");
months = new arr("januari","februari","maart","april","mei","juni","juli","augustus","september","oktober","november","december");

var cur = new Date();

function confirmLink(theLink, confirmMsg) {
    if (confirmMsg == '') {
        return true;
    }
    if (confirmMsg == null) {
		confirmMsg  = 'Weet u zeker dat u deze wilt verwijderen?';
	}
    var is_confirmed = confirm(confirmMsg);
    if (is_confirmed) {
        theLink.href += '&confirmed=1';
    }
    return is_confirmed;
}

function searchBoxWeekDay(day, month, elementId) {
	if (document.getElementById) {
		var theElement = document.getElementById(elementId);
	} else {
		if (document.all) {
			var theElement = document.all[elementId];
		} else {
			var theElement = new Object();
		}
	}
	if (!theElement) { return; }
	curCounter = cur.getDate() + cur.getMonth() * 31;
	dayCounter = day + month * 31;
	if (curCounter > dayCounter) {
		date = new Date(cur.getFullYear() + 1, month, day);
		theElement.innerHTML = "(" + weekdagen[date.getDay()] + ")";
	} else {
		date = new Date(cur.getFullYear(), month, day);
		theElement.innerHTML = "(" + weekdagen[date.getDay()] + ")";
	}
}

function disableOtherIfSelected(select, other) {
	disableOtherIfSelected(select, other, null, false);
}

function disableOtherIfSelected(select, other, other2, changeColor) {
	if (select == null) return;
	if (changeColor) select.style.backgroundColor = '#FFFFFF';
	if (other  == null) return;
	if (select.selectedIndex > 0) {
		other.selectedIndex = 1;
		if (changeColor) other.style.backgroundColor = '#FFE9D1';
	}
	if (other2  == null) return;
	if (select.selectedIndex > 0) {
		other2.selectedIndex = 1;
		if (changeColor) other2.style.backgroundColor = '#FFE9D1';
	}
}

function checkRadio(thing) {
	thing.form.radiolocation.checked = false;
	thing.checked = true;
}

function selectRadioIndex(radio, index) {
	radio[index].checked = true;
}

function changeRadioLocation(aan, uit) {
	aan.style.backgroundColor = '#FFFFFF';

	uit.style.backgroundColor = '#FFE9D1';
	uit.selectedIndex = 1;
}

function clearInput(field, initialValue) {
	if (initialValue == "") {
		field.value = '';
	} else if (initialValue == field.value) {
		field.value = '';
	}
}

function checkCount(veld, aantal, volgende) {
	if(veld.value.length == aantal) {
		volgende.focus(); }
}

function fly(fileID, width, height) {
	fly(fileID, width, height, 0);
}

function fly(fileID, width, height, scroll) {
	win = window.open(fileID , "fly", "menubar=0,scrollbars=" + scroll + ",toolbar=0,location=0,directories=0,status=0,resizable=1,width=" + width + ",height=" + height);
	win.resizeTo(width, height);
}

function show(elementId) {
	if (document.getElementById) {
		var theElement = document.getElementById(elementId);
	} else {
		if (document.all) {
			var theElement = document.all[elementId];
		} else {
			var theElement = new Object();
		}
	}
	if (!theElement) { return; }
	if (theElement.style) { theElement = theElement.style; }
	if (typeof(theElement.display) == 'undefined' && !( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 ) ) { return; }

	theElement.display = 'block';
}

function hide(elementId) {
	if (document.getElementById) {
		var theElement = document.getElementById(elementId);
	} else {
		if (document.all) {
			var theElement = document.all[elementId];
		} else {
			var theElement = new Object();
		}
	}
	if (!theElement) { return; }
	if (theElement.style) { theElement = theElement.style; }
	if (typeof(theElement.display) == 'undefined' && !( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 ) ) { return; }

	theElement.display = 'none';
}

function toggle(e) {
	var theElement = document.getElementById(e);
	if (theElement.style.display == "none")   {
		show(e);
	} else {
		hide(e);
	}
}

var min_year = 2004;
var max_year = 2006;

var weekday_showing              = false;
var dayofweek_returned_as_number = false;
var month_returned_as_number     = true;

if (min_year <= 400) {
	alert("Minimum year must be higher than 400 for this algorithm to work.");
}

function changeDays(numb, day, month, year) {
	mth = month.selectedIndex;
	now = new Date();
	yr = now.getYear();
	if (numb != 1) {
		numDays = numDaysIn(mth,yr);
		day.options.length = numDays;
		for (i=27;i<numDays;i++) {
			day.options[i].text = i+1;
		}
	}
	day = day.selectedIndex+1;
	if (weekday_showing) {
		dayofweek.selectedIndex = getWeekDay(mth,day,yr);
	}
}

function numDaysIn(mth,yr) {
	if (mth==3 || mth==5 || mth==8 || mth==10) return 30;
	else if ((mth==1) && leapYear(yr)) return 29;
	else if (mth==1) return 28;
	else return 31;
}

function leapYear(yr) {
	if (((yr % 4 == 0) && yr % 100 != 0) || yr % 400 == 0)
		return true;
	else
		return false;
}

function arr() {
	this.length=arr.arguments.length;
	for (n=0;n<arr.arguments.length;n++) {
		this[n] = arr.arguments[n];
	}
}

function getWeekDay(mth,day,yr) {
	first_day = firstDayOfYear(yr);
	for (num=0;num<mth;num++) {
		first_day += numDaysIn(num,yr);
	}
	first_day += day-1;
	return first_day%7;
}

function firstDayOfYear(yr) {
	diff = yr - 401;
	return parseInt((1 + diff + (diff / 4) - (diff / 100) + (diff / 400)) % 7);
}

function getFullYear(d) { // d is a date object
	yr = d.getYear();
	if (yr < 1000)
		yr+=1900;
	return yr;
}

function lightOn(o, c){
	if (document.getElementById || (document.all && !(document.getElementById))) {
		o.style.backgroundColor = c;
	}
}

function lightOff(o, c){
	if(document.getElementById || (document.all && !(document.getElementById))){
		o.style.backgroundColor = c;
	}
}

function buildStars(n) {
	for(i = 0; i < n; i++) {
		document.write('<img src="/img/star.gif" height="9" width="10" border="0" />');
	}
}

function selectItem(sel, id) {
	if(sel != null) {
		for(i = 0; i < sel.length; i++) {
			if(sel[i].value == id) {
				sel[i].selected = true;
				break;
			}
		}
	}
}

function setPriceList(res, adults, adultPrice, rooms, onePersonExtra, morePersonDiscount) {
	if (document.getElementById("pl_price")) {

		var pl_price 		= document.getElementById("pl_price");
		var pl_total 		= document.getElementById("pl_total");
		var pl_res 			= document.getElementById("pl_res");
		var pl_restotal		= document.getElementById("pl_restotal");
		var pl_totalprice	= document.getElementById("pl_totalprice");
		var pl_extratitle	= document.getElementById("pl_extratitle");
		var pl_extra		= document.getElementById("pl_extra");
		var pl_extratotal	= document.getElementById("pl_extratotal");

	    var total = (adultPrice * adults + res);

		pl_price.innerHTML 		= "&euro; " + parseFloat(adultPrice).toFixed(2);
		pl_total.innerHTML 		= "&euro; " + (parseFloat(adultPrice) * adults).toFixed(2);
		if(pl_res != 0) {
			pl_res.innerHTML 		= "&euro; " + parseFloat(res).toFixed(2);
			pl_restotal.innerHTML 	= "&euro; " + parseFloat(res).toFixed(2);
		}
	    if ((rooms * 2 - adults) > 0 && onePersonExtra != 0) {
	    	total += onePersonExtra*(rooms * 2 - adults);
	    	pl_extratitle.innerHTML 		= "1-pers. toeslag";
	    	pl_extra.innerHTML 				= "&euro; " + parseFloat(onePersonExtra).toFixed(2);
	    	pl_extratotal.innerHTML 		= "&euro; " + (parseFloat(onePersonExtra)*(rooms * 2 - adults)).toFixed(2);
	    } else if(rooms * 2 < adults && morePersonDiscount != 0) {
	    	total -=  morePersonDiscount * (adults - rooms * 2);
	    	pl_extratitle.innerHTML 		= "Meerpers. korting";
	    	pl_extra.innerHTML 				= "&euro; -" + parseFloat(morePersonDiscount).toFixed(2);
	    	pl_extratotal.innerHTML 		= "&euro; -" + (parseFloat(morePersonDiscount) * (adults - rooms * 2)).toFixed(2);
	    } else {
	    	pl_extratitle.innerHTML 		= "";
	    	pl_extra.innerHTML 				= "";
	    	pl_extratotal.innerHTML 		= "";
	    }
		pl_totalprice.innerHTML	= "&euro; " + parseFloat(total).toFixed(2);

	}
}

function empty(o) {
	o.value = "";
}

function lightTd(o, c) {
	if (document.getElementById || (document.all && !(document.getElementById))) {
    	var tds = o.getElementsByTagName("td");
    	for(var i = 0; i < tds.length; i++) {
    		var mytd = tds[i];
    		mytd.style.backgroundColor = c;
    	}
    }
}

function light(o, c){
	if (document.getElementById || (document.all && !(document.getElementById))) {
		o.style.backgroundColor = c;
  	}
}

function checkCount(field, nr, next) {
	if(field.value.length == nr) {
		next.focus();
	}
}

////////////////////
////////////////////
////////////////////

var inlinepopup;

var initInlinepopup = function() {
	inlinepopup = new YAHOO.widget.Panel("mediadialog", {
		effect: {effect:YAHOO.widget.ContainerEffect.SLIDE, duration:0.2},
		fixedcenter:false,
		visible:false,
		close:true,
		draggable:true,
		underlay: "none",
    	constraintoviewport: true,
    	fixedcenter:true,
		width:"420px"} );

	inlinepopup.render();
	YAHOO.util.Dom.setStyle("mediadialog", "display", "block");

	//YAHOO.util.Event.addListener("mediadialog", "click", inlinepopup.hide, inlinepopup, true);
}

var showInlinePopupText = function(h, c) {
	inlinepopup.setHeader(h);
	inlinepopup.setBody(c);
	inlinepopup.show();
}

var showInlinePopupMediaRewrite = function(c, name) {
	var d = c.getElementsByTagName('img');

	if (d.length > 0) {
		var i = d[0].src;
		i = i.replace(/\/212\/159\//, '/400/300/');
		showInlinePopupMedia(i, name);
	}
}

var inlineName;

var showInlinePopupMedia = function(c, name) {
	if (inlinepopup == null) {
		initInlinepopup();
	}
	
	if (name != undefined && name != null) {
		inlineName = name;
	} else {
		name = inlineName;
	}

	inlinepopup.setHeader(name);
	inlinepopup.setBody('<table width="400" height="300" cellspacing="0" cellpadding="0"><tr><td align="center" valign="center"><img src="' + c + '" /></td></tr></table>');

	if (photos.length > 1) {
		inlinepopup.setFooter('');
		for (var i = 0; i < photos.length; i++) {
			if (c.indexOf(photos[i]) > -1) {
				var p = i - 1;
				var n = i + 1;
				if (p < 0) p = (photos.length - 1);
				if (n > (photos.length - 1)) n = 0;

				var pbutton = "<span onclick=\"showInlinePopupMedia(photos[" + p + "]); return false;\" class='yui-button'><span class='first-child'><button type='button'>vorige foto</button></span></span>";
				var nbutton = "<span onclick=\"showInlinePopupMedia(photos[" + n + "]); return false;\" class='yui-button right'><span class='first-child'><button type='button'>volgende foto</button></span></span>";
				inlinepopup.setFooter(nbutton + pbutton);
				break;
			}
		}
	} else {
		inlinepopup.setFooter('');
	}
	inlinepopup.center();
	inlinepopup.show();
}
