var startList = function() {
    if (document.all && document.getElementById) {
        var navRoot = document.getElementById("nav_317842");
        for (i = 0; i < navRoot.childNodes.length; i++) {
            var node = navRoot.childNodes[i];
            if (node.nodeName == "li") {
                node.onmouseover = function() {
                    this.className += " over";
                }
                node.onmouseout = function() {
                    this.className = this.className.replace(" over", "");
                }
            }
        }
    }
};

var getCookie = function(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 "";
};

window.onload = function() {
	startList();
	
	alert();

	var imgUrl= "/Images/Heroes/Hero###.jpg";
	var numImgs = 7;
	var imgToLoad = Math.floor(Math.random()*7) + 1;
	imgUrl = imgUrl.replace("###", imgToLoad);
	document.getElementById("header").style.backgroundImage = "url('"+ imgUrl + "')";

	// 18+ button
	if (document.getElementById("ageSensitive") != null) {
		document.getElementById("ageVerify").checked = 0;
		document.getElementById("ageSensitive").style.display = "none";

		document.getElementById("ageVerify").onclick = function() {
			if (document.getElementById("ageVerify").checked == 1) {
				document.getElementById("ageSensitive").style.display = "block";
			} else {
				document.getElementById("ageSensitive").style.display = "none";
			}
		}
	}
}

var checkDob = function(date) {
	dob = date.split("/");
	var today = new Date();

	// Do some simple validation to ensure we're dealing with a proper date.
	if ((dob.length == 3) && (!(dob[0] > 31 || dob[0] < 1 || dob[1] > 12 || dob[1] < 1))) {
		
		if (!(dob[0] > 31 || dob[0] < 1 || dob[1] > 12 || dob[1] < 1))
			
		// Check if user is > 18. If so, calculating month/day is unnecessary.
		if (today.getFullYear() - parseInt(dob[2], 10) > 18) {
			return "";
		} else {
			// Check that the user isn't < 18
			if (!(today.getFullYear() - parseInt(dob[2], 10) < 18)) {
				// Check if user was born before the current month
				if ((parseInt(dob[1], 10) - 1) < today.getMonth()) {
					return "";
				// User was born on the current month
				} else if ((parseInt(dob[1], 10) - 1) == today.getMonth()) {
					// Check if user was born on or before this day of the month
					if (parseInt(dob[0], 10) <= today.getDate()) {
						return "";
					}
				}
			}
		}
	} else {
		return "- You must enter a valid date of birth.\n";
	}
	return "- You must be 18 years or older to order.\n";
};

