function getElementPosition(elemId) {
    var elem = document.getElementById(elemId);
    var w = elem.offsetWidth;
    var h = elem.offsetHeight;
    var l = 0;
    var t = 0;
    while (elem)    {
        l += elem.offsetLeft;
        t += elem.offsetTop;
        elem = elem.offsetParent;
    }

    return {"left":l, "top":t, "width": w, "height":h};
}
function getObjectRef(name) {
  if(document.getElementById) return document.getElementById(name);
  else if(document.all) return document.all[name];
  else return null;
}
function openWin(name, width, height) {
  win = window.open(name,'','top=' + (screen.height/2 - height/2) + ',left=' +
             (screen.width/2 - width/2) + ',width='+width+',height='+height+
              'status=no,toolbar=no,menubar=no,scrollbars=no');
  return win;
}
function openScrlWin(name, width, height) {
  win = window.open(name,'','top=10,left=' +
             (screen.width/2 - width/2) + ',width='+width+',height='+height+
              'status=no,toolbar=no,menubar=no,scrollbars=yes');
  return win;
}
function dialog(mask) {
   var ret = "||";
   ret = window.showModalDialog("dialog/sd_dialog.php?filter=" + mask, "", "dialogWidth:310px; dialogHeight:530px; center:yes");
   var ret_mas = ret.split("|");
   return ret_mas;
}
function dialog2(mask,tree,cont,id) {
   var ret = "||";
   ret = window.showModalDialog("dialog/sqtree.php?filter="+mask+"&treetable="+tree+"&contenttable="+cont+"&cat_id="+id,
          "", "dialogWidth:310px; dialogHeight:530px; center:yes");
   var ret_mas = ret.split("|");
   return ret_mas;
}
function dialog3() {
   var ret = "|";
   ret = window.showModalDialog("dialog/brands.php", "", "dialogWidth:310px; dialogHeight:530px; center:yes");
   var ret_mas = ret.split("|");
   return ret_mas;
}
   function checkall(type)
   {
       var i = 0;
       var box_obj;
       var box_all = type?document.getElementById(type + "_all"):document.getElementById("boxall");

       while((box_obj = type?document.getElementById(type + "_box" + i++):document.getElementById("i_box" + i++)) != null)
           box_obj.checked = box_all.checked;
   }
   function select_group(type)
   {
    var ids = Array();
    var i = 0;
    var elem;
    while((elem = type?document.all[type + "_box" + i++]:document.all["i_box" + i++]) != null)
    {
      if(elem.checked)
        ids[ids.length] = elem._id;
    }
    return ids.length?ids.join(","):false;
   }

