﻿<!--

// Busca el Path del Script para cargar el script de las funciones validación base
var lSPathScript = '';
for (var liAux = 0; liAux < document.getElementsByTagName('script').length; liAux++) {
	if (document.getElementsByTagName('script')[liAux].src && document.getElementsByTagName('script')[liAux].src.match(/Valid[^\.]*\.js(\?.*)?$/)) {
		lSPathScript = document.getElementsByTagName('script')[liAux].src.replace(/Valid[^\.]*\.js(\?.*)?$/,'');
	}
}
document.write('<script type="text/javascript" src="' + lSPathScript + 'ValidBase.js"></script>');
// Busca el Path del Script para cargar el script de las funciones validación base

var window_onload_anterior;

if (window.onload != null) { window_onload_anterior = window.onload; };
window.onload = valid_js_window_onload;

// Ids de los controles
var cSFechaNacimientoDia = 'SFechaNacimientoDia';
var cSFechaNacimientoMes = 'SFechaNacimientoMes';
var cSFechaNacimientoAnyo = 'SFechaNacimientoAnyo';
var cSNacionalidad = 'SNacionalidad';
var cITDNI = 'ITDNI';
var cITTelefono = 'ITTelefono';
var cITEMail = 'ITEMail';

function valid_js_window_onload() {
	// Inicialización de las COMBOS
	// Esta inicialización debe declararse siempre antes que los eventos para que los eventos
	// Primero creo la combo de meses, porque la función updateDays depende que haya valores en la combo de meses
	if (document.getElementById(cSFechaNacimientoMes) != null) {
		updateMonths();
		document.getElementById(cSFechaNacimientoMes).onchange = updateDays;
	}
	if (document.getElementById(cSFechaNacimientoDia) != null) { updateDays(); }
	if (document.getElementById(cSFechaNacimientoAnyo) != null) { 
		updateYears();
		document.getElementById(cSFechaNacimientoAnyo).onchange = updateDays;
	}
	if (document.getElementById(cSNacionalidad) != null) { 
		if (document.getElementById(cITDNI) != null) { document.getElementById(cSNacionalidad).onchange = function () { validarDNINIE(this) }; }		
		updateNationalities();
	}
	if (document.getElementById('SOcupacion') != null) { updateWorks(); }
	// Inicialización de las COMBOS

	if (document.getElementById('ITNombre') != null) {
		document.getElementById('ITNombre').onkeypress = function(evt) { return changeKey(this, (window.event || evt), Nombre_Apellidos); };
		document.getElementById('ITNombre').onkeyup = function() { var lSErrores = Field_Validate('SolicitudProducto', 'Nombre', this.id, 'nombre', 2, 100, true, false); this.title = (lSErrores != '' ? lSErrores.substring(1) : ''); MostrarCorrectoIncorrecto(this, (lSErrores == '')); };
		document.getElementById('ITNombre').maxLength = 100;
	}
	if (document.getElementById('ITApellidos') != null) {
		document.getElementById('ITApellidos').onkeypress = function(evt) { return changeKey(this, (window.event || evt), Nombre_Apellidos); };
		document.getElementById('ITApellidos').onkeyup = function() { var lSErrores = Field_Validate('SolicitudProducto', 'Apellidos', this.id, 'nombre', 2, 100, true, false); this.title = (lSErrores != '' ? lSErrores.substring(1) : ''); MostrarCorrectoIncorrecto(this, (lSErrores == '')); };
		document.getElementById('ITApellidos').maxLength = 100;
	}
	if (document.getElementById(cITDNI) != null) {
		document.getElementById(cITDNI).onkeypress = function(evt) { return changeKey(this, (window.event || evt), DNI); };
		document.getElementById(cITDNI).onkeyup = function() { var lSErrores = Field_Validate('SolicitudProducto', 'DNI/NIE', this.id, 'DNI', 9, 9, (document.getElementById(cSNacionalidad) != null && document.getElementById(cSNacionalidad).value != '034' && document.getElementById(cSNacionalidad).value != '376'), false); this.title = (lSErrores != '' ? lSErrores.substring(1) : ''); MostrarCorrectoIncorrecto(this, (lSErrores == '')); };
		document.getElementById(cITDNI).maxLength = 9;
	}
	if (document.getElementById(cITTelefono) != null) {
		document.getElementById(cITTelefono).onkeypress = function(evt) { return changeKey(this, (window.event || evt), cancelNoDigits); };
		document.getElementById(cITTelefono).onkeyup = function() { var lSErrores = Field_Validate('SolicitudProducto', 'Teléfono de contacto', this.id, 'telefono', 9, 9, true, false); this.title = (lSErrores != '' ? lSErrores.substring(1) : ''); MostrarCorrectoIncorrecto(this, (lSErrores == '')); };
		document.getElementById(cITTelefono).maxLength = 9;
	}
	if (document.getElementById('ITTelefono2') != null) {
		document.getElementById('ITTelefono2').onkeypress = function(evt) { return changeKey(this, (window.event || evt), cancelNoDigits); };
		document.getElementById('ITTelefono2').onkeyup = function() { var lSErrores = Field_Validate('SolicitudProducto', 'Teléfono fijo', this.id, 'telefono', 9, 9, false, false); this.title = (lSErrores != '' ? lSErrores.substring(1) : ''); MostrarCorrectoIncorrecto(this, (lSErrores == '')); };
		document.getElementById('ITTelefono2').maxLength = 9;
	}
	if (document.getElementById(cITEMail) != null) {
		document.getElementById(cITEMail).onkeypress = function(evt) { return changeKey(this, (window.event || evt), lettersToLowerCase); };
		document.getElementById(cITEMail).onkeyup = function() { var lSErrores = Field_Validate('SolicitudProducto', 'Email', this.id, 'email', 6, 100, true, false); this.title = (lSErrores != '' ? lSErrores.substring(1) : ''); MostrarCorrectoIncorrecto(this, (lSErrores == '')); };
		document.getElementById(cITEMail).maxLength = 100;
	}
	
	if (document.getElementById('CPolitica') != null) { document.getElementById('CPolitica').value = '1'; }

	if (typeof(window.window_onload_anterior) == 'function') { window.window_onload_anterior(); }
}

/******************** FUNCIONES DE VALIDACION ***************************/
function Form_Validate(FrmValidar) { 
	var errores = Field_Validate(FrmValidar, 'Nombre', 'ITNombre', 'nombre', 2, 100, true, true); 
	errores += Field_Validate(FrmValidar, 'Apellidos', 'ITApellidos', 'nombre', 2, 100, true, true); 			
	if (document.getElementById(cITDNI) != null) {
		errores += Field_Validate(FrmValidar, 'DNI/NIE', cITDNI, 'DNI', 9, 9, (document.getElementById(cSNacionalidad) != null && document.getElementById(cSNacionalidad).value != '034' && document.getElementById(cSNacionalidad).value != '376'), true);
	}
	if (document.getElementById(cSFechaNacimientoDia) != null && document.getElementById(cSFechaNacimientoMes) != null && document.getElementById(cSFechaNacimientoAnyo) != null) {
		errores += Field_Validate(FrmValidar, 'Fecha de nacimiento', cSFechaNacimientoAnyo, 'string', 4, 4, true, true);
		errores += valFecha('Fecha de nacimiento', document.getElementById(cSFechaNacimientoDia).value + '/' + document.getElementById(cSFechaNacimientoMes).value + '/' + document.getElementById(cSFechaNacimientoAnyo).value);
		errores += ComprobarMayoriaEdad(FrmValidar, 'Fecha de nacimiento', parseInt(document.getElementById(cSFechaNacimientoDia).value), parseInt(document.getElementById(cSFechaNacimientoMes).value), parseInt(document.getElementById(cSFechaNacimientoAnyo).value));
	}
	if (document.getElementById(cSNacionalidad) != null) {
		errores += Field_Validate(FrmValidar, 'Nacionalidad', cSNacionalidad, 'string', 3, 3, true, true);
	}
	if (document.getElementById('SOcupacion') != null) {
		errores += Field_Validate(FrmValidar, 'Situación profesional', 'SOcupacion', 'string', 3, 4, true, true);
	}

	errores += Field_Validate(FrmValidar, 'Teléfono de contacto', cITTelefono, 'telefono', 9, 9, true, true);
	if (document.getElementById('ITTelefono2') != null) {
		errores += Field_Validate(FrmValidar, 'Teléfono fijo', 'ITTelefono2', 'telefono', 9, 9, false, true);
//		if (document.getElementById(cITTelefono).value == document.getElementById('ITTelefono2').value) {
//			var lSError = 'Ha escrito el mismo teléfono en los campos \'Teléfono de contacto\' y \'Teléfono fijo\'. Indique otro teléfono en \'Teléfono fijo\' o bórrelo.';
//			if (document.getElementById('ITTelefono_asterisco') != null) {
//				document.getElementById('ITTelefono_asterisco').title = '- Teléfono de contacto:' + lSError;
//				document.getElementById('ITTelefono_asterisco').style.visibility = 'visible';
//			}
//			if (document.getElementById('ITTelefono2_asterisco') != null) {
//				document.getElementById('ITTelefono2_asterisco').title = '- Teléfono fijo:' + lSError;
//				document.getElementById('ITTelefono2_asterisco').style.visibility = 'visible';
//			}
//			errores += lSError;
//		}
	}

	errores += Field_Validate(FrmValidar, 'Email', cITEMail, 'email', 6, 100, true, true);
	errores += Field_Validate(FrmValidar, 'Política de privacidad', 'CPolitica', 'checkbox', 1, 1, true, true);
	if (!document.getElementById('CPolitica').checked) { errores += '\n- Debe de aceptar la política de protección de datos para poder continuar.'; }
	
	// Solo compruebo si el email es español cuando ya está correcto todo el formulario
	if (errores == '') { errores += EsEmailEspanol(document.getElementById(cITEMail).value); }
	if (errores) {
		errores = "Se han producido los siguientes errores en el formulario,\npor favor, corrígelos para poder continuar.\n" + errores; 
		alert(errores);
	} else {

		// Incluyo los parámetros para poder guardar el search
		document.getElementById('IHInfo').value = location.href;

		if (typeof(s) != "undefined") { s.sendFormEvent('s', s.pageName, FrmValidar); }
    var FrmAsp = document.getElementById('aspnetForm');
    if(FrmAsp != null) {
			// Para que funcione en la Ficha de Producto cambio el action de la página por el del formulario
			FrmAsp.action = cSApplicationPath + '/GuardarDatos.aspx?UrlOrigen=' + escape(location.href);
			FrmAsp.submit();
    } else {
			document.forms[FrmValidar].action += (document.forms[FrmValidar].action.indexOf('?') > 0 ? '&' : '?' ) + 'UrlOrigen=' + escape(location.href);
			document.getElementById(FrmValidar).submit();
		}
	}
}

function validarDNINIE(poCampo) {
	if (document.getElementById('LDNI') != null) {
		if (poCampo.value == '') {
			document.getElementById('LDNI').innerText = 'DNI/NIE:';
		} else {
			if (poCampo.value == '034' || this.value == '376') { document.getElementById('LDNI').innerText = 'DNI:'; }
			else { document.getElementById('LDNI').innerText = 'NIE:'; }
		}
	}
	if (document.getElementById(cITDNI) != null) {
		var lSErrores = Field_Validate('SolicitudProducto', 'DNI/NIE', cITDNI, 'DNI', 9, 9, (poCampo.value != '034' && poCampo.value != '376'), false);
		document.getElementById(cITDNI).title = (lSErrores != '' ? lSErrores.substring(1) : '');
		MostrarCorrectoIncorrecto(document.getElementById(cITDNI), (lSErrores == ''));
	}
}

/********************************************************************/
function Form_ValidateAmigo(FrmValidar, BtnValidar) { 
	var errores = ""; 
	errores += Field_Validate(FrmValidar, 'Nombre', 'ITNombre', 'string', 2, 100, true, true); 
	errores += Field_Validate(FrmValidar, 'Email', cITEMail, 'e-mail', 6, 100, true, true); 
	errores += Field_Validate(FrmValidar, 'Email amigo', 'ITEMailAmigo', 'e-mail', 6, 100, true, true); 
	if (errores) {
		errores = "Se han producido los siguientes errores en el formulario,\npor favor, corrígelos para poder continuar.\n" + errores; 
		alert(errores);
	} else {
		EnviarAmigo.submit();
	}
}
/**************** FUNCIONES DE VALIDACION DE FECHA ******************/
function esDigito(sChr){
	var sCod = sChr.charCodeAt(0);
	return ((sCod > 47) && (sCod < 58));
}
/********************************************************************/
function valSep(oTxt){
	var bOk = false;
	bOk = bOk || ((oTxt.charAt(2) == "-") && (oTxt.charAt(5) == "-"));
	bOk = bOk || ((oTxt.charAt(2) == "/") && (oTxt.charAt(5) == "/"));
	return bOk;
}
/********************************************************************/
function finMes(oTxt){
	var nMes = parseInt(oTxt.substr(3, 2), 10);
	var nRes = 0;
	switch (nMes){
		case 1: nRes = 31; break;
		case 2: nRes = 29; break;
		case 3: nRes = 31; break;
		case 4: nRes = 30; break;
		case 5: nRes = 31; break;
		case 6: nRes = 30; break;
		case 7: nRes = 31; break;
		case 8: nRes = 31; break;
		case 9: nRes = 30; break;
		case 10: nRes = 31; break;
		case 11: nRes = 30; break;
		case 12: nRes = 31; break;
	}
	return nRes;
}
/********************************************************************/
function valDia(oTxt){
	var bOk = false;
	var nDia = parseInt(oTxt.substr(0, 2), 10);
	bOk = bOk || ((nDia >= 1) && (nDia <= finMes(oTxt)));
	return bOk;
}
/********************************************************************/
function valMes(oTxt){
	var bOk = false;
	var nMes = parseInt(oTxt.substr(3, 2), 10);
	bOk = bOk || ((nMes >= 1) && (nMes <= 12));
	return bOk;
}
/********************************************************************/
function valAno(oTxt){
	var bOk = true;
	var nAno = oTxt.substr(6);
	bOk = bOk && ((nAno.length == 2) || (nAno.length == 4));
	if (bOk){
		for (var i = 0; i < nAno.length; i++) { bOk = bOk && esDigito(nAno.charAt(i)); }
	}
	return bOk;
}
/********************************************************************/
function valFecha(pSNombreCampo, oTxt){
	var bOk = true;
	if (oTxt != ""){
		bOk = bOk && (valAno(oTxt));
		bOk = bOk && (valMes(oTxt));
		bOk = bOk && (valDia(oTxt));
		bOk = bOk && (valSep(oTxt));
		if (!bOk){
			return '\n- ' + pSNombreCampo + ': La fecha no es correcta. Revise los valores de día y mes.';
		}
	}
	return '';
}
/********************************************************************/
function ComprobarMayoriaEdad(pSNombreFormulario, pSNombreCampo, piDia, piMes, piAnyo) {
	if (!isNaN(piDia) && !isNaN(piMes) && !isNaN(piAnyo)) {
		var firstDate = new Date() ;
		var secondDate = new Date(piAnyo, piMes, piDia);
		var firstYear = firstDate.getFullYear();
		var secondYear = secondDate.getFullYear();
	 
		if (firstYear < secondYear) { fisrtYear = firstYear + 100; } //Account for some browsers & Y2K
	 
		var years = firstYear - secondYear;
	 
		var firstMonth = firstDate.getMonth();
		var secondMonth = secondDate.getMonth();
	 
		if (firstMonth < secondMonth) { years = years - 1; }
		if (firstMonth == secondMonth) { 
			var firstDay = firstDate.getDate();
			var secondDay = secondDate.getDate();
			if (firstDay < secondDay) { years = years - 1; }
		}
		if (years < 14) {
			var lSError = pSNombreCampo + ': Conforme a la Ley Vigente, le informamos que no podemos recoger datos de menores de 14 años.';
			if (typeof(s) != "undefined") { s.sendFormEvent('e', s.pageName, pSNombreFormulario, lSError); }
			return '\n- ' + lSError;
		}
	}
	return '';
}
/******************** FUNCIONES DE VALIDACION ***************************/

/******************** FUNCIONES DE POPUP ***************************/
function popup (tamanyX, tamanyY, adre, nom, posX, posY, attr) {
				var x=(screen.width-tamanyX) * posX / 100;
                var y=(screen.height-tamanyY) * posY / 100;
                if (attr=="") {attr='resizable=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0'}

                finestra=open(adre,nom,attr+',width='+tamanyX+',height='+tamanyY+',left='+x+',top='+y+',screenX='+x+',screenY='+y+'');
                if (mac && !ns4) {finestra.moveTo(x,y)}
}
/******************** FUNCIONES DE POPUP ***************************/

/******************** FUNCIONES PARA LAS COMBOS DE FECHAS ***************************/

function isSpecial(year) { 
	if (document.getElementById(cSFechaNacimientoAnyo).options[document.getElementById(cSFechaNacimientoAnyo).options.selectedIndex].value != "") {
		if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) { return true; }
		else { return false; }
	} else {
		return false;
	}
} 

function clearSelect(obj) { 
	while(obj.hasChildNodes()) {
		obj.removeChild(obj.firstChild); 
	}
} 

function addOption(obj, val, text) { 
	var newOpt = document.createElement("option"); 
	newOpt.appendChild(document.createTextNode(text)); 
	newOpt.setAttribute("value", (val != '' ? (val < 10 ? '0' + val : val) : '')); 
	obj.appendChild(newOpt); 
}

function fill_days(obj, month, year) {
	var last_day;
	
	if (month == 2) { last_day = (isSpecial(year) ? 29 : 28); }
	else if ( month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { last_day = 31; }
	else { last_day = 30; }
	
	addOption(obj, "", "Día");
	for (var a = 1; a <= last_day; a++) {
		addOption(obj, a, a);
	}
}

function updateDays() {
	
	var oDay = document.getElementById(cSFechaNacimientoDia);
	var oMonth = document.getElementById(cSFechaNacimientoMes);
	var oYear = document.getElementById(cSFechaNacimientoAnyo);
	
	var today = oDay.options.selectedIndex;
	
	clearSelect(oDay);
	if (oMonth.options[oMonth.options.selectedIndex].value != "") {
		fill_days(oDay, oMonth.options[oMonth.options.selectedIndex].value, oYear.options[oYear.options.selectedIndex].value);
		try {
			oDay.options.selectedIndex = today;
		} catch (e) {
			oDay.options.selectedIndex = 0;
		}
	} else {
		fill_days(oDay, '01', new Date().getYear());
	}
}

function updateMonths() {
	var oMes = document.getElementById(cSFechaNacimientoMes);
	var liSeleccionado = parseInt(oMes.value);
	clearSelect(oMes);

	addOption(oMes, '', 'Mes');
	for (i = 1; i <= 12; i++) { 
		addOption(oMes, i, i); 
		if (i == liSeleccionado) { oMes.selectedIndex = i; }
	}
}

function updateYears() {
	var oYear = document.getElementById(cSFechaNacimientoAnyo);
	var liSeleccionado = parseInt(oYear.value);
	clearSelect(oYear);

	var hoy = new Date();
	addOption(oYear, '', 'Año');
	for (i = 1900; i <= hoy.getFullYear(); i++) {
		addOption(oYear, i, i);
		if (i == liSeleccionado) { oYear.selectedIndex = i - 1900 + 1; }
	}
}
/******************** FUNCIONES PARA LAS COMBOS DE FECHAS ***************************/

/******************** FUNCIONES PARA OTRAS COMBOS ***************************/
function updateNationalities() {
	var lASNationalityCodes = new Array('034','049','376','213','054','043','032','591','387','055','359','237','056','086','057','506','385','053','045','593','503','421','386','001','372','358','033','030','502','031','504','036','353','354','039','081','371','370','352','389','212','222','052','377','505','047','507','595','051','048','351','787','044','420','851','040','007','046','041','216','090','380','598','058','999');
	var lASNationalities = new Array('España','Alemania','Andorra','Argelia','Argentina','Austria','Bélgica','Bolivia','Bosnia.H.','Brasil','Bulgaria','Camerún','Chile','China','Colombia','Costa Rica','Croacia','Cuba','Dinamarca','Ecuador','El Salvador','Eslovaquia','Eslovenia','EEUU','Estonia','Finlandia','Francia','Grecia','Guatemala','Holanda','Honduras','Hungría','Irlanda','Islandia','Italia','Japón','Letonia','Lituania','Luxemburgo','Macedonia','Marruecos','Mauritania','M&eacute;xico','Mónaco','Nicaragua','Noruega','Panamá','Paraguay','Perú','Polonia','Portugal','Puerto Rico','Reino Unido','Rep. Checa','Rep. Dominicana','Rumanía','Rusia','Suecia','Suiza','Túnez','Turquía','Ucrania','Uruguay','Venezuela','Otros');
	var oNationality = document.getElementById(cSNacionalidad);
	clearSelect(oNationality);

	var hoy = new Date();
	addOption(oNationality, '', 'Selecciona...');
	for (liAux = 0; liAux < lASNationalityCodes.length; liAux++) {
		addOption(oNationality, lASNationalityCodes[liAux], lASNationalities[liAux]);
	}
}

function updateWorks() {
	var lASWorkCodes = new Array('2500','3300','1702','2703','3801','3400','3300','405','3800');
	var lASWorks = new Array('Estudiante/universitario','Empresario','Ejecutivo/Directivo','Empleado por cuenta ajena','Ama de casa','Jubilado','Autónomo/Profesional Liberal','Funcionario/Militar','Desempleado');
	var oWork = document.getElementById("SOcupacion");
	clearSelect(oWork);

	var hoy = new Date();
	addOption(oWork, '', 'Selecciona...');
	for (liAux = 0; liAux < lASWorkCodes.length; liAux++) {
		addOption(oWork, lASWorkCodes[liAux], lASWorks[liAux]);
	}
}
/******************** FUNCIONES PARA OTRAS COMBOS ***************************/

/******************** FUNCIONES PARA EL CONTROL DE LOS DATOS INTRODUCIDOS ***************************/
function Direccion(textControl, keyCode, key) {
	var lSCaracteresPermitidos = "()/ºª'&.-ÇÁÉÍÓÚÀÈÌÙÒÄËÏÖÜÑ 1234567890";
  var newKey = key.toUpperCase();
	if ((newKey >= "A" && newKey <= "Z") || lSCaracteresPermitidos.indexOf(newKey) >= 0) {
		if (newKey != key) {
			return { replaceKey: true, newKeyCode: newKey.charCodeAt(), newKey: newKey };
		} else {
			return { cancelKey: false };
		}
	} else {
		return { cancelKey: true };
	}
}

function DNI(textControl, keyCode, key) {
	var lSValor = textControl.value;
  var newKey = key.toUpperCase();
	if (
		(lSValor.length == 0 && ("0123456789".indexOf(key) != -1 || newKey == "X" || newKey == "Y" || newKey == "Z")) ||
		(lSValor.length > 0  && lSValor.length < 8 && "0123456789".indexOf(key) != -1) ||
		(lSValor.length == 8 && "0123456789".indexOf(key) == -1)) {
		if (newKey != key) {
			return { replaceKey: true, newKeyCode: newKey.charCodeAt(), newKey: newKey };
		} else {
			return { cancelKey: false };
		}
	} else {
		return { cancelKey: true };
	}
}
/******************** FUNCIONES PARA EL CONTROL DE LOS DATOS INTRODUCIDOS ***************************/

/******************** FUNCIONES PARA LA VALIDACIÓN DE DATOS EXTRAS DEL CARRITO ***************************/
function ValidaPotitica(source, args) {
	args.IsValid = document.getElementById(CBPolitica).checked;
}

function ComprobarMayoriaEdadValidador(sender, args) {
	sender.errormessage = ComprobarMayoriaEdad(document.forms[0].id, 'Fecha de Nacimiento', document.getElementById(cSFechaNacimientoDia).value, document.getElementById(cSFechaNacimientoMes).value, document.getElementById(cSFechaNacimientoAnyo).value);
	sender.errormessage = (sender.errormessage != '' ? sender.errormessage.substring(1) : '');
	args.IsValid = (sender.errormessage == '');
}

function NombreFacturacionValidador(sender, args) {
	sender.errormessage = Field_Validate(document.forms[0].id, 'Nombre (datos facturación)', cTBFNombre, 'nombre', 2, 50, true, true);
	sender.errormessage = (sender.errormessage != '' ? sender.errormessage.substring(1) : '');
	args.IsValid = (sender.errormessage == '');
}

function Apellido1FacturacionValidador(sender, args) {
	sender.errormessage = Field_Validate(document.forms[0].id, 'Primer apellido (datos facturación)', cTBFApellido1, 'nombre', 2, 50, true, true);
	sender.errormessage = (sender.errormessage != '' ? sender.errormessage.substring(1) : '');
	args.IsValid = (sender.errormessage == '');
}

function Apellido2FacturacionValidador(sender, args) {
	sender.errormessage = Field_Validate(document.forms[0].id, 'Segundo apellido (datos facturación)', cTBFApellido2, 'nombre', 2, 50, true, true);
	sender.errormessage = (sender.errormessage != '' ? sender.errormessage.substring(1) : '');
	args.IsValid = (sender.errormessage == '');
}

function DNINIEFacturacionValidador(sender, args) {
	sender.errormessage = Field_Validate(document.forms[0].id, 'DNI/NIE (datos facturación)', cITDNI, 'DNI', 9, 9, (document.getElementById(cSNacionalidad) != null && document.getElementById(cSNacionalidad).value != '034' && document.getElementById(cSNacionalidad).value != '376'), true);
	sender.errormessage = (sender.errormessage != '' ? sender.errormessage.substring(1) : '');
	args.IsValid = (sender.errormessage == '');
}

function DireccionFacturacionValidador(sender, args) {
	sender.errormessage = Field_Validate(document.forms[0].id, 'Dirección (datos facturación)', cTBFDireccion, 'direccion', 2, 100, true, true);
	sender.errormessage = (sender.errormessage != '' ? sender.errormessage.substring(1) : '');
	args.IsValid = (sender.errormessage == '');
}

function PoblacionFacturacionValidador(sender, args) {
	sender.errormessage = Field_Validate(document.forms[0].id, 'Población (datos facturación)', cTBFPoblacion, 'nombre', 2, 50, true, true);
	sender.errormessage = (sender.errormessage != '' ? sender.errormessage.substring(1) : '');
	args.IsValid = (sender.errormessage == '');
}

function ProvinciaFacturacionValidador(sender, args) {
	sender.errormessage = Field_Validate(document.forms[0].id, 'Provincia (datos facturación)', cTBFProvincia, 'nombre', 2, 50, true, true);
	sender.errormessage = (sender.errormessage != '' ? sender.errormessage.substring(1) : '');
	args.IsValid = (sender.errormessage == '');
}

function CodigoPostalFacturacionValidador(sender, args) {
	sender.errormessage = Field_Validate(document.forms[0].id, 'Código postal (datos facturación)', cTBFCPostal, 'cpostal', 5, 5, true, true);
	sender.errormessage = (sender.errormessage != '' ? sender.errormessage.substring(1) : '');
	args.IsValid = (sender.errormessage == '');
}

function TelefonoFacturacionValidador(sender, args) {
	sender.errormessage = Field_Validate(document.forms[0].id, 'Teléfono (datos facturación)', cITTelefono, 'telefono', 9, 9, true, true);
	sender.errormessage = (sender.errormessage != '' ? sender.errormessage.substring(1) : '');
	args.IsValid = (sender.errormessage == '');
}

function EmailFacturacionValidador(sender, args) {
	sender.errormessage = Field_Validate(document.forms[0].id, 'Email (datos facturación)', cITEMail, 'email', 6, 100, true, true);
	sender.errormessage = (sender.errormessage != '' ? sender.errormessage.substring(1) : '');
	args.IsValid = (sender.errormessage == '');
}

function ExtensionFacturacionValidador(sender, args) {
	sender.errormessage = Field_Validate(document.forms[0].id, 'Extensión (datos facturación)', cTBFExtension, 'extension', 4, 4, true, true);
	sender.errormessage = (sender.errormessage != '' ? sender.errormessage.substring(1) : '');
	args.IsValid = (sender.errormessage == '');
}

function NombreEnvioValidador(sender, args) {
	sender.errormessage = Field_Validate(document.forms[0].id, 'Nombre (datos envío)', cTBENombre, 'nombre', 2, 50, true, true);
	sender.errormessage = (sender.errormessage != '' ? sender.errormessage.substring(1) : '');
	args.IsValid = (sender.errormessage == '');
}

function Apellido1EnvioValidador(sender, args) {
	sender.errormessage = Field_Validate(document.forms[0].id, 'Primer apellido (datos envío)', cTBEApellido1, 'nombre', 2, 50, true, true);
	sender.errormessage = (sender.errormessage != '' ? sender.errormessage.substring(1) : '');
	args.IsValid = (sender.errormessage == '');
}

function Apellido2EnvioValidador(sender, args) {
	sender.errormessage = Field_Validate(document.forms[0].id, 'Segundo apellido (datos envío)', cTBEApellido2, 'nombre', 2, 50, true, true);
	sender.errormessage = (sender.errormessage != '' ? sender.errormessage.substring(1) : '');
	args.IsValid = (sender.errormessage == '');
}

function DireccionEnvioValidador(sender, args) {
	if (document.getElementById(cDDLFEntrega) != null && document.getElementById(cDDLFEntrega).value != "1") {
		// El dato se ha informado automáticamente
		args.IsValid = true;
	} else {
		// El usuario ha introducido el dato a mano
		sender.errormessage = Field_Validate(document.forms[0].id, 'Dirección (datos envío)', cTBEDireccion, 'direccion', 2, 100, true, true);
		sender.errormessage = (sender.errormessage != '' ? sender.errormessage.substring(1) : '');
		args.IsValid = (sender.errormessage == '');
	}
}

function PoblacionEnvioValidador(sender, args) {
	if (document.getElementById(cDDLFEntrega) != null && document.getElementById(cDDLFEntrega).value != "1") {
		// El dato se ha informado automáticamente
		args.IsValid = true;
	} else {
		// El usuario ha introducido el dato a mano
		sender.errormessage = Field_Validate(document.forms[0].id, 'Población (datos envío)', cTBEPoblacion, 'nombre', 2, 50, true, true);
		sender.errormessage = (sender.errormessage != '' ? sender.errormessage.substring(1) : '');
		args.IsValid = (sender.errormessage == '');
	}
}

function ProvinciaEnvioValidador(sender, args) {
	if (document.getElementById(cDDLFEntrega) != null && document.getElementById(cDDLFEntrega).value != "1") {
		// El dato se ha informado automáticamente
		args.IsValid = true;
	} else {
		// El usuario ha introducido el dato a mano
		sender.errormessage = Field_Validate(document.forms[0].id, 'Provincia (datos envío)', cTBEProvincia, 'nombre', 2, 50, true, true);
		sender.errormessage = (sender.errormessage != '' ? sender.errormessage.substring(1) : '');
		args.IsValid = (sender.errormessage == '');
	}
}

function CodigoPostalEnvioValidador(sender, args) {
	sender.errormessage = Field_Validate(document.forms[0].id, 'Código postal (datos envío)', cTBECPostal, 'cpostal', 5, 5, true, true);
	sender.errormessage = (sender.errormessage != '' ? sender.errormessage.substring(1) : '');
	args.IsValid = (sender.errormessage == '');
}

function InicializarValidacionCarrito() {
	if (document.getElementById(cTBFNombre) != null) {
		document.getElementById(cTBFNombre).onkeypress = function(evt) { return changeKey(this, (window.event || evt), Nombre_Apellidos); };
		document.getElementById(cTBFNombre).onkeyup = function() { var lSErrores = Field_Validate(document.forms[0].id, 'Nombre (datos facturación)', this.id, 'nombre', 2, 50, true, false); this.title = (lSErrores != '' ? lSErrores.substring(1) : ''); MostrarCorrectoIncorrecto(this, (lSErrores == '')); };
		document.getElementById(cTBFNombre).maxLength = 50;
	}
	if (document.getElementById(cTBFApellido1) != null) {
		document.getElementById(cTBFApellido1).onkeypress = function(evt) { return changeKey(this, (window.event || evt), Nombre_Apellidos); };
		document.getElementById(cTBFApellido1).onkeyup = function () { var lSErrores = Field_Validate(document.forms[0].id, 'Primer apellido (datos facturación)', this.id, 'nombre', 2, 50, true, false); this.title = (lSErrores != '' ? lSErrores.substring(1) : ''); MostrarCorrectoIncorrecto(this, (lSErrores == '')); };
		document.getElementById(cTBFApellido1).maxLength = 50;
	}
	if (document.getElementById(cTBFApellido2) != null) {
		document.getElementById(cTBFApellido2).onkeypress = function(evt) { return changeKey(this, (window.event || evt), Nombre_Apellidos); };
		document.getElementById(cTBFApellido2).onkeyup = function () { var lSErrores = Field_Validate(document.forms[0].id, 'Segundo apellido (datos facturación)', this.id, 'nombre', 2, 50, true, false); this.title = (lSErrores != '' ? lSErrores.substring(1) : ''); MostrarCorrectoIncorrecto(this, (lSErrores == '')); };
		document.getElementById(cTBFApellido2).maxLength = 50;
	}
	if (document.getElementById(cTBFDireccion) != null) {
		document.getElementById(cTBFDireccion).onkeypress = function(evt) { return changeKey(this, (window.event || evt), Direccion); };
		document.getElementById(cTBFDireccion).onkeyup = function () { var lSErrores = Field_Validate(document.forms[0].id, 'Dirección (datos facturación)', this.id, 'direccion', 2, 100, true, false); this.title = (lSErrores != '' ? lSErrores.substring(1) : ''); MostrarCorrectoIncorrecto(this, (lSErrores == '')); };
		document.getElementById(cTBFDireccion).maxLength = 100;
	}
	if (document.getElementById(cTBFPoblacion) != null) {
		document.getElementById(cTBFPoblacion).onkeypress = function(evt) { return changeKey(this, (window.event || evt), Nombre_Apellidos); };
		document.getElementById(cTBFPoblacion).onkeyup = function () { var lSErrores = Field_Validate(document.forms[0].id, 'Población (datos facturación)', this.id, 'nombre', 2, 50, true, false); this.title = (lSErrores != '' ? lSErrores.substring(1) : ''); MostrarCorrectoIncorrecto(this, (lSErrores == '')); };
		document.getElementById(cTBFPoblacion).maxLength = 50;
	}
	if (document.getElementById(cTBFProvincia) != null) {
		document.getElementById(cTBFProvincia).onkeypress = function(evt) { return changeKey(this, (window.event || evt), Nombre_Apellidos); };
		document.getElementById(cTBFProvincia).onkeyup = function () { var lSErrores = Field_Validate(document.forms[0].id, 'Provincia (datos facturación)', this.id, 'nombre', 2, 50, true, false); this.title = (lSErrores != '' ? lSErrores.substring(1) : ''); MostrarCorrectoIncorrecto(this, (lSErrores == '')); };
		document.getElementById(cTBFProvincia).maxLength = 50;
	}
	if (document.getElementById(cTBFCPostal) != null) {
		document.getElementById(cTBFCPostal).onkeypress = function(evt) { return changeKey(this, (window.event || evt), cancelNoDigits); };
		document.getElementById(cTBFCPostal).onkeyup = function () { var lSErrores = Field_Validate(document.forms[0].id, 'Código postal (datos facturación)', this.id, 'cpostal', 5, 5, true, false); this.title = (lSErrores != '' ? lSErrores.substring(1) : ''); MostrarCorrectoIncorrecto(this, (lSErrores == '')); };
		document.getElementById(cTBFCPostal).maxLength = 5;
	}
	if (document.getElementById(cTBFExtension) != null) {
		document.getElementById(cTBFExtension).onkeypress = function(evt) { return changeKey(this, (window.event || evt), cancelNoDigits); };
		document.getElementById(cTBFExtension).onkeyup = function () { var lSErrores = Field_Validate(document.forms[0].id, 'Extensión (datos facturación)', this.id, 'extension', 4, 4, true, false); this.title = (lSErrores != '' ? lSErrores.substring(1) : ''); MostrarCorrectoIncorrecto(this, (lSErrores == '')); };
		document.getElementById(cTBFExtension).maxLength = 4;
	}
	if (document.getElementById(cTBENombre) != null) {
		document.getElementById(cTBENombre).onkeypress = function(evt) { return changeKey(this, (window.event || evt), Nombre_Apellidos); };
		document.getElementById(cTBENombre).onkeyup = function () { var lSErrores = Field_Validate(document.forms[0].id, 'Nombre (datos envío)', this.id, 'nombre', 2, 50, true, false); this.title = (lSErrores != '' ? lSErrores.substring(1) : ''); MostrarCorrectoIncorrecto(this, (lSErrores == '')); };
		document.getElementById(cTBENombre).maxLength = 50;
	}
	if (document.getElementById(cTBEApellido1) != null) {
		document.getElementById(cTBEApellido1).onkeypress = function(evt) { return changeKey(this, (window.event || evt), Nombre_Apellidos); };
		document.getElementById(cTBEApellido1).onkeyup = function () { var lSErrores = Field_Validate(document.forms[0].id, 'Primer apellido (datos envío)', this.id, 'nombre', 2, 50, true, false); this.title = (lSErrores != '' ? lSErrores.substring(1) : ''); MostrarCorrectoIncorrecto(this, (lSErrores == '')); };
		document.getElementById(cTBEApellido1).maxLength = 50;
	}
	if (document.getElementById(cTBEApellido2) != null) {
		document.getElementById(cTBEApellido2).onkeypress = function(evt) { return changeKey(this, (window.event || evt), Nombre_Apellidos); };
		document.getElementById(cTBEApellido2).onkeyup = function () { var lSErrores = Field_Validate(document.forms[0].id, 'Segundo apellido (datos envío)', this.id, 'nombre', 2, 50, true, false); this.title = (lSErrores != '' ? lSErrores.substring(1) : ''); MostrarCorrectoIncorrecto(this, (lSErrores == '')); };
		document.getElementById(cTBEApellido2).maxLength = 50;
	}
	if (document.getElementById(cTBEDireccion) != null) {
		document.getElementById(cTBEDireccion).onkeypress = function(evt) { return changeKey(this, (window.event || evt), Direccion); };
		document.getElementById(cTBEDireccion).onkeyup = function () { var lSErrores = Field_Validate(document.forms[0].id, 'Dirección (datos envío)', this.id, 'direccion', 2, 100, true, false); this.title = (lSErrores != '' ? lSErrores.substring(1) : ''); MostrarCorrectoIncorrecto(this, (lSErrores == '')); };
		document.getElementById(cTBEDireccion).maxLength = 100;
	}
	if (document.getElementById(cTBEPoblacion) != null) {
		document.getElementById(cTBEPoblacion).onkeypress = function(evt) { return changeKey(this, (window.event || evt), Nombre_Apellidos); };
		document.getElementById(cTBEPoblacion).onkeyup = function () { var lSErrores = Field_Validate(document.forms[0].id, 'Población (datos envío)', this.id, 'nombre', 2, 50, true, false); this.title = (lSErrores != '' ? lSErrores.substring(1) : ''); MostrarCorrectoIncorrecto(this, (lSErrores == '')); };
		document.getElementById(cTBEPoblacion).maxLength = 50;
	}
	if (document.getElementById(cTBEProvincia) != null) {
		document.getElementById(cTBEProvincia).onkeypress = function(evt) { return changeKey(this, (window.event || evt), Nombre_Apellidos); };
		document.getElementById(cTBEProvincia).onkeyup = function () { var lSErrores = Field_Validate(document.forms[0].id, 'Provincia (datos envío)', this.id, 'nombre', 2, 50, true, false); this.title = (lSErrores != '' ? lSErrores.substring(1) : ''); MostrarCorrectoIncorrecto(this, (lSErrores == '')); };
		document.getElementById(cTBEProvincia).maxLength = 50;
	}
	if (document.getElementById(cTBECPostal) != null) {
		document.getElementById(cTBECPostal).onkeypress = function(evt) { return changeKey(this, (window.event || evt), cancelNoDigits); };
		document.getElementById(cTBECPostal).onkeyup = function () { var lSErrores = Field_Validate(document.forms[0].id, 'Código postal (datos envío)', this.id, 'cpostal', 5, 5, true, false); this.title = (lSErrores != '' ? lSErrores.substring(1) : ''); MostrarCorrectoIncorrecto(this, (lSErrores == '')); };
		document.getElementById(cTBECPostal).maxLength = 5;
	}
	if (typeof(window.carrito_window_onload_anterior) == 'function') { window.carrito_window_onload_anterior(); }
}
/******************** FUNCIONES PARA LA VALIDACIÓN DE DATOS EXTRAS DEL CARRITO ***************************/

//-->
