<!--
ctfthumb = null;
allowedscore = 5;
var thepic = new Array;

function checkVotes()
{
	var votearray = new Array;
	var theform = document.getElementById('vote');
	
	votearray[1] = theform.first.value;

	votearray[2] = theform.second.value;

	votearray[3] = theform.third.value;

	votearray[4] = theform.fourth.value;

	votearray[5] = theform.fifth.value;

	if ( votearray[1] == "" || votearray[2] == "" || votearray[3] == "" || votearray[4] == "" || votearray[5] == "" )	
	{
		alert("You have not voted for 5 images.");
		return false;
	}
	else if ( votearray[1] == votearray[2] || votearray[1] == votearray[3] || votearray[1] == votearray[4] || votearray[1] == votearray[5] || votearray[2] == votearray[3] || votearray[2] == votearray[4] || votearray[2] == votearray[5] || votearray[3] == votearray[4] || votearray[3] == votearray[5] || votearray[4] == votearray[5] )
	{
		alert("You have voted for more than one of the same images.");
		return false;
	}
	else
	{
		return true;
	}
}

function checkIDs()
{
	var ctfusername = document.getElementById('ctf_username').value;
	var ctfsecretid = document.getElementById('ctf_secretID').value;
	
	if ( ctfusername == "" )
	{
		alert("Username cannot be empty.");
		return false;
	}
	else if ( ctfsecretid == "" )
	{
		alert("You must create a Secret ID to prevent unauthorized viewing of the standings.");
		return false;
	}
	else
	{
		return true;
	}
}

function checkForm()
{
	if ( checkVotes() && checkIDs() )
	{
		return true;
	}
	else
	{
		return false;
	}
}

function closethumb() {
	if (ctfthumb && ctfthumb.open && !ctfthumb.closed) ctfthumb.close();
}

function showthumb(url,w,h,param) {
	closethumb();
	w=20+w;
	h=25+h;
	if (w > maxw) {
		w = maxw - 10;
	}
	if (h > maxh) {
		h = maxh - 65;
	}
	if (!param) { param = 'toolbar=no,directories=no,location=no,status=no,menubar=no,resizable=no,scrollbars=no'; }
	ctfthumb = window.open(url,'_ctfthumb','width='+w+',height='+h+','+param);
	ctfthumb.focus();
}

function getmaxdim() {
	maxh = screen.height;
	maxw = screen.width;
}
getmaxdim();

onpic = 1;
function voteonthis(pic_id) {
	for (var j=1; j<=5; j++)
	{
		if (pic_id == thepic[j])
		{
			alert("You have already voted for this image.");
			return;
		}
	}

	if (document.forms[0].first.value == "") {
		onpic = 1;
	}
	else if (document.forms[0].second.value == "") {
		onpic = 2;
	}
	else if (document.forms[0].third.value == "") {
		onpic = 3;
	}
	else if (document.forms[0].fourth.value == "") {
		onpic = 4;
	}
	else if (document.forms[0].fifth.value == "") {
		onpic = 5;
	}
	else {
		onpic = 6;
	}
	
	thepic[onpic] = pic_id;

	if (onpic == 1) {
		if (thumbs)
		{
			var thesrc = String(document.images['thumb'+pic_id].src);
			document.images['vote1'].src = thesrc.replace(/medium/,'small');
		}
		document.forms[0].first.value=pic_id;
		document.forms[0].first.focus();
		document.forms[0].reason1.select();
		document.forms[0].reason1.focus();
		onpic = 2;
	}
	else if (onpic == 2) {
		if (thumbs)
		{
			var thesrc = String(document.images['thumb'+pic_id].src);
			document.images['vote2'].src = thesrc.replace(/medium/,'small');
		}
		document.forms[0].second.value=pic_id;
		document.forms[0].first.focus();
		document.forms[0].reason2.select();
		document.forms[0].reason2.focus();
		onpic = 3;
	}
	else if (onpic == 3) {
		if (thumbs)
		{
			var thesrc = String(document.images['thumb'+pic_id].src);
			document.images['vote3'].src = thesrc.replace(/medium/,'small');
		}
		document.forms[0].third.value=pic_id;
		document.forms[0].first.focus();
		document.forms[0].reason3.select();
		document.forms[0].reason3.focus();
		onpic = 4;
	}
	else if (onpic == 4) {
		if (thumbs)
		{
			var thesrc = String(document.images['thumb'+pic_id].src);
			document.images['vote4'].src = thesrc.replace(/medium/,'small');
		}
		document.forms[0].fourth.value=pic_id;
		document.forms[0].first.focus();
		document.forms[0].reason4.select();
		document.forms[0].reason4.focus();
		onpic = 5;
	}
	else if (onpic == 5) {
		if (thumbs)
		{
			var thesrc = String(document.images['thumb'+pic_id].src);
			document.images['vote5'].src = thesrc.replace(/medium/,'small');
		}
		document.forms[0].fifth.value=pic_id;
		document.forms[0].first.focus();
		document.forms[0].reason5.select();
		document.forms[0].reason5.focus();
		onpic = 6;
	}
	else if (onpic == 6) {
		document.forms[0].first.focus();		
		alert("You have already chosen 5 choices: Clear a choice and select again to chose this image.");
	}
	else {
		onpic = onpic + 1;
	}
}

function changeVotethumb(votenum)
{
	if (thumbs)	document.images[votenum].src='images/nophoto.gif';		
	if (votenum == 'vote1')
	{
		pic_id = document.forms[0].first.value;
		for (var j=1; j<=5; j++)
		{
			if (pic_id == thepic[j])
			{
				alert("You have already voted for this image.");
				document.forms[0].first.value='';
				thepic[j]=0;
				return;
			}
		}
		thepic[1]=(pic_id)?pic_id:0;
	}
	else if (votenum == 'vote2')
	{
		pic_id = document.forms[0].second.value;
		for (var j=1; j<=5; j++)
		{
			if (pic_id == thepic[j])
			{
				alert("You have already voted for this image.");
				document.forms[0].second.value='';
				thepic[j]=0;
				return;
			}
		}
		thepic[2]=(pic_id)?pic_id:0;
	}
	else if (votenum == 'vote3')
	{
		pic_id = document.forms[0].third.value;
		for (var j=1; j<=5; j++)
		{
			if (pic_id == thepic[j])
			{
				alert("You have already voted for this image.");
				document.forms[0].third.value='';
				thepic[j]=0;
				return;
			}
		}
		thepic[3]=(pic_id)?pic_id:0;
	}
	else if (votenum == 'vote4')
	{
		pic_id = document.forms[0].fourth.value;
		for (var j=1; j<=5; j++)
		{
			if (pic_id == thepic[j])
			{
				alert("You have already voted for this image.");
				document.forms[0].fourth.value='';
				thepic[j]=0;
				return;
			}
		}
		thepic[4]=(pic_id)?pic_id:0;
	}
	else if (votenum == 'vote5')
	{
		pic_id = document.forms[0].fifth.value;
		for (var j=1; j<=5; j++)
		{
			if (pic_id == thepic[j])
			{
				alert("You have already voted for this image.");
				document.forms[0].fifth.value='';
				thepic[j]=0;
				return;
			}
		}
		thepic[5]=(pic_id)?pic_id:0;
	}
	if (pic_id.length > 3)
		if (document.images['thumb'+pic_id])
			if (thumbs)
			{
				var thesrc = String(document.images['thumb'+pic_id].src);
				document.images[votenum].src = thesrc.replace(/medium/,'small');
			}
}

function clearVotes(showthumbs)
{
	if (showthumbs)
	{
		document.images['vote1'].src='images/nophoto.gif';	
		document.images['vote2'].src='images/nophoto.gif';	
		document.images['vote3'].src='images/nophoto.gif';	
		document.images['vote4'].src='images/nophoto.gif';	
		document.images['vote5'].src='images/nophoto.gif';
	}
	thepic=null;
	thepic = new Array;
}

function picreturn(photonum)
{
	if (thepic[photonum] != null)
	{
		document.location.hash='id'+thepic[photonum];
		/*document.location.hash='related';*/
	}
}

function calcscore()
{
	for ( i=0; i<document.forms[0].radio1.length; i++ )
	{
		if ( document.forms[0].radio1[i].checked )
		{
			checked = i + 1;
		}
	}
	rad1 = checked;

	for ( i=0; i<document.forms[0].radio2.length; i++ )
	{
		if ( document.forms[0].radio2[i].checked )
		{
			checked = i + 1;
		}
	}
	rad2 = checked;

	for ( i=0; i<document.forms[0].radio3.length; i++ )
	{
		if ( document.forms[0].radio3[i].checked )
		{
			checked = i + 1;
		}
	}
	rad3 = checked;

	for ( i=0; i<document.forms[0].radio4.length; i++ )
	{
		if ( document.forms[0].radio4[i].checked )
		{
			checked = i + 1;
		}
	}
	rad4 = checked;

	for ( i=0; i<document.forms[0].radio5.length; i++ )
	{
		if ( document.forms[0].radio5[i].checked )
		{
			checked = i + 1;
		}
	}
	rad5 = checked;

	totalrad = rad1 + rad2 + rad3 + rad4 + rad5;
	
	rad1 = rad1 / totalrad;	
	rad2 = rad2 / totalrad;	
	rad3 = rad3 / totalrad;
	rad4 = rad4 / totalrad;
	rad5 = rad5 / totalrad;
	
	rad2 = Math.round((rad2*allowedscore)*10)/10;
	rad3 = Math.round((rad3*allowedscore)*10)/10;
	rad4 = Math.round((rad4*allowedscore)*10)/10;
	rad1 = Math.round((rad1*allowedscore)*10)/10;
	rad5 = Math.round((allowedscore - (rad2 + rad3 + rad4 + rad1))*10)/10;
	
	document.forms[0].pts1.value = rad1;
	document.forms[0].pts2.value = rad2;
	document.forms[0].pts3.value = rad3;
	document.forms[0].pts4.value = rad4;
	document.forms[0].pts5.value = rad5;
}

function showForm(formhide, formshow)
{
	var formtohide;
	var formtoshow = document.getElementById(formshow);
	
	if ( formhide ) formtohide = document.getElementById(formhide);
	
	if ( formtoshow.style.display == 'none' )
	{
		formtoshow.style.display='block';
		if ( formhide ) formtohide.style.display='none';
	}
	else
	{
		formtoshow.style.display='none';
		if ( formhide ) formtohide.style.display='block';
	}
}

function showImage(sPicURL, size) { 
	closethumb();
	ctfthumb = window.open("viewimage.php?imageurl="+sPicURL+"&size="+size, "", "resizable=1,HEIGHT=200,WIDTH=200");
	ctfthumb.focus();
}

-->

