
//MM_showHideLayers para la cesta
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}



//Para el mouseover de las pestaÃ±as del menu
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function enviar(login)
{
	document.getElementById(login).submit();	
}

function procesarDatos(login) {
	//* los �ndices para phone_type1 corresponden a:
	//												0: mobile
	//												1: home
	//* los �ndices para phone_type2 corresponden a:
	//												0: --
	//												1: mobile
	//												2: home
	var phone_type1 = document.getElementById('phone_type1').selectedIndex;
	var phone_type2 = document.getElementById('phone_type2').selectedIndex;
	var phone_1 = document.getElementById('phone_1').value;
	var phone_2 = document.getElementById('phone_2').value;
	
	var birth_day_idx 	= document.getElementById('birth_day').selectedIndex;
	var birth_month_idx = document.getElementById('birth_month').selectedIndex;
	var birth_year_idx 	= document.getElementById('any').selectedIndex;
	var birth_day 	= document.getElementById('birth_day')[birth_day_idx].value;
	var birth_month = document.getElementById('birth_month')[birth_month_idx].value;
	var birth_year 	= document.getElementById('any')[birth_year_idx].value;
	var now = new Date();
	var isleap = ((birth_year % 4 == 0 && birth_year % 100 != 0) || birth_year % 400 == 0);
	// [Xavier Arnaus 12/08/2008]
	// Check for adult
	if (getTimestamp(birth_day, birth_month, birth_year) > getTimestamp(now.getDate(), now.getMonth()+1, now.getFullYear()-16)) {
		//alert('No puedes ser usuario de Privalia siendo menor de 16 años.');
		alert(s_alert_16age);
	}
	//[Xavier Batlle & Maure Noguera 23/08/08}
	//check for month days
	else if ((birth_month==4 || birth_month==6 || birth_month==9 || birth_month==11) && birth_day==31) {
		//alert("Este mes no tiene 31 días");
		alert(s_alert_31days);
	}
	
	else if (birth_month == 2 && birth_day>29 || (birth_day==29 && !isleap && birth_month == 2)) { // check for february 29th
		//alert("Febrero del año " + birth_year + " no tuvo " + birth_day + " días");
		alert(s_alert_february + birth_year + s_alert_donthave + birth_day + s_alert_days);
	}
	
	else if (phone_1 != '' && phone_type1 == '0' && phone_1.charAt(0) != '3') {
//		alert('Revisa los datos del tel�fono de contacto. El n�mero indicado no corresponde a un tel�fono movil');
		alert('Rivedi i dati del telefono di contatto. Il numero indicato non corrisponde a un cellulare.');
	}

	else if (phone_1 != '' && phone_type1 == '1' && phone_1.charAt(0) != '0') {
//		alert('Revisa los datos del tel�fono de contacto. El n�mero indicado no corresponde a un tel�fono fijo');
		alert('Rivedi i dati del telefono di contatto. Il numero indicato non corrisponde a un telefono fisso.');
	}

	else if (phone_2 != '' && phone_type2 == '1' && phone_2.charAt(0) != '3') {
//		alert('Revisa los datos del tel�fono adicional. El n�mero indicado no corresponde a un tel�fono movil');
		alert('Rivedi i dati del telefono alternativo. Il numero indicato non corrisponde a un cellulare.');
	}

	else if (phone_2 != '' && phone_type2 == '2' && phone_2.charAt(0) != '0') {
//		alert('Revisa los datos del tel�fono adicional. El n�mero indicado no corresponde a un tel�fono fijo');
		alert('Rivedi i dati del telefono alternativo. Il numero indicato non corrisponde a un telefono fisso');
	}
	else if (phone_1 != '' && phone_2 != '') {
		if (phone_type1 == 0 && phone_type2 == 1) {
//			alert('S�lo podemos guardar un tel�fono movil');
			alert('� possibile registrare solo un cellulare');
		}
		else if (phone_type1 == 1 && phone_type2 == 2) {
//			alert('S�lo podemos guardar un tel�fono fijo');
			alert('� possibile registrare solo un telefono fisso');
		}
		else enviar(login);
		
	}

	else {
		enviar(login);	
	}
}

function getTimestamp(day, month, year)
{
var dia_aux = parseInt(day,10);
var mes_aux = parseInt(month,10);
var ano_aux = parseInt(year,10);
var fecha = new Date();
fecha.setFullYear(ano_aux);
fecha.setMonth(mes_aux-1);
fecha.setDate(dia_aux);
fecha.setHours(0);
fecha.setMinutes(0);
fecha.setSeconds(0);
fecha.setMilliseconds(0);
var timestamp = parseInt(fecha.getTime(),10);

return timestamp;
}

function addToCart(login)
{
	//* M�nica (12/12/2007) Si el producto tiene atributos, y no tiene ning�n valor seleccionado, se muestra un alert informativo.
	if((typeof(document.getElementById('attrib1')) != 'undefined') && (attr1_label != '') ) {
		if(document.getElementById('attrib1').value == '') {
//			alert('Es necesario que selecciones tu ' + attr1_label + ' para añadir el producto a la cesta');
			alert('Seleziona la tua ' + attr1_label + ' per aggiungere il prodotto al carrello');
			return;
		}
	}
	document.getElementById(login).submit();	
}

function enviarConParams(s_formId, s_params) {
	var form = document.getElementById(s_formId);
	form.action += s_params;
	form.submit();
}


function unsuscribe(login, option)
{
	document.getElementById("type_remove").value = option;
	document.getElementById(login).submit();	
	
}

/**
 * Funci�n que comprueba el tama�o que se ha introducido en un textarea. Si el tama�o del texto excede 
 * el m�ximo permitido, mostrar� un mensaje de error. 
 * @params string s_string: Cadena de caracteres a comprobar.
 * @params integer i_max_length: N�mero m�ximo de caracteres permitidos.
 * @returns boolean. True si es un numero entero sin signo o false en caso contrario.
 */
function checkMaxLength(s_string, i_max_length){
	if(s_string.length >= i_max_length){ 
		// alert('Has superado el tama�o m�ximo de caracteres permitidos.'); 
		alert('Hai superato il numero massimo de caratteri consentito.'); 
		return false; 
	}
	return true;
}


/**
 * Funci�n que comprueba si el par�metro es un numero entero sin signo. 
 * @params integer i_number: N�mero a comprobar.
 * @returns boolean. True si es un numero entero sin signo o false en caso contrario.
 */
function isUnsignedInteger(i_yourNumber)
{
	var s_template = /^\d+$/; //Formato de numero entero sin signo
	return s_template.test(i_yourNumber);
}

/**
 * Funci�n que comprueba si el c�digo postal introducido corresponde con el de la provincia. Para ello se usa un array 
 * auxiliar en la que se establecen los dos primeros caracteres del c�digo postal de la provincial. 
 * Comentamos de momento el c�digo postal correspondiente a Canarias, Ceuta y Melilla pues no se hacen env�os a dichas
 * provincias.
 * @params integer i_postalCode. C�digo postal.
 * @returns integer 		0 si no se encontr� el c�digo postal (0)
 *							1 si el c�digo postal es de una provincia a la que no se env�a
 *
 */
function getProvinceFromPostalCode(i_postalCode)
{
	
	if (i_postalCode.length != 5) return 0; 
	else if (!isUnsignedInteger(i_postalCode)) return 0; // Comprobamos que son enteros sin signo.
	
	i_postalCodeTwoDigits = i_postalCode.substring(0, 2);
			
	var st_postalCodeInit = new Array();
	var st_specialPostalCode = new Array();
	var st_postalCodeNoShipments = new Array();
	
	
	// js for italian zipcodes: use Regione, not Provincia
	
	st_specialPostalCode['00120'] = 'Citt� del Vaticano';
	st_specialPostalCode['47890'] = 'Repubblica di San Marino';
	st_specialPostalCode['47891'] = 'Repubblica di San Marino';
	st_specialPostalCode['47892'] = 'Repubblica di San Marino';
	st_specialPostalCode['47893'] = 'Repubblica di San Marino';
	st_specialPostalCode['47894'] = 'Repubblica di San Marino';
	st_specialPostalCode['47895'] = 'Repubblica di San Marino';
	st_specialPostalCode['47896'] = 'Repubblica di San Marino';
	st_specialPostalCode['47897'] = 'Repubblica di San Marino';
	st_specialPostalCode['47898'] = 'Repubblica di San Marino';
	st_specialPostalCode['47899'] = 'Repubblica di San Marino';
	
	
	st_postalCodeInit['00'] = 'Lazio';
	st_postalCodeInit['01'] = 'Lazio';
	st_postalCodeInit['02'] = 'Lazio';
	st_postalCodeInit['03'] = 'Lazio';
	st_postalCodeInit['04'] = 'Lazio';
	st_postalCodeInit['05'] = 'Umbria';
	st_postalCodeInit['06'] = 'Umbria';
	st_postalCodeInit['07'] = 'Sardegna';
	st_postalCodeInit['07'] = 'Sardegna';
	st_postalCodeInit['08'] = 'Sardegna';
	st_postalCodeInit['08'] = 'Sardegna';
	st_postalCodeInit['09'] = 'Sardegna';
	st_postalCodeInit['09'] = 'Sardegna';
	st_postalCodeInit['09'] = 'Sardegna';
	st_postalCodeInit['09'] = 'Sardegna';
	st_postalCodeInit['10'] = 'Piemonte';
	st_postalCodeInit['11'] = 'Valle d\'Aosta';
	st_postalCodeInit['12'] = 'Piemonte';
	st_postalCodeInit['13'] = 'Piemonte';
	st_postalCodeInit['14'] = 'Piemonte';
	st_postalCodeInit['15'] = 'Piemonte';
	st_postalCodeInit['16'] = 'Liguria';
	st_postalCodeInit['17'] = 'Liguria';
	st_postalCodeInit['18'] = 'Liguria';
	st_postalCodeInit['19'] = 'Liguria';
	st_postalCodeInit['20'] = 'Lombardia';
	st_postalCodeInit['21'] = 'Lombardia';
	st_postalCodeInit['22'] = 'Lombardia';
	st_postalCodeInit['23'] = 'Lombardia';
	st_postalCodeInit['24'] = 'Lombardia';
	st_postalCodeInit['25'] = 'Lombardia';
	st_postalCodeInit['26'] = 'Lombardia';
	st_postalCodeInit['27'] = 'Lombardia';
	st_postalCodeInit['28'] = 'Piemonte';
	st_postalCodeInit['29'] = 'Emilia-Romagna';
	st_postalCodeInit['30'] = 'Veneto';
	st_postalCodeInit['31'] = 'Veneto';
	st_postalCodeInit['32'] = 'Veneto';
	st_postalCodeInit['33'] = 'Friuli-Venezia Giulia';
	st_postalCodeInit['34'] = 'Friuli-Venezia Giulia';
	st_postalCodeInit['35'] = 'Veneto';
	st_postalCodeInit['36'] = 'Veneto';
	st_postalCodeInit['37'] = 'Veneto';
	st_postalCodeInit['38'] = 'Trentino-Alto Adige / S�dtirol';
	st_postalCodeInit['39'] = 'Trentino-Alto Adige / S�dtirol';
	st_postalCodeInit['40'] = 'Emilia-Romagna';
	st_postalCodeInit['41'] = 'Emilia-Romagna';
	st_postalCodeInit['42'] = 'Emilia-Romagna';
	st_postalCodeInit['43'] = 'Emilia-Romagna';
	st_postalCodeInit['44'] = 'Emilia-Romagna';
	st_postalCodeInit['45'] = 'Veneto';
	st_postalCodeInit['46'] = 'Lombardia';
	st_postalCodeInit['47'] = 'Emilia-Romagna';
	st_postalCodeInit['48'] = 'Emilia-Romagna';
	st_postalCodeInit['50'] = 'Toscana';
	st_postalCodeInit['51'] = 'Toscana';
	st_postalCodeInit['52'] = 'Toscana';
	st_postalCodeInit['53'] = 'Toscana';
	st_postalCodeInit['54'] = 'Toscana';
	st_postalCodeInit['55'] = 'Toscana';
	st_postalCodeInit['56'] = 'Toscana';
	st_postalCodeInit['57'] = 'Toscana';
	st_postalCodeInit['58'] = 'Toscana';
	st_postalCodeInit['59'] = 'Toscana';
	st_postalCodeInit['60'] = 'Marche';
	st_postalCodeInit['61'] = 'Marche';
	st_postalCodeInit['62'] = 'Marche';
	st_postalCodeInit['63'] = 'Marche';
	st_postalCodeInit['64'] = 'Abruzzo';
	st_postalCodeInit['65'] = 'Abruzzo';
	st_postalCodeInit['66'] = 'Abruzzo';
	st_postalCodeInit['67'] = 'Abruzzo';
	st_postalCodeInit['70'] = 'Puglia';
	st_postalCodeInit['71'] = 'Puglia';
	st_postalCodeInit['72'] = 'Puglia';
	st_postalCodeInit['73'] = 'Puglia';
	st_postalCodeInit['74'] = 'Puglia';
	st_postalCodeInit['75'] = 'Basilicata';
	st_postalCodeInit['80'] = 'Campania';
	st_postalCodeInit['81'] = 'Campania';
	st_postalCodeInit['82'] = 'Campania';
	st_postalCodeInit['83'] = 'Campania';
	st_postalCodeInit['84'] = 'Campania';
	st_postalCodeInit['85'] = 'Basilicata';
	st_postalCodeInit['86'] = 'Molise';
	st_postalCodeInit['87'] = 'Calabria';
	st_postalCodeInit['88'] = 'Calabria';
	st_postalCodeInit['89'] = 'Calabria';
	st_postalCodeInit['90'] = 'Sicilia';
	st_postalCodeInit['91'] = 'Sicilia';
	st_postalCodeInit['92'] = 'Sicilia';
	st_postalCodeInit['93'] = 'Sicilia';
	st_postalCodeInit['94'] = 'Sicilia';
	st_postalCodeInit['95'] = 'Sicilia';
	st_postalCodeInit['96'] = 'Sicilia';
	st_postalCodeInit['97'] = 'Sicilia';
	st_postalCodeInit['98'] = 'Sicilia';
	

	// try specialPostalCode first, then postalCodeInit, then postalCodeNoShipments (empty for now)
	if(typeof(st_specialPostalCode[i_postalCode]) == 'string') {
		return st_specialPostalCode[i_postalCode];
	} else if(typeof(st_postalCodeInit[i_postalCodeTwoDigits]) == 'string') {
		return st_postalCodeInit[i_postalCodeTwoDigits];
	} else if (typeof(st_postalCodeNoShipments[i_postalCodeTwoDigits]) == 'string') {
		return 1;
	} else {
		return 0;
	}

}


/**
 * Funcion para ocultar o mostrar el contenido de la ayuda
 *
 *
 */
	function setHelpActiveItem(helpItems, helpItem) {
		obj_helpBar = document.getElementById('helpBar'); //la barra que separa el menu del texto y que solo se verï¿½ en caso de que el texto este visible
		for(key in helpItems) {
			if(obj_helpItem = document.getElementById(helpItems[key])) {
				if(helpItems[key] == helpItem) {
					// if not expanded then expand, else contract
					if(obj_helpItem.style.display != "block") {
						obj_helpItem.style.display="block";
						obj_helpBar.style.display="block";
					} else {
						obj_helpItem.style.display="none";
						obj_helpBar.style.display="none";
					}
				} else {
					obj_helpItem.style.display="none";
				}
			}
		}
	}

	var helpItems = new Array(	"dummy",
								"helpItem1", "helpItem2", "helpItem3", "helpItem4",
								"helpItem5", "helpItem6", "helpItem7", "helpItem8",
								"helpItem9", "helpItem10", "helpItem11", "helpItem12");

	activeItemID = '';
	if(activeItemID != '') {
		activeItem = 'helpItem' + activeItemID;
		setHelpActiveItem(helpItems, activeItem);
	}

// Xavier Batlle 12-8-08
//AÃ±adida funciÃ³n para comprobar que algÃºn checkbox estÃ¡ marcado en el Ãºltimo paso del proceso de darse de baja
function isChecked(remove)
	{
		var b=false;
		var form=document.getElementById(remove);
		
		
		for(i=0; i<form.elements.length; i++)
		{
		    var element = form.elements[i];
			if (element.type == "checkbox" && element.checked){
				b=true;
			} else if(element.type=="textarea" && element.value!='')
					{
						b=true;
					}
			
		}
		//if(b==false) {alert('No has marcado ninguna opciÃ³n');}
		if(b==false) {alert(s_alert_nooption);}
		return b;
	}