//Upload%JS_CSS_VERSION%.js file used in right frame. Includes Java Script functions 
//for all needed features in right frame. 
//Before modify something here see  JS_CSS_VERSION element in HTCOMNET\web.config file!!!

var showprogressbar=true; //=false;
var uplfiles=1;
function addfile()
{
	var i=-1;
	var seted=0;
	for(i=1; i<=uplfiles; i++) 
	{
		if(eval("document.myform.file" + i + ".value")!='')
			seted+=1;
	}
	if(uplfiles==seted)
	{
		var mydiv=document.getElementById('files')
		uplfiles++;
		var inp;
		inp = document.createElement('span');
		inp.innerHTML = '<span><br><br>&nbsp;&nbsp;<input onFocus="javascript: if(ie50)addfile();" onChange="javascript: addfile()" class="file" type="file" name="file' + uplfiles + '" id="file' + uplfiles + '" style="width:440;"></span>';
		mydiv.appendChild(inp);
	}
}

function RadioClick(RadItem, PropName)
{
	document.getElementById('inp_' + PropName).value=document.getElementById(RadItem).value
}

function ComboChange(PropName)
{
	var selectedIndex = document.getElementById('inp_' + PropName + 'lst').selectedIndex
	document.getElementById('inp_' + PropName).value=document.getElementById('inp_' + PropName + 'lst').options[selectedIndex].text
}


function doupload(ext, systemupl) 
{
	var i=0;
	var k=0;
	var cont=true;	
	var m=1;
	for(m=1; m<=uplfiles; m++) 
	{
		if(i==0) i=(scanforext(ext, eval("document.myform.file" + m + ".value"))==0)?i:1;
	}
	for(m=1; m<=uplfiles; m++) 
	{
		k=scanforfiles(eval("document.myform.file" + m + ".value"))
		if(k==1)
		{
			cont=false;
			break;
		}
		
	}
	if(i==0 && cont==true)
	{
		theUniqueID = (new Date()).getTime() % 1000000000;
			
		var mywidth=470
		var myheight=160
				
		if(showprogressbar && !systemupl)
		{
			window.opener.parent.topFrame.progressbarwindow=window.open("progressbar.aspx?guid=" + theUniqueID, 'progwin','menubar=no, status=no, resizable=no, scrollbars=no, toolbar=no, location=no, fullscreen=no, width=' + mywidth + ' , height=' + myheight + ', left=' + (screen.width-mywidth)/2 + ', top=' + (screen.height-myheight)/2);
			window.opener.parent.topFrame.progressbarwindow.focus();
		}
		document.myform.action = "netupload.aspx?guid=" + theUniqueID				
		document.myform.submit();

	}
}

function showftpwindow(address)
{
	var mywidth=600
	var myheight=400
	window.opener.parent.topFrame.ftpwindow=window.open(address, '','menubar=yes, toolbar=yes, location=yes, status=yes, resizable=yes, scrollbars=yes, width=' + mywidth + ' , height=' + myheight + ', left=' + (screen.width-mywidth)/2 + ', top=' + (screen.height-myheight)/2);
}

function ftpdoupload() 
{
	document.myform.action = "FTPUpload.aspx" ; 				
	document.myform.submit();
}

function scanforext(ext, file)
{
	var i
	var myext=Ext(file); 
	var str=new String(file);
	var ar=ext.toUpperCase().split(";")
	for(i=0; i<=ar.length-1; i++)
	{
		if(ar[i]!="" && myext==ar[i])
		{	
			window.alert(strFormat(FILE_WITH_EXT_CANT_UPLOADED, FileName(file), myext));
			return(1);
		}
	}
	return(0);
}
function scanforfiles(file)
{
	var i=0
	var myfile=""
	var strtemp=""
	myfile=FileName(file).toUpperCase() 
	for(i=0; i <= window.opener.parent.List.Items ; i++)
	{	strtemp=eval("window.opener.parent.List.document.form.i"+ i + ".value").toUpperCase(); 
		if(strtemp==myfile)
		{	
			if(window.opener.parent.topFrame.CanWrite==false)
			{
				window.alert(strFormat(FILE_ALREADY_EXISTS, FileName(file)));
				return 1;
			}
			if(window.opener.parent.List.Attributes[i] & ATTR_READ_ONLY)
			{
				if(window.opener.parent.topFrame.CanSetAttrib)
				{
					if(window.confirm(strFormat(UPLOAD_READ_ONLY, FileName(file))))
						return 0
					else
						return 1;
				}
				else
				{
					window.alert(strFormat(CANT_UPLOAD_READ_ONLY, FileName(file)))	
					return 1;
				}				
			} 			
			if(window.confirm(SOME_FILES_EXISTS))
				return 0
			else
				return 1;
			break;
		}

	} 
	return 0;
}

function drawprogressinfo(imgnums, minleft, secleft, bytedone, bytetotal, bytepersec)
{
	var s;
	var img='';
	var i;
	//for(i=0; i<=imgnums; i++)
	//	img= img + '<img width="8" height="13" src="images/bar_bit.gif">';
	
	s='<b><BR><font color="#000000" size="2" face="Arial, Helvetica, sans-serif">&nbsp;&nbsp;&nbsp;' + PROGRESS_PLEASE_WAIT + '</font></b><br><br>'
	s=s+ '<p style="margin-left:15px;height:20px;width:410px;" class="progress"><table height="20" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="' + 8*imgnums + '" background="images/bar_bit.gif">&nbsp;</td><td>&nbsp;</td></tr></table></p>'	
	s=s+ '<table border="0" width="100%" cellspacing="0" cellpadding="0">' +
	'<tr><td width="20"></td><td width="126"><font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:10px;">' + PROGRESS_TIME_LEFT + ':</font></td><td width="390"><font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:10px;" color="#000000">' + 
	minleft + ' ' + PROGRESS_MIN + ' ' + secleft + ' ' + PROGRESS_SECS + ' (' + bytedone + ' KB ' + PROGRESS_OF + ' ' + bytetotal + 
	'</font><font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:10px;"> KB' + 
	' ' + PROGRESS_UPLOADED + '</font><font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:10px;" color="#000000">)' +
	'</font></td></tr><tr><td width="20">&nbsp;</td><td width="126"><font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:10px;" color="#000000">' + 
	'</font><font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:10px;">' + PROGRESS_TRANSFER_RATE + ':</font></td>' +
	'<td width="390"><font face="Verdana, Arial, Helvetica, sans-serif" style="font-size:10px;" color="#000000">' + 
	bytepersec + ' ' + PROGRESS_KB_SEC + '</font> </td></tr></table>';
	return s;
}


var vZIPlastSelected=0;
var vZIPItems=0;
var SelectedInd=';';
var MouseSelection=false;
var lastMouseSelected=-1;
	
function extractcontent()
{
	var i;
	var k=0;
	for ( i=1; i<= vZIPItems; i++)
		if (document.zipform["h" + i].value=='1')
		{
			document.zipform.submit();
			k=1;
			break;
		}
	if (k==0)
		window.alert(SELECT_AT_LEAST_ONE_ITEM);
}

function deletecontent()
{
	var i;
	var k=0;
	for ( i=1; i<= vZIPItems; i++)
		if (document.zipform["h" + i].value=='1')
		{
			if(window.confirm(DELETE_ITEMS_ZIP))
			{
				document.zipform.action="extractcontent.aspx?delete=true"
				document.zipform.submit();
			}
			k=1;
			break;
		}
	if (k==0)
		window.alert(SELECT_AT_LEAST_ONE_ITEM);
		
}


function zipselectall()
{
	SelectedInd=';'
	for ( i=1; i<= vZIPItems; i++)
	{
		Paint(i)
		document.zipform["h" + i].value='1';
		SelectedInd= SelectedInd + i + ";"		
	}
	checkit()
}

function checkit()
{
	if(SelectedInd!=";")
	{
		document.getElementById("extractbut").disabled=false;
		document.getElementById("deletebut").disabled=false;
	}
	else
	{
		document.getElementById("extractbut").disabled=true;
		document.getElementById("deletebut").disabled=true;
	}
}

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

function Paint(index)
{
	document.getElementById("row" + index).style.background= "#99ccff";
}

function Clear(index)
{
	document.getElementById("row" + index).style.background= "#F8F6E6";
}

function SelectRow(index)
{ 
	if(MouseSelection)
	{
		if(lastMouseSelected==-1)
		{
			Paint(index)
			document.zipform["h" + index].value='1';
			SelectedInd= SelectedInd + index + ";"
			lastMouseSelected=index	
			return;
		}
		var i;
		var k=index>lastMouseSelected?1:-1;
		for(i=lastMouseSelected; (k==1)?i<=index:i>=index; i+=k)
		{
			if(SelectedInd.lastIndexOf(";"+i+";")==-1)
			{
				Paint(i)
				document.zipform["h" + i].value='1';
				SelectedInd= SelectedInd + i + ";"
			}
		
		}
		lastMouseSelected=index	
		checkit()
	}
}

function vZIPSelect(theRow, Ev)
{

	var i;
	if(!Ev.ctrlKey && !Ev.shiftKey) 
	{
		ZipHideAll()
		Paint(theRow)
		document.zipform["h" + theRow].value='1';
		SelectedInd=";" + theRow + ";";
		vZIPlastSelected=theRow;
	}
	else if (Ev.shiftKey)
	{
		ZipHideAll()
	 	var k=theRow>vZIPlastSelected?1:-1;
		for(i=vZIPlastSelected; (k==1)?i<=theRow:i>=theRow; i+=k)
		{
			Paint(i)
			document.zipform["h" + i].value='1';
			SelectedInd= SelectedInd + i + ";"
			
		}
	}
	else if (Ev.ctrlKey)
	{
		if (document.zipform["h" + theRow].value=='0')
		{
			Paint(theRow)
			document.zipform["h" + theRow].value='1';
			SelectedInd= SelectedInd + theRow + ";"
		}
		else
		{
			Clear(theRow)
			document.zipform["h" + theRow].value='0'; 
			SelectedInd= SelectedInd.replace(";" + theRow + ";", ";"); 
		}
		vZIPlastSelected=theRow;
	}
	checkit()
}

function It(index, filename, size, ratio, isfolder)
{
	var s=new String();
	var Ev=GetEventStr();
	s=s+'<tr onMouseOver="SelectRow(' + index + ')" clAss="" id="row' + index + '" onMouseDown="vZIPSelect(' + index + ', ' + Ev + ');">'  
	s=s+'<td id=td0i' + index + ' align="right" width="30">'
	if(isfolder)
		s=s+'<img src="images/foldercol.gif" width="24" height="22"></td><td id=td1i' + index + '><input name="h' + index + '" type="hidden" value="0"><font style="font-family: Arial, Helvetica, sans-serif; font-size: 12px;font-weight: bold;" clAss="list" color="#333399">' + filename + '</font>'
	else
		s=s + '&nbsp\;</td><td id=td1i' + index + '><input name="h' + index + '" type="hidden" value="0"><font style="font-family: Arial, Helvetica, sans-serif; font-size: 12px;font-weight: bold;"  clAss="list" color="#333399">' + Path(filename) + '</font><font clAss="list" size="2" color="#291C18"> ' + FileName(filename) + '</font>' ;	
	
	s=s + '</td><td id=td2i' + index + ' align="right" width="50"><font color="#CC3333" clAss="list" size="1" face="Arial">' + size + '</font></td>'
	s=s + '<td id=td3i' + index + ' align="center" width="50"><font color="#333399" clAss="list" size="1" face="Arial">' + ratio + '%</font></td>'
	s=s + '</font></tr>'
	document.write(s);
}

function afs(path, filename)
{
	var s=new String();
	s=s+ '&nbsp;&nbsp;<a alt="' + strFormat(OPEN_THIS_FOLDER, path) + '" title="' + strFormat(OPEN_THIS_FOLDER, path) + '" href="javascript: window.opener.parent.topFrame.mygoto(\'' + JavaFormat(path) + '\')"><font title="' + strFormat(OPEN_THIS_FOLDER, path) + '" color="#333399">' + path + '</font></a><font clAss="list" color="#291C18">' +  filename + '</font> <a title="' + strFormat(GET_ALT, filename) + '" href="javascript: window.opener.parent.topFrame.open_download2(\'' + JavaFormat(path+filename) + '\')"><font size="1" color="#3242DF">' + GET + '</font></a><br>';
	document.write(s);
}