/* 
    Document   : nvaigation.js
    Created on : November 8, 2006, 11:35 AM
    Author     : Phillip R. Cargo
    Description:
        Provides the JavaScript need to make the TOC/Nav function
        These functions are called both by leftFrame.jsp and the mainFrame.jsp
*/

highlightedSection = null;  	// Variable to Hold Last Highlighted Section

// Variable to Hold a list of Sections
sectionArray = new Array("1-1","1-2","1-3");
// Variable to Hold Complete Status of each Section
sectionComplete = "";
for (var secInd = 0; secInd < sectionArray.length; secInd ++)
	sectionComplete = sectionComplete + "0";


// Move the Window Scroll Position to bring the Section into View
//  moveToTitle( '1' );
function moveToTitle( inSection ) {
    var eleDiv = document.getElementById( inSection + 'title' );
    eleDiv.scrollIntoView();
    //self.scrollTo(0, f_scrollTop() );
}

// Expand a Title Section
//  expandTitle('title1');
function expandTitle( inSection ) {
    var eleDiv = document.getElementById( inSection );
    var eleImg = document.getElementById( inSection + 'img' );
    
    eleDiv.style.display = "block";
    eleImg.src = 'images/arrow_dn.gif';
}

// Collapse a Title Section
//  collapseTitle( 'title1' );
function collapseTitle( inSection ) {
    var eleDiv = document.getElementById( inSection );
    var eleImg = document.getElementById( inSection + 'img' );
    eleDiv.style.display = "none";
    eleImg.src = 'images/arrow_rt.gif';
}

// Open/Closes a Section based on its current state
//  toggleTitle( 'title1' );
function toggleTitle( inSection ) {
    var eleDiv = document.getElementById( inSection );
    if ( eleDiv.style.display == "none" )
            expandTitle( inSection );
    else
            collapseTitle( inSection );
}

// Sets the Corresponding Section Indicator to the inState Color
function setTitleIndicator( inSection, inState ) {
	return; 
	/*
    var eleImg = document.getElementById( inSection + 'ind' );
    switch ( inState ) {
        case -1:   eleImg.src = "images/yellight.gif"; break;
        case 0:    eleImg.src = "images/redlight.gif"; break;
        case 1:    eleImg.src = "images/greenlight.gif"; break;
    }
	*/
}

function setSectionIndicator( inSection ) {
    var eleImg = document.getElementById( inSection + 'ind' );
    eleImg.src = 'images/check.gif';
}


// Set a Cookie for 
function setCookieIndicator( inSection ) {

	sectionCookie = readCookie('pmyrComplete');
		
	// If there is no Cookie set a Default
	if ( sectionCookie == null )
		sectionCookie = sectionComplete;
	
	var sectionIndex = null;
	for (secInd = 0; secInd < sectionArray.length; secInd ++)
		if ( sectionArray[secInd] == inSection )
			sectionIndex = secInd;
	
	sectionCookie = sectionCookie.substr(0,sectionIndex) + '1' + sectionCookie.substr(sectionIndex + 1, sectionCookie.length);
	
	createCookie('pmyrComplete',sectionCookie,7);
	
}


// Modifies the Style on the Input, used to show Mouse Movement on the TOC/Nav
//  highlightMouseOut( '1-1' ); or highlightMouseOut( '1' );
function highlightMouseOut( inSection ) {
    var eleSpan = document.getElementById( inSection );
    eleSpan.style.color = "#000000";
}
// Modifies the Style on the Input, used to show Mouse Movement on the TOC/Nav
//  highlightMouseOver( '1-1' ); or highlightMouseOver( '1' );
function highlightMouseOver( inSection ) {
    var eleSpan = document.getElementById( inSection );
    eleSpan.style.color = "#3d75a2";
}

// Used to Highlight a Section Title to show the user where in the TOC/NAV they are
function highlightSectionOn( inSection ) {
    var eleSpan = document.getElementById( inSection + 'background' );
    eleSpan.className = "highLightOn";
}
// Used to Highlight a Section Title to show the user where in the TOC/NAV they are
function highlightSectionOff( inSection ) {
    var eleSpan = document.getElementById( inSection + 'background' );
    // eleSpan.style.background = "black";
    eleSpan.className = "highLightOff";
}

// Load the mainFrame with the selected Content
//  openSection( '1-1' );
function openSection( inSection ) {
    var eleFrame = parent.document.getElementById( 'mainFrame' );
    eleFrame.src = 'content/' + inSection + '.htm?section=' + inSection;
}

// Highlights a Section
//  highlightSection( '1-1' );
function highlightSection( inSection ) {
    var sectionNumber = inSection.split("-")[0];

    // Scroll to Title of Section
    moveToTitle( sectionNumber );
    // moveToTitle( inSection );

    // Open the Section
    expandTitle( 'title' + sectionNumber );

    // Highlight the Section
    highlightedSection = inSection;
    highlightSectionOn( inSection );
}
// Remove Old Highlight
function clearHighlightSection() {
    if ( highlightedSection != null )
        highlightSectionOff( highlightedSection );
}


// Cookie Scripts
/*
	example:

		Create Cookie:
		
		createCookie('ppkcookie','testcookie',7);
		
		Read Cookie:
		var x = readCookie('ppkcookie1')
		if (x) {
			[do something with x]
		}
		
		Delete Cookie:
		eraseCookie('ppkcookie')

*/
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


// Cross Browser Functions to find Client Width/Height and Scroll Position
function f_clientWidth() {
    return f_filterResults (
        window.innerWidth ? window.innerWidth : 0,
        document.documentElement ? document.documentElement.clientWidth : 0,
        document.body ? document.body.clientWidth : 0
    );
}
function f_clientHeight() {
    return f_filterResults (
        window.innerHeight ? window.innerHeight : 0,
        document.documentElement ? document.documentElement.clientHeight : 0,
        document.body ? document.body.clientHeight : 0
    );
}
function f_scrollLeft() {
    return f_filterResults (
        window.pageXOffset ? window.pageXOffset : 0,
        document.documentElement ? document.documentElement.scrollLeft : 0,
        document.body ? document.body.scrollLeft : 0
    );
}
function f_scrollTop() {
    return f_filterResults (
        window.pageYOffset ? window.pageYOffset : 0,
        document.documentElement ? document.documentElement.scrollTop : 0,
        document.body ? document.body.scrollTop : 0
    );
}
function f_filterResults(n_win, n_docel, n_body) {
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}








function loadChecks() {

	// Update the Completed Section Graphics if there is a Cookie!
	var sectionCookie = readCookie('pmyrComplete');

	if ( sectionCookie != null ) {
		// Loop through sectionArray set the Indicator
		for (var secInd = 0; secInd < sectionArray.length; secInd ++) {
			var blah = sectionCookie.charAt( secInd );
			if ( sectionCookie.charAt( secInd ) == '1' )
				setSectionIndicator( sectionArray[secInd] );
			}
	}
	
}

