

var site_root = 'http://gcp.nihtraining.com/';
var cursor_type = (document.all) ? 'hand' : 'pointer';
var content_div;
var banner_div;
var body_tag;

//	Browser detection
var w3c = (document.getElementById) ? true : false;
var ie = (document.all && !w3c) ? true : false;
var ns4 = (document.layers) ? true : false;

var info_blocks = false;

function init () {
	content_div = document.getElementById('content');
	banner_div = document.getElementById('banner');
	body_tag = document.getElementsByTagName('BODY')[0];
	
	if (info_blocks) {
		initHideShow();
	}

	
		
	var font_size = getFontCookie();
	if (font_size != null) {
		body_tag.className = body_tag.className + ' ' + font_size;
	}
	
	if (document.getElementById('mother') && !document.getElementById('mainMenuPage')) {
		createFontResizer();
	} else {
		showContentDiv();
	}
}

if (w3c) { 	
	document.write('<style type="text/css">#content { visibility: hidden; }</style>');
	window.onload=init;
	}
	
	
function showContentDiv() {
	if (content_div) {
		content_div.style.visibility = 'visible';
	}	
}





function createFontResizer() {
	//var footer_div = document.getElementById('mother');
	var mother_div_childs = document.getElementById('mother').childNodes;
	var footer_div = false;
	var footer_first_element;
	var size_imgs = new Array (3);
	var font_is_set;
	
	var found_nextprev = false;
	for (var pp=0; pp<mother_div_childs.length; pp++) {
		if(mother_div_childs[pp].className == 'nextPrevious' && found_nextprev == false) {
			found_nextprev = true;
			footer_div = mother_div_childs[pp];
			footer_first_element = footer_div.firstChild;
		}
	}
		
	if (footer_div) {
		//alert('Yeah mon!');
		fontResizer_div = document.createElement('DIV');
		fontResizer_div.id = 'fontResizer';
		
		fontsize_img = document.createElement('IMG');
		fontsize_img.src = site_root + 'images/font_size.gif';
		
		fontResizer_div.appendChild(fontsize_img);
		
		for (var aa=0; aa<size_imgs.length; aa++) {
			size_imgs[aa] = document.createElement('IMG');
			size_imgs[aa].assoc_num = aa+1;
			if (getFontCookie() == ('larger'+size_imgs[aa].assoc_num) || (getFontCookie() == null && size_imgs[aa].assoc_num == 2)) {
				size_imgs[aa].src = site_root + 'images/font_size_' + size_imgs[aa].assoc_num + '_sel.gif';
			} else {
				size_imgs[aa].src = site_root + 'images/font_size_' + size_imgs[aa].assoc_num + '.gif';
			}
			size_imgs[aa].assoc_classname = 'larger' + size_imgs[aa].assoc_num;
			size_imgs[aa].onclick = function () {
				curr_body_class = body_tag.className;
				//alert('curr_body_class = '+curr_body_class);
				font_is_set = false;
				for (var hh=1; hh<=3; hh++) {
					check_class = 'larger'+hh;
					if (curr_body_class.indexOf(check_class) != -1) {
						font_is_set = true;
						curr_body_class = curr_body_class.split(check_class);
						//alert('curr_body_class[0] = '+curr_body_class[0]);
						body_tag.className = curr_body_class[0] + this.assoc_classname;
						//alert(body_tag.className);
						break;
						
					}	
				}
								
				if (!font_is_set) {
					body_tag.className = this.assoc_classname;
				}
								
				setFontCookie(this.assoc_classname);
				for (var bb=0; bb<size_imgs.length; bb++) {
					size_imgs[bb].src = site_root + 'images/font_size_' + (bb+1) + '.gif';
				}
				this.src = site_root + 'images/font_size_' + this.assoc_num + '_sel.gif';
			}
			size_imgs[aa].onmouseover = function () {
				this.style.cursor = cursor_type;
			}
			fontResizer_div.appendChild(size_imgs[aa]);
		}
		//footer_div.appendChild(fontResizer_div);
		footer_div.insertBefore(fontResizer_div,footer_first_element);
	}
	showContentDiv();
}

function setFontCookie(class_name) {
	
	//format expiry date
	font_date = new Date();
	font_date.setTime(font_date.getTime() + ( 365 *24*60*60*1000));

	//if (class_name == 'larger1') {
	//	font_date.setTime(0); //	Deletes the cookie
	//}
	document.cookie = 'fontSize=' + class_name
		+ '; expires=' + font_date.toGMTString() 
		+ '; path=/';
}


function getFontCookie() {
	font_cookie = null;	
	
	if (document.cookie && document.cookie.indexOf('fontSize')!=-1) {
		font_cookie = document.cookie.split('fontSize=');
		font_cookie = font_cookie[1].split(';');
		return font_cookie[0];
	}
	//alert(font_cookie);
	
}

function popCourse(the_page) {
	var the_win = window.open(the_page,'MainCourseWindow','scrollbars=yes,left=0,top=0,screenX=0,screenY=0,menubar=yes,status=yes,resizable=yes,height=550,width=785');
	the_win.focus();
}


//	Popup window code
var page_position = (parseInt(navigator.appVersion) > 3) ? 'left=0,top=0,screenX=0,screenY=0,' : "";
var popup_features = 'menubar=yes,status=yes,toolbar=yes,scrollbars=yes,resizable=yes,width=660,height=430';

function popupWindow(url, target, features) {
	if (isUndefined(features)) {
		features = page_position + popup_features;
	}
	if (isUndefined(target)) {
		target = '_blank';
	}
	if (target == 'Glossary') {
		features = page_position + 'menubar=yes,status=yes,scrollbars=yes,resizable=yes,height=300,width=600';
	}
	var the_window = window.open(url, target, page_position+features);
	the_window.focus();
	return the_window;
}

function linkPopup(src, features) {
	return popupWindow(src.getAttribute('href'),src.getAttribute('target') || '_blank',features);
}//	End Popup window code

//	Utility function [currently used in popupWindow()]
function isUndefined(v) { 
	//	Returns true if [v] is not defined, false otherwise
	//	IE 5.0 does not support the undefined keyword, so we cannot 
	//	do a direct comparison such as v===undefined.
	var undef;
	return v===undef;
}


//	ACCORDIAN CODE:
//	Populate info_block array on page with id names of block elements to be toggled
//	Call initHideShow() <body onload="initHideShow()">



var info_block = new Array();
function initHideShow() {
	if(ie && document.all[info_blocks[0]]) {
		for(i=0; i<info_blocks.length; i++) {		
			document.all[info_blocks[i]].style.display = 'none';
			alert('set all to invisible');
		}		
		document.all['content'].style.visibility = 'visible';	
	} else if(w3c && document.getElementById(info_blocks[0])) {
		for(i=0; i<info_blocks.length; i++) {
			document.getElementById(info_blocks[i]).style.display = 'none';
		}		
		document.getElementById('content').style.visibility = 'visible';
	} else {
		return;
	}
}
function hideShowBlock(block_name) {
	if (ie) {
		if (document.all[block_name].style.display == 'none') {
			document.all[block_name].style.display = '';
		} else {
			document.all[block_name].style.display = 'none';
		}
	} else if (w3c) {
		if (document.getElementById(block_name).style.display == 'none') {
			document.getElementById(block_name).style.display = 'block';
		} else {
			document.getElementById(block_name).style.display = 'none';
		}
	} else {
		return;
	}
}
//	Use this code for an accordian list that shows the item clicked on and hides the others
var previously_selected = '';
function revealOneHideOthers(block_name,the_link) {
	if (w3c) {
		for(i=0; i<info_block.length; i++) {
			document.getElementById(info_block[i]).style.display = 'none';
		}
		document.getElementById(block_name).style.display = 'block';
		//	This is how changing the class attribute SHOULD be done
		//	the_link.parentNode.setAttribute('class','selected');
		//	if (previously_selected != '') previously_selected.removeAttribute('class');
		//	previously_selected = the_link.parentNode;
		
		//	This is a hack so that it works in IE!!!!!!
		the_link.parentNode.className = 'selected';
		if (previously_selected != '' && the_link.parentNode != previously_selected) previously_selected.className = 'poo';
		previously_selected = the_link.parentNode;

	} else {
		return;
	}
}


function validate_form() {
    valid = true;

    if ( document.login.first.value == "" )
    {
        alert ( "Please enter your First Name." );
        valid = false;
    }

    if ( document.login.last.value == "" )
    {
        alert ( "Please enter your Last Name." );
        valid = false;
    }

    //if ( document.login.node.value == "" )
    //{
    //    alert ( "Please enter your Node #." );
    //    valid = false;
    //}

    //if ( document.login.staff.value == "" )
    //{
    //    alert ( "Please enter your Staff #." );
    //    valid = false;
    //}

    if ( document.login.email.value == "" )
    {
        alert ( "Please enter your E-Mail Address." );
        valid = false;
    }

    if ( document.login.pass.value == "" )
    {
        alert ( "Please enter a Password." );
        valid = false;
    }

    if ( document.login.pass.value != document.login.pass2.value )
    {
        alert ( "Your Passwords must match!" );
        valid = false;
    }
	
/*	if (valid == false) {
		alert(err_msg);
	}*/
		

    return valid;
}

