﻿var evento = null;
var ie = /msie/i.test(navigator.userAgent)
var ieBox = ie && (document.compatMode == null || document.compatMode == "BackCompat");
	
	function Trim(str){return str.replace(/^\s+|\s+$/g,"");}

	function ValidaEmail(str) {
		var at = "@";
		var dot = ".";
		var lat = str.indexOf(at);
		var lstr = str.length;
		var ldot = str.indexOf(dot);

		if (str.indexOf(at)==-1){
		   	return false;
		}else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			return false;
		}else if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			return false;
		}else if (str.indexOf(at,(lat+1))!=-1){
			return false;
		}else if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			return false;
		}else if (str.indexOf(dot,(lat+2))==-1){
			return false;
		}else if (str.indexOf(" ")!=-1){
			return false;
		}
 		return true;
	}

	function formCheckPedido() {
      if (Trim(document.contato.Nome.value) == "") {
         alert("Por favor coloque o nome da pessoa de contato.");
         return false;
      } else if (Trim(document.contato.Email.value) == "" || ValidaEmail(document.contato.Email.value) == false) {
         alert("O seu e-mail está incorreto. O formato deve ser 'seu_login@provedor.com.br'");
         return false;
      } else if (document.contato.Telefone1.value == "") {
         alert("Por favor preencha corretamente o seu telefone de contato.");
         return false;
      }
   }

   function formCheckSuporte() {
      if(Trim(document.contato.Nome.value) == "") {
         alert("Por favor coloque o nome do adquirinte da licença do ProDent.");
         return false;
      }else if (document.contato.Nome_Pessoa_Contato.value == "") {
         alert("Por favor coloque o nome da pessoa para contato.");
         return false;
      }else if (ValidaEmail(document.contato.Email.value) == false || Trim(document.contato.Email.value) == "") {
         alert("O seu e-mail está incorreto. O formato deve ser 'seu_login@provedor.com.br'");
         return false;
      } else if (Trim(document.contato.Telefone1.value) == "") {
         alert("Por favor preencha corretamente o seu telefone de contato.");
         return false;
      } else if (Trim(document.contato.Numero_Serie.value) == ""){
         alert("Por favor preencha o número de série da licença do ProDent.");
         return false;
      }else if (Trim(document.contato.Comentario.value) == "") {
         alert("Por favor descreva detalhadamente suas dúvidas, problemas ou sugestões.");
         return false;
      }

   }

function formCheckInfo() {
      if (Trim(document.contato.Nome.value) == "") {
         alert("Por favor coloque o nome da pessoa de contato.");
         return false;
      } else if (ValidaEmail(document.contato.Email.value) == false || Trim(document.contato.Email.value) == "") {
         alert("O seu e-mail está incorreto. O formato deve ser 'seu_login@provedor.com.br'");
         return false;
      } else if (Trim(document.contato.Telefone1.value) == "") {
         alert("Por favor preencha corretamente o seu telefone de contato.");
         return false;
      }
}

//temp news 37
function enviaNumPC(){
	var messageID = QueryString("messageID");
	var xcli = QueryString("xcli");
	var num = document.getElementById('numPC').value;

	if(messageID == "" || messageID == undefined || messageID == null || messageID == "undefined"){
		alert('Você não está autorizado a participar desta pesquisa!');	
		return;
	}else if(isNaN(num) == true || num == ""){
		alert('Informe um número válido!');	
		return;
	}else if(isNaN(xcli) == true || xcli == ""){
		alert('Você não está autorizado a participar desta pesquisa!');	
		return;
	}else if(parseFloat(num) > 50){
		alert("O número máximo de computadores é de 50!");	
		return;
	}else if(parseFloat(num) <= 0){
		alert('Informe um número válido!');	
		return;
	}
	carrega('news37/tabela.asp?numPC='+ document.getElementById('numPC').value+'&messageID='+messageID+'&xcli='+xcli, 'divNumPC');
}

function carrega(pagina, idDiv, assincrono, mostraCarregando){
   var xmlhttp = null;
   try{
       xmlhttp = new XMLHttpRequest();
   }catch(ee){
       try{
           xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
       }catch(e){
           try{
               xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
           }catch(E){
               xmlhttp = false;
           }
       }
   }

	if (assincrono == undefined) {
		assincrono = false;
	}
	
	if (mostraCarregando == undefined) {
		mostraCarregando = true;
   }
	
	if(pagina=='')
		return;
	
    var conteudo=document.getElementById(idDiv);

	if(!conteudo)
		return;
	
    if(mostraCarregando){
      window.status = "Carregando..."
	  var conteudoCarregando = "<span class=TextoTahoma12px><strong>Carregando..</strong></span>";
      conteudo.innerHTML=conteudoCarregando;
    }

    xmlhttp.open("GET", pagina, assincrono);
	xmlhttp.setRequestHeader('Content-Type','text/xml');
	xmlhttp.setRequestHeader('encoding','ISO-8859-1');

	if(assincrono){
		xmlhttp.onreadystatechange=function() {

			if (xmlhttp.readyState==4){
				
				if (xmlhttp.status==200){
					var texto=xmlhttp.responseText;

					if(texto=='')
						return;

					insereHTML(idDiv, texto);
					xmlhttp.send(null);
					return;
				}else{
				   return;
				}
			}
		}
    
	}else{
		xmlhttp.send(null);
	   
	   if(mostraCarregando){
      		window.status = "Carregando...";
      		conteudo.innerHTML='<span class="TextoTahoma12px"><strong>Carregando..</strong></span>';
	   }

	   if(xmlhttp.status != 200){
	      carrega('404.html', idDiv);
	   }else{
	      var texto=xmlhttp.responseText;
	      insereHTML(idDiv, texto);
	   }
	}
	window.status = "ProDent® - Software de Apoio à Odontologia";
	xmlhttp = null;
}

function insereHTML(idDiv, html){
	//html=html.replace(/\+/g," ");
	html=unescape(html);
	var conteudo=document.getElementById(idDiv);
	conteudo.innerHTML=html;
	ExtraiScript(html);
}

function initPrincipal(parametros){
   carrega('principalPD.html','principalPD');
   var paginaEnd = "";
   var showMenu = "";
   var variaveis = parametros.replace(/\x3F/,"").replace(/\x2B/g," ").split("&");

   if(variaveis != ""){
      
       for(i=0; i < variaveis.length; i++){
           var valores = variaveis[i].split("=");
            if(valores[0] == "redirect"){
               paginaEnd = unescape(valores[1]);
            }else if(valores[0] == "showmnPD"){
               showMenu = unescape(valores[1]);
            }
       }
   }
   
   if(paginaEnd != ""){
      carrega(paginaEnd, 'principal');
		if(showMenu == "off"){
		   carregaMenu(false, false);
	   }else{
	      carregaMenu(true, false);
	   }

		return true;
	}
   carrega('principal.html','principal');
   return true;
}

function setTitulo(html){
	var titulo = document.getElementById('tituloPagina');
	
	if(titulo==null)
		return;
	
	//html=html.replace(/\+/g," ");
	html=unescape(html);
	titulo.innerHTML= "<div class='TituloPrincipal' align='center'>" + html + "</div>";
	ExtraiScript(html);
}

function ExtraiScript(texto){
//desenvolvido por Skywalker.to, Micox e Pita.
//Não retire para não violar os direitos autorais.
    var ini, pos_src, fim, codigo;
    var objScript = null;
    ini = texto.indexOf('<script', 0);
    while (ini!=-1){
        objScript = document.createElement("script");
        //Busca se tem algum src a partir do inicio do script
        pos_src = texto.indexOf(' src', ini);
        ini = texto.indexOf('>', ini) + 1;

        //Verifica se este e um bloco de script ou include para um arquivo de scripts
        if (pos_src < ini && pos_src >=0){//Se encontrou um "src" dentro da tag script, esta e um include de um arquivo script
            //Marca como sendo o inicio do nome do arquivo para depois do src
            ini = pos_src + 4;
            //Procura pelo ponto do nome da extencao do arquivo e marca para depois dele
            fim = texto.indexOf('.', ini)+4;
            //Pega o nome do arquivo
            codigo = texto.substring(ini,fim);
            //Elimina do nome do arquivo os caracteres que possam ter sido pegos por engano
            codigo = codigo.replace("=","").replace(" ","").replace("\"","").replace("\"","").replace("\'","").replace("\'","").replace(">","");
            // Adiciona o arquivo de script ao objeto que sera adicionado ao documento
            objScript.src = codigo;
        }else{//Se nao encontrou um "src" dentro da tag script, esta e um bloco de codigo script
            // Procura o final do script
            fim = texto.indexOf('</script>', ini);
            // Extrai apenas o script
            codigo = texto.substring(ini,fim);
            // Adiciona o bloco de script ao objeto que sera adicionado ao documento
            objScript.text = codigo;
        }
        //Adiciona o script ao documento.
		if(document.getElementsByTagName("head")){
			document.getElementsByTagName("head").item(0).appendChild(objScript);
		}
        document.body.appendChild(objScript);
        // Procura a proxima tag de <script
        ini = texto.indexOf('<script', fim);

        //Limpa o objeto de script
        objScript = null;
    }
}

function carregaMenu(carregar, carregarPrincipal){
	if(carregarPrincipal == undefined){carregarPrincipal = true;}
	
	if(carregar == true){
		document.getElementById('menu').style.visibility='visible';
		carrega('menu.html','menu');
		
		if(carregarPrincipal)
		   carrega('comparacao.html','principal');
	}else{
		document.getElementById('menu').style.visibility='hidden';
	}
}

function verificaResolucao(){

	if (screen.width<=800){
		document.getElementById('apDiv2').style.left='55%';

		if(screen.width<800){
			alert ("A sua resolução parece ser muito baixa! Para uma melhor visualização do site, aconselhamos no mínimo 800x600!");
		}
	}
}

function overMenu(objeto){
	if(objeto)
		objeto.className='MenuOver';
}

function outMenu(objeto){
	if(objeto)
		objeto.className='Menu';
}

function fecharDiv(id){
	document.getElementById(id).style.visibility='hidden';
}

function suporte(id){
	carrega('menu_suporte.html', 'principal');
	document.getElementById(id).style.visibility='hidden';
}

function abrePOPUP(URL, largura, altura){
	if(largura == undefined)
		largura = 520;

	if(altura == undefined)
		altura = 500;

	window.open(URL,"", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=" + largura + ", height=" + altura);
}

function viewInfo(pagina){
   if(pagina == ""){
      alert('Desculpe, este recurso não tem uma explicação mais detalhada');
      return;
   }
	window.open('principalPD.html?'+pagina,"", "status=0, toolbar=0, location=0, menubar=0, directories=0, resizable=0, scrollbars=1, width=580, height=450");
}

function retornaPagina(variavel, pos){
	if(pos == undefined)
		pos = 0;

	var variaveis = variavel.replace(/\x3F/,"").replace(/\x2B/g," ").split("&");

	if(variaveis != ""){
		return unescape(variaveis[pos]);
	}else{
		return "";
	}
}

var qs=new Array()
var variaveis = location.search.replace(/\x3F/,"").replace(/\x2B/g," ").split("&")

if(variaveis!=""){
	for(i=0;i<variaveis.length;i++){
		nvar=variaveis[i].split("=")
		qs[nvar[0]]=unescape(nvar[1])
	}
}

function QueryString(variavel){
	return qs[variavel]
}

if(document.getElementsByTagName("head")){
   var icon = document.createElement("link");
   icon.setAttribute("rel", "shortcut icon");
   icon.setAttribute("href", "favicon.ico");
   document.getElementsByTagName("head").item(0).appendChild(icon);
}