// JavaScript Document

function pegaEnter(event){
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if (keyCode == 13){
       return false;
    }
}

//cria objeto para o ajaxa
function CriaObjetoXmlHttp(){
        var ObjetoXmlHttp
        try{
            ObjetoXmlHttp = new XMLHttpRequest();
        }
        catch(ee){
                try{
                    ObjetoXmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch(e){
                        try{
                           oObjetoXmlHttp = new ActiveXObject(" Microsoft.XMLHTTP");
                        }
                        catch(E){
                            ObjetoXmlHttp = false;
                        }
                }
        }
        return ObjetoXmlHttp
}
// ajax
function Ajax(url,destino_retorno,metodo)
	{
	xmlHttp=CriaObjetoXmlHttp()
		if (xmlHttp==null)
	{
		alert("Desculpe, seu navegador não suporta a tecnologia usada!");
		return
	}
	xmlHttp.open(metodo,url,true);
	xmlHttp.onreadystatechange=function (){
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
		document.getElementById(destino_retorno).innerHTML=xmlHttp.responseText 
		} 
	}
	xmlHttp.send(null);
}

function enquetevota(){
marcado = -1
	for (i=0; i<document.frmEnquete.rblenqueteResposta.length; i++) {
		if (document.frmEnquete.rblenqueteResposta[i].checked) {
			marcado = i;
			resposta = document.frmEnquete.rblenqueteResposta[i].value;
		}
	}

        Ajax('enquete_vota.aspx?idResposta='+resposta,'SubContent','GET')
return false;
}
function enquetevotaVersaGeral(){
marcado = -1
	for (i=0; i<document.getElementById("rblenqueteResposta").length; i++) {
		if (document.getElementById("rblenqueteResposta")[i].checked) {
			marcado = i;
			resposta = document.getElementById("rblenqueteResposta")[i].value;
		}
	}
	alert(resposta);
	return false;
        Ajax('enquete_vota.aspx?idResposta='+resposta,'SubContent','GET')
return false;
}

function AbreEnquete(id){
    window.open('../enquete/enquete.aspx?idEnquete='+id , 'enquete' , 'width=260,height=265');

}
function SelecionaArea(){
    var urlarea = location.href;
    var varCorTitulo = "", varTxtTitulo = "";
    
    if(urlarea.indexOf('/servicos/')>0){
        document.getElementById('MainArea').className='Servicos';
        document.getElementById('MenuServicos').className='selected';
        varCorTitulo = "0xA3A300";
        varTxtTitulo = "SERVI&Ccedil;OS";
    }
     if(urlarea.indexOf('/solucoes/')>0){
        document.getElementById('MainArea').className='Solucoes';
        document.getElementById('MenuSolucoes').className='selected';
        varCorTitulo = "0x006600";
        varTxtTitulo = "SOLU&Ccedil;&Otilde;ES";
    }
       if(urlarea.indexOf('/versa/')>0){
       document.getElementById('MainArea').className='Versa';
       document.getElementById('MenuVersa').className='selected';
        varCorTitulo = "0x990000";
       varTxtTitulo = "VERSA";

    }
        if(urlarea.indexOf('/busca/')>0){
       document.getElementById('MainArea').className='Versa';
      // document.getElementById('MenuVersa').className='selected';
      varCorTitulo = "0x990000";
       varTxtTitulo = "BUSCA";
    }
          if(urlarea.indexOf('/produtos/')>0){
       document.getElementById('MainArea').className='Produtos';
       document.getElementById('MenuProdutos').className='selected';
       varCorTitulo = "0x006699";
       varTxtTitulo = "PRODUTOS";
    }
            if(urlarea.indexOf('/clientes/')>0){
       document.getElementById('MainArea').className='Clientes';
       document.getElementById('MenuClientes').className='selected';
        varCorTitulo = "0xA30A00";
       varTxtTitulo = "CLIENTES";
    }
             if(urlarea.indexOf('/pirataria/')>0){
       document.getElementById('MainArea').className='Pirataria';
        //document.getElementById('MenuClientes').className='selected';
      varCorTitulo = "0x507A8E";
      varTxtTitulo = "PIRATARIA";
    }
           if(urlarea.indexOf('/parceiros/')>0){
       document.getElementById('MainArea').className='Parceiros';
       document.getElementById('MenuParceiros').className='selected';
       varCorTitulo = "0x006600";
       varTxtTitulo = "PARCEIROS";
    }
           if(urlarea.indexOf('/noticias/')>0){
       document.getElementById('MainArea').className='Noticias';
       document.getElementById('MenuNoticias').className='selected';
       varCorTitulo = "0x5D2B4E";
       varTxtTitulo = "NOT&Iacute;CIAS";
    }
       if(urlarea.indexOf('/mapa/')>0){
       document.getElementById('MainArea').className='Mapa';
      // document.getElementById('MenuNoticias').className='selected';
      varCorTitulo = "0x990000";
      varTxtTitulo = "MAPA DO SITE";
      
    }
    if(urlarea.indexOf('/trabalhe_conosco/')>0){
      document.getElementById('MainArea').className='Trabalhe';
        //document.getElementById('MenuNoticias').className='selected';
      varCorTitulo = "0xA3A300";
        varTxtTitulo = "TRABALHE CONOSCO";
    }
      if(urlarea.indexOf('/contato/')>0){
      document.getElementById('MainArea').className='Contato';
         //document.getElementById('MenuNoticias').className='selected';
           varCorTitulo = "0xA30A00";
        varTxtTitulo = "CONTATO";
        
    }
    if(urlarea.indexOf('/canais/')>0){
        document.getElementById('MainArea').className='Canais';
        document.getElementById('MenuCanais').className='selected';
        varCorTitulo = "0x006699";
        varTxtTitulo = "CANAIS";
    }
     if(urlarea.indexOf('/indique/')>0){
        document.getElementById('MainArea').className='Indique';
      //  document.getElementById('MenuNoticias').className='selected';
      
        varCorTitulo = "0x006600";
       varTxtTitulo = "INDIQUE";
    }
     if(urlarea.indexOf('/area_cliente/')>0){
       document.getElementById('MainArea').className='AreaCliente';
       varCorTitulo = "0x006699";
       varTxtTitulo = "&Aacute;REA DO CLIENTE";
    }	
    

    objSWFTitulo = "";
    objSWFTitulo += "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\"";
    objSWFTitulo += " codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\"";
    objSWFTitulo += " id=\"titulo\" align=\"middle\" height=\"21\" width=\"200\"><param name=\"allowScriptAccess\"";
    objSWFTitulo += " value=\"sameDomain\"><param name=\"movie\" value=\"../../include_global/swf/titulo.swf\">";
    objSWFTitulo += " <param name=\"flashVars\" value=\"corSec="+ varCorTitulo +"&amp;textSec="+ varTxtTitulo +"\"><param name=\"quality\" value=\"high\">";
    objSWFTitulo += " <param name=\"bgcolor\" value=\"#ffffff\">";
    objSWFTitulo += " <embed src=\"../../include_global/swf/titulo.swf\" flashvars=\"corSec="+ varCorTitulo +"&amp;textSec="+ varTxtTitulo +"\" quality=\"high\"";
    objSWFTitulo += " bgcolor=\"#ffffff\" name=\"titulo\" allowscriptaccess=\"sameDomain\" type=\"application/x-shockwave-flash\"";
    objSWFTitulo += " pluginspage=\"http://www.macromedia.com/go/getflashplayer\" align=\"middle\" height=\"21\" width=\"200\"></object>";
  
    document.getElementById('divTituloswf').innerHTML = objSWFTitulo;

}
function DeletaUsuarioAdm(acao,nome){
    if(confirm('Tem certeza que deseja excluir o usuario '+ nome)){
        document.location='administrador.aspx?acao='+acao+'&nome='+nome;
    }
}
function SeleciouImagem(idImagem,NomeImagem){
window.opener.ctl00_ContentPlaceHolder_admin_txtNomeProduto.value=idImagem;

}
function abrepopupImagem(){
var width = 560;
var height = 360;

var left = 99;
var top = 99;

window.open("imagem.aspx",'teste1', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');

}
function VerImagem(idImagem){
var width = 300;
var height = 300;

var left = 99;
var top = 99;
window.open("mostraimagem.aspx?imagem="+idImagem,'teste1', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
}
function FazBusca(){
    if(document.getElementById("ctl00_txtBusca").value.length < 3){
        alert("Digite pelo menos 3 letras para efetuar a busca!");
        document.getElementById("ctl00_txtBusca").focus();
    }else{
        document.location = '../busca/?txtbusca='+ document.getElementById("ctl00_txtBusca").value;
    }
}
function salvar(arquivo){
window.open("download.aspx?arquivo="+arquivo,null, "height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");
}
 function abreimgTamanhoNatural(caminho){
 window.open('mostrarimagem.aspx?caminho='+caminho,null,"height=200,width=0,status=yes,toolbar=no,menubar=no,location=no");

 }

function jogaEvento(){
    document.getElementById("campoBusca").innerHTML="<input name=\"ctl00$txtBusca\" type=\"text\" id=\"ctl00_txtBusca\" class=\"txtBusca\" OnKeyPress=\"pegaEnter(event);\"/>";
    //alert('opa');
    //document.getElementById("ctl00_txtBusca").OnKeyPress = 'pegaEnter(event);';
    //alert(document.getElementById("ctl00_txtBusca").OnKeyPress );
}

var arrSocio = new Array(0);
var arrCpf = new Array(0);
var arrSocioValue = new Array(0);
var arrCpfValue = new Array(0);

function IncluirImput() {
   
    arrSocio.push(arrSocio.length);
    arrCpf.push(arrSocio.length);
    //arrInputValue.push(arrInputValue.length);
    arrSocioValue.push("");
    arrCpfValue.push("");
    document.getElementById('hndTotal').value = (parseInt(document.getElementById('hndTotal').value)+1);        
    Exibe();
   
}

function Exibe() {
  document.getElementById('txtSocios').innerHTML="";
  for (intI=0;intI<arrSocio.length;intI++) {
    document.getElementById('txtSocios').innerHTML+=CriaInput(arrSocio[intI], arrSocioValue[intI],arrCpfValue[intI]);  
  }
}

function SalvaValor(intId,strValue,tipo) {
  if(tipo == 1){
    arrSocioValue[intId]=strValue;
  }
  else{
    arrCpfValue[intId]=strValue;
  }
}  

function CriaInput(id,value,ordem) {
 
  return "\n<br /> S&oacute;cios:<br />    <input class='campoContatoNovo' type='text' maxlength='150' name='txtSocio"+id+"'  id='txtSocio"+(parseInt(id))+"' onChange='javascript:SalvaValor("+id+",this.value,1)' value='"+ value +"' srtyle='width: 120px;' />\n<br />Cpf:<br /> <input type='text'  class='campoContatoNovo' size='15' maxlength='14' name='txtCpf"+id+"' id='txtCpf"+(parseInt(id))+"' value='"+ ordem +"' onChange='javascript:SalvaValor("+id+",this.value,2)' onkeypress=\"return mask(true, event, this, '###.###.###-##');\" />\n";
  
}

function ExcluirImput(){
  
  if (arrSocio.length > 1) { 
     if (arrSocio.length > 0){ 
         arrSocio.pop(); 
         arrCpf.pop(); 
         arrSocioValue.pop();
         arrCpfValue.pop();
    }
  
  document.getElementById('hndTotal').value = (parseInt(document.getElementById('hndTotal').value)-1);
  Exibe();  
  
  }
  
}
 
 
 //Mascara
//usar assim  
// onkeypress="return mask(true, event, this, '####-#');"
 
// Formata o campo valor
function formataValor(campo) {
	campo.value = filtraCampo(campo);
	vr = campo.value;
	tam = vr.length;

	if ( tam <= 2 ){ 
 		campo.value = vr ; }
 	if ( (tam > 2) && (tam <= 5) ){
 		campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
 	if ( (tam >= 6) && (tam <= 8) ){
 		campo.value = vr.substr( 0, tam - 5 ) + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
 	if ( (tam >= 9) && (tam <= 11) ){
 		campo.value = vr.substr( 0, tam - 8 ) + vr.substr( tam - 8, 3 ) + vr.substr( tam - 5, 3 ) + ',' +  vr.substr( tam - 2, tam ) ; }
 	if ( (tam >= 12) && (tam <= 14) ){
 		campo.value = vr.substr( 0, tam - 11 ) + vr.substr( tam - 11, 3 ) + vr.substr( tam - 8, 3 ) + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
 	if ( (tam >= 15) && (tam <= 18) ){
 		campo.value = vr.substr( 0, tam - 14 ) + vr.substr( tam - 14, 3 ) + vr.substr( tam - 11, 3 ) + vr.substr( tam - 8, 3 ) + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
 		
}
// limpa todos os caracteres especiais do campo solicitado
function filtraCampo(campo){
	var s = "";
	var cp = "";
	vr = campo.value;
	tam = vr.length;
	for (i = 0; i < tam ; i++) {  
		if (vr.substring(i,i + 1) != "/" && vr.substring(i,i + 1) != "-" && vr.substring(i,i + 1) != "."  && vr.substring(i,i + 1) != "," ){
		 	s = s + vr.substring(i,i + 1);}
	}
	campo.value = s;
	return cp = campo.value
}

function mask(isNum, event, field, mask, maxLength) {

	var keyCode;
	if (event.srcElement)
		keyCode = event.keyCode;
	else if (event.target)
		keyCode = event.which;
		
	var maskStack = new Array();
		
	var isDynMask = false;
	if (mask.indexOf('[') != -1)
		isDynMask = true;
				
	var length = mask.length;
	
	for (var i = 0; i < length; i++)
		maskStack.push(mask.charAt(i));
		
	var value = field.value;
	var i = value.length;
	
	if (keyCode == 0 || keyCode == 8)
		return true;

	//código adaptado para aceitar X (maiúsculo) ou x (minúsculo), além de números
	if (isNum && (keyCode < 48 || keyCode > 57) && (keyCode != 88) && (keyCode != 120))
		return false;
	
	if (!isDynMask && i < length) {
		
		if (maskStack.toString().indexOf(String.fromCharCode(keyCode)) != -1 && keyCode != 8) {
			return false;
		} else {
			if (keyCode != 8) {
				if (maskStack[i] != '#') {
					var old = field.value;
					field.value = old + maskStack[i];
				}			
			}
			
//			if (autoTab(field, keyCode, length)) {
//				if (!document.layers) {
//					return true;
//				} else if (keyCode != 8) {
//					field.value += String.fromCharCode(keyCode);
//					return false;
//				} else {
//					return true;
//				}
//			} else {
//				return false;
//			}				
		}
		
	} else if (isDynMask) { 
							
		var maskChars = "";
		for (var j = 0; j < maskStack.length; j++)
			if (maskStack[j] != '#' && maskStack[j] != '[' && maskStack[j] != ']')
				maskChars += maskStack[j];

		var tempValue = "";
		for (var j = 0; j < value.length; j++) {
			if (maskChars.indexOf(value.charAt(j)) == -1)
				tempValue += value.charAt(j);
		}
		
		value = tempValue + String.fromCharCode(keyCode);
						
		if (maskChars.indexOf(String.fromCharCode(keyCode)) != -1) {
			return false;
		} else {
		
			var staticMask = mask.substring(mask.indexOf(']') + 1);
			var dynMask = mask.substring(mask.indexOf('[') + 1, mask.indexOf(']'));
		
			var realMask = new Array;
		
			if (mask.indexOf('[') == 0) {
				var countStaticMask = staticMask.length - 1;
				var countDynMask = dynMask.length - 1;
				for (var j = value.length - 1; j >= 0; j--) {
					if (countStaticMask >= 0) {
						realMask.push(staticMask.charAt(countStaticMask));
						countStaticMask--; 
					} 
					if (countStaticMask < 0) {
						if (countDynMask >= 0) {
							if (dynMask.charAt(countDynMask) != '#') {
								realMask.push(dynMask.charAt(countDynMask));
								countDynMask--;
							}
						}
						if (countDynMask == -1) {
							countDynMask = dynMask.length - 1;
						}
						realMask.push(dynMask.charAt(countDynMask));
						countDynMask--; 
					}
				}
			}
			
			var result = "";
				
			var countValue = 0;
			while (realMask.length > 0) {
				var c = realMask.pop();	
				if (c == '#') {
					result += value.charAt(countValue);
					countValue++;	
				} else {
					result += c;
				}
			}
			
			field.value = result;
		
			if (maxLength != undefined &&  value.length == maxLength) {
				
				var form = field.form;
				for (var i = 0; i < form.elements.length; i++) {
					if (form.elements[i] == field) {
						field.blur();
						//if alterado para quando a máscara for utilizada no último campo, não dê mensagem de erro quando tentar colocar o foco no "Salvar"
						//if (form.elements[i + 1] != null)										 
						if ((form.elements[i + 1] != null) && (form.elements[i + 1].name != "METHOD"))
							form.elements[i + 1].focus();
						break;
					}
				}
			}
			
			return false;
		}
	} else {
		return false;
	}
	function autoTab(field, keyCode, length) {
		var i = field.value.length;
			
		if (i == length - 1) {
		
			field.value += String.fromCharCode(keyCode);
		
			var form = field.form;
			for (var i = 0; i < form.elements.length; i++) {
				if (form.elements[i] == field) {
					field.blur();										 
					//if alterado para quando a máscara for utilizada no último campo, não dê mensagem de erro quando tentar colocar o foco no "Salvar"
					//if (form.elements[i + 1] != null)
					if ((form.elements[i + 1] != null) && (form.elements[i + 1].name != "METHOD"))
						form.elements[i + 1].focus();
					break;
				}
			}
			
			return false;
		} else {
			return true;
		}	
	}
}
