function populateSelects(){
	var call_select 		= document.getElementById('call_select');
	var call_select_ext 	= document.getElementById('call_select_extended');
	var count_index 		= 1;
	
	/* Eventos */
	call_select.onchange = function(){
		if(this.options[this.selectedIndex].value == "extended"){
			call_select_ext.style.display = '';
			
			// Zera o departamento
			config.dpto 	= "";
			config.origem 	= "";
			
			// Populando o Select Auxiliar
			populateExtendedSelects(this.options[this.selectedIndex].text, call_select_ext);
			
		} else {
			call_select_ext.style.display = 'none';
			config.dpto 	= this.options[this.selectedIndex].value;
			config.origem 	= this.options[this.selectedIndex].text;
		}
	};
	
	/* Populando o select */
	for(site in sites){
		
		// Insere opção vazia e a seleciona
		call_select.options[0] = new Option(' ... ', '');
		call_select.selectedIndex = 0;
		
		if(sites[site].sections !== undefined){
			call_select.options[count_index] = new Option(site, 'extended');
		} else {
			call_select.options[count_index] = new Option(site, sites[site].url);
		}
		count_index++;
	};
}

function populateExtendedSelects(node, target){	
	for(site in sites){
		
		// Insere opção vazia e a seleciona
		target.options[0] = new Option(' ... ', '');
		target.selectedIndex = 0;
		
		if(node == site){
			for(var i = 0; i < sites[site].sections.length; i++)
			{
				target.options[i+1] = new Option(sites[site].sections[i].label, sites[site].sections[i].url);
			}
		}
	}
	
	target.onchange = function(){
		var parent_select = document.getElementById('call_select');
	
		config.dpto = this.options[target.selectedIndex].value;
		config.origem = parent_select.options[parent_select.selectedIndex].text + " : " + this.options[target.selectedIndex].text;
	}
}

function doSubmit( f ){
	if(f){
		if(config.dpto == "" || config.dpto == undefined){
			alert("Selecione o tipo de atendimento");
			document.getElementById('call_select').focus();
			
			return false;
		}else{
			var SEPARADOR = (config.dpto.indexOf('asp') > -1 || config.dpto.indexOf('htm') > -1 || config.dpto.indexOf('html') > -1) ? "?" : "&";
			window.location = config.dpto + SEPARADOR + "origem=" + config.origem;
			
			return false;
		}
	}
}

function resizeWindow(win, winWidth, winHeight)
{
	var posX = ((screen.availWidth - winWidth) / 2);
	var posY = ((screen.availHeight - winHeight) / 2);
	
	win.resizeTo(winWidth, winHeight);
	win.moveTo(posX, posY);
	win.focus();
}