/**
$Id: pint_commonDEBUG.js,v 1.15 2003/07/03 17:25:16 cducker Exp $

Description:
	PINT Commonly used JavaScript functions and constants.

Dependencies:
	Inward:
		pint_initcleanup.js
	 
	Outward:
		none	
	
Usage:
	n/a		
*/

/* ******** Constants *********************************** */
windowStatus = "";
/* ******** Common Window Settings ********************** */
defaultStatus = "";

/**
 * PINT_GetEventSource()
 * Takes as an argument the first argument to an event handler, and 
 * returns a reference to the object that generated the event
 *
 * @param e - first argument to an event handler
 *
 * @return reference to object that triggered event
 */
function PINT_GetEventSource(e)
{
	return ( //figure out where in the dom events come in on this browser
		(e && e.target) || 
		(window && window.event && window.event.srcElement)
	);	
}

/**
 * PINT_GetElementById()
 * Tries to find an element in the document 
 * by its id or name
 *
 * @param idname - id of element to locate
 */
function PINT_GetElementById(idname)
{
	var handle;

	if (document.getElementById) {
		handle = document.getElementById(idname);
		if (handle) return handle;
	}

	if (document.getElementByName) {
		handle = document.getElementByName(idname)[0];
		if (handle) return handle;
	}

	handle = document[idname];
	if (handle) return handle;

	if (document.all) {
		handle = document.all[idname];
		if (handle) return handle;
	}
	
	if (document.anchors) {
		handle = document.anchors[idname];
		if (handle) return handle;
	}
	
	if (document.links) {
		handle = document.links[idname];
		if (handle) return handle;
	}
	
	if (document.images) {
		handle = document.images[idname];
		if (handle) return handle;
	}
	
	if (document.embeds) {
		handle = document.embeds[idname];
		if (handle) return handle;
	}

	return handle;
}

/**
 * PINT_GetIdByElement()
 * Inverse of PINT_GetElementById, returns the id, 
 * or name, of a given element
 *
 * @param element - object whose id to retrieve
 */
function PINT_GetIdByElement(element)
	{
	if (!(element)) return undefined;
	if (element.id) return element.id;
	if (element.name) return element.name;
	return undefined;
	}

/**
 * PINT_ChangePageTitle()
 * Change title of current page. Use when initial title
 * tag value is optimized for Search Engines, but you 
 * want the title to be more descriptive for the visitor.
 *
 * @param   pageTitle  - new page title
 */	
function PINT_ChangePageTitle( pageTitle )
	{
	if(document.title.readOnly == true) document.title = pageTitle;
	} 	
	
/**
 * PINT_GetCurrentFileName()
 * Get name of current file from path name
 */
function PINT_GetCurrentFileName()
	{
	var URL = unescape( window.location.pathname );
	var start = URL.lastIndexOf( "/" ) + 1;
	var end = ( URL.indexOf( "?" ) > 0 ) ? URL.indexOf( "?" ) : URL.length;
	return( URL.substring( start, end ) );
	}	
/**
 * PINT_GetCurrentFilePath()
 * Get path to current file from path name
 */
function PINT_GetCurrentFilePath()
	{
	var URL = unescape( window.location.pathname );
	var start = URL.lastIndexOf( "/" );
	return( URL.substring( 0, start ) );
	}

/**
 * PINT_GetCurrentDirectory()
 * Get name of current directory from path name
 */			
function PINT_GetCurrentDirectory()
	{
	var filePath = PINT_GetCurrentFilePath();
	var directories = filePath.split("/");
	return directories.length && directories[ directories.length-1 ] != "" ? directories[ directories.length-1 ] : "";
	}
	
/**
 * PINT_IsRootDirectory()
 * Determine if specified directory matches root directory
 *
 * @param directory - directory to check
 */
function PINT_IsRootDirectory( directory )
	{
	return directory == PINT_GetRootDirectory() ? true : false;
	}

/**
 * PINT_IsDefaultFile()
 * Determine if file name is an index file
 *
 * @param fileName - file name to check
 */
function PINT_IsDefaultFile( fileName )
	{
	return fileName == "" || fileName == PINT_GetDefaultFile() ? true : false;
	}	

/**
 * PINT_GetDefaultFile()
 * Gets DefaultFile global variable if defined.
 * 
 * @return		default file name.
 *
 */	
function PINT_GetDefaultFile()
	{
	if( typeof( defaultFile ) == 'undefined' )	
		return "";
	else
		return defaultFile;
	}
	
/**
 * PINT_FirstFocus()
 * Set cursor focus to first available form field
 * 
 * @param field - optional: reference to form input, otherwise defaults to the first element of the first form on the page
 */				
function PINT_FirstFocus()	
	{
	var elementref;
	var i=0;
	if (!(elementref = PINT_FirstFocus.arguments[0]))
		{
		if (!(document.forms[0])) return false;
		while ((elementref = document.forms[0].elements[i++]) && (elementref.type == 'hidden')) {};
		}
	if (!(elementref)) return false;
	elementref.focus();
	return true;
	}


/**
 * PINT_OnMouseOverHandler()
 * Handler for all onmouseover events. Must be explicitly set as 
 * the function handler.
 * 
 * @param e		event
 * @return		True.
 *
 */
function PINT_OnMouseOverHandler(e) 
	{
	e = (e) ? e : ((window.event) ? window.event : "")
	if (e) 
		{
		var eventsource = PINT_GetEventSource(e);
		if( eval( 'typeof(PINT_MenuTriggers)' ) != 'undefined' && 
		    eval( 'typeof(PINT_MenuTriggers[eventsource.id])' ) != 'undefined' )
			PINT_MenuPopUp(e);
		else if( eval( 'typeof(PINT_ROtriggers)' ) != 'undefined' &&  
		    eval( 'typeof(PINT_ROtriggers[eventsource.id])' ) != 'undefined' )
			PINT_RORollover(e);
			
		PINT_SetWindowStatus();	
		}
	return true;	
	}

/**
 * PINT_OnMouseOutHandler()
 * Handler for all onmouseout events. Must be explicitly set as 
 * the function handler.
 * 
 * @param e		event
 * @return		True.
 *
 */	
function PINT_OnMouseOutHandler(e) 
	{
	e = (e) ? e : ((window.event) ? window.event : "")
	if (e) 
		{
		var eventsource = PINT_GetEventSource(e);
		if( eval( 'typeof(PINT_MenuTriggers)' ) != 'undefined' && 
		    eval( 'typeof(PINT_MenuTriggers[eventsource.id])' ) != 'undefined' )
			PINT_MenuPopDown(e);	
		else if( eval( 'typeof(PINT_ROtriggers)' ) != 'undefined' &&  
			eval( 'typeof(PINT_ROtriggers[eventsource.id])' ) != 'undefined' )
			PINT_RORollout(e);
		}
	return true;
	}


/**
 * PINT_SetWindowStatus()
 * Set status bar message from parameter or global variable.
 * 
 * @param e		event
 * @return		True.
 *
 */	
function PINT_SetWindowStatus()
	{
	// if no arguments are passed, look for global windowStatus varible
	if( PINT_SetWindowStatus.arguments.length == 0 )
		{
		if( typeof(windowStatus) != 'undefined' && windowStatus != "" )
			{
			window.status = windowStatus;
			windowStatus = "";
			}
		}	
	else
		window.status = PINT_SetWindowStatus.arguments[0];
	return true;
	}	

/**
 * PINT_GetRootDirectory()
 * Gets rootDirectory global variable if defined.
 * 
 * @return		root directory path.
 *
 */	
function PINT_GetRootDirectory()
	{
	if( typeof( rootDirectory ) == 'undefined' )	
		return "";
	else
		return rootDirectory;
	}

/*
$Id: pint_printcssDEBUG.js,v 1.3 2003/08/11 20:38:55 cducker Exp $

Creator: C. Ducker

Description:
	Display different style sheets depending upon client browser capabilities.

Dependencies:
	pint_common.js
	
Usage:	
	<head>
	<script src="/javascript/pint_printcss.js" language="JavaScript" type="text/javascript"></script>
	<!--
Content Coder: D Whitworth
Programmer: 
-->

</head>
*/
function PINT_PrintCSS()
	{
	var NS4, IE, DOMstandard, CSScapable;
	NS4 = (document.layers) ? 1 : 0;
	IE = (document.all) ? 1 : 0;
	DOMstandard = (document.getElementById) ? 1 : 0;
	CSScapable = (NS4 || IE || DOMstandard) ? 1 : 0;
	
	if(CSScapable) 
		{
		if(NS4) 
			document.write("<link rel=\"stylesheet\" href=\"" + themeRootDirectory + "/css/netscape.css\" type=\"text/css\" media=\"screen\" />");
		else
			document.write("<link rel=\"stylesheet\" href=\"" + themeRootDirectory + "/css/dom.css\" type=\"text/css\" media=\"screen\" />");
		}
	}	
	
/*
$Id: pint_rolloverDEBUG.js,v 1.5 2003/07/03 17:01:44 cducker Exp $

Creator: J. Brock

Description:
	This rollover code is supposed to be 
		1. flexible, to accomodate all possible rollover activity
		2. compatible, should work on anything better than IE4, Netscape 4
		3. easy, so that all the rollover information can be inserted into the img tag in a simple way
		4. robust, so that errors, typos, bad DOM support make it degrade gracefully

Dependancies:
	pint_initcleanup.js

Usage:
	In pint_initcleanup.js:
	function init()
		{
		PINT_RORolloverInit('img1', 'img1', 'img1on.png');
		PINT_RORolloverInit('img2', 'img2', 'img2on.png', 'img1', 'img1on.png');
		};
	
	function cleanup()
		{};
	
	In page.htm:
	<head>
	<script src="\script\PINTRolloverDEBUG.js" language="JavaScript" type="text/javascript"></script>
	<script src="\script\PINTInitCleanup.js" language="JavaScript" type="text/javascript"></script>
	<!--
Content Coder: D Whitworth
Programmer: 
-->

</head>

	<!-- rolling over img1 turns img1 on, rolling over img2 turns img1 and img2 on. -->
	<img name="img1" src="img1off.png">
	<img name="img2" src="img2off.png">
*/

/*************** PRIVATE DATA STRUCTURES ****************/

var PINT_ROcapableFlag = true;			// assume this browser is rollover capable, unless it proves otherwise.
var PINT_ROtriggers = new Array();
var PINT_ROtargets = new Array();
var PINT_ROtargetRollovers = new Array();
if ((typeof PINT_ROtriggers) != 'object') PINT_ROcapableFlag = false;


/************** PUBLIC METHODS **********************/


/*	PINT_RORolloverInit()
	Initializes an html entity for image rollover triggering. This function should only be called after the body of the document has finished loading.
	Arguments: (there must be an odd number of arguments)
		1. the name attribute of the entity (usually an <a> or an <img>) which triggers the rollover
		2. the name attribute of the <img> which will be changed
		3. the source url that the image named by arg 2 will rollover to
		4. same as 2...
		5. same as 3...
		...
	Returns: true on success, false on failure
*/
function PINT_RORolloverInit()
	{
	if (!(PINT_ROcapableFlag)) return false;			// if the browser is not rollover capable, fail
	if (!(document.images)) return PINT_ROcapableFlag = false;
	if (PINT_RORolloverInit.arguments.length < 1 ) return true;		//if no arguments
	//if ((PINT_RORolloverInit.arguments.length % 2) != 0) return false;	//must be even number of arguments

	if( document.getElementById )
		{
		var setTrigger = typeof(PINT_RORolloverInit.arguments[4]) != 'undefined' ? PINT_RORolloverInit.arguments[4] : true;
		var trigger = document.getElementById( PINT_RORolloverInit.arguments[0] );
	
		if( trigger && setTrigger )
			{
			if (!(PINT_ROtriggers[trigger.id])) PINT_ROtriggers[trigger.id] = new Array(); // init the target array
			
			var i, target;
		
			target = document.getElementById( PINT_RORolloverInit.arguments[1] );
			targetrollover = PINT_RORolloverInit.arguments[2];
	
			if (!(target.src)) return false;		// if target is not an image
	
			PINT_ROtargets[target.id] = target.src;     // load up the target rollover sources
			PINT_ROtargetRollovers[targetrollover] = new Image();
			PINT_ROtargetRollovers[targetrollover].src = targetrollover; // cache rollover images in associative array
			//PINT_ROtriggers[trigger.name][target.name] = PINT_ROtargetRollovers[targetrollover]; // reference to the cached image
			PINT_ROtriggers[trigger.id][target.id] = PINT_ROtargetRollovers[targetrollover]; // reference to the cached image
			
			if( typeof(PINT_RORolloverInit.arguments[3]) != 'undefined' )
				PINT_ROtriggers[trigger.id]["window.status"] = PINT_RORolloverInit.arguments[3];
			
			
				
			trigger.onmouseover = PINT_OnMouseOverHandler;
			trigger.onmouseout = PINT_OnMouseOutHandler;
			}
		}
	return true;
	}



/********* PRIVATE METHODS ************/
function PINT_RORollover(e)
{
	if (!PINT_ROcapableFlag) return false;
	var eventsource = PINT_GetEventSource(e);	//figure out where the events come in on this browser
	if (!eventsource) return (PINT_ROcapableFlag = false); // if there's no events, can't do rollovers
	PINT_RORolloverById(eventsource.id);
	return true;
}

function PINT_RORollout(e)
{
	if (!PINT_ROcapableFlag) return false;
	var eventsource = PINT_GetEventSource(e);	//figure out where the events come in on this browser
	if (!eventsource) return (PINT_ROcapableFlag = false); // if there's no events, can't do rollovers
	PINT_RORolloutById(eventsource.id);
	return true;
}	
	
	
function PINT_RORolloverById(elementId)
	{
	if(!PINT_ROcapableFlag)return false;
	if(eval('typeof(PINT_ROtriggers[elementId])')!='undefined')
		{
		for (target in PINT_ROtriggers[elementId]) //for this trigger, rollover each of it's targets
			{
			if( typeof( document[target] ) == 'object' )
				document[target].src = PINT_ROtriggers[elementId][target].src;
	
			if( target == "window.status" )
				windowStatus = PINT_ROtriggers[elementId][target];
			}
		}
	return true;
	}

function PINT_RORolloutById(elementId)
	{
	if(!PINT_ROcapableFlag)return false;
	if(eval('typeof(PINT_ROtriggers[elementId])')!='undefined')
		{
		for (target in PINT_ROtriggers[elementId]) //for this trigger, reset the src for each of it's targets
			{
			if( typeof( document[target] ) == 'object' )
				document[target].src = PINT_ROtargets[target];
			}
		}
	return true;
	}	




var rot13map;
function rot13init()
	{
    var map = new Array();
    var s   = "abcdefghijklmnopqrstuvwxyz";
    for (i=0; i<s.length; i++) map[s.charAt(i)] = s.charAt((i+13)%26);
    for (i=0; i<s.length; i++) map[s.charAt(i).toUpperCase()] = s.charAt((i+13)%26).toUpperCase();
    return map;
	}

function rot13(a)
	{
    if (!rot13map) rot13map=rot13init();
    var s = "";
    for (i=0; i<a.length; i++)
    {
        var b = a.charAt(i);
        s += (b>='A' && b<='Z' || b>='a' && b<='z' ? rot13map[b] : b);
    }
    return s;
	}
	

// named this for obfuscation
function print_e(user, domain)
	{
	var e = rot13(user) + "@" + rot13(domain);
	var out = '<a href="mailto:' + e + '">';
	out += e;
	out += '</a>';
	document.write(out);
	}

PINT_FlashObject=function(swf,id,w,h,defaultImage,ver,imageMap,c){this.swf=swf;this.id=id;this.width=w;this.height=h;this.imageMap=imageMap;this.version=ver||6;this.align="middle";this.codebase=this.version+",0,0,0";this.redirect="";this.sq=document.location.search.split("?")[1]||"";this.defaultImage=defaultImage;this.altTxt="Please <a href='http://www.macromedia.com/go/getflashplayer'>upgrade your Flash Player</a>.";this.bypassTxt="";this.params=new Object();this.variables=new Object();if(c)this.color=this.addParam('bgcolor',c);this.addParam('quality','high');this.doDetect=getQueryParamValue('detectflash');};

PINT_FlashObject.prototype.addParam=function(name,value){this.params[name]=value};

PINT_FlashObject.prototype.getParams=function(){return this.params};

PINT_FlashObject.prototype.getParam=function(name){return this.params[name]};

PINT_FlashObject.prototype.addVariable=function(name,value){this.variables[name]=value};

PINT_FlashObject.prototype.getVariable=function(name){return this.variables[name]};PINT_FlashObject.prototype.getVariables=function(){return this.variables};PINT_FlashObject.prototype.getParamTags=function(){var paramTags="";for(var param in this.getParams()){paramTags+='<param name="'+param+'" value="'+this.getParam(param)+'" />'}if(paramTags==""){paramTags=null}return paramTags};

PINT_FlashObject.prototype.getHTML=function(){var flashHTML="";if(window.ActiveXObject&&navigator.userAgent.indexOf('Mac')==-1){flashHTML+='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+this.codebase+'" width="'+this.width+'" height="'+this.height+'" id="'+this.id+'" align="'+this.align+'">';flashHTML+='<param name="movie" value="'+this.swf+'" />';if(this.getParamTags()!=null){flashHTML+=this.getParamTags();}if(this.getVariablePairs()!=null){flashHTML+='<param name="flashVars" value="'+this.getVariablePairs()+'" />'}flashHTML+='</object>'}else{flashHTML+='<embed type="application/x-shockwave-flash" src="'+this.swf+'" width="'+this.width+'" height="'+this.height+'" id="'+this.id+'" align="'+this.align+'"';for(var param in this.getParams()){flashHTML+=' '+param+'="'+this.getParam(param)+'"'}if(this.getVariablePairs()!=null){flashHTML+=' flashVars="'+this.getVariablePairs()+'"'}flashHTML+='></embed>'}return flashHTML};

PINT_FlashObject.prototype.getVariablePairs=function(){var variablePairs=new Array();for(var name in this.getVariables()){variablePairs.push(name+"="+escape(this.getVariable(name)));}if(variablePairs.length>0){return variablePairs.join("&");}else{return null}};

PINT_FlashObject.prototype.write=function(elementId){if(detectFlash(this.version)||this.doDetect=='false'){if(elementId){document.getElementById(elementId).innerHTML=this.getHTML();}else{document.write(this.getHTML());}}else{if(this.redirect!=""){document.location.replace(this.redirect);}else if(this.defaultImage!=""){imageString="<img src=\""+this.defaultImage+"\" width=\""+this.width+"\" height=\""+this.height+"\" border=\"0\" alt=\"\"";if(eval('typeof(this.imageMap)')!="undefined"&&this.imageMap!="")imageString+=" usemap=\"#"+this.imageMap+"\" ";imageString+=" class=\"inlineimage\" />";document.write(imageString);}else document.write(this.altTxt+""+this.bypassTxt);}};

function getFlashVersion()
{
        var flashversion=0;
        if(navigator.plugins&&navigator.plugins.length)
        {
                var x=navigator.plugins["Shockwave Flash"];
                if(x)
                {
                        if(x.description)
                        {
                                var y=x.description;
                                //the bad line of code!!
                                flashversion=y.charAt(y.indexOf('.')-1);
                                //FIX
                                var pieces = y.split(' ');
                                flashversion = pieces[2]*1;
                        }
                }
        }else
        {
                result=false;
                for(var i=15;i>=3&&result!=true;i--)
                {
                        execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
                        flashversion=i
                }
        }
        return flashversion
}


function detectFlash(ver)
{
	if(getFlashVersion()>=ver)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function getQueryParamValue(param)
{
	var q=document.location.search;
	var detectIndex=q.indexOf(param);
	if(q.length>1&&detectIndex!=-1)
	{	
	return q.substring(q.indexOf("=",detectIndex)+1,q.indexOf("&",detectIndex));
	}
	else{return true;
	}
}
