function screenSize() {
var h;
h = (window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.offsetHeight));
return {h:h};
}

function MsgCharCount(a) {
maxlen = 255;
 if (a.value.length <= maxlen){
 document.getElementById("txtMsgCount").value=a.value.length;
 } else {
   a.value = a.value.substr(0,maxlen);
   }
return true;
}

var tooltip = function(){
    var id = 'tt';
    var maxw = '130';
    var tt,h;
    var ie = document.all ? true : false;
    return{
     init:function(){
     var a = document.all && !window.opera ? document.all : document.getElementsByTagName("*");
      for (var i = 0; i < a.length; i++) {
      var tooltip_title = a[i].getAttribute("title");
       if (tooltip_title && typeof tooltip_title == "string" ) {
       a[i].setAttribute("tt",tooltip_title);
       a[i].removeAttribute("title");
       a[i].onmouseover = function() { tooltip.show( this ) };
       a[i].onmouseout  = function() { tooltip.show( this ,true ) };
       }
      }
     },
     show:function(v,w){
      if(tt == null){
      tt = document.createElement('div');
      tt.setAttribute('id',id);
      document.body.appendChild(tt);
      document.onmousemove = this.pos;
      }
    tt.innerHTML = v.getAttribute("tt");
     tt.style.display = (w!=null) ? 'none' : 'block';
     tt.style.width = (tt.offsetWidth >= maxw) ? maxw + 'px' : 'auto';
     h = parseInt(tt.offsetHeight) + 3;
     },
     pos:function(e){
     var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
     var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
     tt.style.top = (u - h) + 'px';
     tt.style.left = (l + 3) + 'px';
     }
    };
}();

// ala Simon Willison http://simon.incutio.com/archive/2004/05/26/addLoadEvent
// ==============================================================

function addLoadEvent(func) {
var oldonload = window.onload;
  if (typeof window.onload != 'function') {
  window.onload = func;
  } else {
    window.onload = function() {
                    if (oldonload) oldonload();
                    func();
                    }
    }
}


var defarr = [];
function OrderTable() {
var table = document.getElementById('orderlist');
var handle = 0;
 if (! table) return;
 else {
 var tinputs = table.getElementsByTagName('input');
 var newarr = [];
  for (var i = 0; i < tinputs.length; i++) {
  newarr[i] = parseInt(tinputs[i].value);
  tinputs[i].onkeyup = OrderTable;
   if (defarr[i] != newarr[i] && defarr.length > 0) {
   handle = 1; break;
   }
  }
 if (defarr.length == 0) defarr = newarr;
 document.getElementById('refresh').style.visibility = (handle == true) ? 'visible' : 'hidden';
 }
}

addLoadEvent(OrderTable);
addLoadEvent(tooltip.init);
