/*
global.js
--------------------------------------------
This JavaScript file contains global functions that are used across WFSI-owned web sites.
List of functions:
 - scs (string Url)
 - site (string Content ID [,string File Extension])
 - outlink (string Url)
 - nav (string Element)
 - webmaster ()
 - SecureSite (string Url)
 - siteSearch (object HTML Search Form)

 - getMonthName()
 - getTodaysDate()
 - getPartOfDay()
 - getTimeOfDay()
*/

strErrVarNotFound = "One of the variables needed to perform this function could not be found. Please contact this site's web editor to inform them of the error.";
strErrFrmFldNotFound = "One of the standard form fields needed to perform this function could not be found. Please contact this site's web editor to inform them of the error.";

function randomString() {
	var chars = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz1234567890";
	var string_length = 3;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}

//	<summary>
//	Appends the full URL path for this particular site to the supplied file name/url.
//	</summary>
function scs(url)
{
	// Check for existence of strHost variable from site
	if (typeof strHost == "undefined")
	{
		alert(strErrVarNotFound);
		return;
	}
	window.location.href="http://" + strHost + "/stellent/groups/public/documents/www/" + url;
}



//	<summary>
//	Appends the full URL path for this particular site to the supplied file name/url. In
//	addition, it allows the user to only supply the Stellent content id number instead
//	of requiring the file prefix. File extension is optional and defaults to .hcsp if not
//	supplied to the function.
//	</summary>
function site(myval,ext)
{
	// Check for existence of strHost and strPrefix variables from site
	if (typeof strHost == "undefined" || typeof strPrefix == "undefined")
	{
		alert(strErrVarNotFound);
		return;
	}

	// Set default extension and check to see if it is overridden
	var strExt = "hcsp";
	if (ext)
	{
		strExt = ext;
	}
	window.location.href="http://" + strHost + "/stellent/groups/public/documents/www/" + strPrefix + myval + "." + strExt;
}



//	<summary>
//	Appends the full URL path for this particular site to the supplied file name/url. In
//	addition, it allows the user to only supply the Stellent content id number instead
//	of requiring the file prefix. File extension is optional and defaults to .hcsp if not
//	supplied to the function. This will open the URL in a new window.
//	</summary>
function outsite(myval,ext)
{
	// Check for existence of strHost and strPrefix variables from site
	if (typeof strHost == "undefined" || typeof strPrefix == "undefined")
	{
		alert(strErrVarNotFound);
		return;
	}

	// Set default extension and check to see if it is overridden
	var strExt = "hcsp";
	if (ext)
	{
		strExt = ext;
	}
	window.open("http://" + strHost + "/stellent/groups/public/documents/www/" + strPrefix + myval + "." + strExt, 'External', '');
}




//	<summary>
//	Appends the full URL path for this particular site to the supplied file name/url. In
//	addition, it allows the user to only supply the Stellent content id number instead
//	of requiring the file prefix. Requires the document to be checked into the "media" type.
//  File extension is optional and defaults to .mov if not supplied to the function.
//	</summary>
function media(myval,ext)
{
	// Check for existence of strHost and strPrefix variables from site
	if (typeof strHost == "undefined" || typeof strPrefix == "undefined")
	{
		alert(strErrVarNotFound);
		return;
	}

	// Set default extension and check to see if it is overridden
	var strExt = "mov";
	if (ext)
	{
		strExt = ext;
	}
	window.location.href="http://" + strHost + "/stellent/groups/public/documents/media/" + myval + "." + strExt;
}




//	<summary>
//	Opens the supplied URL it in a new window.
//	</summary>
function outlink(url)
{
	window.open(url, 'External' + randomString(), '');
}



//	<summary>
//	Looks for the HTML element on the page and toggles between visible & invisible display.
//	</summary>
function nav(nr)
{
	if (document.getElementById)
	{
		vista = (document.getElementById(nr).style.display == 'none') ? 'block' : 'none';
		document.getElementById(nr).style.display = vista;
	}
}



//	<summary>
//	Opens a mailto: link to the web editor's email address for this site.
//	</summary>
function webmaster()
{
	// Check for existence of strWebEditorEmail and strWebEditorSubject variables from site
	if (typeof strWebEditorEmail == "undefined" || typeof strWebEditorSubject == "undefined")
	{
		alert(strErrVarNotFound);
		return;
	}
	window.location.href="mailto:" + strWebEditorEmail + "?subject=" + strWebEditorSubject;
}



//	<summary>
//	Takes a <SELECT> list as an object. Jumps to the URL that is the value of the OPTION tag.
//	</summary>
// Pick from a drop down and jump to another url
function JumpMenu(myval)
{
	window.location.href = myval.options[myval.selectedIndex].value;
}



//	<summary>
//	Opens a link in a new window. This is intended to open the VeriSign secure site seal
//	window with WFSI's certificate embedded in it.
//	</summary>
function SecureSite(url)
{
	sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
	self.name = "mainWin";
}



//	<summary>
//	Performs a standard search of the content server from a web site. The form must 
//	pass itself as an object into the function.
//	</summary>
function siteSearch(myform)
{
	// Check for existence of SearchField and QueryText form fields from calling page
	if (typeof myform.SearchField == "undefined" || typeof myform.QueryText == "undefined")
	{
		alert(strErrFrmFldNotFound);
		return false;
	}
	// Check for existence of strStandardSearch variable from site
	if (typeof strStandardSearch == "undefined")
	{
		alert(strErrVarNotFound);
		return false;
	}

	// Set search text variable
	var strSearchField = myform.SearchField.value;
	strSearchField = strSearchField.toLowerCase(); // Convert to lowercase for verity
	var strSearchField = "(" + strSearchField + " <OR> dDocTitle <substring> " + strSearchField + " <OR> xComments <substring> " + strSearchField + ")"+ strStandardSearch;

	var strSrchTxt = strSearchField;
	// Test to see if any search terms were entered, if so submit the form
	if (myform.SearchField.value.length > 0)
	{
		myform.QueryText.value = strSrchTxt;
		myform.submit();
	}
	else
	{
		alert("Please enter a search term in order to perform your search.");
		myform.SearchField.focus();
		return false;
	}
}



//	<summary>
//	Return the name of the current month as a string.
//	</summary>
function getMonthName()
{
	var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	var date = new Date();
	return months[date.getMonth()];
}



//	<summary>
//	Return today's date in the 'MMMM, DD YYYY' format as a string.
//	</summary>
function getTodaysDate()
{
	var date = new Date();
	return getMonthName() + " " + date.getDate() + ", " + (date.getYear()+( (date.getYear()>1900) ? 0 : 1900));
}



//	<summary>
//	Return good morning/afternoon/evening as a string.
//	</summary>
function getPartOfDay()
{
	var date = new Date();
	var hours = date.getHours();
	var DayPart = "Morning";
	if ((hours > 17) && (hours < 24))
	{
		DayPart = "Evening";
	}
	else if (hours > 11)
	{
		DayPart = "Afternoon"
	}
	return "Good " + DayPart;
}



//	<summary>
//	Return the current time in 'hh:mm AM/PM' format as a string.
//	</summary>
function getTimeOfDay()
{
	var date = new Date();
	var hours = date.getHours();
	var minutes = date.getMinutes();
	var AMPM = (hours >= 12) ? "PM" : "AM";
	if (hours > 12)
	{
		hours -= 12;
	}
	if (hours == 0)
	{
		hours = 12;
	}
	if (minutes < 10)
	{
		minutes = "0" + minutes;
	}
	return hours + ":" + minutes + " " + AMPM;
}

function mailIt( mstr ) {
	mstr = mstr.replace(/\/n/g,"%0D%0A");
	window.location=mstr;
} // function..mailIt

