﻿function SetParameter(parameterId, parameterValue){
    document.getElementById(parameterId).value = parameterValue;
}

function PostPromoPageForm(){
    document.forms['FrmPromoPage'].submit();
}

function StepForward(){
    SetParameter('Direction', '1');
    document.forms['FrmPromoPage'].submit();
}            

function StepBack(){
    SetParameter('Direction', '-1');
    document.forms['FrmPromoPage'].submit();
}

function RemovePromoPageModal(id){
    $("#" + id + "Wrapper").remove();
    $("#" + id + "ModalWin").remove();
    //$("#" + id).hide();
}

$(document).ready(function(){   
    $(".expandlink").click(function(){
        var div = $(this).attr("href").replace("_","");
        var wrapper = $("<div></div>").css("background","#FFF").css("height","100%").css("width","100%").css("position","absolute").css("top","0px").attr("id",$(div).attr("id")+"Wrapper");
        var newDiv = $('<div></div>').attr('id', $(div).attr('id') + 'ModalWin');
        var newDivClose = $('<div><a href="javascript:;" onclick="RemovePromoPageModal(\'' + $(div).attr('id') + '\')">Stäng fönstret</a></div>').attr('id', $(div).attr('id') + 'ModalClose');
        var newDivContent = $('<div></div>').attr('id', $(div).attr('id') + 'ModalContent').html($(div).html());
        //newDiv.show().css("position","relative").css("top","-580px").css("left","20px").css("height","500px").css("border","1px solid black").css("background","#FFF").css("padding","10px");
        newDiv.show().attr('class', 'ModalWindow');
        
        newDiv.append(newDivClose);
        newDiv.append(newDivContent);
               
        $('.Container').append(newDiv);
        newDiv.before(wrapper);
        
        newDivContent.css("height","450px").css("background","#FFF").css("padding","10px").css("overflow","auto");
        $("#" + $(div).attr("id")+"Wrapper").fadeTo("slow", 0.76);
    });    
    
    $("button.extentlevel").click(function(){
        SetParameter("extentlevelid", $(this).attr("id").replace("extentlevel",""));
        StepForward();
    });
});
