// JavaScript Document

$(function(){	
	//return false;
	
	var urlDirHome 	= '/tvembratel/listarestadoscidades';
	var postHome 	= 'task=estado';
	$.ajax({
		async:false,
		type: "POST",
		dataType: "html",
		contentType: "application/x-www-form-urlencoded",
		url: urlDirHome,
		data: postHome,
		beforeSend: ajaxListarEstadoAguarde,
		error: 		ajaxListarEstadoError,
		success:	ajaxListarEstadoSuccess
	});
	return false;
})
function ajaxListarEstadoAguarde(){
	$('#select_central_estado').html("<option value='0'>aguarde...</option>");
}
function ajaxListarEstadoError(){
	$('#select_central_estado').html("<option value='0'>erro de conexao...</option>");
}
function ajaxListarEstadoSuccess(dados){
	dados = $.trim(dados);
	$('#select_central_estado').html(dados);
	//alert(dados);

	$('#select_central_estado').change(function(){
		//uf_estado = $('#select_central_estado').val();
		// functionGetCidades(uf);		
	});
	
	$('#frm_estado').submit(function(){
		//alert(uf);
		//setEstado($('#select_central_estado').val())
		
		if( $('#select_central_estado').val()==0 ){
			alert('Selecione o estado!');
			return false;
		}
		
		var action = $('#frm_estado').attr('action');
		var post030220101138 	= 'uf_estado='+$('#select_central_estado').val();
		$.ajax({
			async:false,
			type: "POST",
			dataType: "html",
			contentType: "application/x-www-form-urlencoded",
			url: action,
			data: post030220101138,
			beforeSend: function(){
				},
			error: 	 function(){
					alert('erro de conexao!');
				},
			success:  function(dados){
					window.location.href = '';					
				},
		});
		return false;
	});	
	
}

function setEstado()
{
	
}
/*
function functionGetCidades(uf)
{	
	// var uf = $('#central_estado').val();
	//alert('teste'+uf);
	
	if( uf!='0' )
	{
		var urlDir 	= '/tvembratel/listarestadoscidades';
		var post 	= 'task=cidade&uf='+uf;
		$.ajax({
			async:false,
			type: "POST",
			dataType: "html",
			contentType: "application/x-www-form-urlencoded",
			url: urlDir,
			data: post,
			beforeSend: ajaxListarCidadesAguarde,
			error: ajaxListarCidadesError,
			success:ajaxListarCidadesSuccess
		});
		return false;
	}
	else
	{
		$('#select_central_cidade').html("<option value='0' class='estado' id='0' >Escolha seu estado</option>");	
	}
}
function ajaxListarCidadesAguarde(){
	$('#select_central_cidade').html('<option>aguarde...</option>');
}
function ajaxListarCidadesError(){
	$('#select_central_cidade').html('<option>erro de conexao...</option>');
}
function ajaxListarCidadesSuccess(dados){
	dados = $.trim(dados);
	$('#select_central_cidade').html(dados);
	$('#select_central_cidade').change(function(){
		$('#form_estado_cidade').submit(functionGetCentrais);
	});
}
*/


/*
// PEGA AS CENTRAIS DE ATENDIMENTO
function functionGetCentrais()
{
	var id_municipio = $('#select_central_cidade').val();
	//alert(id_municipio);
	if( id_municipio!='0' )
	{		
		var urlDir 	= '/tvembratel/listarcentraideatendimento';
		var post 	= 'id_municipio='+id_municipio;
		$.ajax({
			async:false,
			type: "POST",
			dataType: "html",
			contentType: "application/x-www-form-urlencoded",
			url: urlDir,
			data: post,
			beforeSend: ajaxListarCentraisAguarde,
			error: ajaxListarCentraisError,
			success:ajaxListarCentraisSuccess
		});
		return true;
	}
	else
	{
		$('#centrais_title').fadeTo(1000,0,function(){
			$('#centrais_title').css('display','none');
		});	
		$('#centrais_content').fadeTo(1000,0,function(){
			$('#centrais_content').css('display','none');
		});	
	}
	return true;
}


function ajaxListarCentraisAguarde(){
	//$('#select_central_cidade').html('<option>aguarde...</option>');
}
function ajaxListarCentraisError(){
	$('#centrais_content').html('erro de conexao, tente novamente!');
}
function ajaxListarCentraisSuccess(dados){
	dados = $.trim(dados);
	
	//alert(dados);
	/*
	$('#centrais_title').fadeTo(1,0,function(){
		$('#centrais_title').css('display','block');
		$('#centrais_title').fadeTo(600,1,function(){});
	});	
	$('#centrais_content').fadeTo(1,0,function(){
		$('#centrais_content').html(dados);
		$('#centrais_content').css('display','block');
		$('#centrais_content').fadeTo(600,1,function(){});
	});	
	* /	
}
*/