/**
$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 *********************************** */
rootDirectory = "/viewsonic/site/la";
//rootDirectory = "/clients/viewsonic/site/la"; 
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_GetBaseDirectory()
 * Get name of current directory from path name
 */			
function PINT_GetBaseDirectory()
	{
	var filePath = PINT_GetCurrentFilePath();
	filePath = filePath.substring( rootDirectory.length );
	var directories = filePath.split("/");
	return directories.length && directories[ 1 ] != "" ? directories[ 1 ] : "";
	}
	
/**
 * PINT_IsRootDirectory()
 * Determine if specified directory matches root directory
 *
 * @param directory - directory to check
 */
function PINT_IsRootDirectory( directory )
	{
	return directory == rootDirectory ? true : false;
	}

/**
 * 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(VS_ROtriggers)' ) != 'undefined' &&  
		    eval( 'typeof(VS_ROtriggers[eventsource.id])' ) != 'undefined' )
			VS_RORollover(e);
		*/	
		
		if( eval( 'typeof(PINT_MenuTriggers)' ) != 'undefined' && 
		    eval( 'typeof(PINT_MenuTriggers[eventsource.id])' ) != 'undefined' )
			PINT_MenuPopUp(e);

		if( eval( 'typeof(PINT_ROtriggers)' ) != 'undefined' &&  
		    eval( 'typeof(PINT_ROtriggers[eventsource.name])' ) != '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);

		if( eval( 'typeof(PINT_ROtriggers)' ) != 'undefined' &&  
		    eval( 'typeof(PINT_ROtriggers[eventsource.name])' ) != 'undefined' )
			PINT_RORollout(e);
	
		/*
		if( eval( 'typeof(VS_ROtriggers)' ) != 'undefined' &&  
	    	eval( 'typeof(VS_ROtriggers[eventsource.id])' ) != 'undefined' )
			VS_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;
	}	
	
/* simple redirect for drop downs */
function redirect(urlobject) 
	{
	var urlint = urlobject.selectedIndex;
	var numurls = urlobject.length;
	if( typeof( urlobject.options[urlint].value ) == 'string' && urlobject.options[urlint].value != "" )
		location = urlobject.options[urlint].value;
	}	
	
// old school popup for projector calculator //

function pop_up(location,width,height) {	
 window.open( location , 'pop_up_window' , eval("'status=no,location=no,menubar=no,toolbar=no,resizable=no,scrollbars=no," + "width=" + width + ",height=" + height + "'"));
}
