function addEvent(obj, evType, fn){ 
	if (obj.addEventListener){ 
   		obj.addEventListener(evType, fn, false); 
   		return true; 
 	} else if (obj.attachEvent){ 
   		var r = obj.attachEvent("on"+evType, fn); 
   		return r; 
 	} else { 
   		return false; 
 	} 
}	

function removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}


function openInExtWindow(e) {
	var event;
	if (!e) event = window.event;
	else event = e;
	// Abort if a modifier key is pressed
	if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) {
		return true;
	}
	else {		
	    var url=this.getAttribute('href');
		
		var newWindow = window.open(url,"TreatyOakRum","height=600,width=1000,top=5,left=5,scrollbars=1,resizable=1,toolbars=0");
		
		if (newWindow) {
			if (newWindow.focus) {
				newWindow.focus();
			}
			return false;
		}
		return true;
	}
}	


function getNewWindowLinks() {
	// Check that the browser is DOM compliant
	if (document.getElementById && document.createElement && document.appendChild) {
		// Change this to the text you want to use to alert the user that a new window will be opened
		var strNewWindowAlert = " (opens in a new window)";
		// Find all links
		var links = document.getElementsByTagName('a');
		var objWarningText;
		var link;
		for (var i = 0; i < links.length; i++) {
			link = links[i];			
			if (/\bexternal/.test(link.className)) {				
				link.onclick = openInExtWindow;					
			}else if (/\bregistration/.test(link.className)) {				
				link.onclick = openInRegWindow;					
			}else if (/\bflash/.test(link.className)) {
				link.onclick = openInFlashWindow;		
			}else if (/\bimage/.test(link.className)) {
				link.onclick = openInImageWindow;								
			}else if (/\bprintview/.test(link.className)) {
				link.onclick = openInPrintWindow;					
			}
		}
		objWarningText = null;
	}
}

function checkAge(){
	var month = document.getElementById("month");
	var day = document.getElementById("day");
	var year = document.getElementById("year");	
			
	var oldEnough = false;	
			
	if(parseInt(year.value) && (currYear - parseInt(year.value) > 21)){
		oldEnough = true;
	}else{
		if(parseInt(year.value) && (currYear - parseInt(year.value) == 21)){
			if(parseInt(month.value) < currMonth){
				oldEnough = true;
			}else{
				if(parseInt(month.value) == currMonth){
					if(parseInt(day.value) <= currDay){
						oldEnough = true;		
					}
				}
			}
		}
	}
	if(oldEnough){
		window.location.replace("home.php");		
	}else{
		alert("You must be 21 years old to enter.");
	}
	return false;
}

addEvent(window, 'load', getNewWindowLinks);

