
Array.prototype.inArray = function (value) {
  var i;
  for (i=0; i < this.length; i++) {
    if (this[i] === value) {
      return true;
    }
  }
  return false;
};

String.prototype.isEmpty = function () {
  var tmp = this.replace(/^\s+/g, '').replace(/\s+$/g, '');
  if (tmp.length==0) return true;
  return false;
};

String.prototype.trim = function () {
  return this.replace(/^\s+/g, '').replace(/\s+$/g, '');
};


function getId(id)
{
  if (document.getElementById(id)) return (document.getElementById(id));
  else alert("ID <"+id+"> not found");
}

function openPopup(s) 
{
    window.open(s,"_blank",'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=600,height=480,hotkeys=no');
}

function openPopupBis(s,w,h) 
{
    window.open(s,"_blank",'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width='+w+',height='+h+',hotkeys=no');
}


function showHide(idto,idfrom)
{
  if (getId(idfrom).tagName=='IMG' && (getId(idfrom).src.indexOf('-on.')>-1 || getId(idfrom).src.indexOf('-off.')>-1)) {
    if (getId(idfrom).src.indexOf('-on')>-1) tmp = getId(idfrom).src.replace(/-on/g,'-off');
    else tmp = getId(idfrom).src.replace(/-off/g,'-on');
    getId(idfrom).src = tmp;
  }
  if (getId(idto).style.display=='none') getId(idto).style.display='block';
  else getId(idto).style.display='none';
}

function trim (s) {
  return s.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function kwoPopup(code,width,height) {
  if(!width) width = 300;
  if(!height) height = 460;
  window.open('/service.php?p_m=popup&code='+code,'_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width='+width+',height='+height+',hotkeys=no');
}

function start(flag){
  var fList = window.listStart;
  if(fList){
    for(i=0; i<fList.length; i++){
      func = fList[i];
      if(typeof(func) == 'function'){
        func();
      } else {
        eval(func);
      }
    }
  }
}

function addToStart(func){
  if(!window.listStart) window.listStart = new Array();
  window.listStart.push(func);
}

function end(flag){
  var fList = window.listEnd;
  if(fList){
    for(i=0; i<fList.length; i++){
      func = fList[i];
      if(typeof(func) == 'function'){
        func();
      } else {
        eval(func);
      }
    }
  }
}

function addToEnd(func){
  if(!window.listEnd) window.listEnd = new Array();
  window.listEnd.push(func);
}
