// JavaScript Document

function check_subscription(email,age,sex,interests,external_affiliated,seslang) {
   ajax = new class_ajax();
   ajax.set_response_action(function() {
		ldng_box.remove_box(ldng_box._prototype.id);
		if (ajax.get_response_text() == 'true') {
			yes_function = function() { document.location.href = INCPATH +'index.php'; }
			if(external_affiliated == "")
				new question_box(subscription_ok, '', 'OK', yes_function, null, null);
			else
			{
				// De momento controlamos el identificador a lo duro puesto que es el único que hay con script
				if(external_affiliated == "227")
				{
					new question_box(subscription_ok + "<iframe src=\"http://nodes.reactivpub.fr/scripts/tracking.php?params=951|4&track=" + email + "_" + seslang + "\" style=\"display:none;\"></iframe>", '', 'OK', yes_function, null, null);
					// CRISTIAN: Esto es por si queremos incluir el paso de validación en los emails de reactivPubES 
					//new question_box(subscription_ok_reactivPubEs, '', 'OK', yes_function, null, null);
				}
				else
				{
					new question_box(subscription_ok, '', 'OK', yes_function, null, null);
				}
			}
		} else if (ajax.get_response_text() == 'already') info_box(subscription_already, '');
		else new info_box(subscription_error, ajax.get_response_text());
	});
	ajax.add_var('action', 'subscribe');
	ajax.add_var('email', email);
	// CRISTIAN: Añadimos las demás variables del formulario para el inmailing
	// NOTA: La variable "affiliated_id" se ha cambiado por "external_affiliated" debido a que ahora ya no se puede pasar esa variable por GET por la indexación de Google
	if(age != "")
		ajax.add_var('age',age);
	if(external_affiliated != "")
		ajax.add_var('external_affiliated',external_affiliated);
	if(sex != "")
	{
		if(sex == "1")
			ajax.add_var('sex',true);
		else if(sex == "2")
			ajax.add_var('sex',false);
	}
	if(interests.length > 0)
	{
		for(i = 0; i < interests.length;i++)
			ajax.add_var('interest[]',interests[i]);
	}
	
	ldng_box = new loading_box(message_wait);
	ajax.query_vars(INCPATH +'newsletter/admin_subscriptions.php');
}


function check_unsubscription(email) {
   ajax = new class_ajax();
   ajax.set_response_action(function() {
		ldng_box.remove_box(ldng_box._prototype.id);
		if (ajax.get_response_text() == 'true') {
			yes_function = function() { document.location.href = INCPATH +'index.php'; }
			new question_box(unsubscription_ok, '', 'OK', yes_function, null, null);
		} else if (ajax.get_response_text() == 'notfound') info_box(unsubscription_noemail, '');
		else new info_box(unsubscription_error, '');
	});
	ajax.add_var('action', 'unsubscribe');
	ajax.add_var('email', email);
	ldng_box = new loading_box(message_wait);
   ajax.query_vars(INCPATH +'newsletter/admin_subscriptions.php');
}

