﻿/*
---------------------------------------------
These two functions are used to decrypt the 
"SafeMailTo" class.
---------------------------------------------
*/
Websajt.Utils.deEncAddr = function(ea) {
	var em = '';
	for (i = 0; i < ea.length; ) {
		var le = '';
		le = ea.charAt(i) + ea.charAt(i + 1);
		em += String.fromCharCode(parseInt(le, 16));
		i += 2;
	}
	return em;
}

Websajt.Utils.safeMail = function(ea) {
	document.location.href = 'mailto:' + Websajt.Util.deEncAddr(ea);
}

Websajt.Utils.FilterQuatity = function(evt) {
    var keyCode = evt.which ? evt.which : evt.keyCode;
    return (keyCode >= '0'.charCodeAt() && keyCode <= '9'.charCodeAt()) || keyCode == 8 || keyCode == 46 || keyCode == 37 || keyCode == 39 || (keyCode > 95 && keyCode < 106);
}

Websajt.Utils.ChangeAlert = function(objElement) {
    var bolIsChanged = false;

    if ($(objElement).val() == objElement.defaultValue) {
        $(objElement).css("backgroundColor", "#ffffff");
    }
    else {
        $(objElement).css("backgroundColor", "#ef72b4");
    }

    $('#shop-basket input.textbox').each(
		function(item) {
		    if ($(item).val() != item.defaultValue) {
		        bolIsChanged = true;
		        return;
		    }
		}
	)
}

Websajt.Utils.Search = function(SearchParams) {
    this.SearchUrl = SearchParams.SearchUrl,
    this.Submit = function() {
    if ($("#txtSearchProduct").val().length > 2)
            if (this.SearchUrl.indexOf("?") > -1){
                document.location.href = this.SearchUrl + "&q=" + $("#txtSearchProduct").val();
            }
            else{
                document.location.href = this.SearchUrl + "?q=" + $("#txtSearchProduct").val();
            }
        else {
            SearchBubble.Show();
            setTimeout("SearchBubble.Hide()", 5000);
        }
    }
}


Websajt.Utils.InitBubble = function(strHeadline, strMessage, strId, onlyDisabled, posLeft, Zindex) {
    if (Zindex == null)
        Zindex = 1000;
    if (posLeft == null)
        posLeft = 0;
    if (onlyDisabled == null)
        onlyDisabled = false;
        
    var strHtml = "";
    strHtml += "<div class=\"bubble\" id=\"" + strId + "Bubble\" style=\"z-index:" + Zindex + "\">";
    strHtml += "<div class=\"content\">";
    strHtml += "<h6>" + strHeadline + "</h6>";
    strHtml += strMessage;
    strHtml += "</div>"
    strHtml += "<div class=\"bottom\"></div>";
    strHtml += "</div>";
    $("#" + strId).parent().append(strHtml);

    var Bubble = $("#" + strId + "Bubble");
    var pos = $("#" + strId).position();

    $("#" + strId).mouseover(function(obj) {
        if (!onlyDisabled ||  (onlyDisabled && $("#" + strId).hasClass("disabled"))) {
            Bubble.css({ left: pos.left + (posLeft), top: pos.top - (Bubble.height() + 10) });
            Bubble.show();
        }
    }).mouseout(function() {
        Bubble.hide();
    });
}


Websajt.Utils.InitBubbleMouse = function(strHeadline, strMessage, strId, onlyDisabled, posLeft, Zindex) {
    if (Zindex == null)
        Zindex = 1000;
    if (posLeft == null)
        posLeft = 0;
    if (onlyDisabled == null)
        onlyDisabled = false;

    var strHtml = "";
    strHtml += "<div class=\"bubble\" id=\"" + strId + "Bubble\" style=\"z-index:" + Zindex + "\">";
    strHtml += "<div class=\"content\">";
    strHtml += "<h6>" + strHeadline + "</h6>";
    strHtml += strMessage;
    strHtml += "</div>"
    strHtml += "<div class=\"bottom\"></div>";
    strHtml += "</div>";
    $("#" + strId).parent().append(strHtml);

    var Bubble = $("#" + strId + "Bubble");
    
    $("#" + strId).mouseover(function(obj) {
        if (!onlyDisabled || (onlyDisabled && $("#" + strId).hasClass("disabled"))) {
            Bubble.css({ left: obj.left + (posLeft), top: obj.top - (Bubble.height() + 10) });
            Bubble.show();
        }
    }).mouseout(function() {
        Bubble.hide();
    });
}

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 += "<h6>" + this.Headline + "</h6>";
    	strHtml += this.Message;
    	strHtml += "</div>"
    	strHtml += "<div class=\"bottom\"></div>";
    	strHtml += "</div>";
    	$(document.body).append(strHtml);

    	var pos = $("#" + this.ElementID).offset();
    	$("#" + this.ElementID + "Bubble").css({ left: pos.left + (this.PositionLeft), top: pos.top - ($("#" + this.ElementID + "Bubble").height() + 10) });
    },
    this.Show = function() {
    	$("#" + this.ElementID + "Bubble").show();
    	$("#" + this.ElementID + "Bubble").click(function() {
    		$(this).hide();
    	});
    },
    this.Hide = function() {
    	$("#" + this.ElementID + "Bubble").hide();
    }
}

Websajt.Utils.BubbleAlt = function(strHeadline, strMessage, strId, posTop, Zindex) {
	this.Headline = strHeadline,
    this.Message = strMessage,
    this.ElementID = strId,
    this.PositionTop = posTop,
    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 += "<h6>" + this.Headline + "</h6>";
    	strHtml += this.Message;
    	strHtml += "</div>"
    	strHtml += "<div class=\"bottom\"></div>";
    	strHtml += "</div>";
    	$(document.body).append(strHtml);

    	var pos = $("#" + this.ElementID).offset();
    	$("#" + this.ElementID + "Bubble").css({ left: (pos.left - 10), 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.ShowStaticBubble = function(strLayer, posX, posY) {
    if (posY == null)
        posY = 0;
    $("#" + strLayer).css("top", (parseInt("-" + $("#" + strLayer).height()) + posY) + "px");
    if (posX != null)
        $("#" + strLayer).css("left", posX + "px");
    $("#" + strLayer).show();
}

Websajt.Utils.HideStaticBubble = function(strLayer) {
    $("#" + strLayer).hide();
}

function center(width, height, cx, cy) {
    var x = (cx == 0) ? 0 : (cx == 1) ? parseInt((screen.width - width - 10) / 2) : screen.width - width - 10;
    var y = (cy == 0) ? 0 : (cy == 1) ? parseInt((screen.height - height - 56) / 2) : screen.height - height - 56;
    return (",top=" + y + ",left=" + x);
}
function openwindow(url, w, h) { window.open(url, "myWin", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + w + ",height=" + h + ",top=200,left=200"); }


function showPopupMessage() {

    var h = $(window).height() + 15;
    var w = $(window).width() + 15;
    $("#overlay").height(h);
    $("#overlay").width(w);

    // Copy text
    $("#PopupMessageContent").html($("#PopupMessageContentHolder").html());

    // Show
    $("#overlay").show();

    $("#PopupMessage").css('left', ($(window).width() / 2)-200);
    $("#PopupMessage").show();
}
