// JavaScript Document

function addFan (num) {
	
	var temp = "fan"+num;
	document.getElementById(temp).style.display = 'block';
	
	temp = "frs"+(parseInt(num)-1);
	document.getElementById(temp).innerHTML = "<div style=\"position:relative; height:6px; width:880px; border-bottom:solid 1px #484848; float:left; margin-right:15px;\">&nbsp;</div><a href=\"javascript:subFan('"+num+"');\"><img src=\"imgs/subPlayer.gif\" width=\"15\" height=\"14\" border=\"0\" /></a>";
	
	temp = "frs"+(parseInt(num)-2);
	document.getElementById(temp).innerHTML = "<div style=\"position:relative; height:6px; width:100%; border-bottom:solid 1px #484848;\">&nbsp;</div>";
	
	if (parseInt(num)%3 == 1) {
		addFanPage(Math.ceil(num/3));
	}
	
	if (num == '15') {
		temp = "frs"+num;
		document.getElementById(temp).innerHTML = "<div style=\"position:relative; height:6px; width:100%; border-bottom:solid 1px #484848;\">&nbsp;</div>";
	}
	else {
		temp = "frs"+num;
		document.getElementById(temp).innerHTML = "<div style=\"position:relative; height:6px; width:880px; border-bottom:solid 1px #484848; float:left; margin-right:15px;\">&nbsp;</div><a href=\"javascript:addFan('"+(parseInt(num)+1)+"');\"><img src=\"imgs/addPlayer.gif\" width=\"15\" height=\"14\" border=\"0\" /></a>";	
	}
}

function addFanPage (num) {
	var temp = "page"+(parseInt(num)-1);
	document.getElementById(temp).style.display = 'none';
	temp = "page"+num;
	document.getElementById(temp).style.display = 'block';
	
	temp = parseInt(num);
	var myCode = "";
	
	for (var n=1; n<=temp; n++) {
		if (n != temp) {
			myCode += "&nbsp;&nbsp;<a style=\"font-family:Arial, Helvetica, sans-serif; font-size:14px; color:#FFFFFF; text-decoration:none;\" href=\"javascript:gotoFRPage('"+n+"','"+temp+"','"+temp+"');\">"+n+"</a>";
		}
		else {
			myCode += "&nbsp;&nbsp;"+n;
		}
	}
	
	document.getElementById('pageNum').innerHTML = myCode;
}

function subFan (num) {
	
	var temp = "fan"+num;
	document.getElementById(temp).style.display = 'none';
	
	temp = "frs"+(parseInt(num)-1);
	document.getElementById(temp).innerHTML = "<div style=\"position:relative; height:6px; width:880px; border-bottom:solid 1px #484848; float:left; margin-right:15px;\">&nbsp;</div><a href=\"javascript:addFan('"+num+"');\"><img src=\"imgs/addPlayer.gif\" width=\"15\" height=\"14\" border=\"0\" /></a>";
	
	temp = "frs"+(parseInt(num)-2);
	document.getElementById(temp).innerHTML = "<div style=\"position:relative; height:6px; width:880px; border-bottom:solid 1px #484848; float:left; margin-right:15px;\">&nbsp;</div><a href=\"javascript:subFan('"+(parseInt(num)-1)+"');\"><img src=\"imgs/subPlayer.gif\" width=\"15\" height=\"14\" border=\"0\" /></a>";
	
	if (parseInt(num)%3 == 1) {
		subFanPage(Math.ceil(num/3));
	}
}

function subFanPage (num) {
	var temp = "page"+(parseInt(num)-1);
	document.getElementById(temp).style.display = 'block';
	temp = "page"+num;
	document.getElementById(temp).style.display = 'none';
	
	temp = parseInt(num);
	var myCode = "";
	
	for (var n=1; n<temp; n++) {
		if (n != (temp-1)) {
			myCode += "&nbsp;&nbsp;<a style=\"font-family:Arial, Helvetica, sans-serif; font-size:14px; color:#FFFFFF; text-decoration:none;\" href=\"javascript:gotoFRPage('"+n+"','"+(temp-1)+"','"+(temp-1)+"');\">"+n+"</a>";
		}
		else {
			myCode += "&nbsp;&nbsp;"+n;
		}
	}
	
	document.getElementById('pageNum').innerHTML = myCode;
	
}

function gotoFRPage (wo, akt, maxi) {
	var temp = "page"+akt;
	document.getElementById(temp).style.display = 'none';
	temp = "page"+wo;
	document.getElementById(temp).style.display = 'block';
	
	var myCode = "";
	
	for (var n=1; n<=parseInt(maxi); n++) {
		if (n != parseInt(wo)) {
			myCode += "&nbsp;&nbsp;<a style=\"font-family:Arial, Helvetica, sans-serif; font-size:14px; color:#FFFFFF; text-decoration:none;\" href=\"javascript:gotoFRPage('"+n+"','"+wo+"','"+maxi+"');\">"+n+"</a>";
		}
		else {
			myCode += "&nbsp;&nbsp;"+n;
		}
	}
	
	document.getElementById('pageNum').innerHTML = myCode;
}

var em = "";

function checkFanFields () {
	
	em = "";
	
	for (var n=1; n <= 15; n++) {
		var temp = "fan"+n;
		var myDiv = document.getElementById(temp).style.display;
		if (myDiv != 'none') {
			var temp = "nameF"+n;
			var field = document.getElementById(temp).value;
			if (field == "") {
				em += "Enter the name of fan #"+n+"!\n";
			}
			
			temp = 'snameF'+n;
			field = document.getElementById(temp).value;
			if (field == "") {
				em += "Enter the surname of fan #"+n+"!\n";
			}
			
			temp = 'mailF'+n;
			field = document.getElementById(temp).value;
			if (!checkMailAdres(field)) {
				em += "Enter the email of fan #"+n+"!\n";
			}
			
			temp = 'uniF'+n;
			field = document.getElementById(temp).value;
			if (field == "") {
				em += "Enter the university of fan #"+n+"!\n";
			}
			
			temp = 'countryF'+n;
			field = document.getElementById(temp).value;
			if (field == "") {
				em += "Enter the country of fan #"+n+"!\n";
			}
			
			temp = 'phoneF'+n;
			field = document.getElementById(temp).value;
			if (field == "") {
				em += "Enter the phone number of fan #"+n+"!\n";
			}
		}
		else {
			var temp = "nameF"+n;
			document.getElementById(temp).value = "";
			
			temp = 'snameF'+n;
			document.getElementById(temp).value = "";
			
			temp = 'mailF'+n;
			document.getElementById(temp).value = "";
			
			temp = 'uniF'+n;
			document.getElementById(temp).value = "";
			
			temp = 'countryF'+n;
			document.getElementById(temp).value = "";
			
			temp = 'phoneF'+n;
			document.getElementById(temp).value = "";
		}
	}
	
	if (document.getElementById('conduct').checked == false) {
		em += "Please accept the terms of conduct!";
	}
	
	checkEMF();
}

function checkEMF () {
	if (em == "") {
		sendFanReg();
	}
	else {
		alert(em);
	}
}

function sendFanReg() {
	document.forms['fanReg'].submit();
	alert("Thank you for your registration.\nAn email confirming your registration will be sent to the address you registered with. Remember to check your spam folder, in case the email is automatically filed there");
	if (document.getElementById('type').value == "Fan Registration Male") {
		doRequest("signin/sublinks/fanMaleReg.php", "signin");
	}
	else {
		doRequest("signin/sublinks/fanFemaleReg.php", "signin");
	}
}