/*
Copyright (c) 2008 Henrique T. Barbieri.
C3SL - Center for Scientific Computing and Free Software

This file is part of SiGTChess.

SiGTChess is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

SiGTChess is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
*/


function UnhideReloadIframe(selectedId, divName, iframeName, iframePage){
	if (selectedId=="" || selectedId==-1){
		if (document.getElementById(divName)){
			document.getElementById(divName).style.display='none';
		}else{
			parent.document.getElementById(divName).style.display='none';
		}
	}else{
		if (document.getElementById(divName)){

			window.open(iframePage+"?selectedId="+selectedId, iframeName);
			document.getElementById(divName).style.display='';
		}else{
			window.open(iframePage+"?selectedId="+selectedId, iframeName);
			parent.document.getElementById(divName).style.display='';
		}
		
	}
}

function lockDiv(hideThis, selectedId, divName, iframeName, iframePage){
	if (selectedId=="" || selectedId==-1){
		parent.document.getElementById(divName).style.display='none';
	}else{
		parent.document.getElementById(hideThis).style.display='none';
		window.open(iframePage+"?selectedId="+selectedId, iframeName);
		parent.document.getElementById(divName).style.display='';
		
	}
}

function textareaLimit(field, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
}

function showErrMsg(msg){
	document.getElementById('divConf').style.display='none'; 
	document.getElementById('divErro').style.display=''; 
	document.getElementById('msgErr').value=msg;
}

function showConfMsg(msg){
	document.getElementById('divErro').style.display='none'; 
	document.getElementById('divConf').style.display=''; 
	document.getElementById('msgConf').value=msg;
}

function verifiesMatchesResults(qtd_matches){
	wout_result="";
	err_wo="";
	for (i=0 ; i<qtd_matches ; i++) {
		wo="pc_wo"+i;
		id="winJ"+i;
		mesa=i+1;
		campo="document.frmshowPairing."+id;
		campo_wo="document.frmshowPairing."+wo;
		//verifica se todas as mesas tem resultados
		if (!eval(campo+"[0].checked") && !eval(campo+"[1].checked") && !eval(campo+"[2].checked"))
			wout_result=wout_result+mesa+", ";
	}

	if (wout_result!=""){
		alert("Os resultados das mesas "+wout_result+"não foram gravados! Por favor preencha-os.");
		return false
	}else{
		return true
	}
}



