﻿var prevTooltipTextElement = null;
function ShowTooltipText() {
	if (prevTooltipTextElement) {
		prevTooltipTextElement.css("display", "none");
	}
	var ttElement = jQuery("#" + arguments[0]);
	var jElement = jQuery("#" + arguments[1].id);
	var offset = jElement.offset();
	ttElement.css("left", offset.left - ttElement.outerWidth());
	ttElement.css("top", offset.top - ttElement.outerHeight());
	ttElement.css("display", "block");
	prevTooltipTextElement = ttElement;
}
function CloseTooltipText() {
	var ttElement = jQuery("#" + arguments[0]);
	ttElement.css("display", "none");
	prevTooltipTextElement = null;
}


jQuery(document).ready(function() {
    flashbgElement = jQuery("#flashbg");    
    bodyViewHeight = jQuery("body").height();
    containerHeight = jQuery(document).height();
    footerHeight = jQuery("#footer").height();
    
    if ((containerHeight - footerHeight) > bodyViewHeight) {

        flashbgElement.height(containerHeight);
    }
});


function RartAtVide(){
  if(jQuery("#rartatvide").html()) {

    var minTabel = jQuery("#rartatvide table:last");
    minTabel.css("display", "none");

    var firstTD2 = jQuery("#rartatvide table:last tr:first td:last");
    jQuery("#rartatvide_td2").append(firstTD2.text());

    var mineTR = jQuery("#rartatvide table:last tr");
    var mineTD = null;
    var arrSvar = [];

    for(var i = 0; i<mineTR.length;i++) {
      var b = jQuery(mineTR[i]).find("td:first");
      var a = jQuery("<div id=\"a_"+i+"\"><span>"+ b.text() + "</span></div>");
      if(i == 0) { a.children().addClass("rartatvide_d_aktiv"); }
      if(i == mineTR.length-1) { a.css("border-bottom","none"); }

      arrSvar[i] = b.next("td").text();
      a.click(function(){
        jQuery("#rartatvide table:first tr td span").removeClass("rartatvide_d_aktiv");
        jQuery(this).find("span").addClass("rartatvide_d_aktiv");
        var id = parseInt(this.id.replace("a_",""));
        jQuery(this).parent().next().html("<strong>SVAR</strong><br />"+ arrSvar[id]);
      });
      jQuery("#rartatvide_td1").append(a);
      jQuery("#rartatvide_td1").css("cursor","pointer");
    }

  }
}


var tt = null;
function tooltipToggle() {
	if (!tt) {
		tt = jQuery("<div id=\"tooltip\">&nbsp;</div>");
		jQuery("body").append(tt);
		tt = jQuery("#tooltip");
		tt.css("display", "none");
	}
	if (arguments[0] == 1) {
		tt.html(arguments[1].title);
		var jElement = jQuery("#" + arguments[1].id)
		var offset = jElement.offset();
		tt.css("left", offset.left);
		tt.css("top", offset.top - tt.outerHeight());
		tt.fadeIn("slow");
	} else {
		tt.hide();
		tt.html("&nbsp;");
	}
}

jQuery.fn.getStyle = function(selector) {
	var style = null;
	style = this.css(selector);
	if (!style && this.length > 0) {
		if (this[0].currentStyle) {
			switch (selector) {
				case "backgroundPosition":
					style = this[0].currentStyle["backgroundPositionX"] + " " + this[0].currentStyle["backgroundPositionY"];
					break;
				default:
					style = this[0].currentStyle[selector];
					break;
			}
		} else if (window.getComputedStyle) {
			style = document.defaultView.getComputedStyle(this[0], null).getPropertyValue(selector);
		}
	}
	return style;
};

// Call this method to init ToolTip on the control and pass the controls ID as argument
function initTooltipControl() {
	prevValue = "";
	if (arguments.length > 0) {
		var ctrlElement = jQuery("#" + arguments[0]);
		if (ctrlElement.length > 0) {
                                                if (ctrlElement.attr("type") == "password") {
				ctrlElement.bind("blur", function(e) {
					if (this.value.length <= 0) {
						this.value = prevValue;
					}
					tooltipToggle(0);
				});
				ctrlElement.bind("focus", function(e) {
					prevValue = this.value;
					this.value = "";
					tooltipToggle(1, this);
				});

                                                } else if (!ctrlElement[0].readOnly) {
				ctrlElement.bind("blur", function(e) {
					if (this.value.length <= 0) {
						this.value = prevValue;
					}
					tooltipToggle(0);
				});
				ctrlElement.bind("focus", function(e) {
					prevValue = this.value;
					this.value = "";
					tooltipToggle(1, this);
				});
			}
		}
	}
}

var flashBackgroundLoaded = false;
var flashBackgroundLoadedInterval = null;
var changeBackgroundTo = 0;
function kaldTilAS() {
      var flash = jQuery("#bg")[0];
      //alert("Parameter: "+ arguments[0]);
      changeBackgroundTo = arguments[0];
      if (!flashBackgroundLoaded) {
          flashBackgroundLoadedInterval = setInterval("changeBackground()", 200);
      } else {
          changeBackground();
      }
}
function changeBackground() {
      var flash = jQuery("#bg")[0];
      flash.showOtherPicture(changeBackgroundTo);
      clearInterval(flashBackgroundLoadedInterval);
}
function backgroundReady() {
    flashBackgroundLoaded = true;
}
