	try{
		xmlhttp = new XMLHttpRequest();
		xmlhttp2 = new XMLHttpRequest();
	}catch(ee){
		try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			xmlhttp2 = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(E){
				xmlhttp = false;
				xmlhttp2 = false;
			}
		}
	}


function busca_linha(lang,id_marchi,cboDestino,divDestino,id_linea,txtLbl){
	if (!id_marchi)
	{
		xmlhttp.open("GET", "../cerca_linea.asp",true);	
		xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	}else{
		//Remover(document.getElementById(cboDestino));
		document.getElementById(divDestino).style.display='none';
		if (txtLbl!=''){
			document.getElementById(txtLbl).innerHTML='loading...';
			document.getElementById(txtLbl).style.display='';
		}
		//Abre a url
		xmlhttp.open("GET", "../cerca_linea.asp?sLang="+lang+"&idMarchi="+id_marchi+"&cboDestino="+cboDestino+"&idLinea="+id_linea,true);
		xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	}
	
	 xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4)
		{
			var texto=xmlhttp.responseText;
				document.getElementById(divDestino).style.display='';
				document.getElementById(divDestino).innerHTML="";
				if(cboDestino=="idlineacerca"){
					document.getElementById(divDestino).innerHTML="&nbsp;&nbsp;Linea:&nbsp;"+texto;
				}else{
					document.getElementById(divDestino).innerHTML=texto;
				}
			texto="";
		}
	 }
	xmlhttp.send(null)
}

function busca_linha_cerca(lang,id_marchi,cboDestino,divDestino,id_linea){
	xmlhttp2.open("GET", "../cerca_linea_amm.asp?sLang="+lang+"&idMarchiocerca="+id_marchi+"&cboDestino="+cboDestino+"&idLinea="+id_linea,true);
	xmlhttp2.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");

	 xmlhttp2.onreadystatechange=function() {
		if (xmlhttp2.readyState==4){
			var texto=xmlhttp2.responseText;
				document.getElementById(divDestino).style.display='';
				document.getElementById(divDestino).innerHTML="";
				document.getElementById(divDestino).innerHTML="&nbsp;&nbsp;Linea:&nbsp;"+texto;
			texto="";
		}
	 }
	xmlhttp2.send(null)
}

function cerca_rivenditori(marchio,regione,provincia,divDestino){
	//alert('marchio - '+marchio+' regione - '+regione+' provincia - '+provincia+'');
	if((marchio!='')&&(regione!='')&&(provincia!='')){
		document.getElementById(divDestino).innerHTML="loading...";
		xmlhttp.open("GET", "searchnegozi.asp?regione="+regione+"&marchio="+marchio+"&provincia="+provincia,true);
		xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	}
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4){
			var texto=xmlhttp.responseText;
			document.getElementById(divDestino).innerHTML="";
			document.getElementById(divDestino).innerHTML=texto;
			texto="";	
		}
	 }

	xmlhttp.send(null);
}

function cerca_reserved(marchio,tipo,divDestino){
	if((marchio!='')&&(tipo!='')){
		document.getElementById(divDestino).innerHTML="";
		document.getElementById(divDestino).innerHTML="<br>loading...";
		xmlhttp.open("GET", "cerca_reserved.asp?tipo="+tipo+"&marchi="+marchio,true);
		xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");

		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4){
				var texto=xmlhttp.responseText;
				document.getElementById(divDestino).innerHTML="";
				document.getElementById(divDestino).innerHTML=texto;
				texto="";	
			}
		 }
	
		xmlhttp.send(null);

	}else{
		document.getElementById(divDestino).innerHTML="";
		document.getElementById(divDestino).innerHTML="<br><font color='#ff0000'>Compilare tutti i due campi.</font>";		
	}
	
}

function cerca_prodotti(lang,marchio,tipo,divDestino){
document.getElementById(divDestino).innerHTML="";
	if(marchio!=''){
		document.getElementById('linha_form').style.display="";
		
		document.getElementById('texto_pagina').style.display="";
		document.getElementById('link_volta').style.display="none";
		
		document.getElementById(divDestino).innerHTML="";
		document.getElementById(divDestino).innerHTML="<br>&nbsp;&nbsp;&nbsp;&nbsp;loading...";
		xmlhttp.open("GET", "cerca.asp?lang="+lang+"&prodotto="+tipo+"&marchi="+marchio,true);
		xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
		
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4){
				var texto=xmlhttp.responseText;
				//var a = window.open('','','left=0,width=1000,height=1000');
				//self.focus();
				//a.document.open("text/html");
				//a.document.write(texto);
				document.getElementById(divDestino).innerHTML="";
				document.getElementById(divDestino).innerHTML="<br>"+texto;
				texto="";	
			}
		 }
	
		xmlhttp.send(null);
		
	}else{

		document.getElementById(divDestino).innerHTML="";
		document.getElementById(divDestino).innerHTML="<br>&nbsp;&nbsp;&nbsp;&nbsp;<font color='#ff0000'>Compilare il campo Marchio.</font>";
		
	}
	
}

function mostra_prodotti(idMarca,tipo,idLinha,lang,idProdotto,divDestino){
document.getElementById(divDestino).innerHTML="";
	if(idProdotto!=''){
		document.getElementById('linha_form').style.display="none";
		document.getElementById('texto_pagina').style.display="none";
		document.getElementById('link_volta').style.display="";
		document.getElementById('link_volta').innerHTML="<a href=\"javascript:cerca_prodotti(\'"+lang+"\',\'"+idMarca+"\',\'"+tipo+"\',\'"+divDestino+"\')\">Torna alla pagina precedente</a><br>";
		document.getElementById(divDestino).innerHTML="";
		document.getElementById(divDestino).innerHTML="&nbsp;&nbsp;&nbsp;&nbsp;loading...";
		xmlhttp.open("GET", "cerca.asp?idProdotto="+idProdotto+"&lang="+lang,true);
		xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
		
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4){
				var texto=xmlhttp.responseText;
				//var a = window.open('','','left=0,width=1000,height=1000');
				//self.focus();
				//a.document.open("text/html");
				//a.document.write(texto);
				document.getElementById(divDestino).innerHTML="";
				document.getElementById(divDestino).innerHTML=texto;
				texto="";	
			}
		 }
	
		xmlhttp.send(null);
		
	}else{

		document.getElementById(divDestino).innerHTML="";
		document.getElementById(divDestino).innerHTML="&nbsp;&nbsp;&nbsp;&nbsp;<font color='#ff0000'>Compilare il campo Marchio.</font>";
		
	}
	
}

function cerca_agenti(marchio,contatto,divDestino){
	if((marchio!='')&&(contatto!='')){
		document.getElementById(divDestino).innerHTML="loading...";
		xmlhttp.open("GET", "indirizzi.asp?contatto="+contatto+"&marchio="+marchio,true);
		xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	}
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4){
			var texto=xmlhttp.responseText;
			document.getElementById(divDestino).innerHTML="";
			document.getElementById(divDestino).innerHTML=texto;
			texto="";	
		}
	 }

	xmlhttp.send(null);
}


function busca_regione(marchio,divDestino){
	if(marchio!=''){
		document.getElementById(divDestino).innerHTML="loading...";
		xmlhttp.open("GET", "../cerca_regione.asp?marchio="+marchio,true);
		xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");

		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4){
				var texto=xmlhttp.responseText;
				document.getElementById(divDestino).innerHTML="";
				document.getElementById(divDestino).innerHTML=texto;
				
				texto="";	
			}
		 }

		xmlhttp.send(null);
		
	}
	
}


function busca_provincia(regione,id_marchi,acao,labelDestino,divDestino){
	if (!id_marchi)
	{
		//Abre a url
		if (acao==1){
			document.getElementById(labelDestino).innerHTML="Regione:";
		}else{
			document.getElementById(labelDestino).innerHTML="Provincia:";
		}
		document.getElementById(divDestino).innerHTML="<select name=\"provincia\" class=\"borda\" disabled><option value=\"\"></option></select>";
		xmlhttp.open("GET", "../cerca_provincia.asp",true);	
		xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");

	}
	else
	{

		document.getElementById(divDestino).innerHTML="loading...";
		if (acao==1){
			document.getElementById(labelDestino).innerHTML="Regione:";
			xmlhttp.open("GET", "../cerca_indirizzi.asp?regione="+regione+"&marchio="+id_marchi,true);
			xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
		}else{
			document.getElementById(labelDestino).innerHTML="Provincia:";
			xmlhttp.open("GET", "../cerca_provincia.asp?regione="+regione+"&marchio="+id_marchi,true);
			xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
		}				
	}
	
	 xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4)
		{
		
			var texto=xmlhttp.responseText;

			//if(texto.length==264){
			//	document.getElementById('linha_provincia').style.display='none';
			//}else{
				document.getElementById('linha_provincia').style.display='';				
			//}
			
			document.getElementById(divDestino).innerHTML="";
			document.getElementById(divDestino).innerHTML=texto;
			texto="";
			
		}

	 }

	xmlhttp.send(null)

}

function cadastra_tipoprodotto(lang,divCampoCad,cboDestino,divDestino,valueCampo){

document.getElementById(divDestino).innerHTML="";
document.getElementById(divCampoCad).style.display="none";
document.getElementById('mensagem_tipo').style.display="none";

xmlhttp = new XMLHttpRequest();

	if (valueCampo!=''){
		//Abre a url
		xmlhttp.open("GET", "../cadastra_tipoprodotto.asp?sLang="+lang+"&campo="+valueCampo,false);
		xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");			
	}
	
	 xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4)
		{
		
			var texto=xmlhttp.responseText;
			texto = texto.split("|");

			if(texto[1]!=''){
				document.getElementById('mensagem_tipo').style.display="";
				document.getElementById('mensagem_tipo').innerHTML=texto[1];
			}
			
			document.getElementById(divDestino).innerHTML="";
			document.getElementById(divDestino).innerHTML=texto[0];
			texto="";
			
		}

	 }

	xmlhttp.send(null);

}

function cadastra_linea(lang,divCampoCad,cboDestino,divDestino,valueCampo,idMarca){

document.getElementById(divDestino).innerHTML="";
document.getElementById(divCampoCad).style.display="none";
document.getElementById('mensagem_linea').style.display="none";

xmlhttp = new XMLHttpRequest();

	if (valueCampo!=''){
		//Abre a url
		xmlhttp.open("GET", "../cadastra_linea.asp?sLang="+lang+"&campo="+valueCampo+"&idmarchio="+idMarca,false);
		xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");			
	}
	
	 xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4)
		{
		
			var texto=xmlhttp.responseText;
			texto = texto.split("|");

			if(texto[1]!=''){
				document.getElementById('mensagem_linea').style.display="";
				document.getElementById('mensagem_linea').innerHTML=texto[1];
			}
			
			document.getElementById(divDestino).innerHTML="";
			document.getElementById(divDestino).innerHTML=texto[0];
			texto="";
			
		}

	 }

	xmlhttp.send(null);

}

function cadastra_marca(lang,divCampoCad,cboDestino,divDestino,valueCampo){

document.getElementById(divDestino).innerHTML="";
document.getElementById(divCampoCad).style.display="none";
document.getElementById('mensagem_marchio').style.display="none";

xmlhttp = new XMLHttpRequest();

	if (valueCampo!=''){
		//Abre a url
		xmlhttp.open("GET", "../cadastra_marchio.asp?sLang="+lang+"&campo="+valueCampo,false);
		xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");			
	}
	
	 xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4)
		{
		
			var texto=xmlhttp.responseText;
			texto = texto.split("|");

			if(texto[1]!=''){
				document.getElementById('mensagem_marchio').style.display="";
				document.getElementById('mensagem_marchio').innerHTML=texto[1];
			}
			
			document.getElementById(divDestino).innerHTML="";
			document.getElementById(divDestino).innerHTML=texto[0];
			texto="";
			
		}

	 }

	xmlhttp.send(null);

}

function addNewOption(destino,varText,varValue)
{

	opcao = document.createElement("option");
	opcao.value = varText;
	opcao.text = varValue + "";


	// verifica se já existe o grupo desejado entre os grupos escolhidos
	for (i=0;i<=destino.options.length;i++)
	{

		if (i>=1) // o campo grupos escolhidos tem registros
		{
			if (destino.options(i-1).text.indexOf(opcao.text) != -1)
			{
				add=0; //se o grupo desejado existe entre os grupos escolhidos, não adiciona novamente
			}
		}
		else if (i==0)
		{
			add = 1; // o campo grupos escolhidos tá vazio, então pode adicionar
		}
	}


	if (add==1)
	{
		opcao.text = "" + varValue + "";
		destino.add(opcao,1); //incluí item nos grupos escolhidos
	}
}

function Remover(deonde){
	var itens = deonde;
    for (e=itens.options.length; e >= 0; e--){
		itens.remove(e);
	}
}