<!--
ctfthumb = null;
allowedscore = 5;

var gecko = (document.addEventListener ? 1 : 0); // DOM2

var thepic = new Array;

function uncheckBox(boxname)
{
	var thebox = document.getElementById(boxname);
	thebox.checked = false;
}

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('ctfusername').value;
	var ctfsecretid = document.getElementById('ctfsecretid').value;
	
	if ( ctfusername == "" )
	{
		alert("Username cannot be empty.");
		return false;
	}
	else if ( ctfusername.length < 3 )
	{
		alert("Your username must be at least 3 characters long.");
		return false;
	}
	else if ( ctfsecretid == "" )
	{
		alert("You must create a personal access code to prevent unauthorized viewing of the standings.");
		return false;
	}
	else if ( ctfsecretid.length < 3 )
	{
		alert("Your personal access code must be at least 3 characters long.");
		return false;
	}
	else
	{
		return true;
	}
}

function checkForm()
{
	var ready = document.getElementById('readytosubmit');
	if ( checkVotes() && checkIDs() )
	{
		if ( ready.checked )
		{
			return true;
		}
		else
		{
			alert("You must check the box above to confirm that you have reviewed your selections.");
			return false;
		}
	}
	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)
{
	var votingform = document.getElementById('vote');
	
	for (var j=1; j<=5; j++)
	{
		if (pic_id == thepic[j])
		{
			alert("You have already voted for this image.");
			return;
		}
	}

	if (votingform.first.value == "") {
		onpic = 1;
	}
	else if (votingform.second.value == "") {
		onpic = 2;
	}
	else if (votingform.third.value == "") {
		onpic = 3;
	}
	else if (votingform.fourth.value == "") {
		onpic = 4;
	}
	else if (votingform.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');
		}
		votingform.first.value=pic_id;
		votingform.first.focus();
		votingform.reason1.select();
		votingform.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');
		}
		votingform.second.value=pic_id;
		votingform.first.focus();
		votingform.reason2.select();
		votingform.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');
		}
		votingform.third.value=pic_id;
		votingform.first.focus();
		votingform.reason3.select();
		votingform.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');
		}
		votingform.fourth.value=pic_id;
		votingform.first.focus();
		votingform.reason4.select();
		votingform.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');
		}
		votingform.fifth.value=pic_id;
		votingform.first.focus();
		votingform.reason5.select();
		votingform.reason5.focus();
		onpic = 6;
	}
	else if (onpic == 6) {
		votingform.first.focus();		
		alert("You have already chosen 5 choices: Clear a choice and select again to chose this image.");
	}
	else {
		onpic = onpic + 1;
	}
	uncheckBox('readytosubmit');
}

function changeVotethumb(votenum)
{
	var votingform = document.getElementById('vote');

	var badpic = 0;
	var pic_id;
	if (votenum == 'vote1' && (pic_id = votingform.first.value))
	{
		if (thumbs)	document.images[votenum].src='images/nophoto1.gif';		
		if ( !document.images['thumb'+pic_id] )
		{
			alert("This image does not exist.");
			badpic = 1;
		}
		for (var j=1; j<=5; j++)
		{
			if (pic_id == thepic[j])
			{
				alert("You have already voted for this image.");
				badpic = 1;
			}
		}
		if ( badpic )
		{
			votingform.first.value='';
			thepic[1]=0;
			return;
		}
		else
		{
			thepic[1]=(pic_id)?pic_id:0;
		}
	}
	else if (votenum == 'vote2' && (pic_id = votingform.second.value))
	{
		if (thumbs)	document.images[votenum].src='images/nophoto2.gif';		
		if ( !document.images['thumb'+pic_id] )
		{
			alert("This image does not exist.");
			badpic = 1;
		}
		for (var j=1; j<=5; j++)
		{
			if (pic_id == thepic[j])
			{
				alert("You have already voted for this image.");
				badpic = 1;
			}
		}
		if ( badpic )
		{
			votingform.second.value='';
			thepic[2]=0;
			return;
		}
		else
		{
			thepic[2]=(pic_id)?pic_id:0;
		}
	}
	else if (votenum == 'vote3' && (pic_id = votingform.third.value))
	{
		if (thumbs)	document.images[votenum].src='images/nophoto3.gif';		
		if ( !document.images['thumb'+pic_id] )
		{
			alert("This image does not exist.");
			badpic = 1;
		}
		for (var j=1; j<=5; j++)
		{
			if (pic_id == thepic[j])
			{
				alert("You have already voted for this image.");
				badpic = 1;
			}
		}
		if ( badpic )
		{
			votingform.third.value='';
			thepic[3] = 0;
			return;
		}
		else
		{		
			thepic[3]=(pic_id)?pic_id:0;
		}
	}
	else if (votenum == 'vote4' && (pic_id = votingform.fourth.value))
	{
		if (thumbs)	document.images[votenum].src='images/nophoto4.gif';		
		if ( !document.images['thumb'+pic_id] )
		{
			alert("This image does not exist.");
			badpic = 1;
		}
		for (var j=1; j<=5; j++)
		{
			if (pic_id == thepic[j])
			{
				alert("You have already voted for this image.");
				badpic = 1;
			}
		}
		if ( badpic )
		{
			votingform.fourth.value='';
			thepic[4] = 0;
			return;
		}
		else
		{
			thepic[4]=(pic_id)?pic_id:0;
		}
	}
	else if (votenum == 'vote5' && (pic_id = votingform.fifth.value))
	{
		if (thumbs)	document.images[votenum].src='images/nophoto5.gif';		
		if ( !document.images['thumb'+pic_id] )
		{
			alert("This image does not exist.");
			badpic = 1;
		}
		for (var j=1; j<=5; j++)
		{
			if (pic_id == thepic[j])
			{
				alert("You have already voted for this image.");
				badpic = 1;
			}
		}
		if ( badpic )
		{
			votingform.fifth.value='';
			thepic[5] = 0;
			return;
		}
		else
		{
			thepic[5]=(pic_id)?pic_id:0;
		}
	}
	if (pic_id && pic_id.length > 0)
	{
		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');
			}
		}
	}
	uncheckBox('readytosubmit');
}

function clearVotes(showthumbs)
{
	if (showthumbs)
	{
		document.images['vote1'].src='images/nophoto1.gif';	
		document.images['vote2'].src='images/nophoto2.gif';	
		document.images['vote3'].src='images/nophoto3.gif';	
		document.images['vote4'].src='images/nophoto4.gif';	
		document.images['vote5'].src='images/nophoto5.gif';
	}
	for (var j=1; j<=5; j++)
	{
		thepic[j] = 0;
	}	
	uncheckBox('readytosubmit');
}

function picreturn(photonum)
{
	if (thepic[photonum] != null)
	{
		document.location.hash='id'+thepic[photonum];
		/*document.location.hash='related';*/
	}
}

function calcscore()
{
	var votingform = document.getElementById('vote');
	
	for ( i=0; i<votingform.radio1.length; i++ )
	{
		if ( votingform.radio1[i].checked )
		{
			checked = i + 1;
		}
	}
	rad1 = checked;

	for ( i=0; i<votingform.radio2.length; i++ )
	{
		if ( votingform.radio2[i].checked )
		{
			checked = i + 1;
		}
	}
	rad2 = checked;

	for ( i=0; i<votingform.radio3.length; i++ )
	{
		if ( votingform.radio3[i].checked )
		{
			checked = i + 1;
		}
	}
	rad3 = checked;

	for ( i=0; i<votingform.radio4.length; i++ )
	{
		if ( votingform.radio4[i].checked )
		{
			checked = i + 1;
		}
	}
	rad4 = checked;

	for ( i=0; i<votingform.radio5.length; i++ )
	{
		if ( votingform.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;
	
	votingform.pts1.value = rad1;
	votingform.pts2.value = rad2;
	votingform.pts3.value = rad3;
	votingform.pts4.value = rad4;
	votingform.pts5.value = rad5;

	uncheckBox('readytosubmit');
}

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=(gecko)?'table':'block';
		if ( formhide ) formtohide.style.display='none';
	}
	else
	{
		formtoshow.style.display='none';
		if ( formhide ) formtohide.style.display=(gecko)?'table':'block';
	}
}

function showImage(sPicURL, size) { 
	closethumb();
	ctfthumb = window.open("viewimage.php?imageurl="+sPicURL+"&size="+size, "", "resizable=1,HEIGHT=200,WIDTH=200");
	ctfthumb.focus();
}

-->

