function onLoadFunctionality(){
	if(document.getElementById&&document.getElementsByTagName){
		if(typeof addEventsForInnerTabNavigation!="undefined"){addEventsForInnerTabNavigation();}	
		if(typeof addPrintExpandBlock!="undefined"){addPrintExpandBlock();}		
		if(typeof addDynamicDropDownEvents!="undefined"){addDynamicDropDownEvents();}
		if(typeof addQuickPoll!="undefined"){addQuickPoll();}
		if(typeof addWeatherForecastEvents!="undefined"){addWeatherForecastEvents();}
		if(typeof addDynamicDropDownEventsProperty!="undefined"){addDynamicDropDownEventsProperty();}
		if(typeof addOpenMoreFactsBlock!="undefined"){addOpenMoreFactsBlock();}			
	    if(typeof addExpandMoreHotelInfo!="undefined"){addExpandMoreHotelInfo();}										
		if(typeof addHelpInfoCenterEvents!="undefined"){addHelpInfoCenterEvents();}
		if(typeof addInfoLayerEvents!="undefined"){addInfoLayerEvents();}	
		if(typeof addHelpInfoEvents!="undefined"){addHelpInfoEvents();}
		if(typeof addCloseWeatherPanel!="undefined"){addCloseWeatherPanel();}		
		if(typeof createPaging!="undefined"){createPaging();}
		if(typeof addOpenCityIntroText!="undefined"){addOpenCityIntroText();}
		if(typeof addOpenCityIntroTextTema!="undefined"){addOpenCityIntroTextTema();}
		if(typeof addPrintEvent!="undefined"){addPrintEvent();}
		if(typeof addDynamicDropDownEventsDestCode!="undefined"){addDynamicDropDownEventsDestCode();}				
		if(typeof printPageAndSubPages!="undefined"){printPageAndSubPages();}		
		if(typeof addRedirectDropDownPusher!="undefined"){addRedirectDropDownPusher();}				
		
		oBodyElmForIE=(bIsIE5)?document.body:document.documentElement;
}}
var bIsIE5 = (String(navigator.userAgent).search(/MSIE 5/) != -1) ? true : false;
function addEvent(oElement,strEvent,oFunction,bCapture){
    if (oElement.addEventListener) {
        oElement.addEventListener(strEvent, oFunction, bCapture);
    }
    else if (oElement.attachEvent) {
        oElement.attachEvent(("on" + strEvent), oFunction);
    }
}
function clickSubmitButton(oEvent,strButtonId){
	if(oEvent&&oEvent.keyCode==13){
		var oButton=document.getElementById(strButtonId);
		if(oButton){
			oButton.click();
			oEvent.returnValue=false;
			if(oEvent.preventDefault){oEvent.preventDefault();}
			return false;}}	
}
addEvent(window,"load",onLoadFunctionality,false);
function getElementsByClassName(oElm,strTagName,strClassName){
	var arrElements=(strTagName=="*"&&document.all)?document.all:oElm.getElementsByTagName(strTagName);
	var arrReturnElements=new Array();
	strClassName=strClassName.replace(/\-/g, "\\-");
	var oRegExp=new RegExp("(^|\\s)"+strClassName+"(\\s|$)");
	var oElement;
	for(var i=0;i<arrElements.length;i++){
		oElement=arrElements[i];		
		if(oRegExp.test(oElement.className)){arrReturnElements.push(oElement);}	
	}
	return (arrReturnElements);
}

function setFormAction(action){
	document.forms[0].action = action;
	document.forms[0].method = "post";
	if ($("input[type='file']").length > 0) {
	    document.forms[0].encoding = "multipart/form-data";
	}
}
function fillDropDown(arrOptions){
	if(arrOptions!==null){
		if(oDropDownToFill){
			var selectedOption=oDropDownToFill.value;
			var oOption;
			var arrayOption;	
			for(var i=(oDropDownToFill.options.length-1);i>=0;i--){oDropDownToFill.options[i].parentNode.removeChild(oDropDownToFill.options[i]);}
			for(var j=0;j<arrOptions.length;j++){
				arrayOption=arrOptions[j];
				if(arrayOption!==null){
					oOption = document.createElement("option");
					oOption.setAttribute("value", arrayOption.value);
					oOption.innerHTML = arrayOption.text;
					if (arrayOption.value == selectedOption) {
					    oOption.selected = true;
					}
						
					oDropDownToFill.appendChild(oOption);
			}}
			oDropDownToFill = null;
}}}
function fillDropDownWithIdentifier(strId,arrOptions){
	if(arrOptions!==null){
		var oDropDownToFill=document.getElementById(strId);
		if (oDropDownToFill){
			var selectedOption=oDropDownToFill.value;
			var oOption;
			var arrayOption;			
			for(var i=(oDropDownToFill.options.length-1);i>=0;i--){oDropDownToFill.options[i].parentNode.removeChild(oDropDownToFill.options[i]);}
			for(var j=0;j<arrOptions.length;j++){
				arrayOption=arrOptions[j];
				if(arrayOption!==null){
					oOption=document.createElement("option");
					oOption.setAttribute("value",arrayOption.value);
					oOption.innerHTML=arrayOption.text;
					if(arrayOption.value == selectedOption) {
						oOption.selected = true;
					}						
					oDropDownToFill.appendChild(oOption);
}}}}}


var 
    globalCommonDialogElement,
    globalCommonDialogControl;

// New version of showInfoLayer based on the TUI.Web.UI.WebControls.Dialog MS AJAX control, replace old showInfoLayer() with this one whenever and wherever you can
function showInfoLayerNewVersion(dynamicUrl, width, height, targetElement){
    if (globalCommonDialogControl != null){
        Sys.Application.removeComponent(globalCommonDialogControl);
        $(globalCommonDialogElement).remove();
    }
    
    globalCommonDialogElement = $("<div id='global-common-dialog'></div>").appendTo(targetElement ? $(targetElement).parent() : document.body).get(0);
    globalCommonDialogControl = new TUI.Web.UI.WebControls.Dialog(globalCommonDialogElement);

    globalCommonDialogControl.beginUpdate();
    globalCommonDialogControl.set_innerHtmlTop(String.format("<div class='dialog-top-print' style='float: right; font-weight: normal; cursor: pointer;'>{0}</div>{1}", strCaptionPrint, strHelpInfo));
    globalCommonDialogControl.set_dynamicServiceFullPath(dynamicUrl);
    globalCommonDialogControl.set_isDraggable(true);
    $(globalCommonDialogElement).find('div.dialog-top-print').click( function() { printHTML($(globalCommonDialogElement).find('div.dialog-center-inner').html()); } );
    
    if (targetElement) {
        globalCommonDialogControl.set_targetControl(targetElement);
        globalCommonDialogControl.set_dialogPosition(TUI.Web.UI.WebControls.DialogPosition.nearTargetInsideClient);
    }
    
    globalCommonDialogControl.endUpdate();
    
    if (width) {
        $(globalCommonDialogElement).width(width);
    }
    
    if (height) {
        $(globalCommonDialogElement).find('div.dialog-center-inner').height(height);
    }
    
    globalCommonDialogControl.show();    
    Sys.Application.addComponent(globalCommonDialogControl);
}

var 
    globalCommonHelpPopupDialogElement,
    globalCommonHelpPopupDialogControl;

function registerHelpTextPopups(container) {
    $(container ? container : document).find('a.help-text-popup').click(function(e) {
            var 
                helpSection = this.rel.split("|")[0],
                helpPage = this.rel.split("|")[1];

            if (globalCommonHelpPopupDialogControl != null) {
                if (globalCommonHelpPopupDialogControl.get_targetControl() == this) {
                    return; // A dialog is already attached to the help link - let it take care of hiding and showing or whatever
                }
                else {
                    Sys.Application.removeComponent(globalCommonHelpPopupDialogControl);
                    $(globalCommonHelpPopupDialogElement).remove();
                }
            }

            globalCommonHelpPopupDialogElement = $("<div id='help-text-dialog'></div>").appendTo($(this).parent()).get(0);
            globalCommonHelpPopupDialogControl = new TUI.Web.UI.WebControls.Dialog(globalCommonHelpPopupDialogElement);
            globalCommonHelpPopupDialogControl.beginUpdate();
            globalCommonHelpPopupDialogControl.set_innerHtmlTop(this.title);
            globalCommonHelpPopupDialogControl.set_dynamicServiceFullPath(oBaseAjaxUrls.DynamicContent + 'GetEPiHelpPage.aspx?helpSection=' + helpSection + '&helpPage=' + helpPage);                       
            globalCommonHelpPopupDialogControl.set_isDraggable(true);
            globalCommonHelpPopupDialogControl.set_targetControl(this);
            globalCommonHelpPopupDialogControl.set_dialogPosition(TUI.Web.UI.WebControls.DialogPosition.nearTargetInsideClient);
            globalCommonHelpPopupDialogControl.endUpdate();

            globalCommonHelpPopupDialogControl.show();

            Sys.Application.addComponent(globalCommonHelpPopupDialogControl);
    });
}



function addHelpInfoEvents(){
	$("a.help-info-new-version").click( function (event) { displayHelpInfoNewVersion(event,event.target); } );
	$("a.help-info, a.help-info-no-book").click (function (event) { displayHelpInfo(event,event.target); } );
	$("a.help-info-window").click(function (event) {
			event.returnValue=false;
			event.preventDefault();			
			var w=screen.availWidth;
			var h=screen.availHeight;
			var popW=835,popH=710;
			var leftPos=(w-popW)/2,topPos=(h-popH)/2;				
			OpenWindow(this.getAttribute("href"),835,710,"toolbar=false,directories=false,menubar=false,scrollbars=yes,resizable=false,status=false,left = "+leftPos+",top = "+topPos+" '");
			return false;
	});
}
var infoContent = document.createElement("div");
function displayHelpInfo(oEvent,oElm){
	if (oElm.tagName.toLowerCase()!="a"){oElm=oElm.parentNode;}
	var strURL=oElm.getAttribute("href");
	oEvent.returnValue=false;
	oEvent.preventDefault();
	getXML(strURL, infoContent, _displayHelpInfo);
}
function displayHelpInfoNewVersion(oEvent,oElm)
{
	if (oElm.tagName.toLowerCase()!="a"){oElm=oElm.parentNode;}
	var strURL=oElm.getAttribute("href");
	oEvent.returnValue=false;
	oEvent.preventDefault();
	showInfoLayerNewVersion(strURL, null, null, oElm);
}
function _displayHelpInfo() {
	showInfoLayer(null,infoContent.innerHTML,400);
}
function OpenWindow(url,width,height,features){
	width=(width>0)?",width="+width:"";
	height=(height>0)?",height="+height:"";
	features=(features!=null)?","+features:"";	
	var newWin=window.open(url,'',""+width+""+height+""+features);
	newWin.focus();
}
//--- End Printfunctions ---//
/*** hideOrShowElements -	hides or shows multiple elements (comma separated list of id's)
 *							by altering style.display to and from 'none' and ''
 * @param show				- true if the elements should be shown, otherwise false
 * @param elementsToAffect	- comma separated list of id's
 */
function hideOrShowElements(show,elementsToAffect){
	if ((show==true||show==false)&&elementsToAffect){
		var arrOfIdsToAffect=elementsToAffect.split(",");
		for(idOfElement in arrOfIdsToAffect){
			try{
				var ctrl=document.getElementById(arrOfIdsToAffect[idOfElement]);
				if (ctrl)
					ctrl.className=(show==true?'':'display-none');
			}catch(e){}}}	
}
/*** openElementAndPrint - opens the named element in a new window and prints
 * @param element			- id or reference to the element to print
 * @param elementsToHide	- comma separated string of id's for items to hide before print and show after*/
function openElementAndPrint (element,elementsToHide,ignorePrintEvent){
	if (elementsToHide){hideOrShowElements (false, elementsToHide);}
	var prtContent=typeof element=="object"?element:document.getElementById(element);
	printHTML(prtContent.innerHTML,ignorePrintEvent);
	if (elementsToHide) {
	    hideOrShowElements(true, elementsToHide);
	}
}
function printExpandablePanel(elementId, preHTML, postHTML){
	var 
		infoContainer=document.getElementById(elementId),
		infoBox=getElementsByClassName(infoContainer,"div","box-extra-info")[0],
		allBoxes=getElementsByClassName(infoContainer,"div","box-extra-info-expand");
    
	for(i=0;i<allBoxes.length;i++){allBoxes[i].className = "box-extra-info-expand display-block";}
	infoBox.style.display="none";	
	printHTML((preHTML ? preHTML : '') + infoContainer.innerHTML + (postHTML ? postHTML : ''));
	for(i=0;i<allBoxes.length;i++){allBoxes[i].className="box-extra-info-expand display-none";}
	infoBox.style.display="block";	
}
function printHTML(htmlCode,ignorePrintEvent){
	var useScrollBars = (!ignorePrintEvent) ? '0' : '1';
	var WinPrint=window.open('','','left=0,top=0,width=700,height=500,toolbar=1,scrollbars=' + useScrollBars + ',status=0,resizable=1,menubar=1');		
	WinPrint.document.write('<html>\n');
	WinPrint.document.write('	<head>\n');
	WinPrint.document.write('		<link rel="stylesheet" type="text/css" href="' + oBaseAppSettings.IncludeSiteDirectory + '/Css/BlueSites/general.css" />\n');
	if(isTemaSite){
	    WinPrint.document.write('		<link rel="stylesheet" type="text/css" href="' + oBaseAppSettings.IncludeSiteDirectory + '/Css/Tema/general.css" />\n');		
	}
	WinPrint.document.write('		<link rel="stylesheet" type="text/css" href="' + oBaseAppSettings.IncludeSiteDirectory + '/Css/BlueSites/print.css" media="print, screen" />\n');
	WinPrint.document.write('		<!--[if lt IE 6]>\n');
	WinPrint.document.write('			<link rel="stylesheet" type="text/css" href="' + oBaseAppSettings.IncludeSiteDirectory + '/Css/BlueSites/ie5.css"  />\n');
	WinPrint.document.write('		<![endif]-->\n');
	WinPrint.document.write('		<!--[if lt IE 7]>\n');
	WinPrint.document.write('			<link rel="stylesheet" type="text/css" href="' + oBaseAppSettings.IncludeSiteDirectory + '/Css/BlueSites/ie.css" />\n');
	WinPrint.document.write('		<![endif]-->\n');
	WinPrint.document.write('	</head>\n');
	WinPrint.document.write('	<body>\n');
	WinPrint.document.write('		<form>\n');
	WinPrint.document.write('			<div width="700" height="700" style="margin: 10px;">\n');
	WinPrint.document.write(htmlCode);
	WinPrint.document.write('			</div>\n');
	WinPrint.document.write('		</form>\n');
	WinPrint.document.write('	</body>\n');
	WinPrint.document.write('</html>\n');
	WinPrint.document.close();	
	if (!ignorePrintEvent) 
	{
		WinPrint.print();
		WinPrint.close();
	}
}
function addPrintEvent(){
	var oPrintButton=document.getElementById("print-button");
	var oPrintButton5=document.getElementById("print-button5");
	if(oPrintButton){	
		oPrintButton.onclick=function(oEvent){
			var oEvent=(typeof oEvent!="undefined")?oEvent:event;
			oEvent.returnValue=false;
			if(oEvent.preventDefault){oEvent.preventDefault();}		
			var w=screen.availWidth;
			var h=screen.availHeight;
			var popW=800,popH=780;
			var leftPos=(w-popW)/2,topPos=(h-popH)/2;
			var _width=parseInt(document.getElementById("left-and-main").offsetWidth.toString().replace(/px/i,''))+50;			
			var oNewWindow=window.open((location.href.replace(/travel.aspx/i,'print.aspx')+'?print=true'),"",("width="+_width)+",scrollbars=yes,left = "+leftPos+",top = "+topPos);
	}}	
	if(oPrintButton5){
		oPrintButton5.onclick=function(oEvent){
			var oEvent=(typeof oEvent!="undefined")?oEvent:event;
			oEvent.returnValue=false;
			if(oEvent.preventDefault){oEvent.preventDefault();}
			var w=screen.availWidth;
			var h=screen.availHeight;
			var popW=800,popH=780;
			var leftPos=(w-popW)/2,topPos=(h-popH)/2;
			var oNewWindow = window.open((location.href.replace(/travel.aspx/i, 'print.aspx') + '&print=true'), "", ("width=" + document.getElementById("hotel-comparison").offsetWidth) + ",scrollbars=yes,left = " + leftPos + ",top = " + topPos);	
	}}
	if (location.href.search(/print=true/i) != -1) {
		setTimeout("window.print()", 200);
		setTimeout("window.close()", 300);
	}
}
// Finns en funktion med samma namn i Contentblocks.js En borde bort!?
var oDropDown = null;
var oDropDownToFill = null;
function addDynamicDropDownEvents(){
	var oSelectedBookingType = document.getElementById("selected-booking-type");
	var arrAllDynamicDropDowns=getElementsByClassName(document,"select","dynamic-dropdown");	
	for(var i=0; i<arrAllDynamicDropDowns.length; i++){
		var divValidation=getElementsByClassName(document, "div", "validation-message");
		if (divValidation.length==0){
			switch (arrAllDynamicDropDowns[i].className.replace(/.*type-(\w+)(\b.*|$)/i, "$1")){
				case 'resortStart':
					arrAllDynamicDropDowns[i].options.selectedIndex=0;
					var selectResort=document.getElementById("select-resort");
					if (selectResort){selectResort.options.selectedIndex=0};
				break;
		}}
		arrAllDynamicDropDowns[i].onchange=function(){		
			var strClassName=this.className;			
			var strType=strClassName.replace(/.*type-(\w+)(\b.*|$)/i, "$1");
			var strId=this.options[this.options.selectedIndex].value;			
			if(strId!=''&&strId!=null){
				if(strType=='resort'){			
					var depCode=arrAllDynamicDropDowns[0].value;
					var strURL = "/BlueSites/Templates/DynamicContent/GetDropDownItems.aspx?type=" + strType + "&id=" + strId + "&dep=" + depCode;
				}
				else if(strType=='resortStart'){
					var depCode=arrAllDynamicDropDowns[0].value;
					var strURL = "/BlueSites/Templates/DynamicContent/GetDropDownItems.aspx?type=" + strType + "&id=" + strId + "&dep=" + depCode;
				}
				else if (strType == 'cat_entry') { var strURL = "/BlueSites/Templates/DynamicContent/GetDropDownItems.aspx?type=" + strType + "&id=" + strId; }			
				else{
				    var strURL = "/BlueSites/Templates/DynamicContent/GetDropDownItems.aspx?strBookingType=" + oSelectedBookingType.value + "&type=" + strType + "&id=" + strId;
					oDropDown=this;
					var	sec=getElementsByClassName(document,"select","element-to-fill-return-date");
					if(sec!=null&&sec.length>0&&strClassName.indexOf("element-to-fill-return-date")==-1){setTimeout("SetSec()",100);}
				}			
				var strIdOfElementToFill=strClassName.replace(/.*element-to-fill-([\w\d\-]+)(\b.*|$)/i, "$1");
				getJavaScriptArrayWithIdentifier(strIdOfElementToFill,strURL,"fillDropDownWithIdentifier");				
				var stringToSave=document.getElementById("postbackXml");
				if(stringToSave){
					var PickedTd=document.getElementById("PickedTd");
					var array=this.options[this.options.selectedIndex].value.split("_");	
					var destinationName=this.options[this.options.selectedIndex].text.replace("-","");	
					if(destinationName.indexOf(" ")==0)
						destinationName=destinationName.substring(1,destinationName.length);
						
					stringToSave.value=array[1]+"|"+destinationName;	 
					PickedTd.innerHTML=destinationName;					
				}}};
arrAllDynamicDropDowns[i].onchange();
}}

ClientXY = function(oEvent) {
	intOffsetX = (oEvent.offsetX) ? oEvent.offsetX : 0;
	intOffsetY = 0;
	intScrollLeft = (window.pageXOffset) ? window.scrollX : oBodyElmForIE.scrollLeft;
	intScrollTop = (window.pageYOffset) ? window.scrollY : oBodyElmForIE.scrollTop;
	this.x = (oEvent.clientX - intOffsetX) + intScrollLeft;
	this.y = (oEvent.clientY - intOffsetY) + intScrollTop;
	this.offsetX = intOffsetX;
	this.scrollLeft = intScrollLeft;
}

//  TWINGLY
var tw_language = "swedish";
//var tw_url = "http://www.fritidsresor.se/";
var tw_onComplete = function() {
    $("div.tw_header").html("").append($("div.tw-box span.tw-header"));
    $("div.tw_lw_c").children("div").html("").append($("div.tw-box span.tw-noblogs-header")).append($("div.tw-box span.tw-noblogs-footer"));
    $("div.tw_footer").append($("div.tw_sub_header a").html("").append($("div.tw-box span.tw-footer")));
};

/* Close the panel on fun-staff pages. Called from ContentBlock "/BlueSites/Templates/ContentBlocks/CheckoutWeather.ascx" */
function addCloseWeatherPanel() {
    $("a.close-link-weather").click(function() {
        $("div#weatherDIV").removeClass("display-block").fadeOut("slow");
        $("div#weatherDIVInfo").fadeIn("slow");
        return false;
    });
}

$(document).ready(function() {
    registerHelpTextPopups(document);
});        