 function enterCompetition(comp, week) {
		target = "/update.php?action=entercompetition&comp_id=" + comp;
		ret = confirm("Are you sure you want to join the league?");
		if (ret) {
			location = target;
		}
	 }
	 
	  function deleteLeague(id, comp) {
		target = "/update.php?action=deleteleague&id=" + id + "&comp_id=" + comp;
		ret = confirm("Do you want to delete this mini league?");
		if (ret) {
			location = target;
		}
	 }
	 
	  function showLink() {
		if(document.getElementById("link").style.display == 'none'){
			document.getElementById("link").style.display = 'block';
		}else{
			document.getElementById("link").style.display = 'none';
		}
	 }
	
	 function rejectPredictions(i, form){

	for(y=0;y<i;y++){
	
		document.getElementById("team_A_" + y).value = "";
		document.getElementById("team_A_" + y).selectedIndex = 0;

		document.getElementById("draw_" + y).checked = false;
	
		document.getElementById("team_B_" + y).value = "";
		document.getElementById("team_B_" + y).selectedIndex = 0;
		
		document.getElementById("team_A_" + y).style.visibility = 'visible';
		document.getElementById("draw_" + y).style.visibility = 'visible';
		document.getElementById("team_B_" + y).style.visibility = 'visible';

	
			
	
	}
	}
	
		  function switchWeek(week, weeks) {
		
		for(y=1;y<=weeks;y++){
	
			document.getElementById("week_" + y).style.display = 'none';

		}
		
		document.getElementById("week_" + week).style.display = 'block';
	 }

	 
	 
	 
function change(item, id){
	
	if(item == "A"){

		document.getElementById("draw_" + id).checked = false;
		document.getElementById("team_B_" + id).value = 0;
		document.getElementById("team_B_" + id).selectedIndex  = 0;
		
		if(document.getElementById("team_A_" + id).value == ''){
			document.getElementById("team_A_" + id).style.visibility = 'visible';
			document.getElementById("draw_" + id).style.visibility = 'visible';
			document.getElementById("team_B_" + id).style.visibility = 'visible';
		}else{
			document.getElementById("team_A_" + id).style.visibility = 'visible';
			document.getElementById("draw_" + id).style.visibility = 'hidden';
			document.getElementById("team_B_" + id).style.visibility = 'hidden';
		}
		
	}
	
	if(item == "X"){
		document.getElementById("team_A_" + id).value = 0;
		document.getElementById("team_A_" + id).selectedIndex  = 0;
		document.getElementById("team_B_" + id).value = 0;
		document.getElementById("team_B_" + id).selectedIndex  = 0;
		
		
		if(document.getElementById("draw_" + id).checked){
			document.getElementById("team_A_" + id).style.visibility = 'hidden';
			document.getElementById("draw_" + id).style.visibility = 'visible';
			document.getElementById("team_B_" + id).style.visibility = 'hidden';
		}else{
			document.getElementById("team_A_" + id).style.visibility = 'visible';
			document.getElementById("draw_" + id).style.visibility = 'visible';
			document.getElementById("team_B_" + id).style.visibility = 'visible';
		}
	}
	
	if(item == "B"){
	
		document.getElementById("draw_" + id).value = false;
		document.getElementById("team_A_" + id).value = 0;
		document.getElementById("team_A_" + id).selectedIndex  = 0;
		
		if(document.getElementById("team_B_" + id).value == ''){
			document.getElementById("team_A_" + id).style.visibility = 'visible';
			document.getElementById("draw_" + id).style.visibility = 'visible';
			document.getElementById("team_B_" + id).style.visibility = 'visible';
		}else{
			document.getElementById("team_A_" + id).style.visibility = 'hidden';
			document.getElementById("draw_" + id).style.visibility = 'hidden';
			document.getElementById("team_B_" + id).style.visibility = 'visibile';
		}
	}
}


function checkcreateleague(form){
	var minPasswordLength = 6;
	
	var name = form.elements["name"].value;

	//var password1 = form.elements["passwd1"].value;
	//var password2 = form.elements["passwd2"].value;



	if (!hasValue(name)) {
		alert("Please enter desired league name.");
		form.name.focus();
		return(false);
	}
	
	/*if (!hasValue(password1)) {
		alert("Please enter your password.");
		form.password1.focus();
		return(false);
	}

	if (password1.length < minPasswordLength) {
		alert("Please note, your password must be at least " + minPasswordLength + " characters.\nPlease re-enter your password.");
		form.password1.focus();
		return(false);
	}

	if (!hasValue(password2)) {
		alert("Please confirm your password.");
		form.password2.focus();
		return(false);
	}

	if (password1 != password2) {
		alert("Your passwords do not match, please re-enter your password");
		form.password2.focus();
		return(false);
	}*/

	
	 
	 
	 form.submit();

}

function checkjoinleague(form){

	var league_code = form.elements["league_code"].value;


	if (!hasValue(league_code)) {
		alert("Please enter league's id code.");
		form.league_code.focus();
		return(false);
	}
	 
	 form.submit();

}

function checkinvitation(form){

	var emails = form.elements["emails"].value;


	if (!hasValue(emails)) {
		alert("Please enter email address (addresses)");
		form.emails.focus();
		return(false);
	}
	 
	 form.submit();

}
function checkPredictions(i, form){

	var result = 0;
	var y;
	var data1;
	var data2;
	var data3;
	
	for(y=0;y<i;y++){
	
		if(document.getElementById("team_A_" + y).value > 0){
			result++;
		}
		
		if(document.getElementById("draw_" + y).checked == true){
			result++;
		}
		
		if(document.getElementById("team_B_" + y).value > 0){
			result++;
		}
	
			
	
	}
	
	if(result < i){
		alert("Please set predictions for all fixtures");
		return(false);
	}
	
	if(result > i){
		alert("Please double check predictions");
		return(false);
	}
	
	 form.submit();

}
