/*-------------------------------- imagem trocar
----------------------------------------------------*/
function ProdutoImagemTrocar(imagem) {

	//
	if (imagem) {
		
		// imagem
		if(typeof imagem == "object" || imagem == "[object]")
			document.getElementById('imagem').src = imagem.src;
		else
			document.getElementById('imagem').src = imagem;
		
	}

}
/*-------------------------------------------
-------------------------------------------------*/
function imagemTrocar(imagem, obj) {
	
	//
	if (imagem)
		document.getElementById(obj).src = imagem;

	var floatimg = document.getElementById("floatimg");
		floatimg.setAttribute("src", "img/imprintTower_image004.jpg");

}
/*-------------------------------------------
-------------------------------------------------*/
function DivMostrar(obj) {
	try {	
	document.getElementById(obj).style.display = 'block';
	} catch(err) {
	}	
}

/*-------------------------------------------
---------------------------------------------*/
function DivOcultar(obj) {
	try {
		document.getElementById(obj).style.display = "none";
	} catch(err) {
	}
}


/*-------------------------------------------
-------------------------------------------------*/
function SomenteCaracter(valor, validos) {
	
	// retira caracteres invalidos da string
	var result = "";
	var aux;
	
	//
	for (var i=0; i < valor.length; i++) {
		aux = validos.indexOf(valor.substring(i, i+1));
		if (aux>=0) {
			result += aux;
		}
	}
	
	//
	return result;
	
}

/*-------------------------------------------
-------------------------------------------------*/
function ValorFormatar(campo, tammax, teclapres, decimal) {
	
	var tecla = teclapres.keyCode;
	vr = SomenteCaracter(campo.value,"0123456789");
	tam = vr.length;
	dec = decimal
	
	//
	if (tam < tammax && tecla != 8)
		tam = vr.length + 1 ; 
	
	//
	if (tecla == 8)
		tam = tam - 1 ;
	
	//
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) {
	
		if ( tam <= dec )
			campo.value = vr ;
		
		if ( (tam > dec) && (tam <= 5) )
			campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam );
		if ( (tam >= 6) && (tam <= 8) )
			campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ); 
		if ( (tam >= 9) && (tam <= 11) )
			campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam );
		if ( (tam >= 12) && (tam <= 14) )
			campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam );
		if ( (tam >= 15) && (tam <= 17) )
			campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam );
	
	}
	
}

/*----------------------------------------------------------------------------
validar form
-----------------------------------------------------------------------------*/
function ValidarForm(form) {
	
	//
	for (i=0; i<form.length; i++) {
	
		var obg = form[i].obrigatorio;
	
		//
		if (form[i].value == "" && form[i].type != 'hidden' && form[i].title != '') {
			var title = form[i].title
			alert("Digite " + title)
			form[i].focus();
			return false
		}
			
	}
		
	return true
	
}

/*----------------------------- funcoes do menu esquerdo
-------------------------------------------------------*/
function MenuVertical(obj) {
	
	// customizacao para IE 6.0
	if (navigator.appVersion.indexOf('MSIE 6') > 0 || navigator.appVersion.indexOf('MSIE 5') > 0 ) {

		// fecha outros menus
		for (i=0; i<=30; i++)
			if (document.getElementById('menu_'+i) != null)
				document.getElementById('menu_'+i).style.display = 'none'
	
		//	
		if (obj)
			if (document.getElementById(obj).style.display = 'none')
				document.getElementById(obj).style.display = 'block'
			else
				document.getElementById(obj).style.display = 'none'
				
		setTimeout("MantemVisible('"+obj+"')", 5000)
		
	} else {
	
			// fecha outros menus
			for (i=0; i<=30; i++)
				if (document.getElementById('menu_'+i) != null)
					document.getElementById('menu_'+i).style.visibility = 'hidden'
		
			// 
			if (obj)
				if (document.getElementById(obj).style.visibility = 'hidden')
					document.getElementById(obj).style.visibility = 'visible'
				else
					document.getElementById(obj).style.visibility = 'hidden'
			
		} 	

}

function MantemVisible(obj) {
	
	if (obj)
		if (document.getElementById(obj).style.display = 'block')
			document.getElementById(obj).style.display = 'none'
	
}

/*-------------------------------------------
---------------------------------------------*/
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

/*-------------------------------------------
---------------------------------------------*/
function Menu(posicao, div, bla) {
	
	//
	try {
		if (bla) {
			if (posicao) {
				document.getElementById('menu_esq').style.top = posicao+"px";
				document.getElementById('menu_esq').style.display = "block";
			}
			document.getElementById(div).style.display = "block";
		} else
			document.getElementById(div).style.display = "none";
	} catch(err) {
	}
				
}


/*-------------------------------------------
---------------------------------------------*/
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/*----------------------------------------------------------------------------
somente numeros
-----------------------------------------------------------------------------*/
function SomenteNumero(evt) {
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        return false
    }
    return true
}

/*----------------------------------------------------------------------------
Formataçao para qualquer mascara
-----------------------------------------------------------------------------*/
//Mascara(this, '##-####-####')
function Mascara(src, tecla, mask) {
        
	//
    var charCode = (tecla.which) ? tecla.which : tecla.keyCode
	
	//
	if (charCode != 8) {
		
		//
		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);

	}
	
}


