var AJAX = '/ajax/ajax.php';

function veure_imatge( id_article, id_imatge, lloc )
{
	$.post( AJAX, { id_article: id_article, id_imatge: id_imatge, lloc: lloc, accio: 'veure_imatge' },
	function( resposta )
	{
		var res = resposta.split("||");
	
		$('#imatge-article').html( res[0] );
		$('#imatge-peu').html(res[1] );
		$('#imatge-miniatures').html( res[2] );
	});
}


function enviar_email()
{
	posicio = $('#posicio').val();
	var email = $('#email_e').val();
	var nom = $('#nom_e').val();
	var r_email = $('#r_email').val();
	var r_nom = $('#r_nom').val();
	var comentari = $('#comentari').val();
	var id_article = $('#id_article').val();
	var lloc = $('#lloc').val();

 	if( email != '' )
	{
		$.post( AJAX, { email: email, nom: nom, r_email: r_email, r_nom: r_nom, id_article: id_article, lloc: lloc, comentari: comentari, accio: 'enviar_art' },
		function( resposta )
		{
			var html = '	S\'ha enviat correctament el missatge<br />\n';
			html += '	<div style="float: right"><a onclick="tancar()">Tancar</a></div>\n';
		
			$('#enviar_art' + posicio ).html( html );
			
			setTimeout('enviar_email_cb2()',2000)
		});
	}
	else
	{
		alert("Has de posar un correu de destí com a mínim");
		return false;
	}
}


function enviar_email_cb2()
{
 	$('#enviar_art' + posicio ).hide();
}

function tancar( posicio )
{
	$('#enviar_art' + posicio ).html( '' );
	$('#enviar_art' + posicio ).hide();
}
function enviar_art_form( lloc, id_article, posicio, obj )
{
	var ample = obj.parentNode.clientWidth;
	if( lloc == 'entrevista' ) ample = obj.parentNode.parentNode.clientWidth;

	var html = '<div style="padding-left:30px;">';
	html += '<h6 class="vermell">Envia article</h6>\n';
	html += '<form method="get" name="enviar_art">\n';
	html += '<input type="hidden" id="posicio" value="'+ posicio +'" />\n';
	html += '	<label for="email_e">Correu/s electrònic/s</label>\n';
	html += '	<input id="email_e" type="text" value="" name="email" />\n';
	html += '	<br clear="all" />\n';
	html += '	<label for="nom_e">Nom/s</label>\n';
	html += '	<input id="nom_e" type="text" value="" name="nom" />\n';
	html += '	<br /><small>Per enviar a més d\'un correu separa per ( ; )</small>\n';
	html += '	<br clear="all" /><br />\n';
	html += '	<label for="r_email">El teu correu</label>\n';
	html += '	<input id="r_email" type="text" value="" name="r_email" />\n';
	html += '	<br clear="all" />\n';
	html += '	<label for="r_nom">El teu nom</label>\n';
	html += '	<input id="r_nom" type="text" value="" name="r_nom" />\n';
	html += '	<br clear="all" />\n';
	html += '	<label for="comentari">Comentari</label>\n';
	html += '	<textarea id="comentari" name="comentari" ></textarea><br />\n';
	html += '	<input type="hidden" id="id_article" value="'+ id_article  +'" />\n';
	html += '	<input type="hidden" id="lloc" value="'+ lloc  +'" />\n';
	html += '	<input type="button" value="enviar" name="enviar" onclick="enviar_email()" style="width: 50px" />\n';
	html += '</form>\n';
	html += '<div style="float: right; margin-right: 10px"><a onclick="tancar(\''+ posicio +'\')"><img src="/img/icones/tancar.gif" alt="tancar" /></a></div><br class="p" />\n';
	html += '</div>\n';

	$('#enviar_art' + posicio ).html( html );
	$('#enviar_art' + posicio ).show();
	$('#enviar_art' + posicio ).css( {width: ample + 'px'} );
}


function titulars( valor )
{
	$.post( AJAX, { valor: valor, accio: 'titulars' },
	function( resposta )
	{
		$('#titulars_antics').html( resposta );
	} );
}

