

function SKLJSdecidebtn(win,btnname,buttonset)
{
    if (0 <= buttonset.indexOf(btnname)) {
		  win.button(btnname).show();
    }else{
		  win.button(btnname).hide();
    }
}



// buttonset: list the buttons to show:
//    minmax1
//    help
//    park
//    close
// return value: an array of two elements:
//    [0] is either "CREATED" or "RAISED"
//    [1] is the window object itself
// The ID of the content DIV (direct child of the window) will be auto set to:
//    winID + "_CONTENTOF"
function SKLJScreateOrRaiseWindow(winID,parentID,Xleft,Ytop,width,height,buttonset)
{
    var win;

    dhxWins = new dhtmlXWindows();
    // dhxWins.vp.style.border = "#909090 0px solid";
    dhxWins.setImagePath("DHTMLX-2.5/dhtmlxWindows/codebase/imgs/");

    if (dhxWins.window(winID)) {
		  win = dhxWins.window(winID);
		  win.show();
		  win.bringToTop();
		  return new Array("RAISED",win);
    }else{
		  // CREATE A NEW WINDOW
		  dhxWins.setImagePath("DHTMLX/dhtmlxWindows/codebase/imgs/");
		  //dhxWins.setSkin("blue");
		  win = dhxWins.createWindow(winID, Xleft,Ytop, width, height);
		  SKLJSdecidebtn(win,"minmax1",buttonset);
		  SKLJSdecidebtn(win,"help",buttonset);
		  SKLJSdecidebtn(win,"close",buttonset);
		  SKLJSdecidebtn(win,"park",buttonset);

		  /*
		  // CREATE SOMETHING TO HOLD ITS CONTENT
		  newelem = document.createElement('DIV');
		  newelem.id = winID+"_CONTENTOF";
		  newelem.style.width = '100%';
		  newelem.style.height = '100%';
		  document.getElementById(parentID).appendChild(newelem);
		  win.attachObject(newelem.id);
		  EnsureDhtmlxWinResizing(win,"onResizeFinish");
		  EnsureDhtmlxWinResizing(win,"onMaximize");
		  EnsureDhtmlxWinResizing(win,"onMinimize");
		  */

		  return new Array("CREATED",win);
    }
}




function EnsureDhtmlxWinResizing(win,event)
{
    win.attachEvent(event, EVTH_ensureDhtmlxWinResizing);
}

function EVTH_ensureDhtmlxWinResizing(thewin)
{
    //FIREFOX:
    try {
		  var thegrid = thewin._content.firstChild.grid;
		  thegrid.setSizes();
		  return false;
    }
    catch(err){}
    return true;
}



function PUSH(params)
{
    MarkDirty();
    GLOBALbridge.send("PUSH.php",
							 params+"&invid="+GLOBALinvoiceid,
							 (params.length < 60) ? 'GET':'POST',
							 EVTH_finishedPush);
}


function EVTH_finishedPush(finishtype)
// finishtype:
//    200 = the response text should be useful
//    other positive number = HTTP error code from the server
//    -999 = client could not even conn to server at all
{
    // TOTAL SERVER-CONN FAILURE
    if (finishtype == -999) {
		  alert ("ERROR: your connection to the server has been disrupted.  Your most recent change may not have been sent successfully to the server.  You should cease working with this utility until your connectivity is restored.");
    }

    var result = this.request.responseText;
    if (result.indexOf("OK") >= 0) {
		  return;
    }
    else {
		  alert ("ERROR: the PortCompass server is experiencing problems.  Your most recent change may not have been sent successfully to the PortCompass staff.  Please try again later, or use email to info@portcompass.com to start your inquiry.");
    }
}
