//SCRIPT ABRE IMAGEM
var winpopup=null;

function pop_image(imgname, prwidth, prheight, legenda) 
{ 
  var strcode = 'pop_img.php?img=' + imgname + '&legenda=' + legenda;
  var auxstr;

  auxstr  = 'width=' + prwidth;
  auxstr  = auxstr + ',height=' + prheight;
  auxstr  = auxstr + ',top=10,left=10,scrollbars=1,resizable=yes';

  if (winpopup != null) 
  {
    winpopup.close();
  }
  winpopup = window.open(strcode,'ttb_IMG_DETAIL', auxstr);
}

//SCRIPT LIMPA INPUT PREENCHIDO
function limpainput(obj) {
	obj.value = "";
}

//Monta a data no padrão dd/mm/aaaa
function digitaData(Campo,e)
{
	var tecla = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
	vr = Campo.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 )
	{
		if ( tam > 2 && tam < 5 )
			Campo.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			Campo.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 );
	}
}

function validaEsqueceuSenha()
{
	var form = document.frmEsqueceuSenha;
	var erro = false;
	var msg = "Preencha o(s) campo(s) abaixo:\n";

	if(form.txtEmail.value == "")
	{
		erro = true;
		msg += "\nE-mail";
	} else {
		if(!isMail('frmEsqueceuSenha', 'txtEmail'))
		{
			erro = true;
			msg += "\nE-mail inválido";
		}
	}

	if(erro)
	{
		alert(msg);
		return false;
	} else {
		return true;
	}
}

//Máscara para data
//CHAMADA: onkeypress="FormataData('Campo',event)"
function FormataData(Campo,teclapres)
{
	var tecla = teclapres.keyCode;
	vr = document.form[Campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;
	if( tecla != 9 && tecla != 8 )
	{
	   if( tam > 2 && tam < 5 )
	   document.form[Campo].value = vr.substr( 0, tam - 2 ) + '/' + vr.substr( tam - 2, tam );
	   if( tam >= 5 && tam <= 10 )
	   document.form[Campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 );
	}
}

function ValidaBusca()
{	
	var erro = false;	
	if(verificaIsNum(document.formPaginacao.var_curpage_sup)==false)
	{
		alert('Verifique o seguinte erro:\n\n*Insira um valor p/ a página');
		return true;
	}
}

function ValidaUp()
{
	var strErro = 'Verifique o(s) seguinte(s) erro(s):\n\n';
	var erro = false;
	var form = eval('document.frmSendFile');
	
	if(form.selCategoria.value == '')
	{
		strErro += '* Selecione um PROJETO para o seu arquivo\n';
		erro = true;
	}	
	if(form.txtTituloArquivo.value == '')
	{
		strErro += '* Preencha um TITULO para identificar seu arquivo\n';
		erro = true;
	}
	if(form.txtDescricaoArquivo.value == '')
	{
		strErro += '* Preencha uma DESCRIÇÃO para o seu arquivo\n';
		erro = true;
	}
	if(form.file.value == '')
	{
		strErro += '* Selecione um ARQUIVO\n';
		erro = true;
	}
	if(erro == true)
	{
		alert(strErro);
		return false;
	}
	else
	{
		return true;
	}
}
function ValidaData()
{
	var form = eval("document.FrmBusca") ;
	var strErro = 'Verifique o(s) seguinte(s) erro(s):\n\n';
	var erro = false;
	
	if((form.txtDiaInicio.value != '') && (form.txtMesInicio.value != '') && (form.txtAnoInicio.value != ''))
	{
		return true;
	}
	if((form.txtDiaFim.value != '') && (form.txtMesFim.value != '') && (form.txtAnoFim.value != ''))
	{
		return true;
	}
	if((form.txtDiaInicio.value != '') || (form.txtMesInicio.value != '') || (form.txtAnoInicio.value != ''))
	{
		strErro += '* Preencha completamente a DATA INICIAL\n';
		erro = true;
	}
	if((form.txtDiaFim.value != '') || (form.txtMesFim.value != '') || (form.txtAnoFim.value != ''))
	{
		strErro += '* Preencha completamente a DATA FINAL\n';
		erro = true;
	}
	if(erro == true)
	{
		alert(strErro);
		return false;
	}
	else
	{
		return true;
	}
}

function DeleteFiles()
{
		var form = deleta;
		var Codigos = '';
		var erro = true;
		var msg = "Selecione pelo menos 1 arquivo para deletar!";
		
		for(i = 0; i < form.length; i++)
		{
			if(form.elements[i].type == "checkbox")
			{
				if(form.elements[i].checked == true)
				{					
					Codigos = Codigos + form.elements[i].value + ',';				
				}
			}
		}
		if(Codigos == '')
		{
			alert(msg);
			return false;
		} 
		else
		{
			Codigos = Codigos.substring(0,Codigos.length-1);			
			form.Codigos.value = Codigos;
			if(confirm("Você deseja realmente deletar este(s) arquivo(s)?"))
			{
				return true;
			}
			else 
			{
				return false;
			}
		}
}

function ValidaLoginArquivo()
{
	var strErro = "Verifique o(s) seguinte(s) erro(s):\n\n";
	var erro = false;
	var form = eval("document.frmLoginArquivo");
	
	if(form.txtUsuario.value == '')
	{
		strErro += '*Preencha seu nome de usuário\n';
		erro = true;
	}
	if(form.txtSenha.value == '')
	{
		strErro += '*Preencha sua senha\n';
		erro = true;
	}
	if(erro == true)
	{
		alert(strErro);
		return false;		
	}
	else
	{
		return true;
	}
}

function ValidaLogin()
{
	var form = eval("document.frmLogin");
	var strErro = "Verifique o(s) seguinte(s) erro(s):\n\n";
	var erro = false;
	
	if(form.txtUsuario.value == '' || form.txtUsuario.value == 'usuário')	
	{
		strErro += '* Preencha seu nome de usuário\n';
		erro = true;
	}
	if(form.txtSenha.value == '' || form.txtSenha.value == 'senha')
	{
		strErro += '* Preencha sua senha\n';
		erro = true;
	}
	if(erro == true)
	{
		alert(strErro);
		return false;
	}
	else
	{
		return true;
	}
}

function validaCadastroOng()
{
	var form = document.frmCadastroOng;
	var erro = false;
	var msg = "Preencha o(s) campo(s) abaixo:\n";

	if(form.txtNomeOng.value == "")
	{
		erro = true;
		msg += "\nNome da ONG";
	}
	if(form.txtCidade.value == "")
	{
		erro = true;
		msg += "\nCidade";
	}
	if(form.selEstado.value == "")
	{
		erro = true;
		msg += "\nEstado";
	}
	if(form.txtPais.value == "")
	{
		erro = true;
		msg += "\nPaís";
	}
	if(form.txtContato.value == "")
	{
		erro = true;
		msg += "\nNome do responsável";
	}
	if(form.txtEmail.value == "")
	{
		erro = true;
		msg += "\nE-mail";
	} else {
		if(!isMail('frmCadastroOng', 'txtEmail'))
		{
			erro = true;
			msg += "\nE-mail inválido";
		}
	}
	if(form.txtFone.value == "")
	{
		erro = true;
		msg += "\nTelefone";
	} else {
		if(!verificaIsNum(form.txtFone.value))
		{
			erro = true;
			msg += "\nTelefone inválido";
		}
	}
	if(form.txtUsuario.value == "")
	{
		erro = true;
		msg += "\nUsuário";
	}
	if(form.txtSenha.value == "")
	{
		erro = true;
		msg += "\nSenha";
	}
	if(form.txtSenha2.value == "")
	{
		erro = true;
		msg += "\nRepita Senha";
	}
	if(form.txtSenha.value != form.txtSenha2.value)
	{
		erro = true;
		msg += "\nSenha e repetição devem ser iguais";
	}

	if(erro)
	{
		alert(msg);
		return false;
	} else {
		return true;
	}
}

function ValidaContato()
{
	var strErro = 'Verifique o(s) seguinte(s) erro(s):\n\n';
	var erro = false;
	var form = eval("document.FrmContato");	
	
	if(form.txtNome.value == '')
	{
		strErro += '* Preencha seu nome\n';
		erro = true;
	}
	if(form.txtEmail.value == '')
	{
		strErro += '* Preencha seu e-mail\n';
		erro = true;
	}
	else
	{
		if(isMail('FrmContato','txtEmail')==false)
		{
			strErro += '* Verifique o preenchimento do seu e-mail\n';
			erro = true;
		}
	}
	if(form.txtTelefone.value == '')
	{
		strErro += '* Preencha seu telefone\n';
		erro = true;
	}
	if(form.txtEndereco.value == '')
	{
		strErro += '* Preencha seu telefone\n';
		erro = true;
	}
	if(form.txtCidade.value == '')
	{
		strErro += '* Preencha sua cidade\n';
		erro = true;
	}
	if(form.txtEstado.value == '')
	{
		strErro += '* Preencha seu estado\n';
		erro = true;
	} 
	if(form.txtPais.value == '')
	{
		strErro += '* Preencha seu país\n';
		erro = true;
	}
	if(form.txtAssunto.value == '')
	{
		strErro += '* Especifique o assunto da sua mensagem\n';
		erro = true;
	}
	if(form.txtMsg.value == '')
	{
		strErro += '* Preencha sua mensagem\n';
		erro = true;
	}
	if(erro == true)
	{
		alert(strErro);
		return false;
	}
	else
	{
		return true;
	}
}

function isMail(form, campo)
{
	var re = new RegExp;
	strMail = eval('document.' + form +  '.' + campo + '.value');

	re = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var arr = re.exec(strMail);
	if (arr == null)
	{    
    	return false;
	}
	else
	{
   		return true;
	}
}

//Verifica uma data no padrão:
//00/00/0000 ou 0/0/00
function verificaData(valor)
{
	reDate = /^((0?[1-9]|[12]\d{1,2})\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/(19|20)?\d{2}$/;
	if (reDate.test(valor)) {
		return true;
	} else if (valor != null && valor != "") {
		return false;
	}
}

function permiteSoNumeros(event)
{
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    var caract = new RegExp(/^[0-9 ]+$/i);
    var caract = caract.test(String.fromCharCode(keyCode));
    //------------------------
    if(!caract)
	{
		//alert("Caracter inválido: " + String.fromCharCode(keyCode));
        keyCode = 0;
		return false;
	}
}

//Verifica se o valor é inteiramente numérico
function verificaIsNum(valor)
{
	p = valor;
	p = p.replace("(", "")
	p = p.replace(")", "")
	p = p.replace("-", "")
	p = p.replace("-", "")

	if(isNaN(p) == true)
	{
		return false;
	}
	else
	{
		return true;
	}
}

// SCRIPTS MM
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function over_tr(src,clrOver) {
 if (!src.contains(event.fromElement)) {
  src.style.cursor = 'hand';
  src.bgColor = clrOver;
 }
}
function out_tr(src,clrIn) {
 if (!src.contains(event.toElement)) {
  src.style.cursor = 'default';
  src.bgColor = clrIn;
 }
}


function go(loc) {
window.location.href = loc;
}

/*******************************************************
CHECKBOXES
*******************************************************/
function checkbox(nameOfForm)
{
	// Store variables.
	this.nameOfForm=(nameOfForm) ? nameOfForm:0;
	this.toggleOnOff=1;

	// Can be used externally, but meant for internal use only.
	this.set=function(bool)
	{
		if (document.forms && document.getElementsByTagName)
		{
			var theFields=eval('document.forms["'+this.nameOfForm+'"].getElementsByTagName("input");');

			var theFieldsLen=theFields.length;
			for (i=0; i<theFieldsLen; i++)
			{
				if (theFields[i].getAttribute("type").toLowerCase() == "checkbox")
				{
					if(theFields[i].disabled == false)
					{
						theFields[i].checked=bool;
					}
				}
			}
		}
		else alert('Not Supported');
	}

	// Basic functions to use externally.
	this.check=function() { this.set(true); }
	this.clear=function() { this.set(false); }

	// Just a nifty little feature.
	this.toggle=function()
	{
		if (this.toggleOnOff) { this.set(true); this.toggleOnOff=0; }
		else if (!this.toggleOnOff) { this.set(false); this.toggleOnOff=1; }
	}

	// Call this during BODY onLoad to add mouseover functionality to the form.
	this.enableMouseover=function()
	{
		if (document.forms && document.getElementsByTagName)
		{
			var moFields=eval('document.forms["'+this.nameOfForm+'"].getElementsByTagName("input");');

			var moFieldsLen=moFields.length;
			for (i=0; i<moFieldsLen; i++)
			{
				if (moFields[i].getAttribute("type").toLowerCase() == "checkbox")
				{
					onMO=moFields[i];
					onMO.onmouseover=this.change;
				}
			}
		}
	}

	this.change=function() { this.checked=(this.checked) ? false:true; }

	// By Peter Bailey, www.peterbailey.net
	// Slight modifications by Ryan Parman, www.skyzyx.com
	this.enableClickDrag=function(sameNameOnly)
	{
		// Abort if browser can't do script
		if (document.all && !document.attachEvent) return true;
		else if (!document.all && !document.addEventListener) return true;
		//else if (document.all && !document.addEventListener) return true; // For retarded-ass Opera 7...

		// Initialize Variables/properties
		var f=eval('document.forms["'+this.nameOfForm+'"]');
		var dragObj=this;
		this.checked=false;
		this.mousedown=false;
		this.validClick=false;
		this.same=Boolean( sameNameOnly );

		// Attach Events
		if ( document.attachEvent )
		{
			f.attachEvent( "onmousedown", function() { downHandler( event.srcElement, dragObj ) } );
			f.attachEvent( "onmouseover", function() { overHandler( event.srcElement, dragObj ) } );
			document.attachEvent( "onmouseup", function() { upHandler( event.srcElement, dragObj ) } );
		}
		else
		{
			f.addEventListener( "mousedown", function( e ) { downHandler( e.target, dragObj ) }, false );
			f.addEventListener( "mouseover", function( e ) { overHandler( e.target, dragObj ) }, false );
			document.addEventListener( "mouseup", function( e ) { upHandler( e.target, dragObj ) }, false );
		}

		// Handler for form.onMouseDown event
		function downHandler(elem, o)
		{
			if (elem.type=="checkbox")
			{
				o.validClick=true;
				o.firstCB=elem;
				o.mousedown=true;
				o.checked=!elem.checked
				if (o.same) o.name=elem.name;
			}
		}

		// Handler for document.onMouseUp event
		function upHandler(elem, o)
		{
			if (o.validClick && o.firstCB)
			{
				o.firstCB.checked=o.checked;
				o.mousedown=false;
				o.checked=!o.checked;
				o.validClick=false;
				if (elem===o.firstCB) elem.checked=o.checked;
			}
		}

		// Hanlder for form.onMouseOver event
		function overHandler(elem, o)
		{
			if (elem.type=="checkbox" && o.mousedown)
			{
				if (o.same && elem.name == o.name) elem.checked=o.checked;
				else if (!o.same) elem.checked=o.checked;
			}
		}
	}
}


var ckBox = new checkbox('deleta');

//-->