window.onload = function() {
	var hash = self.document.location.hash.substring(1);
	if(hash == '') {
		tab("home", "home");
	}
	else {
		var location = hash.split('_');
		if(location[0] == "thanks") {
			$(".selected").attr("class", "");
			$("#content_inner").load("/zambia2008/pages/sponsor/thanks.html");
		}
		else {
			switch(location[0]) {
				case "section":
					switch(location[1]) {
						case "home":
						case "sponsor":
							tab(location[1], location[1]);
							break;
						default:
							tab(location[1], '');
					}
					break;
				default:
					switch(location[0]) {
						case "photo":
							// Check for a dash
							var dash = location[1].split('-');
							if(dash[1]) {
								tab('photos', location[1], dash[0]);
							}
							else {
								tab('photos', location[1]);
							}
							break;
						case "video":
							tab('videos', location[1]);
							break;
						case "story":
							tab('stories', location[1]);
							break;
						default:
							tab('home', 'home');
					}
			}
		}
	}
}

function tab(tab, subtab, tabselect) {
	if(document.getElementById("tab_"+tab).style.display != "block") {
		// Hide others
		document.getElementById("tab_home").style.display = "none";
		document.getElementById("tab_photos").style.display = "none";
		document.getElementById("tab_videos").style.display = "none";
		document.getElementById("tab_stories").style.display = "none";
		document.getElementById("tab_sponsor").style.display = "none";
		
		// Select the tab
		$(".selected_tab").attr("class", "");
		$("#link_"+tab).attr("class", "selected_tab");
		
		// Display this
		document.getElementById("tab_"+tab).style.display = "block";
	}
	
	if(subtab) {
		// AJAX load
		$(".selected").attr("class", "");
		if(subtab != "home" && subtab != "sponsor") {
			switch(tab) {
				case "photos":
					type = "p";
					break;
				case "videos":
					type = "v";
					break;
				case "stories":
					type = "s";
					break;
			}
			if(tabselect) {
				document.getElementById(type+tabselect).className = "selected";
			}
			else {
				document.getElementById(type+subtab).className = "selected";
			}
		}
		$("#content_inner").load("/zambia2008/pages/"+tab+"/"+subtab+".html", '', function(){
			//setupZoom();
			$("#photos a").lightBox();
		});
	}
}

function focused(object, placeholder) {
	if(object.value == placeholder)
		object.value = '';
}

function blurred(object, placeholder) {
	if(object.value == '')
		object.value = placeholder;
}

function formcheck() {
	var name  = document.getElementById("name");
	var addr  = document.getElementById("address");
	var city  = document.getElementById("city");
	var state = document.getElementById("state");
	var zip   = document.getElementById("zip");
	var phone = document.getElementById("phone");
	var email = document.getElementById("email");
	
	var error = '';
	
	if(name.value ==  '' || name.value ==  'Name  ') { error = true; name.className = 'fill'; }
	else { name.className = ''; }
	if(addr.value ==  '' || addr.value ==  'Address (line 1)  ') { error = true; addr.className = 'fill'; }
	else { addr.className = ''; }
	if(city.value ==  '' || city.value ==  'City  ') { error = true; city.className = 'fill'; }
	else { city.className = ''; }
	if(state.value == '' || state.value == 'State/Province  ') { error = true; state.className = 'fill'; }
	else { state.className = ''; }
	if(zip.value ==   '' || zip.value ==   'Zip  ') { error = true; zip.className = 'fill'; }
	else { zip.className = ''; }
	if(phone.value == '' || phone.value == 'Phone  ') { error = true; phone.className = 'fill'; }
	else { phone.className = ''; }
	if(email.value == '' || email.value == 'Email  ') { error = true; email.className = 'fill'; }
	else { email.className = ''; }
	
	if(error == true) {
		document.getElementById("formError").style.display = "block";
		return false;
	}
	
	return true;
}
