
$(document).ready(function()
{
	// finner window size og scroll
	arrayPageSize = new Array($(window).width(),$(window).height(),$(window).scrollTop(),$(window).scrollLeft()) 
	
	// setter css høyde
	$("#background").css("height", $(document).height() - 4).hide();
	$(window).resize(function()
	{
		$("#background").css("height", $(document).height() - 4).hide();
	});

	// setter standard tekstinnhold for tekstbokser
	$(".standard_textbox").focus(function()
	{
		if ($(this).val() == $(this)[0].title)
		{
			$(this).removeClass("defaultText");
			$(this).val("");
		}
	});
	$(".standard_textbox").blur(function()
	{
		if ($(this).val() == "")
		{
			$(this).addClass("defaultText");
			$(this).val($(this)[0].title);
		}
	});
	
	// justerer teksthøyde for standard knapper	
	if($.browser.msie != true)
	{
		$('.button_24, .button_94, .standard, .submit, .cancel').css({'padding-bottom': '3px'});
	}
	
	// setter hover (mouseover) for standard knapper	
	$('.standard, .submit, .cancel').hover(function ()
	{
		$(this).addClass('button_hover');
	}, function ()
	{
		$(this).removeClass('button_hover');	
	});
});

//********************************************************

function Navigate(side,target)
{
	if (target == 0)
	{
		window.location.href = side;		
	}
	else
	{
		window.open(side,target);
	}
}

function ChangeVisibility(inn_ut)
{
	if ($("#"+inn_ut+"").is(":hidden"))
	{
		$("#"+inn_ut+"").slideDown("slow");
	}
	else
	{
		$("#"+inn_ut+"").slideUp("slow");
	}
}
	
function ChangeInOut(inn,ut)
{
	if ($("#"+inn+"").is(":hidden"))
	{
		$("#"+inn+"").slideDown("slow");
		$("#"+ut+"").slideUp("slow");
	}
	else
	{
		$("#"+inn+"").slideUp("slow");
		$("#"+ut+"").slideDown("slow");
	}
}

function VerifyHighSlide(width,height,text,id)
{
	hs_width = width;
	hs_height = height;
	hs_headingText = text;
	document.getElementById("highslide_innhold").setAttribute("id",id);
	document.getElementById(id).onclick()
	document.getElementById(id).setAttribute("id","highslide_innhold");
}

function CloseHighSlide()
{
	hs.close()
}

function Favoritter(e,url,title)
{
	if (window.event)
	{
		window.external.AddFavorite(url,title);
	}
	else if (e.which)
	{
		window.sidebar.addPanel(title,url,"");
	}
}

//********************************************************

function setLoadBox()
{
	$("body").append(
	"<div class=\"load_box\" id=\"load_box\">"	
	+ "<table class=\"load_box_table\">"
	+ "<tr>"
	+ "<td align=\"center\"><img border=\"0px\" src=\"http://" + location.hostname + "/ikoner/loading17.gif\" width=\"66px\" height=\"66px\"></td>"
	+ "</tr>"
	+ "</table>"
	+ "</div>"
	);
}

function dimBackground(inn_ut,sec)
{
	if (inn_ut == "inn")
	{
		$("#background").css("display", "block");
		ShowLoadBox(arrayPageSize);
		if (sec > 0)
		{
			window.setTimeout(function()
			{
				HideLoadBox();
				dimBackground("ut","");
			}, sec);
		}				
	}
	else if (inn_ut == "ut")
	{
		HideLoadBox();
		$("#background").css("display", "none");
	}
}

function ShowLoadBox(size)
{
	setLoadBox();
	var arrayPageSize = size;
	var windowWidth = arrayPageSize[0]
	var windowHeight = arrayPageSize[1]
	var windowScrollTop = arrayPageSize[2]
	if (windowScrollTop > 0)
	{
		windowHeight = windowHeight / 2 + windowScrollTop - 65;
	}
	else
	{
		windowHeight = windowHeight / 2 - 65;	
	}
	document.getElementById("load_box").style.left = (windowWidth / 2 - 60) + "px";
	document.getElementById("load_box").style.top = (windowHeight) + "px";
	document.getElementById("load_box").style.visibility = "visible";		
}

function HideLoadBox()
{
	$(".load_box").remove();
}

//********************************************************
// For "forms"
//********************************************************

function FormStyle(formName,elementWidth,focusElement)
{
	var fontFamily = 'Tahoma';
	var fontSize = '12';
	var fontColor = '000000';
	var fontWeight = 'normal';
	var textBoxWidth = elementWidth;
	var textAreaHeight = elementWidth / 2;
	var selectWidth  = elementWidth + 7;
	var buttoWidth = elementWidth / 2.2;
	var setFocusTo = focusElement;
	$("#" + formName + " :input").each(function()
	{
		$(this).wrap("<label />");	
		if ($(this).is("[type='text'], [type='password'], textarea"))
		{
			$(this).addClass("hover ui-state-default ui-corner-all");
			$(this).css({width: '' + textBoxWidth + 'px', 'padding': '4px'});
			$(this).bind
			({
				focusin: function()
				{
					$(this).toggleClass('ui-state-focus');
				},
				focusout: function()
				{
					$(this).toggleClass('ui-state-focus');
				}
			});			
		}
		if ($(this).is("textarea"))
		{
			$(this).css({height: '' + textAreaHeight + 'px'});
		}		
		if ($(this).is("[type='checkbox']"))
		{
			var element = this;
			$(element).parent("label").after("<span />");
			var parent =  $(element).parent("label").next();
			$(element).addClass("ui-helper-hidden");
			parent.css({width: '16px', height: '16px', 'display': 'block'});
			parent.wrap("<span class='ui-state-default ui-corner-all' style='display: inline-block; width: 16px; height: 16px; margin-right: 5px;'/>");
			parent.parent().addClass('hover');
			parent.parent("span").click(function(event)
			{
				$(this).toggleClass("ui-state-active");
				parent.toggleClass("ui-icon ui-icon-check");
				$(element).click();				
			});
		}
		if ($(this).is("[type='radio']"))
		{
			var element = this;
			$(element).parent("label").after("<span />");
			var parent =  $(element).parent("label").next();
			$(element).addClass("ui-helper-hidden");
			parent.addClass("ui-icon ui-icon-radio-off");
			parent.wrap("<span class='ui-state-default ui-corner-all' style='display: inline-block; width: 16px; height: 16px; margin-right: 5px;'/>");
			parent.parent().addClass('hover');
			parent.parent("span").click(function(event)
			{
				$(this).toggleClass("ui-state-active");
				parent.toggleClass("ui-icon-radio-off ui-icon-bullet");
				$(element).click();
			});
		}		
		if ($(this).is("select"))
		{
			$(this).selectmenu({'style': 'dropdown', width: '' + selectWidth + 'px', 'menuWidth': '' + selectWidth + 'px'});
		}
		if ($(this).is("button"))
		{		
			$(this).addClass("ui-button ui-button-text-only");
			$(this).button({icons:{primary: "ui-icon-transferthick-e-w"}});
			$(this).css({width: '' + buttoWidth + 'px', 'padding': '0px', 'outline': 'none'});
		}
		if($(this).hasClass("date"))
		{
			$(this).attr('readonly', true);
			$.datepicker.setDefaults($.datepicker.regional["no"]);
			$(this).datepicker
			({
				firstDay: 1,
				showWeek: true,
				showOtherMonths: true,
				selectOtherMonths: true,
				changeMonth: true,
				changeYear: true,
				defaultDate: '<%=DagensDato%>'	
			});			
		}		
	});
	$(".hover").hover(function()
	{
		$(this).addClass("ui-state-hover"); 
	},function()
	{ 
		$(this).removeClass("ui-state-hover");  
	});						   	
	$(".ui-widget").css({"font-size": "0.86em"});
	$(".ui-state-default").css({'font-family': '' + fontFamily + '', 'font-size': '' + fontSize + 'px', 'color': '#' + fontColor + '', 'font-weight': '' + fontWeight + ''});
	window.setTimeout(function(){document.getElementById(setFocusTo).focus()},500);
}

function UnlockForm(formName,resetForm)
{
	$("#" + formName + " :input").each(function()
	{
		if ($(this).is("[type='text'], [type='password'], textarea"))
		{
			$(this).attr("disabled", false)
			if (resetForm == true)
			{
				$(this).val('');
			}
		}
		if ($(this).is("[type='checkbox']"))
		{
			$(this).attr("disabled", false)
			if (resetForm == true)
			{
				$(this).attr("checked", false)
			}			
		}
		if ($(this).is("[type='radio']"))
		{
			$(this).attr("disabled", false)
			if (resetForm == true)
			{
				$(this).attr("checked", false)
			}			
		}
		if ($(this).is("select"))
		{
			$(this).attr("disabled", false)
		}
		if ($(this).is("button"))
		{
			$(this).attr("disabled", false)
		}
	});
}

function LockForm(formName)
{
	$("#" + formName + " :input").each(function()
	{
		if ($(this).is("[type='text'], [type='password'], textarea"))
		{
			$(this).attr("disabled", true)	
		}
		if ($(this).is("[type='checkbox']"))
		{
			$(this).attr("disabled", true)
		}
		if ($(this).is("[type='radio']"))
		{
			$(this).attr("disabled", true)
		}		
		if ($(this).is("select"))
		{
			$(this).attr("disabled", true)
		}
		if ($(this).is("button"))
		{
			$(this).attr("disabled", true)
		}
	});
}
