var CommandQueue = new Array();
var QueueCount=0;
var x_win=null;

function requestdata(server_command, id, target_id, type_id, param, filter)
{
    var OutArr = new Array();
    OutArr['cmd']= server_command;
    OutArr['tree_req_id']= id;
    OutArr['tree_req_target_id']= target_id;
    OutArr['table']= dbTable;
    OutArr['datatypes']= dbDatatypes;
    OutArr['tree_req_type_id'] = type_id;
    if(param!=null) OutArr['param'] = param;
    if(filter!=null) OutArr['filter'] = filter;
    //OutArr['command'] = command;
    CommandQueue.push(OutArr);
}

function ProcessCommandQueue()
{

    if(CommandQueue.length!=0)
    {
        var LeftPanel = document.getElementById('xmlTree');
        LeftPanel.style.cursor = "wait";
        document.body.style.cursor = "wait";
        document.getElementById(statusall_id).style.display='none';
        JsHttpRequest.query(
                            url,
                            CommandQueue[CommandQueue.length-1],
                            function(result, errors) 
                            {
                                if (result.ok)
                                {
                                    ResponseProcess(result);
                                    document.body.style.cursor = "default";
                                    document.getElementById(statusall_id).style.display='inline'; 
                                }
                                else 
                                {
                                    window.status = "ОШИБКА!";
                                }
                            }
                            ,  true  );        
    }
}

function CloseBar() 
{
    document.body.style.cursor = "default";
    LeftPanel.style.cursor = "default";
}

function ShowGallery(imgArr)
{
   if(x_win!=null)
   {
       x_win.close();
       x_win=null;
   }
    var server=imgArr[0]['src'];
    var prop="width="+(imgArr[0]['width']+40)+",height="+(imgArr[0]['height']+100)+",top=0,left=0, scrollbars=yes,toolbar=no,menubar=no,location=no,status=no,resizable=no";
    x_win = open(server, "x_win",prop );  
    x_win.focus();
/*
    var head = x_win.document.createElement("head");
    script=x_win.document.createElement('script');
    script.id='formPrinter';
    script.type='text/javascript';
    script.src="/js/lib/request.js";
    head.appendChild(script);
    x_win.document.appendChild(head);
*/
//   var temp='<script type="text/javascript">function ChangeImage(image, width, height){document.getElementById("img_main").src=image;window.resizeTo(width+80,height+160);}</script><table><tr><td><img id="img_main" name="img_main" src="'+imgArr[0]["src"]+'"></td></tr><tr><td><table bordercolor="white" border="1" cellpadding="2" cellspacing="6"><tr>';

    x_win.document.open();
  
  // генерировать новый документ 
    x_win.document.write("<html><head><title>СКАДО Галерея");
    x_win.document.write("</title></head><body>");
    var temp="<table><tr><td><img id='img_main' name='img_main' src="+imgArr[0]['src']+"></td></tr><tr><td><table bordercolor='white' border='1' cellpadding='2' cellspacing='6'><tr>";
   
   for(var i=0; i<imgArr.length; i++)
   {
       temp=temp+'<td style="cursor:pointer" bordercolor="black" bgcolor="#64809b" align="center" onclick=changeimage("'+imgArr[i]["src"]+'",'+imgArr[i]["width"]+','+imgArr[i]["height"]+')><font color="white" size="2">'+(i+1)+'</font></td>';
   }
   temp=temp+"</tr></table>";
   temp=temp+"</td></tr></table>";
   temp=temp+'<script type="text/javascript">function changeimage(image, width, height){document.getElementById("img_main").src=image;window.resizeTo(width+80,height+160);}</script>';

   x_win.document.write(temp);
   x_win.document.write("</body></html>");

  // закрыть документ - (но не окно!)
    x_win.document.close();  

}

function ChangeImage(image, width, height)
{
    document.getElementById("img_main").src=image;
    window.resizeTo(width+80,height+160);
}