﻿
//
// Misc functions
//
//

function disable(cont) {
    $(cont).attr("disabled", "disabled");
};

function enable(cont) {
    $(cont).removeAttr("disabled");
};


//
// Menu items
//
//

var menuitem = function(title, header, body) {
    this.title = title;
    this.header = header;
    this.body = body;
}

var menulist =
{
    'items': new Array(),
    'additem': function(item) {
        this.items.push(item);
    },
    'showlist': function(container) {
        var list = new String();
        for (i = 0; i < this.items.length; i++) {
            list += '<a id="' + this.items[i].header + '" class="menuheaderitem';
            if (0 == i) list += ' menuselectedheaderitem';
            list += '" onclick="switchItems(\'' + this.items[i].header + '\',\'' + this.items[i].body + '\'); return false;">' +
                this.items[i].title + '</a>'
        }
        $('#' + container).html(list);
    }
}

function switchItems(menuitem, menubody) {
    menuitem = '#' + menuitem;
    menubody = '#' + menubody;

    // remove selected class
    $('.menuselectedheaderitem').removeClass('menuselectedheaderitem');

    // add selected class
    $(menuitem).addClass('menuselectedheaderitem');
    

    // remove selected class
    $('.menuselectedbodyitem').removeClass('menuselectedbodyitem');

    // add selected class
    $(menubody).addClass('menuselectedbodyitem');

}


//
// Re-Stringify - change /r/n to carriage return an linefee, /t to tab
//
//
function restringify(s) {
    s = new String(s);
    s = s.replace(/\\r\\n/g, "<br />")
        .replace(/\\t/g, "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
    
    return s;
}


//
// Figure out correct URL for both dev and production
//
//
function getURL(targeturl) {
    // first split out target and current urls...
    tlist = targeturl.toString().split("/");

}


//
// Display Notes popup dialog
//
//

$(document).ready(function() {
var $dialog = $('#displaynote')
	.dialog({
	    buttons: { "Ok": function() { $(this).dialog("close"); } },
	    autoOpen: false,
	    title: 'Notes',
	    height: 400,
	    width: 700,
	    modal: true
	});

    $('#opener').click(function() {
        $dialog.dialog('open');
    });

    $(document).ajaxError(function (e, xhr, settings, exception) {
        alert('error in: ' + settings.url + ' \\n' + 'error:\\n' + exception);
    });
});

function getNotes(turl, id, t) {
    var title = t;
    $.get(turl, function(data) {
        data = restringify(data);
        $dialog = $("#displaynote")
        $dialog.html("<label>" + data + "</label>")
        $dialog.dialog('option','title',"Notes: " + t);
        $dialog.dialog('open');
    });
}
