var wintype = null;
var callbackFun = null;
var data = null;

function OpenDir(id)
{
    var dirAtrr = Io.openDir('Select');
    if(dirAtrr == null)
    return;
    document.getElementById(id).value = dirAtrr.path;
    if(dirAtrr){
        if( id == 'temp_dir')
        {
            if(setTemp)setTemp(dirAtrr.path);
        }
        else if (id == 'dest_dir')
        {
           if(setDest)setDest(dirAtrr.path);
        }
    }    
}

function windowInit(arguments)
{
   document.title = arguments[0];
   wintype = arguments[1];
   data = arguments[2];
   callbackFun =  arguments[3];
   if(data['h'])$e("wnd_design").setAttribute("height",data['h']);
   if(data['w'])$e("wnd_design").setAttribute("width",data['w']);
   switch(wintype)
   {
    case 0:
        {
           var node = HtmHelper.make("hbox", {"flex":"1"});
           var val = data['destdir'];
           if(!val)val="";
           node.appendChild(HtmHelper.make("textbox", {"id":"valbox", "flex":"1", "value":val}));
           node.appendChild(HtmHelper.make("button", {"label":getLocalString("overall.label.browse"), "oncommand":"OpenDir('valbox')"}));
           $e("content").appendChild(node);
           node = HtmHelper.make("hbox");
           node.appendChild(HtmHelper.make("spacer", {"flex":"1"}));           
           node.appendChild(HtmHelper.make("button", {"label":getLocalString("overall.label.sure"), "oncommand":"callbackFun($e('valbox').value);closeWin();"}));
           node.appendChild(HtmHelper.make("spacer", {"flex":"1"}));
           node.appendChild(HtmHelper.make("button", {"label":getLocalString("task.state.cancelled"), "oncommand":"closeWin()"}));
           node.appendChild(HtmHelper.make("spacer", {"flex":"1"}));  
           $e("content_down").appendChild(node);
        }
        break;
    case 1:
        {
            var node = HtmHelper.make("hbox");
            node.appendChild(HtmHelper.make("spacer", {"flex":"1"}));
            node.appendChild(HtmHelper.make("button", {"label":getLocalString("overall.label.cancell"), "oncommand":"closeWin()"}));
            $e("content_down").appendChild(node);
            node = HtmHelper.make("hbox", {"flex":"1"});
            var box = HtmHelper.make("vbox");
            box.appendChild(HtmHelper.make("button",{"label":"close1","oncommand":"callbackFun['closeUI']()"}));
            node.appendChild(box);
            box = HtmHelper.make("vbox");
            box.appendChild(HtmHelper.make("button",{"label":"close2","oncommand":"callbackFun['closeAll']()"}));
            node.appendChild(box);
            $e("content").setAttribute("flex", "3");
            $e("content").appendChild(node);
        }
        break;
    case 2:
        {
            $e("content_main").setAttribute("style","display:none");
            $e("guide_merge_container").removeAttribute("style");
            if(data['url'])$e('main_file_name').value = data['url'];
        }
   }
}

function windowClose()
{
    
}

function closeWin()
{
    window.close();
}

function confirmMerge()
{
    var str = getMergedString();
    window.close();
    callbackFun(str);    
}
