
var UploaderScriptUrl='/cgi-bin/uploader/uploader1.cgi';

var MaxFilesToShowInSibgleFolder=500;

var IE     = (document.all)?1:0;

var selectedtextareaID = "";
var hideCnt = 0;
var selectedFolder=0;
var encryptedfiles=new Array();
var tagslist=new Array();
var clipboardfiles=new Array();

var commandbuffer='';

var MyID=0;
var MyEmailBackupsRoot=0;
var sharedforme = new Array();
var sharedbyme = new Array();
var map_gruser_node = new Array();
var emailaccounts=new Array();
var groups_additional_tree = '';
var sharedidinmediatree=0;
var sharedfoldersidinmediatree=0;

var limitlonglists='1';
var currentfilterinfo=0;

var providers=new Array();
var filessearches=new Array();

var countfilestoupload=1;
var rs_uploadingfilenumber=0;

//DEBUG
function clearDebugLogs(){
	
	//if(document.getElementById("debugarea") && document.getElementById("debugarea")!==undefined)
	//	document.getElementById("debugarea").innerHTML='';
}

function addDebugLog(log){
	
	//if(document.getElementById("debugarea") && document.getElementById("debugarea")!==undefined){
	//	document.getElementById("debugarea").innerHTML=log+'\n\n'+document.getElementById("debugarea").innerHTML;
	//}
}


//login form  validator
function loginCheck(f1,f2) {
    re = /[a-z0-9]+/i;
   if(document.getElementById("us_login").value.search(re) < 0) {
          alert("Please enter Login");
	      document.getElementById("us_login").focus();
          return false;
   }
   if (document.getElementById("us_pwd").value == "") {
       alert("Please enter Password");
       document.getElementById("us_pwd").focus();
       return (false);
   }
}

//forgot login form  validator
function forgotCheck() {
   eml = /^\s*([a-z0-9])(([\-\.]|[_]+)?([a-z0-9]+))*@([a-z0-9])((([-]+)?([a-z0-9]+))?)*(\.[a-z]{2,3})?\.[a-z]{2,6}\s*$/i;

   if(document.getElementById("us_email").value.search(eml) < 0) {

               alert("Please enter valid email.");
	          document.getElementById("us_email").focus();
            return false;
   }

}


//delete  any object confirmation function
function delete_record(){
 return confirm("Are you sure???");
}

//submit  hidden form, is  using  to hide  data  from simple  user (systen using POST instead of GET)
function goForm(act,oid) {
  document.getElementById("goform").action = act;
  document.getElementById("objID").value = oid;
  document.getElementById("goform").submit();
}


// check all checkboxes
function checkAll(name,name2) {
        dml=document.messageList;
        val=document.getElementById(name2).checked;
        len = dml.elements.length;
        var i=0;
        for( i=0 ; i<len ; i++) {
       // alert(dml.elements[i].name);

                if (dml.elements[i].name==name) {
                        dml.elements[i].checked=val;
                }
        }
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


 //registration of  new  user form validator
/* 
function regNewUser() {
    re = /[a-z0-9]+/i;

   if(document.getElementById("us_name").value.search(re) < 0)
    {
            alert("Please enter Full Name");
            document.getElementById("us_name").focus();
            return false;
    }

    if(document.getElementById("us_login").value.search(re) < 0)
    {
            alert("Please enter Login");
            document.getElementById("us_login").focus();
            return false;
    }

   if(document.getElementById("us_pwd").value.search(re) < 0)
    {
            alert("Please enter Password");
            document.getElementById("us_pwd").focus();
            return false;
    }

   if(document.getElementById("us_pwd").value != document.getElementById("us_pwd2").value)
    {
            alert("'Password'  and  'Retype Password'  values are not same.");
            document.getElementById("us_pwd2").focus();
            return false;
    }

    eml = /^\s*([a-z0-9])(([\-\.]|[_]+)?([a-z0-9]+))*@([a-z0-9])((([-]+)?([a-z0-9]+))?)*(\.[a-z]{2,3})?\.[a-z]{2,6}\s*$/i;
    if(document.getElementById("us_email").value.search(eml) < 0)
    {
            alert("Please enter valid eMail.");
            document.getElementById("us_email").focus();
            return false;
    }

    var ch = false;
    if (typeof(document.mainform.us_slevel.length) != 'undefined' ) {
       for (i=0; i<document.mainform.us_slevel.length; i++) {
       	    if (!ch) ch = document.mainform.us_slevel[i].checked;
       }
    } else {
       ch = document.getElementById("us_slevel").checked;
    }
    if (!ch)
    {
            alert("Please select any package");
            document.getElementById("us_slevel").focus();
            return false;
    }

    if(document.getElementById("key").value.search(re) < 0)
    {
            alert("Please enter Validation Code");
            document.getElementById("key").focus();
            return false;
    }


}
*/

function upgradeSubmit() {
    var ch = false;
     if (typeof(document.mainform.us_slevel.length) != 'undefined' ) {
       for (i=0; i<document.mainform.us_slevel.length; i++) {
       	    if (!ch) ch = document.mainform.us_slevel[i].checked;
       }
    } else {
       ch = document.getElementById("us_slevel").checked;
    }
    if (!ch)
    {
            alert("Please select any package");
            document.getElementById("us_slevel").focus();
            return false;
    }
}

 //package edit form validator
function packageSubmit() {


    re = /[a-z0-9]+/i;
   if(document.getElementById("pa_name").value.search(re) < 0)
    {
            alert("Please enter Name");
            document.getElementById("pa_name").focus();
            return false;
    }
     de = /^\d+$/i;

   if(document.getElementById("pa_size").value.search(de) < 0)
    {
            alert("Please enter valid Size Limit (integer)");
            document.getElementById("pa_size").focus();
            return false;
    }

   de = /^[\.\,\d]+$/i;


    if(document.getElementById("pa_price").value.search(de) < 0)
    {
            alert("Please enter valid Price");
            document.getElementById("pa_price").focus();
            return false;
    }



}


function getAllForUser() {

   showLoadScreen();
   document.goform.action ='index.php?ajaxfunction=executeAPI&function=getAllForUser&limitlonglists='+limitlonglists;

   AIM.submit(document.goform, aim_c);
}

function refreshTree(){
	var selectedNode=media_tree.selectedNode;
	getAllForUser();
	selectDir(media_tree, selectedNode);
}

function showAllForUser(result){
	MyEmailBackupsRoot=result.rootid;
	//providers
	providers=result.providers;

	if(result.filescount==0 && result.filterinfo.tomachfiles==1){
		currentfilterinfo=result.filterinfo;
		closeModalDialog();
		  
		var html='<p align="center">You have too many files in your account to be displayed at one time in the Cloud File Manager.<br>';
		html+='We recommend you set a filter on your files otherwise the Cloud File Manager may not load.<br> ';
		html+='Note you can also use the <a href="/index.php?p=textcatlist">HTML File Manager</a> which will not require a filter.</p><br>';
		html+='<center><input type="button" value="Set filter" onclick="closeModalDialog();editFilesFilter(2);" >';
		html+='<input type="button" value="No. I do not need filter." onclick="doMissFilter();" style="margin-left:10px;" ></center>';
		messageObj.setHtmlContent(html);
		messageObj.setSize(300, 150);
		messageObj.setSource(false);
		messageObj.setShadowDivVisible(true);
		messageObj.display();
		return;
	}


	sharedidinmediatree=result.maxid+1000;
	sharedfoldersidinmediatree=result.maxid+5000;
	
	
	showFilesList(result,1);
	tagslist=result.tagslist.split(',');
	
	setUpSearches(result.filessearches);
	
	recentlyusedfiles=result.lastfilelist;
	showLastUsedFiles();
	
	if(result.clipboardstatus=='ok' && result.clipboardfilescount>0) {
		clipboardfiles=result.clipboardfiles;
	}else
		clipboardfiles=new Array();

	if(curuserlevel>=pop3toollevel) showEmailAccounts(result);
	if(curuserlevel>=groupstoollevel) 
	{
		showGroupsList(result);

		showAllShared(result);

	}
	if(curuserlevel>=trashtoollevel) showTrash(result);

	var str   =  media_tree.toString();
	//alert(str.length);
	//document.getElementById('logtextarea2').value=str;
   	document.getElementById('treepanel').innerHTML = new String(str);
	//alert(document.getElementById('treepanel').innerHTML.length);
	//document.getElementById('logtextarea').value=document.getElementById('treepanel').innerHTML;

	if(curuserlevel>=groupstoollevel) 
	{
	str   =  groups_tree.toString();
	document.getElementById('groupstree').innerHTML = str;
	}

	

	closeModalDialog();
	if(result.filterinfo.tomachfilteredfiles==1 && result.filterinfo.isfilter==1 && limitlonglists==1){
		alert('Your files are filtered but there are still too many of files for comfortable work. You can work with your files now but we recommend to try another filter.');
	}
}

function trim(string)
{
return string.replace(/(^\s+)|(\s+$)/g, "");
}

function showHideDIV(dname,st,r){
	document.getElementById(dname).style.display=(st==1)?'block':'none';
	document.getElementById(dname+'show').style.display=(st==1)?'none':'block';
	if(r) messageObj.__resizeDivs();
}

function getCorrectFileSize(bytes,misstbd){

	if(bytes<=0 && misstbd!=1) return 't.b.d.';
	
	if(bytes>4096 && bytes<1024*1024){
		bytes=Math.round(bytes/(1024)*100)/100;//kBytes
		bytes+=' Kb';
	}else if(bytes>=1024*1024){
		bytes=Math.round(bytes/(1024*1024)*100)/100;//kBytes
		bytes+=' Mb';
	}else if(bytes<=4096){
		bytes+=' b';
	}
	return bytes;
}

function getTimeBySeconds(sec){

		var hour=0;
		var minutes=0;
		if(sec>=60){
			minutes=Math.floor(sec/60);
			sec=sec-minutes*60;
		}

		if(minutes>=60){
			hour=Math.floor(minutes/60);
			minutes=minutes-hour*60;
		}
	
		var time=hour+':';
		if(minutes<10)
			minutes='0'+minutes;
		time+=minutes+':';
		if(sec<10)
			sec='0'+sec;
		time+=sec;
		return time;

}

function getSelectedFilesIds(file_id,f){
	var ids=new Array();
	//shareingrules.push(result.rule);
	if(file_id=='clipboard'){
		ids=clipboardfiles;
	}else{
		ids.push(file_id);
		//check additional selected files
		if(f!==undefined && f.dirfilelist!==undefined){
			for(i=0;i<f.dirfilelist.length;i++){
				if(f.dirfilelist[i].checked && f.dirfilelist[i].value!=file_id){
					ids.push(f.dirfilelist[i].value);
				}
			}
		}
	}
	
	return ids;
}
function getFilesNamesList(ids){
	var names='';
	for(i=0;i<ids.length;i++){
		if(names!='') names+=', ';
		var fl       = media_tree.getFile(ids[i]);
		names+=fl.name;
	}
	
	return names;
}

function getFilesTotalSize(ids,provider){
	var size=0;
	for(i=0;i<ids.length;i++){
		var fl       = media_tree.getFile(ids[i]);
		if(provider==-1 || provider>-1 && provider!=fl.subobject.provider)
			size-=-fl.size;
	}
	
	return size;
}

function getFilesProviders(ids,provider){
	var providers='';
	var added=',';
	for(i=0;i<ids.length;i++){
		var fl       = media_tree.getFile(ids[i]);
		if(provider==-1 || provider>-1 && provider!=fl.subobject.provider && added.indexOf(','+fl.subobject.provider+',')==-1){
			if(providers!='') providers+=', ';
			var ptitle=getProviderTitle(fl.subobject.provider);
			providers+=ptitle;
			added+=fl.subobject.provider+',';
		}
	}
	
	return providers;
}

function getFilesProvidersCodes(ids,provider){
	var providers='';
	var added=',';
	for(i=0;i<ids.length;i++){
		var fl       = media_tree.getFile(ids[i]);
		if(provider==-1 || provider>-1 && provider!=fl.subobject.provider && added.indexOf(','+fl.subobject.provider+',')==-1){
			if(providers!='') providers+=',';
			var ptitle=getProviderCode(fl.subobject.provider);
			providers+=ptitle;
			added+=fl.subobject.provider+',';
		}
	}
	
	return providers;
}

function getProviderTitle(provider){
	var title='';
	for(var j=0;j<providers.usedcount;j++){
		var pi=providers.used[j];
		if(pi.pi_id==provider){
			title = pi.pr_name;
			if(pi.pi_id>0) title+=' ('+pi.pi_login+')';
			break;
		}
	}
	return title;
}
function getProviderCode(provider){
	var code='';
	for(var j=0;j<providers.usedcount;j++){
		var pi=providers.used[j];
		if(pi.pi_id==provider){
			code = pi.pr_code;
			break;
		}
	}
	return code;
}
// --------------------------------   email file   -------------------------------------------

function fileEmail(file_id,f) {
	var ids=getSelectedFilesIds(file_id,f);
	var filenames=getFilesNamesList(ids);


	messageObj.setHtmlContent('<table height="100%" width="100%" ><tr><td>Email links for files: <i><b>'+filenames+'</b></i></td></tr>'+
		'<tr><td align="center" valign="middle">'+
		'<table bgcolor="white"><tr><tr><td><b>Time to Expire</b> <small>(in days, zero for  no expire link):</small></td>'+
		'<td><input name="days" id="days" type="text" size="2" value="0" /></td></tr>'+
		//'<tr><td><b>Friend Email:</b></td><td>'+getContactsArea('<input name="friend_email" id="friend_email" type="text" value="" />')+'</td></tr>'+
		'<tr><td><b>Friend Email:<br><sub>Or start to type name from contacts</sub></b></td><td>'+
		'<input type="hidden" name="friend_email_id" id="friend_email_id" value="">'+
		'<input name="friend_email" id="friend_email" type="text" value="" /></td></tr>'+
		'<tr><td><b>Your name:</b></td><td><input name="from_name" id="from_name" type="text" value="'+currentusername+'" /></td></tr>'+
		'<tr><td><b>Text:</b></td><td><textarea id="text" name="text"></textarea><input type="hidden" name="fileids" id="fileids" value="'+ids.join(',')+'"></td></tr></table></td></tr></table>'+
		'<div class="md_button"><input type="button" value="Send Email" onclick="doSendEmail()" > <input type="button" value="Cancel" onclick="closeModalDialog()" ></div>');
	messageObj.setSize(450, 290);
	messageObj.setSource(false);
	messageObj.setShadowDivVisible(true);
	messageObj.display();
	
	var options = {
		script:"index.php?ajaxfunction=executeAPI&function=doSuggestContacts&rettype=json&",
		varname:"input",
		json:true,
		shownoresults:false,
		callback: function (obj) { document.getElementById('friend_email_id').value = obj.id; }
	};
	var as_json = new bsn.AutoSuggest('friend_email', options);
}

function doSendEmail(f) {
	
	var dtype='email';
	var dval='';
	
	if(document.getElementById('friend_email_id').value==''){
		re = /[a-z0-9]+/i;
		if (document.getElementById("friend_email").value.search(re) < 0){
			alert("Please enter Friend Email");
			document.getElementById("friend_email").focus();
			return false;
		}
		dval=document.getElementById("friend_email").value;
	}else{
		dtype='contacts';
		dval=document.getElementById('friend_email_id').value;
	}

	//get ids
	var filids=document.getElementById("fileids").value;

   document.goform.action ='index.php?ajaxfunction=executeAPI&function=doSendEmail_API&friend_email='+
       URLEncode(dval)+
       "&text="+
       URLEncode(document.getElementById("text").value)+
        "&days="+
       URLEncode(document.getElementById("days").value)+
	"&from_name="+
       URLEncode(document.getElementById("from_name").value)+
       //"&fi_id="+file_object.id;
	"&fi_id="+filids+
	"&emailtype="+dtype;
//prompt('',document.goform.action);
//return;
	closeModalDialog();
	showLoadScreenCustom('Please wait... sending emails');
	AIM.submit(document.goform, aim_c);
}

function showSendEmail(result) {
		
    closeModalDialog();
}

//RomaSoft---
function emailFileHtml(file_id,t) {

	//get ids
	var filenames=document.getElementById("filename"+file_id).value;
	var fileids=file_id;
	var f=document.fileemail;
	var emailids=f.fileids.value.split(',');
	for(i=0;i<emailids.length;i++){
		if(document.getElementById("emailid"+emailids[i]).checked && emailids[i]!=file_id){
			var fl       =document.getElementById("filename"+emailids[i]).value;
			filenames+=', '+fl;
			fileids+=','+emailids[i];
		}
	}

//----end RomaSoft-------

    messageObj.setHtmlContent('<form name="fileemailform" id="fileemailform" method="post" action="'+BASEURL+'index.php?p=textfilelist&action=email" ><INPUT type="hidden" name="type"  id="type"  value="'+t+'"><INPUT type="hidden" name="fi_id"  value="'+fileids+'"><table height="100%" width="100%" ><tr><td>Email links for files: <i><b>'+filenames+'</b></i></td></tr><tr><td align="center" valign="middle"><table bgcolor="white"><tr><tr><td><b>Time to Expire</b> <small>(in days, zero for  no expire link):</small></td><td><input name="days" id="days" type="text" size="2" value="0" /></td></tr><tr><tr><td><b>Friend Email:</b></td><td><input name="friend_email" id="friend_email" type="text" value="" /></td></tr><tr><td><b>Your name:</b></td><td><input name="from_name" id="from_name" type="text" value="" /></td></tr><tr><td><b>Text:</b></td><td><textarea id="text" name="text"></textarea></td></tr></table></td></tr></table><div class="md_button"><input type="submit" value="Send Email"  > <input type="button" value="Cancel" onclick="closeModalDialog()" ></div></form>');
	messageObj.setSize(350, 190);
	messageObj.setSource(false);
	messageObj.setShadowDivVisible(true);
	messageObj.display();
}
//end RomaSoft


//************************************* Util functions ****************************************************

function extendIcon(curicon,add){
	if(curicon==null || curicon===undefined || curicon=='') return 0;
	//find gif in the end
	curicon=curicon.replace(/\.png$/,add+'.png');
	return curicon;
}

function getIcon(node,open) {

	if (node.fi_type == 1) {
		//check if this is some root node
		if(node.fi_structtype=='c' && node.fi_pid==-1){
			return BASEURL+'templates/'+theme+'/nd/images/dtree/base_contacts.gif';
		}
		if(node.fi_structtype=='e' && node.fi_pid==-1){
			return BASEURL+'templates/'+theme+'/nd/images/dtree/base_backups.gif';
		}
		
		if(node.fi_pid==-1){
			return BASEURL+'templates/'+theme+'/images/dtree/base.gif';
		}
		
		var base='folder';
		var icon=(open==1)?'open':'';
		
		if(node.fi_orgid>0 && node.fi_public==2){
			//get parent node to see if this is top level org folder
			base='org';
		}
		
		if(node.fi_structtype=='c'){
			icon+='_c';
		}
		
		if(node.fi_structtype=='e'){
			if(node.fi_pid==MyEmailBackupsRoot)
				base='emailaccount';
			else
				icon+='_e';			
		}
		//check provider and add provider icon
		if(node.fi_provider>0){
			//get provider code
			var pr_item=getProvider(node.fi_provider);
			if(pr_item) {
				icon+='_'+pr_item.pr_code;

			}
		}
		
		return BASEURL+'templates/'+theme+'/images/foldericons/'+base+icon+'.png';
	}

  if (node.fi_extension == "bmp") return BASEURL+'templates/'+theme+'/images/file_icons/bmp.gif';
  if (node.fi_extension == "jpg" || node.fi_extension == "jpeg") return BASEURL+'templates/'+theme+'/images/file_icons/jpg.gif';
  if (node.fi_extension == "gif"  || node.fi_extension == "tif"  || node.fi_extension == "png" ) return BASEURL+'templates/'+theme+'/images/file_icons/gif.gif';
  if (node.fi_extension == "htm") return BASEURL+'templates/'+theme+'/images/file_icons/htm.gif'
  if (node.fi_extension == "html") return BASEURL+'templates/'+theme+'/images/file_icons/html.gif';
  if (node.fi_extension == "txt") return BASEURL+'templates/'+theme+'/images/file_icons/txt.gif';
  if (node.fi_extension == "rar") return BASEURL+'templates/'+theme+'/images/file_icons/rar.gif';
  if (node.fi_extension == "zip") return BASEURL+'templates/'+theme+'/images/file_icons/zip.gif';
  if (node.fi_extension == "pdf") return BASEURL+'templates/'+theme+'/images/file_icons/pdf.gif';
  if (node.fi_extension == "doc") return BASEURL+'templates/'+theme+'/images/file_icons/doc.gif';
  if (node.fi_extension == "ppt") return BASEURL+'templates/'+theme+'/images/file_icons/ppt.gif';
  if (node.fi_extension == "xls") return BASEURL+'templates/'+theme+'/images/file_icons/excel.gif';
//new office format
  if (node.fi_extension == "docx") return BASEURL+'templates/'+theme+'/images/file_icons/doc.gif';
  if (node.fi_extension == "pptx") return BASEURL+'templates/'+theme+'/images/file_icons/ppt.gif';
  if (node.fi_extension == "xlsx") return BASEURL+'templates/'+theme+'/images/file_icons/excel.gif';

  if (node.fi_extension == "csv") return BASEURL+'templates/'+theme+'/images/file_icons/excel.gif';
  if (node.fi_extension == "mp3") return BASEURL+'templates/'+theme+'/images/file_icons/mp3.gif';
  if (node.fi_extension == "wav") return BASEURL+'templates/'+theme+'/images/file_icons/mp3.gif';    

  return BASEURL+'templates/'+theme+'/images/file_icons/default.gif';
}

function getIconOpen(node) {
	if (node.fi_type == 0) return 0;
	return getIcon(node,1);
}

//------------

function getWaitHTML(){
	return '<div class="md_loading"><img src="'+BASEURL+'templates/'+theme+'/images/loading.gif" width="16" height="16" alt="Loading ..." border="0"/> <b>Please wait ... Loading ...</b></div>';
}

function getCustomWaitHTML(text){
	return '<div class="md_loading"><img src="'+BASEURL+'templates/'+theme+'/images/loading.gif" width="16" height="16" alt="Loading ..." border="0"/> <b>'+text+'</b></div>';
}

 function showLoadScreen() {
    messageObj.setHtmlContent(getWaitHTML());
	messageObj.setSize(250, 50);
	//messageObj.setCssClassMessageBox(cssClass);
	messageObj.setSource(false);
	messageObj.setShadowDivVisible(true);
	messageObj.setPlainStyle();
	messageObj.display();
 }

 function showLoadScreenCustom(text) {
    messageObj.setHtmlContent(getCustomWaitHTML(text));
	messageObj.setSize(250, 50);
	//messageObj.setCssClassMessageBox(cssClass);
	messageObj.setSource(false);
	messageObj.setShadowDivVisible(true);
	messageObj.setPlainStyle();
	messageObj.display();
 }


 function closeModalDialog() {
    messageObj.close();
 }

var g_addHiddenClass = ''
 
 function genFileTable(filelist, name) {	
	 var lastname='';

     var str = "<form action='' method='post' id='"+name+"form' name='"+name+"form' ><table width='100%' id='"+name+"' class='sortable'  name='"+name+"'><tr><th class='unsortable first' width='20'>"+
     "</th><th class='unsortable' width='16'><input name='checkuncheckallfiles' id='checkuncheckallfiles' type='checkbox' value='y' onmouseup=\"checkAllFiles(this)\">"+
     "</th><th class='unsortable' width='16'></th><th class='unsortable' width='16'></th><th class='unsortable' width='16'></th><th>Name</th><th id='th_fileCreatedAt' class='centered"+g_addHiddenClass+"'>Created On</th><th class='centered'>Size</th><th class='unsortable' width='80'>Actions</th></tr>";
     if (filelist.length > 0) {
         for (i=0; i < filelist.length; i++) {
		 
              var file_node = filelist[i];
	      if(!file_node || file_node==undefined) {
		      continue;
	      }
	      lastname=file_node.name;
	      //addDebugLog(file_node.name);
		if(file_node.additional==2)
			file_node.id-=sharedfoldersidinmediatree;
               str += '<tr onMouseOver="this.style.backgroundColor =\'#DEEEF1\';"   onMouseOut="this.style.backgroundColor =\'\';" >';
               str += "<td class='cell_first' width='20' nowrap onMouseDown='dragMouseDown("+file_node.id+", event)'  style='cursor: move;'><img src='"+file_node.icon+"'  border='0' /></td><td class='chkbCol'><input name='dirfilelist' id='dirfilelist' type='checkbox' value='"+file_node.id+"'></td>";
		
		var hv=1;//checkViewer(file_node.ext);
		//var hr=(hv==1)?'javascript:showDownloadBox('+file_node.id+');':'file.php?fi_id='+file_node.id;
		var hr='javascript:showDownloadBox('+file_node.id+');';
		//var hr='file.php?fi_id='+file_node.id;
		var targ=(hv==0)?'target=_blank':'';
		
		//encrypted
		str += '<td >';
		if(checkIfFileIsEncrypted(file_node.id)){
			str += '<img alt="Encrypted file" src="'+BASEURL+'templates/'+theme+'/images/key-16x16.png"  border="0"/>';
		}
		str += '</td>';
		//favourite icon
		str += '<td >';
		if(file_node.subobject!==undefined && file_node.subobject.favourite!==undefined ){
			if(file_node.subobject.favourite==1)
				str += '<a href="javascript:makeFavourite('+file_node.id+',0)" title="Remove from favourite"><img alt="unfavourite" src="'+BASEURL+'templates/'+theme+'/images/favourite_icon.gif"  border="0"/></a>';
			else
				str += '<a href="javascript:makeFavourite('+file_node.id+',1)" title="Make favourite"><img alt="favourite" src="'+BASEURL+'templates/'+theme+'/images/unfavourite_icon.gif"  border="0"/></a>';
		}
		str +='</td>'
		
		str += '<td >';
		if(file_node.subobject!==undefined && file_node.subobject.provider!==undefined) str +=getProviderIconSmall(file_node.subobject.provider,file_node.subobject.provideroptions);
		str +='</td>'

			   str += '<td class="cell_fileName"><a href="'+hr+'" id="link_'+file_node.id+'" name="link_'+file_node.id+'" title="'+file_node.title+'" '+targ+' >'+file_node.name+'</a></td>';
		//str += "<td><a href='file.php?fi_id="+file_node.id+"' id='link_"+file_node.id+"' name='link_"+file_node.id+"' title='"+file_node.title+"' target=_blank >"+file_node.name+"</a></td>";
//end romasoft
               str += "<td class='cell_fileCreatedAt"+g_addHiddenClass+"'>"+file_node.created+"</td>";
               str += "<td class='cell_fileSize'> "+getCorrectFileSize(file_node.size)+"</td>";
               str += "<td class='cell_Actions'>";
		var trashrootid=sharedidinmediatree-2;
		if(file_node.additional==0){
               str += ' <a href="javascript:fileEmail('+file_node.id+',document.'+name+'form)" title="email to friend"><img alt="email to friend" src="'+BASEURL+'templates/'+theme+'/nd/images/email.gif"  border="0"/></a>';
               str += ' <a href="javascript:fileRename('+file_node.id+')" title="edit"><img alt="edit" src="'+BASEURL+'templates/'+theme+'/nd/images/edit.gif"  border="0"/></a>';
               str += ' <a href="javascript:fileDelete('+file_node.id+')" title="delete" style="left:-1px;"><img alt="delete" src="'+BASEURL+'templates/'+theme+'/nd/images/del.gif"  border="0"/></a>';
			   if(curuserlevel>=groupstoollevel) 
				{
				//check if file is chared
				hv='share';
				title='Share...';
				//alert(sharedbyme.length);
				for(var j=0;j<sharedbyme.length;j++){
					var sf=sharedbyme[j];
				//	alert(sf.fi_id);
					if(sf.fi_id==file_node.id){
						hv='shared';
						title='Shared';
						break;
					}
				}
				if(file_node.ispublic==1) {
					hv+='_p';
					title='Shared+Public';
					}
				 str += ' <a href="javascript:void(0)" onclick="fileSharing('+file_node.id+')" title="'+title+'"><img alt="share" src="'+BASEURL+'templates/'+theme+'/nd/images/group_icons/'+hv+'.gif"  border="0" style="margin-right:2px;" /></a>';
				}
               
			}
		else if(file_node.additional==4 && file_node.pid==trashrootid){//  
			//trash
//alert(file_node.pid+' and '+trashrootid);
//alert(file_node.pid==trashrootid);
			str += ' <a href="javascript:fileRestoreFromTrash('+file_node.id+')" title="Restore from trash"><img alt="restore" src="'+BASEURL+'templates/'+theme+'/nd/images/restore.gif"  border="0"/></a>';
			str += ' <a href="javascript:fileDeleteFromTrash('+file_node.id+')" title="Delete from trash"><img alt="delete" src="'+BASEURL+'templates/'+theme+'/nd/images/destroy.gif"  border="0"/></a>';
		}else if(file_node.additional==5){//  
			str += ' <a href="javascript:faxFile('+file_node.id+')" title="Fax document"><img alt="fax" src="'+BASEURL+'templates/'+theme+'/images/faxfile.gif"  border="0"/></a>';
			str += ' <a href="javascript:removeFromMyFaxes('+file_node.id+')" title="Delete from fax queue"><img alt="delete" src="'+BASEURL+'templates/'+theme+'/images/del.gif"  border="0"/></a>';
		}

			
		str += "</td></tr>";
		
		var addsecondrow='';
		
		if(file_node.subobject!==undefined && file_node.subobject.creator!==undefined ){
			addsecondrow='<font color="#DDDDDD">By '+file_node.subobject.creator+'</font>';
		}
		
		if(addsecondrow!=''){
			str += "<tr><td><td><td><td></td><td colspan='4'>";
			str += addsecondrow;
			str += "</td></tr>";
		}
         }
     }

     str += "</table></form>";

     return str;
 }

 function checkAllFiles(ch){
	
	function lf() {
		 var f = document.filestableform;
		 var f = document.forms["filestableform"]
		 /*
		 if(f!==undefined && f.dirfilelist!==undefined){
			for(i=0;i<f.dirfilelist.length;i++){
				f.dirfilelist[i].checked=ch;
			}
		}
		*/
		
		 if (f !== undefined) {
			for (i=0; i<f.elements.length; i++){
				var el = f.elements[i]
				if (el.name == "dirfilelist") {
					el.checked = ch.checked
				}
			}
		}
	}
	setTimeout(lf, 50) 
	
	return true
 }
//romasoft
function showDownloadBox(iiiiid,ct){
	
	var id=iiiiid;
	var fext='';
	var fname='';
	var fid='';
	var fcode='';
	var doanloadlink='';
	var isown=0;
	var favourite=0;
	var structtype='g';
	var issplited=false;

	if(ct=='s'){
		for(var i=0;i<sharedforme.length;i++){
			var sf=sharedforme[i];
			if(sf.fi_id==id){
				fext=sf.fi_extension;
				fname=sf.fi_name;
				fid=sf.fi_id;
				ftitle=sf.fi_description;
				fcode=sf.fi_maincode;
				favourite=sf.fi_favourite;
				structtype=sf.fi_structtype;
				issplited=(sf.fi_ispartof>0);
				break;
			}
		}
		if(fid==''){
			for(var i=0;i<sharedbyme.length;i++){
				var sf=sharedbyme[i];
				if(sf.fi_id==id){
					fext=sf.fi_extension;
					fname=sf.fi_name;
					fid=sf.fi_id;
					ftitle=sf.fi_description;
					fcode=sf.fi_maincode;
					favourite=sf.fi_favourite;
					structtype=sf.fi_structtype;
					issplited=(sf.fi_ispartof>0);
					break;
				}
			}
		}
		
		
	}else{	
		var file       = media_tree.getFile(id);

		if(file.additional==1){
			id-=sharedfoldersidinmediatree;
		}	
		fext=file.ext;
		fname=file.name;
		fid=id;
		ftitle=file.title;
		fcode=file.accesscode;
		if(file.subobject!==undefined && file.subobject.favourite!==undefined ) {
			favourite=file.subobject.favourite;
			structtype=file.subobject.structtype;
			issplited=(file.subobject.ispartof>0);
			//alert(file.subobject.ispartof);
		}
		isown=1;
		
	}
	fid=new String(fid);
	var v='';
	var currentTime = new Date();
	currentTime=new String(currentTime.getTime());
	//var ffid=URLEncode(encode64(fid)+"|"+encode64('0')+"|"+encode64(currentTime));
	var fwidth=330; // 400
	var fheight=150;

	//alert(issplited);
	
	if(!checkIfFileIsEncrypted(id) && !issplited){

		if(!issplited){
			
	if(fext=='mp3'){

		v='<iframe frameborder=0 src="'+BASEURL+'?p=mp3frame&id='+id+'&type=empty" width="100%" height="135"></iframe>';
		fwidth=600;
		fheight=290;
	}
	if(fext=='eml'){

		v='<iframe frameborder=1 src="'+BASEURL+'?p=emailframe&id='+id+'&type=aempty" width="99%" height="400"></iframe>';
		fwidth=600;
		fheight=550;
	}
	if(fext=='jpg' || fext=='jpeg' || fext=='gif' || fext=='png'){

		v='<a href="javascript:void(0)" onclick="emulateImageInParentDoc('+id+',\''+fext+'\',\''+ftitle+'\');">View/Edit file</a>';
		v+='<br>Upload to <a href="javascript:void(0)" onclick="uploadImage('+id+',\''+fext+'\',\'flickr\');">Flickr</a> or edit with ';
		v+='<a href="javascript:void(0)" onclick="uploadImage('+id+',\''+fext+'\',\'picnik\');">Picnik</a>';
	}
	if(fext=='flv'){

		v='<a href="javascript:void(0)" onclick="showVideoBox('+id+');">View video</a>';
	}
	if(fext=='html' || fext=='htm'){
		if(structtype!='c')
			v='<a href="javascript:void(0)" onclick="showWYSIWYGEditor('+id+',\'\');">Edit  as document</a> or <a href="javascript:void(0)" onclick="showWYSIWYGEditor('+id+',\'editarea\');">Edit  as source</a>';
		else
			v='<a href="javascript:void(0)" onclick="showContactEditor('+id+');">View/Edit contact info</a>';
	}
	if(fext=='c' || fext=='php' || fext=='php3' || fext=='php4' || fext=='php5' || fext=='cgi' 
	|| fext=='cpp' || fext=='css' || fext=='js' || fext=='pas' ||fext=='sql' || fext=='xml' || fext=='txt'){

		v='<a href="javascript:void(0)" onclick="showWYSIWYGEditor('+id+',\'editarea\');">Edit</a>';
	}

	if(fext=='doc' || fext=='xls' || fext=='docx' || fext=='xlsx'){

		v='<a target="_blank" href="'+BASEURL+'index.php?p=zoho&action=opendocument&id='+id+'" onclick="closeModalDialog(); return true;">View/Edit file with ZOHO</a>';
		if(google_docsallowed=='y' && 0)
		v+='<br><a target="_blank" href="'+BASEURL+'index.php?p=gdocs&action=opendocument&type=empty2&id='+id+'" onclick="closeModalDialog(); return true;">View/Edit file with Google Docs</a>';
	}

	if(fext=='ppt' ){
		v='<a target="_blank" href="http://show.zoho.com/publicimport.im?url='+BASEURL+'docs/'+fcode+'.'+fext+'" onclick="closeModalDialog(); return true;">View file with ZOHO</a>';
		if(google_docsallowed=='y' && 0)
		v+='<br><a target="_blank" href="'+BASEURL+'index.php?p=gdocs&action=opendocument&type=empty2&id='+id+'" onclick="closeModalDialog(); return true;">View/Edit file with Google Docs</a>';
	}

	if(fext=='doc' || fext=='pdf' || fext=='ppt' ){
		if(v!='')
			v+='<br>';
		v+='<a target="_blank" href="'+BASEURL+'/?p=scribdviewer&type=main_lite&fcode='+fcode+'#'+BASEURL+'files/'+fcode+'.'+fext+'" onclick="closeModalDialog(); return true;">View file with iPaper</a>';
	}
	if(fext=='pdf' || fext=='ppt' || fext=='tiff' || fext=='doc'){
		//google viewer
		if(v!='') v+='<br>';
		v+='<a target="_blank" href="http://docs.google.com/viewer?url='+URLEncode(BASEURL+'files/'+fcode+'.'+fext)+'" onclick="closeModalDialog(); return true;">View file with Google</a>';
	}
	if((useroptions.extra_textflow>0) && (fext=='doc' || fext=='docx')){
		
		if(v!='')
			v+='<br>';
		v+='<a href="javascript:void(0)" onclick="showReviewDocument('+id+');">Review Document</a>';
	}

	if(efaxtoollevel<= curuserlevel){
	if(fext=='doc' || fext=='pdf' || fext=='txt' || fext=='xls' || fext=='tif' || fext=='htm' || fext=='html' || fext=='rtf'){
		if(v!='')
			v+='<br>';
		v+='<a href="javascript:void(0)" onclick="addToMyFaxes('+id+');">Fax the document</a><br>';
		v+='<sub>(add to <b>My faxes</b> for future faxing.)</sub>';
	}
	}

	//if(fext=='avi' || fext=='mov' || fext=='swf' || fext=='wmv' || fext=='flv' || fext=='mp4'){
		//v='<a  href="javascript:void(0)" onclick="closeModalDialog();Videobox.open(\''+BASEURL+'videos/'+fid+'.'+fext+'\',\''+file.title+'\',\'vidbox 300 300\');">View</a>';
		//v='<a href="javascript:void(0)" onclick="closeModalDialog();showVideoFrame('+id+');">View/Edit file</a>';
	//}
	
		}//issplitted
		
		doanloadlink='<a href="file.php?fi_id='+fid+'&errorhtml=y" target="_blank" onclick="closeModalDialog(); return true;">';
		doanloadlink+=(fext=='htm' || fext=='html')?'View':'Download';
		doanloadlink+='</a>';
		
		if(structtype=='c')
			doanloadlink='';
		

	}else if(issplited){
			doanloadlink='This file is chunk of big file<br><a href="file.php?fi_id='+fid+'&errorhtml=y" target="_blank" onclick="closeModalDialog(); return true;">Download full file</a><br>';
			doanloadlink+='<a href="file.php?fi_id='+fid+'&errorhtml=y&justpart=y" target="_blank" onclick="closeModalDialog(); return true;">Download the chunk</a>';
	}
	else{
		v='<div name="encryptionphrasediv" id="encryptionphrasediv" style="display:none"><div name="encryptionphrasewrongdiv" id="encryptionphrasewrongdiv" style="display:none"><font color="red">Encryption phrase is wrong</font><br></div>Encryption phrase: <input type="password" name="encryptionphrase" id="encryptionphrase" value=""><input type="button" value="continue" onclick="continueDownloadFile('+fid+')"></div>';
		v+='<br>This is an encrypted file. File viewing options are not available for encrypted files. Please click "Download" to enter un-encryption phrase and download';
		doanloadlink='<a href="file.php?fi_id='+fid+'&errorhtml=y" target="_blank" onclick="showEncryptionPhrazeInput(); return false;">Download</a>';
		fwidth=400;
		fheight=220;
	}
	
	var twitter='';
	if(twitter_messageallowed=='y'){
		twitter='<div class="md_twitter"><a href="javascript:void(0)" onclick="sendLinkToTwitter('+fid+',\''+fname+'\')">Send link to Twitter</a></div>';	
	}
	
	var favorite='';
	var clipboardcontrol='';
	var fileinfocontrol='';
	if(isown==1){
		if(favourite=='1')
			favorite='<div class="md_favorite"><a href="javascript:makeFavourite('+fid+',0)" title="Remove from favourite"><img alt="unfavourite" src="'+BASEURL+'templates/'+theme+'/images/unfavourite_icon.gif"  border="0"/>Remove from favourite</a></div>';
		else
			favorite='<div class="md_favorite"><a href="javascript:makeFavourite('+fid+',1)" title="Make favourite"><img alt="favourite" src="'+BASEURL+'templates/'+theme+'/images/favourite_icon.gif"  border="0"/>Make favourite</a></div>';
		
		clipboardcontrol='<div class="md_clipboard"><a href="javascript:addFileToClipboard('+fid+')" title="Add to clipboard"><img alt="clipboard" src="'+BASEURL+'templates/'+theme+'/images/clipboard_icon.gif"  border="0"/> Add to clipboard</a></div>';
		fileinfocontrol='<div class="md_fileinfo"><a href="javascript:showFileInfo('+fid+')" title="Show file info"><img alt="fileinfo" src="'+BASEURL+'templates/'+theme+'/images/icon_info.png"  border="0"/> Show file info</a></div>';
		fileinfocontrol+='<div class="md_fileedit"><a href="javascript:showDescriptionEditor('+fid+')" title="Edit file description"><img alt="fileinfo" src="'+BASEURL+'templates/'+theme+'/images/edit.gif"  border="0"/> Edit file description</a></div>';
	}
	
	var extlink=BASEURL+'files/'+fcode+'.'+fext;
	var extenrallinkbox='<input type="text" style="width:258px;float:left" value="'+extlink+'">';
	extenrallinkbox+='<div style="border:solid 1px black; width:60px; height:20px;margin-left:267px;position:relative;top:-1px;">';
	extenrallinkbox+='<object width="60" height="20">';
	extenrallinkbox+='<PARAM NAME=FlashVars VALUE="txtToCopy='+extlink+'&js=void(0)">';
	extenrallinkbox+='<param name="movie" value="/include/flash/copyButton.swf">';
	extenrallinkbox+='<param name="scale" value="noscale">';
	extenrallinkbox+='<param name="salign" value="t">';
	extenrallinkbox+='<embed src="/include/flash/copyButton.swf" salign="t" scale="noscale" flashvars="txtToCopy='+extlink+'&js=void(0)" width="60" height="20">';
	extenrallinkbox+='</embed>';
	extenrallinkbox+='</object>';
	extenrallinkbox+='</div>';
	
	messageObj.setHtmlContent('<div class="md_question">What to do with file <span>'+fname+'</span>?</div>'+
		'<div class="md_doanloadlink">'+doanloadlink+'</div>'+
		'<div class="md_view">'+v+'</div>'+
		twitter+
		'<div class="md_input1">'+extenrallinkbox+'</div>'+
		'<div class="md_tinyurl" id="tinyurldiv" name="tinyurldiv" style="margin-top:2px;"><a href="javascript:void(0)" onclick="getTinyurl('+fid+')">Get TinyURL for the file</a></div>'+
		clipboardcontrol+
		favorite+
		fileinfocontrol+
		'<div class="md_button"><input type="button" value="Cancel" onclick="closeModalDialog()" ></div>');
	
	messageObj.setSize(fwidth, fheight);
	messageObj.setSource(false);
	messageObj.setShadowDivVisible(true);
	messageObj.display();
	
}
//----------------------------------------------------------------------------
function sendLinkToTwitter(fid,fname){
	closeModalDialog();
	messageObj.setHtmlContent('<table height="100%" width="100%" border=0><tr><td align="center">Send link to the file '+fname+' to Twitter</td></tr>'+
		'<tr><td align="center" valign="middle" nowrap>Message (max 110 chars, is <div style="display:inline" id="showusedchars" name="showusedchars">0</div>)</td></tr>'+
		'<tr><td align="center" valign="middle"><center><textarea rows=4 cols=30 name="twittertext" id="twittertext" onKeyPress="limitTextLength(this,110,\'showusedchars\')" onpaste="limitTextLength(this,120,\'showusedchars\')"></textarea></center></td></tr>'+
		'<tr><td align="center" valign="middle"><center>The link will be added to the end of the message.</center></td></tr></table>'+
		'<div class="md_button"><input type="button" value="Send" onclick="doSendLinkToTwitter('+fid+')" >&nbsp;<input type="button" value="Cancel" onclick="closeModalDialog()" ></div>');
	
	messageObj.setSize(300, 200);
	messageObj.setSource(false);
	messageObj.setShadowDivVisible(true);
	messageObj.display();
}
//----------------------------------------------------------------------------
function doSendLinkToTwitter(fid){
	document.goform.action ='index.php?ajaxfunction=executeAPI&function=doSendFileLinkToTwitter'+
       "&fi_id="+fid+
	"&message="+
	URLEncode(document.getElementById("twittertext").value);
	closeModalDialog();
	showLoadScreenCustom('Sending message to Twitter');
   	AIM.submit(document.goform, aim_c);
}
//----------------------------------------------------------------------------
function limitTextLength(obj,len,sid){
	
	if(obj.value.length>=len)
		obj.value=obj.value.substring(0,len-1);
	document.getElementById(sid).innerHTML=obj.value.length+1;
}
//----------------------------------------------------------------------------
function getTinyurl(fid){
	document.getElementById('tinyurldiv').innerHTML='<img src="'+BASEURL+'templates/'+theme+'/images/loading.gif" width="16" height="16" alt="Loading ..." border="0"/>';
	document.goform.action ='index.php?ajaxfunction=executeAPI&function=getFileTinyURL'+
       "&fi_id="+fid;
   	AIM.submit(document.goform, aim_c);
}
//----------------------------------------------------------------------------
function setTinyurl(result){
	var html='<input type="text" style="width:258px;float:left;font-size:11px;font-family:Tahoma;" name="tinyurlinput" id="tinyurlinput" value="'+result.tinyurl+'">';
	html+='<div style="border:solid 1px black; width:60px; height:20px;margin-left:267px;position:relative;top:-1px;">';
	html+='<object width="60" height="20">';
	html+='<PARAM NAME=FlashVars VALUE="txtToCopy='+result.tinyurl+'&js=void(0)">';
	html+='<param name="movie" value="/include/flash/copyButton.swf">';
	html+='<param name="scale" value="noscale">';
	html+='<param name="salign" value="t">';
	html+='<embed src="/include/flash/copyButton.swf" salign="t" scale="noscale" flashvars="txtToCopy='+result.tinyurl+'&js=void(0)" width="60" height="20">';
	html+='</embed>';
	html+='</object>';
	html+='</div>';
	document.getElementById('tinyurldiv').innerHTML=html;
	document.getElementById('tinyurlinput').focus();
	document.getElementById('tinyurlinput').select(); 
}

//video ----------------------------------------------------------------------
function showVideoBox(id){
	closeModalDialog();
	var html='<iframe frameborder=0 src="'+BASEURL+'?p=videoframe&id='+id+'&type=aempty" width="100%" height="490"></iframe>'+
		'<center><input type="button" value="Close" onclick="closeModalDialog()" ></center>';
	
	//return;
	messageObj.setHtmlContent(html);
	
	messageObj.setSize(800, 530);
	messageObj.setSource(false);
	messageObj.setShadowDivVisible(true);
	messageObj.display();
}

function showDescriptionEditor(id){
	closeModalDialog();
	wopen(BASEURL+'?p=description&fi_id='+id+'&type=empty2&', 'Edit file description', 800, 500);
}

function showWYSIWYGEditor(id,editor,ccc){
	if(ccc!=1) closeModalDialog();
	wopen(BASEURL+'?p=wysiwyg&fi_id='+id+'&type=empty2&editor='+editor, 'Edit file', 800, 500);
}

function showContactEditor(id){
	closeModalDialog();
	wopen(BASEURL+'?p=contact&fi_id='+id+'&type=empty2', 'Edit contact info', 600, 400);
}

function uploadImage(id,ext,site){
	closeModalDialog();
//prompt('',BASEURL+'?p=uploadimage&id='+id+'&site='+site+'&ext='+ext+'&type=aempty');
//return;
	/*messageObj.setHtmlContent('<table height="100%" width="100%" border=0><tr><td align="center"><iframe frameborder=1 src="'+BASEURL+'?p=uploadimage&id='+id+'&site='+site+'&ext='+ext+'&type=aempty" width="99%" height="570"></iframe></td></tr>'+
	'<tr><td  align="center"><center><input type="button" value="Close" onclick="closeModalDialog()" ></center></td></tr></table>');
	
	messageObj.setSize(800, 600);
	messageObj.setSource(false);
	messageObj.setShadowDivVisible(true);
	messageObj.display();*/

	//wopen(BASEURL+'?p=uploadimage&id='+id+'&site='+site+'&ext='+ext+'&type=aempty', 'Upload image', 800, 600);
	wopen(BASEURL+'uploadimage/'+id+'/'+site+'/'+ext, 'Upload image', 800, 600);
}

function wopen(url, winname, w, h)
{
  w += 32;
  h += 96;
  var wleft = (screen.width - w) / 2;
  var wtop = (screen.height - h) / 2;
  var option='width=' + w + ',height=' + h + ',' +
    'left=' + wleft + ',top=' + wtop + ',' +
    'location=no,menubar=no,' +
    'status=no,toolbar=no,scrollbars=no,resizable=no';

  option=new String(option);
//  alert(option);
  //prompt('',url);

var win = window.open(url,'',option);
//return;
  //var win = window.open(url,'Upload image',option);
  // Just in case width and height are ignored
  //return;
 // alert(1);
  win.resizeTo(w, h);
  // Just in case left and top are ignored
  win.moveTo(wleft, wtop);
  win.focus();
}

function checkViewer(e){
	if(e== null || e=='') return 0;
	var ext=e.toLowerCase();
	if(ext=='mp3' || ext=='doc' || ext=='xls' || ext=='ppt' || ext=='jpg' || ext=='jpeg' || ext=='gif' || ext=='png' || ext=='eml')
		return 1;
	return 0;
}
//end romasoft

  

function emulateImageInParentDoc(id,ext,title,ccc){

	//prompt('',BASEURL+'imgs/'+id+'.'+ext);
	document.getElementById('viewdiv').innerHTML='<a href="'+BASEURL+'imgs/'+id+'.'+ext+'" rel="lytebox" title="'+title+'" name="aaa" id="aaa"></a>';
	myLytebox.updateLyteboxItems();
	/*var chd=document.getElementById('viewdiv').getElementsByTagName('*');
	closeModalDialog();
	chd[0].onclick();*/
	var target=document.getElementById('aaa');
	
	if(ccc!=1) closeModalDialog();
	if(document.dispatchEvent) { // W3C
    var oEvent = document.createEvent( "MouseEvents" );
    oEvent.initMouseEvent("click", true, true,window, 1, 1, 1, 1, 1, false, false, false, false, 0, target);
    target.dispatchEvent( oEvent );
    }
	else if(document.fireEvent) { // IE
    target.fireEvent("onclick");
	
    }
}

/*function showVideoFrame(id){
	var fr=document.getElementById('videoframe');
	if(!fr){
		alert('Can not find video frame!');
		return;
	}
	var cwidth=1000;
	var cheight=1000;
	if (window.innerWidth || window.innerHeight){ 
		cwidth = window.innerWidth; 
		cheight = window.innerHeight; 
	}else if (document.body.clientWidth || document.body.clientHeight){ 
		cwidth = document.body.clientWidth; 
		cheight = document.body.clientHeight; 
	}else{
		cwidth = Window.getWidth(); 
		cheight = Window.getHeight(); 
	}


	fr.style.width=cwidth;
	fr.style.height=cheight-30;


	fr.src=BASEURL+'?p=videoframe&id='+id+'&type=empty';
	fr.style.display='block';
}
function hideVideoFrame(){
	var fr=document.getElementById('videoframe');
	fr.style.display='none';
}*/
//----------------

function hideHint(el){
	// document.getElementById('divshowhint').style.display='none';
	// ��� 29.01.10
	el.parentNode.parentNode.style.display='none';
}

function closePopupMessage(){
	document.getElementById('divpopupmessage').style.display='none';
	
	if(popupmessageid==0) return '';

	document.goform.action ='index.php?ajaxfunction=executeAPI&function=doSetMessageRead&me_id='+popupmessageid;
   	//showLoadScreen();
	document.getElementById('divpopupmessage').innerHTML=getCustomWaitHTML('Please wait, checking messages');
	document.getElementById('divpopupmessage').style.display='block';
   	AIM.submit(document.goform, aim_c);
	
}

function showClosePopupMessage(result){
	//closeModalDialog();
	document.getElementById('divpopupmessage').style.display='none';
	if(result.isnextmessage=='y'){
		popupmessageid=result.nextmessage.me_id;
		document.getElementById('divpopupmessage').innerHTML=result.nextmessage.me_message;
		document.getElementById('divpopupmessage').innerHTML+='<div class="closeLink"><a href="javascript:void(0)" onclick="closePopupMessage()">Close popup</a></div>';
		document.getElementById('divpopupmessage').style.display='block';
	}
	
	if(isfilemanagershown==1 && tmpvalforsync==1)
		getAllForUser();
}

 function URLEncode(plaintext)
 {
        // The Javascript escape and unescape functions do not correspond
        // with what browsers actually do...



        var SAFECHARS = "0123456789" +                                        // Numeric
                                        "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +        // Alphabetic
                                        "abcdefghijklmnopqrstuvwxyz" +
                                        "-_.!~*'()";                                        // RFC2396 Mark characters
        var HEX = "0123456789ABCDEF";

        var encoded = "";
        for (var i = 0; i < plaintext.length; i++ ) {


                var ch = plaintext.charAt(i);


            if (ch == " ") {
                    encoded += "+";                                // x-www-urlencoded, rather than %20
                } else if (SAFECHARS.indexOf(ch) != -1) {
                    encoded += ch;
                } else {
                    var charCode = ch.charCodeAt(0);
                        if (charCode > 255) {
                            alert( "Unicode Character '"
                        + ch
                        + "' cannot be encoded using standard URL encoding.\n" +
                                          "(URL encoding only supports 8-bit characters.)\n" +
                                                  "A space (+) will be substituted.","messageObj.close()" );
                                encoded += "+";
                        } else {
                                encoded += "%";
                                encoded += HEX.charAt((charCode >> 4) & 0xF);
                                encoded += HEX.charAt(charCode & 0xF);
                        }
                }
        } // for


        return encoded;
}

function testMD(){
	showLoadScreenCustom('<br><br><br><br><br><input type="button" value="Cancel" onclick="closeModalDialog()" >');
}

function getProvider(pid){
	if(pid<1) return null;
	for (var i=0;i<providers.used.length;i++) {
		var pr_item = providers.used[i];
		if(pr_item.pi_id==pid) {
			return pr_item;
		}
	}
	return null;
}

function getProviderIconSmall(pid,options){
	var pr_item=getProvider(pid);
	if(!pr_item) return '';
	providercode=pr_item.pr_code;
	providername=pr_item.pr_name;
	if(providercode!=''){
		if(providercode=='s3' && options!==undefined && options=='rrs=y')
			providercode='s3rrs';
		return '<img alt="'+providername+'" title="File stored at '+providername+'" src="'+BASEURL+'templates/'+theme+'/images/'+providercode+'_small.gif"  border="0"/>';
	}
	return '';
}

function getFileName(num){
	var filename=document.getElementById('file_'+num).value;
	if(filename.indexOf('\\')>-1 || filename.indexOf('/')>-1){
		var bs='\\';
		if(filename.indexOf('\\')<filename.indexOf('/'))
			bs='/';
		filename=filename.substring(filename.lastIndexOf(bs)+1);
		
	}
	return filename;
}

function setFileName(num){
	document.getElementById('file_name'+num).value=getFileName(num);
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function checkAllItems(obj,name,dml) {
        val=obj.checked;
        len = dml.elements.length;
        var i=0;
        for( i=0 ; i<len ; i++) {
                if (dml.elements[i].name==name) {
                        dml.elements[i].checked=val;
                }
        }
}

function smeAlert(text){
	messageObj.setHtmlContent('<div width="100%"><center>'+text+'</center><br><center><input type="button" value="Close" onclick="closeModalDialog()" ></center></div>');
	messageObj.setSize(350, 250);
	messageObj.setSource(false);
	messageObj.setShadowDivVisible(true);
	messageObj.display();
}
