// JavaScript Document

var fbDirs  =new Array();
var fbFiles =new Array();

function fileInit(domObj)
{
  //var data='Box='+domObj.getAttribute('id');
 //alert(domObj.getAttribute('id')); 
  //if (!domObj.onChange) domObj.onChange=function(){}; 
    
  sendRequest('ajax/axFileBrowser.php','',domObj.getAttribute('id'));
 
}

function fileGoDir(ctrlName,DirName)
 {sendRequest('ajax/axFileBrowser.php','ACTION=ChDir&Dir='+DirName,ctrlName);}
function fileUpDir(ctrlName)
 {sendRequest('ajax/axFileBrowser.php','ACTION=UpDir',ctrlName);}
function fileView(ctrlName,View)
 {sendRequest('ajax/axFileBrowser.php','ACTION=SetView&View='+View,ctrlName);}
function fileSort(ctrlName,Field)
 {sendRequest('ajax/axFileBrowser.php','ACTION=Sort&OrderBy='+Field,ctrlName);}
function fileChoose(ctrlName,FileName)
 {
    fbObj=document.getElementById(ctrlName);
    fbObj.value='.'+fbObj.relPath+'/'+FileName;    
    fbObj.onChange(); 
 }
function fileMakeDir(ctrlName)
{
	strDirName=prompt(_lngENTER_DIRECTORY_NAME);
	sendRequest('ajax/axFileBrowser.php',
	            'ACTION=MkDir&DirName='+strDirName,ctrlName
						 );
}

function filePopUpFileBrowser(oClient)
{
  _dialog.open('pupFileBrowser',true,oClient);
  _dialog.reSize('pupFileBrowser','400px','400px');
  _dialog.position('pupFileBrowser','25%','25%');

  //The callback-function of the application is always oClient.onReturn
  
  pupObj=document.getElementById('dialog_pupFileBrowser');
  pupW=pupObj.clientWidth;
  pupH=pupObj.clientHeight;

  var fbHTML='';  
  fbHTML+='<DIV ID=fbPath STYLE="position:absolute;width:100%;height:20px;">Path to file</DIV>';
  fbHTML+='<DIV ID=fbToolBar STYLE="position:absolute;top:20px;width:'+(pupW-2)+'px;height:22px;" CLASS=_ToolBar>';
  fbHTML+='  <INPUT ID=fbChoosen STYLE="width:150px;" CLASS=_Control >';
  fbHTML+='  <IMG SRC=img/icons/application_view_list.png  onClick=fileView("fbBrowser","List")>';
  fbHTML+='  <IMG SRC=img/icons/application_view_icons.png onClick=fileView("fbBrowser","Tiles")>';
  fbHTML+='  <IMG SRC=img/icons/application_view_tile.png  onClick=fileView("fbBrowser","Preview")>';
  fbHTML+='  <IMG SRC=img/icons/arrow_up.png               onClick=fileUpDir("fbBrowser")>';
	fbHTML+='  <IMG SRC=img/icons/folder_add.png             onClick=fileMakeDir("fbBrowser")>';
  fbHTML+='  Sort: <SELECT CLASS=_Control onchange=fileSort("fbBrowser",this.options[this.selectedIndex].text)><OPTION>Name</OPTION><OPTION>Size</OPTION><OPTION>Time</OPTION></SELECT>';
  fbHTML+='</DIV>';
  fbHTML+='<DIV ID=fbBrowser STYLE="position:absolute;top:44px;width:100%;height:'+(pupH-45)+'px" ';
  fbHTML+=' ELEM_init=fileInit(objControl)></DIV>';
  

  
  pupObj.innerHTML=fbHTML;
  _ctrl.init('fbBrowser','onChange[+]filePupChoose');
}

function filePupChoose()
{
  //----------------------------------------------------------------------------
  // Fire when file is clicked in browser-popup
  fbObj=document.getElementById('fbBrowser');

  _dialog.currDialog.value=this.value;
  
  
  inputObj=document.getElementById('fbChoosen');
  inputObj.value=this.value;
}
