Siglas = new Array(); // cria vetor Siglas[]
SiglasIndex = 0;
Cidades = new Array(); // cria vetor Cidades[]
CidadeIndex = 0;

function matriz_cidades(cod,nome){ 
this.cod=cod; 
this.nome=nome;
}


function matriz_siglas(id,sigla){ 
this.id=id; 
this.sigla=sigla;
}


/*cod = "1";
nome = "Animais";
Cidades[CidadeIndex] = new matriz_cidades(cod,nome);
CidadeIndex++;

cod = "2";
nome = "Automóveis";
Cidades[CidadeIndex] = new matriz_cidades(cod,nome);
CidadeIndex++;

*/
/*
limite = Cidades.length;
for(i=0;i<limite;i++){
document.write("Código: "+Cidades[i].cod+"<br>");
document.write("Grupo: "+Cidades[i].nome+"<br>");
if((i+1)<limite)document.write("<p>");
}
*/

function imprimirCidades()
{
	limite = Cidades.length;
	for(i=0;i<limite;i++)
	{		
		if((i+1)<limite)document.write("<p>");
	}
}


function populaCombo(obj)
{
	limite = Cidades.length;
	total = obj.length;
	for(i=(total-1);i>=0;i--)
	{
		obj.remove(i); 
	}
	
	novo = document.createElement("OPTION");
	novo.text = "Selecione uma cidade";
	novo.value = "";
	obj.options.add(novo);
	
	for(i=0;i<limite;i++)
	{
		novo = document.createElement("OPTION");
		novo.text = Cidades[i].nome;
		novo.value = Cidades[i].cod;
		obj.options.add(novo);
	}
}

function buscaLojista(objUF, objCidade)
{
	//alert(objUF.selectedIndex);
	//alert(objCidade.selectedIndex);
	
	if(objUF.selectedIndex != 0 && objCidade.selectedIndex != 0)
	{
	
		window.open("default.asp?ufid=" + objUF.value + "&cidadeid=" + objCidade.value,"_parent");
		
	}
	else
	{
		if(objUF.selectedIndex == 0 && objCidade.selectedIndex == 0)
		{
			document.getElementById("err11").style.display = "none";
			document.getElementById("err12").style.display = "block";
			document.getElementById("err13").style.display = "none";
		}
		
		if(objUF.selectedIndex != 0 && objCidade.selectedIndex == 0  && objCidade.length > 1)
		{
			document.getElementById("err11").style.display = "block";
			document.getElementById("err12").style.display = "none";
			document.getElementById("err13").style.display = "none";
		}
		
		if(objUF.selectedIndex != 0 && objCidade.selectedIndex == 0 && objCidade.length == 1)
		{
			document.getElementById("err11").style.display = "none";
			document.getElementById("err12").style.display = "none";
			document.getElementById("err13").style.display = "block";
		}
	}
}

function buscaRepresentante(objUF)
{
	if(objUF.selectedIndex != 0)
	{
		window.open("default.asp?ufid=" + objUF.value,"_parent");
	}
	else
	{
		document.getElementById("err2").style.display = "block";
	}
}


function sendToActionScript(value) 
{
	thisMovie("map").sendToActionScript(value);
}


function setMap(obj)
{	
	for(i=0;i<SiglasIndex;i++)
	{  
		if(obj.options[obj.selectedIndex].value == Siglas[i].id)
		{
			sendToActionScript(Siglas[i].sigla);			
		}
	}
}


 function thisMovie(movieName) {
	 if (navigator.appName.indexOf("Microsoft") != -1) {
		 return window[movieName];
	 } else {
		 return document[movieName];
	 }
 }


function reloadIFrame(obj) 
 {
	   var uf = obj.options[obj.selectedIndex].value;
	   //alert("populaCidade.asp?ufId=" + uf);
	   window.open("populaCidade.asp?ufId=" + uf,"cidades"); 
	   setMap(obj);
 }


function setCombosEstados(objCbo1, objCbo2, valueSigla)
{
	var ufId = 0;

	for(i=0;i<SiglasIndex;i++)
	{  		
		if(Siglas[i].sigla == valueSigla)
		{
			ufId = Siglas[i].id
		}
	}

	for(i=0;i<objCbo1.options.length;i++)
	{		
		if( objCbo1.options[i].value == ufId )
		{
			if (objCbo2) {
				window.open("populaCidade.asp?ufId=" + ufId,"cidades");
			}
			
			objCbo1.options[i].selected = true;		
		}
	}
}


function sendToJavaScript(value) 
{
	setCombosEstados(document.getElementById('cboLojista'), document.getElementById('cboLojistaCidade'),value);
}