function handleError() {
	return true;
}
window.onerror = handleError;

domain = 'whirdev'

// This function shifts the backgrounds behind the site navigation.
function navShift(foo) {
	if (foo === '') { 
		if (document.getElementById('newsSection')) { navShift('3954'); }
		else if (document.getElementById('eventSection')) { navShift('3954'); }
		else if (document.getElementById('articleSection')) { navShift('3954'); }
		else if (document.getElementById('blogSection')) { navShift('3295'); }
		else if (document.getElementById('findSection')) { navShift('2636'); }
		else if (document.getElementById('articlecentralSection')) { navShift('2636'); }
		else if (document.getElementById('resellerSection')) { navShift('1977'); }
		else if (document.getElementById('magazineSection')) { navShift('1318'); }
		else if (document.getElementById('tvSection')) { navShift('659'); }
		else { navShift('0'); }
	} else {
		if(document.getElementById('serversecuritymonitoringSection')) { document.getElementById('nav3').style.background = 'url(http://static.thewhir.com/images/54f3_bg_nav3.gif) ' + foo + 'px 0'; }
		else { document.getElementById('nav3').style.background = 'url(http://static.thewhir.com/images/bg_nav3.gif) ' + foo + 'px 0'; }
	}
}

// These functions open and close the boxes at the top of the page
function toggleTop(foo) {
	closeMe();
	document.getElementById(foo).style.display = 'block';
}

function closeMe(foo) {
	var topBoxes;
	topBoxes = document.getElementsByTagName('div');
	for (i=0 ; i<topBoxes.length ; i++) {
		if (topBoxes[i].className === 'topBox') topBoxes[i].style.display = 'none';
	}
}

// These functions open and close the boxes on Article Central - these should really be consolidated with the ones above.  Consider it on the "to-do" list.
function toggleCats(foo) {
	closeMe2();
	document.getElementById('article'+foo).style.display = 'block';
}

function closeMe2(foo) {
	var catBoxes;
	catBoxes = document.getElementsByTagName('div');
	for (i=0 ; i<catBoxes.length ; i++) {
		if (catBoxes[i].className === 'articleSubcat') catBoxes[i].style.display = 'none';
	}
}

// This function "hooks up" all contact forms - greatly reduces spam
function activate(brillig) {
	document.getElementById('config').name = "config";
	document.getElementById('config').value = brillig;
}

// This functions creates the total bill for annual directory listings
function order() {
	var allcats = '';
	var allsvc = '';
	var total = 0;
	
	inputs = document.getElementsByTagName('input');
	
	for (i=0 ; i<inputs.length ; i++) {
		if (inputs[i].className === 'cats' && inputs[i].checked === true) {
			allcats += inputs[i].value+', '
			total = parseFloat(total)+99;
		}
		if (inputs[i].className === 'svc' && inputs[i].checked === true) {
			allsvc += inputs[i].value+', '
			total = parseFloat(total)+99;
		}
	}
	document.getElementById('All_Categories').value = allcats;
	document.getElementById('All_Services').value = allsvc;
	
	if (document.getElementById('Country').value !== '') total = parseFloat(total)+49;
	document.getElementById('showtot').innerHTML = total;
	document.getElementById('total').value = total;
}

// This function runs whenever any page loads
function setup() {
	
	// This module causes all external links to open in a new window
	/*
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var URL = anchors[i].href;
		URL = URL.substring(0,URL.lastIndexOf('com'));
		if (URL.search('http')!==-1 {
			if (URL.search(domain)===-1) anchors[i].target = "_blank";
		}
	}
	*/
	
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	var pageURL = window.location+'';
	if (pageURL.search('/find/web-hosting/') || pageURL.search('/reseller/web-hosting/')) {
		for (var i=0; i<anchors.length; i++) {
			var URL = anchors[i].href;
			//URL = URL.substring(0,URL.lastIndexOf('com'));
			if (URL.search('67.228.215.199')!==-1 || URL.search('whirads')!==-1) {
				anchors[i].target = "_blank";
			}
		}
	}


	// These modules compare specific containers and ensures they appear to be the same height.
	var colHeight1
	var colHeight2
	
	if (document.getElementById('compare1-1') && document.getElementById('compare1-2') && document.getElementById('compare1-3')) {
		colHeight1 = document.getElementById('compare1-1').offsetHeight;
		colHeight2 = document.getElementById('compare1-3').offsetHeight;
		if (colHeight1 < colHeight2) {
			document.getElementById('compare1-2').style.height = (document.getElementById('compare1-2').offsetHeight + (colHeight2-colHeight1))-12 + 'px';
		} else if (colHeight1 > colHeight2) {
			document.getElementById('compare1-4').style.height = (document.getElementById('compare1-4').offsetHeight + (colHeight1-colHeight2))-12 + 'px';
		}
	}
	
	if (document.getElementById('compare2-1') && document.getElementById('compare2-2')) {
		colHeight1 = document.getElementById('compare2-1').offsetHeight;
		colHeight2 = document.getElementById('compare2-2').offsetHeight;
		if (colHeight1 < colHeight2) {
			document.getElementById('compare2-1').style.height = (document.getElementById('compare2-1').offsetHeight + (colHeight2-colHeight1))-12 + 'px';
		} else if (colHeight1 > colHeight2) {
			document.getElementById('compare2-2').style.height = (document.getElementById('compare2-2').offsetHeight + (colHeight1-colHeight2))-12 + 'px';
		}
	}
	
	if (document.getElementById('compare3-1') && document.getElementById('compare3-2')) {
		colHeight1 = document.getElementById('compare3-1').offsetHeight;
		colHeight2 = document.getElementById('compare3-2').offsetHeight;
		if (colHeight1 < colHeight2) {
			document.getElementById('compare3-1').style.height = (document.getElementById('compare3-1').offsetHeight + (colHeight2-colHeight1))-14 + 'px';
		} else if (colHeight1 > colHeight2) {
			document.getElementById('compare3-2').style.height = (document.getElementById('compare3-2').offsetHeight + (colHeight1-colHeight2))-14 + 'px';
		}
	}
	
	if (document.getElementById('compare4-1') && document.getElementById('compare4-2') && document.getElementById('compare4-3')) {
		colHeight1 = document.getElementById('compare4-1').offsetHeight + document.getElementById('compare4-2').offsetHeight + document.getElementById('prenav3').offsetHeight;
		colHeight2 = document.getElementById('sidebar').offsetHeight;
		if (colHeight1 < colHeight2) {
			document.getElementById('compare4-3').style.height = (document.getElementById('compare4-3').offsetHeight + (colHeight2-colHeight1))-28 + 'px';
			document.getElementById('content').style.background = 'url(http://static.thewhir.com/images/bg_content1Bottom.gif) bottom left no-repeat';
			document.getElementById('compare4-3').style.background = 'none';
		} else if (colHeight1 > colHeight2) {
			document.getElementById('sidebar').style.height = (document.getElementById('sidebar').offsetHeight + (colHeight1-colHeight2))-30 + 'px';
			document.getElementById('content').style.background = 'url(http://static.thewhir.com/images/bg_content1Bottom.gif) bottom left no-repeat';
			document.getElementById('compare4-3').style.background = 'none';
		}
	}
	
	if (document.getElementById('compare4-1') && !document.getElementById('compare4-2') && !document.getElementById('homeSection')) {
		colHeight1 = document.getElementById('compare4-1').offsetHeight + document.getElementById('prenav3').offsetHeight;
		colHeight2 = document.getElementById('sidebar').offsetHeight;
		if (colHeight1 < colHeight2) {
			if (document.getElementById('magazineNullSection')) {
				document.getElementById('compare4-1').style.height = (document.getElementById('sidebar').offsetHeight)-190 + 'px';
			} else {
				document.getElementById('compare4-1').style.height = (document.getElementById('sidebar').offsetHeight)-60 + 'px';
			}
			document.getElementById('pageBottom').style.background = 'url(http://static.thewhir.com/images/bg_pageBottom2.gif) bottom left no-repeat'
			document.getElementById('compareMain').style.background = 'none'
		} else if (colHeight1 > colHeight2) {
			if (document.getElementById('magazineSection')) {
				document.getElementById('sidebar').style.height = ((document.getElementById('sidebar').offsetHeight + (colHeight1-colHeight2)))-290 + 'px';
			} else {
				document.getElementById('sidebar').style.height = ((document.getElementById('sidebar').offsetHeight + (colHeight1-colHeight2)))-60 + 'px';
			}
			// Added if-statement, 5-10-09 - if bug is found, remove the if part around these items. This was done to combat the comparison happening in layout.php after the 5-10-09 update.
			if (!document.getElementById('homeSection')) {
				document.getElementById('pageBottom').style.background = 'url(http://static.thewhir.com/images/bg_pageBottom2.gif) bottom left no-repeat';
				document.getElementById('compareMain').style.background = 'none';
			}
		}
	}
	
navShift('');
}

// This function switches the tabs in the box on the sidebar
function switchBox(foo) {
	if (foo === '1') {
		document.getElementById('switchBox1').style.display = 'block';
		document.getElementById('switchBox2').style.display = 'none';
		document.getElementById('switch1').childNodes[0].className = 'down';
		document.getElementById('switch2').childNodes[0].className = 'up';
	} else {
		document.getElementById('switchBox1').style.display = 'none';
		document.getElementById('switchBox2').style.display = 'block';
		document.getElementById('switch1').childNodes[0].className = 'up';
		document.getElementById('switch2').childNodes[0].className = 'down';
	}
}

window.onload=setup; 
