/* THIS FILE CONTAINS ROLLOVER CODE, NORVAX INTERFACE CODE and MENUING CODE  */

/* MENUS */
function switchMenu(obj) {
var el = document.getElementById(obj);
if ( el.style.display != 'none' ) {
el.style.display = 'none';
}
else {
el.style.display = '';
}
}

function $() {
var elements = new Array();
for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
if (typeof element == 'string')
element = document.getElementById(element);
if (arguments.length == 1)
return element;
elements.push(element);
}
return elements;
}

function collapseAll(objs) {
var i;
for (i=0;i<objs.length;i++ ) {
objs[i].style.display = 'none';
}
}

function menuCloseAll7() {
collapseAll($('menu1','menu2','menu3','menu4','menu5','menu6','menu7'));
}

function menuCloseAll6() {
collapseAll($('menu1','menu2','menu3','menu4','menu5','menu6'));
}

function menuCloseAll5() {
collapseAll($('menu1','menu2','menu3','menu4','menu5'));
}

function menuCloseAll4() {
collapseAll($('menu1','menu2','menu3','menu4'));
}

function menuCloseAll3() {
collapseAll($('menu1','menu2','menu3'));
}

function menuCloseAll2() {
collapseAll($('menu1','menu2'));
}


function menuCloseAllButTop() {
collapseAll($('menu2','menu3','menu4','menu5','menu6','menu7'));
}

function menuCloseAllButCurrent() {
	//alert("in menuCloseAllButTop");
	// Close all sub menus
	// done below -- collapseAll($('menu1','menu2','menu3','menu4','menu5','menu6','menu7'));

	// Now, re-open any active sub menu
	lnActivemenu = 0;    // Flag: If there's any active menu, this will be 1.
	var menudivnames = new Array('menu1','menu2','menu3','menu4','menu5','menu6','menu7');
	for (i=0;i<menudivnames.length;i++ ) {
		var mylist=document.getElementById(menudivnames[i])
		if (mylist != null) {
			var listitems= mylist.getElementsByTagName("a")
			var el = document.getElementById(menudivnames[i]);   // The actual DIV menu object
			// First, close this menu, if it exists (determined by whether or not it has choices within - <a tags)
			if(listitems.length > 0) {
				el.style.display = 'none';
			}
			// Now, evaluate the menu as having a current selection - if so, reopen it
			for (ii=0; ii<listitems.length; ii++) {
				//alert(listitems[ii].innerHTML);
				//alert(listitems[ii].className);
				// This menu contains an active selection, so open it up
				if(listitems[ii].className.indexOf("current") > -1) {
					lnActivemenu = 1;    // Flag: If there's any active menu, this will be 1.
					el.style.display = '';
					break;
				}
			}
		}
	}
	// If no menus are current, close all but open top
	if (lnActivemenu == 0) {
		//alert("open top");
		var el = document.getElementById('menu1');
		el.style.display = '';
	}
}



/* 
	NORVAX SUBMISSIONS
*/
function submitNorvaxForm() {
	if (this.insurancetype) {
		this.action = "/quote.php/?zip=" + this.zip.value + "&insurancetype=" + this.insurancetype.value + "&";
	} else {
		this.action = "/quote.php/?zip=" + this.zip.value + "&";
	}
}

function onloadNorvax() {
//	var productElement = document.getElementById("zipform");
//	if (productElement != null) {
		document.zipform.onsubmit = submitNorvaxForm;
//	}
}


/*
	ROLLOVER CODE
	Standards Compliant Rollover Script
	Author : Daniel Nolan
	http://www.bleedingego.co.uk/webdev.php
*/

function initRollovers() {
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_over'+ftype);
                                                var csrc = src.replace(ftype, '_down'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
                                                aImages[i].setAttribute('csrc', csrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
                                                aPreLoad[i].src = csrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			aImages[i].onclick = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('csrc'));
			}	


			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_over'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}

	// Close all menus but currently chosen menu; but only if menu (DIVS) exist
	var el = document.getElementById('menu1');
	if (el != null) {
		menuCloseAllButCurrent();
	}

	// Check for ZIP code entry and set up appropriate post; but only if the zipform FORM exists
	if (document.zipform) {
		onloadNorvax();
	}
//	var el = document.getElementById('zipform');
//	if (el != null) {
//		onloadNorvax();
//	}
}





window.onload=function(){
 initRollovers();
 initTip();

}


