var keepOn;
jQuery(document).ready(function() {
	jQuery('.bt_compartilhe').click( 
		function (){
			jQuery(this).css('background-position','top');
			jQuery('.bt_indique').css('background-position','bottom');
			jQuery('.bt_receba').css('background-position','bottom');
			jQuery('.bt_imprima').css('background-position','bottom');
			
			keepOn = '.bt_compartilhe';
			jQuery('#sharing').html(jQuery('#compartilhar').html());	
			jQuery('#sharing').attr('class','sharedata compartilhar');			
		}
	);
	jQuery('.bt_indique').click( 
		function (){
			jQuery(this).css('background-position','top');
			jQuery('.bt_compartilhe').css('background-position','bottom');
			jQuery('.bt_receba').css('background-position','bottom');
			jQuery('.bt_imprima').css('background-position','bottom');
			
			keepOn = '.bt_indique';
			jQuery('#sharing').html(jQuery('#indicar').html());	
			jQuery('#sharing').attr('class','sharedata indicar');	
		}
	);
	jQuery('.bt_receba').click( 
		function (){
			jQuery(this).css('background-position','top');
			jQuery('.bt_compartilhe').css('background-position','bottom');
			jQuery('.bt_indique').css('background-position','bottom');
			jQuery('.bt_imprima').css('background-position','bottom');
			
			keepOn = '.bt_receba';
			jQuery('#sharing').html(jQuery('#receber').html());	
			jQuery('#sharing').attr('class','sharedata indicar receber');	
		}
	);
	jQuery('.bt_imprima').click( 
		function (){
			jQuery(this).css('background-position','top');
			jQuery('.bt_compartilhe').css('background-position','bottom');
			jQuery('.bt_indique').css('background-position','bottom');
			jQuery('.bt_receba').css('background-position','bottom');
			
			keepOn = '.bt_imprima';
			jQuery('#sharing').html('');	
		}
	);
	
	
	jQuery('.bt_receba').hover( 
		function() {
			jQuery(this).css('background-position','top');
		},
		function() {
			if(keepOn != '.bt_receba') jQuery(this).css('background-position','bottom');
		}
	);
	jQuery('.bt_indique').hover( 
		function() {
			jQuery(this).css('background-position','top');
		},
		function() {
			if(keepOn != '.bt_indique') jQuery(this).css('background-position','bottom');
		}
	);
	jQuery('.bt_compartilhe').hover( 
		function() {
			jQuery(this).css('background-position','top');
		},
		function() {
			if(keepOn != '.bt_compartilhe') jQuery(this).css('background-position','bottom');
		}
	);
	jQuery('.bt_imprima').hover( 
		function() {
			jQuery(this).css('background-position','top');
		},
		function() {
			if(keepOn != '.bt_imprima') jQuery(this).css('background-position','bottom');
		}
	);
});

/*******/
function clearVal(v, o) {
	if(o.value == v) o.value = '';	
}
function setVal(v, o, validate) {
	if(o.value == '') {
		o.value = v;	
	} else if(validate=='email' && !_checkEmail(o.value)) {
		o.value = v;		
		o.focus;
		alert('E-mail inválido');		
	}
}
function _checkEmail(v) {
	var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;	
	if (filter.test(v)) {
		return true;
	} else {
		return false;
	}
}
function _checkForm(f) {
	var ret = '';
	if(!_checkEmail(f.uemail.value)) {
		ret += "Seu e-mail é inválido\n";
	}
	if(!_checkEmail(f.aemail.value)) {
		ret += "E-mail do amigo é inválido\n";
	}
	if(f.unome.value.length <= 1 || f.unome.value == 'seu nome' ) {
		ret += "Informe seu nome\n";
	}
	if(f.anome.value.length <= 1 || f.anome.value == 'nome do amigo' ) {
		ret += "Informe o nome do amigo\n";
	}
	
	if(ret.length > 0) {
		alert(ret);
		return false;
	} else {
		jQuery.post("/sfDanica2/web/index.php/home/ajaxIndiqueDo", 
	 	{ unome: f.unome.value, uemail: f.uemail.value, anome: f.anome.value, aemail: f.aemail.value, page: f.page.value },
	  	function(data){	 
	  		if(data != 'Mensagem enviada!') {
	  			jQuery("#_msg").show();
	  			jQuery("#_msg").html(data);
	  		} else {
	  			alert(data);
	  			f.unome.value = 'seu nome';
	  			f.uemail.value = 'seu e-mail';
	  			f.anome.value = 'nome do amigo';
	  			f.aemail.value = 'e-mail do amigo';
	  		}
    	});
	}
	return false;
}

function _checkNewsletterForm(f)
{
	var ret='';
	if(f.newsletter_sign_nome.value == "" || f.newsletter_sign_nome.value == "seu nome")
	{
		ret += "Informe seu nome\n";
	}
	if(f.newsletter_sign_email.value == "" || f.newsletter_sign_email.value == "seu e-mail")
	{
		ret += "Informe o seu e-mail\n";
	} else if (!_checkEmail(f.newsletter_sign_email.value)) {
		ret += "E-mail inválido\n";
	}
	if(ret.length > 0) {
		alert(ret);
		return false;
	} else {
		jQuery.post("/sfDanica2/web/index.php/newsletter/ajaxUpdate", 
	 	{ 'newsletter_sign[email]': f.newsletter_sign_email.value, 
	 		'newsletter_sign[nome]': f.newsletter_sign_nome.value, 
	 		'newsletter_sign[_csrf_token]': f.newsletter_sign__csrf_token.value,
	 	},
	  	function(data){	 
	  		if(data != 'ok') {
	  			jQuery("#_msg").show();
	  			jQuery("#_msg").html(data);
	  		} else {
	  			alert('Cadastro realizado com sucesso!');
	  			f.newsletter_sign_email.value = 'seu e-mail';
	  			f.newsletter_sign_nome.value = 'seu nome';
	  		}
    	});
	}
	return false;
}
