function showLargeThumb(sObjectID)
{
	if(sObjectID)
	{
		oLargeImage = document.getElementById("large_thumb_"+sObjectID);
		oLargeImage.style.display = 'block';
	}
}

function hideLargeThumb(sObjectID)
{
	if(sObjectID)
	{
		oLargeImage = document.getElementById("large_thumb_"+sObjectID);
		oLargeImage.style.display = 'none';
	}
}

function CreateBookmarkLink(url,title)
{
    if (window.sidebar)
        window.sidebar.addPanel(title, url,"");
    else if (window.external)
        window.external.AddFavorite( url, title); 
    else if (window.opera && window.print)
        return true;
}

function changePhoto(oSrc)
{
	oBF = document.getElementById("big");
	oImg = oBF.getElementsByTagName("div");
	oImg[0].style.backgroundImage  = oSrc.style.backgroundImage.replace("/thumbnails/","/photos/");
}

function setCategory(c)
{
	if (c == 1)
	{
		document.getElementById('month').disabled = false;
	}
	else
	{
		document.getElementById('month').selectedIndex = 0;
		document.getElementById('duration').selectedIndex = 0;
		document.getElementById('arrival_date').selectedIndex = 0;
		document.getElementById('month').disabled = true;
		document.getElementById('duration').disabled = true;
		document.getElementById('arrival_date').disabled = true;
	}
	
	GetDestinations(c);
}

function setMonth(m)
{
	if (m != '')
	{
		document.getElementById('duration').disabled=false;
		document.getElementById('duration').options[0].text=((language=="NL")?'Kies duur':'Bitte wählen Sie hier');
		
		var duration = document.getElementById('duration').options[document.getElementById('duration').selectedIndex].value;
		if (duration != '')
		{
			document.getElementById('arrival_date').options[0].text=((language=="NL")?'Even geduld aub':'Bitte kürz warten');
			
			var destination = document.getElementById('destination').options[document.getElementById('destination').selectedIndex].value;
			
			GetArrivalDates(document.getElementById('month').options[document.getElementById('month').selectedIndex].value, duration, destination);
		}
	}
	else
	{
		document.getElementById('duration').selectedIndex=0;
		document.getElementById('duration').options[0].text=((language=="NL")?'Kies maand':'Bitte wählen Sie hier');
		document.getElementById('duration').disabled=true;
		
		document.getElementById('arrival_date').selectedIndex=0;
		document.getElementById('arrival_date').options[0].text=((language=="NL")?'Kies eerst een maand en de duur':'Wählen Sie erst Monat danach Reisedauer');
		document.getElementById('arrival_date').disabled=true;
	}
}

function setDuration(dur)
{
	if (dur != '')
	{
		document.getElementById('arrival_date').options[0].text=((language=="NL")?'Even geduld aub':'Bitte kürz warten');
		
		var destination = document.getElementById('destination').options[document.getElementById('destination').selectedIndex].value;
		
		GetArrivalDates(document.getElementById('month').options[document.getElementById('month').selectedIndex].value, dur, destination);
		document.getElementById('arrival_date').disabled=false;
	}
	else
	{
		document.getElementById('arrival_date').selectedIndex=0;
		document.getElementById('arrival_date').options[0].text=((language=="NL")?'Kies eerst een maand en de duur':'Wählen Sie erst Monat danach Reisedauer');
		document.getElementById('arrival_date').disabled=true;
	}
}

function DoHttpRequest(url, callback_function, el)
{
    var http_request = false;
	
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) { }
        }
    }
	
    if (!http_request) {
        alert('Unfortunately you browser doesn\'t support this feature.');
        return false;
    }
	
    http_request.onreadystatechange = function() {
	
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
				eval(callback_function + "(http_request.responseXML, el)");
            } else {
                alert('There was a problem with the request.(Code: ' + http_request.status + ')');
            }
        }
    }
    http_request.open('GET', url, true);
    http_request.send(null);
}

function GetDestinations(c)
{
	DoHttpRequest('/?act=get_destinations&cat='+c, 'FillDestinations');
}

function FillDestinations(xml)
{
	var destinations = xml.getElementsByTagName('destination');
	
	var list = ["select", {id:'destination', name:'destination'}];
	
	list.push(['option', {value:''}, ((language=="NL") ? 'Kies een bestemming' : 'Wählen Sie Land')]);
	
	var len = destinations.length;
	
	for(i=0;i<len;i++)
	{
		if(destinations[0].textContent == undefined)
		{
			label = destinations[i].getElementsByTagName('acc_country_name');
			label = label[0].text;
			value = destinations[i].getElementsByTagName('acc_country_id');
			value = value[0].text;
			list.push(['option', {value:value}, utf8decode(label)]);
		}
		else
		{
			label = destinations[i].getElementsByTagName('acc_country_name');
			label = label[0].textContent;
			value = destinations[i].getElementsByTagName('acc_country_id');
			value = value[0].textContent;
			list.push(['option', {value:value}, utf8decode(label)]);
		}
	}
	
	var destinations = document.getElementById('destination');
	destinations.parentNode.removeChild(destinations);
	
	graft(document.getElementById("insert-destinations-here"), list);
}

function GetArrivalDates(m, dur, dest)
{
	DoHttpRequest('/?act=get_arrival_dates&month='+m+'&duration='+dur+'&destination='+dest, 'FillArrivalDates', 'fillarrivaldates');
}

function FillArrivalDates(xml, el)
{
	var xmlDoc = xml;
	
	var arrivaldates = xmlDoc.getElementsByTagName('arrivaldate');
	
	var list = ["select", {id:'arrival_date', name:'arrival_date'}];
	
	list.push(['option', {value:''}, ((language=="NL") ? 'Kies een aankomstdatum' : 'Wählen Sie Ankunfstdatum')]);
	
	var len = arrivaldates.length;
	
	for(i=0;i<len;i++)
	{
		if(arrivaldates[0].textContent == undefined)
		{
			label = arrivaldates[i].getElementsByTagName('label');
			label = label[0].text;
			value = arrivaldates[i].getElementsByTagName('value');
			value = value[0].text;
			list.push(['option', {value:value}, utf8decode(((language=="NL") ? 'rond '+label : 'um '+label+' herum'))]);
		}
		else
		{
			label = arrivaldates[i].getElementsByTagName('label');
			label = label[0].textContent;
			value = arrivaldates[i].getElementsByTagName('value');
			value = value[0].textContent;
			list.push(['option', {value:value}, utf8decode(((language=="NL") ? 'rond '+label : 'um '+label+' herum'))]);
		}
	}
	
	var arrivals = document.getElementById('arrival_date');
	arrivals.parentNode.removeChild(arrivals);
	
	graft(document.getElementById("insert-here"), list);
}

function utf8encode(string)
{
    string = string.replace(/\r\n/g,"\n");
    var utftext = "";
	
    for (var n = 0; n < string.length; n++)
	{
        var c = string.charCodeAt(n);
		
        if (c < 128)
		{
            utftext += String.fromCharCode(c);
        }
        else if((c > 127) && (c < 2048))
		{
            utftext += String.fromCharCode((c >> 6) | 192);
            utftext += String.fromCharCode((c & 63) | 128);
        }
        else
		{
            utftext += String.fromCharCode((c >> 12) | 224);
            utftext += String.fromCharCode(((c >> 6) & 63) | 128);
            utftext += String.fromCharCode((c & 63) | 128);
        }
    }
	
    return utftext;
}

function utf8decode(utftext)
{
    var string = "";
    var i = 0;
    var c = c1 = c2 = 0;
	
    while ( i < utftext.length )
	{
        c = utftext.charCodeAt(i);
		
        if (c < 128)
		{
            string += String.fromCharCode(c);
            i++;
        }
        else if((c > 191) && (c < 224))
		{
            c2 = utftext.charCodeAt(i+1);
            string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
            i += 2;
        }
        else
		{
            c2 = utftext.charCodeAt(i+1);
            c3 = utftext.charCodeAt(i+2);
            string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
    }
	
    return string;
}

// graft() function
// Originally by Sean M. Burke from interglacial.com
// Closure support added by Maciek Adwent
//
// Modified by Kasper to support style attributes in IE
//
function graft (parent, t, doc)
{
    doc = (doc || parent.ownerDocument || document);
    var e;
	
    if(t == undefined) {
        throw complaining( "Can't graft an undefined value");
    } else if(t.constructor == String) {
        e = doc.createTextNode( t );
    } else if(t.length == 0) {
        e = doc.createElement( "span" );
        e.setAttribute( "class", "fromEmptyLOL" );
    } else {
        for(var i = 0; i < t.length; i++) {
            if( i == 0 && t[i].constructor == String ) {
                var snared;
                snared = t[i].match( /^([a-z][a-z0-9]*)\.([^\s\.]+)$/i );
                if( snared ) {
                    e = doc.createElement(   snared[1] );
                    e.setAttribute( 'className', snared[2] );
                    continue;
                }
                snared = t[i].match( /^([a-z][a-z0-9]*)$/i );
                if( snared ) {
                    e = doc.createElement( snared[1] );  // but no class
                    continue;
                }
				
                // Otherwise:
                e = doc.createElement( "span" );
                e.setAttribute( "class", "namelessFromLOL" );
            }
			
            if( t[i] == undefined ) {
                throw complaining("Can't graft an undefined value in a list!");
            } else if(  t[i].constructor == String ||
                                    t[i].constructor == Array ) {
                graft( e, t[i], doc );
            } else if(  t[i].constructor == Number ) {
                graft( e, t[i].toString(), doc );
            } else if(  t[i].constructor == Object ) {
                // hash's properties => element's attributes
                for(var k in t[i]) {
                    // support for attaching closures to DOM objects
                    if(typeof(t[i][k])=='function'){
                        e[k] = t[i][k];
                    } else {
						if( k == "style" )
							e.style.cssText = t[i][k]; // this bit modified by Kasper
						else
							e.setAttribute( k, t[i][k] );
                    }
                }
            } else {
                throw complaining( "Object " + t[i] +
                    " is inscrutable as an graft arglet." );
            }
        }
    }
	
    parent.appendChild( e );
    return e; // return the topmost created node
}

function complaining (s) { alert(s); return new Error(s); }

function addAsFavorite(iObjectID,sMakeFavo,sUnFavo,bIsStarItem)
{
	exdate = new Date();
	exdate.setDate(exdate.getDate() + 60);
	sCurCookie = getCookie("FeriolandFavs");
	
	oCLLink = document.getElementById("oFavMaker" + iObjectID);
	
	bInArray = false;
	sRebuild = "";
	aFavs = sCurCookie.split(":");
	
	for (key=0; key < aFavs.length; key++)
	{
		if(aFavs[key] == iObjectID)
			bInArray = true;
		else
			sRebuild += (sRebuild ? ":" : "") + aFavs[key];
	}
	
	if (bInArray)
	{
		document.cookie = "FeriolandFavs=" + sRebuild + ";expires=" + exdate.toGMTString() + ";path=/";
		
		if(oCLLink.textContent == undefined)
		{
			oCLLink.innerText = sMakeFavo;
		}
		else
		{
			oCLLink.textContent = sMakeFavo;
		}
		
		if(bIsStarItem)
			oCLLink.className = "ico_star";
		else
			oCLLink.parentNode.className = "ico_star";
	}
	else
	{
		document.cookie = "FeriolandFavs=" + sCurCookie + (sCurCookie ? ":" : "") + iObjectID + ";expires=" + exdate.toGMTString() + ";path=/";
		
		if (oCLLink.textContent == undefined)
		{
			oCLLink.innerText = sUnFavo;
		}
		else
		{
			oCLLink.textContent = sUnFavo;
		}
		
		if (bIsStarItem)
		{
			oCLLink.className = "ico_star ico_star_on";
		}
		else
		{
			oCLLink.parentNode.className = "ico_star ico_star_on";
		}
	}
}

function getCookie(sName)
{
	if(document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(sName+"=");
		if(c_start!=-1)
		{
			c_start+=(sName.length)+1;
			c_end=document.cookie.indexOf(";",c_start);
			if(c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

function killCookie()
{
	// merely for debug purposes
	exdate=new Date();
	exdate.setDate(exdate.getDate()-60);
	document.cookie="FeriolandFavs=;expires="+exdate.toGMTString();
}

function changeHand()
{
	iCurHandOpacity=0;
	iHand=1;
	changeHandAlpha();
}

function changeHandAlpha()
{
	
}

function getTabs(sTabsContainer)
{
	if(typeof sTabsContainer!='string') sTabsContainer='tabs';

	oTabContainer=document.getElementById(sTabsContainer);
	
	if(!oTabContainer) return false;
	
	aElements=oTabContainer.getElementsByTagName("a");
	
	for(i=0;i<aElements.length;i++)
	{
		oHref=aElements[i];
		
		if(i==0) oCurOpen=oHref;
		
		oHref.onclick=function(e)
		{
			e=window.event || e;
			var who=e.target || e.srcElement;
			loadTab(who);
			return false;
		}
		oHref.id="tab"+oHref.href.split('#')[1];
	}
	
	if (typeof window.location.href.split('#')[1] == 'string')
		openTab(window.location.href.split('#')[1]);
	else
		loadTab(oCurOpen);
}

function loadTab(newAObject)
{
	// close and hide the current open tab
	setTabProps(oCurOpen,'','none');
	
	if (document.getElementById('tabToLoad'))
	{
		document.getElementById('tabToLoad').value = newAObject.href.split('#')[1];
	}
	
	// open the new tab
	setTabProps(newAObject,'active-tab','block');
	
	oCurOpen=newAObject;
	return false;
}

// this function is to "manually" open tabs (now also being used to open up the "start-tab"
function openTab(sTabname)
{
	if(typeof sTabname!='string') return;
	return loadTab(document.getElementById("tab"+sTabname));
}

function setTabProps(oObject,sClass,sDisplay)
{
	oObject.className=sClass;
	sHref=oObject.href.split("#");
	oToFix=document.getElementById(sHref[1]);
	oToFix.style.display=sDisplay;

	// haxor for the fotos tab
	if(sWebsiteMode!='extranet')
	{
		if(sDisplay=='block')
		{
			oDetail=document.getElementById("detail_weergave");
			oAlbum=document.getElementById("album");
			
			if (document.getElementById("fotos"))
				oFotos=document.getElementById("fotos");
			else if (document.getElementById("bilder"))
				oFotos=document.getElementById("bilder");
			
			if(sHref[1]=="fotos" || sHref[1]=="bilder")
			{
				oDetail.style.width='';
				oFotos.style.width='100%';
				oAlbum.style.display='none';
			}
			else
			{
				oDetail.style.width='615px';
				oFotos.style.width='615px';
				oAlbum.style.display='block';
			}
		}
	}
}

function InitTabs()
{
	getTabs();
	
	if (sWebsiteMode == 'extranet')
	{
		if (tabToLoad != '')
		{
			if (document.getElementById("tab"+tabToLoad))
			{
				loadTab(document.getElementById("tab"+tabToLoad));
			}
		}
	}
}

function strrev(input)
{ 
	return input.split('').reverse().join('');
}
// sets the elements its href to a mailto to the given mailaddress
function setMailTo(el, mailAddress)
{
	tmp = el.innerHTML; // for some reason IE fucks up the inner html after changing the href. so store it to reset it afterwards
	el.href = 'mailto:' + mailAddress;
	el.innerHTML = tmp;
}


window.onload=InitTabs;

