function popUp(URL) {
    window.open(URL, Math.random(), 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=550');
}

function displayMessage(message) {
    //TODO: do something graceful if there is no message div on the page

    messageDiv = $("div[id='message']");
    messageDiv.html("<h1 style=\"color: red\">"+message+"</div>"); //temp till a designer designs a normal message
    messageDiv.show();
    messageDiv.effect("highlight", {color: '#29AE1C'}, 1000);
}

function showhide(id){
    if (document.getElementById){
        obj = document.getElementById(id);
        if (obj.style.display == "none"){
            obj.style.display = "";
        } else {
            obj.style.display = "none";
        }
    }
}

function megaHoverOver(){ //Show popup windows when hovering tab names
    $(this).find(".sub").stop().fadeTo('fast', 1).show();

    //Calculate width of all ul's
    (function($) {
        jQuery.fn.calcSubWidth = function() {
            rowWidth = 0;
            //Calculate row
            $(this).find("ul").each(function() {
                rowWidth += $(this).width();
            });
        };
    })(jQuery);

    if ( $(this).find(".row").length > 0 ) { //If row exists...
        var biggestRow = 0;
        //Calculate each row
        $(this).find(".row").each(function() {
            $(this).calcSubWidth();
            //Find biggest row
            if(rowWidth > biggestRow) {
                biggestRow = rowWidth;
            }
        });
        //Set width
        $(this).find(".sub").css({'width' :biggestRow});
        $(this).find(".row:last").css({'margin':'0'});

    } else { //If row does not exist...

        $(this).calcSubWidth();
        //Set Width
        $(this).find(".sub").css({'width' : rowWidth});

    }
}

function megaHoverOut(){
    $(this).find(".sub").stop().fadeTo('fast', 0, function() {
        $(this).hide();
    });
}

function limitText(limitField, limitCount, limitNum) { // Limits characters
 if (limitField.value.length > limitNum) {
 limitField.value = limitField.value.substring(0, limitNum);
 } else {
 limitCount.value = limitNum - limitField.value.length;
 }
} 
