var oldDisp = null;	  								 // Display popup information
function setDisp( nId ){
	if ( oldDisp && oldDisp.style ) {
		oldDisp.style.display = '';
		oldDisp=null;
	}
	if ( nId ) {
		nId.onmouseout = clearDisp;
		oldDisp = nId.firstChild;
		while ( oldDisp.nodeType == '3' )	oldDisp = oldDisp.nextSibling;	// skip text nodes
		oldDisp = oldDisp.nextSibling;				// second item is controlled
		while ( oldDisp.nodeType == '3' )	oldDisp = oldDisp.nextSibling;	// skip text nodes
		oldDisp.style.display = 'block';
	}
}
function clearDisp(){
	if ( oldDisp && oldDisp.style ) {
		oldDisp.style.display = '';
		oldDisp=null;
	}
}

function toggleDisp( ctl ){
	if (!document.all && !document.getElementById ) return;
	if ( typeof ctl == "string" ) {
		ctl = document.all ? document.all[ctl] : document.getElementById(ctl);
	}
	if (ctl.style.display == 'none'){
		ctl.style.display = '';
	}else{
		ctl.style.display = 'none';
	}
} 


var toggleMenuList = "content";
function toggleMenu( ctl, state ){
	if ( !document.all && !document.getElementById ) return;	   // Browser too Dumb
	if ( typeof ctl == "string" ) 
		ctl = document.all ? document.all[ctl] : document.getElementById(ctl);
	if ( !state )
		state = ctl.firstChild.substringData(0,4);
	if ( typeof toggleMenuList == "string" ) 
		toggleMenuList = document.all ? document.all[toggleMenuList] : document.getElementById(toggleMenuList);
	if ( toggleMenuList )
		toggleMenuList.className = state+'Menu';

	state = (state == "Hide") ? "Show" : "Hide";	// next display
	ctl.firstChild.replaceData(0,4, state );
}


function blinkMe( ctl, cnt ) {
	if ( !document.all && !document.getElementById ) return;
	if ( typeof ctl == "string" ) {
		target = document.all ? document.all[ctl] : document.getElementById(ctl);
		count = cnt;
	}
	if (target.style.visibility == 'hidden'){
		target.style.visibility = '';
		if (count == 1 )		return;
		setTimeout("blinkMe()", 1000 );
		if ( count > 1 )		count--;
	}else{
		target.style.visibility = 'hidden';
		setTimeout("blinkMe()", 500 );
	}
} 


var marqueeCtl;
var marqueBaseColor="#fff";
var marqueHighColor="#000";

function marqueeSetUp( type ) {
	if (!document.all && !document.getElementById ) return;	   // Browser too Dumb
	marqueeCtl = document.all ? document.all['marquee'] : document.getElementById('marquee');
	var msg = marqueeCtl.innerHTML;
	var oldText = marqueeCtl.removeChild( marqueeCtl.firstChild );
	marqueeCtl.type = type;
	var ctl = document.createElement( "img" );
	ctl.src = "/images/marqueeStop.jpg";
	ctl.altSrc = "/images/marqueePlay.jpg";
	ctl.align="left";
	ctl.height = "20";
	ctl.style.margin = "0px 10px";
	ctl.title= "Stop/Play the animation"
	ctl.alt = "animation control";
	ctl.onclick = function(){var tmp=this.src; this.src=this.altSrc; this.altSrc=tmp;
			if (tmp.indexOf("Stop")>-1) this.target.stop(); else this.target.start();};
	marqueeCtl.appendChild( ctl );
	if ( type == 0 ) {
		var marq = document.createElement( "marquee" );
		marq.appendChild( oldText );
		marq.setAttribute("height", 15);
		marq.setAttribute("scrollamount", 2);
		ctl.target = marq;
		marqueeCtl.appendChild( marq );
		return;
	}

	ctl.target = marqueeCtl;
	marqueeCtl.stop=function(){clearTimeout(marqueeCtl.timeout);};
	marqueeCtl.start=neon;
	for ( var ix=0; ix<msg.length; ix++ ) {
		var span = document.createElement( "span" );
		span.appendChild( document.createTextNode( msg.charAt(ix)));
		marqueeCtl.appendChild( span );
	}
	neon();
}
var neonPos=0;
function neon(){
	if ( neonPos==0 ){	//Change all letters to base color
		for ( var ix=0; ix<marqueeCtl.childNodes.length; ix++) {
			marqueeCtl.childNodes[ ix ].style.color=marqueBaseColor;
		}
	}
//cycle through and change individual letters to neon color
	marqueeCtl.childNodes[ neonPos ].style.color = marqueHighColor;

	if ( neonPos < marqueeCtl.childNodes.length-1 ) {
		neonPos++;
		marqueeCtl.timeout = setTimeout("neon()",200);
	} else {
		neonPos=0;
		marqueeCtl.timeout = setTimeout("neon()",5000);
	}
}

function highlightAccessKeys() {
    if (!document.getElementsByTagName) return;    //don't do anything in old browsers
    var tagNames = new Array('A', 'BUTTON');
    for (var j = 0; j < tagNames.length; j++) {
        var elements = document.getElementsByTagName(tagNames[j]);
        for (var i = 0; i < elements.length; i++) {
            if (elements[i].accessKey) {
                highlightAccessKey(elements[i], elements[i].accessKey);
            }
        }
    }
}
// Highlights the specified character in the specified element
function highlightAccessKey(e, accessKey) {
    if (e.hasChildNodes()) {
        var childNode, txt;
        
        //find the first text node that contains the access character
        for (var i = 0; i < e.childNodes.length; i++) {
            txt = e.childNodes[i].nodeValue;
            if (e.childNodes[i].nodeType == 3 &&
                txt.toLowerCase().indexOf(accessKey.toLowerCase()) != -1) {
            
                childNode = e.childNodes[i];
                break;
            }
        }
        
        if (!childNode) {
            //access character was not found
            return;
        }

        var pos = txt.toLowerCase().indexOf(accessKey.toLowerCase());
        var span = document.createElement('SPAN');
        var spanText = document.createTextNode(txt.substr(pos, 1));
        span.className = 'accesskey';
        span.appendChild(spanText);

        //the text before the access key
        var text1 = document.createTextNode(txt.substr(0, pos));
        //the text after the access key
        var text2 = document.createTextNode(txt.substr(pos+1));
        
        if (text1.length > 0) e.insertBefore(text1, childNode);
        e.insertBefore(span, childNode);
        if (text2.length > 0) e.insertBefore(text2, childNode);

        e.removeChild(childNode);
    }
}

function fixContentHeight(){
	if ( !document.all && !document.getElementById ) return;	   // Browser too Dumb	
	var item = document.all ? document.all['mainMenu'] : document.getElementById('mainMenu');
	var hgt = item.offsetHeight;
	item = document.all ? document.all['content'] : document.getElementById('content');
	if ( hgt > item.offsetHeight ) {
		item.style.height = hgt+'px';
	}
}

////////////////////////////////////////////////////////////////////////////////
//   Web Page Comment Functions
////////////////////////////////////////////////////////////////////////////////
function genFeedbackForm( ctl ){	// Generate feedback form following this control
	if ( ctl.cForm ) {
		toggleDisp( ctl.cForm, ctl.cForm.uName );
		return false;
	}
	cForm = document.createElement( 'form' );
	cForm.id = "feedbackForm";	cForm.name = "feedbackForm";
	tStr = "<p>Many pages on our site have a comment button &amp; form like this one.\n";
	tStr+= "If you like or don't like this page or would add/change something about it just let us know.\n";
	tStr+= "Our Website will be updated based on your input!<br /><br />\n";
	tStr+= "<input type=\"text\" class=\"theurl\" readonly=\"readonly\" name=\"url\" title=\"target page name\" />\n";
	tStr+= "<label for=\"webCmtName\">Your Name: <small>(optional)</small>";
	tStr+= "<input type=\"text\" id=\"webCmtName\" name=\"uName\" /></label>\n";
	tStr+= "<label for=\"webCmtEmail\">Email Address: <small>(optional)</small>";
	tStr+= "<input type=\"text\" id=\"webCmtEmail\" name=\"uEmail\" /></label>\n";
	tStr+= "<label for=\"webCmtComment\">Your Comment / Correction:";
	tStr+= "<textarea id=\"webCmtComment\" name=\"comment\" cols=\"40\" rows=\"4\"></textarea></label>\n";
	tStr+= "<input type=\"submit\" value=\"Send my Comment\" name=\"submit\" onclick=\"submitFeedbackForm(this.form); return false;\" />\n";
	tStr+= "</p><p id=\"window_closer\">\n";
	tStr+= "<a href=\"#\" onclick=\"toggleDisp('feedbackForm'); return false;\">Close Window</a></p>\n";
	cForm.innerHTML = tStr;
	cForm.url.value = document.location.pathname;
	ctl.cForm = ctl.parentNode.appendChild( cForm );
	ctl.cForm.uName.focus();
	return false;
}

function submitFeedbackForm( frm ){
	if (frm.comment.value == ''){
		alert("Please be sure to fill in the Comment field.");
		return( false );
    }
	submit_form('/webCmt.php',
                '&url=' + frm.url.value +
                '&comment=' + frm.comment.value +
                '&uName=' + frm.uName.value +
                '&uEmail=' + frm.uEmail.value +
                '&resX=' + screen.width + '&resY=' + screen.height +
                '&agent=' + navigator.userAgent);

    frm.comment.value = '';
    frm.uName.value = '';
    frm.uEmail.value = '';
    toggleDisp(frm);
	return false;
} 

function submit_form(theUrl, theValues){
    if (window.XMLHttpRequest) {
        var xmlReq = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        var xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlReq.open("POST", theUrl, true);
    xmlReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
    xmlReq.send(theValues);
} 
