// ABRE POPUPS
var win = null;

function abrirVentana(url,nombre,ancho,alto,otros) {
     var izquierda = (screen.width-ancho)/2;
     var arriba = (screen.height-alto)/2;
     if (izquierda < 0) izquierda = 0;
     if (arriba < 0) arriba = 0;
     var parametros = 'height=' + alto + ',';
     parametros += 'width=' + ancho + ',';
     parametros += 'top=' + arriba + ',';
     parametros += 'left=' + izquierda + ',';
     parametros += otros;
     win = window.open(url,nombre,parametros);
     win.window.focus();
}



// PERMITE APLICAR LA PSEUDO CLASE HOVER EN EXPLORER
// NECESARIA PARA EL MENU DESPLEGABLE
sfHover = function() {
     var sfEls = document.getElementById("listadoFamiliasMenu").getElementsByTagName("LI");
     for (var i=0; i<sfEls.length; i++) {
          sfEls[i].onmouseover=function() {
               this.className+=" sfhover";
          }
          sfEls[i].onmouseout=function() {
               this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
          }
     }
}

if (window.attachEvent) window.attachEvent("onload", sfHover); 



// EVITA SELECCIONAR TEXTO
function disabletext(e) {
  return false
  }

function reEnable(){
  return true
  }

document.onselectstart=new Function ("return false")
if (window.sidebar) {
  document.onmousedown=disabletext
  document.onclick=reEnable
  }




// INTERCAMBIA FORMULARIOS DE SOLICITUD DE INFORMACIÓN Y RECOMENDACIÓN
var ids=new Array('formSolicitudInformacion','formRecomendarCurso');

function verForm(id){
	hideallids();
	showdiv(id);
}

function hideallids() {
  for (var i=0;i<ids.length;i++){
    hidediv(ids[i]);
  }
}

function hidediv(id) {
  if (document.getElementById) { // DOM3 = IE5, NS6
    document.getElementById(id).style.display = 'none';
  }
  else {
    if (document.layers) { // Netscape 4
      document.id.display = 'none';
    }
    else { // IE 4
      document.all.id.style.display = 'none';
    }
  }
}

function showdiv(id) {
  if (document.getElementById) { // DOM3 = IE5, NS6
    document.getElementById(id).style.display = 'block';
  }
  else {
    if (document.layers) { // Netscape 4
      document.id.display = 'block';
    }
    else { // IE 4
      document.all.id.style.display = 'block';
    }
  }
}




// COMPRUEBA LOS CAMPOS EN LOS FORMULARIOS
function comprobarSolicitudInformacion() {
  if (formSolicitudInformacion.nombre.value==""||formSolicitudInformacion.email.value=="") {
    alert("Debes rellenar todos los campos para enviar el mensaje");
    return false}
  if ((formSolicitudInformacion.email.value.indexOf ('@',0)==-1)||(formSolicitudInformacion.email.value.length<10)) {
      alert ("Por favor, revisa el email; la dirección introducida no es válida");
      return false}
  if (!formSolicitudInformacion.acepto.checked) {
     alert("Debes haber leído y aceptado la Política de Privacidad de la empresa para enviar este formulario.");
     return false}
  else {formSolicitudInformacion.submit()}
}

function comprobarRecomendarCurso() {
  if (formRecomendarCurso.nombre1.value==""||formRecomendarCurso.email1.value==""||formRecomendarCurso.nombre2.value==""||formRecomendarCurso.email2.value=="") {
    alert("Debes rellenar todos los campos para enviar el mensaje");
    return false}
  if ((formRecomendarCurso.email1.value.indexOf ('@',0)==-1)||(formRecomendarCurso.email1.value.length<10)||(formRecomendarCurso.email2.value.indexOf ('@',0)==-1)||(formRecomendarCurso.email2.value.length<10)) {
      alert ("Por favor, revisa el email; la dirección introducida no es válida");
      return false}
  else {formRecomendarCurso.submit()}
}

function comprobarContactar() {
  if (formContactar.nombre.value==""||formContactar.email.value==""||formContactar.mensaje.value=="") {
    alert("Debes rellenar todos los campos para enviar el mensaje.");
    return false}
  if ((formContactar.email.value.indexOf ('@',0)==-1)||(formContactar.email.value.length<10)) {
      alert ("Por favor, revisa el email; la dirección introducida no es válida");
      return false}
  if (!formContactar.acepto.checked) {alert("Debe aceptar las condiciones de envío del formulario.\nPuede leerlas en Política de privacidad");return false}
  else {formContactar.submit()}
}

function comprobarTestimonio() {
  if (formTestimonio.nombre.value==""||formTestimonio.email.value==""||formTestimonio.mensaje.value=="") {
    alert("Debes rellenar todos los campos para enviar el mensaje.");
    return false}
  if ((formTestimonio.email.value.indexOf ('@',0)==-1)||(formTestimonio.email.value.length<10)) {
      alert ("Por favor, revisa el email; la dirección introducida no es válida");
      return false}
  if (!formTestimonio.acepto.checked) {alert("Debe aceptar las condiciones de envío del formulario.\nPuede leerlas en Política de privacidad");return false}
  else {formTestimonio.submit()}
}

function comprobarPagoCurso() {
  if (formPagoCurso.nombre.value==""||formPagoCurso.apellidos.value==""||formPagoCurso.nif.value==""||formPagoCurso.email.value==""||formPagoCurso.telefono_fijo.value==""||formPagoCurso.telefono_movil.value==""||formPagoCurso.direccion.value==""||formPagoCurso.poblacion.value==""||formPagoCurso.provincia.value==""||formPagoCurso.codigo_postal.value==""||formPagoCurso.pais.value==""||formPagoCurso.estudios.value==""||formPagoCurso.nacimiento.value==""||formPagoCurso.sexo.value=="") {
    alert("Debes rellenar todos los campos para realizar el pago.");
    return false}
  if ((formPagoCurso.email.value.indexOf ('@',0)==-1)||(formPagoCurso.email.value.length<10)) {
      alert ("Por favor, revisa el email; la dirección introducida no es válida");
      return false}
  else {formPagoCurso.submit()}
}

function redondeo2decimales(numero)
{
	var original=parseFloat(numero);
	var result=Math.round(original*100)/100 ;
	return result;
}









// AÑADIR A FAVORITOS
var addBookmarkObj = {
  linkText:'Favoritos',
  addTextLink:function(parId){
    var a=addBookmarkObj.makeLink(parId);
    if(!a) return;
    a.appendChild(document.createTextNode(addBookmarkObj.linkText));
  },
  addImageLink:function(parId,imgPath){
    if(!imgPath || isEmpty(imgPath)) return;
    var a=addBookmarkObj.makeLink(parId);
    if(!a) return;
    var img = document.createElement('img');
    img.alt = addBookmarkObj.linkText;
    img.title = '';
    img.src = imgPath;
    a.appendChild(img);
  },
  makeLink:function(parId) {
    if(!document.getElementById || !document.createTextNode) return null;
    parId=((typeof(parId)=='string')&&!isEmpty(parId))
      ?parId:'addBookmarkContainer';
    var cont=document.getElementById(parId);
    if(!cont) return null;
    var a=document.createElement('a');
    a.href=location.href;
    if(window.opera) {
      a.rel='sidebar';
    } else {
      a.onclick=function() {
        addBookmarkObj.exec(this.href,this.title);
        return false;
      }
    }
    a.title='Formación Universitaria. Añade nuestro sitio a tus favoritos'; //document.title;
    return cont.appendChild(a);
  },
  exec:function(url, title) {
    var isKonq=(isLikelyKonqueror3 && isLikelyKonqueror3());
    var isMac=(navigator.userAgent.toLowerCase().indexOf('mac')!=-1);
    var buttonStr = isMac?'Command/Cmd':'CTRL';

    if(window.external && (!document.createTextNode ||
      (typeof(window.external.AddFavorite)=='unknown'))) {
        window.external.AddFavorite(url, title);
    } else if(isKonq) {
      alert('Debes presionar CTRL + B para añadir nuestro sitio a favoritos.');
    } else if(window.opera) {
      void(0);
    } else if(window.home) {
      alert('Debes presionar '+buttonStr+' + D para añadir nuestro sitio a tus favoritos.');
    } else if(!window.print || isMac) {
      alert('Debes presionar Command/Cmd + D para añadir nuestro sitio a tus favoritos.');    
    } else {
      alert('Para añadir este sitio a favoritos deberás hacerlo manualmente a través de tu navegador.');
    }
  }
}

function isEmpty(s){return ((s=='')||/^\s*$/.test(s));}

function isLikelyKonqueror3() {
  if(!document.getElementById) return false;
  if(document.defaultCharset || window.opera || !window.print) return false;
  if(window.home) return false;
  if(document.all) return true;
  var likely = 1;
  eval("try{var str=document.all[0].tagName;}catch(err){likely=0;}");
  return likely;
}

function dss_addEvent(el,etype,fn) {
  if(el.addEventListener && (!window.opera || opera.version) &&
  (etype!='load')) {
    el.addEventListener(etype,fn,false);
  } else if(el.attachEvent) {
    el.attachEvent('on'+etype,fn);
  } else {
    if(typeof(fn) != "function") return;
    if(typeof(window.earlyNS4)=='undefined') {
      window.earlyNS4=((navigator.appName.toLowerCase()=='netscape')&&
      (parseFloat(navigator.appVersion)<4.02)&&document.layers);
    }
    if((typeof(el['on'+etype])=="function")&&!window.earlyNS4) {
      var tempFunc = el['on'+etype];
      el['on'+etype]=function(e){
        var a=tempFunc(e),b=fn(e);
        a=(typeof(a)=='undefined')?true:a;
        b=(typeof(b)=='undefined')?true:b;
        return (a&&b);
      }
    } else {
      el['on'+etype]=fn;
    }
  }
}

dss_addEvent(window,'load',addBookmarkObj.addTextLink);






// ABRE ENLACES EXTERNOS EN OTRA VENTANA
this.blankwin = function()
{
     var hostname = window.location.hostname;
     hostname = hostname.replace("www.","").toLowerCase();
     var a = document.getElementsByTagName("a");	
     this.check = function(obj)
     {
          var href = obj.href.toLowerCase();
          return (href.indexOf("http://")!=-1 && href.indexOf(hostname)==-1) ? true : false;
     };
     this.set = function(obj)
     {
          obj.target = "_blank";
          obj.className = "external";
     };
     for (var i=0;i<a.length;i++)
     {
          if(check(a[i])) set(a[i]);
     };
};


this.addEvent = function(obj,type,fn)
{
     if(obj.attachEvent){
          obj['e'+type+fn] = fn;
          obj[type+fn] = function(){obj['e'+type+fn](window.event);}
          obj.attachEvent('on'+type, obj[type+fn]);
     }
     else
     {
          obj.addEventListener(type,fn,false);
     };
};

addEvent(window,"load",blankwin);