function rollImg (imgName, imgSrc) {
	if (document.images) {
		document[imgName].src = imgSrc;
	}
}

function rollStyle (styleObj, styleName) {
	if (styleObj.className) {
		styleObj.className = styleName;
	} else {
		document.getElementById(styleObj).className = styleName;
	}
}

var cookieName = "nrwlimitcookie";
function checkCookie () {
	if (document.cookie.lastIndexOf(cookieName) > -1) {
		location.href = "/promos/getanimated/giveaway/error.html";
	}
}

function setCookie () {
	expireDate =  new Date(2009,1,1);
	expireDate.setFullYear(expireDate.getFullYear()+1); 
	
	//Set cookie domain to xxxx.com (not www.xxxx.com)
	domain = self.location.host;
	if (/^[^.]+\.[^.]+\.[^.]+$/.test(domain)) {
		domain = domain.substring(domain.indexOf('.')+1);
	}
	
	if (domain != '') {
		if ( !(document.cookie = cookieName + '=true; expires=' + expireDate.toGMTString() + '; path=/; domain=' + domain) ) {
			//If setting the cookie failed, try without specifying the domain (Netscape can be tricky).
			document.cookie = cookieName + '=true; expires=' + expireDate.toGMTString() + '; path=/';
		}
	} else {
		document.cookie = cookieName + '=true; expires=' + expireDate.toGMTString() + '; path=/';
	}
	location.href = "/promos/getanimated/giveaway/error.html";
}

var selMonth;
var selYear;
function validateForm () {
	checkCookie();
	hasError = false;
	for (i = 0; i < document.schoolinfo.elements.length; i++) {
		titleElm = "";
		if (document.schoolinfo.elements[i].type == "text") {
			if (document.schoolinfo.elements[i].value == "" || document.schoolinfo.elements[i].value == undefined) {
				titleElm = document.schoolinfo.elements[i].name + "Block";
				document.getElementById(titleElm).className = "redTxt";
				hasError = true;
			}
		}
		if (document.schoolinfo.elements[i].type == "checkbox") {
			if (document.schoolinfo.elements[i].checked != true) {
				hasError = true;
			}
		}
		if (document.schoolinfo.elements[i].type == "select-one") {
			if (document.schoolinfo.elements[i][document.schoolinfo.elements[i].selectedIndex].value == "null") {
				titleElm = document.schoolinfo.elements[i].name + "Block";
				document.getElementById(titleElm).className = "redTxt";
				hasError = true;
			} else {
				if (document.schoolinfo.elements[i].name == "month") {
					if (document.schoolinfo.elements[i][document.schoolinfo.elements[i].selectedIndex].value == "Jan") {
						selMonth = 1;
					}
					if (document.schoolinfo.elements[i][document.schoolinfo.elements[i].selectedIndex].value == "Feb") {
						selMonth = 2;
					}
					if (document.schoolinfo.elements[i][document.schoolinfo.elements[i].selectedIndex].value == "Mar") {
						selMonth = 3;
					}
					if (document.schoolinfo.elements[i][document.schoolinfo.elements[i].selectedIndex].value == "Apr") {
						selMonth = 4;
					}
					if (document.schoolinfo.elements[i][document.schoolinfo.elements[i].selectedIndex].value == "May") {
						selMonth = 5;
					}
					if (document.schoolinfo.elements[i][document.schoolinfo.elements[i].selectedIndex].value == "Jun") {
						selMonth = 6;
					}
					if (document.schoolinfo.elements[i][document.schoolinfo.elements[i].selectedIndex].value == "Jul") {
						selMonth = 7;
					}
					if (document.schoolinfo.elements[i][document.schoolinfo.elements[i].selectedIndex].value == "Aug") {
						selMonth = 8;
					}
					if (document.schoolinfo.elements[i][document.schoolinfo.elements[i].selectedIndex].value == "Sep") {
						selMonth = 9;
					}
					if (document.schoolinfo.elements[i][document.schoolinfo.elements[i].selectedIndex].value == "Oct") {
						selMonth = 10;
					}
					if (document.schoolinfo.elements[i][document.schoolinfo.elements[i].selectedIndex].value == "Nov") {
						selMonth = 11;
					}
					if (document.schoolinfo.elements[i][document.schoolinfo.elements[i].selectedIndex].value == "Dec") {
						selMonth = 12;
					}
				}
				if (document.schoolinfo.elements[i].name == "year") {
					selYear = parseInt(document.schoolinfo.elements[i][document.schoolinfo.elements[i].selectedIndex].value);
				}
			}
		}
	}
	if (hasError) {
		alert("Please complete all fields before submitting.");
	} else {
		if ((tyear - selYear) > 12) {
			document.schoolinfo.submit();
		} else if ((tyear - selYear) == 12) {
			if (selMonth >= tmonth) {
			document.schoolinfo.submit();
			} else {
				setCookie();
			}
		} else {
			setCookie();
		}
	}
}