// Initialize DHTML Menu functions
var HM_DOM = (document.getElementById) ? true : false;
var HM_NS4 = (document.layers) ? true : false;
var HM_IE = (document.all) ? true : false;
var HM_IE4 = HM_IE && !HM_DOM;
var HM_Mac = (navigator.appVersion.indexOf("Mac") != -1);
var HM_IE4M = HM_IE4 && HM_Mac;

// Set default window status
window.defaultStatus = 'SleptOn Magazine: Don\'t Sleep On The Struggle. Be A Part Of It';

// Initialize global variables
var blnHomepage = false;

// Images cache
var SpacerCache = new Image();
SpacerCache.src = "/graphics/spacer.gif";
var Nav01Cache = new Image();
Nav01Cache.src = "/graphics/top_nav/aboutus-on.gif";
var Nav02Cache = new Image();
Nav02Cache.src = "/graphics/top_nav/contactus-on.gif";
var Nav03Cache = new Image();
Nav03Cache.src = "/graphics/top_nav/participate-on.gif";
var Nav04Cache = new Image();
Nav04Cache.src = "/graphics/top_nav/events-on.gif";
var Nav05Cache = new Image();
Nav05Cache.src = "/graphics/top_nav/links-on.gif";
var Nav06Cache = new Image();
Nav06Cache.src = "/graphics/top_nav/discuss-on.gif";
var Nav07Cache = new Image();
Nav07Cache.src = "/graphics/top_nav/archive-on.gif";

// Include JS Date function for IR site
function MakeArray(n) {
	this.length = n
	return this;
}

function customDateString(oneDate) {
	var theDay = dayNames[oneDate.getDay() + 1];
	var theMonth = monthNames[oneDate.getMonth() + 1];
	var theYear = oneDate.getFullYear();
	return theMonth.toUpperCase() + " " + oneDate.getDate() + ", " + theYear;
}

function copyrightDate(oneDate) {
	var theYear = oneDate.getFullYear();
	return theYear;
}

var monthNames = new MakeArray(12);
monthNames[1] = "January";
monthNames[2] = "February";
monthNames[3] = "March";
monthNames[4] = "April";
monthNames[5] = "May";
monthNames[6] = "June";
monthNames[7] = "July";
monthNames[8] = "August";
monthNames[9] = "September";
monthNames[10] = "October";
monthNames[11] = "November";
monthNames[12] = "December";

var dayNames = new MakeArray(7);
dayNames[1] = "Sunday";
dayNames[2] = "Monday";
dayNames[3] = "Tuesday";
dayNames[4] = "Wednesday";
dayNames[5] = "Thursday";
dayNames[6] = "Friday";
dayNames[7] = "Saturday";

// Begin Global JS Functions
function DropdownChooser(Product) {
	if (Product != "") {
		window.location = Product;
	}
}

function SpawnWin(wURL,wName,wW,wH) {
Spawned = window.open(wURL,wName,'width='+wW+',height='+wH+',resizable=1, scrollbars=yes, menubar=yes, toolbar=no');
// Refocus window
setTimeout("Spawned.focus()",500);
}

function EmailURL(wURL,wName,wW,wH) {
wURL = wURL + '?url=' + window.location.href + window.location.hash;
SpawnWin(wURL,wName,wW,wH);
}

function enableAll(imgName,imgLimit) {
	for (t=1; t<=imgLimit; t++) {
		ShowItem("HM_Menu" + t,"block");
	}
}

function imgHilite(imgID) {
	// Replaces the terminus of an image "_off.gif" with "_on.gif" only
	var thisSrc = eval(GetDIVStyleID(imgID)).src;
	var newSrc =  thisSrc.substring(0,thisSrc.lastIndexOf('-off.gif')) + "-on.gif";
	eval(GetDIVStyleID(imgID)).src = newSrc;
}

function imgUnHilite(imgID) {
	// Replaces the terminus of an image "_on.gif" with "_off.gif" only
	var thisSrc = eval(GetDIVStyleID(imgID)).src;
	var newSrc =  thisSrc.substring(0,thisSrc.lastIndexOf('-on.gif')) + "-off.gif";
	eval(GetDIVStyleID(imgID)).src = newSrc;
}

function ToggleMenuVisibility(myid){
	if (eval(GetDIVStyleID('div_Nav_' + myid)).style.display == "none") {
		imgHilite('img_NavExp_' + myid);
		ShowItem('div_Nav_' + myid,"block");
	}
	else {
		imgUnHilite('img_NavExp_' + myid);
		ShowItem('div_Nav_' + myid,"none");
	}
}

function TriggerFlash() {
var args = TriggerFlash.arguments;
	for (x = 0; x < args.length; x++) {
		var Root = eval("window." + args[x]);
		if (Root) {
			Root.Play();
		}
	}
}

function clrSearch(thisBox) {
	if (thisBox.value == "Search") {
		thisBox.value = "";
	}
}

function fillSearch(thisBox) {
	if (thisBox.value == "") {
		thisBox.value = "Search";
	}
}

function GetDIVStyleID(myid) {
	if ((HM_IE) || (HM_DOM)) {
		// Explorer
		if (HM_IE){
			var ThisDIV = document.all[myid];
		}
		// DOM Browsers
		else if (HM_DOM) {
			var ThisDIV = document.getElementById(myid);
		}
		return (ThisDIV);
	}
	else {
		return false;
	}
}

function ShowItem(myid,mydisplay) {
	if (mydisplay == "none") {
		eval(GetDIVStyleID(myid)).style.display = "none";
	}
	else if (mydisplay == "block") {
		eval(GetDIVStyleID(myid)).style.display = "block";
	}
}

function validateSearch(frm) {
	if ((frm.keys.value == "") || (frm.keys.value == "Search")) {
		return false;
	}
	else {
		return true;
	}
}

function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	if (obj.filters) {obj.filters.alpha.opacity=opacity;}
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
} 

function is_valid_email_address(email) {
	var qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
	var dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
	var atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'+'\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
	var quoted_pair = '\\x5c\\x00-\\x7f';
	var domain_literal = '\\x5b('+dtext+'|'+quoted_pair+')*\\x5d';
	var quoted_string = '\\x22('+qtext+'|'+quoted_pair+')*\\x22';
	var domain_ref = atom;
	var sub_domain = '('+domain_ref+'|'+domain_literal+')';
	var word = '('+atom+'|'+quoted_string+')';
	var domain = sub_domain+'(\\x2e'+sub_domain+')*';
	var local_part = word+'(\\x2e'+word+')*';
	var addr_spec = local_part+'\\x40'+domain;
	var filter = eval('/^' + addr_spec + '$/');
	
	return ((filter.test(email)) ? 1 : 0);
}

function toggleTextBoxVal(obj,ev,defVal) {
	if (obj) {
		if (ev == 'focus') {
			if (obj.value == defVal) {
				obj.value = '';
			}
		}
		else if (ev == 'blur') {
			if (obj.value == '') {
				obj.value = defVal;
			}
		}
	}
}