// barc.js

var lastfolderclicked;
var lastdrawerclicked;
var currentfileid;
var iOldNode;
var iswritable = 0;
function popUp(URL, vW, vH) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + vW + " ,height=" + vH + "');");
}
function openPreview(vId) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open('preview.php?id=" + vId + "', '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=500');");
}
function openPreview800x600(vId) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open('preview.php?id=" + vId + "', '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=600');");
}
function swap2(){
	var xmlTree = new CXMLTree (treexml('NFC'));
	treeDef = xmlTree.toObject();
	var treeView = new CTree(treeDef.Menu, "sample");
	treeView.create();
}
function swap1(){
	var xmlTree = new CXMLTree (CodeThat.findElement("id1").value);
	treeDef = xmlTree.toObject();
	var treeView = new CTree(treeDef.Menu, "sample");
	treeView.create();
}

function setfolderadmin(folderid, foldername, writable){
	setpath(folderid);
	//iLabel = document.getElementById("gridtag")
	//iLabel.innerHTML = thispath;
	
	id = 'treenode_' + folderid;
	iswritable = writable;
	if (iOldNode != undefined)
	{
		//clear the old one
		iOldNode.style.bgcolor = "#FFFFFF";
		iOldNode.styleover = "onMouseOver=\"CT_setStyle(this, ['#000000','<?= $colors['treeover']?>','-'], '', false)\" onMouseOut=\"CT_setStyle(this, ['#000000','','-'], 'test2tree', false)\""
	}
	
	iNode = treeView.getNode(id)
	if (iNode != null)
	{
		iNode.style.bgcolor="#CCCCCC";
		iNode.styleover = "onMouseOver=\"CT_setStyle(this, ['#000000','#CCCCCC','-'], '', false)\" onMouseOut=\"CT_setStyle(this, ['#000000','#CCCCCC','-'], 'test2tree', false)\""
		treeView.paint();
	}
	//Store the new node
	iOldNode = iNode;

	var foldertag = document.getElementById("adminfolderspan1");
	foldertag.innerHTML = foldername;
	var foldertag = document.getElementById("adminfolderspan2");
	foldertag.innerHTML = foldername;
	var foldertag = document.getElementById("adminfoldername");
	foldertag.value = foldername;
	lastfolderclicked = folderid;
	currentfileid = 0;
	
}

function chkFolder(){
	if(lastfolderclicked>0){
		//alert(lastfolderclicked>0);
		if (iswritable == 1 || '<? print $admin; ?>' == '1')
		{
			return true;
		}else{
			alert("Sorry, you do not have permission to upload files to this folder.");
		}
	}else{
		alert("Sorry, you may not upload files until you have selected a destination folder.");
	}
	return false;
}

function downloadFile(iId){
	window.location.href = 'getfile.php?fileid='+iId;
	return true;
}

function gogetfile(){
	if(currentfileid>0){
		window.location.href ='getfile.php?fileid='+currentfileid;
		return true;
	}else{
		alert("You have not selected a file.");
	}
	return false;
}

function showfolderadmin(){
	if(lastfolderclicked>0){
		//document.getElementById("folderadmindiv").style.display="block";
		return true;
	}else{
		alert("You have not selected a folder.");
	}
	return false;
}

function getfileinfo(){
	if(currentfileid>0){
		popUp("fileinfo.php?fileid="+currentfileid, 550, 285);
		return true;
	}else{
		alert("You have not selected a file.");
	}
	return false;	
}

function popDrawerMaint(){
	if(lastdrawerclicked>0){
		popUp("drawermaintenance.php?drawerid="+lastdrawerclicked, 400, 200);
		//document.getElementById("folderadmindiv").style.display="block";
		return true;
	}else{
		alert("You have not selected a drawer.");
	}
	return false;
}


function popFolderMaint(){
	if(lastfolderclicked>0){
		popUp("foldermaintenance.php?folderid="+lastfolderclicked, 400, 300);
		//document.getElementById("folderadmindiv").style.display="block";
		return true;
	}else{
		alert("You have not selected a folder.");
	}
	return false;
}




function setlogo(){
	thistab = cabinetObject.lastExpandedTab;
	
	for(i=0;i<cabinetObject.accordionTabs.length;i++){
		if (thistab == cabinetObject.accordionTabs[i])
		{
			thistabid = i;
		}	
	}
	if (thistabid == null || thistabid == undefined)
	{
		thistabid = 0;
	}
	
	if( (jslogolist[thistabid]).length ){
		document.getElementById('logoimg').src='/phpthumb/phpThumb.php?h=50&src=/extranet/logos/'+jslogolist[thistabid];
	}else{
		document.getElementById('logoimg').src="img/transparent.gif";
	}
}

function getcurrentcabinet(){
	thistab = cabinetObject.lastExpandedTab;
	
	for(i=0;i<cabinetObject.accordionTabs.length;i++){
		if (thistab == cabinetObject.accordionTabs[i])
		{
			thistabid = i;
		}	
	}
	if (thistabid == null || thistabid == undefined)
	{
		thistabid = 0;
	}
	
	return jscabinetidlist[thistabid];
}

// error check login/password
function valid_form ( form ) {
  if ( form.login.value.length == 0 || form.pwd.value.length == 0 ) {
    alert ( "You must enter a username and a password");
    return false;
  }
  return true;
}

function setFocus() {
 login_form.login.focus();
}




function reloadLastCabinet(){
	iTab = cabinetObject.lastExpandedTab;
	for(i=0;i<cabinetObject.accordionTabs.length;i++){
		if (iTab == cabinetObject.accordionTabs[i])
		{
			iId = i;
		}	
	}
	if (iId == null || iId == undefined)
	{
		iId = 0;
	}
	
	refreshInterval = window.setInterval("refreshCabinet(" + iId + " )", 500);
}


function refreshCabinet(iId){
	clearInterval(refreshInterval);
	sURL = unescape(window.location.pathname);
	if (iId > 0 ){
		window.location.href = sURL+"?pannelid="+iId + "&random=" + Math.random();
	}else{
		window.location.href = sURL + "?random=" + Math.random();
	}
	return false;	
}


function reloadLastGrid(){
	refreshInterval = window.setInterval("refreshGrid()", 500);
}


function refreshGrid(){
	clearInterval(refreshInterval);
	if (lastfolderclicked > 0){
		filelist_xml_by_id(lastfolderclicked);
	}
}


function reloadLastTree(){
	refreshInterval = window.setInterval("refreshTree()", 500);
}


function refreshTree(){
	clearInterval(refreshInterval);
	if (lastdrawerclicked > 0)	{
		iName = document.getElementById('treelabel').innerHTML;
		treexml_by_id(lastdrawerclicked, iName);
	}
}


function rowHandler(){
	id=t.getColByTitle("ID");
	value = t.getKeyArray(-1);
	currentfileid = t.cells[value[0]][id].getData();
}

function rowDoubleClick(e){
	//get the current cell
	src = e.target;
	//find the row
	while (Def(src) && Undef(src.id) && Def(src.tagName) && src.tagName.toLowerCase() != "body"){
		src = ((ua.ie) ? src.parentElement : src.parentNode);
	}; 
	if (src != undefined){
		//check the number
		idNum = src.firstChild.innerHTML;
		
		if (idNum > 0){
			getfileinfo()
		}
	}
	//get the row id num from the first cell
}
