window.onload = function() {
	setBranding();
	if (document.getElementById('close-promo')){initPromoClose();};
	if (section != "members") {initSearchBox();};
	if (section != "Home" && section!="" && section!= "the-big-picture" && section!= "members") {relatedLinks();};
	if (section == "movie-reviews") {xtraRatingInfo(); mediaLinks();};
	if (subsection == "contact_us") {prepTheForm('contact_form');}
	if (subsection == "register") {prepTheForm('member_form');}
}

function setBranding() {
	var branding = document.getElementById('branding');
	var class_rnd = new Array ("one clearfloat", "two clearfloat", "three clearfloat", "four clearfloat", "five clearfloat", "six clearfloat");

	var i = Math.floor(5*Math.random());
	
	branding.className = class_rnd[i];
}

function xtraRatingInfo() {
	var extrasLink = document.getElementById("xtra_ratings_a")
	var xtraRatings = document.getElementById("xtra_ratings");
	var closeRatings = document.getElementById("closeRatings");
	
	extrasLink.onclick = function() {
		xtraRatings.style.display = "block";
		return false;
	}

	closeRatings.onclick = function() {
		xtraRatings.style.display = "none";
		return false;	
	}
}


function prepTheForm(theForm) {
	
	prepForm = document.getElementById(theForm);
	prepForm.onsubmit = function() {
		return validateForm(this);
	}
}

function validateForm(whichForm) {
	for (var i=0; whichForm.elements.length; i++) {
		var element = whichForm.elements[i];
		if (element.className.indexOf("validate") != -1) {
			if (element.value != "5") {
				element.setAttribute("class","validate error")
				alert("Please enter the result of 2 + 3.");
				return false;
			}
		}
	}
	return true;
}

function initSearchBox() {
	var titleSearch = document.getElementById('search_titles');
	var siteSearch = document.getElementById('search_all');
	var titlesBttn = document.getElementById('titles_button');
	var siteBttn = document.getElementById('site_button');
	
	siteBttn.onclick = function() {
		titleSearch.style.display="none";
		siteSearch.style.display="block";
		siteBttn.className = "active";
		titlesBttn.className = "";
		return false;
	}
	
	titlesBttn.onclick = function() {
		siteSearch.style.display="none";
		titleSearch.style.display="block";
		titlesBttn.className = "active";
		siteBttn.className = "";
		return false;
	}
}

function initPromoClose() {
	var closeLink = document.getElementById('close-promo');
	var promoBox = document.getElementById('promo');
	
	closeLink.onclick = function() {
		promoBox.style.display = "none";
		return false;	
	}
}

