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

domain = 'thewhir'

// This function shifts the backgrounds behind the site navigation.
function navShift(foo) {

}

// 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 allptr = '';
	var pretaxtotal = 0;
	var tax = 0;
	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+', '
			pretaxtotal = parseFloat(pretaxtotal)+99;
		}
		if (inputs[i].className === 'svc' && inputs[i].checked === true) {
			allsvc += inputs[i].value+', '
			pretaxtotal = parseFloat(pretaxtotal)+99;
		}
		if (inputs[i].className === 'ptr' && inputs[i].checked === true) {
			allptr += inputs[i].value+', '
			pretaxtotal = parseFloat(pretaxtotal)+99;
		}
	}
	document.getElementById('All_Categories').value = allcats;
	document.getElementById('All_Services').value = allsvc;
	document.getElementById('All_Partners').value = allptr;
	
	if (document.getElementById('Country').value !== '') pretaxtotal = parseFloat(pretaxtotal)+49;
	if (document.getElementById('Canada_Resident').checked === true) { 
		tax = (parseFloat(pretaxtotal)*.05)
		tax = tax.toFixed(2);
		document.getElementById('tax').innerHTML = '<br />$' + tax + ' + 5% GST';
	} else {
		document.getElementById('tax').innerHTML = '';
	}
	total = parseFloat(pretaxtotal)+parseFloat(tax);
	total = total.toFixed(2);
	document.getElementById('showtot').innerHTML = pretaxtotal + '.00';
	document.getElementById('amount').value = pretaxtotal;
	document.getElementById('total').value = total;

	if (parseFloat(total) === 0) {
		document.getElementById('checkoutwarning').style.display = 'block';
		document.getElementById('checkout3').style.display = 'none';
	} else {
		document.getElementById('checkoutwarning').style.display = 'none';
		document.getElementById('checkout3').style.display = 'block';
	}
}

// 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('whirdev')===-1 && URL.search('thewhir')===-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('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-3')) {
		colHeight1 = document.getElementById('compare1-1').offsetHeight;
		colHeight2 = document.getElementById('compare1-3').offsetHeight;
		if (colHeight1 < colHeight2) {
			document.getElementById('compare1-1').style.height = (document.getElementById('compare1-3').offsetHeight - 12) + 'px';
		} else if (colHeight1 > colHeight2) {
			document.getElementById('compare1-3').style.height = (document.getElementById('compare1-1').offsetHeight - 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('compare5-1') && document.getElementById('compare5-2')) {
		colHeight1 = document.getElementById('compare5-1').offsetHeight;
		colHeight2 = document.getElementById('compare5-2').offsetHeight;
		if (colHeight1 < colHeight2) {
			document.getElementById('compare5-1').style.height = (document.getElementById('compare5-1').offsetHeight + (colHeight2-colHeight1))-12 + 'px';
		} else if (colHeight1 > colHeight2) {
			document.getElementById('compare5-2').style.height = (document.getElementById('compare5-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('navMain').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(/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(/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('navMain').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(/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(/images/bg_pageBottom2.gif) bottom left no-repeat';
				document.getElementById('compareMain').style.background = 'none';
			}
		}
	}
	// THIS FUNCTION SWAPS IN A DIFFERENT BACKGROUND FOR THE MAIN NAVIGATION, IF SUBNAVIGATION IS PRESENT
	allDivs = document.getElementsByTagName('div');
	if(!document.getElementById('tvSection')) {
		for (i=0 ; i<allDivs.length ; i++) {
			if (allDivs[i].className === 'subnav') { 
				document.getElementById('navMain').style.background = 'url(/images/bg_navMain2.gif) bottom left repeat-x';
				j=1;
			}
		}
	}
}

// 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; 

/*
jQuery(document).ready(function() {                       
  
  
  var showFields = function() {
    var fields = ['#reg-form .row-address-1', '#reg-form .row-address-2', '#reg-form .row-city', '#reg-form .row-state', '#reg-form .row-zip-code', '#reg-form .row-country'];
    $.each(fields, function() {
      eval("var field = $('" + this +"');");
      (field).toggle();
    });
    
    $('#mag_sub_fields_msg').toggle();
  }
 
  $('#reg-form input[id=magazine]').click(showFields)
 
  if ($('#reg-form input[id=magazine]').attr('checked') === true) {
    showFields();
  }   
});*/

jQuery(document).ready(function() {                       
  if($('#reg-form input[id=user_reg_magazine]:checked').val() == null) {
  	$('#reg-form .row-address').hide();
  }
  
  var showFields = function() {
    $('#reg-form .row-address').toggle();
  }
  
  $('#reg-form input[id=user_reg_magazine]').click(showFields);
 
  $('#user_job').change(function() {
    if ($(this).val() == 'Other') {  
      $('.other-job').show();
      $('#user_job_other').focus();
    }
    else {
      $('.other-job').hide();
    }
  });
  
  $('#user_company_type').change(function() {
    if ($(this).val() == 'Other') {  
      $('.other-company-type').show();
      $('#user_company_type_other').focus();
    }
    else {
      $('.other-company-type').hide();
    }
  });
  
  $('#user_referrer').change(function() {
    if ($(this).val() == 'Other') {
      $('.other-referrer').show();
      $('#user_referrer_other').focus();
      $('.other-tradeshow').hide();
    }
    else if ($(this).val() == 'Conference or Trade Show') {
      $('.other-tradeshow').show();
      $('#user_tradeshow').focus();
      $('.other-referrer').hide();
    }
    else {
      $('.other-tradeshow').hide();
      $('.other-referrer').hide();
    }
  });
  
  $('.trigger-non-generic').click(function() {
    $('.generic-author td input').val('');
    $('.non-generic-author').toggle();
    $('.generic-author').hide();
    return false;
  });

  $('.trigger-generic-author').click(function() {
    $('.generic-author').show();
    $('.non-generic-author').hide();
    return false;
  });
  
  $('.select-image span a').click(function() {
    $(this).parent().parent().find('span a').each(function() {
      $(this).removeClass('chosen');
    });            
    $(this).parent().parent().find('input').attr('value', $(this).find('img').attr('src'));
    $(this).addClass('chosen');
    return false;
  });
});

