


// misc macros

function min (a,b) {return (a<b)?a:b}
function max (a,b) {return (a<b)?b:a}
function abs (a) {return (a>0)?a:-a}
function mod (a,b) {return a-Math.floor(a/b)*b}



// misc layout

function switchOpacity (id,val)
{
   if (BrowserDetect.browser == "Firefox") document.getElementById(id).style.opacity=val/100;
   else if (BrowserDetect.browser == "Explorer") document.getElementById(id).filters.alpha.opacity = val;
}



// cookies

var Cookies = {

   init: function () {
      var allCookies = document.cookie.split('; ');
      for (var i=0;i<allCookies.length;i++) {
         var cookiePair = allCookies[i].split('=');
         this[cookiePair[0]] = cookiePair[1];
      }
   },

   create: function (name,value,days) {
      if (days) {
         var date = new Date();
	 date.setTime(date.getTime()+(days*24*60*60*1000));
	 var expires = "; expires="+date.toGMTString();
      }
      else var expires = "";
      document.cookie = name+"="+value+expires+"; path=/";
      this[name] = value;
   },

   erase: function (name) {
      this.create(name,'',-1);
      this[name] = undefined;
   }

}


Cookies.init();

function popup (url, width, height, options) {
  var top  = (screen.height-height) / 2;
  var left = (screen.width-width) / 2;
  window.open(url,"","top="+top+",left="+left+",width="+width+",height="+height+","+options);
}

function getInnerDimX () {
   if (self.innerHeight) return self.innerWidth;
   if (document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientWidth;
   if (document.body) return document.body.clientWidth;
}

function getInnerDimY () {
   if (self.innerHeight) return self.innerHeight;
   if (document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight;
   if (document.body) return document.body.clientHeight;
}



// ajax

var xmlhttp;

function load(id,url)
{
   xmlhttp=null;
   if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }                         // code for IE7, Firefox, Opera, etc.
   else if (window.ActiveXObject) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }   // code for IE6, IE5
   if (xmlhttp!=null)
   {
      xmlhttp.onreadystatechange = function ()
      {
         if (xmlhttp.readyState==4)
	 //if (xmlhttp.status==200)
	 document.getElementById("text").innerHTML=xmlhttp.responseText;
      }
      xmlhttp.open("GET",url,true);
      xmlhttp.setRequestHeader("Content-Type","text/xml; charset:ISO-8859-1"); 
      xmlhttp.setRequestHeader("Accept-Charset", "ISO-8859-1");
      xmlhttp.send(null);
   }
   else { alert("Your browser does not support XMLHTTP."); }
}

