﻿<!--

// 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_click2call;

if (window.onload != null) { window_onload_anterior_click2call = window.onload; };
window.onload = valid_js_window_onload_click2call;

function valid_js_window_onload_click2call() {
	if (document.getElementById('ITNombreClick2Call') != null) {
		document.getElementById('ITNombreClick2Call').onkeypress = function(evt) { return changeKey(this, (window.event || evt), Nombre_Apellidos); };
		document.getElementById('ITNombreClick2Call').onkeyup = function() { var lSErrores = Field_Validate('Click2CallForm', 'Nombre', this.id, 'nombre', 2, 100, true, false); this.title = (lSErrores != '' ? lSErrores.substring(1) : ''); MostrarCorrectoIncorrecto(this, (lSErrores == '')); };
		document.getElementById('ITNombreClick2Call').maxLength = 256;
	}
	if (document.getElementById('ITApellidosClick2Call') != null) {
		document.getElementById('ITApellidosClick2Call').onkeypress = function(evt) { return changeKey(this, (window.event || evt), Nombre_Apellidos); };
		document.getElementById('ITApellidosClick2Call').onkeyup = function() { var lSErrores = Field_Validate('Click2CallForm', 'Apellidos', this.id, 'nombre', 2, 100, true, false); this.title = (lSErrores != '' ? lSErrores.substring(1) : ''); MostrarCorrectoIncorrecto(this, (lSErrores == '')); };
		document.getElementById('ITApellidosClick2Call').maxLength = 256;
	}
	if (document.getElementById('ITEMailClick2Call') != null) {
		document.getElementById('ITEMailClick2Call').onkeypress = function(evt) { return changeKey(this, (window.event || evt), lettersToLowerCase); };
		document.getElementById('ITEMailClick2Call').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('ITEMailClick2Call').maxLength = 100;
	}

	if (document.getElementById('CPoliticaClick2Call') != null) { document.getElementById('CPoliticaClick2Call').value = '1'; }
	
	if (typeof(window.window_onload_anterior_click2call) == 'function') { window.window_onload_anterior_click2call(); }
}

/******************** FUNCIONES DE VALIDACION ***************************/
function Form_Validate_Click2Call(FrmValidar, Empresa, IdPack, IdPildora, LinkIdClick2Call) {
	var errores = Field_Validate(FrmValidar, 'Nombre', 'ITNombreClick2Call', 'nombre', 2, 256, true, true); 
	errores += Field_Validate(FrmValidar, 'Apellidos', 'ITApellidosClick2Call', 'nombre', 2, 256, true, true); 			
	errores += Field_Validate(FrmValidar, 'Email', 'ITEMailClick2Call', 'email', 6, 100, true, true);
	errores += Field_Validate(FrmValidar, 'Política de privacidad', 'CPoliticaClick2Call', 'checkbox', 1, 1, true, true);
	if (!document.getElementById('CPoliticaClick2Call').checked) { errores += '\n- Debe de aceptar la política de protección de datos para poder continuar.'; }
	
	if (errores) {
		errores = "Se han producido los siguientes errores en el formulario,\npor favor, corrígelos para poder continuar.\n" + errores; 
		alert(errores);
	} else {
		if (typeof(track_links) != 'undefined') { track_links('enlace_click2call', 'event7', 'enlace_ficha_producto'); }
		
		var liId = 0;
		if (typeof(ProspectoEstaraService) != 'undefined') {
			liId = ProspectoEstaraService.Guardar(IdPack, IdPildora, document.getElementById('IHProductoClick2Call').value, document.getElementById('ITNombreClick2Call').value, document.getElementById('ITApellidosClick2Call').value, document.getElementById('ITEMailClick2Call').value, document.getElementById('IHPermitirTratarDatosEmpresas').value, location.href, onGuardarCompleted);
		}
		webVoicePop('Template=' + LinkIdClick2Call, 'var1=' + Empresa, 'var2=' + document.getElementById('IHProductoClick2Call').value, 'var3=' + document.getElementById('ITNombreClick2Call').value, 'var4=' + document.getElementById('ITApellidosClick2Call').value, 'var5=' + document.getElementById('ITEMailClick2Call').value, 'var6=' + liId);
	}
}

function MostrarClick2Call(Empresa, LinkIdClick2Call) {
	if (typeof(track_links) != 'undefined') { track_links('enlace_click2call', 'event7', 'enlace_ficha_producto'); }
	webVoicePop('Template=' + LinkIdClick2Call, 'var1=' + Empresa, 'var2=' + document.getElementById('IHProductoClick2Call').value);
}

function onGuardarCompleted(result) {
  if (result != null) { 
		// No comprobamos la respuesta. No importa si se han podido guardar los datos o no.
  }
}

/******************** FUNCIONES DE VALIDACION ***************************/
//-->
