/********************************************************************************
*	Page Tools Version 3.2	 Updated on March 1, 2004							*
* 	By Jordan Duggan of Indicium Design, Copyright (c) 1997-2004				*
*	jordan@indicium.com				www.indicium.com							*
*********************************************************************************/

//  Utility functions for debugging javascript
//	strTrace = 'Start';
//	function printTrace(){alert(strTrace);}
//	function trace(strValue){strTrace += '\n' + strValue;}

/*---------------------------------------------------------------------------------------------------
	GLOBAL CONFIGURATION SETTINGS
----------------------------------------------------------------------------------------------------*/
	ptConfig = new Array();

	// Message for functions not supported by user's browser
	ptConfig['strNonIEMsg'] = 'We apologize, but this function is not supported by this browser.';
	// Absolute path to page used to create printer friendly view
	ptConfig['strPrinterFriendlyPagePath'] = '/tools/pf_view.asp';
	ptConfig['strEmailURLPagePath'] 	   = '/tools/email_page.asp';

	// Rollover image registrations for this specific page layout
	function initPage(){
		initMainNav();
		initPageTools();
		//printTrace();
	}

	// Rollover main nav image registrations for this specific page layout
	function initMainNav(){
		if (document.images){	
			// Main nav rollover object registration
			var pgNavImgs = new Object();
			// Set the image base path where the rollovers are located
			pgNavImgs['ImgBasePath'] = '/_images/header/';
			// Main nav - Normal State, Active State
			pgNavImgs['Home']  				= ['nav_home_0.gif','nav_home_1.gif'];
			pgNavImgs['DataManagement']     = ['nav_data_management_0.gif','nav_data_management_1.gif'];
			pgNavImgs['Implementations']	= ['nav_implementations_0.gif','nav_implementations_1.gif'];  	   
			pgNavImgs['ProductsServices']   = ['nav_products_services_0.gif','nav_products_services_1.gif'];
			pgNavImgs['DataManagement']     = ['nav_data_management_0.gif','nav_data_management_1.gif'];
			pgNavImgs['Resources']			= ['nav_resources_0.gif','nav_resources_1.gif'];  
			pgNavImgs['AboutUs'] 		 	= ['nav_about_us_0.gif','nav_about_us_1.gif'];  
			pgNavImgs['NewsEvents']    		= ['nav_news_events_0.gif','nav_news_events_1.gif'];
			preload(pgNavImgs);
		}
	}

	// Rollover page tool image registrations for this specific page layout
	function initPageTools(){
		if (document.images){	
			// Page tool rollover object registration
			var pgToolImgs = new Object();
			// Set the image base path where the rollovers are located
			pgToolImgs['ImgBasePath'] = '';
			// Top Page Tool - Normal State, Active State
			pgToolImgs['topEmail']    = ['top_email_0.gif','top_email_1.gif'];
			pgToolImgs['topPrint']    = ['top_print_0.gif','top_print_1.gif'];
			pgToolImgs['topBookmark'] = ['top_bookmark_0.gif','top_bookmark_1.gif'];
			pgToolImgs['topContact']  = ['top_contact_0.gif','top_contact_1.gif'];  	   
			// Bottom Page Tools - Normal State, Active State
			pgToolImgs['botEmail']    = ['bot_email_0.gif','bot_email_1.gif'];     
			pgToolImgs['botPrint'] 	  = ['bot_print_0.gif','bot_print_1.gif'];   
			pgToolImgs['botBookmark'] = ['bot_bookmark_0.gif','bot_bookmark_1.gif'];
			pgToolImgs['botContact']  = ['bot_contact_0.gif','bot_contact_1.gif'];
			preload(pgToolImgs);
		}
	}
/*---------------------------------------------------------------------------------------------------
	Image Preloader:
	These functions are used by individual image rollover registrations (such as the page tools) to 
	preload and manipulate rollover image states
----------------------------------------------------------------------------------------------------*/

	// Create a global page object that will hold all image rollovers 
	// associated with an array of their various view states
	allImageRegistrations = new Object();

	// Preload all images in the global registration object 
	function preload(objNewImageRegs) {
		// Loop over all new rollover enabled image registrations
		for (strReg in objNewImageRegs) {
			// Loop over all states of rollover objects
			if (strReg != 'ImgBasePath') {
				// If there are problems, uncomment to trace the loading process
				// alert(strReg + ' ' + typeof objNewImageRegs[strReg] + ' ' + objNewImageRegs[strReg][0]);
				allImageRegistrations[strReg] = new Array(objNewImageRegs[strReg].length);
				for (var k = 0; k < objNewImageRegs[strReg].length; k++) {
					// Add the new rollover registrations to global page registration object
					allImageRegistrations[strReg][k] = new Image();
					allImageRegistrations[strReg][k].src = objNewImageRegs['ImgBasePath'] + objNewImageRegs[strReg][k];
					//trace('Loading ' + objNewImageRegs['ImgBasePath'] + objNewImageRegs[strReg][k]);
				}
			}
		}   
	}   
	
	// This function swaps images   
	function imgSwap(img, strImage, intState) {
		if (document.images){
			img.src = allImageRegistrations[strImage][intState].src;
		} 
	}
	
	
/*---------------------------------------------------------------------------------------------------
	Open printer friendly page:
	Opens up a child window for the same URL using the printer friendly page 
----------------------------------------------------------------------------------------------------*/

	function openPrinterFriendly(){
		window.name = 'main';
		win=window.open(ptConfig['strPrinterFriendlyPagePath'] + '?url=' + escape(window.location.href), 'PFFormat', "width=750, height=550, scrollbars=yes, resizable=yes, toolbar=no, status=no, location=no, menubar=no");
		win.focus();      // BRING TO FRONT
	}
	
/*---------------------------------------------------------------------------------------------------
	Open Email URL to friend page:
	Opens up a dialog window to email the URL to a friend
----------------------------------------------------------------------------------------------------*/

	function openEmailURLForm(){
		openup(ptConfig['strEmailURLPagePath'] + '?url=' + escape(window.location.href), 'EMAILPAGE');
	}

/*---------------------------------------------------------------------------------------------------
	Bookmark This Page Script:
	Automatically opens the bookmark dialog in IE 4.0 and later (degrades gracefully in others)
	To use an image instead of the text for this link by using the following in the strWho variable:
		var strWho = "<img src='some.gif' width='30' height='30' border='0'>"
	Use an image name (and full http:// path if needed) as shown above. 
----------------------------------------------------------------------------------------------------*/

	//  Modify prototype so Netscape will support .innerText
	if (typeof HTMLElement!="undefined") {
			HTMLElement.prototype.__defineGetter__("innerText", function() {	return this.innerHTML.replace(/<[^>]+>/g,"");	}
		)
	}
	
	function addBookmark(){
		//  Bookmark URL
		var strUrl = window.location.href;
		//  Reader friendly caption to describe bookmarked URL
		var strWho = 'DataDynamic - ' + document.getElementById('PageTitle').innerText;
		var strBrowser = navigator.appName;
		var intVersion = parseInt(navigator.appVersion);
		if ((strBrowser == "Microsoft Internet Explorer")&&(intVersion >= 4)) {
		   window.external.AddFavorite(strUrl,strWho);
		}else{
		   alert(ptConfig['strNonIEMsg']);
		} 
	}
	
/*---------------------------------------------------------------------------------------------------
	Utilitiy Function to open child windows for various purposes
----------------------------------------------------------------------------------------------------*/
function openup(openURL, viewName) {
	var intHeight, intWidth, winParams = '';
	switch (viewName){ 
	   case 'BASIC' : 
		  intHeight = 550;
		  intWidth  = 525;
		  winParams = 'scrollbars=yes, resizable=yes, toolbar=yes, status=yes, location=yes, menubar=yes';
		  openCenteredWindow(openURL, viewName, intHeight, intWidth, winParams);
		  break;
	   case 'EMAILPAGE' : 
		  intHeight = 550;
		  intWidth  = 525;
		  winParams = 'scrollbars=yes, resizable=yes, toolbar=no, status=no, location=no, menubar=no';
		  openCenteredWindow(openURL, viewName, intHeight, intWidth, winParams);
		  break;
	   case 'DEMO' : 
		  intHeight = 552;
		  intWidth  = 815;
		  winParams = 'scrollbars=yes, resizable=yes, toolbar=yes, status=yes, location=no, menubar=yes';
		  openCenteredWindow(openURL, viewName, intHeight, intWidth, winParams);
		  break;
	   case 'PHOTO' : 
		  intHeight = 550;
		  intWidth  = 525;
		  winParams = 'scrollbars=yes, resizable=yes, toolbar=no, status=no, location=no, menubar=no';
		  openCenteredWindow(openURL, viewName, intHeight, intWidth, winParams);
		  break;
	   case 'LINKMANAGER' : 
		  intHeight = 325;
		  intWidth  = 700;
		  winParams = 'scrollbars=yes, resizable=yes, toolbar=no, status=no, location=no, menubar=no';
		  openCenteredWindow(openURL, viewName, intHeight, intWidth, winParams);
		  break; 
	   case 'ADMINDETAIL' : 
		  intHeight = 550;
		  intWidth  = 780;
		  winParams = 'scrollbars=yes, resizable=yes, toolbar=no, status=no, location=no, menubar=no';
		  openCenteredWindow(openURL, viewName, intHeight, intWidth, winParams);
		  break; 
	   case 'ADMINPROCESS' : 
		  intHeight = 275;
		  intWidth  = 430;
		  winParams = 'scrollbars=no, resizable=no, toolbar=no, status=no, location=no, menubar=no';
		  openCenteredWindow(openURL, viewName, intHeight, intWidth, winParams);
		  break;		    
	   default : 
		  // Warn of invalid call 
		  alert('An invalid window view was called.');
	}
}

function openCenteredWindow(openURL, viewName, intHeight, intWidth, winParams) {
	// First label the parent window for callback controls to target
	window.name = 'main';
	// Calculate the center coordinates
	var intLeft = Math.floor( (screen.width - intWidth) / 2);
	var intTop = Math.floor( (screen.height - intHeight) / 2);
	//Build Param string
	var strParms = "top=" + intTop + ",left=" + intLeft + ",height=" + intHeight + ",width=" + intWidth;
	if (winParams) {strParms += "," + winParams; }
	//Open the window and bring it to the front
	var win = window.open(openURL, viewName, strParms);
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }      // BRING TO FRONT
	return win;
}

function loadIntoOpener(openURL) {
    if (opener && !opener.closed)
        opener.location=openURL;
    else {
		var win = window.open(openURL, '', "width=800, height=600, scrollbars=yes, resizable=yes, toolbar=yes, status=yes, location=yes, menubar=yes");
        // var myWin = window.open(page,'','width=100,height=100');
        // trick the window into thinking it was opened by this new window:
        opener = win;
    }
}

/*---------------------------------------------------------------------------------------------------
	Utilitiy Functions
----------------------------------------------------------------------------------------------------*/
	// Allows select menus to jump to an anchor on a page 
	function jumpTo(strLoc){
    	return location.href = "#"+ strLoc;
	}
	
	function selVal(strName){
		var selObj = document.getElementById(strName);
		return selObj.options[selObj.selectedIndex].value;
	}


/*---------------------------------------------------------------------------------------------------
	Initilization Function - After everything is loaded
----------------------------------------------------------------------------------------------------*/

	initPage();
	
	