// called on page load
function init() {
  fixmacie('cf', 'li');
  fixmacie('last-iteration', 'dl');
}

re1=/^ */
re2=/ *$/
String.prototype.ltrim = function () { return this.replace(re1,""); } 
String.prototype.rtrim = function () { return this.replace(re2,""); } 
String.prototype.trim  = function () { return this.ltrim().rtrim(); } 


// http://www.positioniseverything.net/easyclearing.html
function fixmacie(classname, tagname) {
  clearstyle = 'clear:both; height:0; overflow:hidden;';

  /* Check if the browser is IE5 Mac */
  if( navigator.appVersion.indexOf('Mac')!=-1 && document.all) {
    /* Pass the class name on the container to fixmacie 
       (must be the FIRST classname if multiple classnames 
       are used on the li!) */    

    var tags = document.getElementsByTagName(tagname);
    for(var d = 0; d < tags.length; d++) {
      if(tags[d].className.indexOf(classname) == 0) {
        tags[d].innerHTML += '<div style="'+clearstyle+'"> </div>'; 
        /* The above html tags get added to the end of 
     the cleared container if the browser is IE/mac. */  
      } 
    }
  }
}


function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function arrayTrim(a){
  var tmp=new Array();
  for(j=0;j<a.length;j++)
    if(a[j]!='')
      tmp[tmp.length]=a[j];
  a.length=tmp.length;
  for(j=0;j<tmp.length;j++)
    a[j]=tmp[j];
  return a;
}

function str_replace(search, replace, subject) {
  retval = '';
  for (var i=0; i < subject.length; i++) {
    retval+= (subject.charAt(i) == search) ? replace : subject.charAt(i);
  }
  return retval;
}

// http://www.informit.com/isapi/product_id~%7BE40D98B6-703F-4ED9-9B6C-9DD2E731FAD5%7D/element_id~%7B26FC4DC0-4520-47D2-B188-EFF1FF8F2E10%7D/st~%7BB09E5FA9-ACC5-4D80-B7A6-5DA9841F043F%7D/content/articlex.asp
// emulate array.push-method for IE prior to 5.5
function Array_push() {
  var A_p = 0
  for (A_p = 0; A_p < arguments.length; A_p++) {
    this[this.length] = arguments[A_p]
  }
  return this.length
}

if (typeof Array.prototype.push == "undefined") {
  Array.prototype.push = Array_push
}

function min(val1, val2) {
  if (val1 <= val2) {
    return val1;
  }
  return val2;
}

function max(val1, val2) {
  if (val1 >= val2) {
    return val1;
  }
  return val2;
}

function getRef(layer) {
  var ref;
  if (_isN6())
    ref = eval(document.getElementById(layer));
  if (_isMSIE5())
    ref = eval("document.all."+layer);
  return ref;
}

function getQueryVariable(variable, query) {
  if (!query) {
    var query = window.location.search.substring(1);
  }
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  // variable not found in query string
  return false;
}

function openWindow(url, width, height, resizable, scrollbars, targetName) {
  wleft = (screen.width - width) / 2;
  wtop  = (screen.height - height) / 2;
  
  targetName = targetName ? targetName : 'new';
  resizable = resizable ? resizable : 'no';
  scrollbars = scrollbars ? scrollbars : 'no';
  
  window.open(url, targetName, 'toolbar=no,location=no,directories=no,scrollbars='+scrollbars+',status=no,menubar=no,resizable='+resizable+',width='+width+',height='+height+',left='+wleft+',top='+wtop);
}

function openUrl(url, targetName) {
  window.open(url, targetName);
}

function isInt(str) {
  var i = parseInt(str);

  if (isNaN (i))
    return false;

  i = i.toString();
  if (i != str)
    return false;

  return true;
}