//Up.js file used in top frame. Includes Java Script functions 
//to show top panel and functions which runs all operations with items.
//Before modify something here see  JS_CSS_VERSION element in HTCOMNET\web.config file!!!
var ActiveTheme='';
var email='';
var CanUp=false;
var CanWrite=false;
var CanUpload=false;
var CanZip=false;
var CanUnzip=false;
var CanPaste=false;
var CanSetAttrib=false;
var CanFTP=false;
var CanFlash8=false;
var CanAddProperties=false;
var CanReadProperties=false;
var ViewStr='';
var EditStr='';
var vp='';
var dd=false;
var rbs=false;	
var CurrentPath='';
var Paste='Paste';
var Language=''
var HelpFile=''
var newwindow='';
var logoffclick=false;
var progressbarwindow;
var ftpwindow;
function MakeGrey(imgName)
{
	var img=document.getElementById("img"+imgName);
	if(img)
	{	
		if(img.style.filter || img.style.filter=='')
		{
			if(img.style.filter=='')
			{
				img.style.filter='Alpha(Opacity=70)Gray';
			}
		}
		else
		{
			var imgpath="images/XP_gray" + imgName+ ".gif"		
			if(document["img"+imgName].src!=imgpath) 
				document["img"+imgName].src=imgpath;
		}
	}
	if(imgName=="Up") CanUp=false;
	if(imgName=="Paste") CanPaste=false;
	
}
function MakeGood(imgName)
{
    var img=document.getElementById("img"+imgName);
	if(img)
	{
		if(img.style.filter || img.style.filter=='')
		{
			if(img.style.filter!='') 
				img.style.filter='';
		}
		else
		{
			var imgpath="images/XP_" + imgName+ ".gif"
			if(document["img"+imgName].src!=imgpath) 		
				document["img"+imgName].src=imgpath;
		}
	}

	if(imgName=="Up") CanUp=true;
	if(imgName=="Paste") CanPaste=true;
}

function setgotopath()
{
	if(document.myform)
    {
		document.myform.textfield.value=CurrentPath
	}
}

function drawStick()
{
	document.write('<td align="center" width="12"><img src="images/Frame_lnstick.gif" width="3" height="36"></td>')
}

function drawsrramk(imgname, alt, myonclick, secname, width, height)
{
	var s=new String();
	var localt=(alt=='Paste')?Paste:"'" + alt + "'"
	s='<td title="' + alt + '" class="iconunsel" onclick="javascript: '+ myonclick +' " onmouseout="javascript: RamkOff(this); document.getElementById(\'ms\').style.visibility=\'hidden\'; return true;" onmouseover="javascript: RamkOn(this);document.getElementById(\'ms\').innerHTML=' + localt + '; document.getElementById(\'ms\').style.visibility=\'visible\'; return true;" style="cursor:hand;">&nbsp;<img alt="' + alt + '" height="' + height + '" width="' + width + '" name="' + secname +'" id="' + secname +'" style="" border="0" src="images/XP_' + imgname + '.gif">' +
	'&nbsp;</td>'
	document.write(s);
}

function RamkOn(item)
{
	item.className = "iconsel";
}

function RamkOff(item)
{
	item.className = "iconunsel";
}


function isfilefoldercorrect(s)
{
	var i;
	for(i=0; i<=s.length; i++)
		if(s.charAt(i)=='\\' || s.charAt(i)=='\/' || s.charAt(i)=='\:' || s.charAt(i)=='\*' || s.charAt(i)=='\?'|| s.charAt(i)=='\"' || s.charAt(i)=='\<' || s.charAt(i)=='\>' || s.charAt(i)=='\|')
			return false;
	return true;
}


function open_folders() 
{
	var mywidth=500	
	var myheight=550	
    newwindow = window.open('Folders.aspx', null, 'menubar=yes, toolbar=yes, location=no, status=no, resizable=yes, scrollbars=yes, width=' + mywidth + ' , height=' + myheight + ', left=' + (screen.width-mywidth)/2 + ', top=' + (screen.height-myheight)/2);
    newwindow.focus();
}

function Up()
{
	if(CanUp)
		window.parent.List.location.href='list.aspx?task=closedir'
	else
		window.alert(ON_TOP);
}

function createdir()
{ 
	var r;
	if((r=window.prompt(ENTER_FOLDER_NAME, "New Folder")))
		if(isfilefoldercorrect(r))
		{
			window.parent.List.document.form.newfoldername.value=r
			window.parent.List.document.form.action="createnewfolder.aspx"
			window.parent.List.document.form.submit()
		}
		else
			window.alert(NAME_CANNOT_CONTAIN);	
}

function createfile()
{ 
	var r;
	var mess = ENTER_FILE_NAME;
	if(CanWrite)
		mess += ENTER_TXT_EXTENSION;
	if((r=window.prompt(mess, "New file.txt")))
		if(isfilefoldercorrect(r))
		{
			window.parent.List.document.form.newfilename.value=r
			window.parent.List.document.form.action="createnewfile.aspx"
			window.parent.List.document.form.submit()
		}
		else
			window.alert(NAME_CANNOT_CONTAIN);
}

function rename()
{

	var r; 
	var IndArray=window.parent.List.SelectedInd.split(";")	
	if(IndArray.length<3)
		window.alert(SELECT_AN_ITEM)
	else if(IndArray.length>3)
		window.alert(SELECT_ONLY_ONE_ITEM)
	else
	{
		if(window.parent.List.Attributes[IndArray[1]] & ATTR_READ_ONLY)
		{
				if(CanSetAttrib)
				{
					if(!window.confirm(strFormat(RENAME_READ_ONLY, window.parent.List.document.form["i" + IndArray[1]].value)))
					return;
				}
				else
				{
					window.alert(strFormat(CANT_RENAME_READ_ONLY, window.parent.List.document.form["i" + IndArray[1]].value))	
					return;
				}				
		}
		if((r=window.prompt(ENTER_NEW_NAME, window.parent.List.document.form["i" + IndArray[1]].value)))
		{
			if(isfilefoldercorrect(r))
			{
				window.parent.List.document.form.targetname.value=window.parent.List.document.form["i" + IndArray[1]].value
				window.parent.List.document.form.newname.value=r
				window.parent.List.document.form.action="rename.aspx"
				window.parent.List.document.form.submit()
			}
			else
				window.alert(NAME_CANNOT_CONTAIN);
		}
	}
}

function cut()
{
	var IndArray=window.parent.List.SelectedInd.split(";")
	if(IndArray.length<3)
		window.alert(SELECT_AT_LEAST_ONE_ITEM)
	else
	{
		var delstr=''
		var i;
		for(i=1; i<IndArray.length-1;i++)
		{	
			if(window.parent.List.Attributes[IndArray[i]] & ATTR_READ_ONLY)
			{
				if(CanSetAttrib)
				{
					if(window.confirm(strFormat(CUT_READ_ONLY, window.parent.List.document.form["i" + IndArray[i]].value)))
						delstr=delstr + window.parent.List.document.form["i" + IndArray[i]].value + ', '
					else
						return;
				}
				else
				{
					window.alert(strFormat(CANT_CUT_READ_ONLY, window.parent.List.document.form["i" + IndArray[i]].value))	
					return;
				}				
			}
			else
				delstr=delstr + window.parent.List.document.form["i" + IndArray[i]].value + ', '; 
		}
		if(EndsWith(delstr, ', '))
			delstr=delstr.substring(0, delstr.length-2);
		if(window.confirm(strFormat(CUTED_ITEMS, delstr)))
		{
			window.parent.List.document.form.action="cut.aspx"
			window.parent.List.document.form.submit()
		}
	}
}

function showcopy()
{
	var IndArray=window.parent.List.SelectedInd.split(";")
	if(IndArray.length<3)
		window.alert(SELECT_AT_LEAST_ONE_ITEM)
	else 
	{
		window.parent.List.document.form.action="copy.aspx"
		window.parent.List.document.form.submit()
		
	}
}

function CopyMoveHere(action)
{
	if(window.parent.List.DragDropTargetSelectedIndex!=-1)
	{
		window.parent.List.document.form.targetname.value=window.parent.List.DragDropTargetSelectedIndex
		window.parent.List.document.form.action="Paste.aspx?action=" + action
	}
	else
	{
		if(window.parent.Tree)
		{
			if(window.parent.Tree.DragDropTargetSelectedIndex!=-1)
			{
				window.parent.List.document.form.fullpath.value=window.parent.Tree.tree._aNodes[window.parent.Tree.tree._searchNode(window.parent.Tree.DragDropTargetSelectedIndex)].folderpath
				window.parent.List.document.form.action="Paste.aspx?intree=true&action=" + action
			}
		}
	}
	window.parent.List.document.form.submit()

}


function paste()
{
	if (CanPaste)
		window.parent.List.location.href="paste.aspx"
	else
		window.alert(YOU_SHOULD_COPY_OR_CUT);
}

function showdelete()
{
	var IndArray=window.parent.List.SelectedInd.split(";")
	if(IndArray.length<3)
		window.alert(SELECT_AT_LEAST_ONE_ITEM)
	else
	{
		var delstr=''
		var i;
		for(i=1; i<IndArray.length-1;i++)
		{	
			if(window.parent.List.Attributes[IndArray[i]] & ATTR_READ_ONLY)
			{
				if(CanSetAttrib)
				{
					if(window.confirm(strFormat(DELETE_READ_ONLY, window.parent.List.document.form["i" + IndArray[i]].value)))
						delstr=delstr + window.parent.List.document.form["i" + IndArray[i]].value + ', '
					else
						return;
				}
				else
				{
					window.alert(strFormat(CANT_DELETE_READ_ONLY, window.parent.List.document.form["i" + IndArray[i]].value))	
					return;
				}				
			}
			else
				delstr=delstr + window.parent.List.document.form["i" + IndArray[i]].value + ', '; 
		}
		if(EndsWith(delstr, ', '))
			delstr=delstr.substring(0, delstr.length-2);
		if(window.confirm(strFormat(DELETED_ITEMS, delstr)))
		{
			window.parent.List.document.form.action="delete.aspx"
			window.parent.List.document.form.submit()
		}
	}
}

function viewinfo()
{

	var IndArray=window.parent.List.SelectedInd.split(";")
	if(IndArray.length<3)
		window.alert(SELECT_AT_LEAST_ONE_ITEM)
	else
	{
		var str=''
		var i;
		for(i=1; i<IndArray.length-2;i++)
		{	
			str=str + window.parent.List.FilePath + window.parent.List.document.form["i" + IndArray[i]].value + ': '; 
		}
		str=str + window.parent.List.FilePath + window.parent.List.document.form["i" + IndArray[i]].value
		if(IndArray.length==3)
		{
			var mywidth=500	
			var myheight=450	
			newwindow = window.open('onefileprop.aspx?fileorfolder=' + escapeplus(str), null, 'menubar=yes, toolbar=yes, location=no, status=no, resizable=yes, scrollbars=yes, width=' + mywidth + ' , height=' + myheight + ', left=' + (screen.width-mywidth)/2 + ', top=' + (screen.height-myheight)/2);
			newwindow.focus();
		}
		else
		{
			var mywidth=500	
			var myheight=450	
			newwindow = window.open('multifileprop.aspx?fileorfolder=' + escapeplus(str), null, 'menubar=yes, toolbar=yes, location=no, status=no, resizable=yes, scrollbars=yes, width=' + mywidth + ' , height=' + myheight + ', left=' + (screen.width-mywidth)/2 + ', top=' + (screen.height-myheight)/2);
			newwindow.focus();
		}
	}	
}

function open_upload() 
{
	var mywidth=500	
	var myheight=450	
	newwindow = window.open('Upload.aspx', null, 'menubar=yes, toolbar=yes, location=no, status=no, resizable=yes, scrollbars=yes, width=' + mywidth + ' , height=' + myheight + ', left=' + (screen.width-mywidth)/2 + ', top=' + ((screen.height-myheight)/2 -50));
	newwindow.focus();	
}

function open_uploadFTP() 
{
	var mywidth=500	
	var myheight=450	
	newwindow = window.open('Upload.aspx?ftpmode=yes', null, 'menubar=yes, toolbar=yes, location=no, status=no, resizable=yes, scrollbars=yes, width=' + mywidth + ' , height=' + myheight + ', left=' + (screen.width-mywidth)/2 + ', top=' + (screen.height-myheight)/2);
	newwindow.focus();	
}
function open_uploadFlash8() 
{
	var mywidth=500	
	var myheight=450	
	newwindow = window.open('Upload.aspx?flash8mode=yes', null, 'menubar=yes, toolbar=yes, location=no, status=no, resizable=yes, scrollbars=yes, width=' + mywidth + ' , height=' + myheight + ', left=' + (screen.width-mywidth)/2 + ', top=' + (screen.height-myheight)/2);
	newwindow.focus();	
}

function findfile()
{
	var r;
	if((r=window.prompt(ENTER_SEARCH_CRITERIA, '')))
	{
		var mywidth=500	
		var myheight=450	
		newwindow = window.open('findfile.aspx?pattern=' + escapeplus(r), null, 'menubar=yes, toolbar=yes, location=no, status=no, resizable=yes, scrollbars=yes, width=' + mywidth + ' , height=' + myheight + ', left=' + (screen.width-mywidth)/2 + ', top=' + (screen.height-myheight)/2);
		newwindow.focus();
	}
}

function AdvProperties(index)
{
	var filename=window.parent.List.document.form["i"+ index ].value
	var mywidth=500	
	var myheight=450	
	newwindow = window.open('AddProperties.aspx?fileorfolder=' + escapeplus(filename), null, 'menubar=yes, toolbar=yes, location=no, status=no, resizable=yes, scrollbars=yes, width=' + mywidth + ' , height=' + myheight + ', left=' + (screen.width-mywidth)/2 + ', top=' + (screen.height-myheight)/2);
	newwindow.focus();

}

/*
function sendviamail()
{
	var r;
	var f="";
	var i;
	var k=0;
	var wasfolder=0;
	for(i=0; i <= window.parent.List.Items ; i++)
		if (window.parent.List.document.form["id"+ i ].value=='1')
		{
			k=k+1;
			if(i<=window.parent.List.folders)
				wasfolder=1;
		}

		if(k==0)
			window.alert(SELECT_AT_LEAST_ONE_ITEM)
		else
  		{
			if(wasfolder==1)
				window.alert(CAN_SEND_ONLY_FILES)
			else
			{
				if((r=window.prompt('Send the selected files by email', email)))
				{
					if(r!=null) email=r
					window.parent.List.document.form.to.value=r
					window.parent.List.document.form.action="sendviamail.aspx"
					window.parent.List.document.form.submit()
				}
			}

		}
		
}*/

function makezip()
{
	var r=""
	if((r=window.prompt(ENTER_NEW_ZIP_NAME, "New zip.zip")))
		if(isfilefoldercorrect(r))
		{
			window.parent.List.document.form.zipname.value=r
			window.parent.List.document.form.action="createnewzip.aspx"
			window.parent.List.document.form.submit()
		}
		else
			window.alert(NAME_CANNOT_CONTAIN);
}

function addDRAGtozip()
{
  	if(window.parent.List.DragDropTargetSelectedIndex!=-1)
  	{
  		window.parent.List.document.form.zipname.value=window.parent.List.document.form["i" + window.parent.List.DragDropTargetSelectedIndex].value
		window.parent.List.document.form.action="addtozip.aspx?createnewzip=true"
		window.parent.List.document.form.submit()
	}	
}


function addnewzip()
{
	var IndArray=window.parent.List.SelectedInd.split(";")
	var r=""
	if((r=window.prompt(ENTER_NEW_OR_EXISTING_ZIP_NAME, "New zip.zip")))
	{
		if(isfilefoldercorrect(r))
		{
			if(IndArray.length<3)
				window.alert(SELECT_AT_LEAST_ONE_ITEM)
			else
  			{
  				window.parent.List.document.form.zipname.value=r
				window.parent.List.document.form.action="addtozip.aspx?createnewzip=true"
				window.parent.List.document.form.submit()
			}
		}
		else
			window.alert(NAME_CANNOT_CONTAIN);
	}			
	
}

function addzip()
{
	var IndArray=window.parent.List.SelectedInd.split(";")
	if(!window.parent.List.zip)
		window.alert(SHOULD_HAVE_ZIP)
	else
	{
		if(IndArray.length<3)
			window.alert(SELECT_AT_LEAST_ONE_ITEM)
		else
  		{
			window.parent.List.document.form.action="addtozip.aspx"
			window.parent.List.document.form.submit()
		}
	}
}

function extractzip()
{
	var IndArray=window.parent.List.SelectedInd.split(";")
	if(IndArray.length<3)
		window.alert(SELECT_ZIP)
	else if(IndArray.length>3)
		window.alert(SELECT_ONLY_ONE_ITEM)
	else if(Ext(window.parent.List.document.form["i" + IndArray[1]].value)!="ZIP")
		window.alert(SELECT_WITH_ZIP_EXT)
	else
	{	
		var s=new String(window.parent.List.document.form["i" + IndArray[1]].value);
		var n=s.lastIndexOf('.')
		s=s.substring(0,n)

		if((r=window.prompt(EXTRACT_TO, CurrentPath + s)))
		{
				window.parent.List.document.form.zipname.value=window.parent.List.document.form["i" + IndArray[1]].value
				window.parent.List.document.form.newfoldername.value=r
				window.parent.List.document.form.action="extractzip.aspx"
				window.parent.List.document.form.submit()
		}
	}
}

function viewcontent()
{
	var IndArray=window.parent.List.SelectedInd.split(";")	
	if(IndArray.length<3)
		window.alert(SELECT_ZIP)
	else if(IndArray.length>3)
		window.alert(SELECT_ONLY_ONE_ITEM)
	else if(Ext(window.parent.List.document.form["i" + IndArray[1]].value)!="ZIP")
		window.alert(SELECT_WITH_ZIP_EXT)
	else
	{
		
		var mywidth=500	
		var myheight=450	
		newwindow = window.open('viewzipcontent.aspx?content=' + escapeplus(window.parent.List.document.form["i" + IndArray[1]].value), null, 'menubar=yes, toolbar=yes, location=no, status=no, resizable=yes, scrollbars=yes, width=' + mywidth + ' , height=' + myheight + ', left=' + (screen.width-mywidth)/2 + ', top=' + (screen.height-myheight)/2);
		newwindow.focus();	
	}
}

function fresh()
{
	window.parent.List.location.href="List.aspx?task=nothing" 	
}

function selectall()
{
	var i=0;
	window.parent.List.SelectedInd=";"
	for(i=0; i<=window.parent.List.Items; i++)
	{
		window.parent.List.document.form["id" + i].value='1';
		window.parent.List.Paint(i);
		window.parent.List.SelectedInd= window.parent.List.SelectedInd + i + ";"
	}
	window.parent.List.lastMouseSelected=window.parent.List.Items;
	window.parent.List.continualGray();
}

function InvertSelection()
{
		var i=0;
		window.parent.List.SelectedInd=";"
		window.parent.List.lastMouseSelected=-1;
		for(i=0; i<=window.parent.List.Items;i++)
		{				
			if(window.parent.List.document.form["id" + i].value=='1')
			{
				window.parent.List.Clear(i);	
				window.parent.List.document.form["id" + i].value='0'; 
			}
			else
			{
					window.parent.List.document.form["id" + i].value='1';
					window.parent.List.Paint(i);
					window.parent.List.SelectedInd= window.parent.List.SelectedInd + i + ";"
					window.parent.List.lastMouseSelected=i;
			}
			
		}		
		window.parent.List.continualGray();
}

function open_themes()
{
		var mywidth=500	
		var myheight=450	
		newwindow = window.open('Themes.aspx', null, 'menubar=yes, toolbar=yes, location=no, status=no, resizable=yes, scrollbars=yes, width=' + mywidth + ' , height=' + myheight + ', left=' + (screen.width-mywidth)/2 + ', top=' + (screen.height-myheight)/2);
		newwindow.focus();	
}

function help()
{
	var mywidth=650		
	var myheight=450	
    newwindow = window.open('Languages/' + escapeplus(HelpFile) + '.htm', null, 'menubar=yes, toolbar=yes, location=no, status=no, resizable=yes, scrollbars=yes, width=' + mywidth + ' , height=' + myheight + ', left=' + (screen.width-mywidth)/2 + ', top=' + (screen.height-myheight)/2);
    newwindow.focus();
}

function logoff()
{
	logoffclick = true;
	if(window.parent.topFrame.newwindow)
	{
		/*if(window.parent.topFrame.newwindow.location)
			window.parent.topFrame.newwindow.location.href='logoff.aspx?dontclose=yes';	*/
		window.parent.topFrame.newwindow.close();	
		
	}
	window.parent.location.href="logoff.aspx"  
}

function SelectZIP()
{
	var IndArray=window.parent.List.SelectedInd.split(";")	
	window.parent.List.document.form.zipname.value=window.parent.List.document.form["i" + IndArray[1]].value
	window.parent.List.document.form.action="createnewzip.aspx?select=true"
	window.parent.List.document.form.submit()
}

function open_dir(index)
{
	window.parent.List.document.form.index.value=index
	window.parent.List.document.form.action="list.aspx"
	window.parent.List.document.form.submit()
}

function open_editor(index) 
{
	var mywidth=650		
	var myheight=520
	var filename=window.parent.List.document.form["i"+ index ].value
	newwindow = window.open('EditFile.aspx?file=' + escapeplus(filename), 'editwin','status=no, menubar=yes, resizable=yes, scrollbars=yes, toolbar=yes, location=no, width=' + mywidth + ' , height=' + myheight + ', left=' + (screen.width-mywidth)/2 + ', top=' + (screen.height-myheight)/2 );
	newwindow.focus();
}

function ftpdownload()
{
	var IndArray=window.parent.List.SelectedInd.split(";")
	if(IndArray.length<3)
		window.alert(SELECT_AT_LEAST_ONE_ITEM)
	else
	{
		window.parent.List.document.form.action="ftpdownload.aspx"
		window.parent.List.document.form.submit()
	}
}


function open_download(index, isview)
{
	var filename=window.parent.List.document.form["i"+ index ].value
	var mywidth=500
	var myheight=450
	if (dd==true)
	{
		if (rbs==true)
		{
			newwindow=window.open(vp + replace(window.parent.List.FilePath, '\\', '/') + filename )
			newwindow.focus();	
		}
		else
		{
			newwindow=window.open(vp + window.parent.List.FilePath + filename)
			newwindow.focus();	
		}		
	}
	else
	{
		if(isview==true)
		{
			newwindow=window.open('getfile.aspx?view=true&file=' + escapeplus(filename)  , 'viewwin','menubar=yes, status=no, resizable=yes, scrollbars=yes, toolbar=yes, location=no, fullscreen=no, width=' + mywidth + ' , height=' + myheight + ', left=' + (screen.width-mywidth)/2 + ', top=' + (screen.height-myheight)/2);
			newwindow.focus();		
		}
		else
		{
			newwindow=window.open('getfile.aspx?file=' + escapeplus(filename))
			newwindow.focus();
		}
	}
}

function open_download2(filename)
{
	if (dd==true)
	{
		if (rbs==true)
		{
			newwindow=window.open(vp + replace(filename, '\\', '/'))
			newwindow.focus();	
		}
		else
		{
			newwindow=window.open(vp + filename)
			newwindow.focus();	
		}		
	}
	else
	{
		newwindow=window.open('getfile.aspx?fullpath=' + escapeplus(filename))
		newwindow.focus();
	}
}

function mygoto(path)
{
	window.parent.List.document.form.fullpath.value=path
	window.parent.List.document.form.action="goto.aspx"
	window.parent.List.document.form.submit()
}