/******************************************
Arquivo .............. functions.js
Escrito Por .......... Sydhnney
Criado Em ............ 15/10/2006
******************************************/
var Ajax;
var linhaselecionada;
var consulta;
function AjaxRequest(){
	Ajax = false;
	if (window.XMLHttpRequest){
		Ajax = new XMLHttpRequest();
	} else if (window.ActiveXObject){
		try{	
			Ajax = new ActiveXObject("Msxm12.XMLHTTP");
		} catch(e) {
				try{
					Ajax = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {}
			}
		}
}

function processaAjax(metodo, url, parametros, fctresposta){
	AjaxRequest();
	if (metodo == 'GET') {Ajax.open(metodo,url+'?'+parametros,true);}
	if (metodo == 'POST') {Ajax.open(metodo,url,true);}	
	
	Ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");    
	//Ajax.setRequestHeader("Encoding","ISO-8859-1"); 	
	Ajax.setRequestHeader("Cache-Control","no-store, no-cache, must-revalidate");			
	Ajax.setRequestHeader("Cache-Control","post-'=0, pre-check=0");
	Ajax.setRequestHeader("Pragma", "no-cache");
	Ajax.onreadystatechange = fctresposta;	
	if (metodo == 'GET') {Ajax.send(null);}
	if (metodo == 'POST') {Ajax.send(parametros);}
}

function processandoAjax(){
	if (Ajax.readyState == 1){
		teste2('Carregando Informações...');
	} else if (Ajax.readyState == 2){
		teste2('Carga Completa');
	} else if (Ajax.readyState ==3){
		teste2('Processando...');
	} else if (Ajax.readyState == 4) {		
		teste2('Processado Com Sucesso');
	}
}


var Ajax2;
function AjaxRequest2(){
	Ajax2 = false;
	if (window.XMLHttpRequest){
		Ajax2 = new XMLHttpRequest();
	} else if (window.ActiveXObject){
		try{	
			Ajax2 = new ActiveXObject("Msxm12.XMLHTTP");
		} catch(e) {
				try{
					Ajax2 = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {}
			}
		}
}

function processaAjax2(metodo, url, parametros, fctresposta){
	AjaxRequest2();
	if (metodo == 'GET') {Ajax2.open(metodo,url+'?'+parametros,false);}
	if (metodo == 'POST') {Ajax2.open(metodo,url,false);}	
	
	Ajax2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");    
	Ajax2.setRequestHeader("Encoding","ISO-8859-1"); 	
	Ajax2.setRequestHeader("Cache-Control","no-store, no-cache, must-revalidate");			
	Ajax2.setRequestHeader("Cache-Control","post-'=0, pre-check=0");
	Ajax2.setRequestHeader("Pragma", "no-cache");
	Ajax2.onreadystatechange = fctresposta;	
	if (metodo == 'GET') {Ajax2.send(null);}
	if (metodo == 'POST') {Ajax2.send(parametros);}
}

function processandoAjax2(){
	if (Ajax2.readyState == 1){
		teste2('Carregando Informações...');
	} else if (Ajax2.readyState == 2){
		teste2('Carga Completa');
	} else if (Ajax2.readyState ==3){
		teste2('Processando...');
	} else if (Ajax2.readyState == 4) {		
		teste2('Processado Com Sucesso');
	}
}

function apagarBox(){
	var e = document.getElementById('lg_bg');
	var d = document.getElementById('aa');
	if ((d) && (d.hasChildNodes())){
		e.removeChild(d);
	}
}

function closeObj(id){	
	var e = document.getElementById(id);
	if (e) {
		e.setAttribute('class','esc');
		e.setAttribute('className','esc');
	}
}

function activeOpacity(){
	var o = document.getElementById('opac');
	o.setAttribute('class','cmd');
	o.setAttribute('className','cmd');
}

function inactiveOpacity(){
	var o = document.getElementById('opac');
	if (o){
		o.setAttribute('class','esc');
		o.setAttribute('className','esc');
	}
}

function openObj(id, nome_classe){	
	var e = document.getElementById(id);
	e.setAttribute('class',nome_classe);
	e.setAttribute('className',nome_classe);
	clearMensagem('bdMain');
}

function setClasse(id, nome_classe){	
	var e = document.getElementById(id);
	e.setAttribute('class',nome_classe);
	e.setAttribute('className',nome_classe);
	clearMensagem('bdMain');
}

function closeAllForms(){
	clearMensagem('bdMain');
	var d = document.body.getElementsByTagName('form');
	for (var i=0; i< (d.length); i++){
		var e = d[i];
		closeObj(e.parentNode.getAttribute('id'));
	}
}

function closeForm(id){	
	var e = document.getElementById(id);
	if (e) {
		e.setAttribute('class','esc');
		e.setAttribute('className','esc');
	}
	inactiveOpacity();
}

function openForm(abrirIdForm, focar, fecharIdForm){
	window.scrollTo(0,0);
	var e = document.getElementById(abrirIdForm);
	if (e){
		//closeAllForms();
		if (fecharIdForm) {closeObj(fecharIdForm);}
		e.setAttribute('class','frm_bg');
		e.setAttribute('className','frm_bg');
		
		e = document.getElementById(focar);
		if (e){
			e.focus();

		}
	}
}

function alternarTab(abrir, focar){
	clearMensagem('bdMain');
	closeObj('dvOse1');
	closeObj('dvOse2');
	closeObj('dvOse3');
	closeObj('dvOse4');	

	var e = document.getElementById(abrir);
	e.setAttribute('class','#');
	e.setAttribute('className','#');
	document.getElementById(focar).focus();
}

function entrarCampo(campo){
	campo.style.backgroundColor='#FFFFD7';
}

function sairCampo(campo){
	clearMensagem('bdMain');
	campo.style.backgroundColor='#FFFFFF';
}

function teste2(txt){
	var novaDiv = document.createElement('div');
	novaDiv.style.cssText='width:200px; font-size:12px; background:red; position:relative;';
	novaDiv.innerHTML = txt;
	document.body.appendChild(novaDiv);
}

function clearMensagem(elemento_pai){
	var b = document.getElementById('box_msg');
	if (b){		
		document.body.removeChild(b);                           
	}
}

function mensagem(txt, elemento_pai){
	window.scrollTo(0,0);
	clearMensagem(elemento_pai);
	var novaDiv = document.createElement('div');
	novaDiv.setAttribute('id','box_msg');
	novaDiv.innerHTML = txt;
	document.body.appendChild(novaDiv);
}

function mensagem_error(txt, elemento_pai){
	window.scrollTo(0,0);
	clearMensagem(elemento_pai);
	var novaDiv = document.createElement('div');
	novaDiv.setAttribute('id','box_msg_error');
	novaDiv.innerHTML = txt;
	document.body.appendChild(novaDiv);
}

//linha de tabela
function bglinein(linha){
	//linha.style.backgroundColor='#ECEBD9';
	linha.style.backgroundColor='#FFFFCC';
}

//linha tabela
function bglineout(linha){
	linha.style.backgroundColor='';	
}

function countLinhaTabela(refer){
	var tabela = document.getElementById(refer);
	var qtd = tabela.rows.length;
	return qtd;
}

function addLinha(tbl, codigo, nome, dados, fctEditar, fctDeletar, btnEditar, btnDeletar){
	var tabela = document.getElementById(tbl);
	if (btnEditar) { var edt = createLinkImg('javascript:'+fctEditar+'('+codigo+')','../img/editar.png','OK','Editar',15,15);}
	if (btnDeletar) {var exc = createLinkImg('javascript:'+fctDeletar+'('+codigo+',\''+nome+'\')','../img/excluir.png','OK','Excluir',15,15);}
	var nrlinhas = tabela.getElementsByTagName('tr').length-1;
	var novalinha = tabela.insertRow(nrlinhas);
	novalinha.setAttribute('onmouseover','bglinein(this);');
	novalinha.setAttribute('onmouseout','bglineout(this);');
	novalinha.setAttribute('id','L'+codigo);
	for (var i=0; i<dados.length; i++){
		var novacoluna= novalinha.insertCell(i);
		novacoluna.innerHTML = dados[i];
	}
	if (btnDeletar){
		var novacoluna= novalinha.insertCell(i);
		novacoluna.appendChild(exc);
	}
	if (btnEditar){
		var novacoluna= novalinha.insertCell(i);
		novacoluna.appendChild(edt);
	}
}

function addLinhaSemFoot(tbl, codigo, nome, dados, fctEditar, fctDeletar, btnEditar, btnDeletar){
	var tabela = document.getElementById(tbl);
	if (btnEditar) { var edt = createLinkImg('javascript:'+fctEditar+'('+codigo+')','../img/editar.png','OK','Editar',15,15);}
	if (btnDeletar) {var exc = createLinkImg('javascript:'+fctDeletar+'('+codigo+',\''+nome+'\')','../img/excluir.png','OK','Excluir',15,15);}
	var nrlinhas = tabela.getElementsByTagName('tr').length;
	var novalinha = tabela.insertRow(nrlinhas);
	novalinha.setAttribute('onmouseover','bglinein(this);');
	novalinha.setAttribute('onmouseout','bglineout(this);');
	novalinha.setAttribute('id','L'+codigo);
	for (var i=0; i<dados.length; i++){
		var novacoluna= novalinha.insertCell(i);
		novacoluna.innerHTML = dados[i];
	}
	if (btnDeletar){
		var novacoluna= novalinha.insertCell(i);
		novacoluna.appendChild(exc);
	}
	if (btnEditar){
		var novacoluna= novalinha.insertCell(i);
		novacoluna.appendChild(edt);
	}
}

function clearLinhaFoot(refer){
	var tabela = document.getElementById(refer);
	while (tabela.hasChildNodes()){
		tabela.removeChild(tabela.firstChild);
	}
}

function addLinhaFoot(refer, total, por_pagina, currPagina, fctPesquisa){
	var tabela = document.getElementById(refer);
	clearLinhaFoot(refer);
	
	if (total == null){
		total = 0;
	}
	qtd_pag = Math.ceil(total / por_pagina);
	var dv_resumo = document.createElement('div');	
	dv_resumo.setAttribute('id','dv_resumo');
	//var texto = document.createTextNode('Reg: '+total+' Pags: '+qtd_pag);		
	var texto = document.createTextNode('Reg: '+total);	
	dv_resumo.appendChild(texto);
	dv_resumo.style.cssText="width:80px; float:left; margin-top:3px;";
	var dv_pag = document.createElement('div');	
	dv_pag.style.cssText="float:left; width:350px;";
	dv_pag.setAttribute('id','dv_pag');
	//var texto2 = document.createTextNode(' < ');
	//dv_pag.appendChild(texto2);
	var qtd_link_paginas = 25;

	for (var i=1; i <= qtd_pag; i++){
		if (i <= qtd_link_paginas){
			var link1 = document.createElement('A');
			if (currPagina == i){
				link1.style.cssText='font-size:12px; color:red; margin-left:8px;';
			} else { 
				link1.style.cssText='font-size:10px; margin-left:8px';
			}
			link1.setAttribute('href','javascript:'+fctPesquisa+'('+i+')');
			var pag = document.createTextNode(i);
			link1.appendChild(pag);
			dv_pag.appendChild(link1);
		}
	}
	
	if (qtd_pag > qtd_link_paginas) {
		var texto4 = document.createTextNode(' ....... ');
		dv_pag.appendChild(texto4);	
		 
		//criando link para ultima pag
		var linkfinal = document.createElement('A');
		var pagfinal = document.createTextNode(qtd_pag);
		linkfinal.setAttribute('href','javascript:'+fctPesquisa+'('+qtd_pag+')');
		if (currPagina == qtd_pag){
			linkfinal.style.cssText='font-size:12px; color:red;';
		} else {
			linkfinal.style.cssText='font-size:10px;';
		}
		linkfinal.appendChild(pagfinal);
		dv_pag.appendChild(linkfinal);
	}
	
	tabela.appendChild(dv_resumo);
	tabela.appendChild(dv_pag);
	window.scrollTo(0,0);
}

function atualizaQtdRegistro(){
	var dv = document.getElementById('dv_resumo');
	if (dv){
		var texto =dv.innerHTML;
		var texto_array = texto.split(" ");
		var qtd = parseInt(texto_array[1]);
		if (qtd > 0) {
			qtd--;
			dv.innerHTML = ('Registros: '+qtd);
		}
	}
}                        

function limparTabela(tabela){
	var t = document.getElementById(tabela);
	if (t){
		while (t.rows.length > 3) {
			t.deleteRow(countLinhaTabela(tabela)-2);
		}
	}
}

function limparTabelaSemFooter(tabela, num){
	var t = document.getElementById(tabela);
	if (t){
		while (t.rows.length > 2) {
			t.deleteRow(countLinhaTabela(tabela)-1);
		}
	}
}

function limparTabelaGeral(tabela, foot){
	limparTabela(tabela);
	clearLinhaFoot(foot);
}

function getRegPorPagina(){
	return 30;	
}

function openProgress(){
	if (document.getElementById('progress')){
		openObj('progress','pg');
	}
}

function closeProgress(){
	closeObj('progress');	
}

function randomizar(){
	var valor = Math.ceil(Math.random() * 1000000);
	return valor;
}

function getXML(ObjAjax){
	if (navigator.appName == 'Microsoft Internet Explorer'){
		xmldoc = document.createElement('xml');
		xmldoc.innerHTML = ObjAjax.responseText;
		document.body.appendChild(xmldoc);
	} else {
		if (window.XMLHttpRequest){
			 xmldoc = ObjAjax.responseXML;
		}
	}
	return xmldoc;
}

function clearCampos(nomeDiv, focar){
	var e = document.getElementById(nomeDiv);
	var x = e.getElementsByTagName('input');
	for (var i=0; i<=(x.length-1); i++){
		var campo = x[i];
		var id = campo.getAttribute('id');
		if ((campo.getAttribute('type') == 'text') && (campo.getAttribute('alt') != '#')){
			campo.value = '';
		}
		
		if ((campo.getAttribute('type') == 'password') && (campo.getAttribute('alt') != '#')){
			campo.value = '';
		}
		
		if ((campo.getAttribute('type') == 'hidden') && (campo.getAttribute('alt') != '#')){
			campo.value = '';
		}
		
		if (campo.getAttribute('type') == 'checkbox'){
			campo.checked = false;
		}
		
	}
	x = e.getElementsByTagName('textarea');
	if (x){
		for (i=0; i <=(x.length-1);i++){
			x[i].value = '';
		}
	}
	window.scrollTo(0,0);
	if (focar != ''){
		e = document.getElementById(focar);
		if (e){
			e.focus();
		}
	}
}

function getCampos(nomeDiv){
	var texto = '';
	var e = document.getElementById(nomeDiv);
	var x = e.getElementsByTagName('input');
	for (var i=0; i<=(x.length-1); i++){
		if (x[i].type == 'text') 
			texto = texto + x[i].getAttribute('id') + '='+ x[i].value + '&';

		if (x[i].type == 'hidden') 
			texto = texto + x[i].getAttribute('id') + '='+ x[i].value + '&';
		
		if (x[i].type == 'password') 
			texto = texto + x[i].getAttribute('id') + '='+ x[i].value + '&';

		if (x[i].type == 'select-one') 
			texto = texto + x[i].getAttribute('id') + '='+ x[i].value + '&';
			
		if ((x[i].type == 'radio') && (x[i].checked))
			texto = texto + x[i].getAttribute('name') + '='+ x[i].value + '&';
		
		if (x[i].type == 'checkbox'){ 
			if (x[i].checked) {
				texto = texto + x[i].getAttribute('id') + '=1&';
			} else {
				texto = texto + x[i].getAttribute('id') + '=0&';
			}
		}
	}
	
	x = e.getElementsByTagName('select');
	if (x){
		for (i=0; i<=(x.length-1); i++){
			nome = texto + x[i].getAttribute('id');
			texto =  nome + '=' + x[i].value + '&';
		}
	}
	
	x = e.getElementsByTagName('textarea');
	if (x){
		for (i=0; i <=(x.length-1); i++){
			nome = texto + x[i].getAttribute('id');		
			texto = nome + '='+ x[i].value + '&';
		}
	}	
	return texto;
}

function setCampos(campo, texto){
	var e = document.getElementById(campo);
	if (e){
		if ((e.type == 'text') || (e.type == 'hidden') || (e.type == 'select-one') || (e.type == 'textarea') || (e.type == 'password')) {
			e.value = texto;
		}
		if (e.type == 'checkbox'){
			if (texto == 1){ e.checked=true} else {e.checked=false}	
		}
	}                                                                                            
}

function clearDivs(nome_parent){
	var e = document.getElementById(nome_parent);
	if (e) {
		var ediv = e.getElementsByTagName('div');
		for (var i=0; i <= ediv.length-1; i++){
			if (ediv[i].getAttribute('id') != ''){
				closeObj(ediv[i].getAttribute('id'));
			}
		}
	}
}

function switchClass(id, class1, class2){
	var e = document.getElementById(id);
	if (e){
		if ((e.getAttribute('class') == class1) || (e.getAttribute('className') == class1)){
			e.setAttribute('class', class2);
			e.setAttribute('className', class2);
		} else {
			e.setAttribute('class', class1);
			e.setAttribute('className', class1);
		}
	}
}

function abrir(url,id, lar,alt) {
	janela = null;
	cima = (window.screen.height - alt)/2;
	lado = (window.screen.width - lar)/2;
	janela = window.open(url,id,"toolbars=no, scrollbars=yes, resizable=no, location=no,width="+lar+",height="+alt+",top="+cima+",left="+lado);
	return janela;
}

function setSelect(elementSelect, lista){
	var e = document.getElementById(elementSelect);
	for (var i=0; i<lista.length; i++){
		o = document.createElement('option');
		o.text = lista[i];
		o.value = i;
		try{
			e.add(o,null);
		} catch(ex){
			e.add(o);  //IE	
		}
	}
}

function checkVazio(idElement, msg){
	if ((document.getElementById(idElement).value == '') || (document.getElementById(idElement).value == '-1')){
		document.getElementById(idElement).focus();
		alert(msg);
		closeProgress();
		return false;
	}
	return true;
}

function checkRadioVazio(idElement1, idElement2, msg){
	if ((!document.getElementById(idElement1).checked) && (!document.getElementById(idElement2).checked)){
		document.getElementById(idElement1).focus();
		alert(msg);
		return false;
	}

	return true;
}

function checkVazioAlert(idElement, msg){
	if ((document.getElementById(idElement).value == '') || (document.getElementById(idElement).value == '-1')){
		document.getElementById(idElement).focus();
		alert(msg);
		closeProgress();
		return false;
	}
	return true;
}


function checkCPF(idElement){
	if (document.getElementById(idElement).value != ''){
		if (!isCpf(document.getElementById(idElement).value)){
			alert('CPF Inválido');
			return false;
		}
	}
	return true;
}

function checkCNPJ(idElement){
	if (document.getElementById(idElement).value != ''){
		if (!isCnpj(document.getElementById(idElement).value)){
			mensagem('CNPJ Inválido', 'bdMain');
			return false;
		}
	}
	return true;
}

function checkCPFCNPJ(idElement){
	if (document.getElementById(idElement).value != ''){
		if (!isCpfCnpj(document.getElementById(idElement).value)){
			mensagem('CPF/ CNPJ Inválido', 'bdMain');
			return false;
		}
	}
	return true;
}

function getDateNow(){
	var data = new Date();
	var mes = new Array(12);
	mes[0] = '01';
	mes[1] = '02';
	mes[2] = '03';
	mes[3] = '04';
	mes[4] = '05';
	mes[5] = '06';
	mes[6] = '07';
	mes[7] = '08';
	mes[8] = '09';
	mes[9] = '10';
	mes[10] = '11';
	mes[11] = '12';
	var dia = parseInt(data.getDate());
	if (dia < 10) { dia = '0'+dia}
	return (dia+'/'+mes[data.getMonth()]+'/'+data.getFullYear());
}

function setDataCampo(campo){
	document.getElementById(campo).value = getDateNow();	
}
                           
function addOptionSelect(elementSelect, valor, nome, selected){
	var e = document.getElementById(elementSelect);
	o = document.createElement('option');
	o.text = nome;             
	o.value = valor;
	if (selected) {
		o.selected=true;
	}
	try{
		e.add(o,null);
	} catch(ex){
		e.add(o);  //IE	
	}
}

function addOptionSelect2(elementSelect, valor, nome, selected){
	var e = opener.document.getElementById(elementSelect);
	o = document.createElement('option');
	o.text = nome;             
	o.value = valor;
	if (selected) {
		o.selected=true;
	}
	try{
		e.add(o,null);
	} catch(ex){
		e.add(o);  //IE	
	}
}

function clearSelect(elementSelect){
	var e = document.getElementById(elementSelect);
	if (e){
		var qtd = e.length;
		while (qtd > 0) {
			e.remove(0);
			qtd = e.length;
		}
	}
}

function realToDolar(valor){
	valor = valor.replace('.','');
	valor = valor.replace(',','.');
	valor = parseFloat(valor);
	if (isNaN(valor)) {
		return 0;
	} else {
		return valor;
	}
}

function dolarToReal(valor){
    valor = parseFloat(valor);
    valor = valor.toFixed(2);
	valor = valor.replace('.',',');
	return valor;
}

function focar(campo1, campo2){
	if (document.getElementById(campo1)){
		document.getElementById(campo1).focus();
	} else {
		document.getElementById(campo2).focus();
	}
}

function setStyleSheet(estilo){
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == estilo) a.disabled = false;
      if (a.getAttribute('title') == estilo){
      a.disable = false;
      }
    }
  }
}

function loadXMLDoc(dname){
	var xmlDoc;
	// code for IE
	if (window.ActiveXObject){
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	}
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument){
		xmlDoc=document.implementation.createDocument("","",null);
	}
	else
	{
		alert('Seu Browser Nao Suporta XML');
	}
	xmlDoc.async=false;
	xmlDoc.load(dname);
	return(xmlDoc);
}


function xmlToSelect(idSelect, fileXML, xmldoc){
	if (xmldoc){
		var xml = fileXML;
	} else {
		var xml = loadXMLDoc('./../xml/'+fileXML);
	}
	var opcoes = xml.getElementsByTagName('opcao')[0].getElementsByTagName('desc');
	for (var i=0; i<=opcoes.length-1; i++){
		var desc = opcoes[i].firstChild.nodeValue;
		var cod = opcoes[i].getAttribute('id');
		var sel = opcoes[i].getAttribute('selected');
		addOptionSelect(idSelect, cod, desc, sel)
	}
}

//cria tag img
function createImage(fileimg, alt, title, height, width){
	var img = document.createElement('img');
	img.setAttribute('src',fileimg);
	img.setAttribute('alt',alt);
	img.setAttribute('title',title);                                             
	img.setAttribute('height',height);
	img.setAttribute('width',width);
	img.setAttribute('border',0);
	return img;	
}

//cria link com img
function createLinkImg(url, fileimg, alt, title, height, width){
	var img = createImage(fileimg, alt, title, height, width);
	var lnk = document.createElement('A');
	lnk.setAttribute('href',url);
	lnk.appendChild(img);
	return lnk;
}

function disabledCampo(campo, acao){
	document.getElementById(campo).disabled=acao;
}

function getUrlSistema(){
	return 'http://www.meusistemaweb.com/curriculo/sistema/';
	//return 'http://localhost/curriculo/sistema/';
}

function goSistema(){
	location.href=getUrlSistema();
	//window.history.go(-1);
}

function redirect(url){
	location.href=url;
}

//usado para transporte de qualquer valor do escopo global
function setConsulta(valor){
	consulta = valor;
}
function getConsulta(){
	return consulta;
}


function ativarEnter(event){
	//Internet Explorer
	if(window.event && window.event.keyCode == 13){
		sendLogin();
	}
	//Netscape e Mozilla
	if (event && event.which == 13){
		sendLogin();
	}
}

function setCampoTexto(id, valor){
	document.getElementById(id).value = valor;
}

function getCampoTexto(id){
	return document.getElementById(id).value;
}

//calcula diferença entre horas
function diffHora(inicio, fim){
	var di = new Date('2008/12/01 '+inicio);
	var df = new Date('2008/12/01 '+fim);
	var xhora = 0;
	if (di.getHours() > df.getHours()){
		var xhora = 24 - di.getHours() + df.getHours();
		if (df.getMinutes() < di.getMinutes()){
			xhora--;
		}
		xhora = formatarValor(xhora,0,2);
		if (df.getMinutes() > di.getMinutes()){
			var xminuto = df.getMinutes() - di.getMinutes();
		} else {
			
			if (df.getHours() > di.getHours()){
				var xminuto = 60-di.getMinutes() + df.getMinutes();
			} else {
				var xminuto = di.getMinutes() - df.getMinutes();	
			}
		}
		xminuto = formatarValor(xminuto,0,2);
		var tempo = xhora+':'+xminuto;
	} else {
		var diffM = df.getMinutes() - di.getMinutes();
		if (di.getHours()+1 == df.getHours()){
			if (60-di.getMinutes() + df.getMinutes() < 60){
				xhora = 0;
			} else {
				xhora = df.getHours() - di.getHours();
			}
		} else if (di.getHours() == df.getHours()){
			if (df.getMinutes() >= di.getMinutes()){
				xhora = 0;
			} else {
				xhora = 24 - di.getHours() + df.getHours();
				if (df.getMinutes() < di.getMinutes()){
					xhora--;
				}
			}
		} else {
			xhora = df.getHours() - di.getHours();
			if (df.getMinutes() < di.getMinutes()){
					xhora--;
				}
		}
		
		var hora2minuto = xhora * 60;
		if (diffM == 0){
			xminuto = 0;
		} else {
			xminuto = diffM;
		}
		resto = (hora2minuto + xminuto)%60;
		
		if (resto == 0){
			xhora = (hora2minuto + xminuto)/60;
		} else {
			if (di.getMinutes() > df.getMinutes()){
				xminuto = 60 - di.getMinutes() + df.getMinutes();
			}
		}
		xhora = formatarValor(xhora,0,2);
		xminuto = formatarValor(xminuto,0,2);
		tempo = xhora+':'+xminuto;
	}
	return tempo;
}
//preenche com zeros a esquerda
function formatarValor(valor, simbolo,qtd){
	var saida = '';
	valor = String(valor);
	j = 0;
	for (i=1; i<=qtd; i++){
		if (i > qtd-valor.length){
			saida = saida + valor[j]
			j++;
		} else {
			saida = saida + simbolo;
		}
	}
	return saida;
}

function formatarMascara(src, mask){
	var i = src.value.length;
	var saida = mask.substring(0,1);
	var texto = mask.substring(i)
	if (texto.substring(0,1) != saida){
		src.value += texto.substring(0,1);
	}
}

function assigned(obj){
	return document.getElementById(obj) ? true : false;
}

function getObj(obj){
	return document.getElementById(obj);
}
