function roll(para,nome){
	if(nome){
		document.getElementById(nome).src = para;
	}
}

function preroll(pendente,carregada,nome){
	if(nome){
		//alert(document.getElementById(nome).src);
		/*if(document.getElementById(nome).src == carregada){*//*}*/;
		//alert(document.getElementById(nome).src);
		/*if(document.getElementById(nome).src == pendente){*//*}*/;
		//alert(document.getElementById(nome).src);
		document.getElementById(nome).src = pendente;
		}
}

function comu(id,al){
	if(navigator.appName != "Microsoft Internet Explorer"){
		al = al * 0.01;
		document.getElementById(id).style.MozOpacity = al;
		document.getElementById(id).style.opacity = al;
	}else{
		document.getElementById(id).filters.alpha.opacity = al;
	}
}//chave final-inicial

var gerape =	'@&nbsp;1024x768 de tela '+
				'em&nbsp;Explorer 6+ ou Firefox 2+ &copy; '+
				'<a title="Webmaster formado desde 2000." '+
				'href="http://www.ioferreira.com/sobre/sites.htm" '+
				'target="_blank">'+
				'Igor Oliveira Ferreira</a> 2006-2011 '+
				'para Persiste Produtos Eletr&ocirc;nicos. '+
				'<a title="Hospedagem de sites sem limites." href="http://www.hospedasim.com.br/"'+
				'target="_blank">'+
				'Hospedagem de sites</a> por Hospedasim.';

function marcar(cidade)
{
var linhas_tabela_str = window.document.getElementsByTagName('tr');
var linhas_tabela_num = (linhas_tabela_str.length) -1;
var linhas_tabela_xid = window.document.getElementsByTagName('tr').item(linhas_tabela_num).id;

	do{
	linhas_tabela_xid = window.document.getElementsByTagName('tr').item(linhas_tabela_num).id;

		if(linhas_tabela_xid == cidade)
		{
		linhas_tabela_str.item(linhas_tabela_num).style.backgroundColor = '#FAE7E8';
		}else{
		linhas_tabela_str.item(linhas_tabela_num).style.backgroundColor = '';
		};

	linhas_tabela_num--;
	}while(linhas_tabela_num > 1);

}



// Validar form de contato [modelo antigo]
 function validarfl()
  {
var erro = 0;
setTimeout("",0);

 if (document.getElementsByTagName("input").item(0).value == "")
  {document.getElementById('status').innerHTML = "Digite o seu nome."
  setTimeout("document.getElementById('status').innerHTML = '&nbsp;'",12000)
  document.getElementsByTagName("input").item(0).focus();return false;
  erro = 1;}
 if (document.getElementsByTagName("input").item(1).value == "")
  {document.getElementById('status').innerHTML = "Digite o seu e-mail."
  setTimeout("document.getElementById('status').innerHTML = '&nbsp;'",12000)
  document.getElementsByTagName("input").item(1).focus();return false;
  erro = 1;}
 if (document.getElementsByTagName("textarea").item(0).value == "")
  {document.getElementById('status').innerHTML = "Escreva uma mensagem."
  setTimeout("document.getElementById('status').innerHTML = '&nbsp;'",12000)
  document.getElementsByTagName("textarea").item(0).focus();return false;
  erro = 1;}

 if (erro == 0){
  document.forms[0].submit();
 }

  }
  

function mostrar(){

	
	document.getElementById('imagens').style.display = 'block';
	
}

function fechar(){
	
	document.getElementById('imagens').style.display = 'none';
	interativo.document.location = 'pre_carregando.htm';
	
}

document.onkeydown = function(e){ 
								/* http://snipplr.com/view/13832/get-key-event--esc-on-document/ */
          if (e == null) {		// ie 
            keycode = event.keyCode; 
          } else {				// mozilla, opera 
            keycode = e.which; 
          } 
          
		  if(keycode == 27){	// escape, close box, esc
			fechar();			//what you nedd
          } 
        };

function cliente(tdl){
//2.0
//alert(document.body.offsetWidth);

aviso = 0;
	if(screen.availWidth < 832){
		alert("Este site foi desenvolvido para 1024x768 ou superior.");
		aviso = 1;
	}
	
	if(screen.colorDepth < 16){
		alert("Este site foi desenvolvido para 16 ou mais bits de cor.");
		aviso = 2;
	}

	if(aviso != 0){
		
	}

	if(document.body.offsetWidth > 1034){
		document.cookie = tdl;
		window.document.location = "entrar.htm";
	}
	
/*
//teste = window.scroll == true;
teste = scrollbars.visible;
alert(teste);
*/
}

function semprevolta(){
h01 = window.history.length;
	if(h01 > 1){
		window.history.back();
	}else{
		top.document.location = 'index.htm';
	}

}

/* http://twitter.com/javascripts/blogger.js */

function twitterCallback2(twitters) {
  var statusHTML = [];
  for (var i=0; i<twitters.length; i++){
    var username = twitters[i].user.screen_name;
    var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
      return '<a href="'+url+'">'+url+'</a>';
    }).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
      return  reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
    });
    statusHTML.push('<span style="font-size:90%">'+status+'</span> <a style="font-size:90%" href="http://twitter.com/'+username+'/statuses/'+twitters[i].id_str+'">'+relative_time(twitters[i].created_at)+'</a>');
  }
  document.getElementById('twitter_update_list').innerHTML = statusHTML.join('');
}

function relative_time(time_value) {
  var values = time_value.split(" ");
  time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
  var parsed_date = Date.parse(time_value);
  var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
  var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
  delta = delta + (relative_to.getTimezoneOffset() * 60);

  if (delta < 60) {
    return 'h&aacute; menos de um minuto atr&aacute;s';
  } else if(delta < 120) {
    return 'h&aacute; cerca de um minuto atr&aacute;s';
  } else if(delta < (60*60)) {
    return 'h&aacute; ' + (parseInt(delta / 60)).toString() + ' minutos atr&aacute;s';
  } else if(delta < (120*60)) {
    return 'h&aacute; cerca de uma hora atr&aacute;s';
  } else if(delta < (24*60*60)) {
    return 'h&aacute; cerca de ' + (parseInt(delta / 3600)).toString() + ' horas atr&aacute;s';
  } else if(delta < (48*60*60)) {
    return 'h&aacute; 1 dia atr&aacute;s';
  } else {
    return 'h&aacute; ' + (parseInt(delta / 86400)).toString() + ' dias atr&aacute;s';
  }
}

function janela(url, largura, altura, esquerda, topo) {
	
	dcl = document.cookie;
	window.open(dcl,'SAFENIGHT','width='+largura+',height='+altura+',left='+esquerda+',top='+topo+',scrollbars=yes,status=yes,toolbar=yes,location=yes,directories=no,menubar=no,resizable=no,fullscreen=no');

}

function getAddress() {

		/* original: http://ceplivre.pc2consultoria.com/ */

		cep8 = document.getElementById("cep").value;
		cep5 = cep8.substr(0,5);
		cep3 = cep8.substr(5,8);
		cep9 = cep5 + "-" + cep3;
		
		// alert(cep3); 
	
	cepLivre.buscaEndereco(cep9, function(address){
		
		logr = address.tipoLogradouroDesc + " " + address.logradouro;
		document.getElementById("logradouro").value = logr;
				
		brro = address.bairro;
		document.getElementById("bairro").value = brro;
		
		cdde = address.cidade;
		document.getElementById("cidade").value = cdde;
		
		estd = address.ufSigla;
		document.getElementById("estado").value = estd;
	
	}); 
}

function adicionar(id){
		qtdd = document.getElementById(id).value;
		if(qtdd > 98){}else{qtdd++;}
		document.getElementById(id).value = qtdd;
		document.getElementById(id).focus();
		mudabgc('modelos','#ffffff');
}

function corrigir(id){
		qtdd = document.getElementById(id).value;
		qtdd++;
		qtdd--;
		//if(qtdd >= 100){qtdd = 99;}
		document.getElementById(id).value = qtdd;
}

function zerar(){
	if(confirm("Este comando zera todas as quantidades definidas. Continuar?")){
		document.getElementById('al36fx').value = 0;
		document.getElementById('al36fx2').value = 0;
		document.getElementById('sn1').value = 0;
		document.getElementById('sn1litio').value = 0;
		document.getElementById('sn2').value = 0;
		document.getElementById('sn2litio').value = 0;
	}else{}	
}

function modelo(nome){
	if(nome == "al36fx"){caminho = 'alarmes_modelo_al36fx.htm'}
	if(nome == "al36fx2"){caminho = 'alarmes_modelo_al36fx2.htm'}
	if(nome == "sn1"){caminho = 'alarmes_modelo_sn1.htm'}
	if(nome == "sn1litio"){caminho = 'alarmes_modelo_sn1-litio.htm'}
	if(nome == "sn2"){caminho = 'alarmes_modelo_sn2.htm'}
	if(nome == "sn2litio"){caminho = 'alarmes_modelo_sn2-litio.htm'}
	
	if(confirm('Este comando abre noutra janela, detalhes sobre o modelo escolhido. Continuar?')){
		alert('Feche a janela que vai abrir, quando quiser retornar ao pedido.');
		janela(caminho,'1024','768','50','50');}
}

function mudabgc(id,cor){
 		if(id != "modelos"){
			document.getElementById(id).style.backgroundColor = cor;
		}else{
			document.getElementById('al36fx').style.backgroundColor = cor;
			document.getElementById('al36fx2').style.backgroundColor = cor;
			document.getElementById('sn1').style.backgroundColor = cor;
			document.getElementById('sn1litio').style.backgroundColor = cor;
			document.getElementById('sn2').style.backgroundColor = cor;
			document.getElementById('sn2litio').style.backgroundColor = cor;
		}
}
