
/* Javascript functions for Challenger Connect */


/* 	Name:			formatMyDate
	Description:	formats date parameter and writes it out to the document
	Parameters:		dateSource=date to format
					dateFormat=format to return date as
	Example:
					dateFormat(1) = dd/mm/yyyy   = 21/04/2004
					dateFormat(2) = dd MMMM yyyy = 21 March 2004
	
	Created By:		Ian Fairbairn
	Created Date:	21 April 2004
*/
function formatMyDate(dateSource, dateFormat)
{
    if (dateSource) {
    
        if (dateFormat==1) {     
            var d  = dateSource.getDate();
            var day = (d < 10) ? '0' + d : d;
            var m = dateSource.getMonth() + 1;
            var month = (m < 10) ? '0' + m : m;
            var yy = dateSource.getYear();
            var year = (yy < 1000) ? yy + 1900 : yy;
            return (day + "/" + month + "/" + year);
        }else{
            var d  = dateSource.getDate();
            var day = (d < 10) ? '0' + d : d;
            var month = getMonthName(dateSource.getMonth() + 1);
            var yy = dateSource.getYear();
            var year = (yy < 1000) ? yy + 1900 : yy;
            return (day + " " + month + " " + year);
        }

    }else{
    
        return "empty";
    }    
}

/* 	Name:			getMonthName
	Description:	formats a month given as a integer as its long name
	Parameters:		monthNumber = month number to format
	Example:
					getMonthName(1) = "January"
					getMonthName(11) = "November"
					getMonthName(0) = "Unknown"
					
	Created By:		Ian Fairbairn
	Created Date:	21 April 2004
*/
function getMonthName(monthNumber) {

    switch(monthNumber) {
        case 1 :
            return "January";
        case 2 :
            return "February";
        case 3 :
            return "March";
        case 4 :
            return "April";
        case 5 :
            return "May";
        case 6 :
            return "June";
        case 7 :
            return "July";
        case 8 :
            return "August";
        case 9 :
            return "September";
        case 10 :
            return "October";
        case 11 :
            return "November";
        case 12 :
            return "December";
        default :
            return "Unknown";
    }
}


/* 	Name:			popupWindow
	Description:	opens a popup window
	Parameters:		url = url of page to show in new window
					windowHeight = height of popup window
					windowWidth = width of popup window
	Example:
					popupWindow("/intranet/test.html", 500, 500)
					
	Created By:		Ian Fairbairn
	Created Date:	21 April 2004			
*/
function popupWindow(url, windowHeight, windowWidth)
{
    window.open(url,"","height=" + windowHeight + ",width=" + windowWidth + ",titlebar=no,status=no,toolbar=no,menubar=no,location=no");
}


/* 	Name:			formatTable
	Description:	formats and tables within the document held within a div element with id="table"
	Parameters:		divTable = HTML div element
	Example:
					var div = document.getElementById("table")
					if (div) {
						formatTable(div);
					}
	Created By:		Ian Fairbairn
	Created Date:	21 April 2004					
*/

function formatTableBlue(divTable)
{

	if (divTable)
		{
			var tablesToFormat = divTable.children.tags("table");
			var rowsToFormat;
			for (var i=0; i < tablesToFormat.length; i++) {
				rowsToFormat = tablesToFormat[i].rows;
				
				for (var j=0; j < rowsToFormat.length; j++) {
				
					colMax = rowsToFormat[j].cells.length;
					if (j==0)
					{
						rowsToFormat[j].bgColor = "0288C5";
							for (var k=0; k<colMax;k++)
							{
								rowsToFormat[j].cells[k].style.color = "#d9e7ec";
								rowsToFormat[j].cells[k].style.fontWeight= "bold";
								rowsToFormat[j].cells[k].style.fontSize = "10px";
							}
					}
					else
					{
						if (j % 2) {
							rowsToFormat[j].bgColor = "#cbdee5";
						} else {
							rowsToFormat[j].bgColor = "#d9e7ec";
						}
						for (var k=0; k<colMax;k++)
						{
								rowsToFormat[j].cells[k].style.color = "#666666";
								rowsToFormat[j].cells[k].style.fontWeight= "normal";
								rowsToFormat[j].cells[k].style.fontSize = "10px";
						}
					}
						
				}
			}
		}
}	

function formatTable(divTable)
{

	if (divTable)
		{
			var tablesToFormat = divTable.children.tags("table");
			var rowsToFormat;
			for (var i=0; i < tablesToFormat.length; i++) {
				rowsToFormat = tablesToFormat[i].rows;
				for (var j=0; j < rowsToFormat.length; j++) {
					if (j % 2) {
						rowsToFormat[j].bgColor = "#EAF3F8";
					} else {
						rowsToFormat[j].bgColor = "#DAEBF3";
					}
				}
			}
		}
}

function formatTableGreen(divTable)
{

	if (divTable)
		{
			var tablesToFormat = divTable.children.tags("table");
			var rowsToFormat;
			for (var i=0; i < tablesToFormat.length; i++) {
				rowsToFormat = tablesToFormat[i].rows;
				
				for (var j=0; j < rowsToFormat.length; j++) {
				
					colMax = rowsToFormat[j].cells.length;
					if (j==0)
					{
						rowsToFormat[j].bgColor = "E0EC96";
							for (var k=0; k<colMax;k++)
							{
								rowsToFormat[j].cells[k].style.color = "#5C6A08";
								rowsToFormat[j].cells[k].style.fontWeight= "bold";
								rowsToFormat[j].cells[k].style.fontSize = "10px";
							}
					}
					else
					{
						if (j % 2) {
							rowsToFormat[j].bgColor = "#F0F0EE";
						} else {
							rowsToFormat[j].bgColor = "#E7E7E7";
						}
						for (var k=0; k<colMax;k++)
						{
								rowsToFormat[j].cells[k].style.color = "#666666";
								rowsToFormat[j].cells[k].style.fontWeight= "normal";
								rowsToFormat[j].cells[k].style.fontSize = "10px";
						}
					}
						
				}
			}
		}
}		


/* 	Name:			getRandomImage
	Description:	returns a random URL of an image from any number of image URL's passed into the function
	Parameters:		imageURL[n]
	Example:
					document.write "<img src='" + getRandomImage("images/image1.gif","images/image2.gif","images/image3.gif") + "'/>"

	Created By:		Ian Fairbairn
	Created Date:	22 April 2004					
*/
function getRandomImage()
{

	return arguments[Math.floor(Math.random()*arguments.length)];

}


/* 	Name:			formatFileSize
	Description:	removes decimal places from a filesize
	Parameters:		strFileSize = number to format
	Example:
					document.write(formatFileSize('<%attributeDocumentSize%>'));

	Created By:		Fred
	Created Date:	30 April 2004					
*/
function formatFileSize(strFileSize) 
{
	var formattedFileSize = strFileSize;
	if (formattedFileSize.indexOf('.') != -1)
	{
		return formattedFileSize.substring(0, formattedFileSize.indexOf('.'));
	} else  {
		return formattedFileSize;
	}
}

