

function ltrim(string)
  {
    string=new String(string);
    var string1=new Array();
    var i,j;
    for(i=0,j=0;i<string.length;i++)
    {
      if(j==0)
      {
        if(string.charAt(i)!=" ")
        {
            string1[j++]=string.charAt(i);
        }
      }
      else
      {
        string1[j++]=string.charAt(i);
      }
        
    }
    string="";
    for(i=0;i<string1.length;i++)
    {
      string+=string1[i];
    } 
    return string;
  }

function rtrim(string)
  {
    string=new String(string);
    var string1=new Array();
    var i,j;
    for(i=string.length;i>=0;i--)
    {
      if(string.charAt(i-1)==" ")
      {
        continue;
      }
      else
      {
        for(j=0;j<i;j++)
        {
          string1[j]=string.charAt(j);
        }
        break;
      }
        
    }
    string="";
    for(i=0;i<string1.length;i++)
    {
      string+=string1[i];
    }
    
    
    return string;
  }
  
  function trim(string)
  {
    string=ltrim(string); // // This function is used to trim the left side of a String
    string=rtrim(string);// This function is used to trim the right side of a String
    return string;
  }

//////////////////////////////////////////////////////////////////////////////////////////////////////



function submitforgotpwd()
{
	var regex = /^[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
	
	if(trim(document.frmforgotpwd.txtemail.value).length<1)
    {
      alert("Please enter email address");
      document.frmforgotpwd.frmclient.focus();
    }
	else if(!regex.test(document.frmforgotpwd.txtemail.value))
	{
      alert("Please enter a valid email address");
      document.frmforgotpwd.txtemail.focus();
    }
	else
	{
		document.frmforgotpwd.submit();
	}
}

function submitlogin()
{
	if(trim(document.frmlogin.txtusername.value).length<1)
    {
      alert("Please enter username");
      document.frmlogin.txtusername.focus();
    }
	else if(trim(document.frmlogin.txtpasswd.value).length<1)
    {
      alert("Please enter password");
      document.frmlogin.txtpasswd.focus();
    }
	else
	{
		var retval=userObj__login(document.frmlogin.txtusername.value,document.frmlogin.txtpasswd.value,{type:"r"})
		
		if(retval==0)
		  alert("invalid username/password");
		else
		  document.location.href="login.php?uid="+retval; 
	}
}


function userselectdir(dirname)
{
	document.getElementById('txtseldirname').value=dirname;
	document.frmdirlist.submit();
	/*var clientdirpath=document.getElementById('clientdirpath').value;
	var clienthomedir=document.getElementById('clienthomedir').value;
	var userhomedir=document.getElementById('userhomedir').value;
	var userseldirpath=clientdirpath+clienthomedir+"/"+userhomedir+"/"+dirname;
	
	alert(userseldirpath);*/
}

function submitnewdir()
{	 
	var re = /^[\w ]+$/;
	
	if(trim(document.frmnewdir.txtdirname.value).length<1)
    {
		alert("Please enter directory name");
      	document.frmnewdir.txtdirname.focus();
    }
	else if(!re.test(document.frmnewdir.txtdirname.value))
	{
		alert("Directory name contains invalid characters!")
		document.frmnewdir.txtdirname.focus();
	}
	else if(trim(document.frmnewdir.txtdirname.value).length>25)
    {
		alert("Directory name should not exceed 25 characters");
      	document.frmnewdir.txtdirname.focus();
    }
	else
	{
		styledPopupClose1();
		document.frmnewdir.submit();
	}
}

function submitfileupload()
{
	
	if(document.theForm.txtclientid.value==0)
    {
      		alert("Please select a client");
			styledPopupClose2();
    }
	else if(document.theForm.txtuserid.value==0)
    {
      		alert("Please select a user");
			styledPopupClose2();
    }
	else if(document.theForm.txtuserseldir2.value==0 || document.theForm.txtuserseldir2.value=="No directory listed")
    {
      		alert("Please select a directory");
			styledPopupClose2();
    }
	else if(trim(document.theForm.myFile.value).length<1)
    {
		alert("Please select a file to upload");
      	document.theForm.myFile.focus();
    }
	else
	{
		
		
		document.theForm.submit();
		setTimeout(toggleDisplay('formfile'),10000);
		//styledPopupClose2();
		//document.getElementById('styled_popup7').style.display='block';
		//var oas = new ActiveXObject("Scripting.FileSystemObject");
		//var file= document.frmnewfile.txtfilename.value;
		/*var e = oas.getFile(file);
        var f = e.size;
        alert(f/1024 + " Kilo-bytes");*/
		//var newWindow=window.open("http://sharemyfiles.co.uk/default.php?file="+file,"Upload Status",        "width=550,height=170,status=1,top=200,scrollbars=1");
	    // newWindow.resizeTo(500,500);
		
		
		
	}
}
function toggleDisplay(divId) {

  var div = document.getElementById(divId);

  div.style.display = "none";

}
function ShowProgress(percent)
{
	
	var cid=document.theForm.txtclientid.value;
	var uid=document.theForm.txtuserid.value;
	var filename=document.theForm.myFile.value;
	var directory=document.theForm.txtuserseldir2.value;
	document.getElementById('upload_status').style.width = percent+'%';
	
	if(percent>=100)
	{   
	    var msg=1;
	   	var url="postfile.php?cid="+cid+"&uid="+uid+"&msg="+msg+"&filenm="+filename+"&directory="+directory;
		document.location.href=url;
		//styledPopupClose2();
	}
}
function userselectfile(filename)
{
	document.getElementById('txtselfilename').value=filename;
	document.frmfilelist.submit();
}

function submitfiledelete()
{
	if(trim(document.frmdeletefile.txtuserselfile3.value).length<1)
    {
		alert("Please select the file to delete");
		styledPopupClose4();
    }
	else
	{
		styledPopupClose4();
		document.frmdeletefile.submit();
	}
}

function submitfilerename()
{
	var fname=trim(document.frmrenamefile.txtfilenewname.value);
	var pos1=fname.lastIndexOf('.');
	
	if(trim(document.frmrenamefile.txtuserselfile2.value).length<1)
    {
		alert("Please select the file to rename");
		styledPopupClose3();
    }
	else if(trim(document.frmrenamefile.txtfilenewname.value).length<1)
    {
		alert("Please enter the new file name");
      	document.frmrenamefile.txtfilenewname.focus();
    }
	else if(trim(document.frmrenamefile.txtfilenewname.value).lastIndexOf('.')<1)
    {
		alert("Please enter the file extension");
      	document.frmrenamefile.txtfilenewname.focus();
    }
	else
	{
		styledPopupClose3();
		document.frmrenamefile.submit();
	}
}

function submitdownload()
{
	if(trim(document.frmdownload.txtuserselfile4.value).length<1)
    {
		alert("Please select the file to download");
    }
	else
	{
		document.frmdownload.submit();
	}
}
function submitfolderdelete()
{
	if(trim(document.frmdeletefolder.txtuserseldir6.value).length<1)
    {
		alert("Please select the folder to delete");
		styledPopupClose6();
    }
	else
	{
		styledPopupClose6();
		document.frmdeletefolder.submit();
	}
}

