
  // .: Version 1.2.3 :. //

  function jFrostTimer() {

    this.name='a timer';
    this.times=50;
    this.progression='linear';
    this.dt=10;
    this.shouldExit=false;

    this.start=function() {
      this.cycle();
    }

    this.cycle=function() {
      if (this.shouldExit) {
        this.onExit();
        return;
      }
      var dothistime=true;
      if (typeof this.remaining=='undefined') {
        this.remaining=this.times-1;
        dothistime=this.firstTime();
      }      
      if (--this.remaining > 0) {
        if (dothistime)
          this.eachTime();
        setTimeout( "jfrost.timerCycle('"+this.name+"')", this.dt );
        return;
      } else if (this.lastTime())
        this.eachTime();
    }

    this.firstTime=function() {
      return true;
    }
    this.eachTime=function() {

    }
    this.lastTime=function() {
      return true;
    }
    this.onExit=function() {

    }
  }

  function jFrost() {

    this.timers=new Array();

    this.get=function(name) {
      var o=null;
      eval('if (this.'+name+'!=undefined) o=this.'+name+';');

      return o;
    }

    this.new_=function(a,b) {
      eval('this.'+a+'='+b);
    }

    this.addEventsOnClass=function(a, tag, obj) {
      var w=document.getElementsByClassName(a);
      for(var i=0;i<w.length;i++) {
        var ei=w[i];
        if (tag=='any' || ei.tagName==tag)
          for(var key in obj)
            if (ei[key]==undefined)
              ei[key]=obj[key];
      }
    }

    this.addEventsById=function(id, obj) {
      var e=document.getElementById(id);
      if (e!=undefined)
        for(var key in obj)
          if (e[key]==undefined)
            e[key]=obj[key];
    }

    this.deleteConfirmation=function() {
      var w=document.getElementsByClassName('delete');
      for(var i=0;i<w.length;i++) {
        var ei=w[i];
        if (ei.tagName=='A')
          ei.onclick=function() {
            return confirm("Is it sure to delete this entry?");
          }
      }
    }

    this.showNHide=function(a, b) {
      var A=document.getElementById(a);
      var B=document.getElementById(b);
      A.onmouseover=function() {
        B.style.display='';
      }
      A.onmouseout=function() {
        B.style.display='none';
      }
    }

    this.addOnLoad=function(func) {
      var ool=window.onload;
      if (typeof window.onload != 'function')
        window.onload=func;
      else
        window.onload=function() {
          if (ool)
            ool();
          func();
        }
    }

		this.getNestedElements=function(e, type) {
			var v=new Array();
			var w=e.childNodes;
			for(var i=0;i<w.length;i++) {
				if (w[i].tagName==type)
					v.push(w[i]);
				v.concat( this.getNestedElements(w[i], type) );
			}

			return v;
		}

		this.getFirstNestedElement=function(e, type) {
			var w=this.getNestedElements(e, type);
			if (w.length == 0)
				return null;
			else
				return w[0];
		}

    this.getFirstElementByClassName=function(cname) {
      var w=document.getElementsByClassName(cname);
      if (w.length==0)
        return null;
      return w[0];
    }

    this.checkGetElementsByClassName=function() {
      if (document.getElementsByClassName != undefined)
        return;

      document.getElementsByClassName=function(className) {
        var hasClassName=new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
        var allElements=document.getElementsByTagName("*");
        var results=[];

        var element;
        for (var i=0;(element=allElements[i])!=null;i++) {
          var elementClass=element.className;
          if (elementClass &&
              elementClass.indexOf(className) != -1 &&
              hasClassName.test(elementClass))
            results.push(element);
        }

        return results;
      }
    }

    this.createHTTPRequest=function() {
      if (window.XMLHttpRequest)  // .: IE7+, Firefox, Chrome, Opera, Safari :. //
        return new XMLHttpRequest();
      else  // .: IE6, IE5 :. //
        return new ActiveXObject("Microsoft.XMLHTTP");
    }

    this.findFirstTagWithClass=function(e, tag, className) {
      var v=e.getElementsByTagName(tag);
      for(var i=0;i<v.length;i++)
        if (v[i].className==className)
         return v[i];

      return null;
    }

		this.isInternetExplorer=function() {
			return navigator.appName=='Microsoft Internet Explorer';
		}

    this.newTimer=function(name, v) {
      var theTimer=new jFrostTimer();
      theTimer.name=name;
      for(var key in v)
        theTimer[key]=v[key];

      this.timers[name]=theTimer;

      return theTimer;
    }

    this.newBeginnerTimer=function(name, v) {
      var theTimer=this.newTimer(name, v);
      theTimer.start();

      return theTimer;
    }

    this.timerCycle=function(name) {
      //if (typeof this.timers[name]=='undefined')
      //  console.log('No he encontrado '+name);
      this.timers[name].cycle();
    }

    this.getTimer=function(name) {
      return this.timers[name];
    }
    this.indexOfTimer=function(key) {
      var i=0;
      for(var keyi in this.timers)
        if (keyi==key)
          return i;
        else
          i++;

      return -1;
    }
    this.deleteTimer=function(name) {
      var theTimer=this.timers[name];
      delete this.timers[name];
      delete theTimer;
    }

    this.activeTimer=function(name) {
      var theTimer=this.getTimer(name);
      if (typeof theTimer!='undefined' &&
          typeof theTimer.remaining!='undefined' &&
          theTimer.remaining > 0)
        return true;
      else
        return false;
    }

    this.debugTimers=function() {
      var str='[timers]';
      for(var key in this.timers)
        str+=':'+key;
    }

    this.hack=function() {
      alert(';)');
    }

    this.checkGetElementsByClassName();
  }

  function jf(a) {
    return jfrost.get(a);
  }
    jf.new_=function(a, b) {
      jfrost.new_(a, b);
    }
    jf.trim=function(str, chars) {
      return jf.ltrim(jf.rtrim(str, chars), chars);
    }
    jf.ltrim=function(str, chars) {
      chars = chars || "\\s";
      return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
    }
    jf.rtrim=function(str, chars) {
      chars = chars || "\\s";
      return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
    }
    jf.in_array=function(needle, haystack) {
      var length=haystack.length;
      for(var i=0;i<length;i++)
        if (haystack[i]==needle)
          return true;
      return false;
    }
    jf.classXPath=function(o, path) {
      if (typeof path=='string')
        path=path.split('/');
      var w;

      var theTag='*';
      var theClass='*';
      var index=path[0].indexOf('.');
      var _length_=path[0].length;
      if (index==-1)
        theClass=path[0];
      else if (index==0) {
        if (path[0].length>1)
          theClass=path[0].substring(1);
      } else if (_length_==index+1)
        theClass=path[0].substring(0, index);
      else {
        var aux=path[0].split('.');
        theTag=aux[0];
        theClass=aux[1];
      }

      if (o==null) {
        if (theClass=='*')
          w=document.childNodes;
        else
          w=document.getElementsByClassName(theClass);
      } else
        w=o.childNodes;

      for(var i=0;i<w.length;i++)
        if ( typeof w[i].className=='string' &&
              ( theClass=='*'
                  ||
                jf.in_array( theClass, w[i].className.split(' ') )
                  ||
                path[0]==w[i].className ) &&
             ( theTag=='*' || w[i].tagName==theTag )
           ) {
          if (path.length>1) {
            path.shift();
            return jf.classXPath(w[i], path);
          } else
            return w[i];
        }

      return null;
    }

  jfrost=new jFrost();



