// TITLE
var message="Master Centre d'Estudis - masterce.es                                             - Bienvenido/a a MASTER     "  //specifys the title
var message=message+"          " //gives a pause at the end,1 space=1 speed unit, here I used 10 spaces@150 each = 1.5seconds.
k="0"                            //declares the variable and sets it to start at 0
var temptitle=""                 //declares the variable and sets it to have no value yet.
var velocidad="90"              //the delay in milliseconds between letters

function titler() {
  if (!document.all&&!document.getElementById) return
  document.title=temptitle+message.charAt(k)  //sets the initial title
  temptitle=temptitle+message.charAt(k)       //increases the title by one letter
  k++                                         //increments the counter
  if (k==message.length)                      //determines the end of the message
  {
    k="0"                                     //resets the counter at the end of the message
    temptitle=""                              //resets the title to a blank value
  }
  setTimeout("titler()",velocidad)            //Restarts. Remove line for no-repeat.
}

titler();

// BARRA D'ESTAT
var text1=" *** Contacto: info@masterce.es - MASTER Centre d'Estudis -  www.masterce.es ***  "
comeback=0
cometo=0
function dis(){
window.status=text1.substring(0,cometo)
if(comeback==1){
cometo--;
if(cometo==0){comeback=0}
} else {cometo++;if(cometo==text1.length){comeback=1}}
window.status=text1.substring(0,cometo)+"|"
if(cometo==text1.length){window.setTimeout("dis()",500);} else
{window.setTimeout("dis()",50);}
}
dis()

// TOOLS
function DeleteWhiteSpace(s) {
  if (s==undefined) return;

  var i=0;
  var j=s.length;

  if (j!=0) {
     while (s.substr(i,1)==" ") i++;
     if (i<j)
         while (s.substr(j-1,1)==" ") j--;
  }
  return s.substr(i,j-i);
}

function isDigit(c) {
  return ((c >= "0") && (c <= "9"))
}

function isInteger(s) {
  var i;

  if (s.length==0) return false;

  for (i=0;i<s.length;i++) {
      if (!isDigit(s.charAt(i))) return false;
  }
  return true;
}

function isTelf(s) {
  var i=0;

  if (s.length!=9) return false;
  else {
    while ((i<9) && (isDigit(s.charAt(i)))) i++;
    return (i==9);
  }
}

function isMail(str) {
  // Are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported)
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function ischecked(obj) {
  var i=0;
  while ((i<obj.length) && (!obj[i].checked)) i++;
  return (i<obj.length);
}

// POPUP
function cnw(mypage,myname,w,h,scroll,resize,fullscreen) {
  LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
  TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
  settings='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable='+resize+',fullscreen='+fullscreen;
  window.open(mypage,myname,settings)
}

// IMATGES
function MM_swapImgRestore() {
  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_preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) {
  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 && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() {
  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];}
}

// FUNCION DE CAMBIO DE IDIOMA
function idioma(lang) {
  var i,nparam,url,ok;

  if (window.location.href.indexOf("?")==-1) {
     url=window.location.href+"?idioma="+lang;
  } else {
     urlquery=window.location.href.split("?");
     urlterms=urlquery[1].split("&");

     i=0; ok=0;
     nparam=urlterms.length;
     url=urlquery[0]+"?";
     for (i=0;i<nparam;i++) {
         if (i>0) url=url+"&";
         if (urlterms[i].indexOf("idioma")!=-1) {
            url=url+"idioma="+lang; ok=1;
         } else
            url=url+urlterms[i];
     }

     if (!ok) url=url+"&idioma="+lang;
  }

  window.location=url;
}
