// /_scripts/global.js
//window.onerror = onError;

var w3c = (document.getElementById) ? 1:0;
var ns4 = (document.layers) ? 1:0;
var ie4 = (document.all) ? 1:0;
var pc	= (navigator.platform.indexOf('Win') == 0) ? 1:0;
var mac	= (navigator.platform.indexOf('Mac') == 0) ? 1:0;

//===============================================================================================================================================================
//=     FUNCTION:       onError() 
//=     PARAMETERS:     sMessage as string is the error reason 
//=						sUrl as string is the URL that raised the error 
//=						sLine is the line number of the error 
//=     RETURNS:        integer 
//=     PURPOSE:        All javascript errors are directed to this funciton by window.error 
//=						The true return value supresses any browser javascript errors. 
//=     AUTHOR:         Steve Jansen, Byte Interactive <stj@byteinteractive.com> 
//=     DATE:           Decmeber 11th, 2000 
//===============================================================================================================================================================
function onError(sMessage, sURL, sLine) 
{ 
        var sPrompt; 
        sPrompt = "________________________________________________________\n\n" 
        sPrompt += "A client-side javascript error has occured.\n" 
        sPrompt += "________________________________________________________\n\n" 
        sPrompt += "Line:\t" + sLine + "\n" 
        sPrompt += "Reason:\t" + sMessage + "\n" 
        sPrompt += "URL:\t" + sURL + "\n" 
                
        //test to see if this is the development site 
      	if (location.href.indexOf('byteinteractive.com') > 0 ) 
                alert(sPrompt); 
                
        return true; 
 } 

//===============================================================================================================================================================
//=	FUNCTION: 	onLoad()
//=	PARAMETERS:	none
//=	RETURNS:	true
//=	PURPOSE:	Event handler for onload of all pages
//=	AUTHOR:		Steve Jansen, Byte Interactive <stj@byteinteractive.com>
//=	DATE:		November 29th, 2000
//===============================================================================================================================================================
function onLoad()
{ 
	cacheImages();	//function to cache all rollover images
	//window.status = 'Welcome To ';
	return true;
}

//===============================================================================================================================================================
//=	FUNCTION: 	cacheImages()
//=	PARAMETERS:	none
//=	RETURNS:	null
//=	PURPOSE:	Used for JavaScript rollovers.  This function preloads (caches) all "on" state images.
//=				Call this function from the body onload event.
//=	AUTHOR:		Steve Jansen, Byte Interactive <stj@byteinteractive.com>
//=	DATE:		November 30th, 2000
//===============================================================================================================================================================
function cacheImages()
{
	var i;
	
	var oImages = new Array(document.images.length);			//array of image objects
	//reset all rollover images to their "off" state
	for (i=0; i<document.images.length; i++)
	{
		if ( document.images[i].src.search(/\_off\.(gif|jpg)/) > 0 )
		{	
			oImages[i] = new Image();
			oImages[i].src = document.images[i].src.replace("_off.", "_on.");
		}
	}
	return;
}

//===============================================================================================================================================================
//=	FUNCTION: 	setImage()
//=	PARAMETERS:	oImage (Image Object)
//=	RETURNS:	null
//=	PURPOSE:	Used for JavaScript rollovers.  This function changes the src of oImage to the "on" state
//=	AUTHOR:		Steve Jansen, Byte Interactive <stj@byteinteractive.com>
//=	DATE:		November 30th, 2000
//===============================================================================================================================================================
function setImage(oImage)
{
	var i;

	//first reset all rollover images to their "off" state
	for (i=0; i<document.images.length; i++)
	{
		if ( document.images[i].src.search(/\_on\.(gif|jpg)/) )
			document.images[i].src.replace("_on.", "_off.");
	}
	
	//now set the image to be in the "on" state		
	oImage.src = oImage.src.replace("_off.", "_on.");
				
	return;
}

//===============================================================================================================================================================
//=	FUNCTION: 	clearImages()
//=	PARAMETERS:	oImage (Image Object)
//=	RETURNS:	null
//=	PURPOSE:	Used for JavaScript rollovers.  This function resets all images to their "off" state upon the mouseout event
//=	AUTHOR:		Steve Jansen, Byte Interactive <stj@byteinteractive.com>
//=	DATE:		November 30th, 2000
//===============================================================================================================================================================
function clearImages()
{
	var i;
	
	//reset all rollover images to their "off" state
	for (i=0; i<document.images.length; i++)
	{
		if ( document.images[i].src.search(/\_on\.(gif|jpg)/) > 0 )
			document.images[i].src = document.images[i].src.replace("_on.", "_off.");
	}
	return;
}

//===============================================================================================================================================================
//=     FUNCTION:       debugObj() 
//=     PARAMETERS:     oObject is the Object to be displayed
//=     RETURNS:        n/a
//=     PURPOSE:        Display the contents of an object in a window for debugging purposes
//=     AUTHOR:         David Whalen, Byte Interactive <dw@byteinteractive.com> 
//=     DATE:           April 11, 2001
//===============================================================================================================================================================
function debugObj(oObject) {
	var oDebug = window.open('','','width=400,height=300,scrollbars=1,resizable=1');
	oDebug.document.open();
	oDebug.document.write('<table border=1><tr><th colspan=2>Debugging Object: "' + oObject.name + '"</th></tr>\n');
	for (var iItem in oObject) {
		oDebug.document.write('<tr><td><b>' + iItem + '</b></td><td>&nbsp;' + oObject[iItem] + '</td></tr>\n');
	}
	oDebug.document.write('</table>\n');
	oDebug.document.close();
}

//===============================================================================================================================================================
//=	FUNCTION: 	openWindow()
//=	PARAMETERS:	url, name, w, h, rs, scr, cen
//=	RETURNS:	null
//=	PURPOSE:	Used for opening a new window with set properties
//=	AUTHOR:		David Alperovich, Byte Interactive <dalperovich@byteinteractive.com>
//= UPDATED:	David Whalen, Byte Interactive <david.whalen@byteinteractive.com>
//=	DATE:		December 11, 2001
//===============================================================================================================================================================
function openWindow(url, name, width, height, resize, scroll, center)
{
	var sParams = '';
	name = (name == null) ? '' : name;

	sParams += 'width=' + width;
	sParams += ',height=' + height;
	sParams += (resize || resize == 'true') ? ',resizable=yes' : ',resizable=no';
	sParams += (scroll || scroll == 'true') ? ',scrollbars=yes' : ',scrollbars=no';
	sParams += (center || center == 'true') ? ',left=' + ((screen.width - width) / 2) : '';
	sParams += (center || center == 'true') ? ',top=' + ((screen.height - height) / 2) : '';

	window.name = 'opener';
	var popupWin = window.open(url, name, sParams);
	return popupWin;
}

//===============================================================================================================================================================
//=     FUNCTION:       dialog() 
//=     PARAMETERS:     sUrl as string is the URL to load into the window
//=						nWidth is the outer width of the window 
//=						nHeight is the outer height of the window
//=     RETURNS:        n/a
//=     PURPOSE:        Create a dialog window which will center on the screen.
//=		REQUIRES:		openWindow() function [q.v.]
//=     AUTHOR:         David Whalen, Byte Interactive <dw@byteinteractive.com> 
//=     UPDATED:        December 18, 2001
//===============================================================================================================================================================
function dialog(sURL, nWidth, nHeight) { 
	if (sURL != null) {
		var oDaughter = openWindow(sURL, '', nWidth, nHeight, 0, 0, 1);
		oDaughter.focus();
	}
} 

//===============================================================================================================================================================
//=     FUNCTION:       dateTimeObj() 
//=     PARAMETERS:     nDate as a UNIX-based representation of the datetime to format
//=     RETURNS:        Object
//=     PURPOSE:        Construct a Date-format object for display purposes.
//=     AUTHOR:         David Whalen, Byte Interactive <dw@byteinteractive.com> 
//=     CREATED:        December 19, 2001
//===============================================================================================================================================================
function dateTimeObj(nDate) {
	// time constants
	var cMillisecondsPerSecond	= 1000;
	var cSecondsPerMinute		= cMillisecondsPerSecond * 60;
	var cMinutesPerHour			= cSecondsPerMinute * 60;
	var cHoursPerDay			= cMinutesPerHour * 24;
	var cDaysPerYear			= cHoursPerDay * 365.25;

	// no negative numbers, please!
	nDate = Math.abs(nDate);

	// Years
	this.Years			= parseInt(nDate / cDaysPerYear);
	nDate				-= (this.Years * cDaysPerYear);
	// Days
	this.Days			= parseInt(nDate / cHoursPerDay);
	nDate				-= (this.Days * cHoursPerDay);
	// Hours
	this.Hours			= parseInt(nDate / cMinutesPerHour);
	nDate				-= (this.Hours * cMinutesPerHour);
	// Minutes
	this.Minutes		= parseInt(nDate / cSecondsPerMinute);
	nDate				-= (this.Minutes * cSecondsPerMinute);
	// Seconds
	this.Seconds		= parseInt(nDate / cMillisecondsPerSecond);
	nDate				-= (this.Seconds * cMillisecondsPerSecond);
	// Milliseconds
	this.Milliseconds	= nDate;
		
	return(this);
} 


//==========================================================================
//= Local Function: showCandidate(id)
//= Cetntralized display of candidate data in a pop-up window
//==========================================================================
function showCandidate(id) {
	if (id != null) {
		var sURL = '/candidate.asp?id=' + id;
		var oDaughter = openWindow(sURL,'candidate', 425, 510, 0, 1, 1);
		oDaughter.focus();
	}
} 

//==========================================================================
//= Local Function: sendPostcard(id)
//= Cetntralized display of candidate data in a pop-up window
//==========================================================================
function sendPostcard(id) {
	if (id != null) {
		var sURL = '/email_candidate.asp?id=' + id;
		var oDaughter = openWindow(sURL,'email', 500, 620, 0, 1, 1);
		oDaughter.focus();
	}
} 

//==========================================================================
//= Local Function: showCandidate_end(id)
//= Cetntralized display of candidate data in a pop-up window
//==========================================================================
function showCandidate_end(id) {
	if (id != null) {
		var sURL = '/candidate_end.asp?id=' + id;
		var oDaughter = openWindow(sURL,'candidate_end', 425, 510, 0, 1, 1);
		oDaughter.focus();
	}
} 

// For scrolling ticker:
var tid;
function initScrolling () {
	if (w3c && ie4) {
		tid = setInterval('scrollText()', 10);
	} else if (w3c) {
		tid = setInterval('scrollText()', 5);
	}	
}

function scrollText() {
	if (w3c) {
		if (ie4) {
			var shift = 1;
		} else {
			var shift = 2;
		}
		var st = document.getElementById('scrollingText');
		if (!st.style.left) st.style.left = '0px';
		st.style.left = (parseInt(st.style.left) - shift) + 'px';
		if (parseInt(st.innerHTML.length) + parseInt(st.style.left) < 250)
			st.style.left = '250px';
	}
}

//===============================================================================================================================================================
//=	FUNCTION: 	setImageJPG()
//=	PARAMETERS:	oImage (Image Object)
//=	RETURNS:	null
//=	PURPOSE:	Used for JavaScript rollovers.  This function changes the src of oImage to the "on" state for JPG's
//=	AUTHOR:		Steve Jansen, Byte Interactive <stj@byteinteractive.com>
//=	DATE:		November 30th, 2000
//===============================================================================================================================================================
function setImageJPG(oImage)
{
	var i;

	//first reset all rollover images to their "off" state
	for (i=0; i<document.images.length; i++)
	{
		if ( document.images[i].src.search(/_on.jpg/) )
			document.images[i].src.replace("_on.jpg", "_off.jpg");
	}
	
	//now set the image to be in the "on" state		
	oImage.src = oImage.src.replace("_off.jpg", "_on.jpg");
				
	return;
}

//===============================================================================================================================================================
//=	FUNCTION: 	clearImages()
//=	PARAMETERS:	oImage (Image Object)
//=	RETURNS:	null
//=	PURPOSE:	Used for JavaScript rollovers.  This function resets all images to their "off" state upon the mouseout event //=				for JPG's
//=	AUTHOR:		Steve Jansen, Byte Interactive <stj@byteinteractive.com>
//=	DATE:		November 30th, 2000
//===============================================================================================================================================================
function clearImagesJPG()
{
	var i;
	
	//reset all rollover images to their "off" state
	for (i=0; i<document.images.length; i++)
	{
		if ( document.images[i].src.search(/_on.jpg/) > 0 )
			document.images[i].src = document.images[i].src.replace("_on.jpg", "_off.jpg");
	}
	return;
}

//===============================================================================================================================================================
//=     FUNCTION:       freeSample() 
//=     PARAMETERS:     sUrl as string is the URL to load into the window
//=						nWidth is the outer width of the window 
//=						nHeight is the outer height of the window
//=     RETURNS:        n/a
//=     PURPOSE:        Create a dialog window which will center on the screen.
//=		REQUIRES:		openWindow() function [q.v.]
//=     AUTHOR:         David Whalen, Byte Interactive <dw@byteinteractive.com> 
//=     UPDATED:        December 18, 2001
//===============================================================================================================================================================
function freeSample(sURL, nWidth, nHeight) { 
	if (sURL != null) {
		var oDaughter = openWindow(sURL, '', nWidth, nHeight, 0, 0, 1);
		oDaughter.focus();
	}
} 