
function checktournament(which)
{
	var oops = false;

	var sd = document.getElementById("startdate").value;
	var ed = document.getElementById("enddate").value;

	if (document.getElementById("reqtourname").value == '') {
		oops = "Please fill in a Tournament name";
	} else if (sd == '') {
		oops = "Please Enter Start Date";
	} else if (ed == '') {
		oops = "Please Enter End Date";
	} else if (new Date(sd) > new Date(ed)) {
		oops = "Start Date Cannot Be After End Date";
	} else {
		switch (document.getElementById("choice").value) {
		case "4":
			if (document.getElementById("course4").value == "none") {
				oops = "Please Select Golf Course #4";
			}
		case "3":
			if (document.getElementById("course3").value == "none") {
				oops = "Please Select Golf Course #3";
			}
		case "2":
			if (document.getElementById("course2").value == "none") {
				oops = "Please Select Golf Course #2";
			}
		default:
			if (document.getElementById("course1").value == "none") {
				oops = "Please Select Golf Course #1";
			}
		}
	}

	if (oops) {
		alert(oops);
		return false;
	}

	return true;
}


function checkForm() {

	var f = document.forms[0];
	var pass1;
	var pass2;

	for (var i=0; i< f.elements.length; i++)
	{
		if(f.elements[i].type == "checkbox")
		{
			if(f.elements[i].checked == true)
			{
				f.elements[i].value = true;
			}
			else
			{
				f.elements[i].value = false;
			}
		}
		else if(f.elements[i].type == "password")
		{
			if(f.elements[i].name == "password")
			{
				pass1 = f.elements[i].value;
			}
			else if(f.elements[i].name == "password2")
			{
				pass2 = f.elements[i].value;
			}
		}
	}

	if(pass1 != pass2)
	{
		alert('Passwords do not match');
		return false;
	}

	return true;
}

function promptDeleteUser(){

	var answer = confirm("Do you want to delete the user and all data\nassociated with him?")
	if(answer) return true;

	return false;
}

function promptDeleteTournament(){

	var answer = confirm("Do you want to delete the tournament \n and all data associated with this event?")
	if(answer) return true;

	return false;
}

function submit_team_add(){
	var f = document.forms[0];

	if(!checkteam(f)) return;

	f.submit();
}

function isIE() {
	return document.all;
}

function search_user_lname(letter) {

	var frm = isIE() ? document.name_search : document.forms['name_search'];
	frm.firstName.value = "";
	frm.lastName.value=letter;
	frm.submit();
}

function checkteam(which)
{
	var pass=true;

	if (document.images)
	{
		for (i=0;i<which.length;i++)
		{
			var tempobj=which.elements[i];

			if (tempobj.name.substring(0,3)=="req")
			{
				if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1))
				{
					pass=false;
					break;
				}
			}
		}
	}

	if (!pass)
	{
		alert("Please fill team name");
		return false;
	}
	return true;
}

function clear_values(ndx){
	var fn = "fn" + ndx;
	//var ln = "ln" + ndx;
	//var id = "id" + ndx;

	document.getElementById(fn).value = "";
	//document.getElementById(ln).value = "";
	//document.getElementById(id).value = "";
}

function print_score_2()
{
	document.getElementById('scpr_controls').style.display = "";
	document.getElementById('welcomeBorder').style.display = "";
	document.getElementById('mainBorder').style.border = "";
}

function print_scorecard()
{
	document.getElementById('scpr_controls').style.display = "none";
	document.getElementById('welcomeBorder').style.display = "none";
	document.getElementById('mainBorder').style.border = "none";
	window.print();
	window.setTimeout('print_score_2()', 2000);
	return false;
}

function keyable(e)
{
	var keynum;
	var keystr;
	keynum = e.keyCode;
	if (!window.event && e.which) {
		keynum = e.which;
	}
	keystr = String.fromCharCode(keynum);
	return /[\d\.a-zA-Z \b\t\r]/.test(keystr);
}

function videoSelect(vnum)
{
        
	var fade_msecs = 500;
	videostuff.selected = vnum;
	var vid = videostuff[vnum]['path'];
	var wd = videostuff[vnum]['width'];
	var ht = videostuff[vnum]['height'];
	if (wd > 960) {
		ht = ht * 960 / wd;
		wd = 960;
	}
	$("#unotes").val(videostuff[vnum]['usernotes']);
	if (videostuff[vnum]['format'] === "mp4") {
		// flash!
		// <a href="jim.flv" style="display:block;width:640px;height:240px" id="player"> </a> 
		// href='" + vid + "'
		$("#vid_eo").html("<a style='display:block;width:" + wd + "px;height:" + ht + "px' id='player'></a>");
		var fpopts = {
			clip: {
				autoBuffering: true,
				autoPlay: false
			},
			plugins: {
				controls: {
					volume: false,
					mute: false,
					tooltips: {
						buttons: true
					}
				}
			}
		};
		fpopts['clip']['url'] = vid;
		flowplayer("player", "flowplayer/flowplayer-3.2.7.swf", fpopts);
	} else {
		// HTML 5 is _so_ much easier!
		//$("#vid_eo").html("<video src='" + vid + "' width=" + wd + " height=" + ht + " controls></video>");       
                        $("#vid_eo").html("<video src='" + vid + "' width=" + wd + " height=" + ht + "></video>");
                        $('audio,video').mediaelementplayer({
                            success: function(player, node) {
                            $('#' + node.id + '-mode').html('mode: ' + player.pluginType);
                            }
});
//			$("#vid_eo").html(jwplayer("vid_eo").setup({
//			flashplayer: "jwplayer/player.swf",
//			file: vid,
//			height: ht,
//			width: wd
//}));
	}
	$("#vid_select").slideUp(fade_msecs);
	$("#vid_play").slideDown(fade_msecs);
}

function videoBack()
{
	var vnum = videostuff.selected;
	var note = $("#unotes").val();
	videostuff[vnum]['usernotes'] = note;
	var params = { action: 39, vidnote: note, id: videostuff[vnum]['id'] };
	$.post('simscore.php', params, function(data) {
		var fade_msecs = 500;
		$("#vid_play").slideUp(fade_msecs, function() { 
			$("#vid_eo").html('');
		});
		$("#vid_select").slideDown(fade_msecs);
	});
}

function confirmSubmit()
{
	return confirm("Are you sure you want to Leave?");
}

function confirmSubmitDel()
{
	return confirm("Are you sure you want to Remove?");
}

function confirmSubmitSave()
{
	return confirm("Are you sure you want to Save your changes?");
}

function shotdetail(scid, hole)
{
	var url = "tmisc.php?fnx=12&scid=" + scid + "&holeno=" + hole;
	var fade_msecs = 500;
	$.get(url, function(data){
		$("#scorecard_cont").slideUp(fade_msecs);
		$("#score_detail").html(data).slideDown(fade_msecs);
	});
}

function shotback()
{
	var fade_msecs = 500;
	$("#score_detail").slideUp(fade_msecs);
	$("#scorecard_cont").slideDown(fade_msecs);
}


