/*
General Functions JavaScript Module
-----------------------------------
Author: Stephen McKenzie, Dave Falkus (Glasgows)
Version: 1.0 (May 2006)
Version: 1.1 (August 2006)
*/

function popupWindow(url,winname,features) {

	objPopup = window.open(url,winname,features); //see Open Method Notes below
	if (window.focus) {objPopup.focus()}; //Return focus to the popup
	return false;
}

function refreshPage() {
	
	window.history.go();
}


function displayDate(sDate,sFormat) {
	
	//Initate date object
	if(sDate == "") {
		var dteDate = new Date();
	} else {
		var dteDate = new Date(sDate);
	}
	
	//extract 'parts' from date...
	var intDayOfWeek = dteDate.getDay();
	var strDayOfWeek = dayName(intDayOfWeek);
	var intDayOfMonth = dteDate.getDate();
	var intMonth = dteDate.getMonth();
	intMonth++;
	var strFullMonth = monthFullName(intMonth);
	var strAbbvMonth = monthAbbvName(intMonth);
	var intYear = dteDate.getYear();
	var intFullYear = dteDate.getFullYear();
		
	//Build date string...
	var strDate = ""

	if (sFormat != "") {
		switch (sFormat) {
			case "dd-mm-yyyy":
				strDate += intDayOfMonth + "-" + intMonth + "-" + intFullYear;
				break;
			case "dd/mm/yyyy":
			case "Short":
			case "short":
				strDate += intDayOfMonth + "/" + intMonth + "/" + intFullYear;
				break;
			case "dd-MMM-yyyy":
			case "Medium":
			case "medium":
				strDate += intDayOfMonth + "-" + strAbbvMonth + "-" + intFullYear;
				break;		
			case "ddd, dd MMMM yyyy":
			case "Full":
			case "full":
				strDate += strDayOfWeek + " " + intDayOfMonth + " " + strFullMonth + " " + intFullYear;
				break;
			default:
				strDate += intDayOfMonth + "/" + intMonth + "/" + intFullYear;
		}
	} else {
		strDate += intDayOfMonth + "/" + intMonth + "/" + intFullYear;
	}
	
	//return formated string
	return strDate;
}

function dayName(iDayNumber) {

	//Create array containing day names...
	var strDay = Array(7);
	strDay[1] = 'Monday';
	strDay[2] = 'Tuesday';
	strDay[3] = 'Wednesday';
	strDay[4] = 'Thursday';
	strDay[5] = 'Friday';
	strDay[6] = 'Saturday';
	strDay[7] = 'Sunday';
	
	//Deteremine month by passing aurgument into array...
	strDayName = strDay[iDayNumber];
	return strDayName;
}

function monthAbbvName(iMonthNumber) {

	//Create array containing month names...
	var strMonth = Array(12);
	strMonth[1] = 'Jan';
	strMonth[2] = 'Feb';
	strMonth[3] = 'Mar';
	strMonth[4] = 'Apr';
	strMonth[5] = 'May';
	strMonth[6] = 'Jun';
	strMonth[7] = 'July';
	strMonth[8] = 'Aug';
	strMonth[9] = 'Sept';
	strMonth[10] = 'Oct';
	strMonth[11] = 'Nov';
	strMonth[12] = 'Dec';
	
	//Deteremine month by passing aurgument into array...
	strMonthName = strMonth[iMonthNumber];
	return strMonthName;
}

function monthFullName(iMonthNumber) {

	//Create array containing month names...
	var strMonth = Array(12);
	strMonth[1] = 'January';
	strMonth[2] = 'February';
	strMonth[3] = 'March';
	strMonth[4] = 'April';
	strMonth[5] = 'May';
	strMonth[6] = 'June';
	strMonth[7] = 'July';
	strMonth[8] = 'August';
	strMonth[9] = 'September';
	strMonth[10] = 'October';
	strMonth[11] = 'November';
	strMonth[12] = 'December';
	
	//Deteremine month by passing aurgument into array...
	strMonthName = strMonth[iMonthNumber];
	return strMonthName;
}

function getDate(){
	document.getElementById("date").innerHTML = displayDate("","Full");
}

/*
Open Method Notes
-----------------

'features' parameter options:

	channelmode = { yes | no | 1 | 0 }	
	Specifies whether to display the window in theater mode and show the channel band
	The default is no
		
	directories = { yes | no | 1 | 0 }
	Specifies whether to add directory buttons
	The default is yes
		
	fullscreen = { yes | no | 1 | 0 }
	Specifies whether to display the browser in full-screen mode
	The default is no
	Use full-screen mode carefully
	Because this mode hides the browser's title bar and menus
	You should always provide a button or other visual clue to help the user close the window
	ALT+F4 closes the new window
	A window in full-screen mode must also be in theater mode (channelmode)
		
	height = number
	Specifies the height of the window, in pixels
	The minimum value is 100.

	left = number
	Specifies the left position, in pixels
	This value is relative to the upper-left corner of the screen
	The value must be greater than or equal to 0
	
    location = { yes | no | 1 | 0 }
	Specifies whether to display the input field for entering URLs directly into the browser
	The default is yes
    
	menubar = { yes | no | 1 | 0 }
	Specifies whether to display the menu bar. The default is yes
    resizable = { yes | no | 1 | 0 }
	Specifies whether to display resize handles at the corners of the window
	The default is yes
	
    scrollbars = { yes | no | 1 | 0 }
	Specifies whether to display horizontal and vertical scroll bars
	The default is yes.
	
    status = { yes | no | 1 | 0 }
	Specifies whether to add a status bar at the bottom of the window
	The default is yes
	
    titlebar = { yes | no | 1 | 0 }
	Specifies whether to display a title bar for the window
	This parameter is ignored unless the calling application is an HTML Application
	or a trusted dialog box
	The default is yes
	
    toolbar = { yes | no | 1 | 0 }
	Specifies whether to display the browser toolbar, making buttons such 
	as 	Back, Forward, and Stop available
	The default is yes
	
    top = number
	Specifies the top position, in pixels
	This value is relative to the upper-left corner of the screen
	The value must be greater than or equal to 0
	
    width = number
	Sets the width of the window, in pixels
	The minimum value is 100
*/
