// JavaScript Document

function onLoad() {
	startWebcam();
}

function startWebcam() {
	var timeout = 10000;
	var path = "http://www.wicb.org/webcam/camfile.jpg?" + (new Date()).getTime();

	document.images["webcam"].src = path;

	setTimeout('startWebcam()', timeout);
}

var menuId = null;
var btnId = null;
var timerId = null;
var timeout = 100;

function showMenu(id, btn) {
	stopCloseTimer();
	
	if (menuId)
		hideMenu();
		
	menuId = document.getElementById(id);
	menuId.style.visibility = 'visible';
	
	btnId = btn;
	btnId.style.backgroundPosition = '0px -35px';
}

function hideMenu() {
	if (menuId) {
		menuId.style.visibility = 'hidden';
		btnId.style.backgroundPosition = '0px 0px';
	}
}

function startCloseTimer() {
	timerId = window.setTimeout('hideMenu()', timeout);
}

function stopCloseTimer() {
	if (timerId) {
		window.clearTimeout(timerId);
		timerId = null;
	}
}

function openHighStream() {
	LaunchBroadcast('wicbhigh', 'live365', '', '', '', '', '', 'OK', 'Y');
}

function openLowStream() {
	LaunchBroadcast('wicblow', 'live365', '', '', '', '', '', 'OK', 'Y');
}

function openProgram(program) {
	window.location.href = "programs.php#" + program;
}

function validEmail(email) {
	if (email == "" || email == null)
		return true;
		
	var atpos = email.indexOf("@");
	var dotpos = email.lastIndexOf(".");
	
	if (atpos < 1 || dotpos < 3 || (dotpos - atpos < 2) || (email.length - dotpos < 2) || (email.length - 1 == dotpos))
		return false;
		
	return true;
}

function validDjEmail(email) {
	if (email == "" || !validEmail(email)) {
		alert("Error: Please enter a valid e-mail address.");
		return false;
	}
	
	return true;
}
		
function validateCommunityForm(form) {
	var name = form.contactName.value;
	var phone = form.contactPhone.value;
	var email = form.contactEmail.value;
	var eventName = form.eventName.value;
	var eventDate = form.eventDate.value;
	var eventTime = form.eventTime.value;
	var desc = form.desc.value;
	
	if (name == "" || name == null) {
		alert("Error: Please enter a contact name.");
		form.contactName.focus();
		return false;
	}
	else if (phone == "" || phone == null) {
		alert("Error: Please enter a contact phone number.");
		form.contactPhone.focus();
		return false;
	}
	else if (phone.length < 10) {
		alert("Error: Please enter a valid contact phone number.");
		form.contactPhone.focus();
		return false;
	}
	else if (!validEmail(email)) {
		alert("Error: Please enter a valid e-mail address.");
		form.contactEmail.focus();
		return false;
	}
	else if (eventName == "" || eventName == null) {
		alert("Error: Please enter an event name.");
		form.eventName.focus();
		return false;
	}
	else if (eventDate === "" || eventDate == null) {
		alert("Error: Please enter an event date.");
		form.eventDate.focus();
		return false;
	}
	else if (eventTime == "" || eventTime == null) {
		alert("Error: Please enter an event time.");
		form.eventTime.focus();
		return false;
	}
	else if (desc == "" || desc == null) {
		alert("Error: Please enter an event description.");
		form.desc.focus();
		return false;
	}
	
	return true;
}

function validateConcertForm(form) {
	var name = form.contactName.value;
	var phone = form.contactPhone.value;
	var email = form.contactEmail.value;
	var artist = form.artist.value;
	var date = form.date.value;
	var time = form.time.value;
	var venue = form.venue.value;
	
	form.contactName.style.backgroundColor = "#FFFFFF";
	form.contactPhone.style.backgroundColor = "#FFFFFF";
	form.contactEmail.style.backgroundColor = "#FFFFFF";
	form.artist.style.backgroundColor = "#FFFFFF";
	form.date.style.backgroundColor = "#FFFFFF";
	form.time.style.backgroundColor = "#FFFFFF";
	form.venue.style.backgroundColor = "#FFFFFF";
	
	if (name == "" || name == null) {
			alert("Error: Please enter a contact name.");
			form.contactName.focus();
			form.contactName.style.backgroundColor = "#FF9A9A";
			return false;
	}
	else if (phone == "" || phone == null) {
		alert("Error: Please enter a contact phone number.");
		form.contactPhone.focus();
		form.contactPhone.style.backgroundColor = "#FF9A9A";
		return false;
	}
	else if (phone.length < 10) {
		alert("Error: Please enter a valid contact phone number.");
		form.contactPhone.focus();
		form.contactPhone.style.backgroundColor = "#FF9A9A";
		return false;
	}
	else if (!validEmail(email)) {
		alert("Error: Please enter a valid e-mail address.");
		form.contactEmail.focus();
		form.contactEmail.style.backgroundColor = "#FF9A9A";
		return false;
	}
	else if (artist == "" || artist == null) {
		alert("Error: Please enter an artist name.");
		form.artist.focus();
		form.artist.style.backgroundColor = "#FF9A9A";
		return false;
	}
	else if (date == "" || date == null) {
		alert("Error: Please enter a concert date.");
		form.date.focus();
		form.date.style.backgroundColor = "#FF9A9A";
		return false;
	}
	else if (time == "" || time == null) {
		alert("Error: Please enter a concert time.");
		form.time.focus();
		form.time.style.backgroundColor = "#FF9A9A";
		return false;
	}
	else if (venue == "" || venue == null) {
		alert("Error: Please enter a venue.");
		form.venue.focus();
		form.venue.style.backgroundColor = "#FF9A9A";
		return false;
	}
	
	return true;
}