User:Topaz/util.js

From Wikipedia, the free encyclopedia

Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.

topaz.util = {
getobj:function(id) {
  return document.getElementById ?
             document.getElementById(id) :
             document.all[id];
},
time:function() {
  return((new Date()).getTime()/1000);
},
add:function(parent, tag, attr) {
  var el = document.createElement(tag);
  if (attr) {
    for (key in attr) {
      el[key] = attr[key];
    }
  }
  return parent.appendChild(el);
},
fullescape:function(text) {
  return escape(text).replace(/\+/g,"%2B");
},
mousebtnmap:{
  ns:[null,1,3,2],
  ie:[null,1,2,null,3]
},
xmlhttpreq:function() {
  if (window.XMLHttpRequest) {
    xmlhttpobj = new XMLHttpRequest()
  } else {
    try {
      xmlhttpobj = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttpobj = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        xmlhttpobj = null;
      }
    }
  }
  return xmlhttpobj;
},
 
cookie:{
  noexpire:(function(){
    var d = new Date();
    d.setTime(d.getTime()+(365*24*60*60*1000));
    return d.toGMTString();
  })(),
 
  expire:(function(){
    var d = new Date();
    d.setTime(d.getTime()-1);
    return d.toGMTString();
  })(),
 
  get:function(name) {
    var cl = document.cookie.split(/;\s*/);
    for (var i=0; i<cl.length; i++) {
      var curc = cl[i].split(/\=/);
      if (curc[0] == name) {
        return(curc[1]);
      }
    }
    return null;
  },
 
  set:function(name, value) {
    document.cookie = name + "=" + escape(value) +
        "; expires=" + topaz.util.cookie.noexpire +
        "; path=/";
  },
 
  del:function(name) {
    document.cookie = name+"=; expires="+topaz.util.coookie.expire+"; path=/";
  }
}
};