/* javascipt con mootools */ var myRequestMostrarInfoForm = new Request.HTML(); var myRequestEnviarInfoForm = new Request.HTML(); var objContainerFx = new Fx.Slide('containerFx', { duration: 1500, mode: 'horizontal' /*transition: Fx.Transitions.Bounce.easeOut*/ }); var mas_info_div = new Element('div', { 'class': 'mas_info_div', 'html': 'Requests information or budget' }); var error_div = new Element('div', { 'class': 'error', 'html': 'Please enter correct the details in red. ' }); window.addEvent('domready', function() { addMasInfoDebajoDelUltimoParrafo(); // otros elements que actĂșan como mas_info addEventoToSimilarMas_info('correo_info_foot'); addEventoToSimilarMas_info('correo_madrid'); addEventoToSimilarMas_info('correo_salamanca'); addEventoToSimilarMas_info('noti_titular'); addEventoToSimilarMas_info('noti_princial'); }); function addMasInfoDebajoDelUltimoParrafo( ) { if ($defined($('mas_info_a'))) return; //alert(document.location); var url_actual = document.location; if ( url_actual.toString().indexOf('index')!=-1 ) return; if ( url_actual=='http://www.toldosmonita.com/' ) return; if ( url_actual.toString().indexOf('nager')!=-1 ) return; if ( url_actual.toString().indexOf('descargas')!=-1 ) return; if ( url_actual.toString().indexOf('os-ha-conocido')!=-1 ) return; if ( url_actual.toString().indexOf('empleo')!=-1 ) return; var lastElement = null; $('content').getElements('[class=parrafo]').each(function(element, index) { lastElement = element; }); if (lastElement==null) { //$('content').grab(mas_info_div); /* divObjElement = $('content').getElement('[class=obj_cen]'); if (divObjElement != null) divObjElement.grab(mas_info_div); else $('content').grab(mas_info_div); */ divPanel = $('content').getElement('[class=panel]'); if (divPanel != null) divPanel.grab(mas_info_div,'top'); else $('content').grab(mas_info_div); } else { lastElement.grab(mas_info_div); } addEventoToMas_info_a(); return; } function addEventoToMas_info_a( ) { $('mas_info_a').addEvent('click', function(e) { e.stop(); objContainerFx.slideOut(); requestMostrarInfoForm(); pageTracker._trackPageview('/info/mostrar/'); }); } function addEventoToSimilarMas_info( _id ) { if ( !$defined($(_id)) ) return; $(_id).addEvent('click', function(e) { e.stop(); objContainerFx.slideOut(); requestMostrarInfoForm(); pageTracker._trackPageview('/info/mostrar/'); }); } function ocultarContainerFx(){ // ocultar containerFx por el flash $('containerFx').addClass('oculto'); }; function mostrarContainerFx(){ // ocultar containerFx por el flash $('containerFx').removeClass('oculto'); }; function ocultarInfo(){ // ocultar containerFx por el flash $('info').addClass('oculto'); }; function mostrarInfo(){ // ocultar containerFx por el flash $('info').removeClass('oculto'); }; function requestMostrarInfoForm( ) { mostrarInfo.delay(1400); myRequestMostrarInfoForm.onSuccess=function(html) { $('info').set('text', ''); $('info').adopt(html); if ($defined($('cerrar'))) addEventoToCerrarYVolver('cerrar'); if ($defined($('volver'))) addEventoToCerrarYVolver('volver'); if ($defined($('infoForm'))) { addEventoToInfoFormInputs(); } if ($defined($('fkIdProductoNoti'))) { $('fkIdProducto').set('value',$('fkIdProductoNoti').get('value')); } //if ($defined($('fkIdProductoNoti'))) { $('fkIdProducto').set('value',$('fkIdProductoNoti').get('value')); alert('fkIdProductoNoti='+$('fkIdProductoNoti').get('value')); } }; myRequestMostrarInfoForm.onFailure=function(html) { $('info').set('text', 'The request failed.'); }; myRequestMostrarInfoForm.send({url:'info.php', data: 'accion=info.nuevo&ajax=true' }); } function addEventoToCerrarYVolver( _id ) { $(_id).addEvent('click', function(e) { e.stop(); ocultarInfo.delay(0); objContainerFx.slideIn('horizontal'); pageTracker._trackPageview('/info/cerrar/'); }); } function addEventoToInfoFormInputs( _id ) { $('ajax').set('value','true'); $('nombreCompleto').addEvent('blur', function(e) { if ((this.get('value')).length < 3) this.addClass('errorInput'); else if (this.hasClass('errorInput')) this.removeClass('errorInput'); }); $('cliTipoEmpresa').addEvent('click', function(e) { if ($('empresa').hasClass('oculto')) { $('empresa').removeClass('oculto'); } }); $('cliTipoParticular').addEvent('click', function(e) { $('empresa').addClass('oculto'); }); /* $('cliTipo').addEvent('change', function(e) { if ( this.get('value')=='Empresa' ) { if ($('empresa').hasClass('oculto')) $('empresa').removeClass('oculto'); } else { $('empresa').addClass('oculto'); } }); */ $('empresa').addEvent('blur', function(e) { //alert($('cliTipoEmpresa').get('checked')); if ( $('cliTipoEmpresa').get('checked')==true && ($('empresa').get('value')).length < 3 ) { $('empresa').addClass('errorInput'); } else { if ($('empresa').hasClass('errorInput')) $('empresa').removeClass('errorInput'); } }); $('correo').addEvent('blur', function(e) { if ( !regIsEmail(this.get('value')) ) this.addClass('errorInput'); else if (this.hasClass('errorInput')) this.removeClass('errorInput'); }); $('categoria').addEvent('blur', function(e) { if ( this.get('value')==0 || isNaN(this.get('value')) ) this.addClass('errorInput'); else if (this.hasClass('errorInput')) this.removeClass('errorInput'); }); $('tlf').addEvent('blur', function(e) { if ((this.get('value')).length < 9) this.addClass('errorInput'); else if (this.hasClass('errorInput')) this.removeClass('errorInput'); }); $('lugar').addEvent('change', function(e) { if ( this.get('value')=='Spain' ) { if ($('provincia').hasClass('oculto')) $('provincia').removeClass('oculto'); } else { $('provincia').addClass('oculto'); } }); $('provincia').addEvent('blur', function(e) { if ( $('lugar').get('value')=='Spain' && this.get('value')==0 ) this.addClass('errorInput'); else if (this.hasClass('errorInput')) this.removeClass('errorInput'); }); $('infoForm').addEvent('submit', function(e) { e.stop(); pageTracker._trackPageview('/info/enviar/'); var result = validarForm( this ); if ( result==true ) { $('message_dbj').set('text', ''); requestEnviarInfoForm( this ); } else { $('message_dbj').adopt(error_div); pageTracker._trackPageview('/info/errorValidacion/'); } return false; }); } function validarForm( _form ) { var error = ''; if ( $('ConsentimientoLOPD').getProperty('checked')!=true ) { $('ConsentimientoLOPDError').addClass('errorInput'); error += 'ConsentimientoLOPD'; } else { if ($('ConsentimientoLOPDError').hasClass('errorInput')) $('ConsentimientoLOPD').removeClass('errorInput'); } if (($('nombreCompleto').get('value')).length < 3) { $('nombreCompleto').addClass('errorInput'); error += 'nombreCompleto'; } else { if ($('nombreCompleto').hasClass('errorInput')) $('nombreCompleto').removeClass('errorInput'); } if ( $('cliTipoEmpresa').get('checked')==true && ($('empresa').get('value')).length < 3 ) { $('empresa').addClass('errorInput'); error += 'empresa'; } else { if ($('empresa').hasClass('errorInput')) $('empresa').removeClass('errorInput'); } if ( !regIsEmail($('correo').get('value')) ) { $('correo').addClass('errorInput'); error += 'correo'; } else { if ($('correo').hasClass('errorInput')) $('correo').removeClass('errorInput'); } if ( $('categoria').get('value')==0 || isNaN($('categoria').get('value')) ) { $('categoria').addClass('errorInput'); error += 'categoria'; } else { if ($('categoria').hasClass('errorInput')) $('categoria').removeClass('errorInput'); } if ( $('lugar').get('value')=='Spain' && $('provincia').get('value')==0 ) { $('provincia').addClass('errorInput'); error += 'provincia'; } else { if ($('provincia').hasClass('errorInput')) $('provincia').removeClass('errorInput'); } if (($('tlf').get('value')).length < 9) { $('tlf').addClass('errorInput'); error += 'tlf'; } else { if ($('tlf').hasClass('errorInput')) $('tlf').removeClass('errorInput'); } //alert(error); if (error=='') return true; return false; } function requestEnviarInfoForm( _form ) { $('enviarInfoForm').addClass('oculto'); $('loading').removeClass('oculto'); myRequestEnviarInfoForm.onSuccess=function(html) { ocultarInfo.delay(0); objContainerFx.slideIn('horizontal'); $('message_dbj').adopt(html); pageTracker._trackPageview('/info/enviadoOK/'); }; myRequestEnviarInfoForm.onFailure=function(html) { //$('message_dbj').getElement('div[class="error"]').set('text', 'The request failed.'); //$('message_dbj').adopt(html); // No recoge el html en onFailure $('message_dbj').adopt(error_div); $('enviarInfoForm').removeClass('oculto'); $('loading').addClass('oculto'); pageTracker._trackPageview('/info/errorOnFailure/'); }; myRequestEnviarInfoForm.send({data: _form, url: _form.get('action')}); } // Check if string is a valid email address function regIsEmail(fData) { /* http://ntt.cc/2008/05/10/over-10-useful-javascript-regular-expression-functions-to-improve-your-web-applications-efficiency.html */ //var reg = new RegExp("^[0-9a-zA-Z]+@[0-9a-zA-Z]+[\.]{1}[0-9a-zA-Z]+[\.]?[0-9a-zA-Z]+$"); var reg = new RegExp("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}$"); //alert('regIsEmail'+reg.test(fData)) return reg.test(fData); }