// * chmod helper, Version 1.0
// * by Dan Kaplan <design@abledesign.com>
// * Last Modified: May 24, 2001
// * Bug fixed by VseDoFeNi Oct 6, 2006
// * Edited by NetSpider Feb 14, 2007
// * http://netspider.kiev.ua/
// * --------------------------------------------------------------------
// * Inspired by 'Chmod Calculator' by Peter Crouch:
// * http://wsabstract.com/script/script2/chmodcal.shtml
// *
// * USE THIS LIBRARY AT YOUR OWN RISK; no warranties are expressed or
// * implied. You may modify the file however you see fit, so long as
// * you retain this header information and any credits to other sources
// * throughout the file.  If you make any modifications or improvements,
// * please send them via email to Dan Kaplan <design@abledesign.com>.
// * --------------------------------------------------------------------
//*/

function do_chmod(user) {
	var field4 = user + "4";
	var field2 = user + "2";
	var field1 = user + "1";
	var total = "t_" + user;
	var symbolic = "sym_" + user;
	var number = 0;
	var sym_string = "";

	if (document.chmod[field4].checked == true) { number += 4; }
	if (document.chmod[field2].checked == true) { number += 2; }
	if (document.chmod[field1].checked == true) { number += 1; }

	if (document.chmod[field4].checked == true) {
		sym_string += "r";
	} else {
		sym_string += "-";
	}
	if (document.chmod[field2].checked == true) {
		sym_string += "w";
	} else {
		sym_string += "-";
	}
	if (document.chmod[field1].checked == true) {
		sym_string += "x";
	} else {
		sym_string += "-";
	}

	if (number == 0) { number = ""; }
	document.chmod[total].value = number;
	document.chmod[symbolic].value = sym_string;
  if (document.chmod.t_owner.value == "") document.chmod.t_owner.value = 0;
  if (document.chmod.t_group.value == "") document.chmod.t_group.value = 0;
  if (document.chmod.t_other.value == "") document.chmod.t_other.value = 0;
  
  if (document.chmod.sym_owner.value == "") document.chmod.sym_owner.value = "---";
  if (document.chmod.sym_group.value == "") document.chmod.sym_group.value = "---";
  if (document.chmod.sym_other.value == "") document.chmod.sym_other.value = "---";

	document.chmod.t_total.value = document.chmod.t_owner.value + document.chmod.t_group.value + document.chmod.t_other.value;

	document.chmod.sym_total.value = "-" + document.chmod.sym_owner.value + document.chmod.sym_group.value + document.chmod.sym_other.value;
}
