// Application-specific JavaScript functions and classes
// This file is automatically included by javascript_include_tag :defaults

//=============================================================================
// Date Utilities
//=============================================================================

// write today's date into the document
function todaysdate() {
    document.write(formatDateFull(new Date()));
}

// format the date in full descriptive form
function formatDateFull(date) {
    var dayNames = new Array();
	dayNames[0] = "Sunday";
	dayNames[1] = "Monday";
	dayNames[2] = "Tuesday";
	dayNames[3] = "Wednesday";
	dayNames[4] = "Thursday";
	dayNames[5] = "Friday";
	dayNames[6] = "Saturday";
		
	var monthNames = new Array();
	monthNames[0] = "January";
	monthNames[1] = "February";
	monthNames[2] = "March";
	monthNames[3] = "April";
	monthNames[4] = "May";
	monthNames[5] = "June";
	monthNames[6] = "July";
	monthNames[7] = "August";
	monthNames[8] = "September";
	monthNames[9] = "October";
	monthNames[10] = "November";
	monthNames[11] = "December";

	var year = date.getFullYear();
	var monthIndex = date.getMonth();
	var dayOfMonth = date.getDate();
	var dayIndex = date.getDay();
	return (dayNames[dayIndex]) + " " + (monthNames[monthIndex]) +" " + dayOfMonth + ", " + year;
}

//=============================================================================
// User Interaction Services
//=============================================================================

// request user confirmation before proceeding
function confirmOperation(msg, targetRef) {
	var answer = confirm(msg);
	if (answer = true)  {
		document.location = targetRef;
	} 
}

function printPage() {
    window.print();  
}

function goBack() {
	history.go(-1);
}

//=============================================================================
// Document and Window Services
//=============================================================================

// open a file in a popup window - optionally specify whether to include menubar (default off)
function openPopup(ref, name, width, height, includeMenubar) {
    nArgs = arguments.length;
    if (nArgs < 4){
        throw new Error("openPopup function requires args ref, name, width, height")
    }
    if (nArgs < 5){
        includeMenubar = false;
    }
    features = "width=" + width + ",height=" + height + ",resizable=yes,scrollbars=yes,menubar=" + (includeMenubar ? "yes" : "no")
    popup = window.open( ref, name, features);
    popup.focus();
}

function openAnnouncement(ref, width, height) {
    if (arguments.length == 1) {
        width = 800;
        height = 800;
    }
    openPopup(ref, "fwm_announcement", width, height);
}

function openInfo(ref, width, height) {
    if (arguments.length == 1) {
        width = 800;
        height = 800;
    }
    openPopup(ref, "fwm_info", width, height);
}

function openOpsInfo(ref, width, height, includeMenubar) {
    //#### TO DO: dynamically insert print/close links and get rid of the menu bar [DJL 27-Nov-2002]
    nArgs = arguments.length;
    if (nArgs == 1) {
        width = 800;
        height = 800;
    }
    if (nArgs < 5){
        includeMenubar = false;
    }
    //openPopup(ref, "fwm_ops", width, height, includeMenubar);
    features = "width=" + width + ",height=" + height + ",resizable=yes,scrollbars=yes,menubar=" + (includeMenubar ? "yes" : "no")
    popup = window.open( ref, name, features);
    //insertPrintAndClose(popup.document);
    popup.focus();
}

function openResults(ref, width, height) {
    if (arguments.length == 1) {
        width = 800;
        height = 800;
    }
    includeMenubar = true;
    openPopup(ref, "fwm_results", width, height, includeMenubar);
}

//-----------------------------------------------------------------------------
