//Copyright - 2000-2009 Alfredo J G A Borba. Todos os Direitos Reservados (www.webcalc.com.br)


//Mensagens de Erro
window.onerror = msgErro;

var msg_txt = "";
var msg_html = "";
function msgErro(msg, url, lnh) {	
	if ((navigator.userAgent.indexOf("MSIE")==-1 && navigator.userAgent.indexOf("Firefox")==-1) || (navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("MSIE 6")==-1 && navigator.userAgent.indexOf("MSIE 7")==-1)) {
		//Navegadores diferentes do Firefox e do IE6+ nao executam o codigo abaixo
	}
	else {	
		if (msg.indexOf("Error loading script")!=-1) {
			return true;
		}
		if (msg.indexOf("Syntax")!=-1 && (lnh=="2" || lnh=="3")) {
			return true;
		}
		if (msg.indexOf("sintaxe")!=-1 && (lnh=="2" || lnh=="3")) {
			return true;
		}
		if (msg.indexOf("Caractere")!=-1 && (lnh=="2" || lnh=="3")) {
			return true;
		}
		if (msg.indexOf("character")!=-1 && (lnh=="2" || lnh=="3")) {
			return true;
		}
	}
	
	var janURL = "";
	var jan_alt = 435;
	msg_html = "<p>Se os recursos do <b>WebCalc</b> n&atilde;o estiverem funcionando corretamente e/ou o problema persistir, entre em contato conosco, preenchendo o formul&aacute;rio abaixo e clicando no bot&atilde;o \"<strong>Enviar</strong>\".</p>";	
	if (msg.indexOf("obj_format")!=-1 || msg.indexOf("parent.frames")!=-1 || msg.indexOf("window.opener")!=-1) {	
		msg_html = "<p>O tipo de erro apresentado normalmente é eliminado recarregando-se a página (Clique no botão \"<strong>Atualizar</strong>\" do Navegador e aguarde a página recarregar). Persistindo o erro entre em contato conosco preenchendo o formul&aacute;rio abaixo e clicando no bot&atilde;o \"<b>Enviar</b>\".</p>";
		jan_alt = 465;	
	}	
	if (navigator.platform.indexOf("Win32")==-1) {	
		msg_html = "<p>As funcionalidades do WebCalc são plenamente suportadas pela Plataforma \"<strong>Windows</strong>\" (ME/NT/XP), outras Plataformas podem causar eventuais erros. Entre em contato conosco, se desejar, preenchendo o formul&aacute;rio abaixo e clicando no bot&atilde;o \"<b>Enviar</b>\".</p>";
		jan_alt = 450;	
	}
	if ((navigator.userAgent.indexOf("MSIE")==-1 && navigator.userAgent.indexOf("Firefox")==-1) || (navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("MSIE 6")==-1 && navigator.userAgent.indexOf("MSIE 7")==-1 && navigator.userAgent.indexOf("MSIE 8")==-1)) {	
		msg_html = "<p>As funcionalidades do WebCalc são plenamente suportadas pelos Navegadores \"<strong>Firefox</strong>\" e \"<strong>Internet Explorer (Versões 6 e superiores)</strong>\", outros Navegadores, ou Versões, podem causar eventuais erros. Entre em contato conosco, se desejar, preenchendo o formul&aacute;rio abaixo e clicando no bot&atilde;o \"<b>Enviar</b>\".</p>";
		jan_alt = 465;	
	}	
	
	msg_txt += "Informa" + unescape("\u00E7") + unescape("\u00F5") + "es t" + unescape("\u00E9") + "cnicas do erro:\n";
	msg_txt += msg+"\n\n";
	msg_txt += "Linha: "+lnh+"\n";
	msg_txt += "URL: "+url+"\n";	
	msg_txt += "Aplicativo: "+window.document.title+"\n";
	msg_txt += "topURL: "+top.window.location.href+"\n";
	msg_txt += "Navegador: "+navigator.appName+"\n";
	msg_txt += "Vers" + unescape("\u00E3") + "o: "+navigator.userAgent+"\n";
	msg_txt += "Idioma: "+navigator.systemLanguage+"\n";
	msg_txt += "Cookie: "+navigator.cookieEnabled+"\n";
	msg_txt += "Java: "+navigator.javaEnabled()+"\n";
	msg_txt += "Plataforma: "+navigator.platform+"\n\n";
	msg_txt += "Mensagem: "+msg_html+"\n\n";
	
	var pgURL = window.location.href;
	if (pgURL.indexOf("webcalc.com.br")!=-1) {
		janURL = "http://www.webcalc.com.br/ajuda/jan_erro.html";
	}
	else {
		if (window.location.protocol=="file:") {
			var idURL = pgURL.indexOf("wbc") + 4;
			janURL = pgURL.substring(0, idURL) + "ajuda/jan_erro.html";
		}
	}

	janErro = window.open(janURL,'Erro','toolbar=0,location=no,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=480,height='+jan_alt+',left=110,top=10');

	return true;	
}
//Fim de Mensagens de Erro


//Detecção do navegador
function Is() {
    var agent = navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.ns  = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1) && (agent.indexOf('firefox') == -1) && (agent.indexOf('chrome') == -1)));
    this.ns2 = (this.ns && (this.major == 3));
    this.ns3 = (this.ns && (this.major == 3));
    this.ns4 = (this.ns && (this.major >= 4));
    this.ns406 = (this.ns && (this.minor == 4.06));
    this.ns407 = (this.ns && (this.minor == 4.07));
    this.ns408 = (this.ns && (this.minor == 4.08));
    this.ns45 = (this.ns && (this.minor == 4.5));
    this.ns6 = (this.ns && (this.major >= 5));
    this.ie   = (agent.indexOf("msie") != -1 || agent.indexOf('firefox') != -1 || agent.indexOf('chrome') != -1);
    this.ie3  = (this.ie && (this.major == 2));
    this.ie4  = (this.ie && (this.major >= 4));    
	this.ie5  = (this.ie4 && (navigator.appVersion.indexOf('MSIE 4')==-1));
	this.ie6  = (this.ie5 && (navigator.appVersion.indexOf('MSIE 5')==-1));
	this.ie7  = (this.ie6 && (navigator.appVersion.indexOf('MSIE 6')==-1));
	this.ie8  = (this.ie7 && (navigator.appVersion.indexOf('MSIE 7')==-1));
    this.fox = (agent.indexOf("firefox") != -1 || agent.indexOf("chrome") != -1);
	this.chr = (agent.indexOf("chrome") != -1);
	this.op3 = (agent.indexOf("opera") != -1);
	this.mac = (navigator.appVersion.indexOf("Mac")!=-1);
}

var is = new Is()
//Fim da Detecção do navegador


//Desabilita uso de Paginas Fora do Frame
if(!parent.frames[0]){
	if ((!is.ns4 && !is.ie4) || is.mac) {
		self.location.href="http://www.webcalc.com.br"
	}
	else {	
	    if (top == self) {
	        location.replace("http://www.webcalc.com.br/frame.asp?pag="+self.location);
		}
		else {
			self.location.href="http://www.webcalc.com.br"
		}	
	}	
}
//Fim - Desabilita uso de Paginas...


//Cria Cookie
function setCookie(name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape(value) + 
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  ((path == null) ? "" : "; path=" + path) +
  ((domain == null) ? "" : "; domain=" + domain) +
  ((secure == null) ? "" : "; secure");
}
//Fim de Cria Cookie


// Recupera Cookie
function getCookie(name){
  var cname = name + "=";               
  var dc = document.cookie;             
  if (dc.length > 0) {              
    begin = dc.indexOf(cname);       
    if (begin != -1) {           
      begin += cname.length;       
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    } 
  }
  return null;
}
// Fim de Recupera Cookie


// Deleta Cookie
function delCookie (name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path == null) ? "" : "; path=" + path) +
    ((domain == null) ? "" : "; domain=" + domain) +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
// Fim de Deleta Cookie


//Abertura de Janela (Geral)	
function Janela(URL, nome, config) {
	popUpWin = window.open(URL, nome, config);
}
//Fim de Abertura de Janela (Geral)	


//Abertura das Janelas de Ajuda	
function janAjuda(url) {
	popUpWin = window.open(url,'ajuda','toolbar=0,location=no,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,width=570,height=450,left=30,top=10');
	popUpWin.focus();
}	
//Fim de Abertura das Janelas de Ajuda	


//Abertura da Janela de Aviso
function JanelaAviso(url) {
        popUpWin = window.open(url,'fotoWin','toolbar=0,location=no,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=400,height=150');
        if (navigator.appName == 'Netscape') {
                popUpWin.focus();
        }
}
//Fim da Abertura da Janela de Aviso


//Envio de E-mail
function Mail(m){
var end=m
if (end=="") {parent.location="mailto:info@webcalc.com.br?subject=WebCalc - Contato:"}
	
else if (end=="erros") {parent.location="mailto:info@webcalc.com.br?subject=WebCalc - Comunicado de Erro(s):"}
else {parent.location="mailto:"+end}
}

var loaded=false;
if (parent.idframe==-1 && parent.idframe2==-1) {
	loaded=true;
}

function wcalc1(){
	var dtv=parent.dtv
	var hoje=new Date()
	var val=dtv-hoje.getTime()
	
	if (val>0) {
		document.write("<hr><font style='color: #0000FF; font-size: 9pt; font-weight: bold;'><b><font size='3'>Aten&ccedil;&atilde;o Usu&aacute;rio</font>: Esta p&aacute;gina n&atilde;o foi aberta no servidor do <font size='3'>WebCalc</font> e pode, portanto, apresentar mensagens de erro e/ou falhas de exibi&ccedil;&atilde;o. Para acessar corretamente esta p&aacute;gina <a href='http://www.webcalc.com.br' target='_blank'>clique aqui</a></b></font><hr>");
		loaded=false
	}
	else
		 { document.write("<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><h3><hr>Aten&ccedil;&atilde;o Usu&aacute;rio:</h3><h5>N&atilde;o foi poss&iacute;vel estabelecer conex&atilde;o com o servidor.</h5><br><br><p>Para sanar o problema redirecione para <a href='http://www.webcalc.com.br' target='_blank'>www.webcalc.com.br</a></p><hr>");
		document.write("<!--");
		}
}


//Centraliza paginas no WebCalc - Painel
if(is.ie && !is.fox && (parent.window.document.title).indexOf("Painel")!=-1) {	
	document.onreadystatechange=centraliza;
}

function centraliza() {
	if (document.readyState=="complete") {		
		if ((document.title).indexOf("WebCalc Mapas")!=-1) {return false;}
		document.getElementsByTagName('table')[0].align = "center";
	}
}
//Fim de Centraliza paginas no WebCalc - Painel