﻿/*
---------------------------------------------
Lägger till Target _blank och external-link 
klassen på alla länkar som pekar externt och 
inte har någon klass specificerad
---------------------------------------------
*/
Websajt.Utils.StyleExternalLinks = function() {
	$('a').each(function() {
		if (($(this).attr('href').indexOf('http://') > -1 && $(this).attr('href').indexOf(location.hostname) == -1) && $(this).attr('class').length == 0) {
			$(this).addClass('external-link');
			$(this).attr("target", "_blank")
		}
	});
}

/*
---------------------------------------------
Jämnar ut storleken på boxar
---------------------------------------------
*/
Websajt.Utils.EqualHeights = function(strSelector) {
	$(strSelector).equalHeights(true);
}

Websajt.Utils.EqualBoxHeights = function(strSelector) {
	$(strSelector).equalBoxHeights(true);
}

/*
---------------------------------------------
Visar felmeddelande för NOT NETS inbyggda 
formulärvalidering
---------------------------------------------
*/
Websajt.Utils.BubbleDotNet = function(strHeadline, strMessage, strId, posLeft, posTop, Zindex, type) {
	this.Headline = strHeadline,
    this.Message = strMessage,
    this.ElementID = strId,
    this.PositionLeft = posLeft,
    this.ZIndex = Zindex,
    this.Init = function() {

    	if (Zindex == null)
    		Zindex = 1000;
    	if (this.PositionLeft == null)
    		this.PositionLeft = 0;
    	if (type == null)
    		type = "";

    	var strHtml = "<div style=\"position:relative;\">";
    	strHtml += "<div class=\"bubble" + type + "\" id=\"" + this.ElementID + "Bubble\" style=\"z-index:" + this.ZIndex + "\">";
    	strHtml += "<div class=\"content\">";
    	strHtml += "<label class=\"headline\" style=\"display:block;\">" + this.Headline + "</label>";
    	strHtml += this.Message;
    	strHtml += "</div>"
    	strHtml += "<div class=\"bottom\"></div>";
    	strHtml += "</div>";
    	strHtml += "</div>";
    	$("#" + strId).prepend(strHtml);

    	//var pos = $("#" + this.ElementID).offset();
    	$("#" + this.ElementID + "Bubble").css({ left: (this.PositionLeft), top: -($("#" + this.ElementID + "Bubble").height() + (posTop + 10)) });
    	$("#" + this.ElementID + "Bubble").show();
    }
}
/*
---------------------------------------------
Meddelande rutor
---------------------------------------------
*/
Websajt.Utils.Bubble = function(strHeadline, strMessage, strId, posLeft, Zindex) {
	this.Headline = strHeadline,
    this.Message = strMessage,
    this.ElementID = strId,
    this.PositionLeft = posLeft,
    this.ZIndex = Zindex,
    this.Init = function() {

    	if (Zindex == null)
    		Zindex = 1000;
    	if (this.PositionLeft == null)
    		this.PositionLeft = 0;

    	var strHtml = "";
    	strHtml += "<div class=\"bubble\" id=\"" + this.ElementID + "Bubble\" style=\"z-index:" + this.ZIndex + "\">";
    	strHtml += "<div class=\"content\">";
    	strHtml += "<label class=\"headline\" style=\"display:block;\">" + this.Headline + "</label>";
    	strHtml += this.Message;
    	strHtml += "</div>"
    	strHtml += "<div class=\"bottom\"></div>";
    	strHtml += "</div>";
    	$(document.body).prepend(strHtml);

    	var pos = $("#" + this.ElementID).offset();
    	
    	$("#" + this.ElementID + "Bubble").css({ left: pos.left + (this.PositionLeft), top: pos.top - ($("#" + this.ElementID + "Bubble").height() + 45) });
    },
    this.Show = function() {
    	$("#" + this.ElementID + "Bubble").show();
    },
    this.Toggle = function() {
		if ($("#" + this.ElementID + "Bubble:visible").length > 0)
			$("#" + this.ElementID + "Bubble").hide();
    	else
    		$("#" + this.ElementID + "Bubble").show();
    },
    this.Hide = function() {
    	$("#" + this.ElementID + "Bubble").hide();
    }
}

Websajt.Utils.BubbleAlt = function(strHeadline, strMessage, strId, posLeft, posTop, Zindex) {
	this.Headline = strHeadline,
    this.Message = strMessage,
    this.ElementID = strId,
    this.PositionTop = posTop,
    this.PositionLeft = posLeft,
    this.ZIndex = Zindex,
    this.Init = function() {

    	if (Zindex == null)
    		Zindex = 1000;
    	if (this.PositionLeft == null)
    		this.PositionLeft = 0;

    	var strHtml = "";
    	strHtml += "<div class=\"bubble-alt\" id=\"" + this.ElementID + "Bubble\" style=\"z-index:" + this.ZIndex + "\">";
    	strHtml += "<div class=\"content\">";
    	strHtml += "<label class=\"headline\" style=\"display:block;\">" + this.Headline + "</label>";
    	strHtml += this.Message;
    	strHtml += "</div>"
    	strHtml += "<div class=\"bottom\"></div>";
    	strHtml += "</div>";
    	$(document.body).prepend(strHtml);
    	
    	var pos = $("#" + this.ElementID).offset();
    	$("#" + this.ElementID + "Bubble").css({ left: (pos.left + (this.PositionLeft)), top: pos.top + (this.PositionTop) });
    },
    this.Show = function() {
    	$("#" + this.ElementID + "Bubble").show();

    	$("#" + this.ElementID + "Bubble").click(function() {
    		$(this).hide();
    	})
    },
    this.Hide = function() {
    	$("#" + this.ElementID + "Bubble").hide();
    }
}

Websajt.Utils.RenderLinkSifr = function(strSelector, strColor, strHoverColor) {
		sIFR.replace(
		sIFR_DEFAULT, {
			selector: strSelector,
			css: [
				'.sIFR-root {}',
				'a { text-decoration: none; }',
				'a:link { color: ' + strColor + ' }',
				'a:hover { color: ' + strHoverColor + '; }'
				],
			fitExactly: true,
			wmode: 'transparent'
		});
	
}

Websajt.Utils.RenderSifr = function(strSelector, strColor) {
		sIFR.replace(
		sIFR_DEFAULT, {
			selector: strSelector,
			css: [
				'.sIFR-root {color: ' + strColor + '; }'
			],
			fitExactly: true,
			wmode: 'transparent'
		});
	
}

Websajt.Utils.SetPageOpacity = function(opacity1, opacity2, bgcolor, Zindex) {
	$("#opacity").remove();
	$("body").append("<div id=\"opacity\" class=\"opacity\" style=\"filter:alpha(opacity=" + opacity1 + ");-moz-opacity:." + opacity2 + ";opacity:." + opacity2 + "; z-index:" + Zindex + "; background-color:" + bgcolor + ";\"></div>");
	var intWidth = $(document).width();
	var intHeight = $(document).height();
	$("#opacity").css("width", intWidth + "px");
	$("#opacity").css("height", intHeight + "px");
}

Websajt.Utils.RemovePageOpacity = function() {
	$("#opacity").remove();
}

Websajt.Utils.Center = function(elementWidth,elementHeight,elementID) {
	var intWidth = $(window).width();
	var intHeight = $(window).height();
	$('#' + elementID).css("left", (intWidth / 2) - (elementWidth / 2))
	$('#' + elementID).css("top", (intHeight / 2) - (elementHeight / 2) + $(window).scrollTop())
}

Websajt.Utils.RenderTable = function() {
		// Every other tr has darker background
		$('table.data-table tbody').each(function() {
			$('tr:even td:not(.empty)', this).addClass('zebra');
		});

		// Every other td has even darker background
		$('table.data-table tbody tr').each(function() {
			$('td:not(.zebra):odd', this).addClass('zLight');
		});

		// Every other td has even darker background
		$('table.data-table tbody tr').each(function() {
			$('td.zebra:odd', this).addClass('zebraGray');
		});

		// Every other th has darker background
		$('table.data-table tbody').each(function() {
			$('th:odd', this).addClass('zebraDarkTh');
		});
}