this.LogicaPopup = function() {
    var popupSelecter = ".LogicaPopupSelector";
    var vis = $(popupSelecter)[0];

    if (vis != null) {
        var popUpDiv = vis.parentNode;
        var popupDivId = popUpDiv.id;
        var backgroundDivId = popupDivId.replace('popUpDialog', 'backgroundPopupDialog');
        var backgroundDiv = document.getElementById(backgroundDivId);

        popupDivId = "#" + popupDivId;
        backgroundDivId = "#" + backgroundDivId;


        var windowWidth = document.documentElement.clientWidth;
        var windowHeight = document.documentElement.clientHeight;
        var popupHeight = $(popupDivId).height();
        var popupWidth = $(popupDivId).width();
        var leftPos = ((windowWidth / 2) - (popupWidth / 2)) + "px";
        var topPos = ((windowHeight / 2) - (popupHeight / 2)) + "px";
        var backgroundHeight = windowHeight;
        if (backgroundHeight < 1000) {
            backgroundHeight = 1000;
        }
        if (vis.value == 'show') {
            $(popupDivId).css("display", "block").css("top", topPos).css("left", leftPos);
            $(backgroundDivId).css("display", "block").css("height", backgroundHeight).css("opacity", "0.7");
            backgroundDiv.style.display = "block";
            popUpDiv.style.display = "block";
        }
        else {
            $(popupDivId).css("display", "none").css("top", topPos).css("left", leftPos);
            $(backgroundDivId).css("display", "none").css("height", backgroundHeight).css("opacity", "0.7");
            backgroundDiv.style.display = "none";
            popUpDiv.style.display = "none";
        }
    }
}
this.LogicaToolTips=function()
{
     var imgSelecter=".InfoTipImg";
     var divToolTipsSelecter=".InfoTipDiv";
      var xOffset = -10;
      var yOffset = 20;
 	 $(imgSelecter).hover(function(e) 
 	                 {
// 	                    
                       
 		                var resId = $(this).attr("id");
		                resId =resId.replace('_img','') ;
		                var testresId = resId.indexOf('SubscriptionSubExistingNumber');		                                               
		                if(testresId != -1)
		                {
		                    resId= 'ctl00_infoBoxcontent_lblInfoBoxMobileNumberText';
		                }

		                var lblText=document.getElementById(resId);
		                if(lblText ==null) return ;
		                var hoverText = lblText.innerHTML;		                
		                $("body").append("<div id='divTooltip' class='tooltip'><p id='tooltip'>"+ hoverText  +"</p><span class='tooltipBottom'>&nbsp;</span></div>");
		                
		                $("#divTooltip").css("top",(e.pageY + xOffset) + "px").css("left",(e.pageX + yOffset) + "px").fadeIn("fast");

 	                 },
 	                 function()
 	                        {
 	                        $("#divTooltip").remove();
 	                        }
 	                    );
 	
$(imgSelecter).mousemove(function(e){
		$("#divTooltip").css("top",(e.pageY + xOffset) + "px").css("left",(e.pageX + yOffset) + "px");
});
}
//function to show tooltips on the facetsearchitems on the productlistpage
this.LogicaFacetToolTips = function() {
    var xOffset = -10;
    var yOffset = 20;

    $(".header1Click").hover(function(e) {
        
        var lblText = $(this).next("span");
        var hoverText = $(lblText).html();
        if (hoverText != null && hoverText.length != 0) {
            $("body").append("<div id='divTooltip' class='tooltip'><p id='tooltip'>" + hoverText + "</p><span class='tooltipBottom'>&nbsp;</span></div>");
            $("#divTooltip").css("top", (e.pageY + xOffset) + "px").css("left", (e.pageX + yOffset) + "px").fadeIn("fast");
        }
    }
,
 	                 function() {
 	                     $("#divTooltip").remove();
 	                 });
    $(".tooltipcontainer").mousemove(function(e) {
        $("#divTooltip").css("top", (e.pageY + xOffset) + "px").css("left", (e.pageX + yOffset) + "px");

    });

}
//function to show tooltips on the lowest subscription prices.
this.LogicaLowestToolTips = function() {
    var xOffset = -10;
    var yOffset = 20;

    $(".tooltipcontainer").hover(function(e) {
        var hoverText = "";
        if ($(this).attr("id") == "mobil") {
            hoverText = $("#mobiltext").children('span').text();
        }
        else if ($(this).attr("id") == "pc") {
            hoverText = $("#pctext").children('span').text();
        }
        else if ($(this).attr("id") == "mobiltilb") {
            hoverText = $("#mobiltilbtext").children('span').text();
        }
        else if ($(this).attr("id") == "aboInfo") {
            hoverText = $(this).prev('.hiddenAboInfo').html();
        }
        if (hoverText.length != 0) {

            hoverText = hoverText.replace(/\'/gi, "\"");


            $("body").append("<div id='divTooltip' class='tooltip'><p id='tooltip'>" + hoverText + "</p><span class='tooltipBottom'>&nbsp;</span></div>");
            $("#divTooltip").css("top", (e.pageY + xOffset) + "px").css("left", (e.pageX + yOffset) + "px").fadeIn("fast");
        }
    }
    ,
 	                     function() {
 	                         $("#divTooltip").remove();
 	                     });
    $(".tooltipcontainer").mousemove(function(e) {
        $("#divTooltip").css("top", (e.pageY + xOffset) + "px").css("left", (e.pageX + yOffset) + "px");

    });

}
//function to show tooltips discount "hva er dette" field in OrderPayment.aspx
this.LogicaDiscountHelp = function() {
    var xOffset = -10;
    var yOffset = 20;

    $("#discountHelp").hover(function(e) {
        var hoverText = "";
        if (hoverText.length != 0) {

            hoverText = hoverText.replace(/\'/gi, "\"");


            $("body").append("<div id='divTooltip' class='tooltip'><p id='tooltip'>" + hoverText + "</p><span class='tooltipBottom'>&nbsp;</span></div>");
            $("#divTooltip").css("top", (e.pageY + xOffset) + "px").css("left", (e.pageX + yOffset) + "px").fadeIn("fast");
        }
    }
    ,
 	                     function() {
 	                         $("#divTooltip").remove();
 	                     });
    $(".tooltipcontainer").mousemove(function(e) {
        $("#divTooltip").css("top", (e.pageY + xOffset) + "px").css("left", (e.pageX + yOffset) + "px");

    });

}
//DropDownList functionality Checkout
function ChangeContent(dropdown) {
    var selectedDropDown = document.getElementById(dropdown);
    var elements = document.getElementsByTagName('Select');
    var hiddenId = dropdown.replace("ddlPickNumber", "ddlNumbersLeft");
    var hiddenDropDown = document.getElementById(hiddenId);
    for (var i = 0; i < elements.length; i++) {
        if (IsElementDropDownList(elements[i].id)) {
            if (elements[i].id != selectedDropDown.id) {
                RemoveContent(selectedDropDown.value, elements[i].id);
                if (hiddenDropDown.value != null && hiddenDropDown.value != '') {
                    AddContent(hiddenDropDown.value, elements[i].id);
                }
            }
            UpdateText(elements[i].id);
        }
    }
    hiddenDropDown.value = selectedDropDown.value;
}
//DropDownList functionality Checkout
function UpdateText(id) {
    var list = document.getElementById(id);
    var hiddenId = id.replace("ddlPickNumber", "txtNumber");
    var hiddenText = document.getElementById(hiddenId);

    hiddenText.value = '';
    for (var i = 0; i < list.options.length; i++) {
        if (hiddenText.value == '')
            hiddenText.value = list.options[i].value;
        else
            hiddenText.value += ',' + list.options[i].value;
    }
}
//DropDownList functionality Checkout
function IsElementDropDownList(id) {
    var pattern = 'lvItems_ctrl\\d_ddlPickNumber';
    var regularExpresssion = new RegExp(pattern);
    if (id.match(regularExpresssion)) return true;
    else return false;
}
//DropDownList functionality Checkout
function AddContent(value, id) {
    var optn = document.createElement("OPTION");
    optn.value = value;
    optn.text = value;

    var list = document.getElementById(id);
    list.options.add(optn);
}
//DropDownList functionality Checkout
function RemoveContent(value, id) {
    var list = document.getElementById(id);

    for (var j = 0; j < list.options.length; j++) {
        if (list.options[j].value == value) {
            list.remove(j);
        }
    }
}

function scrollWindow(x, y)
{
	window.scrollTo(x, y);
}
//productdetail radiobuttons..
function SetUniqueRadioButton(current) {
    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type == 'radio') {
            elm.checked = false;
        }
    }
    current.checked = true;
    var mobileprice = $(current).parent("td").nextAll("td:last").children("span.phonePrice").text();
    var totalprice = $(current).parent("td").nextAll("td:has(span.lowestprice)").children("span.tooltipcontainer").text();
    var valgtAboMedMndPris = $(current).parent("td").nextAll("td:has(span#aboInfo)").children("span#aboInfo").text();
    $(".productDetailChoosenAbo").text(valgtAboMedMndPris);
    $("#lowestpricetext").text(totalprice);
    $(".prispriseksempel").children("em").text(mobileprice);
};

function ProductDetailDocumentReady() {
    $(document).ready(function() {
        $(".showmore").click(function() {
            debugger;
            if ($(this).attr("class") == "showmore") {
                $(".toggle").show();
                $(".showmore").removeClass("showmore").addClass("showall");
                var hasmore = (".allsub");
                var size = $(hasmore).size();
                if (size > 0) {
                    var linktext = "Vis alle abonnement"
                }
                else {
                    $(this).text("");
                }
                $(this).text(linktext);
            }
            else {
                $(".allsub").show();
                $(this).text("");
            }
        }
        )
        LogicaLowestToolTips();
        var totalprice;
        if (document.getElementById('mobil'))
            totalprice = $('#mobil').text();
        if (document.getElementById('pc'))
            totalprice = $('#pc').text();
        $("#lowestpricetext").text(totalprice);
    }
);
}
function ProductListDocumentReady() {
    $(document).ready(function() {
        $('.hidden').hide();
        LogicaFacetToolTips();
        $('#ctl00_Content_productListUserControl1_ddlSortAbo').removeAttr('disabled');
        $('#ctl00_Content_productListUserControl1_ddlSortPriceAndCategories').removeAttr('disabled');

        $(".productimages").lazyload({
        placeholder: "App_Themes/images/placeholderWhite.png",
            effect: "fadeIn"
        });
    });
}
function ProductSubscriptionDocumentReady() {
    $(document).ready(function() {
        $(".more").click(function() {
            var theid = $(this).attr("id");
            var theclass = $(this).attr("class");
            var obj = $(this);
            if (theclass.indexOf("plus") > -1) {
                $.ajax({
                    type: "POST",
                    url: "ProductSubscription.aspx/CallOmniture",
                    data: "{'id':'" + theid + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function(msg) {
                        $('.omnitureScript').html(msg.d);
                        obj.parents("tr:first").next("tr.info:first").toggle();
                        obj.parents("tr:first").toggleClass("abo");
                        obj.removeClass("plus").addClass("minus");                      
                    }
                });
            }
            else {
                obj.parents("tr:first").next("tr.info:first").toggle();
                obj.parents("tr:first").toggleClass("abo");
                obj.removeClass("minus").addClass("plus");
            }
        }); 
        LogicaLowestToolTips();
        var hasmore = (".toggle");
        var size = $(hasmore).size();
        if (size == 0) {
            $(".showmore").text("");
            $(".blue-arrow-down").hide();
        }
        $(".showmore").click(function() {
            $(".toggle").show();
            $(this).text("");
            $(".blue-arrow-down").hide();
        }
        );
    });
}
function SetUniqueRbSub(current) {

    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type == 'radio' && (elm.id.indexOf('rbSub') > -1)) {
            elm.checked = false;
        }
    }
    current.checked = true;
}
function SetUniqueRbPrice(current) {

    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type == 'radio' && (elm.id.indexOf('rbPrice') > -1)) {
            elm.checked = false;
        }
    }
    current.checked = true;
}
function SetUniqueRbCampaign(current) {

    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type == 'radio' && (elm.id.indexOf('rbCampaign') > -1)) {
            elm.checked = false;
        }
    }
    current.checked = true;
}
function SetUniqueRbSort(current) {

    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type == 'radio' && (elm.id.indexOf('rbSort') > -1)) {
            elm.checked = false;
        }
    }
    current.checked = true;
}

function SetUniqueRbMBB(current) {

    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type == 'radio' && (elm.id.indexOf('rbAboId') > -1)) {
            elm.checked = false;
        }
    }
    current.checked = true;
}
function SetUniqueRbMBBColor(current) {

    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type == 'radio' && (elm.id.indexOf('colorselector') > -1)) {
            elm.checked = false;
        }
    }
    current.checked = true;
}