jQuery(document).ready(function(){
	// Configuracion
	jQuery("#wpnabaztag-listatts").click(function(){
		jQuery('#wpnabaztag-error').html('');
		jQuery.post(
			"http://www.pasqualotto.org/wp-content/plugins/wp-nabaztag/wp-nabaztag.sn.php",
			"nserie="+jQuery('#wpnabaztag-nserie').val()+"&nautor="+jQuery('#wpnabaztag-nautor').val(),
			function(resp){
				if (jQuery(resp).find('message').text()) {
					jQuery('#wpnabaztag-error').html('<strong>ERROR</strong>: '+jQuery(resp).find('comment').text());
				} else {
					jQuery("#wpnabaztag-voztts").html('');
					jQuery(resp).find('voice').each(function(){
						jQuery("#wpnabaztag-voztts").html(jQuery("#wpnabaztag-voztts").html()+'<option value='+jQuery(this).attr('command')+'>'+jQuery(this).attr('command')+' ('+jQuery(this).attr('lang')+')'+'</option>');
					});
				}
			},
			"xml"
		);
	});
	// Widget
	jQuery("#wpnabaztag-volver").click(function(){
		jQuery('#wpnabaztag-resp').hide();
		jQuery('#wpnabaztag-resp').html('');
		jQuery('#wpnabaztag-volver').hide();
		jQuery('#wpnabaztag-mensaje').val('');
		jQuery('#wpnabaztag-form').fadeIn();
	});
	jQuery("#wpnabaztag-form").submit(function(){
		jQuery('#wpnabaztag-form').hide();
		if(jQuery('#wpnabaztag-mensaje').val()) {
			jQuery('#wpnabaztag-carga').fadeIn();
			jQuery.post(
				"http://www.pasqualotto.org/wp-content/plugins/wp-nabaztag/wp-nabaztag.sn.php",
				"wpnabaztag-mensaje=" + jQuery('#wpnabaztag-mensaje').val(),
				function(resp){
					if (jQuery(resp).find('message').text() != 'TTSSENT') {
						jQuery('#wpnabaztag-resp').html('<strong>ERROR</strong>: '+jQuery(resp).find('comment').text());
					} else {
						jQuery('#wpnabaztag-resp').html('Message sent');
					}
					jQuery('#wpnabaztag-carga').hide();
				},
				"xml"
			);
		} else {
			jQuery('#wpnabaztag-resp').html('You have not written a message');
		}
		jQuery('#wpnabaztag-resp').fadeIn();
		jQuery('#wpnabaztag-volver').fadeIn();
	return false;
	});
});
