function demo_version(){
	alert("Sorry, this feature is available only in the Personal version.\nPlease go to www.mywebftp.com for more info.");
	return false;
	}

function new_dir(){
	f = document.mwForm;
	if( f.new_dir_name.value = prompt("Please enter the new directory name", "newdir") ){
		buildAction('newdir');
		}
	else {
		return false;
		}
	}

function new_file(){
	f = document.mwForm;
	if( f.new_file_name.value = prompt("Please enter the new file name", "newfile.html") ){
		buildAction('newtextfile');
		}
	else {
		return false;
		}
	}

function ctl_inc( ctl, val, inc){
	if( ! inc )
		val = -val;
	var old_val = ctl.value;
	if( ! old_val)
		old_val = 0;
//	ctl.value = parseInt(old_val) + parseInt(val);
	ctl.value = format_chmod( parseInt(old_val, 10) + parseInt(val, 10) );
	}

function format_chmod(dig){
	var str = new String('' + dig);
	var final_length = 3;
	var add_length = final_length - str.length;
	for(var i=0; i < add_length; i++){
		str = '0' + str;
		}
	return str;
	}

function fill_chmod( dig, r_ctl, w_ctl, x_ctl){
	var r_mask = 4; var w_mask = 2; var x_mask = 1;
	if( dig & r_mask)
		r_ctl.checked = true;
	if( dig & w_mask)
		w_ctl.checked = true;
	if( dig & x_mask)
		x_ctl.checked = true;
	}

function buildAction(command, tocheck){
	f = document.mwForm;
	f.ftp_action.value = '';
	if(tocheck && f.num_sel.value > 0){
		f.ftp_action.value = command;
		f.submit();
		}
	else if (tocheck){
		alert("Please select files or directories.");
		}
	else {
		f.ftp_action.value = command;
		f.submit();
		}
	f.ftp_action.value = '';
	}

function buildAction2(command, tocheck){
	f = document.mwForm;
	f.ftp_action.value = '';

	if(tocheck && f.num_sel.value <= 0){
		alert('Please select files or directories.');
		}
	else {
		nw = window.open('', 'actionWin', 'scrollbars=yes,status=yes,menubar=no,location=no,resizable=yes,width=590,height=400');
		nw.focus();
		f.ftp_action.value = command;
		f.target = 'actionWin';
		f.submit();
		f.ftp_action.value = '';
		f.target = '';
		}
	}

function fill_anon(){
	f = document.mwForm;
	if (f.anon_check.checked){
		f.ftp_user.value = 'anonymous';
		f.ftp_pass.value = 'some@email.com';
		}
	else {
		f.ftp_user.value = '';
		f.ftp_pass.value = '';
		}
	}

function check_anon(){
	f = document.mwForm;
	if(f.ftp_user.value == 'anonymous'){
		f.anon_check.checked = true;
		}
	else{
		f.anon_check.checked = false;
		}
	}

function setFields(){
	f = document.mwForm;
	for(var i = 0; i < (arguments.length)/2; i++){
		f.elements[arguments[2*i]].value = arguments[2*i+1];
		}
	f.submit();
	}

function checkFields(){
	f = document.mwForm;
	for(var i = 0; i < arguments.length; i++){
		if(! f.elements[ arguments[i] ].value){
			alert('Please fill all the required fields!');
			return false;
			}
		}
	return true;
	}

function sf(dir){
	f = document.mwForm;
//	if(dir){
		f.dir.value = dir;
//		}
	f.submit();
	}

function highlight_all() {
	var f = document.mwForm;
	var len = f.elements.length;
	for (var i = 0; i < len; i++) {
		var e = f.elements[i];
		if ( (e.type == "checkbox") && (e.name != "switcher") ) {
			if(e.checked != f.switcher.checked){
				e.checked = f.switcher.checked;
				highlight(e);
				}
			}
		}
	}

function reset_all(){
	var f = document.mwForm;
	var len = f.elements.length;
	for (var i = 0; i < len; i++) {
		var e = f.elements[i];
		if ( (e.type == "checkbox") && (e.checked) ) {
			e.checked = false;
			if ( e.name != "switcher" ){
				highlight(e);
				}
			}
		}
	}

function highlight(e){
	var table = null;
	f = document.mwForm;
	if (e.parentNode.parentNode.parentNode.parentNode){
		table = e.parentNode.parentNode.parentNode.parentNode;
		}
	else if (e.parentElement.parentElement.parentElement){
		table = e.parentElement.parentElement.parentElement;
		}
	if (table){
		if(e.checked){
			table.className = "listing_high";
			f.num_sel.value++;
			}
		else {
			table.className = "listing";
			f.num_sel.value--;
			}
		}
	}

function open_dir_list(sess_id, current_dir){
	nw = window.open('', 'newWin', 'scrollbars=yes,status=no,menubar=no,location=no,resizable=yes,width=510,height=300');
	nw.document.write("<HTML><BODY><FORM NAME='mwForm' METHOD='POST'>");
	nw.document.write("<INPUT TYPE='hidden' NAME='sid' VALUE='" + sess_id + "'>");
	nw.document.write("<INPUT TYPE='hidden' NAME='dir' VALUE='" + current_dir + "'>");
	nw.document.write("<INPUT TYPE='hidden' NAME='page' VALUE='selector'>");
	nw.document.write("</FORM></BODY></HTML>");
	nw.document.mwForm.submit();
	nw.focus();
	}

function open_file_list(sess_id, current_dir, current_file){
	fw = window.open('', 'newWin', 'scrollbars=yes,status=no,menubar=no,location=no,resizable=yes,width=510,height=300');
	fw.document.write("<HTML><BODY><FORM NAME='mwForm' METHOD='POST'>");
	fw.document.write("<INPUT TYPE='hidden' NAME='sid' VALUE='" + sess_id + "'>");
	fw.document.write("<INPUT TYPE='hidden' NAME='dir' VALUE='" + current_dir + "'>");
	fw.document.write("<INPUT TYPE='hidden' NAME='new_file_name' VALUE='" + current_file + "'>");
	fw.document.write("<INPUT TYPE='hidden' NAME='page' VALUE='saveas'>");
	fw.document.write("</FORM></BODY></HTML>");
	fw.document.mwForm.submit();
	fw.focus();
	}

function open_upload_started(){
	iw = window.open('', 'infoWin', 'scrollbars=no,status=no,menubar=no,location=no,resizable=no,width=200,height=50');
	iw.document.write("<HTML><BODY>");
	iw.document.write("Please wait while the files are being uploaded.");
	iw.document.write("</BODY></HTML>");
	iw.focus();
	}

function ok_button(){
	window.opener.document.mwForm.dest_dir.value = document.mwForm.dest_dir.value;
	window.close();
	}
function cancel_button(){
	window.close();
	}

function save_as(){
	of = window.opener.document.mwForm;
	f = document.mwForm;
	of.dir.value = f.dir.value;
	if(f.new_file_name.value){
		of.name.value = f.new_file_name.value;
		of.action_savefile.click();
		window.close();
		}
	else {
		alert("Please enter the file name!");
		}
	}
function set_file_name(file_name){
	document.mwForm.new_file_name.value = file_name;
	}
