
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
 


function box2Show()
{
        if (readCookie('dci_underage') == "true")
        {
            var e = document.getElementById("box-2");
            e.innerHTML = '<br/><table bgcolor="#ffffff" width="300" border="1"><tr><td>We are sorry, you do not meet the registration requirements. Please contact Customer Service at (800) 324-6496.</td></tr></table>';
        }

   
}


function checkAge(check)
{
//alert(readCookie('dci_underage'));
var min_age = 18;
var e = document.getElementById("box-2");

var year = parseInt(document.forms.check.yearBorn.value);
var month = parseInt(document.forms.check.monthBorn.value)-1;
var day = parseInt(document.forms.check.dateBorn.value)-1;

var theirDate = new Date(year, month, day);
var today = new Date;
var datediff = (today - theirDate);

var inDays = Math.round(datediff/(1000*60*60*24));
var inYears = (inDays/365.25);



//alert("in years = " + inYears);

if (readCookie('dci_underage') == "true"){
window.location = "http://www.wizards.com/default.asp?x=dci/wopnunderage";
return (false);
   }



if (document.check.firstName.value == "") {
e.innerHTML = '<span class="error">Your First name is missing. <a href="http://www.wizards.com/default.asp?x=dci/wopn">Back to the form</a><span>';
return (false);
}

if (document.check.lastName.value == "") {
e.innerHTML = '<span class="error">Your Last name is missing. <a href="http://www.wizards.com/default.asp?x=dci/wopn">Back to the form</a><span>';
return (false);
}

if (document.check.email.value == "") {
e.innerHTML = '<span class="error">Your eMail is missing. <a href="http://www.wizards.com/default.asp?x=dci/wopn">Back to the form</a><span>';
return (false);
}

if (document.check.yearBorn.value == "") {
e.innerHTML = '<span class="error">Please enter your birthdate. <a href="http://www.wizards.com/default.asp?x=dci/wopn">Back to the form</a><span>';
return (false);
}

if (inYears < 18) {
window.location = "http://www.wizards.com/default.asp?x=dci/wopnunderage";
return (false);
}

return (true);

}