//List.js file. used only in frame with files/folders list. Includes
//Java Script functions to show interface, items selection and menu features.
//Before modify something here see  JS_CSS_VERSION element in HTCOMNET\web.config file!!!

var Items=0;
var FilePath='';
var folders=0;
var zip=false;
var lastSelected=0;
var SelectedInd=';';
var MouseSelection=false;
var lastMouseSelected=-1;
var Attributes;
var MoveState=false;
var oMenu;
var oRow;
var DragDropTargetSelectedIndex=-1
var DragWasPrepared=false
var PreparedIndex=-1
var SelectAfterMouseUp=false
var ColumnsArray;
var lastGrayState=-1;
var RightClickMenuShown=false;


function writelistformfields()
{
	document.write('<input type="hidden" name="content"><input type="hidden" name="newfoldername"><input type="hidden" name="newfilename">' + 
	 '<input type="hidden" name="zipname"><input type="hidden" name="addnewzip"><input type="hidden" name="targetname">' +
	 '<input type="hidden" name="newname"><input type="hidden" name="filename"><input type="hidden" name="to"><input type="hidden" name="fileorfolder">'+
	 '<input type="hidden" name="fullpath"><input type="hidden" name="file"><input type="hidden" name="indexes"><input type="hidden" name="index"><input type="hidden" name="task">')
}


function makeMenu(obj)
{
	
    return document.getElementById(obj)
}

function MakeMenuItem(id, text, myonclick, color)
{
	var str='<tr mytype="context"><td valign="middle" mytype="context" style="color:' + color + ';" class="menuitem" onClick="window.parent.List.DisableBothMenus(); ' + myonclick + '" id="' + id + '" onMouseOver="this.className=\'menuitemsel\';this.style.color=\'#FFFFFF\'" onMouseOut="this.style.color=\'' + color + '\';this.className=\'menuitem\';"><nobr mytype="context">' +  text + '&nbsp;&nbsp;</nobr></td></tr>'
	return str;
}

function SetMenuXY(Ev, win)
{
	var r; 
	var b; 
	var Menu=win.oMenu;
	var x, y;
	if (Ev.x)
	{	
		x = Ev.x;
		r = win.document.body.clientWidth - Ev.x;
		if (win.document.body)
			x += win.document.body.scrollLeft;
		if (win.document.documentElement)
			x += win.document.documentElement.scrollLeft;
	}
	else if (Ev.pageX)
		x = Ev.pageX;
	if (Ev.y)
	{	
		y = Ev.y;
		b = win.document.body.clientHeight - Ev.y;
		if (win.document.body)
			y += win.document.body.scrollTop;
		if (win.document.documentElement)
			y += win.document.documentElement.scrollTop;
	}
	else if (Ev.pageY)
		y = Ev.pageY;
	Menu.style.position='absolute';
	if (r < Menu.offsetWidth) 
		Menu.style.left = x - Menu.offsetWidth
	else
		Menu.style.left=x;
		
	if (b < Menu.offsetHeight) 
		Menu.style.top = y -  Menu.offsetHeight
	else
		Menu.style.top= y;
	

}

function ShowDragAndDropMenu(theRow, Ev, inTree)
{
	
	
	RightClickMenuShown=true
	var MenuWidth=130
	var str=''
	var filename;
	var isZIP=false;
	var objMenu
	if(theRow==-1)
		inTree=true;
	if(!inTree)
	{
		filename=document.form["i"+ theRow].value;
		if((theRow>folders) && (Ext(filename)=="ZIP"))
			isZIP=true;
	}

	str = '<table name="mnuTable" id="mnuTable" width="' + MenuWidth + '" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" class="menupanelfade"><tr>' + 
	 '<td mytype="context"><table bgcolor="#FFFFFF" class="menupanel" width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">'
	if(isZIP)
	{
		str = str + MakeMenuItem('mnuCopyHereftp',COPY_TO_ZIP,'window.parent.topFrame.addDRAGtozip()','#000000')	
	}
	else
	{
		str = str + MakeMenuItem('mnuCopyHereftp',COPY_HERE,'window.parent.topFrame.CopyMoveHere(\'copy\')','#000000')	
  		str = str + MakeMenuItem('mnuMoveHereftp',MOVE_HERE,'window.parent.topFrame.CopyMoveHere(\'cut\')','#000000')	
 	}
 	str=str +  '</table></td></tr></table>'
	

	
	if(inTree)
	{
		if(window.parent.Tree.oMenu)
  			window.parent.Tree.document.body.removeChild(window.parent.Tree.oMenu);
		window.parent.Tree.oMenu=window.parent.Tree.document.createElement('div');
		objMenu=window.parent.Tree.oMenu;
		objMenu.innerHTML = str
		SetMenuXY(Ev, window.parent.Tree)
		objMenu.style.height = objMenu.offsetHeight
		objMenu.style.width = MenuWidth		
		objMenu.style.visibility='visible'
		window.parent.Tree.document.body.appendChild(objMenu);
	}		
	else
	{
		if(oMenu)
  			document.body.removeChild(oMenu);
		oMenu=document.createElement('div');
		objMenu=oMenu;	
		objMenu.innerHTML = str		
		objMenu.style.width = MenuWidth			
		document.body.appendChild(objMenu);
		SetMenuXY(Ev, window.parent.List);
		objMenu.style.visibility='visible'
	}



}

function ShowMenu(theRow, Ev)
{
	
	RightClickMenuShown=true
	var str=''
	var isone=1
	var IndArray=SelectedInd.split(";")
	var singlename=''
	var wasZIPitem=false;
	var LineMenuHTML='<tr height="3"><td mytype="context"><HR mytype="context" size="1" style="position:static;padding:0px;color:Black;border-style:solid;border-color:#B2B4BF;height:1px;"></td></tr>'
	if(IndArray.length!=3)
		isone=0		
	else
		singlename=document.form["i"+ IndArray[1]].value;	
	var filename;	
	var MenuWidth=130
	if(theRow!=-1)
	{
		filename=document.form["i"+ theRow].value;
	}
	str = '<table mytype="context" style="z-index:5;" name="mnuTable" id="mnuTable" width="' + MenuWidth + '" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" class="menupanelfade"><tr>' + 
	 '<td mytype="context"><table mytype="context" bgcolor="#FFFFFF" class="menupanel" width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">'
	
	if(theRow!=-1 && window.parent.topFrame.CanFTP)
	{
		str = str + MakeMenuItem('mnuDownloadftp',MENU_FTPDOWNLOAD,'window.parent.topFrame.ftpdownload()','blue')	
  	}  	
	if(theRow!=-1)
		if( theRow > folders && isone==1)
		{
		str = str + MakeMenuItem('mnuDownload',MENU_DOWNLOAD, 'window.parent.topFrame.open_download(' +  theRow  +  ')', 'blue')
		}
	if (window.parent.topFrame.CanWrite)
	{
		if(theRow!=-1)
			if (isone==1)
			{
				str = str + MakeMenuItem('mnuRename',MENU_RENAME,'window.parent.topFrame.rename()','#000000')
			}
		if(theRow!=-1)
		{
			str = str + MakeMenuItem('mnuCut',MENU_CUT,'window.parent.topFrame.cut()','red')
		}
		if(theRow!=-1)
		{
			str = str + MakeMenuItem('mnuCopy',MENU_COPY,'window.parent.topFrame.showcopy()','#000000')
		}
		if(window.parent.topFrame.CanPaste)
		{
			str = str + MakeMenuItem('mnuPaste',MENU_PASTE,'window.parent.topFrame.paste()','#000000') 
		}
		if(theRow!=-1)
		{
			str = str + MakeMenuItem('mnuDelete',MENU_DELETE,'window.parent.topFrame.showdelete()','red')
		}
   }
   	if (theRow!=-1 && window.parent.topFrame.CanWrite && window.parent.topFrame.CanZip)
	{
		str = str + MakeMenuItem('mnuAddtoZIP',MENU_ADD_TO_NEW_ZIP,'window.parent.topFrame.addnewzip()','#FF6600')
	}
	if(theRow!=-1)
	{
		if(window.parent.List.zip)
			if (window.parent.topFrame.CanWrite && window.parent.topFrame.CanZip)
			{
				str = str + MakeMenuItem('mnuAddtoZIP',MENU_ADD_TO_ZIP,'window.parent.topFrame.addzip()','#FF6600')
			}
		if (isone==1)
		{
			
			if (Ext(filename)=="ZIP" && theRow > folders)
			{
				if (window.parent.topFrame.CanWrite && window.parent.topFrame.CanUnzip)
				{
					str = str + LineMenuHTML
					wasZIPitem=true
   					str = str + MakeMenuItem('mnuExtracttofolder',MENU_EXTRACT,'window.parent.topFrame.extractzip()','#FF6600') 
					str = str + MakeMenuItem('mnuViewcontent',MENU_VIEW_CONTENT,'window.parent.topFrame.viewcontent()','#FF6600')
   				}	
   				if (window.parent.topFrame.CanWrite && window.parent.topFrame.CanZip)
				{
					if(!wasZIPitem)
					{
						str = str + LineMenuHTML
						wasZIPitem=true
					}
					str = str + MakeMenuItem('mnuSelectZip',MENU_SELECT_ZIP,'window.parent.topFrame.SelectZIP()','#FF6600')
   				}
   				if(wasZIPitem) //add close line
   				{
   					str = str + LineMenuHTML;
   				}	
			}
			var n=window.parent.topFrame.ViewStr.lastIndexOf(';' + Ext(filename) + ';')
			if (n!=-1 && theRow > folders)
			{
					str = str + MakeMenuItem('mnuView',MENU_VIEW,'window.parent.topFrame.open_download(' + theRow + ', true)','#000000') 
			}
			var b=window.parent.topFrame.EditStr.lastIndexOf(';' + Ext(filename) + ';')
			if (b!=-1 && theRow > folders)
			{
				if (window.parent.topFrame.CanWrite)
				{
					str = str + MakeMenuItem('mnuEdit',MENU_EDIT,'window.parent.topFrame.open_editor(' + theRow + ')','#000000')
   				}
			
			}
		}
		
	}	 
	if(theRow!=-1)
	{
		str = str + MakeMenuItem('mnuProperties',MENU_PROPERTIES,'window.parent.topFrame.viewinfo()','#000000')	
  	}
  	if(theRow!=-1 && isone==1 && window.parent.topFrame.CanAddProperties)
  	{
  		str = str + LineMenuHTML;
  		str = str + MakeMenuItem('mnuAdvProperties',MENU_ADV_PROPERTIES,'window.parent.topFrame.AdvProperties(' + theRow + ')','#000000')  	
  	}  		 
  	str=str + '</table></td></tr></table>'
  	if(theRow==-1 && !window.parent.topFrame.CanPaste)
  		return; 
  	if(oMenu)
  		document.body.removeChild(oMenu);
  	
  	oMenu=document.createElement('div');
	oMenu.innerHTML = str	
	oMenu.style.width=MenuWidth	
	document.body.appendChild(oMenu);
	SetMenuXY(Ev, window.parent.List);
	oMenu.style.visibility='visible'

}



function GetRow(obj)
{
    return document.getElementById(obj)	
}

function PrepareDrag(index, Ev)
{
	DragWasPrepared=true
	PreparedIndex=index
	DragDropTargetSelectedIndex=-1	
}

function Drag(index, Ev)
{
	var MenuHeight=25
	var MenuWidth=130
	
	MoveState=true
	DragDropTargetSelectedIndex=-1
	var str='';
	if(SelectedInd!=";")
	{
		var IndArray=SelectedInd.split(";")		
		var ind=-1;
		var indind=-1;
		var value=-1;		
		var i, k;
		for(k=1; k<IndArray.length-1;k++)		
		{
			ind=100000;
			for(i=1; i<IndArray.length-1;i++)		
			{	
				if(IndArray[i]!=-1)
				{
					value = parseInt(IndArray[i]);
					if(value<ind)
					{
						ind = value;
						indind = i;																
					}
				}
							 
			}			
			if(ind!=100000)	
			{		
				str=str + document.getElementById('td0i' + ind).innerHTML + document.getElementById('td1i' + ind).innerHTML + '<BR>';
				IndArray[indind] = -1;	
			}
		}
	}
	else
	{		
		str = document.getElementById('td0i' + index).innerHTML + document.getElementById('td1i' + index).innerHTML
	}
	if(oRow)
		document.body.removeChild(oRow);
	
	oRow=document.createElement('div');	
	oRow.innerHTML = str
	oRow.style.height=MenuHeight
	oRow.style.width=MenuWidth	
	oRow.style.position='absolute';
	oRow.style.visibility='visible'
	document.body.appendChild(oRow);
}

function CloseDragAndMenu(Ev, type)
{
	var src = null;
    if (Ev.srcElement)
        src = Ev.srcElement;
    else if (Ev.target)
        src = Ev.target;
    var mytype
    if(src)
    {   
		var mytype=getAttribute(src, 'mytype');
		if(mytype==null && getParent(src)!=null) // Mozilla don't read Attributes of text objects.
			mytype=getAttribute(getParent(src), 'mytype');
		if(Ev.button==2 && type=='down' && mytype=='emptyfield')
		{
			DisableBothDrag();
			DisableBothMenus();
			ShowMenu(-1, Ev);
			return;
		}
		
		if(type=='down' && RightClickMenuShown==true && mytype!='context')
		{
			DisableBothDrag();
			DisableBothMenus();
		}		
		if(mytype=='row')
			return;
		if(mytype=='context')
			return;
    }
	DisableBothDrag();
	DisableBothMenus();
}

function ListMouseEvent(Ev, eventname)
{
	if (Ev.srcElement)
        src = Ev.srcElement;
    else if (Ev.target)
        src = Ev.target;
    if(src)
    {   
		var mytype=getAttribute(src, 'mytype');
		if(mytype==null && getParent(src)!=null) 
			mytype=getAttribute(getParent(src), 'mytype');
		
		var mysubtype=getAttribute(src, 'mysubtype');
		if(mysubtype==null && getParent(src)!=null) 
			mysubtype=getAttribute(getParent(src), 'mysubtype');
		
		var index=getAttribute(src, 'index');
		if(index==null && getParent(src)!=null) 
			index=getAttribute(getParent(src), 'index');
					
		if(mytype=='row')
		{
			if(eventname=='Down')
			{
				RowMouseDown(parseInt(index), Ev);
				if(mysubtype=='filename' || mysubtype=='foldername')
					if(window.parent.topFrame.CanWrite)
						PrepareDrag(parseInt(index), Ev);
						
				
			}
			else if(eventname=='Up')
			{
				RowMouseUp(parseInt(index), Ev);
				if(mysubtype=='filename' || mysubtype=='foldername')
				{
					DragWasPrepared=false;
				}
			}
			else if(eventname=='Out')
			{
				RowMouseOut(parseInt(index), Ev);
			}			
			else if(eventname=='Over')
			{
				SelectRow(parseInt(index))
			}				
		}
    }
//onMouseDown="RowMouseDown(' + index + ', ' + Ev + ');"
//onMouseUp="RowMouseUp(' + index + ', ' + Ev + ');"
//onMouseOut="RowMouseOut(' + index + ', ' + Ev + ')"
//onMouseOver="SelectRow(' + index + ')"
}

function DisableBothDrag()
{
	if(window.parent.Tree)
	{
		if(window.parent.Tree.oRow)
		{
			window.parent.Tree.document.body.removeChild(window.parent.Tree.oRow);
			window.parent.Tree.oRow = null;
		}
		window.parent.Tree.RowOut(window.parent.Tree.DragDropTargetSelectedIndex);
		window.parent.Tree.MoveState=false
	}
	
	if(window.parent.List.oRow)
	{
		document.body.removeChild(oRow);
		oRow=null;
	}
	window.parent.List.RowOut(window.parent.List.DragDropTargetSelectedIndex);
	window.parent.List.MoveState=false
	
	window.parent.List.DragWasPrepared=false
	window.parent.List.PreparedIndex=-1
	window.parent.List.MoveState=false
}

function DisableBothMenus()
{
	if(window.parent.Tree)
	{
		if(window.parent.Tree.oMenu)	
		{
			window.parent.Tree.document.body.removeChild(window.parent.Tree.oMenu);
			window.parent.Tree.oMenu = null;
		}
	}
	if(window.parent.List.oMenu)	
	{
		document.body.removeChild(oMenu);
		oMenu=null;		
	}
	RightClickMenuShown=false;
}

function RowEndDragDrop(index, Ev)
{
	DragWasPrepared=false
	PreparedIndex=-1
	if(MoveState==true)
	{
		if(DragDropTargetSelectedIndex!=-1)
		{
			ShowDragAndDropMenu(DragDropTargetSelectedIndex, Ev)
		}
		DisableBothDrag();
	}
}

function Move(Ev)
{
	if(window.parent.Tree)
	{
		if(window.parent.Tree.MoveState==true)
		{
			window.parent.Tree.oRow.style.visibility='hidden';	
			window.parent.Tree.MoveState=false;
			oRow.style.visibility='visible';
			MoveState=true;	
		}
	}
	if(MoveState==true && oRow)
	{
		var MenuHeight=25
		var MenuWidth=130
		var r = document.body.clientWidth - Ev.clientX; 
		var b = document.body.clientHeight - Ev.clientY; 
		var ScrollX=(ie)?document.body.scrollLeft:window.pageXOffset
		var ScrollY=(ie)?document.body.scrollTop:window.pageYOffset
		if (r < MenuWidth) 
			oRow.style.left = ScrollX + Ev.clientX - MenuWidth + 5
		else
			oRow.style.left=ScrollX + Ev.clientX + 5;
			
		if (b < MenuHeight) 
			oRow.style.top = ScrollY + Ev.clientY - MenuHeight + 5
		else
			oRow.style.top=ScrollY + Ev.clientY + 5;
	}
}



function continualGray()
{
	var IndArray=SelectedInd.split(";");	
	var IsOne=false;
	var IsFew=false;
	var State=-2;
	
	if(IndArray.length==3)
	{
		IsOne=true;
		State=1;
	}
	if(IndArray.length>3)
	{
		IsFew=true;
		State=2;
	}
	if(State==lastGrayState) 
		return;
	if(IsOne || IsFew)
	{
		if(window.parent.topFrame.CanWrite)
		{
			if(IsOne)
				window.parent.topFrame.MakeGood('Rename')
			else
				window.parent.topFrame.MakeGrey('Rename');
			window.parent.topFrame.MakeGood('Cut')
			window.parent.topFrame.MakeGood('Copy')
			window.parent.topFrame.MakeGood('Delete')
		}
	}
	else
	{	
		State=0	
		window.parent.topFrame.MakeGrey('Rename')
		window.parent.topFrame.MakeGrey('Cut')
		window.parent.topFrame.MakeGrey('Copy')
		window.parent.topFrame.MakeGrey('Delete')
	}
	lastGrayState=State;
}

function SetMenuItem(id, value)
{
	if(value==true)	
		AvailableMenuItem(id)
	else
		GrayMenuItem(id);
}


function HideAll()
{
		if(SelectedInd!=";")
		{
			var IndArray=SelectedInd.split(";")
			for(i=1; i<IndArray.length-1;i++)
			{
				Clear(IndArray[i])	
				document.form["id" + IndArray[i]].value='0'; 
			}
		}
		SelectedInd =";";
}

function Paint(index)
{
	var rowColor="#99ccff";
	document.getElementById("row" + index).style.background = rowColor
	var TD0=document.getElementById("td" + 0 + "i" + index)
	var TD1=document.getElementById("td" + 1 + "i" + index)
	if(TD0.style.background!=rowColor)
		TD0.style.background = rowColor;
	if(TD1.style.background!=rowColor)
		TD1.style.background = rowColor;
}

function Clear(index)
{
	var rowColor='';
	if((index % 2)==false)
		rowColor='#EBEBEB'
	else
		rowColor='#F5F5F5';
	document.getElementById("row" + index).style.background= rowColor;
	
	var TD0=document.getElementById("td" + 0 + "i" + index)
	var TD1=document.getElementById("td" + 1 + "i" + index)
	
	if(TD0.style.background!=rowColor)
		TD0.style.background = rowColor;
	if(TD1.style.background!=rowColor)
		TD1.style.background = rowColor;
}

function SelectRow(index)
{
	/*if(DragDropTargetSelectedIndex!=-1)
		Clear(DragDropTargetSelectedIndex);*/
	if(MoveState==true) 
	{			
		var filename=document.form["i"+ index].value;
		if((index<=folders) || (index>folders && Ext(filename)=="ZIP"))
		{
			if (document.form["id" + index].value=='0')
			{
				document.getElementById("td" + 0 + "i" + index).style.background= "#CDCDCD";
				document.getElementById("td" + 1 + "i" + index).style.background= "#CDCDCD";
				DragDropTargetSelectedIndex=index;	
			}	
		}
		else
		{
			DragDropTargetSelectedIndex=-1
		}
		return		
	}
	
	
	//if(Opera5 || Opera6) return;

	
	if(MouseSelection)
	{
		if(lastMouseSelected==-1)
		{
			Paint(index)
			document.form["id" + index].value='1';
			SelectedInd= SelectedInd + index + ";"
			lastMouseSelected=index	
			continualGray()
			return;
		}
		var i=0;
		var k=index>lastMouseSelected?1:-1;
		
		for(i=lastMouseSelected; (k==1)?i<=index:i>=index; i+=k)
		{
			if(document.form["id" + i].value=='0')
			{
				Paint(i)
				document.form["id" + i].value='1';
				SelectedInd= SelectedInd + i + ";"
			}
			else
			{
				if(i!=lastMouseSelected && i-k>=0)
				{
					if(document.form["id" + (i-k)].value=='1')
					{
						Clear(i-k)	
						document.form["id" + (i-k)].value='0';
						SelectedInd= SelectedInd.replace(";" + (i-k) + ";", ";"); 
					}	
				}		
			}
		
		}
		lastMouseSelected=index	
		continualGray()
	}	
}

function RowOut(index, Ev)
{
		if(DragWasPrepared==true)
		{
			Drag(PreparedIndex, Ev)
			DragWasPrepared=false
			PreparedIndex=-1
		}
		if(MoveState==true)
		{
				if (index!=-1)	
				{
					if (document.form["id" + index].value=='0')
					{
						Clear(index)
					}
				}
				return;
		}

}

function RowMouseDown(theRow, Ev)
{
	if(MoveState==true) return;
	
	var i;
	
	SelectAfterMouseUp=false;
	
	if(Ev.button==2 && !Ev.ctrlKey)
	{
		if (document.form["id" + theRow].value=='1')
		{
			return;
		}
	}	
	 
	if(!Ev.ctrlKey)
	{
		if (document.form["id" + theRow].value=='1')
		{
			if (Ev.srcElement)
				src = Ev.srcElement
			else if (Ev.target)
				src = Ev.target;
			if(src)
			{   
				var mysubtype=getAttribute(src, 'mysubtype');
				if(mysubtype==null && getParent(src)!=null) 
					mysubtype=getAttribute(getParent(src), 'mysubtype');
				if(mysubtype=='filename' || mysubtype=='foldername')
						return;
			}
		}
	}	
	 
	if(!Ev.ctrlKey && !Ev.shiftKey) 
	{
		HideAll();
		Paint(theRow)
		document.form["id" + theRow].value='1';
		SelectedInd=";" + theRow + ";";
		lastSelected=theRow;
	}
	else if (Ev.shiftKey)
	{
		HideAll();
	 	var k=theRow>lastSelected?1:-1;
		for(i=lastSelected; (k==1)?i<=theRow:i>=theRow; i+=k)
		{
			Paint(i)
			document.form["id" + i].value='1';
			SelectedInd= SelectedInd + i + ";"
			
		}
	}
	else if (Ev.ctrlKey)
	{
		if (document.form["id" + theRow].value=='0')
		{
			Paint(theRow)
			document.form["id" + theRow].value='1';
			SelectedInd= SelectedInd + theRow + ";"
		}
		else
		{
			Clear(theRow)
			document.form["id" + theRow].value='0'; 
			SelectedInd= SelectedInd.replace(";" + theRow + ";", ";"); 
		}
		lastSelected=theRow;		
	}
	lastMouseSelected=lastSelected
	continualGray()
}

function RowMouseUp(index, Ev)
{
	
	DragWasPrepared=false;
	if(MoveState==true) 
	{
		RowEndDragDrop(index, Ev);
		return;
	}
	if(SelectAfterMouseUp==true)
	{
			
			HideAll();
			Paint(index);
			document.form["id" + index].value='1';
			SelectedInd=";" + index + ";";
			lastSelected=index;
			lastMouseSelected=lastSelected;
			continualGray()
	
	}	
	if(Ev.button==2) rightclick(index, Ev)
	
}


function RowMouseOut(index, Ev)
{
	RowOut(index, Ev);
	return;
}

function rightclick(theRow, Ev)
{
	DragWasPrepared=false
	PreparedIndex=-1
	if (document.form["id" + theRow].value=='0')
	{
		
		window.parent.topFrame.SelectedFrame=window.parent.List
		HideAll();
		Paint(theRow)
		document.form["id" + theRow].value='1';
		SelectedInd=";" + theRow + ";";
	}
	ShowMenu(theRow, Ev)
	return false; 
}

function writesort(sortedtype, sortedmethod)
{
	var s=new String();
	var i;
	var name='';
	var size=0;
	var color;
	var align;
	var title;
	var onclick;
	s="<tr id=\"ListHeader\" style=\"background-image:url(images/XP_listcenter.gif);position:static;\"  cellspacing=\"0\" cellpadding=\"0\" height=\"20\"><td width=\"18\">&nbsp;</td>"
	for (i in ColumnsArray)
	{
		
		name=ColumnsArray[i][0];
		if(i!=0)
			size = 'width="' + ColumnsArray[i][1] + '"'
		else
			size='';
		color=ColumnsArray[i][2];
		align=ColumnsArray[i][3];
		if(strCompare(name,window.parent.topFrame.allpropmess,true)!=0)
		{
			title='title="' + SORT_BY + ' ' + name + '"';
			onclick="onclick=\"javascript: window.parent.List.location.href='sort.aspx?sorttype=" + escapeplus(name) + "'\"";
		}
		else
		{
			title='';
			onclick='';
		}
		s = s + "<td " + title + " style=\"cursor:pointer;cursor:hand;border-right: #C7C5B2 1px solid;\" " + onclick + " onmouseout=\"javascript: this.className='Sort';\" onmouseover=\"javascript: this.className='active-box-item';\" " + size + " class=\"Sort\"><font style=\"font-size:12px;\" class=\"Sort\"><nobr>&nbsp;" + name + "&nbsp;" 
		if(sortedtype==name && sortedmethod=='down')
			s = s + '<img src="images/XP_listtriangledown.gif" width="9" height="5">'
		else if(sortedtype==name && sortedmethod=='up')
			s = s + '<img src="images/XP_listtriangleup.gif" width="9" height="5">';
		s = s + '</nobr></font></td>'
	}

	s=s+'</tr>'
	document.write(s);
}

function SplitProperties(Name, Value)
{
	var Names = Name.split("|")
	var Values = Value.split("|")
	var i=0
	var ret=""
	for(i=0; i<Names.length; i++)
	{
		ret=ret + Names[i] + ": " + Values[i] + '\n'
	}
	if(EndsWith(ret, '\n'))
		ret=ret.substring(0, ret.length-1);
	return ret;
}

function GetExtendedTD(index, ArrayProps, SystemColumnsLength)
{
	var showedproperties='';
	var i=0;	
	var columnrecord;	
	var properties='';	
	for(i=SystemColumnsLength;i<ArrayProps.length;i++)
	{
		columnrecord = ArrayProps[i].split("#")		
		properties += columnrecord[0] + ": " + columnrecord[1] + '\n'	
		showedproperties = showedproperties + columnrecord[1] + ", "
	}	

	if(EndsWith(properties, '\n'))
		properties = properties.substring(0, properties.length-1);
		
	if(EndsWith(showedproperties, ', '))
		showedproperties = showedproperties.substring(0, showedproperties.length-2);
		
	if (showedproperties.length>35)
		showedproperties = showedproperties.substring(0,35) + '...';

	
	if(showedproperties!='')
	{
		
		var s='<td index="' + index +'" mytype="row"  width="100" align="left">'
		if(window.parent.topFrame.CanAddProperties)
			s=s+'<a title="' + properties + '" href="javascript:window.parent.topFrame.AdvProperties(' + index + ')">'
		s=s+'<font title="' + properties + '" color="#4B4B4B" size="1" face="Arial">&nbsp;' + showedproperties + '</font>'
		if(window.parent.topFrame.CanAddProperties)
			s=s+'</a>';
		s=s+'</td>'
		return s;
	}
	else if(window.parent.topFrame.CanAddProperties)
		return '<td index="' + index +'" mytype="row"  width="100" align="left"><a class="fileaction" title="' + ADD_PROPERTIES + '" href="javascript:window.parent.topFrame.AdvProperties(' + index + ')"><font color="#4B4B4B" face="Arial">' + ADD_PROPERTIES_SHORT + '</font></a></td>'
	else
		return '<td index="' + index +'" mytype="row"  width="100" align="left">&nbsp;</td>';
	
}

function fil(index, image, filetype, attribs, name, ArrayProps)
{
	//StartCountTime('fil');
	var s=new String();
	var getfile='&nbsp';
	var i=0;
	var isFolder=(index<=folders);
	var imgIcon='';
	var ItemLabel='';
	var Ev=GetEventStr();			
	
	var rowColor='';
	if((index % 2)==false)
		rowColor='#EBEBEB'
	else
		rowColor='#F5F5F5';

	var alt='';
	var columntext='';
	var columnval='';
	var found=false;
	var issystem=false;
	var ReshPos=-1;
	
	
	Attributes[index]=attribs
	
	var SystemColumnsLength
	if(isFolder)
		SystemColumnsLength=3
	else
		SystemColumnsLength=4;
	
	alt='Type: ' + filetype + '\n' 
	for(k=0; k<SystemColumnsLength; k++)
	{
		alt += ArrayProps[k].replace("#",": ") + '\n';
	}
	alt=alt.substring(0,alt.length-1);
	alt=alt.replace('"','&quot;')
	alt=alt.replace('&nbsp;',' ')

	
	
	for(i=2; i<ColumnsArray.length; i++)	
	{	
		found=false;
		issystem=false;
		for(k=0; k<ArrayProps.length; k++)
		{
			if(StartsWith(ArrayProps[k],ColumnsArray[i][0]+"#"))
			{				
				ReshPos = ArrayProps[k].indexOf("#"); 
				if(ReshPos>=0)				
					columnval=ArrayProps[k].substring(ReshPos+1,ArrayProps[k].length);
				found=true;					
				if(k<SystemColumnsLength)
					issystem=true;
				break;
			}			
		}
		
		if(found)
		{
			if(issystem)
				columnval='<nobr index="' + index +'" mytype="row">' + columnval + '</nobr>';
			columntext += '<td index="' + index +'" mytype="row"  width="' + ColumnsArray[i][1] + '" align="' + ColumnsArray[i][3] + '" valign="middle"><font index="' + index +'" mytype="row"  class="list" size="1" face="Arial" color="' + ColumnsArray[i][2] + '">' + columnval +	'&nbsp;</font></td>';
		}
		else
		{
			if(strCompare(ColumnsArray[i][0],window.parent.topFrame.allpropmess,true)==0)
			{
				if((ArrayProps.length-SystemColumnsLength)>=0) 
					columntext +=  GetExtendedTD(index, ArrayProps, SystemColumnsLength)
				else
					columntext += '<td index="' + index +'" mytype="row"  width="100" align="left">&nbsp;</td>';
			}
			else
				columntext += '<td index="' + index +'" mytype="row"  width="' + ColumnsArray[i][1] + '">&nbsp;</td>';	
		}
	}
	

	var showedname=BreakToPieces(name, 25, '<font style="font-size:1px"> </font>')
	
	if(isFolder)
	{
		imgIcon='<td index="' + index +'" mytype="row" width="18" id=td0i' + index + ' align="right"><a title="' + OPEN_FOLDER + '" href="javascript: window.parent.topFrame.open_dir(' + index + ')"><img index="' + index +'" mytype="row" src="images/EXT/' + image + '" width="16" height="16" border="0" alt="' + OPEN_FOLDER + '"></a></td>'
		ItemLabel='<font ondblclick="javascript: window.parent.topFrame.open_dir(' + index + ')" class="listfolder" title="' + alt + '" index="' + index +'" mytype="row" mysubtype="foldername">' + showedname +	'</font>'
		getfile='<td index="' + index +'" mytype="row"  width="48">&nbsp;</td>'	 
	}
	else
	{
		imgIcon='<td index="' + index +'" mytype="row"  width="18" id=td0i' + index + ' align="right"><img index="' + index +'" mytype="row"  width="16" height="16" title="' + filetype + '" alt="' + filetype + '" src="images/EXT/' + image + '" border="0"></td>'
		ItemLabel='<font index="' + index +'" mytype="row" mysubtype="filename" title="' + alt + '"  class="list" size="2" color="#291C18">'  + showedname + '</font>'
		getfile='<td align="center" width="48"><a index="' + index +'" mytype="row"  title="' + strFormat(GET_ALT, name) + '" class="fileaction" href="javascript:window.parent.topFrame.open_download(' + index + ');" ><font index="' + index +'" mytype="row"  color="#3242DF">' + GET + '&nbsp;</font></a></td>'	
	}
	
	s='<tr index="' + index +'" mytype="row" bgcolor="' + rowColor + '" id="row' + index +'" class="list"><input type="hidden" name="id'+ index +'" value="0"><input name="i' + index + '" type="hidden" value="' + name + '">' + imgIcon + '<td index="' + index +'" mytype="row"  id=td1i' + index + '>&nbsp;' +
	ItemLabel + '</td>' + getfile + columntext + '</tr>';
	//FinishCountTime('fil');
	document.write(s);
	
	
}