// Behvavior: Excelsior Marketing

window.onload = function() {
	if (window.attachEvent) window.attachEvent("onload", sfHover);
	contactSend();
	printMuse();
	if (window.attachEvent) window.attachEvent("onload", shareHover);	
}


/* -- checks to see if variables in each function exist -- */

function checkVars(e) {
	var x = e.split(",");
	var pass = true;
	checkerInvalid = new Array;

	for(i=0; i<x.length; i++) {
		
		if(!eval(x[i])) {
		pass = false; 
		checkerInvalid[checkerInvalid.length] = x[i];
		}
		
	}
	
	return pass;

}


/* -- makes the dropdown to work in ie6 -- */

sfHover = function() {
	
	//if(!checkVars('document.getElementById("nav").getElementsByTagName("LI")')) {return;}
	
	if(!document.getElementById("nav").getElementsByTagName("LI")) {
		return;
	}
	
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}


/* --  contact form validation  -- */

function valContactForm() {
	
	//if(!checkVars('document.contact_form')) {return;}

	if(!document.contact_form) {
		return;
	}
	
	var email_regex = /^([\w]+)(.[\w]+)*@([\w]+)(.[\w]{2,3}){1,2}$/;
	
	var name_value = document.contact_form.name.value;
	var email_value = document.contact_form.email.value;
	var message_value = document.contact_form.message.value;
	var errormsg = '';


	if (name_value == '') {
		errormsg = errormsg + '-You must enter your Name\n';
	}
	
	if (email_value == '' || email_regex.test(email_value) != true) {
		errormsg = errormsg + '-You must enter a valid Email Address\n';
	}
	
	if (message_value == '') {
		errormsg = errormsg + '-You must enter a Message\n';
	}
	
	if (errormsg != '') {
		alert('The following errors were found:\n'+errormsg);
		return false;
	}
	
	else { 
		return true; 
	}

}

function contactSend() {
	
	//if(!checkVars('document.contact_form')) {return;}

	if(!document.contact_form) {
		return;
	}
	
	var contact_form = document.getElementById("contact_form");
	
	contact_form.onsubmit = function() {
		return valContactForm();
	}
}

function printMuse() {

	if(!document.getElementById("print_muse")) {
		return;
	}

	var print_muse = document.getElementById("print_muse");
	
	print_muse.onclick = function() {
		//alert("hello");	
		window.print();
	}
}


/* -- makes the share link work in ie6 -- */

shareHover = function() {
	
	//if(!checkVars('document.getElementById("nav").getElementsByTagName("LI")')) {return;}
	
	if(!document.getElementById("museshare").getElementsByTagName("LI")) {
		return;
	}
	
	var sfEls = document.getElementById("museshare").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sharehover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sharehover\\b"), "");
		}
	}
}