﻿
function openWeather()
{
    tmSizedPopup('/addons/weather/WeatherReport.aspx','weather',400,300);
}
function fileBrowserCallBack(i_fieldName) {
    imageBrowserWin = window.open('/admin/FileManager/','imageBrowser','width=760,height=420,status=yes,toolbar=no,scrollbars=yes,resizable=yes');
    document.imageWinFieldname = i_fieldName;
    imageBrowserWin.focus();
}

function fileBrowserCallBack_return(fileRef)
{
    
    if(document.imageWinRef != null)
        document.imageWinRef.document.forms[0][document.imageWinFieldname].value=fileRef;
    else
        document.forms[0][document.imageWinFieldname].value=fileRef;
    if (document.imageWinFieldname.indexOf("imgLink")>-1)
    {
        var splitName = document.imageWinFieldname.substring("imgLink".length);
        updateImage(splitName, fileRef);
    }
    else if (document.imageWinFieldname.indexOf("swfLink")>-1)
    {
        var splitName = document.imageWinFieldname.substring("swfLink".length);
        updateSWF(splitName, fileRef);
    }
}


// WTB OPTIMERING...
function updateSWF(i_key, i_url)
{
    var w = document.getElementById('swfWidth' + i_key).value;
    var h = document.getElementById('swfHeight' + i_key).value;
    $.post("/admin/SWFArea_update.aspx",{key: i_key,url: i_url, width: w, height: h}, function(i_val) {
        if (i_val == "width")
        {
            if (confirm("Vald flashs bredd är större än ytan specificerade bredd, vill du ändå fortsätta?"))
            {
                $.post("/admin/SWFArea_update.aspx",{key: i_key,url: i_url,width: w, height: h, confirmed: "true"}, function(i_val2){
                    if (i_val2 == "not_found")
                        alert("Flashen blev borttagen någon gång under processen, kontrollera att den finns!");
                    else
                    {
                        window.location = window.location;
                        window.focus();
                    }
                });
            }
        }
        else if (i_val == "height")
        {
            if (confirm("Vald flashs höjd är större än ytan specificerade höjd, vill du ändå fortsätta?"))
            {
                alert("postar igen");
                $.post("/admin/SWFArea_update.aspx",{key: i_key,url: i_url,width: w, height: h, confirmed: "true"}, function(i_val2){
                    if (i_val2 == "not_found")
                        alert("Flashen blev borttagen någon gång under processen, kontrollera att den finns!");
                    else
                    {
                        window.location = window.location;
                        window.focus();
                    }
                });
                
            }
        }
        else if (i_val == "widthheight")
        {
            if (confirm("Flashens storlek är både bredare och högre än ytans storlek, vill du ändå fortsätta?"))
            {
                $.post("/admin/SWFArea_update.aspx",{key: i_key,url: i_url,width: w, height: h, confirmed: "true"}, function(i_val2){
                    if (i_val2 == "not_found")
                        alert("Flashen blev borttagen någon gång under processen, kontrollera att den finns!");
                    else
                    {
                        window.location = window.location;
                        window.focus();
                    }
                });
            }
        }
        else if (i_val == "not_found")
            alert("Flashen blev borttagen någon gång under processen, kontrollera att den finns!");
        else
        {
            window.location = window.location;
            window.focus();
        }
    }); 
}

// WTB OPTIMERING...
function updateImage(i_key, i_url)
{
    
    var w = document.getElementById('width' + i_key).value;
    var h = document.getElementById('height' + i_key).value;
    $.post("/admin/ImageArea_update.aspx",{key: i_key,url: i_url,width: w, height: h}, function(i_val) {
        if (i_val == "width")
        {
            if (confirm("Vald bilds bredd är större än ytan specificerade bredd, vill du ändå fortsätta?"))
            {
                $.post("/admin/ImageArea_update.aspx",{key: i_key,url: i_url,width: w, height: h, confirmed: "true"}, function(i_val2){
                    if (i_val2 == "not_found")
                        alert("Bilden blev borttagen någon gång under processen, kontrollera att den finns!");
                    else
                    {
                        window.location = window.location;
                        window.focus();
                    }
                });
            }
        }
        else if (i_val == "height")
        {
            if (confirm("Vald bilds höjd är större än ytan specificerade höjd, vill du ändå fortsätta?"))
            {
                $.post("/admin/ImageArea_update.aspx",{key: i_key,url: i_url,width: w, height: h, confirmed: "true"}, function(i_val2){
                    if (i_val2 == "not_found")
                        alert("Bilden blev borttagen någon gång under processen, kontrollera att den finns!");
                    else
                    {
                        window.location = window.location;
                        window.focus();
                    }
                });
                
            }
        }
        else if (i_val == "widthheight")
        {
            if (confirm("Bildens storlek är både bredare och högre än ytans storlek, vill du ändå fortsätta?"))
            {
                $.post("/admin/ImageArea_update.aspx",{key: i_key,url: i_url,width: w, height: h, confirmed: "true"}, function(i_val2){
                    if (i_val2 == "not_found")
                        alert("Bilden blev borttagen någon gång under processen, kontrollera att den finns!");
                    else
                    {
                        window.location = window.location;
                        window.focus();
                    }
                });
            }
        }
        else if (i_val == "not_found")
            alert("Bilden blev borttagen någon gång under processen, kontrollera att den finns!");
        else
        {
            window.location = window.location;
            window.focus();
        }
    }); 
}


function ShowEmailContentArea(i_where, i_beforeAt, i_afterAt, i_afterDot, i_additional) {
    if (i_additional == null)
        i_additional = "";
    builtStr = i_beforeAt + "@" + i_afterAt + "." + i_afterDot;
    $(i_where).append(i_additional + '<a href="mailto:' + builtStr + '">' + builtStr + '</a>');
}

