// JavaScript - SISTEMA DE OBRAS - CEBRACE

var isNN = (navigator.appName.indexOf("Netscape")!=-1);

// Desabilita combo select quando um combo esta selecionado e vice-versa
function Desabilita(campo)
{
	if (document.form1.produto.value != "")
	{
		document.form1.aplicacao.disabled = true;
	}
	else
	{
	document.form1.aplicacao.disabled = false;
	}
	

	if (document.form1.aplicacao.value != "")
	{
		document.form1.produto.disabled = true;
	}
		else
	{
	document.form1.produto.disabled = false;
	}

}

//========================================================================
//            AVISO
//========================================================================
function Aviso(erro)
{
	alert(erro);
	return false;
}


//========================================================================
//               POP-UP PARA VISUALIZAR FOTOS
//========================================================================

function Visualizar(theURL) 
{ //v2.0
  window.open(theURL,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no');
 
}

//========================================================================
//       Redimensiona a janela no tamanho da imagem
//========================================================================
function reSizeImage() {
	//Pego o tamanho da tela Horizontal e Vertical
	var valorW = screen.width;
	var valorH = screen.height;
//	var valorW = 640;
//	var valorH = 480;
	//Pego o tamanho da imagem Horizontal e Vertical
	var width = document.getElementById('imagem').width;
	var height = document.getElementById('imagem').height;
	//Variavel que identifica se a imagem eh maior que a tela
	var estouro = false;
	//Se o tamanho Horizontal da imagem for maior que o tamanho da tela
	if ( width > valorW ) {
		//Calculo o tamanho vertical da imagem proporcional ao tamanho da tela
		height = retornaProporcional( width, height, valorW );
		width = valorW;
		//Redimensiono a imagem para o tamanho da tela
		//Diminuo um pouco a imagem para que ela seja exibida completa
		//Windows XP deixa uma barra maior na parte inferior do popup
		document.getElementById('imagem').width = width - 12;
		document.getElementById('imagem').height = height - 60;
		estouro = true;
	}
	//Se o tamanho Vertical da imagem for maior que o tamanho da tela
	if ( height > valorH ) {
		//Calculo o tamanho horizontal da imagem proporcional ao tamanho da tela
		width = retornaProporcional( height, width, valorH );
		height = valorH;
		//Redimensiono a imagem para o tamanho da tela
		//Diminuo um pouco a imagem para que ela seja exibida completa
		//Windows XP deixa uma barra maior na parte inferior do popup
		document.getElementById('imagem').width = width - 12;
		document.getElementById('imagem').height = height - 60;
		estouro = true;
	}
	if ( !estouro ) {
		width += 12;
		height += 60;
	}
	window.resizeTo(width,height);
	self.focus();
};

function retornaProporcional( x, y, valor ) {
	var retorno;
	//Calculo um valor proporcional para y de acordo com x e valor
	retorno = new Number( y / ( x / valor ) );
	return retorno.toFixed(0);
}
//========================================================================
function Redireciona(valor)
{
	document.location = valor;	
}

//------------------------------------------------------------------------
//    Imagens página de portifólio de obras

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

//================================================================================================
//Função para formatar Campo//////////////////////////////////////////////////////
//Função utilizada na página mailing.asp
function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
     var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

     if(document.all) { // Internet Explorer
       nTecla = evtKeyPress.keyCode; }
     else if(document.layers) { // Nestcape
       nTecla = evtKeyPress.which;
     }

     sValue = objForm[strField].value;

     // Limpa todos os caracteres de formatação que
     // já estiverem no campo.
     sValue = sValue.toString().replace( "-", "" );
     sValue = sValue.toString().replace( "-", "" );
     sValue = sValue.toString().replace( ".", "" );
     sValue = sValue.toString().replace( ".", "" );
     sValue = sValue.toString().replace( "/", "" );
     sValue = sValue.toString().replace( "/", "" );
     sValue = sValue.toString().replace( "(", "" );
     sValue = sValue.toString().replace( "(", "" );
     sValue = sValue.toString().replace( ")", "" );
     sValue = sValue.toString().replace( ")", "" );
     sValue = sValue.toString().replace( " ", "" );
     sValue = sValue.toString().replace( " ", "" );
     fldLen = sValue.length;
     mskLen = sMask.length;

     i = 0;
     nCount = 0;
     sCod = "";
     mskLen = fldLen;

     while (i <= mskLen) {
       bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
       bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

       if (bolMask) {
         sCod += sMask.charAt(i);
         mskLen++; }
       else {
         sCod += sValue.charAt(nCount);
         nCount++;
       }

       i++;
     }

     objForm[strField].value = sCod;

     if (nTecla != 8) { // backspace
       if (sMask.charAt(i-1) == "9") { // apenas números...
          return((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
       else { // qualquer caracter...
         return true;
       } }
     else {
        return true;
     }
   }
//================================================================================================
//Função para formata Email //////////////////////////////////////////////////////
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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+=' EMAIL INCORRETO.';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += ' EMAIL INCORRETO.\n'; }
  } if (errors) alert('ATENÇÃO!'+errors);
  document.MM_returnValue = (errors == '');
}


//--------------------------------------------------------------
function autoTab(input,len,e) {
var keyCode = (isNN) ? e.which : e.keyCode;
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
}

//---------------------------------------------------------------
//Scroll em tabela - Página de Guia de Especificação - Negocio01Guia.asp

 var oIntervBottom;
 var oIntervTop;

 function fTop(){
  window.clearInterval(oIntervTop);
  oIntervTop = window.setInterval("divScroll.scrollTop=divScroll.scrollTop-5",100); <!-- Velocidade quando sobre o Bt (CIMA)-->
 }
 function fBottom(){
  window.clearInterval(oIntervBottom);
  oIntervBottom = window.setInterval("divScroll.scrollTop=divScroll.scrollTop+5",100); <!-- Velocidade quando sobre o Bt (BAIXO)-->
 }
 function fStopBottom(){
  window.clearInterval(oIntervBottom);
 }
 function fStopTop(){
  window.clearInterval(oIntervTop);
 }
 function fTopTudo(){
  window.clearInterval(oIntervTop);
  oIntervTop = window.setInterval("divScroll.scrollTop=divScroll.scrollTop-5",20);  <!-- Velocidade quando clicado no Bt (CIMA)-->
 }
 function fBottomTudo(){
  window.clearInterval(oIntervBottom);
  oIntervBottom = window.setInterval("divScroll.scrollTop=divScroll.scrollTop+5",20); <!-- Velocidade quando Clicado no Bt (BAIXO)-->
 }
 
 //-----------------------------------------
 // Jump select - página Negocio01Guia.asp
 
 function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

//-------------------------------------------------

