function swapToDiv(msg){
	if(document.getElementById("div_usuario"))
		document.getElementById("div_usuario").style.display = "none";
	
	if(document.getElementById("div_dj"))
		document.getElementById("div_dj").style.display = "none";

	if(document.getElementById("div_casa_noturna"))
		document.getElementById("div_casa_noturna").style.display = "none";

	var div = document.getElementById("div_message")
	div.style.display = "";
	div.innerHTML = msg+"<br/>&nbsp;";
	window.location.hash = "topo";
}
function resetCity(idcampo,divloding){
	if (divloding != '') {
		var span = document.getElementById(divloding);
		if(span)
			span.innerHTML = "&nbsp;&nbsp;&nbsp;Carregando...";
	}
	var s = document.getElementById(idcampo);
	
	for(x=s.length-1;x>=0;x--){
		s.remove(x);
	}
	
	var option = document.createElement('option');
	option.value = "";
	option.text = "Cidade";
	
	try {//outros navegadores
		s.add(option,null);
	} catch(ex) {//para IE
		s.add(option);
	}
	
	option = document.createElement('option');
	option.value = "";
	option.text = "------";
	
	try {//outros navegadores
		s.add(option,null);
	} catch(ex) {//para IE
		s.add(option);
	}
}
function loadCidade(id_estado,tmp_eval,idcampo,divloding){
	resetCity(idcampo,divloding);
	if(id_estado != ""){
		var a = new Ajax();
		a.onLoad = function(){
			var s = document.getElementById(idcampo);
			var arr = this.html.split("###");//separa por registro
			var arraux = new Array();
			for(x=0;x<arr.length;x++){
				arraux[x] = arr[x].split("...");
				var option = document.createElement('option');
				option.value = arraux[x][0];
				option.text = arraux[x][1];
				
				try {//outros navegadores
					s.add(option,null);
				} catch(ex) {//para IE
					s.add(option);
				}
			}
			if(tmp_eval){
				eval(tmp_eval);
			}
			if (divloding != '') {
				var span = document.getElementById(divloding);
				span.innerHTML = "";
			}
		}
		a.get('site/inc/routines/routines.php?routine=load_cidade&id_estado='+id_estado);
	}
}
function swapForm(tipo){
	document.getElementById("div_message").style.display = "none";
	switch(tipo) {
		case 1:
				document.getElementById("div_dj").style.display = "none";
				document.getElementById("div_casa_noturna").style.display = "none";
				document.getElementById("div_usuario").style.display = "";
			break;
			
		case 2:
				document.getElementById("div_usuario").style.display = "none";
				document.getElementById("div_casa_noturna").style.display = "none";
				document.getElementById("div_dj").style.display = "";
			break;
			
		case 3:
				document.getElementById("div_usuario").style.display = "none";
				document.getElementById("div_dj").style.display = "none";
				document.getElementById("div_casa_noturna").style.display = "";
			break;		
	}
}
function swapAgencia(show){
	if(show){
		document.getElementById("div_agencia").style.display = "";
		document.getElementById("Seleciona a Agência_CMB0").selectedIndex = 0;
		document.getElementById("div_outraagencia").style.display = "none";
		document.getElementById("tr_bookings").style.display = "none";
	} else {
		document.getElementById("div_agencia").style.display = "none";
		document.getElementById("div_outraagencia").style.display = "none";
		document.getElementById("tr_bookings").style.display = "";
	}
}
function selectAgencia(id_agencia){
	if((id_agencia+"_") == "_"){
		document.getElementById("div_outraagencia").style.display = "none";
	} else if((id_agencia+"_") == "0_"){
		document.getElementById("div_outraagencia").style.display = "";
	} else {
		document.getElementById("div_outraagencia").style.display = "none";
	}
}
function enviarDj(){
	var nome = document.getElementById("Nome Artístico_TXT1");
	
	if((nome.value != "Nome Artístico") && (nome.value != "")){
		//testa genero
		if(!testaGenero()){
			alert("Selecione ao menos um gênero.");
			return false;
		}
	}
	var rep = representandoporagencia();
	if(rep != -1){
		if(rep == 1){//tem agencia
			var idagencia = document.getElementById("Seleciona a Agência_CMB0");
			if(idagencia.options[idagencia.selectedIndex].value == ""){
				alert("Selecione uma agência.");
				idagencia.focus();
				return false;
			} else if (idagencia.options[idagencia.selectedIndex].value == 0) {
				var nomea = document.getElementById("Nome da agência_TXT0");
				if((nomea.value == "Nome da agência") || (nomea.value == "")){
					alert("Preencha o nome da sua agência.");
					nomea.focus();
					return false;
				}
				
				var tela = document.getElementById("Telefone da agência_TEL0");
				if((tela.value == "Telefone da agência") || (tela.value == "")){
					alert("Preencha um telefone de contato da sua agência.");
					tela.focus();
					return false;
				}
			}
		} else {
			var tel = document.getElementById("Tefone de contato para bookings_TEL0");
			if((tel.value == "Tefone de contato para bookings") || (tel.value == "")){
				alert("Preencha um telefone de contato para bookings.");
				tel.focus();
				return false;
			}
			
			var mail = document.getElementById("E-mail de contato para bookings_EML0");
			if((mail.value == "E-mail de contato para bookings") || (mail.value == "")){
				alert("Preencha um E-mail de contato para bookings.");
				mail.focus();
				return false;
			}
		}
	}
	f.send('frm_dj');
}
function representandoporagencia(){
	var raidios = document.getElementsByName("representadoporagencia");
	for(var x=0;x<raidios.length;x++){
		if(raidios[x].checked){
			//alert("roçou:"+x);
			//alert(raidios[x].value);
			return raidios[x].value;
		} else {
			//alert("não roçou:"+x);
		}
	}
	return -1;
}
function testaGenero(){
	var total = document.getElementById("totalgenero");
	var selecionado = false;
	
	for(var x=0;x<total.value;x++){
		genero = document.getElementById("Generos"+x);
		if(genero){
			if(genero.checked){
				selecionado = true;
				break;
			}
		}
	}
	return selecionado;
}