function isEmpty(text){
   var enter1 = "\n",
       enter2 = "\r",
       espaco = " ",
       tab = "\t";

   if (text =="") return true;
   if (text ==0) return true;

   //A verifica se o caracter selecionada possui valor vahlido
   for (var indice = 0; indice < text.length; indice++){
      if (text.charAt(indice) != espaco && 
         text.charAt(indice) != tab &&
         text.charAt(indice) != enter1 && 
         text.charAt(indice) != enter2 )
         return false;
   }
   return true;
}

// simple test for URL format
function testURL(Ctrl) {
	if (Ctrl.value == "" || Ctrl.value.indexOf("http://",0) == -1) {
		return (false);
	} else	{
		return (true);
	}
}

function checkUncheck(field, field2)
{
/*
The function is called in onclick
event, if checkbox was checked call
de function checkAll to checker all
checkox or if checkox was unchecked 
call the function uncheckAll to unchecker
all checkbox 
*/
  if (field.checked == 1){
    //checkAll(field2);


  for (var c = 0; c < nlt_vincular_contatos.elements.length; c++)
    if (nlt_vincular_contatos.elements[c].type == 'checkbox')
      nlt_vincular_contatos.elements[c].checked = true;



  }else{
    //uncheckAll(field2);
  for (var c = 0; c < nlt_vincular_contatos.elements.length; c++)
    if (nlt_vincular_contatos.elements[c].type == 'checkbox')
      nlt_vincular_contatos.elements[c].checked = false;


  }
}

function checkAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = true ;
}
function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = false ;
}
function testa_file()
{
alert("Clique no botão \"Procurar\" para informar o nome do arquivo.");
return false;
}
function quebra_frame()
{
  if (top.location != location) {
    top.location.href = document.location.href ;
  }
}
function mClk(src) {
	if(event.srcElement.tagName=='TD'){
	  src.children.tags('A')[0].click();
	}
}
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_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
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_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}
/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;


/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0) 
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // Garvin: deactivated onclick marking of the checkbox because it's also executed
            // when an action (like edit/delete) on a single item is performed. Then the checkbox
            // would get deactived, even though we need it activated. Maybe there is a way
            // to detect if the row was clicked, and not an item therein...
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function

function goToUrl(goToLocation){
    eval("document.location.href = '" + goToLocation + "'");
}

function pop_up(pagina,nome_pagina,largura,altura,rolagem) {
// Este script mostra um pop-up no meio da página do visitante  
  // Variaveis da página 
        
  var posLargura = (screen.width / 2) - (largura / 2); 
  var posAltura  = (screen.height / 2) - (altura / 2); 

  var propriedades = 'toolbar=no,';          // retira a barra de  
                                             //   trabalho 
  propriedades    += 'location=no,';         // retira a barra de 
                                             //   localização 
  propriedades    += 'directories=no,';      // retira a barra de  
                                             //   diretorios 
  propriedades    += 'status=no,';           // retira a barra de  
                                             //   status 
  propriedades    += 'menubar=no,';          // retira a barra de  
                                             //   menu 

if (rolagem == 0){
   propriedades    += 'scrollbars=no,';      // retira as barras  
                                             //   de rolagem 
}else{
   propriedades    += 'scrollbars=yes,';      // retira as barras  
                                             //   de rolagem 
}

  propriedades    += 'resizable=no,';        // retira a opção de  
                                             //   reescalagem da janela 
  propriedades    += 'width='+largura+',';   // largura da janela 
  propriedades    += 'height='+altura+',';   // altura da janela 
  propriedades    += 'left='+posLargura+','; // posição inicial  
                                             //   horizontal da janela 
  propriedades    += 'top='+posAltura;       // posição inicial  
                                             //   vertical da janela  
  window.open(pagina, nome_pagina, propriedades); 

}
function apenasValoresNumericos(caracter) {
	// Internet Explorer
	if(document.all){ 
		var tecla = event.keyCode;
	}else {
		if(document.layers) { // Nestcape
			var tecla = caracter.which;
		}
	}

	if(tecla > 47 && tecla < 58){ // numeros de 0 a 9
		return true;
	}else{
		if (tecla != 8){ // backspace
			return false;
		}else{
			return true;
		}
	}
}
function check_date(field){ 
	var checkstr = "0123456789"; 
	var DateField = field; 
	var Datevalue = ""; 
	var DateTemp = ""; 
	var seperator = "/"; 
	var day; 
	var month; 
	var year; 
	var leap = 0; 
	var err = 0; 
	var i; 
	err = 0; 
	DateValue = DateField.value; 
	/* Deleta todos os caracteres exceto 0..9 */ 
	for (i = 0; i < DateValue.length; i++) { 
		if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) { 
			DateTemp = DateTemp + DateValue.substr(i,1); 
		} 
	} 
	DateValue = DateTemp; 
	/* Sempre modifica a data para 8 digitos*/ 
	/* Se o ano for digitado com 2 digitos assume 20xx */ 
	if (DateValue.length == 6) { 
		DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); 
	} 
	if (DateValue.length != 8) { 
		err = 1;
	} 
	/* ano é considerado inválido se for = 0000 */ 
	year = DateValue.substr(4,4); 
	if (year == 0) { 
	err = 1; 
	} 
	/* Validação do Mês */ 
	month = DateValue.substr(2,2); 
	if ((month < 1) || (month > 12)) { 
	err = 1; 
	} 
	/* Validação do Dia */ 
	day = DateValue.substr(0,2); 
	if (day < 1) { 
	err = 1; 
	} 
	/* Validação do ano bissexto referente ao mês de fevereiro */ 
	if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) { 
	leap = 1; 
	} 
	if ((month == 2) && (leap == 1) && (day > 29)) { 
	err = 1; 
	} 
	if ((month == 2) && (leap != 1) && (day > 28)) { 
	err = 1; 
	} 
	/* Validação dos outros meses */ 
	if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) { 
	err = 1; 
	} 
	if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) { 
	err = 1; 
	} 
	/* Se não houver erro escreve a data completa no campo input com os separadores (ex. 07/01/2004) */ 
	if (err == 0) { 
	DateField.value = day + seperator + month + seperator + year; 
	} 
	/* Escreve mensagem de erro se err != 0 */ 
	else { 
		if (DateValue != ''){
			alert("Data Incorreta!!!"); 
			DateField.value = "";
			DateField.focus();
			return false;
		}
	} 
	return (true); 
} 
function envia_form_banner()
{

	if (isEmpty(document.banner.titulo.value)){
	   alert ("Campo Título deve ser preenchido");
	   document.banner.titulo.focus();
	   return false;
	}

	if (isEmpty(document.banner.endereco_site.value)){
	   alert ("Campo Site deve ser preenchido");
	   document.banner.endereco_site.focus();
	   return false;
	}

	if (!testURL(document.banner.endereco_site)){
	   alert ("Campo Site deve ser preenchido com um\nendereço válido iniciando com http://");
	   document.banner.endereco_site.focus();
	   return false;
	}

	if (isEmpty(document.banner.endereco_arquivo.value)){
	   alert ("Campo Arquivo deve ser preenchido");
	   document.banner.endereco_arquivo.focus();
	   return false;
	}

	document.banner.Salvar.disabled = "true";
	document.banner.Salvar.value = "Salvando os dados...";

	return true;
}

function envia_form_dica_categoria()
{

	if (isEmpty(document.dica_categoria.titulo.value)){
	   alert ("Campo Título deve ser preenchido");
	   document.dica_categoria.titulo.focus();
	   return false;
	}

	document.dica_categoria.Salvar.disabled = "true";
	document.dica_categoria.Salvar.value = "Salvando os dados...";

	return true;
}


function envia_form_gua_porte()
{

	if (isEmpty(document.gua_porte.titulo.value)){
	   alert ("Campo Título deve ser preenchido");
	   document.gua_porte.titulo.focus();
	   return false;
	}

	document.gua_porte.Salvar.disabled = "true";
	document.gua_porte.Salvar.value = "Salvando os dados...";

	return true;
}

function envia_form_gua_especie()
{

	if (isEmpty(document.gua_especie.titulo.value)){
	   alert ("Campo Título deve ser preenchido");
	   document.gua_especie.titulo.focus();
	   return false;
	}

	document.gua_especie.Salvar.disabled = "true";
	document.gua_especie.Salvar.value = "Salvando os dados...";

	return true;
}

function envia_form_gua_raca()
{

	if (document.gua_raca.id_gua_especie.selectedIndex == 0){
	   alert ("Campo Espécie deve ser preenchido");
	   document.gua_raca.id_gua_especie.focus();
	   return false;
	}

	if (isEmpty(document.gua_raca.titulo.value)){
	   alert ("Campo Título deve ser preenchido");
	   document.gua_raca.titulo.focus();
	   return false;
	}

	document.gua_raca.Salvar.disabled = "true";
	document.gua_raca.Salvar.value = "Salvando os dados...";

	return true;
}

function envia_form_dica()
{
	if (document.dica.id_dica_categoria.selectedIndex == 0){
	   alert ("Campo Categoria de Dicas deve ser preenchido");
	   document.dica.id_dica_categoria.focus();
	   return false;
	}
	if (isEmpty(document.dica.titulo.value)){
	   alert ("Campo Título deve ser preenchido");
	   document.dica.titulo.focus();
	   return false;
	}
	if (isEmpty(document.dica.resumo.value)){
	   alert ("Campo Resumo deve ser preenchido");
	   document.dica.resumo.focus();
	   return false;
	}

	return true;
}

function envia_form_noticia()
{

	if (isEmpty(document.noticia.dt_publicacao.value)){
	   alert ("Campo Data de Publicação deve ser preenchido");
	   document.noticia.dt_publicacao.focus();
	   return false;
	}

	check_date(document.noticia.dt_publicacao);

	if (isEmpty(document.noticia.titulo.value)){
	   alert ("Campo Título deve ser preenchido");
	   document.noticia.titulo.focus();
	   return false;
	}
	if (isEmpty(document.noticia.resumo.value)){
	   alert ("Campo Resumo deve ser preenchido");
	   document.noticia.resumo.focus();
	   return false;
	}
	
	return true;
}

function envia_form_historico()
{

	if (isEmpty(document.historico.dt_ocorrencia.value)){
	   alert ("Campo Data de Atendimento deve ser preenchido");
	   document.historico.dt_ocorrencia.focus();
	   return false;
	}

	check_date(document.historico.dt_ocorrencia);

	if (isEmpty(document.historico.local.value)){
	   alert ("Campo Local deve ser preenchido");
	   document.historico.local.focus();
	   return false;
	}
	if (isEmpty(document.historico.protetor.value)){
	   alert ("Campo Protetor deve ser preenchido");
	   document.historico.protetor.focus();
	   return false;
	}
	if (isEmpty(document.historico.descricao.value)){
	   alert ("Campo Descricao deve ser preenchido");
	   document.historico.descricao.focus();
	   return false;
	}
	
	return true;
}

function envia_form_site_conteudo()
{
	return true;
}

function envia_form_gua_contato()
{

	if (isEmpty(document.gua_contato.nome.value)){
	   alert ("Campo Nome deve ser preenchido");
	   document.gua_contato.nome.focus();
	   return false;
	}

	if (isEmpty(document.gua_contato.email.value)){
	   alert ("Campo E-mail deve ser preenchido");
	   document.gua_contato.email.focus();
	   return false;
	}

	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.gua_contato.email.value))){ 
	   alert ("Por favor, informe um E-mail válido");
	   document.gua_contato.email.focus();   
	   return false;
	}

	document.gua_contato.Salvar.disabled = "true";
	document.gua_contato.Salvar.value = "Salvando os dados...";

	return true;
}

function envia_form_gua_adocao()
{
	if (document.gua_adocao.id_gua_especie.selectedIndex == 0){
	   alert ("Campo Espécie deve ser preenchido");
	   document.gua_adocao.id_gua_especie.focus();
	   return false;
	}
	if (document.gua_adocao.id_gua_raca.selectedIndex == 0){
	   alert ("Campo Raça deve ser preenchido");
	   document.gua_adocao.id_gua_raca.focus();
	   return false;
	}
	if (document.gua_adocao.id_gua_contato_doador.selectedIndex == 0){
	   alert ("Campo Contato Doador deve ser preenchido");
	   document.gua_adocao.id_gua_contato_doador.focus();
	   return false;
	}

	return true;
}

function envia_form_login()
{

	if (isEmpty(document.login.email.value)){
	   alert ("Campo E-mail deve ser preenchido");
	   document.login.email.focus();
	   return false;
	}

	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.login.email.value))){ 
	   alert ("Por favor, informe um E-mail válido");
	   document.login.email.focus();   
	   return false;
	}

	if (isEmpty(document.login.senha.value)){
	   alert ("Campo Senha deve ser preenchido");
	   document.login.senha.focus();
	   return false;
	}

	document.login.Acessar.disabled = "true";
	document.login.Acessar.value = "Verificando login...";

	return true;
}

function envia_form_usuario()
{

	if (isEmpty(document.usuario.nome.value)){
	   alert ("Campo Nome deve ser preenchido");
	   document.usuario.nome.focus();
	   return false;
	}

	if (isEmpty(document.usuario.remetente_email.value)){
	   alert ("Campo E-mail deve ser preenchido");
	   document.usuario.remetente_email.focus();
	   return false;
	}

	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.usuario.remetente_email.value))){ 
	   alert ("Por favor, informe um E-mail válido");
	   document.usuario.remetente_email.focus();   
	   return false;
	}

	if (isEmpty(document.usuario.senha.value)){
	   alert ("Campo Senha deve ser preenchido");
	   document.usuario.senha.focus();
	   return false;
	}

	document.usuario.Salvar.disabled = "true";
	document.usuario.Salvar.value = "Salvando os dados...";

	return true;
}

function envia_form_newsletter()
{

	if (isEmpty(document.newsletter.remetente_nome.value)){
	   alert ("Campo Remetente - Nome deve ser preenchido");
	   document.newsletter.remetente_nome.focus();
	   return false;
	}

	if (isEmpty(document.newsletter.remetente_email.value)){
	   alert ("Campo Remetente - E-mail deve ser preenchido");
	   document.newsletter.remetente_email.focus();
	   return false;
	}

	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.newsletter.remetente_email.value))){ 
	   alert ("Por favor, informe um E-mail válido");
	   document.newsletter.remetente_email.focus();   
	   return false;
	}

	if (isEmpty(document.newsletter.assunto.value)){
	   alert ("Campo Assunto deve ser preenchido");
	   document.newsletter.assunto.focus();
	   return false;
	}

	return true;
}

function envia_newsletter_cadastro_site()
{

	if (isEmpty(document.newsletter.nome.value)){
	   alert ("Campo Nome deve ser preenchido");
	   document.newsletter.nome.focus();
	   return false;
	}

	if (isEmpty(document.newsletter.email.value)){
	   alert ("Campo E-mail deve ser preenchido");
	   document.newsletter.email.focus();
	   return false;
	}

	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.newsletter.email.value))){ 
	   alert ("Por favor, informe um E-mail válido");
	   document.newsletter.email.focus();   
	   return false;
	}

	document.newsletter.Enviar.disabled = "true";
	document.newsletter.Enviar.value = "Enviando os dados...";

	return true;
}


function envia_fale_conosco()
{

	if (isEmpty(document.fale_conosco.nome.value)){
	   alert ("Campo Nome deve ser preenchido");
	   document.fale_conosco.nome.focus();
	   return false;
	}

	if (isEmpty(document.fale_conosco.email.value)){
	   alert ("Campo E-mail deve ser preenchido");
	   document.fale_conosco.email.focus();
	   return false;
	}

	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.fale_conosco.email.value))){ 
	   alert ("Por favor, informe um E-mail válido");
	   document.fale_conosco.email.focus();   
	   return false;
	}

	if (isEmpty(document.fale_conosco.mensagem.value)){
	   alert ("Campo Mensagem deve ser preenchido");
	   document.fale_conosco.mensagem.focus();
	   return false;
	}

	document.fale_conosco.Enviar.disabled = "true";
	document.fale_conosco.Enviar.value = "Enviando os dados...";

	return true;
}
