Shadowbox.init({
    		// let's skip the automatic setup because we don't have any
    		// properly configured link elements on the page
    		skipSetup: true,
    		modal: true,
    		overlayOpacity: 0.8

		});

$(document).ready(function() { 
		//$.cookie("adult",null);
		
	if($.cookie("adult") != 'yes' )
	{
		window.onload = function(){
			 var divId = document.getElementById('block_bday_div');
	
	
	    	// open a welcome message as soon as the window loads
			 Shadowbox.open({
				content:    divId.innerHTML,
				player:     "html",				
				height:     450,
				width:      650,
				options:{
					onFinish: function() {
				 
						//console.log( $('#sb-container .popupDatepicker') );
						$('#sb-container .popupDatepicker').datepick({
                             
							 
							    onSelect: function(dates) { 
							        
							        var minDate = dates[0]; 
							        for (var i = 1; i < dates.length; i++) { 
							            if (dates[i].getTime() < minDate.getTime()) { 
							                minDate = dates[i]; 
							            } 
							        } 
							       showdate($.datepick.formatDate(minDate)); 
							        
							    } 
					
							
						});
						
						
					}
				}
			 
				
			});		
			 
			 
		}; // window onload end
		
	} // if end
		

});

function showdate(dt)
{
	
	document.getElementById('nwdt').value = dt;
	
}
function boxclose(){

	if($.cookie("adult") == 'yes')
	{
		parent.Shadowbox.close();
	}
	else
	{
		window.location='';
	}
}

function agesubmit()
{
	var age = checkAge();
	//alert(age);
	if(age > 18)
	{
		$.cookie("adult" , "yes", { path: '/'});
		Shadowbox.close();
	}
	else
	{
		alert("Too young to view this site");
	}
}

function checkAge()
{ 
	
	var today = new Date(); 
	//alert(today);
	//var d = document.getElementById("date").value;
	
	var d = document.getElementById('nwdt').value;
	
	if (!/\d{2}\/\d{2}\/\d{4}/.test(d))
	{   // check valid format
		showMessage();
		return false;
	}	

	d = d.split("/");
	//alert(d);
	var byr = parseInt(d[2]); 
	var nowyear = today.getFullYear();
	//alert(nowyear)
	if (byr >= nowyear || byr < 1900) 
	{  // check valid year
		showMessage();
		return false;
	}
	var bmth = parseInt(d[0],10)-1;   // radix 10!
	//alert(bmth)
	if (bmth <0 || bmth >11) 
	{  // check valid month 0-11
		showMessage() 
		return false;
	}
	var bdy = parseInt(d[1],10);   // radix 10!
	var dim = daysInMonth(bmth+1,byr);
	if (bdy <1 || bdy > dim) 
	{  // check valid date according to month
		showMessage();
		return false;
	}

	var age = nowyear - byr;

	var nowmonth = today.getMonth();
	var nowday = today.getDate();
	if (bmth > nowmonth) {age = age - 1}  // next birthday not yet reached
	else if (bmth == nowmonth && nowday < bdy) {age = age - 1}
	
	return age;
}

function showMessage() 
{
	
}

function daysInMonth(month,year)
{  // months are 1-12
	var dd = new Date(year, month, 0);
	return dd.getDate();
} 

