// BEGIN MMI Drop Down Menu
function mmi_dd_menu() {
	var dd_ul_id = "nav_ul";
	if (!(document.getElementById(dd_ul_id))) return false;
	var uls = document.getElementById(dd_ul_id).getElementsByTagName("ul");
	for (i=0; i < uls.length; i++) {
		ul_class = "";
		uls[i].parentNode.onmouseover = function() { 
			ul_class = this.getElementsByTagName("ul")[0].className;
			this.getElementsByTagName("ul")[0].className = "on";
		}
		uls[i].parentNode.onmouseout = function() { this.getElementsByTagName("ul")[0].className = ul_class; }
		lis = uls[i].getElementsByTagName("li");
		for (j=0; j < lis.length; j++) { 
			a_class = "";
			lis[j].onmouseover = function() {
				a_class = this.parentNode.parentNode.getElementsByTagName("a")[0].className;
				this.parentNode.parentNode.getElementsByTagName("a")[0].className = "on";
			}
			lis[j].onmouseout = function() { this.parentNode.parentNode.getElementsByTagName("a")[0].className = a_class; }
		}
	}
}

if (window.addEventListener) window.addEventListener("load", mmi_dd_menu, false);
else if (window.attachEvent) window.attachEvent("onload", mmi_dd_menu);
// END MMI Drop Down Menu

// BEGIN MMI Lookout Bar
function mmi_lo_bar(){
	var lo_ul_id = "lookout_bar";
	if (!(document.getElementById(lo_ul_id))) return false;
	var lo_uls = document.getElementById(lo_ul_id).getElementsByTagName("ul");
	for (i=0; i < lo_uls.length; i++) {
		lo_uls[i].parentNode.onclick = function() { 
			collapse_all(lo_uls);
			this.getElementsByTagName("a")[0].className = "on";
			this.getElementsByTagName("ul")[0].style.display = "block";
			return false;
		}
	}
}

function collapse_all(lo_uls) {
	for (i=0; i < lo_uls.length; i++) {
		lo_uls[i].parentNode.getElementsByTagName("a")[0].className = "";
		lo_uls[i].style.display = "none";
	}
}

if (window.addEventListener) window.addEventListener("load", mmi_lo_bar, false);
else if (window.attachEvent) window.attachEvent("onload", mmi_lo_bar); // IE fun :(
// END MMI  Lookout Bar


// BEGIN MMI Rollover (images and text)
// preload 1.png - 6.png
for (i = 1; i <= 6; i++) {
	var liner = ["preload_img" + i];
	liner  = new Image();
	liner.src = '/images/site/' + i + '.png';
}

function mmi_ro(){
	var ro_div_id = "orange_nav";
	var ro_div2_id = "hp_content";
	var ro_div3_id = "content";
	var ro_divg_id = "graphic";
	var div_start = 1;	
	var image_suf = ".png";
	var image_start = 1;
	var bg_start = "transparent url(/images/site/";
	var bg_end = ") no-repeat scroll right bottom";
	var bg_orig = bg_start + image_start + image_suf + bg_end;
	if (!(document.getElementById(ro_div_id))) return false;
	var ro_lis = document.getElementById(ro_div_id).getElementsByTagName("li");
	for (i=0; i < ro_lis.length; i++) {
		num = (div_start + 1 + i);
		ro_lis[i].linum = ro_div3_id + num;
		img = (image_start + i + 1) + image_suf;
		ro_lis[i].linum2 = bg_start + img + bg_end;
		ro_lis[i].onmouseover = function() {
			document.getElementById(ro_div2_id).innerHTML = document.getElementById(this.linum).innerHTML;
			document.getElementById(ro_divg_id).style.background = this.linum2;
			if(i == 1) {
				document.getElementById("new_face").className = 'new_face_alt'
			} else {
				document.getElementById("new_face").className = 'new_face'
			}
		}
		ro_lis[i].onmouseout = function() {
			document.getElementById(ro_div2_id).innerHTML = document.getElementById(ro_div3_id+''+div_start).innerHTML;
			document.getElementById(ro_divg_id).style.background = bg_orig;
			if(i == 1) {
				document.getElementById("new_face").className = 'new_face'
			}
		}
	}
}

if (window.addEventListener) window.addEventListener("load", mmi_ro, false);
else if (window.attachEvent) window.attachEvent("onload", mmi_ro); // IE fun :(
// END MMI Rollover

/*
// BEGIN MMI Rollover (text only)
function mmi_ro(){
	var ro_div_id = "orange_nav";
	var ro_div2_id = "hp_content";
	var ro_div3_id = "content";
	var div_start = 1;
	if (!(document.getElementById(ro_div_id))) return false;
	if (!(document.getElementById(ro_div2_id))) return false;
	var ro_lis = document.getElementById(ro_div_id).getElementsByTagName("li");
	for (i=0; i < ro_lis.length; i++) {
		num = (div_start + 1 + i);
		ro_lis[i].linum = ro_div3_id + num;
		ro_lis[i].onmouseover = function() { document.getElementById(ro_div2_id).innerHTML = document.getElementById(this.linum).innerHTML; }
		
		// modified by Rusty Cage - removed on mouseout function; user must be able to interact with the rollover content
		//ro_lis[i].onmouseout = function() { document.getElementById(ro_div2_id).innerHTML = document.getElementById(ro_div3_id+''+div_start).innerHTML; }
	}
}

if (window.addEventListener) window.addEventListener("load", mmi_ro, false);
else if (window.attachEvent) window.attachEvent("onload", mmi_ro); // IE fun :(
// END MMI Rollover
*/

/*
// BEGIN MMI Rollover (images only)
function mmi_ro(){
	var ro_div_id = "orange_nav";
	var ro_div2_id = "graphic";
	var image_pre = "bg_home_image";
	var image_suf = ".gif";
	var image_start = 1;
	var bg_start = "transparent url(/images/site/";
	var bg_end = ") no-repeat scroll right bottom";
	var bg_orig = bg_start + image_pre + image_start + image_suf + bg_end;
	if (!(document.getElementById(ro_div_id))) return false;
	var ro_lis = document.getElementById(ro_div_id).getElementsByTagName("li");
	for (i=0; i < ro_lis.length; i++) {
		img = image_pre + (image_start + i + 1) + image_suf;
		ro_lis[i].linum = bg_start + img + bg_end;
		ro_lis[i].onmouseover = function() { document.getElementById(ro_div2_id).style.background = this.linum;	}
		ro_lis[i].onmouseout = function() { document.getElementById(ro_div2_id).style.background = bg_orig; }
	}
}

if (window.addEventListener) window.addEventListener("load", mmi_ro, false);
else if (window.attachEvent) window.attachEvent("onload", mmi_ro); // IE fun :(
// END MMI Rollover
*/

// CLEAR INPUT TEXT BOXES ON FORMS
function clearOnFocus(id, content) {
	elem = document.getElementById(id);
	if (elem.value == content) {
		elem.value = "";
	}
}

// show diagnostic form
function showForm() {
	var divDown = document.getElementById("diagnosticForm");
	if ( divDown.style.display == 'none' ) {
		divDown.style.display = 'block';
	}
}

// function to trim white space and carriage returns form field input values
function trim(s) {
	// Remove leading spaces and carriage returns
	while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r')){
                 s = s.substring(1,s.length);
         }
	return s;
}


// validate comments form
function validateCommentForm() {
var val;
var txt;
var emailReg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var frm = document.forms['comment_form'];	
   val = frm.name.value;
   txt = "Name is required";
   if (trim(val) == "") {
		alert(txt);
		frm.name.focus();
		return false;

	}
	val = frm.email.value;
	txt = "A valid Email is required";
	if(!emailReg.test(val)) {
		alert(txt);
		frm.email.focus();
		return false;
	}
	val = frm.comment.value;
   txt = "Comment is required";
   if (trim(val) == "") {
		alert(txt);
		frm.name.focus();
		return false;

	}
	//return true;
	return true;
} 


function imgHover(currentImg, replaceImg) {
	document.getElementById(currentImg).src = replaceImg;
}
