function user_Browser() {
	//taken from mail.yahoo.com
	d = document;
	this.agt = navigator.userAgent.toLowerCase();
	this.major = parseInt(navigator.appVersion);
	this.dom = (d.getElementById) ? 1 : 0; // true for ie6, ns6
	this.ns = (d.layers);
	this.ns4up = (this.ns && this.major >=4);
	this.ns6 = (this.dom && navigator.appName=="Netscape");
	this.op = this.agt.indexOf('opera')!=-1;
	this.ie = (d.all);
	this.ie4 = (d.all && !this.dom) ? 1 : 0;
	this.ie4up = (this.ie && this.major >= 4);
	this.ie5 = (d.all && this.dom);
	this.win = ((this.agt.indexOf("win")!=-1) || (this.agt.indexOf("16bit")!=-1));
	this.mac = (this.agt.indexOf("mac")!=-1);
	}

var uB = new user_Browser();

function new_dir(){
	f = document.mwForm;
	if( f.new_dir_name.value = prompt("Please enter the new directory name", "newdir") ){
		return true;
		}
	else {
		return false;
		}
	}

function new_file(){
	f = document.mwForm;
	if( f.new_file_name.value = prompt("Please enter the new file name", "newfile.html") ){
		return true;
		}
	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 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 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 (uB.ie5){
		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--;
				}
			}
		}
	else {
		if(e.checked){
			f.num_sel.value++;
			}
		else {
			f.num_sel.value--;
			}
		}
	}

function open_dir_list(sess_id, current_dir){
	url = "index.php?sid=" + sess_id + "&page=selector" + "&dir=" + current_dir;
	nw = window.open(url, 'newWin', 'scrollbars=yes,status=no,menubar=no,location=no,resizable=yes,width=510,height=300');
	}

function open_file_list(sess_id, current_dir, current_file){
	url = "index.php?sid=" + sess_id + "&page=saveas" + "&new_file_name=" + current_file + "&dir=" + current_dir;
	fw = window.open(url, 'newWin', 'scrollbars=yes,status=yes,menubar=no,location=no,resizable=yes,width=510,height=300');
	}

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>");
	}

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;
	}

