﻿Namespace.Manager.Register('Content.Detail.Standards');
Namespace.Manager.Register('Content.Detail.Resources');

Content.Detail.Standards.GetAll = function() { alert('ERROR: Function not implemented.  That\'s ashame.'); return false; }

Content.Detail.Standards.GetAll_Start = function(e) {
    Portal.UI.Loader.Show();
    return true;
}

Content.Detail.Standards.GetAll_End = function(e) { Portal.UI.Loader.Hide(); }

Content.Detail.Resources.WindowId = 0;
Content.Detail.Resources.View = function(u, title, o) {
    Content.Detail.Resources.WindowId++;
    var options = o ? o : { modal: false, width: 990, height: 650, resize: true, dragenabled: true };
    var winId = 'resourceWin' + Content.Detail.Resources.WindowId;
    var win = MsgWindow.open(winId, 'iframe', u, title, options);
}
Content.Detail.Resources.Print = function(id) {
    var options = { modal: false, width: 990, height: 650, resize: true, dragenabled: true };
    var win = MsgWindow.open('printer', 'iframe', Content.Detail.Print.Url + '?ID=' + id, document.title, options);
}

Content.Detail.Resources.InitDetailPage = function() {
    var IsPrintView = document.URL.indexOf('print.aspx') != -1;
    // all properties must open Urls in WebWindow
    $('#properties a').click(function() {
        if (this.href.indexOf('http://cdnf.') != -1) {
            return true;
        }
        Content.Detail.Resources.View(this.href, this.text, null);
        return false;
    });
    // setup Add Bookmark
    $('li.bookmark a').click(function() {
        Portfolio.Bookmarks.Add(document.title, document.URL);
        return false;
    });
    // setup Printer Friendly Version
    $('li.print-page a').click(function() {
        if (IsPrintView) { window.print(); } else { Content.Detail.Resources.Print($('input.EdResourceID').val()); }
        return false;
    });
    // setup Printer Friendly Version
    $('li.send a').click(function() {
        SendToMyFriend.Open();
        return false;
    });

    if (IsPrintView) { $('li.print-page a').text('Send to Printer'); }
}
Content.Detail.Print = {
    Url:'/resources/print.aspx'
}

Content.Detail.Back = function() { history.go(-1); return false; }

$(document).ready(Content.Detail.Resources.InitDetailPage);
//$(document).ready(changeLinkTargets);
function StartSaveComments() {
    // arguments come in as EdResourceId, UserMessage.
    SaveComment({ "EdResourceId": arguments[0], "Text": arguments[1] });
    return false
}

// calls the script callback for changing pages for the comments in the resource details view.
function changeCommentsPage(pageNumber) {
    CommentsPageChange({ "PageNumber": pageNumber });
    //return false;
}

function ShowLoader() {
    var divLoading = el('loading');
    centerEl(divLoading, false);
    $("#loading").removeClass('hide');
    $("#loading").show();
    return true;
}

function HideLoader() {
    $("#loading").fadeOut(500);
}

Content.Detail.Resources.View = function(u, title, o, WindowId) {
    var options = o ? o : { modal: false, width: 990, height: 650, resize: true, dragenabled: true };
    var winId = 'resourceWin' + WindowId;
    var win = MsgWindow.open(winId, 'iframe', u, title, options);
}

function openResourceWindow(sHref, iID) {
    window.open(sHref, 'extRes' + iID, 'directories=no,height=650,width=990,scrollbars=yes,toolbar=yes,menubar=yes');
    return false;
}

function changeLinkTargets() {
    aLinks = document.links;
    for (var i = 0; i < aLinks.length; i++) {
        //alert();
        var sLinkHref = aLinks[i].href;
        var sPageHref = document.location.host;
        if ((sLinkHref.indexOf(sPageHref) == -1) && (sLinkHref.indexOf("javascript:void(0);") == -1)) {
            //aLinks[i].setAttribute("onclick", "return Content.Detail.Resources.View(this, 'Window', '" + aLinks[i].innerHTML + "', '" + aLinks[i].href + "');");
            //aLinks[i].setAttribute("onclick", "return Content.Detail.Resources.View('" + aLinks[i].href + "','" + aLinks[i].innerHTML + "', 'Ext" + i + "');");
            aLinks[i].setAttribute("onclick", "return openResourceWindow('" + aLinks[i].href + "', 'ResourceWin" + i + "');");
            aLinks[i].href = "javascript:void(0);";
            
            //aLinks[i].target = "ExternalResourceWin" + i;
        }
    }
}
