// Functions for determining age


		document.observe("dom:loaded", function() { // on DOM load
		
			// first, see if the verified cookie exists
			var hasCookie = getCookie('verified');
			
			if(hasCookie != 'true') { // If the cookie is not set to true, pop up the age gate
			
				// show the age gate modal
				Modalbox.show('age-gate.php', {title: 'Age Gate', width: 663, overlayClose:false, transitions:false, afterLoad:setupFields});
				Modalbox.deactivate();
				Modalbox.resizeToContent();
				


			
			}
			
		});
		
		function checkAge() {
		
			// Grab the user-inputted dates
			var myMonth = $("age-month").getValue(this.element);
			var myDay = $("age-day").getValue(this.element);
			var myYear = $("age-year").getValue(this.element);
			
			if(isNaN(myMonth) || isNaN(myDay) || isNaN(myYear)) { // see if all the user-entered values are numbers
			
				alert('Please enter numbers only.\n For example, April 11th 1980 should be entered as 4 11 80.');
			
			} else {

				var fullBirthday = myMonth+'/'+myDay+'/19'+myYear;
			
				var formattedBirthday = new Date(fullBirthday);
				var thisDate = new Date;
    			var diff = thisDate - formattedBirthday;
     			var age_in_years = diff/(1000*60*60*24*365.25);
			
				if(age_in_years >= 21) {
				
					//alert('you are ' + age_in_years);
					// Set a cookie and close the modal window
					setCookie('verified',true);
					Modalbox.hide();
					
				} else {
				
					alert('You must be 21 years old to view this website.');
					
				}
			
			}
			
			return false;
		}
		
		
		function setCookie(c_name,value,expiredays) {
        	var exdate=new Date();
        	exdate.setDate(exdate.getDate()+expiredays);
        	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
		}
		
		function getCookie(c_name) {
        	if (document.cookie.length>0) {
         		c_start=document.cookie.indexOf(c_name + "=")
          		if (c_start!=-1) {
                	c_start=c_start + c_name.length+1
                	c_end=document.cookie.indexOf(";",c_start)
                	if (c_end==-1) c_end=document.cookie.length
                	return unescape(document.cookie.substring(c_start,c_end))
                }
          	}
        	return ""
		} 
		
		
		
		
		function setupFields() {
		
			var allInputs = $$("#agegate input");
			
			allInputs.each(function(item) {
			$(item).observe("click", function(){
				if($(this).getValue() == "MM" || $(this).getValue() == "DD" || $(this).getValue() == "YY") {
					$(this).setValue("");
				}
			});
			$(item).observe("focus", function(){
				if($(this).getValue() == "MM" || $(this).getValue() == "DD" || $(this).getValue() == "YY") {
					$(this).setValue("");
				}
			});
			
			});
		}

		/////////////////////////
