/* Version: 3i
*/
    var WinHeight = screen.height-80;
    var contentwinfeat = 'toolbar=0,scrollbars=1,status=1,resizable=1,menubar=0,location=0,' +
                        'top=28,left=20,width=850,height=' + (WinHeight - 40);
    var listmenu = new Array();

    function CM_openBrWindow(theURL,winName,features) {
     window.open(theURL,winName,features);
    }
    
    function CM_highlight(obj, color) {
      $(obj).attr('style', 'background-color:'+color);
    }
    
    function CM_lmin(obj, idx) {
      listmenu[idx] = 1;
      $(obj).attr('style', 'background-color:#BBB');
    }
    
    function CM_lmout(obj, idx, menuid) {
      $(obj).attr('style', 'background-color:#EEE');
      CM_closelm(idx, menuid);
      //setTimeout("CM_closelm("+idx+", '"+menuid+"')", 500);
    }
    
    function CM_closelm(idx, menuid) {
      listmenu[idx] = 0;
      setTimeout("if (listmenu["+idx+"] == 0) $('#"+menuid+"').hide('slow');", 500);
    }
    
    function CM_lmclick(cmd, listID, contentID, siteID) {
      $("#CMListMenu_"+listID).hide("slow");
      callCommand(cmd, contentID, listID, siteID);
    }
    
    function callCommand(cmd, contentID, listID, siteID) {
      //alert("cmd= " + cmd + ", contentID= " + contentID + ", listID= " + listID + ", siteID= " + siteID);
      //alert(document.all.imgAddCmd.parentElement.id);
      //alert(document.getElementById("imgAddCmd").parentNode.id);
      
      if (cmd == "DeleteListItem") {
        r=confirm("Do you really want to permanently delete this item?");
        if (r!=true){
          return false;
        }
      }
      
      nocache = Math.random(); //stupid IE cashing issue
      $.get('/CM/CMCommands.php',
            { cmd: cmd, contentID: contentID, listID: listID, siteID: siteID, nocache: nocache }, 
            function(data){
                if (cmd=="DeleteListItem") {
                    //document.location.reload();
                    
                    /* This code works as well: removing elements without refreshing
                    document.getElementById(id).style.display = 'none';
                    document.getElementById(id + "1").style.display = 'none';
                    document.getElementById(id + "2").style.display = 'none';
                    document.getElementById(id + "3").style.display = 'none';
                    document.getElementById(id + "4").style.display = 'none';
                    document.getElementById(id + "Edit").style.display = 'none';
                    document.getElementById(id + "Menu").style.display = 'none';
                    moveCMAreas();
                    */
                }
                //alert("cmd= " + cmd + ", contentID= " + contentID + ", listID= " + listID + ", siteid= " + siteID + ", data: " + data);
                if (cmd=="AddListItem") {
                    //document.location.reload();
                    //alert("ADD - " + data);
                }
                if (cmd=="GetContent") {
                    return (data);
                }
                document.location.reload();
            },
            'text');
   }