/*
============================
Various Javascript functions
Wally Beben (c) 2006-2008
The Geek Workshop LLC
============================
*/

// Send Comms popup boxes for recipient selection
function SelectSendTo(type) {
	var type = type;
	var sendact = "alert_sendtoselect.php?t=" + type;
	my_window = window.open(sendact,
		"", "channelmode=no, directories=no, menubar=no, scrollbars=1, titlebar=no, toolbar=no, status=no, width=500, height=550");
}


// Validate input box values
function InputValidate(element) {
  if (element.value == "") alert("This Value Cannot be Blank");
}

function CheckAll(exby) {
  var boxes = cBoxes.getElementsByTagName("input");
  for (var i = 0; i < boxes.length; i++) {
    myType = boxes[i].getAttribute("type");
    if ( myType == "checkbox") {
      boxes[i].checked = exby.checked ? true : false;
    }
  }
}
function LCheckAll(exby) {
  var boxes = sBoxes.getElementsByTagName("input");
  for (var i = 0; i < boxes.length; i++) {
    myType = boxes[i].getAttribute("type");
    if ( myType == "checkbox") {
      boxes[i].checked = exby.checked ? true : false;
    }
  }
}
function OnSubmitFormU(tok, tp) {
	var jtok = tok;
	var jtp = tp;
	if(document.pressed == 'userupd') {
		var sendaction = "users.php?g=" + jtok + "&act=upd";
		document.updateu.action = sendaction;
	} else if(document.pressed == 'userdel') {
		var sendaction = "users.php?g=" + jtok + "&act=del";
		alert(sendaction);
		document.updateu.action = sendaction;
	}
}
function msgwin(box, owner, guid) {
	var jbox = box;
	var jowner = owner;
	var jguid = guid;
	var sendact = "msgwin.php?box=" + jbox + "&owner=" + jowner + "&acc=" + jguid;
	my_window = window.open(sendact,
		"msgowner", 
		"channelmode=no, directories=no, menubar=no, resizable=no, titlebar=no, toolbar=no, status=no, width=450, height=340");
}
function msgview(guid) {
	var jguid = guid;
	var sendact = "msgview.php?msg=" + jguid;
	my_window = window.open(sendact,
		"msgowner", 
		"channelmode=no, directories=no, menubar=no, resizable=no, titlebar=no, toolbar=no, status=no, width=450, height=340");
}
function eduser(guid, rowc, type) {
	var jguid = guid;
	var jrowc = rowc;
  var type = type;
	var sendact = "alert_edituser.php?g=" + jguid + "&r=" + jrowc + "&t=" + type;
	my_window = window.open(sendact,
		"msgowner", 
		"channelmode=no, directories=no, menubar=no, resizable=no, titlebar=no, toolbar=no, status=no, width=500, height=420");
}

function cppcontact() {
	var sendact = "asis_cppcontact.php";
	my_window = window.open(sendact,
		"msgowner", 
		"channelmode=no, directories=no, menubar=no, titlebar=no, toolbar=no, status=no, scrollbars=1, width=650, height=600");
}

/*
==================================================================================
The following functions define the popups for list management and editing of users
*/
function sub_adduser(g, l) {
	var g0 = g; var l0 = l;
	var sendact = "sub_adduser.php?g=" + g0 + "&r=" + l0;
	var my_window = window.open(sendact,
		"msgowner", 
		"channelmode=no, directories=no, menubar=no, resizable=no, titlebar=no, toolbar=no, status=no, width=450, height=340");
}
function sub_deluser(g, l) {
	var g0 = g; var l0 = l;
	var sendact = "sub_deluser.php?g=" + g0 + "&r=" + l0;
	var my_window = window.open(sendact,
		"msgowner", 
		"channelmode=no, directories=no, menubar=no, resizable=no, titlebar=no, toolbar=no, status=no, width=450, height=340");
}
function sub_addname(g, l) {
	var g0 = g; var l0 = l;
	var sendact = "sub_addname.php?g=" + g0 + "&r=" + l0;
	var my_window = window.open(sendact,
		"msgowner", 
		"channelmode=no, directories=no, menubar=no, resizable=no, titlebar=no, toolbar=no, status=no, width=450, height=340");
}
function sub_delname(g, l) {
	var g0 = g; var l0 = l;
	var sendact = "sub_delname.php?g=" + g0 + "&r=" + l0;
	var my_window = window.open(sendact,
		"msgowner", 
		"channelmode=no, directories=no, menubar=no, resizable=no, titlebar=no, toolbar=no, status=no, width=450, height=340");
}
function sub_editname(g, l) {
	var g0 = g; var l0 = l;
	var sendact = "sub_editname.php?g=" + g0 + "&r=" + l0;
	var my_window = window.open(sendact,
		"msgowner", 
		"channelmode=no, directories=no, menubar=no, resizable=no, titlebar=no, toolbar=no, status=no, width=450, height=340");
}
function sub_addaccess(g, l) {
	var g0 = g; var l0 = l;
	var sendact = "sub_addaccess.php?g=" + g0 + "&r=" + l0;
	var my_window = window.open(sendact,
		"msgowner", 
		"channelmode=no, directories=no, menubar=no, resizable=no, titlebar=no, toolbar=no, status=no, width=450, height=340");
}
function sub_delaccess(g, l) {
	var g0 = g; var l0 = l;
	var sendact = "sub_delaccess.php?g=" + g0 + "&r=" + l0;
	var my_window = window.open(sendact,
		"msgowner", 
		"channelmode=no, directories=no, menubar=no, resizable=no, titlebar=no, toolbar=no, status=no, width=450, height=340");
}



function deletelist(list) {
	var jlist = list;
	var sendact = "deletelist.php?list=" + jlist;
	var my_window = window.open(sendact,
		"msgowner", 
		"channelmode=no, directories=no, menubar=no, resizable=no, titlebar=no, toolbar=no, status=no, width=450, height=340");
}

// For the Add New User Management Section
function jdoManager(form) {
  var fname = form.firstname.value;
  var lname = form.lastname.value;
  if (fname == "" || lname == "") {
    form.manage[0].checked = true;
    alert ("You must input both a first and last name!");
  } else {
    // set up the relevant uname and password fields
    form.manage[1].checked = true;
    form.uname.value = fname.substr(0, 1) + lname;
    form.upass.value = rPass(8);
  }
}
function rPass(length) {
  chars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789";
  pass = "";
  for(x=0;x<length;x++) {
    i = Math.floor(Math.random() * 59);
    pass += chars.charAt(i);
  }
  return pass;
}

/*
Printing the ASIS Membership Roster
*/
function printroster(mems) {
  var mems = mems;
	var sendact = "alert_printroster.php?t=" + mems;
	var my_window = window.open(sendact,
		"msgowner", 
		"channelmode=no, directories=no, menubar=no, resizable=no, titlebar=no, toolbar=no, status=no, scrollbars=yes, width=800, height=400");
}
function LostPassword() {
	var sendact = "lostpwd.php";
	var my_window = window.open(sendact,
		"msgowner", 
		"channelmode=no, directories=no, menubar=no, resizable=no, titlebar=no, toolbar=no, status=no, scrollbars=yes, width=450, height=350");
}
