<!--
//INICIO - Funcoes gerais
function Combotensao(valor,cb, msg)
{
	if (!window.confirm (msg))
	{
	    document.getElementById(cb).value = valor;
	}
	
	//Combotensao('Todos os produtos serão configurados para a nova voltagem. Confirma?');
}


//Formata CPF
function FormataCPF(pForm,pCampo,pTamMax,pPos1,pPos2,pPosTraco,pTeclaPres)
{
	var wTecla, wVr, wTam;	
	var nerros=true;
	
    wTecla = pTeclaPres.keyCode;
    
	wVr = pForm[pCampo].value;
	wVr = wVr.toString().replace( "-", "" );
	wVr = wVr.toString().replace( ".", "" );
	wVr = wVr.toString().replace( ".", "" );
	wVr = wVr.toString().replace( "/", "" );
	wTam = wVr.length ;
	

	if (wTecla == 13) {
		nerros = true;
		return nerros;
	}

	if (wTam < pTamMax && wTecla != 8) 
	{ 
	   wTam = wVr.length + 1 ; 
	}

	if (wTecla == 8 ) 
	{ 
	   wTam = wTam - 1 ; 
	}
			
	if ( wTecla == 8 || wTecla == 88 || (wTecla >= 48 && wTecla <= 57) || (wTecla >= 96 && wTecla <= 105) )
	{
		if ( wTam <= 2 )
		{
	 		pForm[pCampo].value = wVr ;
		}
		if (wTam > pPosTraco && wTam <= pTamMax) 
		{
	       wVr = wVr.substr(0, wTam - pPosTraco) + '-' + wVr.substr(wTam - pPosTraco, wTam);
		}
		if ( wTam == pTamMax)
		{
		      wVr = wVr.substr( 0, wTam - pPos1 ) + '.' + wVr.substr(wTam - pPos1, 3) + '.' + wVr.substr(wTam - pPos2, wTam);
		}
		pForm[pCampo].value = wVr;
		pForm[pCampo].value = toInteger(pForm[pCampo].value);
		nerros=true;
	}
	else
	{
		
		pForm[pCampo].value = toInteger(pForm[pCampo].value);
		nerros = false;
		
		
	}

	if (wTecla == 9) nerros = true;
	return nerros;
	
}


function toInteger(checkString)
{
 var newString = "";    
 var count = 0;         
    for (i = 0; i < checkString.length; i++) {
        ch = checkString.substring(i, i+1);
        if (ch >= "0" && ch <= "9") 
        {
            newString += ch;
        }
        else
        {
         if (ch == "-") newString += ch;
         if (ch == ".") newString += ch;
         if (ch == "/") newString += ch;
        }
    }
    
    return newString; //checkString;
}


//Valida CPF e CNPJ
function ClearStr(str, vchar)
{
  while((cx=str.indexOf(vchar))!=-1)
  {		
    str = str.substring(0,cx)+str.substring(cx+1);
  }
  return(str);
}

function ParseNumb(c)
{
  c=ClearStr(c,"-");
  c=ClearStr(c,"/");
  c=ClearStr(c,",");
  c=ClearStr(c,".");
  c=ClearStr(c,"(");
  c=ClearStr(c,")");
  c=ClearStr(c," ");
  if((parseFloat(c) / c != 1))
  {
    if(parseFloat(c) * c == 0)
    {
      return(c);
    }
    else
    {
      return(0);
    }
  }
  else
  {
    return(c);
  }
  return(c);
}

function Verify(source, arguments)
{
	var CNUMB = arguments.Value
	var CTYPE='CPF';

  if (CNUMB.split('1').length > 9 ||
	  CNUMB.split('2').length > 9 ||
	  CNUMB.split('3').length > 9 ||
	  CNUMB.split('4').length > 9 ||
	  CNUMB.split('5').length > 9 ||
	  CNUMB.split('6').length > 9 ||
	  CNUMB.split('7').length > 9 ||
	  CNUMB.split('8').length > 9 ||
	  CNUMB.split('9').length > 9) {
    arguments.IsValid = false;
	return;
  }

  CNUMB=ParseNumb(CNUMB)
  if(CNUMB == 0)
  {
    arguments.IsValid = false;
	return;
  }
  else
  {
    g=CNUMB.length-2;
    if(TestDigit(CNUMB,CTYPE,g))
    {
      g=CNUMB.length-1;
      if(TestDigit(CNUMB,CTYPE,g))
      {	
		arguments.IsValid = true;
		return;

      }
      else
      {
		arguments.IsValid = false;
		return;
      }
    }
    else
    {
	    arguments.IsValid = false;
		return;
    }
  }
}

function TestDigit(CNUMB,CTYPE,g)
{
  var dig=0;
  var ind=2;
  for(f=g;f>0;f--)
  {
    dig+=parseInt(CNUMB.charAt(f-1))*ind;
    if (CTYPE=='CNPJ')
    { if(ind>8) {ind=2} else {ind++} }
    else
    { ind++ }
  }
  dig%=11;
  if(dig<2)
  {
    dig=0;
  }
  else
  {
    dig=11-dig;
  }
  if(dig!=parseInt(CNUMB.charAt(g)))
  {
    return(false);
  }
  else
  {
    return(true);
  }
}

function TESTA(CNUMB,CTYPE)
{
  if(Verify(CNUMB, CTYPE))
  {
    alert(CTYPE+" válido!");
  }
  else
  {
    alert(CTYPE+" inválido!");
  }
  return;
}

//Tabulação automática
var VerifiqueTAB=true;
function Mostra(quem, tammax) {
	//if (quem.value.length < tammax) {VerifiqueTAB=true;} else {VerifiqueTAB=false;}
	if ( (quem.value.length == tammax) && (VerifiqueTAB) ) {
		var i=0,j=0, indice=-1;
		for (i=0; i<document.forms.length; i++) {
			for (j=0; j<document.forms[i].elements.length; j++) {
				if (document.forms[i].elements[j].name == quem.name) {
					indice=i;
					break;
				}
			}
			if (indice != -1)
		         break;
		}
		for (i=0; i<=document.forms[indice].elements.length; i++) {
			if (document.forms[indice].elements[i].name == quem.name) {
				while ( (document.forms[indice].elements[(i+1)].type == "hidden") &&
						(i < document.forms[indice].elements.length) ) {
							i++;
				}
				document.forms[indice].elements[(i+1)].focus();
				VerifiqueTAB=false;
				break;
			}
		}
	}
}

//Parar tabulação automática
function PararTAB() 
{ 
   VerifiqueTAB=false; 
} 


//Manter apenas números
var keyCodigo = 0;
function soNumeroPress(evento){

	if (keyCodigo == 0){
		keyCodigo = evento.keyCode;
	}
	if ((keyCodigo == 8 || keyCodigo == 13 || keyCodigo == 9 || keyCodigo == 71 || keyCodigo == 46 || keyCodigo  == 37  || keyCodigo  == 39) || (keyCodigo >= 48 && keyCodigo <= 57) || (keyCodigo >= 96 && keyCodigo <= 105)) 
	{
		VerifiqueTAB=true; 

		return true;

	} else 
	{
		   if (detectar('B')=="NP")
			{
			 return true;
			}	
		   else	 	
			return false;
	}
}

function soNumeroDown(evento){

//alert(keyCodigo);
	keyCodigo = evento.keyCode;
	if ((keyCodigo == 8 || keyCodigo == 13 || keyCodigo == 9 || keyCodigo == 46) || (keyCodigo >= 48 && keyCodigo <= 57) || (keyCodigo >= 96 && keyCodigo <= 105) ){ 
		VerifiqueTAB=true; 
		
		return true;

	} else {
		   if (detectar('B')=="NP")
			{
			 return true;
			}	
		   else	 	
			return false;


	}
}

var detect = navigator.userAgent.toLowerCase();
var thestring;	
var versao = parseFloat(navigator.appVersion);
function detectar(tipo)
{ 
	var OS,browser,version,total;
	var retorno
	if (checkIt('konqueror'))
	{
		browser = "Konqueror";
		OS = "Linux";
	}
	else if (checkIt('omniweb')) browser = "OmniWeb"
	else if (checkIt('opera')) browser = "Opera"
	else if (checkIt('webtv')) browser = "WebTV";
	else if (checkIt('icab')) browser = "iCab"
	else if (checkIt('msie')) browser = "IE"
	else if (!checkIt('compatible'))
	{
		browser = "NP"
		version = detect.charAt(8);
	}
	else browser = "An unknown browser";

	
	
	if (!version) version = detect.charAt(place + thestring.length);
	
	if (!OS)
	{
		if (checkIt('linux')) OS = "Linux";
		else if (checkIt('x11')) OS = "Unix";
		else if (checkIt('mac')) OS = "Mac"
		else if (checkIt('win')) OS = "Windows"
		else OS = "an unknown operating system";
	}
	
	if (tipo=='B')
	  retorno = browser
 	else if (tipo=='O') retorno = OS

    return retorno 	
}

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

// FIM DO SCRIPT  --------------------------------------------------

function delete_item() {
	if (window.confirm ("Deseja realmente excluir o item?")) return true
	else return false
}


// Manter posição da página scroll

function ScrollIt(){
    window.scrollTo(document.frmDefault.PageX.value, document.frmDefault.PageY.value);
    }
function setcoords(){
    var myPageX;
    var myPageY;
    if (document.all){
        myPageX = document.body.scrollLeft;
        myPageY = document.body.scrollTop;
        }
    else{
        myPageX = window.pageXOffset;
        myPageY = window.pageYOffset;
        }
    document.frmDefault.PageX.value = myPageX;
    document.frmDefault.PageY.value = myPageY;
    }

// Final posição da página scroll

// PopUp
function PopUp(theURL,winName, width, height, top, left, features) { //v2.0
		if(navigator.appName=="Microsoft Internet Explorer")
		{
	  		newwindow=window.open(theURL,winName ,'width=' + width + ',height=' + height + ',top=' + top + ',left=' + left + features);
	  		if (window.focus) {newwindow.focus()}
		}
		else
		{
			newwindow=window.open(theURL, winName, 'location=0,fullscreen=0,menubar=0,toolbar=0,status=0,screenX=' + left + ',screenY=' + top + ',resizable=1,width=' + width + ',height=' + height);
	  		if (window.focus) {newwindow.focus()}
		}
		//return false;
	}

 function PopUp2(theURL,winName, width, height, top, left, features) 
	{ //v2.0
		if(navigator.appName=="Microsoft Internet Explorer")
		{
	  		newwindow=window.open(theURL,winName ,'width=' + width + ',height=' + height + ',top=' + top + ',left=' + left + features);
	  		if (window.focus) {newwindow.focus()}
		}
		else
		{
			newwindow=window.open(theURL, winName, 'location=0,fullscreen=0,menubar=0,toolbar=0,status=0,screenX=' + left + ',screenY=' + top + ',resizable=1,width=' + width + ',height=' + height);
	  		if (window.focus) {newwindow.focus()}
		}
		return false;
	}


// Exemplo chamada
//		PopUp('/Visita/c_visita.asp?acao=PesquisarCliente&nome_cliente=' + frmInclusao.nome_cliente.value,'buscacliente','width=282,height=282,top=50,left=300')


//Final PopUp

//-->
function verificaNumero(obj)
{  
  if (obj.value.length < 1)
 {
	obj.value=0;
 }else
 	if (isNaN(obj.value.substring(0,1)))
	{
		obj.value=0;
	}
	if (obj.value.substring(0,1)=="")
	{
		obj.value=0;
	}

}

function Copia(pForm,obj,nomecampo)
{
	pForm[nomecampo].value= obj.value;
}

//Posicao Inicial DIV

function ScrollItdiv(varPosicao, varDiv){
    document.getElementById(varDiv).scrollTop = varPosicao;
    }

function setcoordsdiv(myPageY){
    document.frmDefault.PageY.value = myPageY;
    }


//-->