// JavaScript Document
function selecionar_linha_li( obj, nome ) {
	obj.className = nome;
}

function resizeMe(obj){
	docHeight = stats.document.body.scrollHeight
	obj.style.height = docHeight + 0 + 'px'
}
function voltar(){
	history.go(-1);	
}
function abre_site(width, height, nome,barra) {
	var top; var left; 
	if (barra == "") {
		barra = 0;
	}
	top = ( (screen.height/2) - (height/2) )
	left = ( (screen.width/2) - (width/2) )
	window.open(nome, "","toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0,scrollbars=1,width="+width+",height="+height+",left="+left+",top="+top);
}
function addItem(obj,strText,strValue,blSel2,intPos){ 
	 var newOpt,i,ArTemp,selIndex;
	 if(blSel2 == 1){
		 blSel = true;
	 } else {
		blSel = false; 
	 }
	 selIndex = (blSel)?intPos:obj.selectedIndex; 
	 newOpt = new Option(strText,strValue); 
	 Len = obj.options.length+1 
	 if (intPos > Len) return 
	 obj.options.length = Len 
	 if (intPos != Len) { 
		  ArTemp = new Array(); 
		  for(i=intPos;i<obj.options.length-1;i++) 
			   ArTemp[i] = Array(obj.options[i].text,obj.options[i].value); 
		  for(i=intPos+1;i<Len;i++) 
			   obj.options[i] = new Option(ArTemp[i-1][0],ArTemp[i-1][1]); 
	 } 
	 obj.options[intPos] = newOpt; 
	 if (selIndex > intPos) 
		  obj.selectedIndex = selIndex+1; 
	 else if (selIndex == intPos)  
		  obj.selectedIndex = intPos; 
} 
function FormataValor(objeto,teclapres,tammax,decimais) 
{

	var tecla			= teclapres.keyCode;
	var tamanhoObjeto	= objeto.value.length;

	if ((tecla == 8) && (tamanhoObjeto == tammax))
	{
		tamanhoObjeto = tamanhoObjeto - 1 ;
	}



if (( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) && ((tamanhoObjeto+1) <= tammax))
	{

		vr	= objeto.value;
		vr	= vr.replace( "/", "" );
		vr	= vr.replace( "/", "" );
		vr	= vr.replace( ",", "" );
		vr	= vr.replace( ".", "" );
		vr	= vr.replace( ".", "" );
		vr	= vr.replace( ".", "" );
		vr	= vr.replace( ".", "" );
		tam	= vr.length;
		
		if (tam < tammax && tecla != 8)
		{
			tam = vr.length + 1 ;
		}

		if ((tecla == 8) && (tam > 1))
		{
			tam = tam - 1 ;
			vr = objeto.value;
			vr = vr.replace( "/", "" );
			vr = vr.replace( "/", "" );
			vr = vr.replace( ",", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
		}
	
		//Cálculo para casas decimais setadas por parametro
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
		{
			if (decimais > 0)
			{
				if ( (tam <= decimais) )
				{ 
					objeto.value = ("0," + vr) ;
				}
				if( (tam == (decimais + 1)) && (tecla == 8))
				{
					objeto.value = vr.substr( 0, (tam - decimais)) + ',' + vr.substr( tam - (decimais), tam ) ;	
				}
				if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) == "0"))
				{
					objeto.value = vr.substr( 1, (tam - (decimais+1))) + ',' + vr.substr( tam - (decimais), tam ) ;
				}
				if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) != "0"))
				{
				    objeto.value = vr.substr( 0, tam - decimais ) + ',' + vr.substr( tam - decimais, tam ) ; 
				}
				if ( (tam >= (decimais + 4)) && (tam <= (decimais + 6)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 3) ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
			 	if ( (tam >= (decimais + 7)) && (tam <= (decimais + 9)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 6) ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
				if ( (tam >= (decimais + 10)) && (tam <= (decimais + 12)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 9) ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
				if ( (tam >= (decimais + 13)) && (tam <= (decimais + 15)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 12) ) + '.' + vr.substr( tam - (decimais + 12), 3 ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
			}
			else if(decimais == 0)
			{
				if ( tam <= 3 )
				{ 
			 		objeto.value = vr ;
				}
				if ( (tam >= 4) && (tam <= 6) )
				{
					if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr(0, tam - 3) + '.' + vr.substr( tam - 3, 3 ); 
				}
				if ( (tam >= 7) && (tam <= 9) )
				{
					if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr( 0, tam - 6 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ); 
				}
				if ( (tam >= 10) && (tam <= 12) )
				{
			 		if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ); 
				}

				if ( (tam >= 13) && (tam <= 15) )
				{
					if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr( 0, tam - 12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ) ;
				}			
			}
		}
	}
	else if((window.event.keyCode != 8) && (window.event.keyCode != 9) && (window.event.keyCode != 13) && (window.event.keyCode != 35) && (window.event.keyCode != 36) && (window.event.keyCode != 46))
		{
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		}
}	
function open_page( page, name_window, x, y, w, h ){
	if ( x == undefined || x == '' ) { x = 0; }
	if ( y == undefined || y == '' ) { y = 0; }
	if ( w == undefined ) { w = 400; }
	if ( h == undefined ) { h = 300; }
	if ( name_window == undefined ) { name_window = ''; }
	window.open( page, name_window, 'statusbar,scrollbars,toolbar,resizable,top=' + x + ',left=' + y + ',width=' + w + ',height=' + h  );
}
function selecionar_linha_tabela( obj, nome ) {
	if ( obj.className == "Selecao" ) {
		obj.className = nome;
	} else {
		obj.className = "Selecao";
	}
}
function abre_site(width, height, nome) {
	var top; var left;
	top = ( (screen.height/2) - (height/2) )
	left = ( (screen.width/2) - (width/2) )
	window.open(nome, "","toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0,scrollbars=1,width="+width+",height="+height+",left="+left+",top="+top);
}
function fechar(){
	window.close()
}

	function resultado_cod() {
		if (document.procura.codigo.value == "") {
		 	alert("Favor digitar o código");
			document.procura.codigo.focus();
		} else {
			situacao = 0;
	 		if (document.procura.situacao[0].checked) {
		 		situacao = 1;
			} else if((document.procura.situacao[1].checked)) {
		 		situacao = 2;
			}
			if(situacao == 1){
				codigo = document.procura.codigo.value;
				abre_site(793,550,"detalhes.php?codigo="+codigo+"&situacao="+situacao);
			} else if (situacao == 2) {
				codigo = document.procura.codigo.value;
				abre_site(793,550,"detalhes-aluguel.php?codigo="+codigo);
			} else {
				alert("Favor informar a situação!");
			}
		}
	}
	function detalhes(codigo,situacao){
		abre_site(527,450,"detalhe.php?codigo="+codigo+"&situacao="+situacao);	
	}
	function fotos(codigo,situacao){
		abre_site(700,450,"fotos.php?codigo="+codigo+"&situacao="+situacao);	
	}
	function fotos(codigo,situacao){
		abre_site(700,450,"fotos.php?codigo="+codigo+"&situacao="+situacao);	
	}
	function fotos_2(codigo,situacao,posicao){
		abre_site(700,450,"fotos_2.php?codigo="+codigo+"&situacao="+situacao+"&posicao="+posicao);	
	}
	function _validaFormulario(frm){
		var campos = new Array();
		var mensagem = new Array();
		var temp1 = frm.campos_obrigatorios.value;
		var temp2 = frm.mensagem_preenchidos.value;
		campos = temp1.split(",");
		mensagem = temp2.split(",");
		for(i = 0; i < campos.length; i++){		
			if(campo = document.getElementById(campos[i])){
				if(campo.type == "text" || campo.type == "password"){
					if(campo.value == ""){
						alert(mensagem[i]);
						campo.focus();
						return false;
					}
				} else if(campo.type == "select-one"){
					if(campo.value == "0"){
						alert(mensagem[i]);
						campo.focus();
						return false;
					}
				} 
			}
		}
	}
startday = new Date();
	clockStart = startday.getTime();
	function initStopwatch(){ 
		var myTime = new Date(); 
        var timeNow = myTime.getTime();  
        var timeDiff = timeNow - clockStart; 
        this.diffSecs = timeDiff/1000; 
        return(this.diffSecs); 
	}
	function getSecs(){
        var mySecs = initStopwatch(); 
        var mySecs1 = ""+mySecs;
        window.setTimeout("getSecs()",slideShowSpeed);
		slideShowAuto();
	}
	function iniciar(){
		stopstatus = 0;		
		window.setTimeout("getSecs()",slideShowSpeed);
	}
	function parar(){
		stopstatus = 1;
	}
	function slideShow(){
		changeImageInfo(Imagens[imagemPosicao]);		
	}
	function slideShowAuto(){
		if(stopstatus != 1){
			imagemPosicao++;
			if(Imagens.length == imagemPosicao){
				imagemPosicao = 0;
			}
			changeImageInfo(Imagens[imagemPosicao]);			
		}
	}
	function primeiro(){
		imagemPosicao = 0;
		slideShow();
	}
	function anterior(){	
		ultima = Imagens.length - 1;
		if(imagemPosicao == 0){
			imagemPosicao = Imagens.length - 1;
		} else if (imagemPosicao == ultima) {
			imagemPosicao = ultima - 1;
		}else {
			imagemPosicao = imagemPosicao - 1;
		}
		slideShow();
	}
	function proximo(){
		imagemPosicao++;
		if(Imagens.length == imagemPosicao){
			imagemPosicao = 0;
		}
		slideShow();
	}
	function ultimo(){
		imagemPosicao = Imagens.length - 1;
		slideShow();
	}
	function changeImageInfo(imageURL,title){
		document.big_image.src = imageURL;
	}
function _validaFormulario(frm){
		var campos = new Array();
		var mensagem = new Array();
		var temp1 = frm.campos_obrigatorios.value;
		var temp2 = frm.mensagem_preenchidos.value;
		campos = temp1.split(",");
		mensagem = temp2.split(",");
		for(i = 0; i < campos.length; i++){		
			if(campo = document.getElementById(campos[i])){
				if(campo.type == "text" || campo.type == "password"){
					if(campo.value == ""){
						alert(mensagem[i]);
						campo.focus();
						return false;
					}
				} else if(campo.type == "select-one"){
					if(campo.value == "0"){
						alert(mensagem[i]);
						campo.focus();
						return false;
					}
				} 
			}
		}
	}
function SomenteNumeros()
{
	if(event.keyCode < 48 || event.keyCode > 57)
	{
		event.keyCode = 0;
			return false;
	}
	else
	{
		return true;
	}
}