// js for SETEM
function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

function addToFav() {
    if (document.all)
        window.external.AddFavorite(location.href,document.title);
    else if(window.sidebar)
            window.sidebar.addPanel(document.title,location.href,'');
}




$(document).ready(function() {
    $('#lang_sel').change(function() {
        //window.location.replace($(this).val());
        window.open($(this).val(),'_top');
    });
    
	if ($('#content > .div2 > .moreInfo')[0]){
		var p = $('#content > .div2 > .moreInfo').height()+ 50;
		$('#content > .div2').css('paddingBottom',p);
	}
	
		/* Fancy d' imatges */
	 $("a[rel=gallery]").fancybox({
	            'overlayColor'      : '#fff',
	            'overlayOpacity'    : '0.8',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
	
	/* Fancy box de videos */
	$("a.video").fancybox({
        	    'overlayColor'      : '#fff',
	            'overlayOpacity'    : '0.8',
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
	});
	
	/* Fancy box d'imatge simple, sense carrousel  */
	$("a.zoom-simple").fancybox({
            'overlayColor'      : '#fff',
            'overlayOpacity'    : '0.8',
    		'transitionIn'		: 'none',
    		'transitionOut'		: 'none',
    		'titlePosition' 	: 'over',
    		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
    		    if (title)
    			    return '<span id="fancybox-title-over">'+ title + '</span>';
    			else 
    			    return '';
    		}
	});
	
});


function valida_nif_cif_nie(a) 
{
	var temp=a.toUpperCase();
	var cadenadni="TRWAGMYFPDXBNJZSQVHLCKE";
 
	if (temp!==''){
		//si no tiene un formato valido devuelve error
		if ((!/^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$/.test(temp) && !/^[T]{1}[A-Z0-9]{8}$/.test(temp)) && !/^[0-9]{8}[A-Z]{1}$/.test(temp))
		{
			return false;
		}
 
		//comprobacion de NIFs estandar
		if (/^[0-9]{8}[A-Z]{1}$/.test(temp))
		{
			posicion = a.substring(8,0) % 23;
			letra = cadenadni.charAt(posicion);
			var letradni=temp.charAt(8);
			if (letra == letradni)
			{
			   	return true;
			}
			else
			{
				return false;
			}
		}
 
		//algoritmo para comprobacion de codigos tipo CIF
		suma = parseInt(a.charAt(2))+parseInt(a.charAt(4))+parseInt(a.charAt(6));
		for (i = 1; i < 8; i += 2)
		{
			temp1 = 2 * parseInt(a.charAt(i));
			temp1 += '';
			temp1 = temp1.substring(0,1);
			temp2 = 2 * parseInt(a.charAt(i));
			temp2 += '';
			temp2 = temp2.substring(1,2);
			if (temp2 == '')
			{
				temp2 = '0';
			}
 
			suma += (parseInt(temp1) + parseInt(temp2));
		}
		suma += '';
		n = 10 - parseInt(suma.substring(suma.length-1, suma.length));
 
		//comprobacion de NIFs especiales (se calculan como CIFs)
		if (/^[KLM]{1}/.test(temp))
		{
			if (a.charAt(8) == String.fromCharCode(64 + n))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
 
		//comprobacion de CIFs
		if (/^[ABCDEFGHJNPQRSUVW]{1}/.test(temp))
		{
			temp = n + '';
			if (a.charAt(8) == String.fromCharCode(64 + n) || a.charAt(8) == parseInt(temp.substring(temp.length-1, temp.length)))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
 
		//comprobacion de NIEs
		//T
		if (/^[T]{1}/.test(temp))
		{

			if (a.charAt(8) == /^[T]{1}[A-Z0-9]{8}$/.test(temp))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
 
		//XYZ
		if (/^[XYZ]{1}/.test(temp))
		{
			pos = str_replace(['X', 'Y', 'Z'], ['0','1','2'], temp).substring(0, 8) % 23;
			if (a.charAt(8) == cadenadni.substring(pos, pos + 1))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
	}
 
	return false;
}


