function GetXmlHttpObject()
{ 
	var objXMLHttp1=null

	if (window.XMLHttpRequest)
	{
		objXMLHttp1=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp1=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp1
}

function exibeMarcas(tipoveiculo,marca, tp)
{	


	xmlHttp1=GetXmlHttpObject()
	
	if (xmlHttp1==null)
	{
		alert ("Sem suporte a HTTP Request")
		return
	} 
	var url="ajax_marcas.php";	
	url=url+"?tipo_veiculo="+tipoveiculo+"&marca="+marca+"&tp="+tp+"&"+new Date().getTime()+"&"+Math.random();
	
	xmlHttp1.onreadystatechange=stateChanged
	xmlHttp1.open("GET",url,true)
	xmlHttp1.send(null)	
}

function exibeModelos(tipoveiculo,marca,modelo,tp)
{	

	xmlHttp2=GetXmlHttpObject()
	
	if (xmlHttp2==null)
	{
		alert ("Sem suporte a HTTP Request")
		return
	} 
	var url="ajax_modelos.php";	
	url=url+"?tipo_veiculo="+tipoveiculo+"&marca="+marca+"&tp="+tp+"&modelo="+modelo+"&"+new Date().getTime()+"&"+Math.random();
	
	xmlHttp2.onreadystatechange=stateChanged2
	xmlHttp2.open("GET",url,true)
	xmlHttp2.send(null)	
}

function exibeVersao(tipoveiculo,marca,modelo,versao,tp)
{	
	xmlHttp3=GetXmlHttpObject()
	
	if (xmlHttp3==null)
	{
		alert ("Sem suporte a HTTP Request")
		return
	} 
	var url="ajax_versao.php";	
	url=url+"?tipo_veiculo="+tipoveiculo+"&marca="+marca+"&tp="+tp+"&modelo="+modelo+"&versao="+versao+"&"+new Date().getTime()+"&"+Math.random();
	
	xmlHttp3.onreadystatechange=stateChanged5
	xmlHttp3.open("GET",url,true)
	xmlHttp3.send(null)	
}


function exibeModelosPrincipal(marca)
{	
	xmlHttp3=GetXmlHttpObject()
	
	if (xmlHttp3==null)
	{
		alert ("Sem suporte a HTTP Request")
		return
	} 
	var url="ajax_modelosPrincipal.php";	
	url=url+"?marca="+marca+"&"+new Date().getTime()+"&"+Math.random();
	
	xmlHttp3.onreadystatechange=stateChanged3
	xmlHttp3.open("GET",url,true)
	xmlHttp3.send(null)	
}


function exibeCidade(categoria, cidade)
{	
	xmlHttp4=GetXmlHttpObject()
	
	if (xmlHttp4==null)
	{
		alert ("Sem suporte a HTTP Request")
		return
	} 
	var url="ajax_cidades.php";	
	url=url+"?categoria="+categoria+"&cidade="+cidade+"&tp="+tp+"&"+new Date().getTime()+"&"+Math.random();
	
	xmlHttp4.onreadystatechange=stateChanged4
	xmlHttp4.open("GET",url,true)
	xmlHttp4.send(null)	
}


function stateChanged() 
{ 
	
    if (xmlHttp1.readyState == 4) 
	{
      
        	if (xmlHttp1.status == 200) 
			{
				document.getElementById('marcas').innerHTML = xmlHttp1.responseText;			
			}
			
			else 
			{
            	alert("Houve um problema ao obter os dados:\n" + xmlHttp1.statusText);
       		}
    }
	else
	{
		document.getElementById('marcas').innerHTML='';
	}		
}

function stateChanged2() 
{ 
	
    if (xmlHttp2.readyState == 4) 
	{
      
        	if (xmlHttp2.status == 200) 
			{
				document.getElementById('modelos').innerHTML = xmlHttp2.responseText;			
			}
			
			else 
			{
            	alert("Houve um problema ao obter os dados:\n" + xmlHttp2.statusText);
       		}
    }
	else
	{
		document.getElementById('modelos').innerHTML='';
	}		
}

function stateChanged3() 
{ 
	
    if (xmlHttp3.readyState == 4) 
	{
      
        	if (xmlHttp3.status == 200) 
			{
				document.getElementById('modelosPrincipal').innerHTML = xmlHttp3.responseText;			
			}
			
			else 
			{
            	alert("Houve um problema ao obter os dados:\n" + xmlHttp3.statusText);
       		}
    }
	else
	{
		document.getElementById('modelosPrincipal').innerHTML='';
	}		
}

function stateChanged4() 
{ 
	
    if (xmlHttp4.readyState == 4) 
	{
      
        	if (xmlHttp4.status == 200) 
			{
				document.getElementById('cidade').innerHTML = xmlHttp4.responseText;			
			}
			
			else 
			{
            	alert("Houve um problema ao obter os dados:\n" + xmlHttp3.statusText);
       		}
    }
	else
	{
		document.getElementById('cidade').innerHTML='';
	}		
}

function stateChanged5() 
{ 
	
    if (xmlHttp3.readyState == 4) 
	{
      
        	if (xmlHttp3.status == 200) 
			{
				document.getElementById('versao').innerHTML = xmlHttp3.responseText;			
			}
			
			else 
			{
            	alert("Houve um problema ao obter os dados:\n" + xmlHttp3.statusText);
       		}
    }
	else
	{
		document.getElementById('versao').innerHTML='';
	}		
}

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;
}
/* Functions that swaps images. */
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];}
}
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;
}

// Verificamos browser, versão e sistema operacional 
var isNav = false, isIE = false, isWin = false, Versao="0";

AppName = navigator.appName
AppVersion = navigator.appVersion
if ( AppName.indexOf("Netscape") != -1 )
{
  isNav = true;
  Versao = AppVersion.substring(0, 4);
  AuxStr = AppVersion.substring(AppVersion.indexOf("W"), AppVersion.indexOf(";"));
  document.captureEvents(Event.KEYDOWN);
}
else if ( AppName.indexOf("Microsoft") != -1 )
{
   isIE = true;
   Versao = AppVersion.substring((AppVersion.indexOf("E")+1), (AppVersion.indexOf("E")+6));
   AuxStr = AppVersion.substring(AppVersion.indexOf("W"), (AppVersion.length-1));
}

if ( ( isNav && AuxStr.indexOf("16") != -1 ) ||
     ( isIE && AuxStr.indexOf("3.1") != -1 ) ||
     ( AuxStr.indexOf("95") != -1 ) || ( AuxStr.indexOf("98") != -1 ) || ( AuxStr.indexOf("NT") != -1 ) || ( AuxStr.indexOf("32") != -1 ) )
{
  isWin = true;
}

NUMVER = parseFloat(Versao);
if ( NUMVER >= 5) Versao = "5";
else if ( NUMVER >= 4 ) Versao = "4";
else if ( NUMVER >= 3 ) Versao = "3";
else Versao = "2";

function ValidaConteudo_OnKeyPress( el,event,tipo,form,elemento,evento,tamanho,tipocont)
{
  var key;
  var kCode = (navigator.appName == "Netscape") ? evento.which : evento.keyCode
  eleval=elemento.value;
  eleName=elemento.name;
  frmNome=form.name;
  tLength=parseInt(elemento.value.length);
  frmLength=parseInt(document.forms.length);

  if (isNav)
    key = String.fromCharCode( event.which );
  else
    key = String.fromCharCode( event.keyCode );


  if ( isNav && (event.which == 8 || event.which == 0) )
  return true;
  
     
  for(p=0;p < frmLength;p++)
  {
   if(document.forms[p].name==frmNome)
   {
   elemntLength=parseInt(document.forms[p].elements.length)
    for(i=0;i<elemntLength;i++)
	{
		if(document.forms[p].elements[i].name == eleName)
		{
			for(k=0;k < tLength;k++)
			{
			j=i+1;
				if( (kCode !=8) && (kCode !=46))
				{
	  		          nxtElmnt=document.forms[p].elements[j].name;
						if( (elemento.value.length == tamanho) || (kCode == 9) || (kCode == 13))
						{
							document.forms[p][nxtElmnt].focus();
							break;
						}
				}
			}
		}
     }
	}
	}

    if ( ( ( tipo != "decimal" ) || ( tipo == "decimal" && ( ( key != "") ) ) ) && !ValidaCaractere( key ) )
    return false;
 
  return true;
}

function ValidaCaractere( caractere )
{
  var strValidos = "0123456789abcdefghijklmnoprqrstuvxyzwABCDEFGHIJKLMNOPRQSTUVXYZWàèìòùáéíóúâêîôûÁÉÍÓÚÂÊÎÔÛãÃÕõçÇ-+?:;.,<>_@/ "
  if ( strValidos.indexOf( caractere ) == -1 )
  {
    return false
  }
  return true
}


function ValidaConteudo_OnKeyPress2( el,event,tipo,form,elemento,evento,tamanho,tipocont)
{
  var key;
  var kCode = (navigator.appName == "Netscape") ? evento.which : evento.keyCode
  eleval=elemento.value;
  eleName=elemento.name;
  frmNome=form.name;
  tLength=parseInt(elemento.value.length);
  frmLength=parseInt(document.forms.length);

  if (isNav)
    key = String.fromCharCode( event.which );
  else
    key = String.fromCharCode( event.keyCode );


  if ( isNav && (event.which == 8 || event.which == 0))
  return true;  
     
  for(p=0;p < frmLength;p++)
  {
   if(document.forms[p].name==frmNome)
   {
   elemntLength=parseInt(document.forms[p].elements.length)
    for(i=0;i<elemntLength;i++)
	{
		if(document.forms[p].elements[i].name == eleName)
		{
			for(k=0;k < tLength;k++)
			{
			j=i+1;
				if( (kCode !=8) && (kCode !=46))
				{
	  		          nxtElmnt=document.forms[p].elements[j].name;
						if( (elemento.value.length == tamanho) || (kCode == 9) || (kCode == 13))
						{
							document.forms[p][nxtElmnt].focus();
							break;
						}
				}
			}
		}
     }
	}
	}

    if ( ( ( tipo != "decimal" ) || ( tipo == "decimal" && ( ( key != "") ) ) ) && !ValidaCaractere2( key ) )
    return false;
 
  return true;
}

function ValidaCaractere2( caractere )
{
  var strValidos = "0123456789"
  if ( strValidos.indexOf( caractere ) == -1 )
  {
    return false
  }
  return true
}


function ValidaConteudo_OnKeyPress3( el,event,tipo,form,elemento,evento,tamanho,tipocont)
{
  var key;
  var kCode = (navigator.appName == "Netscape") ? evento.which : evento.keyCode
  eleval=elemento.value;
  eleName=elemento.name;
  frmNome=form.name;
  tLength=parseInt(elemento.value.length);
  frmLength=parseInt(document.forms.length);

  if (isNav)
    key = String.fromCharCode( event.which );
  else
    key = String.fromCharCode( event.keyCode );

  if ( isNav && event.which == 8 )
  return true;  
     
  for(p=0;p < frmLength;p++)
  {
   if(document.forms[p].name==frmNome)
   {
   elemntLength=parseInt(document.forms[p].elements.length)
    for(i=0;i<elemntLength;i++)
	{
		if(document.forms[p].elements[i].name == eleName)
		{
			for(k=0;k < tLength;k++)
			{
			j=i+1;
				if( (kCode !=8) && (kCode !=46))
				{
	  		          nxtElmnt=document.forms[p].elements[j].name;
						if( (elemento.value.length == tamanho) || (kCode == 9) || (kCode == 13))
						{
							document.forms[p][nxtElmnt].focus();
							break;
						}
				}
			}
		}
     }
	}
	}

    if ( ( ( tipo != "decimal" ) || ( tipo == "decimal" && ( ( key != "") ) ) ) && !ValidaCaractere3( key ) )
    return false;
 
  return true;
}

function ValidaCaractere3( caractere )
{
  var strValidos = "0123456789ABCDEFGHIJKLMNOPRQRSTUVXWYZabcdefghijklmnopqrstuvxwyz"
  if ( strValidos.indexOf( caractere ) == -1 )
  {
    return false
  }
  return true
}
