



    
  var i=1;
  var ua = navigator.userAgent;
  var opera = /opera [56789]|opera\/[56789]/i.test(ua);
  var ie = !opera && /MSIE/.test(ua);
  var ie50 = ie && /MSIE 5\.[01234]/.test(ua);
  var ie6 = ie && /MSIE [6789]/.test(ua);
  var ieBox = ie && (document.compatMode == null || document.compatMode != "CSS1Compat");
  var moz = !opera && /gecko/i.test(ua);
  var nn6 = !opera && /netscape.*6\./i.test(ua);
  var safari = ua.indexOf('Safari')>-1;
  var originalUploadElementsContent = null;

  function hasUploadElement(j){
      return document.getElementById("fid"+j)!=null;
  }
  function restoreUploadElements(){
      if(originalUploadElementsContent!=null){
          $('#fileTR').parent().html(originalUploadElementsContent);
      }
  }
  function removeFileField(d){
      var ftr=document.getElementById("fid"+d);
      if(ftr!=null){
          ftr=ftr.parentNode.parentNode;
          ftr.parentNode.removeChild(ftr);
      }
  }

  function cloneFileField(){
      var ftr=document.getElementById("fileTR");
      if(originalUploadElementsContent==null){
          originalUploadElementsContent=$('#fileTR').parent().html();
      }
      var ftr2= ftr.cloneNode(true);

      var td=ftr2.getElementsByTagName("input")[0];
      td.name="fff"+i;
      td.id="fid"+i;
      td.value = "";
      
      var a=ftr2.getElementsByTagName("a")[0];
      a.href="javascript:removeFileField("+i+")";
      a.style.display="inline";

      var ftable=document.getElementById("fileTBODY");
      ftable.appendChild(ftr2);
      i++;
  }

  function createDirectory(e){
     var desc = "Please enter folder name";
     var title = "Create a new folder";
     var baseValue = "";
     promptCreateNewDir(e,desc, title , baseValue, "createDirectoryAction");

  }

  function createDirectoryAction(dirName, share){
     if (dirName){
       document.theForm.newdir.value=dirName;
       document.theForm.sharenewdir.value=(share==undefined ? 0 : share);
       document.theForm.submit();
     }
    return false;
  }



  function upDir(){
     document.theForm.updir.value="1";
     document.theForm.submit();
  }
  function emptyRecycleBin(){
    if(window.confirm("Are you sure you want to permanently delete all files in the Recycle Bin?")){
      massAction(18);
    }
  }

  function deldir(id,name){
       delImpl(id,name,1);
  }

  function deldirPerm(id,name){
      delImplPerm(id,name,1);
 }

  function delfile(id,name){
       delImpl(id,name,2);
  }

  function delImpl(id,name,w){
    var confirmMsg = "Are you sure you want to move $[p1] to the Recycle Bin?\nFiles in your Recycle Bin are subject to deletion at any time.";
    confirmMsg =  confirmMsg.replace(/\$\[p1\]/,"\""+name+"\"");
    
    if (window.confirm(confirmMsg)){
      if (w==1){
       document.theForm.deldir.value=id;
      }else {
       document.theForm.delfile.value=id;
      }
      document.theForm.submit();
    }
  }
  function delfilePerm(id,name){
       delImplPerm(id,name,2);
  }
  function delmessagePerm(id,name){
    delImplPermForForm(id,name,3,document.pmForm);
  }
  function delImplPerm(id,name,w){
    delImplPermForForm(id,name,w,document.theForm);
  }
  function delImplPermForForm(id,name,w,aForm){
    var confirmMsg = "Are you sure you want to delete $[p1] permanently?";
    confirmMsg = confirmMsg.replace(/\$\[p1\]/,"\""+name+"\"");
    if (window.confirm(confirmMsg)){
      if (w==1){
       aForm.deldir.value=id;
      }else  {
      if (w==2){
       aForm.delfile.value=id;
      } else {
       aForm.delmessage.value=id;
}
      }
      aForm.submit();
    }
  }
  function restoreFile(id,name){
    var confirmMsg = "Are you sure you want to restore $[p1] ?";
    confirmMsg = confirmMsg.replace(/\$\[p1\]/,"\""+name+"\"");
    if (window.confirm(confirmMsg)){
      document.theForm.restorefile.value=id;
      document.theForm.submit();
    }
  }
  
  function restoreFolder(id,name){
    var confirmMsg = "Are you sure you want to restore $[p1] ?";
    confirmMsg = confirmMsg.replace(/\$\[p1\]/,"\""+name+"\"");
    if (window.confirm(confirmMsg)){
      document.theForm.restoredir.value=id;
      document.theForm.submit();
    }
  }
  
  function showDirContents(id) {
  	 $.getJSON('/account/RecDirContent.jsp', {ajax: 'true', dirId: id} ,function(data){
          var res;
          if(data.ok && data.ok === true){
              res = data.content;
              promptReadOnly({pageX:350,pageY:100}, res);
          }                    
      });    
  }

  function closePrompt() {
      writeDrag.hide();
  }

  function promptReadOnly(event, str) {
  var w = 400;
  var h = 250; // size

  if ( dragObj.supported && typeof document.body.innerHTML != "undefined" ) {
    var cntnt;
    try {
      cntnt = '<div class="text" width='+w+' height='+h+'><form name="prompt" onSubmit="javascript:closePrompt()" >'+
              'Folder content'+'<br />'+
          '<textarea rows="10" cols="61" style="width:'+w+'px" class="xBox" readonly>'+str+'</textarea>'+
          '<div class="alignRight"><input type="button" value="Close" style="width:50px;" onClick="javascript:closePrompt()"/></div></form></div>';
      // class="xBox" is attached to the text element so that mouse were working inside the text as usual
      // (selecting text), not dragging the prompt. If class attribute is needed for design
      // then dw_drag.js must be changed to perform substring, not exact class comparison
      document.getElementById("popupTitle").innerHTML = 'Folder content';
      writeDrag.set(event, cntnt, w);      
    }catch (e){
    alert(e);
  }
  }
  return false;
  //alert(str);
  }

  function delFavFile(id){
    document.theForm.delfile.value=id;
    document.theForm.submit();
  }

  var selectAll=true;

  function changeSelectAllName(sAll, newName, title) {
      if(sAll) {
          if(title) {
            sAll.title=newName;
          } else {
              sAll.innerHTML = newName;
          }
        }
  }

    function changeFriend(friendName) {
      changeFriend(null, -1, friendName);
    }

    function detectUnsub(e) {
      if(e && e.target) {
        return $(e.target).hasClass("usbtn");
      }

      return false;
    }

    function changeFriend(e, userId, friendName) {
    
      goto('/login.jsp?chf=' + userId);
    
    }

    function changeToSubscribe(button) {
      button.get(0).innerHTML = "Subscribe";
      
      button.removeClass("usbtn").addClass("sbtn");      
    }

    function changeToUnsubscribe(button) {
      button.get(0).innerHTML = "Unsubscribe";
      button.removeClass("sbtn").addClass("usbtn");
    }

  function selectAllOrNone(){
    var sAll=document.getElementById("selectAll");
      var sAll2 = document.getElementById("selectAll2");
    if (selectAll){
    $(".stable tr")
        .filter(':has(:checkbox:not(:checked))')
        .addClass('trclick')
        .find(':checkbox',this)
              .attr('checked', function() {
                return !this.checked;
              })
        .end();
        changeSelectAllName(sAll, "Select None", true);
        changeSelectAllName(sAll2, '<img src="/images/icons/16x16/unselectall.png" width="16" height="16" class="absmid" alt="Select none" /> Select none', false);
      selectAll=false;
    } else {
    $(".stable tr")
        .filter(':has(:checkbox:checked)')
        .removeClass('trclick')
        .find(':checkbox',this)
              .attr('checked', function() {
                return !this.checked;
              })
        .end();
      changeSelectAllName(sAll, "Select All", true);
        changeSelectAllName(sAll2, '<img src="/images/icons/16x16/selectall.png" width="16" height="16" class="absmid" alt="Select all" /> Select all&nbsp;&nbsp;&nbsp;&nbsp;', false);
      selectAll=true;
    }


  }

  function checkFileWithId(fileid){
      var el = document.getElementsByTagName("input");
      for (i = 0; i < el.length; i++) {
          var elem = el[i];
          if (elem.type != 'checkbox' || elem.name == null || elem.value == null || elem.value == 'undefined') {
              continue;
          }
          if (elem.name == 'ch_f' && elem.value==fileid) {
              elem.checked=true;
          }
      }
  }
        
  function checkDirWithId(dirid){
      var el = document.getElementsByTagName("input");
      for (i = 0; i < el.length; i++) {
          var elem = el[i];
          if (elem.type != 'checkbox' || elem.name == null || elem.value == null || elem.value == 'undefined') {
              continue;
          }
          if (elem.name == 'ch_d' && elem.value==dirid) {
              elem.checked=true;
          }
      }
  }

    function addSelectedToMyAccount() {
      if(!hasCheckedFiles()) {
        alert('Please check items to add to your account');
        return;
      }
      document.theForm.homemode.value=31;
      $.post(document.theForm.action, $("#theForm").serialize() ,function(data){        
        if(data.ok && data.guid) {
          goto('/login.jsp?asl='+data.guid);
        }
      }, "json");
    }

  function uncheckAll(){
    checkDirsImpl(false);
    checkFilesImpl(false);
  }

  function checkDirs(){
    checkDirsImpl(true);
  }
  function checkDirsImpl(checkValue){
      var el = document.getElementsByTagName("input");
      for (i = 0; i < el.length; i++) {
          var elem = el[i];
          if (elem.type != 'checkbox' || elem.name == null || elem.value == null || elem.value == 'undefined') {
              continue;
          }
          if (elem.name == 'ch_d') {
              elem.checked=checkValue;
          }
      }
  }

  function checkFiles(){
    checkFilesImpl(true);
  }
  function unCheckFiles(){
    checkFilesImpl(false);
  }
  function checkFilesImpl(checkValue){
      var el = document.getElementsByTagName("input");
      for (i = 0; i < el.length; i++) {
          var elem = el[i];
          if (elem.type != 'checkbox' || elem.name == null || elem.value == null || elem.value == 'undefined') {
              continue;
          }
          if (elem.name == 'ch_f') {
              elem.checked=checkValue;
          }
      }
  }

  function hasCheckedFiles(){
      var el = document.getElementsByTagName("input");
      for (i = 0; i < el.length; i++) {
          var elem = el[i];
          if (elem.type != 'checkbox' || elem.name == null || elem.value == null || elem.value == 'undefined' || !elem.checked) {
              continue;
          }
          if (elem.name == 'ch_f' || elem.name == 'ch_d') {
              return true;
          }
      }
      return false;

  }

   function hasCheckedDirsOnly(){
      var el = document.getElementsByTagName("input");
      for (i = 0; i < el.length; i++) {
          var elem = el[i];
          if (elem.type != 'checkbox' || elem.name == null || elem.value == null || elem.value == 'undefined' || !elem.checked) {
              continue;
          }
          if (elem.name == 'ch_d') {
              return true;
          }
      }
      return false;

  }

  function hasCheckedFilesOnly(){
    var el = document.getElementsByTagName("input");
    for (i = 0; i < el.length; i++) {
        var elem = el[i];
        if (elem.type != 'checkbox' || elem.name == null || elem.value == null || elem.value == 'undefined' || !elem.checked) {
            continue;
        }
        if (elem.name == 'ch_f') {
            return true;
        }
    }
    return false;
  }

  function toEmail(mode){
    if (!hasCheckedFiles()){
      alert("Please check files to email");
    }else {
      massAction(mode);
    }

  }

  function massAction(mode){
      document.theForm.homemode.value=mode;
      document.theForm.submit();
  }

  function goForward(){
    massAction(14);
  }
  function goBack(){
    massAction(13);
  }

  function copyFiles(mode){
    if (!hasCheckedFiles()){
      alert("Please check files to copy");
    }else {
      massAction(mode);
    }
  }

   function shareFolders(mode){
    if (!hasCheckedDirsOnly()){
      alert("Please check folders to share");
    }else {
      massAction(mode);
    }
  }

  function makeRenameWOEvent(oldname,fid,isItFileToRename){
    document.theForm.renamefileid.value=fid;
    document.theForm.isFileToRename.value=isItFileToRename;
    var desc = "Please enter new name";
    var title = "Rename";
    promptIE7(contextMenuEvent,desc, title , oldname, "renameFileAction2",contextMenuEventX,contextMenuEventY,true);
  }

  
  function renameFile(event,oldname,fid,isItFileToRename,offx,offy){
    document.theForm.renamefileid.value=fid;
    document.theForm.isFileToRename.value=isItFileToRename;
    var desc = "Please enter new name";
    var title = "Rename";
    promptIE7(event, desc , title , oldname, "renameFileAction2",offx,offy);
  }

  function renameFileAction2(s){
    if(s.length==0){
      alert("Name should not be empty");
    }else {
      document.theForm.newfilename.value=s;
      massAction(12);
    }
    return false;
  }

  function addChangeFolderDescription(event,olddescription,dirid,offx,offy){
    document.theForm.addchangedescriptionfolderid.value=dirid;
    var desc = "Please enter new description";
    var title = "Add folder description";
    promptBigWindowIE7(event, desc , title , olddescription, "addChangeFolderDescription2",offx,offy);
}

  function addChangeFolderDescription2(s){
    if(s.length==0){
      alert("Description should not be empty");
    }else {
    writeDrag.hide();
     // document.theForm.newfolderdescription.value=s;
      changeDirAddParams="&homemode="+21+"&newfolderdescription="+ encodeURIComponent(s) + "&addchangedescriptionfolderid="+currentDirId;
         changeDirImpl(currentDirId,true);
     // massAction(21);
    }
    return false;
  }

  function cutFiles(mode){
    if (!hasCheckedFiles()){
      alert("Please check files to cut");
    }else {
      massAction(mode);
    }
  }


  function deleteFiles(mode){
      if (!hasCheckedFiles()){
          alert("Please check files to move to the Recycle Bin");
      }else {
          if (window.confirm("Are you sure you want to move selected files to the Recycle Bin?\nFiles in your Recycle Bin are subject to deletion at any time.")){
              massAction(mode);
          }
      }
  }
  function restoreFiles(mode){
      if (!hasCheckedFiles()){
          alert("Please check files to restore");
      }else {
          if (window.confirm("Are you sure you want to restore selected files?")){
              massAction(mode);
          }
      }
  }
  function deleteFilesPerm(mode){
      if (!hasCheckedFiles()){
          alert("Please check files to delete");
      }else {
          if (window.confirm("Are you sure you want to delete selected files permanently?")){
              massAction(mode);
          }
      }
  }
  function zipFiles(event,offx,offy){
      if (!hasCheckedFiles()){
          alert("Please check files to zip");
      }else {
        var desc = "Please enter zip filename";
        var title = "Zip";
         promptIE7(event, desc , title ,document.theForm.defaultZipName.value , "zipFilesAction",offx,offy);

      }
  }

	function downloadAll(event) {
    
      promptGetPremium(event,'In order to download all files in folder press \"Activate\" button to get Premium account and activate all Premium features','<b>\"Download folder\"<\u002fb> function available only for Premium account!','','getPremiumAction','c','c');
    
	}

    function getCheckedDirIds() {
      var res = [];
      $("input[name='ch_d']:checked").each(function() {
        res.push($(this).val());
      });
      /*var el = document.getElementsByTagName("input");
      for (i = 0; i < el.length; i++) {
        var elem = el[i];
        if (elem.type != 'checkbox' || elem.name == null || elem.value == null || elem.value == 'undefined' || !elem.checked) {
          continue;
        }
        if (elem.name == 'ch_f' || elem.name == 'ch_d') {
          return true;
        }
      }*/
      return res;
    }

    function getCheckedFileIds() {
      var res = [];
      $("input[name='ch_f']:checked").each(function() {
        res.push($(this).val());
      });
      return res;
    }

    function downloadSelected(event) {
      
        promptGetPremium(event,'In order to download selected files in folder press &quot;Activate&quot; button to get Premium account and activate all Premium features','<b>\"Download selected\"<\u002fb> function available only for Premium account!','','getPremiumAction','c','c')
      
    }
	
	function viewAll(firstFileToShow) {
		document.theForm.target = 'blank';
		document.theForm.firstFileToShow.value = firstFileToShow; 
		document.theForm.homemode.value=26;
		document.theForm.submit();
	}

   function zipFilesAction(s){
         var enteredZipName=s;
        if(enteredZipName==null || enteredZipName=='undefined' || enteredZipName==''){
          alert("You should enter zip filename");
          return false;
        }
         writeDrag.hide();
         document.theForm.zipname.value=enteredZipName;
         var oldTarget =document.theForm.target;
         var oldAction =document.theForm.action;
         document.theForm.target='zipframe';
         document.theForm.action=document.theForm.zipFormURL.value;

         top.zipStarts = true;
         massAction(9);
         showProgressBar('zip');
         document.theForm.target=oldTarget;
         document.theForm.action=oldAction;
        return false;
      }

      function deleteFavoriteFiles(mode){
        if (!hasCheckedFilesOnly()){
          alert("Please check files to delete from Favorites");
        }else {
          massAction(mode);
        }
      }

      function addToFavorites(mode){
        if (!hasCheckedFilesOnly()){
          alert("Please check files to add to Favorites");
        }else {
          massAction(mode);
        }
      }

    function markFiles(mode){
      if (!hasCheckedFiles()){
        alert("Please check files to mark as public");
      }else {
        massAction(mode);
      }
    }

    function markOffFiles(mode){
      if (!hasCheckedFiles()){
        alert("Please check files to mark off as public");
      }else {
        massAction(mode);
      }
    }

    function showPreview(url){
      var img=document.getElementById("smallImg");
      img.src = url;
      img.style.display="inline";
    }

    function hidePreview(){
      var img=document.getElementById("smallImg");
      img.style.display="none";
    }

    function fileOver(page,isImg,link,rowNum){
//     if (isImg){
//       showPreview(link);
//     }
    setPointer(page,rowNum, 'over', 'Window', (safari?'#FFFFDE':'InfoBackground'), '#C3D9FF');
    //setPointer(page,rowNum, 'over', '#E5E5E5', '#CCFFCC', '#C3D9FF');

    }
    function fileOut(page,isImg,link,rowNum){
//     if (isImg){
//       hidePreview();
//     }
     //setPointer(page,rowNum, 'out', '#E5E5E5', '#CCFFCC', '#C3D9FF');
     setPointer(page, rowNum, 'out', 'Window', (safari?'#FFFFDE':'InfoBackground'), '#C3D9FF');
    }


     function fileDownCheckBox(isFile,fid,td,rowNum){
      var el = document.getElementsByTagName("input");
      for(i=0;i<el.length;i++){
          var elem = el[i];
          if(elem.value!=fid || elem.type!='checkbox' || elem.name==null){
              continue;
          }
          if(isFile  && elem.name=='ch_f'){
              elem.checked=!elem.checked;
              break;
          }
          if(!isFile && elem.name=='ch_d'){
              elem.checked=!elem.checked;
          }
      }
    }

function cloneObjShallow(myObj)
{
	if(typeof(myObj) != 'object') return myObj;
	if(myObj == null) return myObj;

	var myNewObj = new Object();

	for(var ifield in myObj)
		myNewObj[ifield] = myObj[ifield];

	return myNewObj;
}

//writeDrag.writeId = "cntnt";
function wrapContent(e, img, w, h, txt,
                     downloadLink, fileExt,
                     wd, offx, offy) {
  var imgStr, cntnt, win, str;
  imgStr = '<img src="' + img + '"' + (w? ' width="' + w + '"': "") + (h? ' height="' + h + '"': "") + '>';
  if( downloadLink ){
      window.originalMediaPreviewEvent=cloneObjShallow(e);
      txt += '\n<a href="#" onclick="return showMediaPreview(window.originalMediaPreviewEvent, \''
              + downloadLink + '\',\''+ fileExt + '\')">';
      txt += '\n<img alt="Play" src="/images/play.gif" title="Play media file" class="absmid" /></a>';
  }
  if ( dragObj.supported && typeof document.body.innerHTML != "undefined" ) {
    cntnt = '<div class="previewImg">' + imgStr + '</div>';
    if (txt) cntnt += '<div class="previewMsg">' + txt + '</div>';
    if (!wd) wd = w;
    document.getElementById("popupTitle").innerHTML = 'Preview';
    writeDrag.set(e, cntnt, wd, offx, offy);
  } else { // non-capable browsers will open sub window
    w = w+80 || wd || 250; h = h+80 || 250; // size
    win = window.open('', 'subwin', 'resizable,width='+w+',height='+h+',left=100,top=100');
    if (win && !win.closed) win.resizeTo(w,h);
    str = '<html><head><title>Image Display</title></head>';
  	str += '<body style="text-align:center">';
    str += imgStr + (txt? '<p>' + txt + '</p>':"");
  	str += '</body></html>'
  	win.document.write(str);
  	win.document.close();
    if (win && !win.closed) win.focus();
  }
  return false;
}







function showMediaPreview(e, url, ext, haveFlv, streamer) {
  var spanStr, cntnt, win, str;
  spanStr = '<span id=\'music1\'></span>';
  var w = 330;
  var h = 250; // size
  if ( dragObj.supported && typeof document.body.innerHTML != "undefined" ) {
    cntnt = '<div class="previewImg">' + spanStr + '</div>';
    document.getElementById("popupTitle").innerHTML = 'Play';
    writeDrag.set(e, cntnt, w, 0, 0);
    playMedia(document, url, ext, haveFlv, streamer);
  } else { // non-capable browsers will open sub window
    win = window.open('', 'subwin', 'resizable,width='+w+',height='+h+',left=100,top=100');
    if (win && !win.closed) win.resizeTo(w,h);
    str = '<html><head><title>Media Preview</title></head>';
  	str += '<body style="text-align:center">';
    str += spanStr ;
  	str += '</body></html>'
  	win.document.write(str);
  	win.document.close();
    if (win && !win.closed) win.focus();
    playMedia(win.document, url, ext, streamer);
  }
  return false;
}



function showZipPreview(e, previewURL, w, h, wd, fid,unzipFormUrl,unzipProgressUrl) {
  var imgStr, cntnt, win, str;
  if(document.unzipForm!=null){
     document.unzipForm.zipFile.value=fid;
     document.unzipForm.action=unzipFormUrl;
     document.unzipForm.unzipProgressUrl.value=unzipProgressUrl;
  }
  iframeStr = '<iframe src="'+previewURL + '"' + (w? ' width="' + w + '"': "") + (h? ' height="' + h + '"': "") + ' scrolling="yes"></iframe>';
  if (dragObj.supported && typeof document.body.innerHTML != "undefined" ) {//****************
    if(unzipFormUrl!=null && unzipFormUrl!=''){
      cntnt = '<div class="previewImg"><button type="button" class="oneline" onclick="top.unzipAction();" id="unzipButton">Unzip</button><br>' +iframeStr + '</div>';
    }else {
      cntnt = '<div class="previewImg"><br>' +iframeStr + '</div>';
    }

    if (!wd) wd = w;
    document.getElementById("popupTitle").innerHTML = 'Zip preview';
    writeDrag.set(e, cntnt, wd, 0, 0);
  } else { // non-capable browsers will open sub window
    w = w+80 || wd || 250; h = h+80 || 250; // size
    win = window.open(previewURL, 'subwin', 'resizable,width='+w+',height='+h+',left=100,top=100');
    if (win && !win.closed) win.resizeTo(w,h);
    if (win && !win.closed) win.focus();
  }
  return false;
}
function showTextPreview(e, fid, w, h, wd, offx, offy) {
  var imgStr, cntnt, win, str;
  iframeStr = '<iframe src="'+fid + '"' + (w? ' width="' + w + '"': "") + (h? ' height="' + h + '"': "") + ' scrolling="yes"></iframe>';
  if (dragObj.supported && typeof document.body.innerHTML != "undefined" ) {//****************
    cntnt = '<div class="previewImg">' + iframeStr + '</div>';
    if (!wd) wd = w;
    document.getElementById("popupTitle").innerHTML = 'Text preview';
    writeDrag.set(e, cntnt, wd, offx, offy);
  } else { // non-capable browsers will open sub window
    w = w+80 || wd || 250; h = h+80 || 250; // size
    win = window.open(fid, 'subwin', 'resizable,width='+w+',height='+h+',left=100,top=100');
    if (win && !win.closed) win.resizeTo(w,h);
    if (win && !win.closed) win.focus();
  }
  return false;
}


function showFileLinks(e, directLinkEnabled, selectionType, w, h, wd, offx, offy) {

    var f="";
    var filesCount=0;
    var sharedDirsCount =0;
    var notSharedDirsCount = 0;

    var el = document.getElementsByTagName("input");
    for (i = 0; i < el.length; i++) {
        var elem = el[i];
        if (elem.type != 'checkbox' || elem.name == null || elem.value == null || elem.value == 'undefined' || !elem.checked) {
            continue;
        }
        if (elem.name == 'ch_f') {
            f += "f=" + elem.value + "&";
            filesCount++;
        }
        if (elem.name == 'ch_d') {
            if (document.getElementById("ch_sd_id_" + elem.value)) {
                f += "d=" + elem.value + "&";
                sharedDirsCount++;
            } else {
                f += "nsd=" + elem.value + "&";
                notSharedDirsCount++;
            }
        }
    }
    if (f.length==0)  {
     alert('Please select files or folders you would like to get links to.');
     return;
     }
     if (filesCount==0 && sharedDirsCount==0 && notSharedDirsCount > 0) return;
    
    if (directLinkEnabled=='true') {
        f+="dl=true";
    } else {
        f+="dl=false";
    }
    if (selectionType=='select') {
       f+="&st=sel";
    } else {
       f+="&st=upl";
    }
    f = "&"+f;
    var aj = new AjaxHelper();
    aj.sendGetTextRequest('/account/fileLinksOnSelectOrUpload.jsp?sId=YQIwgnp1vhp1J8Ye'+f
      ,
      function(linksStr){
          var cntnt, win, str;
          if (dragObj.supported && typeof document.body.innerHTML != "undefined" ) {//****************
            cntnt = '<div class="previewImg">' + linksStr + '</div>';
            if (!wd) wd = w;
            document.getElementById("popupTitle").innerHTML = 'File links';
            //writeDrag.s
            writeDrag.set(e, cntnt, wd, offx, offy);
            setupAllTabs();
          } else { // non-capable browsers will open sub window
            w = w+80 || wd || 250; h = h+80 || 250; // size
            win = window.open(fid, 'subwin', 'resizable,width='+w+',height='+h+',left=100,top=100');
            if (win && !win.closed) win.resizeTo(w,h);
            if (win && !win.closed) win.focus();
          }

      }
    );


/*
  if (dragObj.supported && typeof document.body.innerHTML != "undefined" ) {/*/
/****************
    cntnt = '<div class="previewImg">' + linksStr + '</div>';
    if (!wd) wd = w;
    document.getElementById("popupTitle").innerHTML = 'File links';
    writeDrag.s
    writeDrag.set(e, cntnt, wd, offx, offy);
    setupAllTabs();
  } else { // non-capable browsers will open sub window
    w = w+80 || wd || 250; h = h+80 || 250; // size
    win = window.open(fid, 'subwin', 'resizable,width='+w+',height='+h+',left=100,top=100');
    if (win && !win.closed) win.resizeTo(w,h);
    if (win && !win.closed) win.focus();
  }
*/
  return false;
}



  function openNewWindow(url){
    document.newWindowForm.action=url;
    document.newWindowForm.submit();
  }


  function promptIE7(event, desc, title, baseValue, method, offx, offy, ppEvent, checkName, errMsg){
    var w = 250;
    var h = 250; // size

    if ( dragObj.supported && typeof document.body.innerHTML != "undefined" ) {
      var action = method+"(document.prompt.promptText.value)";
      var cntnt;
      var onSubmit;
      if(checkName){
        onSubmit = 'return quickEditIsValidFileName(this.promptText) ? eval('+action+') : false;';
      }else{
        onSubmit = 'return eval('+action+')';
      }
      try {
        cntnt = '<div class="text"><form name="prompt" onSubmit="' + onSubmit + '" style="padding:5px">';
        cntnt += desc+'<br />';
        cntnt += '<input type="text" name="promptText" maxlength="255" value="'+baseValue+'" style="width:180px" class="xBox"' + (checkName ? ' onkeypress="return quickEditIsValidCharForFileName(event);" ' : '') + ' /> ';
        cntnt += '<input type="submit" value="Ok" style="width:50px" /></form></div>';
        if(checkName){
          cntnt += '<div style="font-size:11px;color:#B02B11 !important"><span style="display:none;" id="editFileNameError">' + errMsg + '</span></div>';
        }
        // class="xBox" is attached to the text element so that mouse were working inside the text as usual
        // (selecting text), not dragging the prompt. If class attribute is needed for design
        // then dw_drag.js must be changed to perform substring, not exact class comparison
        document.getElementById("popupTitle").innerHTML = title;
        writeDrag.set(event, cntnt, w, offx,offy,ppEvent);
        document.prompt.promptText.focus();
        document.prompt.promptText.select();
      }catch (e){
        alert(e);
      }
    } else {
      var oldA = method+"(prompt('"+s+"'))";
      return eval(oldA);
    }
    return false;
  }

  var shareNewDir = 0;

  function promptCreateNewDir(event, desc, title, baseValue, method, offx,offy, ppEvent){
    var w = 250;
    shareNewDir = 1;

    if ( dragObj.supported && typeof document.body.innerHTML != "undefined" ) {
      var action = method+"(document.prompt.promptText.value, shareNewDir)";
      var cntnt;
      try {
        cntnt = '<div class="text"><form name="prompt" onSubmit="return eval('+action+')" style="padding:5px">'+ desc+'<br />'+
            '<input type="text" name="promptText" maxlength="255" value="'+baseValue+'" style="width:180px" class="xBox" /> '+
            '<input type="submit" value="Ok" style="width:50px" />' +
            '<br/>' +
            '<input type="radio" id="promptSharedDir" name="promptSharedDir" class="xBox" onclick="shareNewDir=' + '1' + '" checked="checked" />' +
            '<label class="text" for="promptSharedDir">Share folder</label>' +
            '&nbsp;&nbsp;' +
            '<input type="radio" id="promptSharedDir" name="promptSharedDir" class="xBox" onclick="shareNewDir=' + '0' + '" />' +
            '<label for="promptSharedDir">Do not share</label>' +
            '</form></div>';
        document.getElementById("popupTitle").innerHTML = title;
        writeDrag.set(event, cntnt, w, offx,offy,ppEvent);
        document.prompt.promptText.focus();
        document.prompt.promptText.select();
      }catch (e){
        alert(e);
      }
    } else {
      var oldA = method+"(prompt('"+s+"'))";
      return eval(oldA);
    }
    return false;
  }

  function editFileInfo(e, fileId, dirId, index, offx, offy) {
    var evnt = cloneEventFix(e);
    var w = 348;
    var f='&fId=' + fileId + '&dId=' + dirId + (index != undefined ? '&startPage=' + index : '');
    var aj = new AjaxHelper();
    aj.sendGetTextRequest('/account/editFileInfoForm.jsp?sId=YQIwgnp1vhp1J8Ye'+f
      ,
      function(linksStr){
          var cntnt, win;
          if (dragObj.supported && typeof document.body.innerHTML != "undefined" ) {//****************
            cntnt = '<div class="previewImg">' + linksStr + '</div>';
            document.getElementById("popupTitle").innerHTML = 'Edit info';
            writeDrag.set(evnt, cntnt, w, offx, offy);
            setupAllTabs();
          } else { // non-capable browsers will open sub window
            w = w+80 || wd || 250; h = h+80 || 250; // size
            win = window.open(fid, 'subwin', 'resizable,width='+w+',height='+h+',left=100,top=100');
            if (win && !win.closed) win.resizeTo(w,h);
            if (win && !win.closed) win.focus();
          }
      }
    );
  }

  function cloneEventFix(obj){
    if(obj == null || typeof(obj) != 'object')
      return obj;

    var temp = {};
    for(var key in obj)
      temp[key] = obj[key];

    return temp;
  }

  function promptBigWindowIE7(event, desc, title, baseValue, method,offx,offy, ppEvent){
  var w = 345;
  var h = 450; // size

  if ( dragObj.supported && typeof document.body.innerHTML != "undefined" ) {
    var action = method+"(document.prompt.promptText.value)";
    var cntnt;
    try {
      cntnt = '<div class="text"><form name="prompt" onSubmit="return eval('+action+')" style="padding:5px">'+
              desc+'<br />'+
          '<textarea rows="10" cols="61" name="promptText" style="width:330px" class="xBox">'+baseValue+'</textarea><br />' +
          //'<input type="text" name="promptText" value="'+baseValue+'" style="width:180px" class="xBox" /> '+
          '<div class="alignRight"><input type="submit" value="Ok" style="width:70px" /></div></form></div>';
      // class="xBox" is attached to the text element so that mouse were working inside the text as usual
      // (selecting text), not dragging the prompt. If class attribute is needed for design
      // then dw_drag.js must be changed to perform substring, not exact class comparison
      document.getElementById("popupTitle").innerHTML = title;
      writeDrag.set(event, cntnt, w, offx,offy,ppEvent);
      document.prompt.promptText.focus();
      document.prompt.promptText.select();
    }catch (e){
    alert(e);
  }
  } else {
    var oldA = method+"(prompt('"+s+"'))";
    return eval(oldA);
  }
  return false;




  }

        function promptGetPremium(event, desc, title, baseValue, method, offx,offy, ppEvent){
          var w = 500;
          shareNewDir = 1;
          var prem = '<table cellpadding="10" cellspacing="1" style="background:#FFFFFF"><tr><td style="background:#E6F5FF">'+
              '<b>Premium features:</b><br/>'+
              '<table cellpadding="0" cellspacing="0" width="300" class="oftable">'+
              '<tr>'+
                '<td class="title"><b>Download folder</b></td>'+
                '<td class="detail">Yes</td>'+
              '</tr><tr>'+
              '<tr>'+
                '<td class="title">Premium traffic</td>'+
                '<td class="detail">100GB/month</td>'+
              '</tr><tr>'+
                '<td class="title">No advertising</td>'+
                '<td class="detail">Yes</td>'+
              '</tr><tr>'+
                '<td class="title">Storage Space</td>'+
                '<td class="detail">100GB</td>'+
              '</tr><tr>'+
                '<td class="title">Download limit per 24 hour</td>'+
                '<td class="detail">Unlimited</td>'+
              '</tr></table></td>'+
                '<td align="center" style="background:#E6F5FF"><div style="padding:10px">Activate Premium Account</div>'+
                  '<select class="text xBox" style="width:135px" name="months">'+
                     '<option  value="1">1 month....$9.95/month</option>'+
                     '<option  value="3">3 months....$7.98/month</option>'+
                     '<option  value="6">6 months....$7.16/month</option>'+
                     '<option selected value="12">1 year....$6.50/month</option></select>'+
                   '<div class="btn xBox" onclick="return submitPurchase(\'\', \'downloadAllN\');">Activate &raquo;</div>'+
              
                   '<div class="text"><input name="payment" id="paypal" class="absmid xBox" type="radio" checked="CHECKED"><label for="paypal" class="absmid xBox">PayPal</label>'+
                   '<input name="payment" id="plimus" class="absmid xBox" type="radio"><label for="plimus" class="absmid xBox">Credit card</label></div>'+
              
                '</td>'

          if ( dragObj.supported && typeof document.body.innerHTML != "undefined" ) {
            var action = method+"(document.prompt.promptText.value, shareNewDir)";
            var cntnt;
            try {
              cntnt = '<div class="text">' +
                      '<div style="background:#FFFFFF;color:#5B5B5B;font:normal 12px Arial,sans-serif;padding:15px">'+desc +'</div>'+ prem +
                      '</div>';
              document.getElementById("popupTitle").innerHTML = title;
              writeDrag.set(event, cntnt, w, offx,offy,ppEvent);
            }catch (e){
              alert(e);
            }
          } else {
            var oldA = method+"(prompt('"+s+"'))";
            return eval(oldA);
          }
          return false;
        }
    
    /*

  function promptIE7PrivateMessage(event, desc, title, method,offx,offy, ppEvent){
  var w = 345;
  var h = 450; // size

  if ( dragObj.supported && typeof document.body.innerHTML != "undefined" ) {
    var action = method+"(document.prompt.promptText.value)";
    var cntnt;
    try {
      cntnt = '<div class="text"><form name="prompt" onSubmit="return eval('+action+')" style="padding:5px">'+
              desc+'<br />'+
              'Subject: <input type=" text" name="subj"/><br />'+
          '<textarea rows="10" cols="61" name="promptText" style="width:330px" class="xBox">'+baseValue+'</textarea><br />' +
          //'<input type="text" name="promptText" value="'+baseValue+'" style="width:180px" class="xBox" /> '+
          '<div align="right"><input type="submit" value="Ok" style="width:70px" /></div></form></div>';
      // class="xBox" is attached to the text element so that mouse were working inside the text as usual
      // (selecting text), not dragging the prompt. If class attribute is needed for design
      // then dw_drag.js must be changed to perform substring, not exact class comparison
      document.getElementById("popupTitle").innerHTML = title;
      writeDrag.set(event, cntnt, w, offx,offy,ppEvent);
      document.prompt.promptText.focus();
      document.prompt.promptText.select();
    }catch (e){
    alert(e);
  }
  } else {
    var oldA = method+"(prompt('"+s+"'))";
    return eval(oldA);
  }
  return false;




  }

*/

    function saveBatchChanges() {      
      document.theForm.homemode.value = 33;
      $.post(document.theForm.action, $('#theForm').serialize(), function(data) {
        if (data) {
          if (data.message) {
            alert(data.message);
          }
          if (data.ok ) {            
            changeViewBatchOps();
          } else {
            reloadViewBatchOps();
          }
        }
      }, "json");
      return false;
    }

    function addTags() {
      var tags = $('input[name=tagsToAdd]').get(0).value;
      if(tags == undefined || tags.trim() == '') {
        alert('Please, enter tags to add to each file in current folder.');
      }
      var elems = $('input[type=text][name^=f_tags]');
      elems.each(function() {
        if(this.value == undefined || this.value == '') {
          this.value += tags;
        } else {
          this.value += " "+tags;
        }
      });
    }


