﻿
var mousePosX;
var mousePosY;

function init() {
	try {
		var selectedMenue = document.getElementById("ctl00_txtMenueID_Selected").value;
		var menueObj = document.getElementById("menueList_" + selectedMenue);
		menueObj.style.borderBottom = "solid 3px black";
	} catch (e) {
		alert("Länken fungerade ej.")
	}
	try {
		PageInit();
		//IsCookieEnabled();
	} catch (e) {
		//alert("Page Init() genererade ett fel.")
	}

}
function PageInit() {
	// empty function
	// if same function exists in ContentPage then that function overrides this one
	// this makes it possible for each contentpage to set their one onload functions
}
function IsCookieEnabled() {
	try {
		var data = "";
		data = "inSessionID=" + $("#ctl00_hiddenGUID").val();
		makePostReq("wsFunctions.asmx/IsCookiesEnabled", data, "ctl00_lblCookieEnabled", "", "text")
	} catch (e) {
	alert("IsCookieEnabled(): " + e.description);
	}
}
function goToPage(inURL) {
	try {
		//document.getElementById("menueList_"+ )
	} catch (e) { 
		//alert("Länken fungerade ej.")
	}
}

function OpenArchive(inYear) {
	try {
		var obj = getObj("Archive_" + inYear);
		obj.style.display = (obj.offsetHeight == "0") ? "inline" : "none";
	} catch (e) { 
		//alert("OpenArchive fungerar inte.")
	}
}
function OpenYear(inYear) {
	try {
		getObj("diary_content").innerHTML = getObj("Year_" + inYear).innerHTML;

    //$("#diary_content div").css("border-left", "solid 2px silver")
    //$("#diary_content div").css("padding-left", "15px")
		
		$("#diary_content div div").each(function() {
			$(this).css("border-left", "dotted 2px black");
			$(this).css("padding-left", "10px");
		})
		
		/*$("#diary_content div").each(function() {
			$(this).find("p:last").css("border-bottom", "dotted 2px black");
			$(this).find("p:last").css("padding-bottom", "10px");
		})*/  
		
	} catch (e) {
		//alert("OpenYear fungerar inte.")
	}
}
function OpenMonth(inMonth) {
	try {
		getObj("diary_content").innerHTML = getObj("Month_" + inMonth).innerHTML;
		
		$("#diary_content div").each(function() {
			$(this).css("border-left", "dotted 2px black");
			$(this).css("padding-left", "10px");
		})

		//var obj = getObj("Month_" + inMonth).style;
		//obj.display = (obj.display == "inline") ? "none" : "inline";
	} catch (e) {
		//alert("OpenMonth fungerar inte.")
	}
}

function GetImages(inImageIndex){
	try {
	  //alert("Hämta bilder via AJAX")
		//return document.getElementById(inImageIndex);
	} catch (e) { 
		//alert("Bildarkiv "+ inImageIndex +" kunde inte hittas.")
	}
}

function getObj(inID){
	try {
		return document.getElementById(inID);
	} catch (e) { 
		//alert("ID "+ inID +" kunde inte hittas på sidan.")
	}
}
function ToggleDisplay(inID){
	try {
		if ($("#" + inID).css("display")=="none"){
		  $("#" + inID).css("display", "inline");
		}else{
		  $("#" + inID).css("display", "none");
		}
	} catch (e) { 
		//alert("ToggleDisplay() genererade ett fel")
	}
}

function ShowMsg(msg, centerOfScreen, width) {
	try {
		if (mousePosX == undefined || mousePosY == undefined || centerOfScreen == true) {
			mousePosX = 150; //parseInt($(document).width()) / 2
			mousePosY = parseInt($(document).height()) / 2
		}
		var x = (mousePosX - 100) + "px";
		var y = (mousePosY + 15) + "px";

		$('#message_box').css("top", mousePosY);
		$('#message_box').css("left", x);
    
    if (width != undefined) {
      
      $('#message_box').css("width", (width+50) +"px");
      $('#message_box_text').css("width", width +"px")
    }
		$('#message_box_text').html(msg);

		//when the close button at right corner of the message box is clicked
		$('#message_box').click(function() {
			//the messagebox gets scrool down with top property and gets hidden with zero opacity
			$('#message_box').animate({ top: mousePosY + "px", opacity: "hide" }, "slow");
		});

		$('#message_box').animate({ top: y, left: x, opacity: "show" }, "slow");
	} catch (e) { alert("ShowMsg: "+ e.description) }
}
function ConfirmMsg(msg) {
  var retVal = "notset";
  retVal = jqDialog.confirm(msg,true,false);
  return retVal
  //confirm(msg,
  //  function() { alert('ja'); },
  //  function() { alert('nej'); }
  //);
}


$(document).ready(function(){
  try{
    //scroll the message box to the top offset of browser's scrool bar
    $(window).scroll(function(){
      $('#message_box').animate({top:$(window).scrollTop()+"px" },{queue: false, duration: 50});
    });
    
    $(document).mousemove(function(e){     
      mousePosX = e.pageX
      mousePosY = e.pageY
    });
  }catch(e){
    alert("document.ready: "+ e.description)
  }
});



/**************************************************************/
/* jsLib.js */
		
function makeAjaxReq(strURL, strData, strTargetID, strLoaderID, strType, strDataType) {
	try {
		strType = (strType =! undefined && strType != "") ? "GET" : "POST";
		strDataType	= (strDataType =! undefined && strDataType != "") ? "xml" : "text";
		toggleLoader(strLoaderID, true);
		$.ajax({
			type: strType,
			url: strURL,
			dataType: strDataType,
			data: strData,
			success:
				function(data) {
					try {
						$("#" + strTargetID).html($(data).text());
						toggleLoader(strLoaderID, false);
					} catch (e) {
						alert("Fel uppstod i callback-funktionen i AJAX.\n" + e.description);
					}
				}
		});
	} catch (e) {
		//alert("makeAjaxReq():" + e.description)
	}
}

function toggleLoader(strLoaderID, bolShow) {
	try {
		if (strLoaderID != undefined && strLoaderID != "") {
			var strText = (bolShow == true) ? "<img src=\"includes/images/loader.GIF\" height=\"16\" width=\"16\" />" : "";
			$("#" + strLoaderID).html(strText);
		}
	} catch (e) {
		//alert("toggleLoader():" + e.description)
	}
}

function makeGetReq(strURL, strData, strTargetID, strLoaderID, strDataType) {
	try {
		strType = "GET";
		//strDataType = "html";
		toggleLoader(strLoaderID, true);
		$.ajax({
			type: strType,
			url: strURL,
			dataType: strDataType,
			data: strData,
			success:
				function(data) {
			try {
				//alert(data)
						document.getElementById(strTargetID).innerHTML = data
						//$("#" + strTargetID).html(data);
						//toggleLoader(strLoaderID, false);
					} catch (e) {
						alert("Fel uppstod i callback-funktionen i AJAX.\n" + e.description);
					}
				}
		});
	} catch (e) {
	//alert("makeGetReq():" + e.description)
	}
}
function makePostReq(strURL, strData, strTargetID, strLoaderID, strDataType) {
	try {
		strType = "POST";
		toggleLoader(strLoaderID, true);
		$.ajax({
			type: strType,
			url: strURL,
			dataType: strDataType,
			data: strData,
			success:
				function(data) {
					try {
						/*var result="";
						$("string", data).each(function() {
							result += $(this, "xml").text() + "###";
						});*/

						$("#" + strTargetID).html($(data).text());
						toggleLoader(strLoaderID, false);
					} catch (e) {
						alert("Fel uppstod i callback-funktionen i AJAX.\n" + e.description);
					}
				}
		});
	} catch (e) {
	}
}


/********************************************************/
/* jquery.ui.potato.menu */
/* Copyright (c) 2009-2010 makoto_kw, http://www.makotokw.com
 * Licensed under the MIT license.
 * @author makoto_kw
 * @version 1.0
*/
(function($) {
	var defaults = {
		vertical:false,
		menuItemSelector: 'li',
		menuGroupSelector: 'ul',
		rootClass:'potato-menu',
		menuItemClass:'potato-menu-item',
		menuGroupClass:'potato-menu-group',
		verticalClass:'potato-menu-vertical',
		holizontalClass:'potato-menu-holizontal',
		hasVerticalClass:'potato-menu-has-vertical',
		hasHolizontalClass:'potato-menu-has-holizontal',
		hoverClass:'potato-menu-hover',
		showDuration: 20,
		hideDuration: 20
	}
	function menu() {
		var option = (typeof(arguments[0])!='string') ? $.extend(defaults,arguments[0]) : $.extend(defaults,{});
		var $menu = $(this).addClass(option.rootClass+' '+option.menuGroupClass).addClass((option.vertical) ? option.verticalClass : option.holizontalClass);
		var $menuItems = $menu.find(option.menuItemSelector).addClass(option.menuItemClass);
		var $menuGroups = $menu.find(option.menuGroupSelector).addClass(option.menuGroupClass);
		
		$menuItems.hover(
			function(e) {
				$(this).addClass(option.hoverClass);
			},
			function(e) {
				$(this).removeClass(option.hoverClass);
			}
		);
		$menuGroups.parent().each(function(index){
			var $parentMenuItem = $(this); // menu item that has menu group
			var displayDirection = ($parentMenuItem.parent().hasClass(option.holizontalClass)) ? 'bottom' : 'right';
			$parentMenuItem.addClass((displayDirection=='bottom') ? option.hasVerticalClass : option.hasHolizontalClass);
			var $menuGroup = $parentMenuItem.find(option.menuGroupSelector+':first').addClass(option.verticalClass);
			$parentMenuItem.hover(
				function(e) {
					var offset = (displayDirection=='bottom') ? {left:'0',top:''} : {left:$(this).width()+'px',top:'0'};
					$menuGroup.css({left:offset.left,top:offset.top}).fadeIn(option.showDuration);
				},
				function(e) {
					$menuGroup.fadeOut(option.hideDuration);
				}
			);
		});
		$menu.find('a[href^="#"]').click(function() {
			$menuGroups.fadeOut(option.hideDuration);
			return ($(this).attr('href') != '#');
		})
		return this;
	}
	$.fn.extend({
		ptMenu:menu
	});
})(jQuery);

/*************************************************************/
/** jqDialog.js
	Kailash Nadh,	http://kailashnadh.name
	August 2009
	Smooth popup dialog for jQuery

	License:	GNU Public License: http://www.fsf.org/copyleft/gpl.html
	
	v1.2.1	September 5 2009
**/
var jqDialog=new function(){this.strOk='Ok';this.strYes='Ja';this.strNo='Nej';this.strCancel='Avbryt';this.strX='X';this.closeTimer=null;this.width=0;this.height=0;this.divBoxName='jqDialog_box';this.divBox=null;this.divContentName='jqDialog_content';this.divContent=null;this.divOptionsName='jqDialog_options';this.divOptions=null;this.btCloseName='jqDialog_close';this.btClose=null;this.btYesName='jqDialog_yes';this.btYes=null;this.btNoName='jqDialog_no';this.btNo=null;this.btOkName='jqDialog_ok';this.btOk=null;this.btCancel='jqDialog_ok';this.btCancel=null;this.inputName='jqDialog_input';this.input=null;this.confirm=function(message,callback_yes,callback_no){this.createDialog(message);this.btYes.show();this.btNo.show();this.btYes.focus();this.btOk.hide();this.btCancel.hide();this.btYes.unbind().click(function(){jqDialog.close();if(callback_yes)callback_yes();});this.btNo.unbind().click(function(){jqDialog.close();if(callback_no)callback_no();});};this.prompt=function(message,content,callback_ok,callback_cancel){this.createDialog($("<p>").append(message).append($("<p>").append($(this.input).val(content))));this.btYes.hide();this.btNo.hide();this.btOk.show();this.input.focus();this.btCancel.show();this.btOk.unbind().click(function(){jqDialog.close();if(callback_ok)callback_ok(jqDialog.input.val());});this.btCancel.unbind().click(function(){jqDialog.close();if(callback_cancel)callback_cancel();});};this.alert=function(content,callback_ok){this.createDialog(content);this.btCancel.hide();this.btYes.hide();this.btNo.hide();this.btOk.show();this.btOk.focus();this.btOk.unbind().click(function(){jqDialog.close();if(callback_ok)
callback_ok();});};this.content=function(content,close_seconds){this.createDialog(content);this.divOptions.hide();};this.notify=function(content,close_seconds){this.content(content);this.btClose.focus();if(close_seconds)
this.closeTimer=setTimeout(function(){jqDialog.close();},close_seconds*1000);};this.createDialog=function(content){clearTimeout(this.closeTimer);this.divOptions.show();this.divContent.html(content);this.divBox.fadeIn('fast');this.maintainPosition();};this.close=function(){this.divBox.fadeOut('fast');this.clearPosition();};this.clearPosition=function(){$(window).scroll().remove();};this.makeCenter=function(){$(jqDialog.divBox).css({top:((($(window).height()/2)-(($(jqDialog.divBox).height())/2)))+($(document).scrollTop())+'px',left:((($(window).width()/2)-(($(jqDialog.divBox).width())/2)))+($(document).scrollLeft())+'px'});};this.maintainPosition=function(){$(window).scroll(function(){jqDialog.makeCenter();});}
this.init=function(){this.divBox=$("<div>").attr({id:this.divBoxName});this.divContent=$("<div>").attr({id:this.divContentName});this.divOptions=$("<div>").attr({id:this.divOptionsName});this.btYes=$("<button>").attr({id:this.btYesName}).append(document.createTextNode(this.strYes));this.btNo=$("<button>").attr({id:this.btNoName}).append(document.createTextNode(this.strNo));this.btOk=$("<button>").attr({id:this.btOkName}).append(document.createTextNode(this.strOk));this.btCancel=$("<button>").attr({id:this.btCancelName}).append(document.createTextNode(this.strCancel));this.input=$("<input>").attr({id:this.inputName});this.btClose=$("<button>").attr({id:this.btCloseName}).append(document.createTextNode(this.strX)).click(function(){jqDialog.close();});this.divBox.append(this.btClose).append(this.divContent).append(this.divOptions.append(this.btYes).append(this.btNo).append(this.btOk).append(this.btCancel));this.divBox.hide();$('body').append(this.divBox);this.makeCenter();};};$(window).load(function(){jqDialog.init();});
