function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (
			anchor.getAttribute("href") && ( 
			anchor.getAttribute("rel") == "external" || 
			anchor.getAttribute("rel") == "external nofollow" || 
			anchor.getAttribute("rel") == "nofollow external" )
			)
		anchor.target = "_blank";
	}
}

function nospam(user,domain) {
	locationstring = "mailto:" + user + "@" + domain;
	window.location = locationstring;
}


function checkAge() {

	var ageField = $('#less18');
	var adultField = $('#menores');

	if (ageField.is(':checked') == true) {		
		adultField.show();
	} else {
		adultField.hide();
	}

}

function sumaTotal() {

	// Valores
	var price = 0;
	var total = 0;

	// Campos
	var totalField = $('#preu');
	var inscripField1 = $('#soci_federat');
	var inscripField2 = $('#soci');
	var inscripField3 = $('#federat');
	var inscripField4 = $('#public');
	var busField = $('#bus');
	
	// Analizamos fecha
	var currentTime = new Date();
	var finishTime = new Date();
	finishTime.setFullYear(2011, 05, 10);

	if (finishTime > currentTime) {
	
		// Precios inscripciones
		if (inscripField1.is(':checked') == true) {
			price = 16;
		} else if (inscripField2.is(':checked') == true) {
			price = 19;
		} else if (inscripField3.is(':checked') == true) {
			price = 22;
		} else if (inscripField4.is(':checked') == true) {
			price = 25;
		} else {
			price = 0;
		}
		
	} else {
		
		// Precios inscripciones
		if (inscripField1.is(':checked') == true) {
			price = 16;
		} else if (inscripField2.is(':checked') == true) {
			price = 19;
		} else if (inscripField3.is(':checked') == true) {
			price = 22;
		} else if (inscripField4.is(':checked') == true) {
			price = 25;
		} else {
			price = 0;
		}		
		
	}

	// Transporte
	if (busField.is(':checked') == true) {
		priceBus = 10;
	} else {
		priceBus = 0;
	}

	total = price + priceBus;

	totalField.attr('value', total + "€");

}

function validar(idForm, lang) {

	var myForm = $(idForm);
	var error = false;
	var fields = new Array('#cognoms','#nom','#telefon','#dni','#direccio','#poblacio','#cp');
	var messages = new Array();
	switch (lang) {
		case 'ct':
			messages[0] = 'Revisi els camps obligatoris';
		break;
		case 'es':
			messages[0] = 'Revisa los campos obligatorios';
		break;
	}

	// Datos personales
	for (i = 0; i < fields.length; i++ ) {

		var f = $(fields[i]);
		var v = f.val();
		
		if (v == '') {
			f.css('border', '1px solid #f00');
			error = true;
		} else {				
			f.css('border','1px solid #090');
			//f.style.border = '1px solid #090';
			error = false;			
		}			

	}

	// Datos edad
	if ($('#less18').is(':checked') == true) {
		if ($('#acompanyant').val() == '') {
			error = true;
			$('#acompanyant').css('border','1px solid #f00');
		}
	}

	if (error) {
		window.alert(messages[0]);
		return false;
	} else {
		myForm.attr('action','?m=inscripcion&a=submit');
		myForm.submit();
	}

}

function confirmPayment(idForm, lang) {

	var myForm = $(idForm);
	var messages = new Array();

	switch (lang) {
		case 'ct':
			messages[0] = 'Confirmar pagament';
		break;
		case 'es':
			messages[0] = 'Confirmar pago';
		break;
	}

	if(confirm(messages[0])){
		myForm.submit();
	}

}

// Aceptar borrado
function doDelete(nameForm, urlForm) {

	//window.alert(nameForm);
	// Variable
	//var myForm = $(nameForm);

	// Procesamos peticion
	var estado = confirm('Desea eliminar los registros seleccionados');
	if (estado == true) {
		window.location=urlForm;
	}

	return;
	
}


$(document).ready(function() {
	
	externalLinks();
	
	if ($('#content').height() < 500) {
		$('#content').height(500);
	}
});


