// JavaScript Document

$(document).ready(function() { 
	
	$('input[type=text],input[type=password],textarea').keyup(function() { 
		if($(this).val().length > 0)
			$(this).css({borderColor:'#dbdfdb'}); 
	});
	
});



values = '';
function getCheckboxValues(name) {
	$('input[type=checkbox][name='+name+']:checked').each(function()
	{
		if($(this).val()!='Outro')
		{
			if(values == '')
				values += $(this).val();
			else
				values += ', '+$(this).val();
		}
		else
		{
			values += ', '+$('#'+name+'_outro').val();
		}
	});
	temp = values;
	values = '';
	return temp;
}

value = '';
function getRadioValue(name) {
	$('input[type=radio][name='+name+']:checked').each(function()
	{
		if($(this).val()!='Outro')
			value = $(this).val();
		else
		if(value != '')
			value = ', '+$('#'+name+'_Outro').val();
		else
			value = $('#'+name+'_Outro').val();
	});
	temp = value;
	value = '';
	return temp;

}
tipo='';
msg ='';
function setFocus(id) { $('#'+id).css({borderColor:"#FF0000"}); $('#'+id).focus(); }
function finishAjax(response) {
	if(response == 1) 
	{
		//window.location = '<?=$L?>cadastro/ok/'+tipo;
		if(msg=='') alert('Mensagem enviada com sucesso!');
		else alert(msg);
		$('form').each(function() {
			this.reset();						
		});
	}
	else { var err = response.split(','); alert(err[1]); setFocus(err[2]); }
}

endereco = '';


function validaNews() {
	$.post("news.php", {
	nome: $('#nome_news').val(),
	email: $('#email_news').val()
	},	function(response) {
		msg = 'Cadastro efetuado com sucesso!';
		finishAjax(response);
	});
	return false;
}

function removerNews() {
	$.post("<?=$L?>home/removerNews", {
	nome: $('#nome').val(),
	email: $('#email').val()
	},	function(response) {
		msg = 'E-mail removido com sucesso!';
		finishAjax(response);
	});
	return false;
}

