function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
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_site_conteudo()
{
	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_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;
}

/* Validação Categoria - Produtos */
function envia_form_prod_categoria()
{

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

	if (isEmpty(document.prod_categoria.endereco_imagem_destaque.value)){
	   alert ("Campo Imagem Destaque deve ser preenchido");
	   document.prod_categoria.endereco_imagem_destaque.focus();
	   return false;
	}

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

	return true;
}

function insere_str_medida()
{
	if (document.prod_produto.str_medidas.selectedIndex != 0){
		if (isEmpty(document.prod_produto.medidas.value)){
			document.prod_produto.medidas.value = document.prod_produto.medidas.value + document.prod_produto.str_medidas.value;
		}else{
			document.prod_produto.medidas.value = document.prod_produto.medidas.value + "\n" + document.prod_produto.str_medidas.value;
		}
	}
}

/* Validação Produtos */
function envia_form_prod_produto()
{
	if (document.prod_produto.id_prod_categoria.selectedIndex == 0){
	   alert ("Campo Categoria deve ser preenchido");
	   document.prod_produto.id_prod_categoria.focus();
	   return false;
	}

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

	if (isEmpty(document.prod_produto.referencia.value)){
	   alert ("Campo Referência deve ser preenchido");
	   document.prod_produto.referencia.focus();
	   return false;
	}

	/* Campos para maiusculo */
	document.prod_produto.nome.value = document.prod_produto.nome.value.toUpperCase();
	document.prod_produto.referencia.value = document.prod_produto.referencia.value.toUpperCase();
	document.prod_produto.medidas.value = document.prod_produto.medidas.value.toUpperCase();

	return true;
}

// Troca Imagem Produto Destaque
function trocaImagemProdDestaque(novaImagem, novaLargura, novaAltura)
{
	document.produto_destaque.src = '_imagens/transparent.gif';
	document.produto_destaque.height = novaAltura;
	document.produto_destaque.width = novaLargura;
	document.produto_destaque.src = novaImagem;
}

/* Validação da Busca Rápida dos Produtos */
function envia_form_produtos_busca_rapida()
{
	if (isEmpty(document.produtos_busca_rapida.referencia.value) && isEmpty(document.produtos_busca_rapida.descricao.value)){
	   alert ("Por favor, informe a Referência ou Descrição\n para executar a busca.");
	   document.produtos_busca_rapida.referencia.focus();
	   return false;
	}

	document.produtos_busca_rapida.Buscar.disabled = "true";
	document.produtos_busca_rapida.Buscar.value = "Buscando...";

	return true;
}

function envia_form_webmail()
{
	if (document.webmail.webmail_usuario.value == 'E-mail' || document.webmail.webmail_senha.value == 'Senha'){
	   alert ("Informe o Usuário e Senha para acessar o webmail");
	   document.webmail.webmail_usuario.focus();
	   return false;
	}
	if (isEmpty(document.webmail.webmail_usuario.value)){
	   alert ("Informe o Usuário");
	   document.webmail.webmail_usuario.focus();
	   return false;
	}
	if (isEmpty(document.webmail.webmail_senha.value)){
	   alert ("Informe Senha");
	   document.webmail.webmail_senha.focus();
	   return false;
	}

	document.webmail.userid.value = document.webmail.webmail_usuario.value;
    document.webmail.password.value = document.webmail.webmail_senha.value; 

	return true;
}

function envia_form_mail_marketing_bi()
{
	if (isEmpty(document.mail_marketing_bi.destinatario.value)){
	   alert ("Informe o(s) destinatário(s)");
	   document.mail_marketing_bi.destinatario.focus();
	   return false;
	}
	if (isEmpty(document.mail_marketing_bi.assunto.value)){
	   alert ("Informe o assunto");
	   document.mail_marketing_bi.assunto.focus();
	   return false;
	}

	document.mail_marketing_bi.Enviar.disabled = "true";
	document.mail_marketing_bi.Enviar.value = "Enviado...";

	return true;
}
