
function decimalPlaces(num, places) {

   num = Math.round((parseFloat(num)) * 100 ) / 100;
   return num;
}


function getAjaxRequest() {
   var ajaxRequest;

   try { ajaxRequest = new XMLHttpRequest(); } catch (e) {
      try { ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
         try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){
            alert("Your browser doesn't support AJAX");
            return false;
         }
      }
   }
   return ajaxRequest;
}
/*
function appendChildren(element, children) {
	for (var i in children) element.appendChild(children[i]);
}

function getChildById(parent, id) {
   o = parent.firstChild;
   if (!o) return null;
   do {
      if (o.id == id) return o;
   } while(o = o.nextSibling);
   return null;
}

function createSafeElement(title, attributes) {

   if (attributes == '' || attributes == null) return document.createElement(title);
   var n = null;
   try {
      n = document.createElement('<'+title+' '+attributes+'>');
   } catch (e) {
      n = document.createElement(title);
      var att = attributes.split(' ');
      for (var i = 0; i < att.length; i++) {
         var a = att[i].split('=');
         n.setAttribute(a[0], a[1]);
      }
   }
   return n;
}

function changeOpacity(o, opacity) {
   if (navigator.appName.indexOf("Netscape")!=-1 && parseInt(navigator.appVersion)>=5)
      o.style.MozOpacity=opacity/100;
   else if (navigator.appName.indexOf("Microsoft")!= -1 && parseInt(navigator.appVersion)>=4)
      o.style.filter = "alpha(opacity='" + opacity + "')";
}

function createDiv(attributes, content) {
   var n = createSafeElement('div', attributes);
   if (typeof(content) == 'string') n.innerHTML = content;
   else if (typeof(content) != 'undefined') n.appendChild(content);
   return n;
}

function createRow () {
   var tr = document.createElement('tr');
   for (var i = 0; i < arguments.length; i++)
      tr.appendChild(arguments[i]);
   return tr;
}

function createCell(attributes) {
   var td = createSafeElement('td', attributes);
   for (var i = 1; i < arguments.length; i++) {
      if (typeof(arguments[i]) == 'string') td.innerHTML += arguments[i];
      else td.appendChild(arguments[i]);
   }
   return td;
}

function createTable(attributes) {
   var t = createSafeElement('table', attributes);
   t.appendChild(document.createElement('tBody'));
   t.tB = t.tBodies[0];
   return t;
}
*/


function setCookie(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+";";
}

function getCookie(name) {
   var nameEQ = name + "=";
   var ca = document.cookie.split(';');
   for(var i=0; i < ca.length; i++) {
      var c = ca[i];
      while (c.charAt(0)==' ') c = c.substring(1,c.length);
         if (c.indexOf(nameEQ) == 0) 
            return c.substring(nameEQ.length,c.length);
   }
   return null;
}

function deleteCookie(name) {
   setCookie(name,"",-1);
}

/*
function sendInvite(email, dir) {
   var ajaxRequest = getAjaxRequest();

   ajaxRequest.onreadystatechange = function() {
      if(ajaxRequest.readyState == 4){
         //loading.hide();
         alert(ajaxRequest.responseText)
         //document.emailForm.reset()
      }
      //else loading.show()
   }
   var queryString="?e="+email+"&z="+(new Date().getTime());
   ajaxRequest.open("GET", dir+"make_invite.php"+queryString,true);
   ajaxRequest.send(null);
}

function inviteFocus(o) {
   o.style.fontStyle = 'normal';
   o.style.color = '#000000';
   o.value = '';
}

function isArray(object) {
   return object && object.constructor === Array;
}

function isString(obj) {

//    return typeof obj == "string";
   if (typeof obj == 'string') return true;

   if (typeof obj == 'object') {
      return (obj.constructor == String);
//       return (criterion != null);
//      var criterion = obj.constructor.toString().match(/string/i);
//      return (criterion != null);
   }
   return false;
   
}


/* Build Your Empire JS framework.
 *
 * Borrows concepts from the prototype framework.
 *
 * (c) Build Your Empire . net
 */
  /*
var Framework = {
  Version: '0',

  Browser: {
    IE:     !!(window.attachEvent && !window.opera),
    Opera:  !!window.opera,
    WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
    Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1,
    MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)
  },

  BrowserFeatures: {
    XPath: !!document.evaluate,
    ElementExtensions: !!window.HTMLElement,
    SpecificElementExtensions:
      document.createElement('div').__proto__ &&
      document.createElement('div').__proto__ !==
        document.createElement('form').__proto__
  }
};       */

Element.addMethods({

   popup: function(element) {
      alert("asdf");
   },

   addChildren: function(element) {

      var parent = null;

      if (element.tagName == 'TABLE') {
         if (element.firstChild && element.firstChild.tagName == 'TBODY')
            parent = element.firstChild
         else parent = element.appendChild(E('tbody', {}));
      }
      else parent = element;

      for (var i = 1; i < arguments.length; i++) {

         if (Object.isArray(arguments[i]))
            for (var j = 0; j < arguments[i].length; j++)
               parent.addChild(arguments[i][j]);
         else parent.addChild(arguments[i]);
      }

      return element;
   },

   addChild: function(element, child) {
      if (typeof child == "string") element.innerHTML += child;
      else element.appendChild(child);

      return element;
   },

   removeChildren: function(element) {

      d = element.firstChild;

      while(c = d) {
         //var args = $A(arguments);
         d = c.nextSibling;
         //if (!args.find(c.id))
         element.removeChild(c);
      }
      return element;
   },

   removeChildById: function(element, childId) {

      for (c = element.firstChild; c; c = c.nextSibling)
         if (c.id == childId) element.removeChild(c);
      return element;
   },

   addEvent: function(element, event, listener) {

      element[event] = listener;
      return element;
   },

   getChildById: function(element, childId) {

      for (c = element.firstChild; c; c = c.nextSibling)
         if (c.id == childId) 
            return $(c);

      return null;
   }

   /*,

   extend: function(element, methods) {

      Object.extend(element, methods);
   }*/

});

function E(tag, attr) {

   var element = new Element(tag, attr);

/*
   var element = null;

   if (Framework.Browser.IE) {
      var attrStr = '';
      for (attrName in attr) attrStr += " "+attrName+"='"+attr[attrName]+"'";
      element = document.createElement('<'+tag+attrStr+'>');
   }

   else {
      element = document.createElement(tag);
      for (attrName in attr) element.setAttribute(attrName, attr[attrName]);
   }

   //Object.extend(element, elementMethods);
   // element['aC'] = element.addChildren;

*/
   if (typeof arguments[2] != "undefined") {

      if (Object.isArray(arguments[2])) var children = arguments[2];
      else var children = [].splice.call(arguments, 2, arguments.length-2);

      if (tag == 'table') element.appendChild(E('tBody', {}, children));
      else element.addChildren(children);
   }

   return element;

}


/*
function $(elementId) {
   var element = (typeof elementId == "string") ? document.getElementById(elementId) : elementId;
   if (typeof element == "undefined" || !element) return;
   extendObject(element, elementMethods);
   element['aC'] = element.addChildren;
   return element;
}

function extendObject(object, functions) {
  for (var property in functions)
     object[property] = functions[property];
}

var xCount = 0;

extendObject(Array.prototype, {

   contains: function(needle) {

      for (i = 0; i < this.length; i++)
         if (this[i] == needle) return true;
      return false;
   },

   dump: function() {

      var str = "Array: \n"
      for (i = 0; i < this.length; i++) 
         str += i+": "+this[i]+"\n";
      return str;
   }
});

function toArray(iterable) {

  if (!iterable) return [];
  var length = iterable.length || 0, results = new Array(length);
  while (length--) results[length] = iterable[length];
  return results;
}


var elementMethods = {

   extend: function(functions) {
      extendObject(this, functions);
      return this;
   },

   addAttributes: function(attr) {
      for(attrName in attr)
         this.setAttribute(attrName, attr[attrName]);
      return this;
   },
   
   setStyle: function(styles) {
      for(styleName in styles)
         this.style[styleName] = styles[styleName];
      return this;
   },

   getStyle: function(styleName) {
      return this.style[styleName];
   },
      
   addChildren: function() {

      var parent = null;

      if (this.tagName == 'TABLE') {
         if (this.firstChild && this.firstChild.tagName == 'TBODY')
            parent = this.firstChild
         else parent = this.appendChild(E('tbody', {}));
      }
      else parent = this;

      for (var i = 0; i < arguments.length; i++) 
         if (isArray(arguments[i])) 
            for (var j = 0; j < arguments[i].length; j++)
               parent.addChild(arguments[i][j]);
         else parent.addChild(arguments[i]);
         
      return this;
   },

   addChild: function(child) {
      if (typeof child == "string") this.innerHTML += child;
      else this.appendChild(child);

   },

   removeChildren: function() {

      d = this.firstChild;

      while(c = d) {
         var args = toArray(arguments);
         d = c.nextSibling;
         if (!args.contains(c.id))
            this.removeChild(c);
      }
      return this;
   },

   getChildById: function(childId) {

      for (c = this.firstChild; c; c = c.nextSibling)
         if (c.id == childId)
            return $(c);

      return null;
   },
   
   removeChildById: function(childId) {
      
      for (c = this.firstChild; c; c = c.nextSibling) 
         if (c.id == childId) this.removeChild(c);
      return this;
   },

   addEvent: function(event, listener) {

      this[event] = listener;
      return this;
   },

   hasClass: function(className) {
      var classArr = this.className.split(" ");
      for (var i = 0; i < classArr.length; i++)
        if (classArr[i] == className)
           return true;

      return false;
   },

   addClass: function(className) {

      if (!this.hasClass(className))
         this.className += (this.className ? ' ' : '') + className;

      return this;
   },

   removeClass: function(className) {

      var classArr = this.className.split(" ");

      for (var i = 0; i < classArr.length; i++)
         if (classArr[i] == className)
            classArr.splice(i, 1);

      this.className = classArr.join(" ");
      return this;
   },

   fade: function(to) {

      var opacity = (to > 100) ? 100 : ((to < 1) ? 0 : to);
      if (Framework.Browser.IE) this.style.filter = "alpha(opacity='" + opacity + "')";
      else if (Framework.Browser.Gecko) this.style.MozOpacity = (opacity/100);
      return this;
   },

   show: function() {

      this.style.display = "";
      return this;
   },

   hide: function() {

      this.style.display = "none";
      return this;
   },

   update: function(text, override) {
      if (typeof override == "undefined") override = true;

      if (override) this.innerHTML = text;
      else this.innerHTML += text;
      return this;
   },
   
   getDimensions: function() {
      
      var display = this.getStyle('display');
      if (display != 'none' && display != null) // Safari bug
         return {width: this.offsetWidth, height: this.offsetHeight};
      
      // All *Width and *Height properties give 0 on elements with display none,
      // so enable the element temporarily
      var origVisibility = this.getStyle('visibility');
      var origPosition = this.getStyle('position');
      var origDisplay = this.getStyle('display');
      this.setStyle({
         visibility: 'hidden',
         position: 'absolute',
         display: 'block'
      });
      var origWidth = this.clientWidth;
      var origHeight = this.clientHeight;
      this.setStyle({
         display: 'origDisplay',
         position: 'origPosition',
         visibility: 'origVisibility'
      });
      return {width: origWidth, height: origHeight};
   }
};


var blankSpace = '&nbsp;&nbsp;&nbsp;';
*/