function tab_setup () {
if (document.getElementsByTagName) {
	if (document.URL.match(/articles/)) {
		var theURL = 'aindex';
	} else {
		document.URL.match(/^.+(\\|\/)(.+)\.html.*$/);
		var theURL = RegExp.$2;
	}

	if ((theURL == 'index')) {
		var logoArea = document.getElementById ('logo_link');
		logoArea.setAttribute("href","#");
	}

	var thelist = document.getElementById ('tab_container');
	var links = thelist.getElementsByTagName ("li");
	
	for (var i = 0; i < links.length; i++) {
		RegExp.$3 = '.html"';
		links[i].innerHTML.match (/^(<.+=\")(.+)(\.html\"|\/\")(.*>.+<\/.+)$/);
		
		//alert(i+': '+links[i].innerHTML+'\n'+RegExp.$1+'  '+RegExp.$2+'  '+RegExp.$3+'  '+RegExp.$4+'\n'+theURL);
				
		if (RegExp.$2 == theURL) {
			links[i].innerHTML = RegExp.$1+'#" class="current" ^'+RegExp.$4;
		}
	}
}
}

function footer_setup () {
if (document.getElementsByTagName) {
	document.getElementById('copy_date').innerHTML = new Date().getFullYear();
}
}

function email (first, last, mailto) {
	var last = (last == false) ? "com" : last;
    var first = (first == false) ? "chris" : first;
	var mailto = (mailto == false) ? "" : "mailto:";
	var domain = 'hmu';
	return mailto+first+'@'+domain+'.'+last;
}

var newwindow;
function popup(url, title)
{
	newwindow=window.open('', 'Screenshot','height=400,width=500,resizable=yes,scrollbars=yes,toolbar=no,status=no');
	if (window.focus) {
		newwindow.focus();
	}
	newwindow.document.write('<html><head><title>');
	newwindow.document.write(title);
	newwindow.document.write('</title>');
	newwindow.document.write('<style type="text/css" media="screen">body{color:white;background-color:black;text-align:center}"</style>');
	newwindow.document.write('</head><body><p><img src="');
	newwindow.document.write(url);
	newwindow.document.write('"></p><h3>');
	newwindow.document.write(title);
	newwindow.document.write('</h3><p style="text-align: right"><a href="javascript:self.close()">Close Window</a></p>');
	newwindow.document.write('</body></html>');
	newwindow.document.close();
}

function checkForm() {
	var gname, gemail, gcode, gmessage;
	with (window.document.contactFrm) {
		gname    = name;
		gemail   = email;
		gcode     = code;
		gmessage = comments;
	}
	
	if (trim(gname.value) == '') {
		alert('Please enter your name');
		gname.focus();
		return false;
	}
	else if (trim(gemail.value) == '') {
		alert('Please enter an email address or phone number');
		gemail.focus();
		return false;
	}
	else if (isntEmail(trim(gemail.value))) {
		alert('Please enter a valid email address');
		gemail.focus();
		return false;
	}
	else if (trim(gcode.value) == '') {
		alert('Please enter the security code');
		gcode.focus();
		return false;
	}
	else if (trim(gcode.value) != '137') {
		alert('Please enter the correct security code');
		gcode.focus();
		return false;
	}
	else {
		return true;
	}
}

function checkForm2() {
	var gname, gemail, gcode, gmessage;
	with (window.document.contactFrm2) {
		gname    = name;
		gemail   = email;
		gcode     = code;
		gmessage = comments;
	}
	
	if (trim(gname.value) == '') {
		alert('Please enter your name');
		gname.focus();
		return false;
	}
	else if (trim(gemail.value) == '') {
		alert('Please enter an email address or phone number');
		gemail.focus();
		return false;
	}
	else if (isntEmail(trim(gemail.value)) & isntPhone(trim(gemail.value))) {
		alert('Please enter a valid email address or phone number');
		gemail.focus();
		return false;
	}
	else if (trim(gcode.value) == '') {
		alert('Please enter the security code');
		gcode.focus();
		return false;
	}
	else if (trim(gcode.value) != '137') {
		alert('Please enter the correct security code');
		gcode.focus();
		return false;
	}
	else {
		return true;
	}
}

function checkForm3() {
	var gname, gemail, gurl, gcode, gmessage;
	with (window.document.bookFrm) {
		gname    = name;
		gemail   = email;
		gurl     = url;
		gcode    = code;
		gmessage = comments;
	}
	
	if (trim(gname.value) == '') {
		alert('Please enter your name');
		gname.focus();
		return false;
	}
	else if (trim(gemail.value) == '') {
		alert('Please enter an email address or phone number');
		gemail.focus();
		return false;
	}
	else if (isntEmail(trim(gemail.value)) & isntPhone(trim(gemail.value))) {
		alert('Please enter a valid email address or phone number');
		gemail.focus();
		return false;
	}
	else if (isntURL (trim(gurl.value))) {
		alert('Please enter a valid website URL');
		gurl.focus();
		return false;
	}
	else if (trim(gcode.value) == '') {
		alert('Please enter the security code');
		gcode.focus();
		return false;
	}
	else if (trim(gcode.value) != '249') {
		alert('Please enter the correct security code');
		gcode.focus();
		return false;
	}
	else {
		return true;
	}
}

function checkMultiForm(whichType) {
	var gname, gemail, gcode, gmessage;
	
	if (whichType == 'book') {
		with (window.document.bookFrm) {
			gname = name;
			gemail = email;
			gurl = url;
		}
	} else if (whichType == 'mail') {
		with (window.document.mailFrm) {
			gname = name;
			gemail = email;
			gmessage = message;
			gcode = code;
		}
	} else {
		with (window.document.leadFrm) {
			gname = name;
			gemail = email;
		}
	}
	
	if (trim(gname.value) == '') {
		alert("Please enter your name in the form...\nI need to know who I'm sending this pack to.\nThanks.");
		gname.focus();
		return false;
	}
	if (trim(gemail.value) == '') {
		alert("Please enter an email address in the form...\nI need an email address to send the pack to.\nThanks.");
		gemail.focus();
		return false;
	}
	if (isntEmail(trim(gemail.value))) {
		alert("Please enter a valid email address...\nI can't send you the pack without a proper email address.\nThanks.");
		gemail.focus();
		return false;
	}

	if (whichType == 'book') {
		if (trim(gurl.value) == 'http://') {
			alert('Please enter a website URL in the form');
			gurl.focus();
			return false;
		}
		if  (isntURL (trim(gurl.value))) {
			alert('Please enter a valid website URL');
			gurl.focus();
			return false;
		}
	} else if (whichType == 'mail') {
		if (trim(gmessage.value) == '') {
			alert('Please enter a message in the form');
			gmessage.focus();
			return false;
		}
		if (trim(gmessage.code) == '') {
			alert('Please enter the spam code in the form');
			gcode.focus();
			return false;
		}
	} else {
		return true;
	}
}

/*
Strip whitespace from the beginning and end of a string
Input  : a string
Output : the trimmed string
*/
function trim(str) {
	return str.replace(/^\s+|\s+$/g,'');
}

/*
Check if a string is in valid email format. 
Input  : the string to check
Output : true if the string is a valid email address, false otherwise.
*/
function isntEmail(str) {
	var regex = /^[-_.a-z0-9]+@(([-a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
	return !regex.test(str);
}

function isntPhone(str) {
	var regex = /^[-\s\(\)0-9]{7,}$/i;
	return !regex.test(str);
}

function isntURL(str) {
	var regex = /^http:\/\/[-_a-z0-9]+\.(([-_a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
	return !regex.test(str);
}

function set_cookie( name, value, expires, path, domain, secure ) {
// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}

	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}


function get_cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ ) {
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name ) {
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 ) {
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) {
		return null;
	}
}

function check_browser () {
	if (get_cookie ("ep") && get_cookie ("ep") != '/') {
		window.location =  get_cookie ('ep');
	} else {
		set_cookie ('ep', '/', 1, '/', '', '');
	}
}

function check_page () {
	if (get_cookie ("ep") == null) {
		set_cookie ('ep', 'free.html', 1, '/', '', '');
	}
}