/* couriersite.js -- javascript routines for Couriersite
# Copyright (C) 2009-2010  Jeff Jansen <jeff.jansen@kkoncepts.net>
#
# This file is part of Couriersite.
#
# Couriersite is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Couriersite is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Couriersite.  If not, see <http://www.gnu.org/licenses/>.
*/
var replies_to_list;

window.onload = removeImg;

function removeImg() {
  var deletingImg =  document.getElementById('loading');
  document.getElementById('title').removeChild(deletingImg);
}

function confirm_deactivate(user_name) {
      return confirm('Are you sure you want to deactivate the user "' + user_name + '"?  They will no longer be able to send, receive, or read mail.');
}

function confirm_delete(user_name) {
      return confirm('Are you sure you want to delete the user "' + user_name + '"?  All their mail and calendars will be deleted.  Once done it cannot be undone.');
}

function check_if(is_checked,whichone) {
 var el = document.forms[0].elements[whichone];
 if (is_checked) {
  for (i = 0; i < el.length; i++) {
    el[i].checked = false;
    el[i].disabled = true;
  }
 } else {
  for (i = 0; i < el.length; i++) {
    el[i].disabled = false;
  }
 }
}

function confirm_del_domain(domain_name) {
  if (confirm('Are you sure you want to delete the entire domain, "' + domain_name + '"?  Once deleted it cannot be recovered.')) {
     return confirm("You are about to delete EVERY user and all the mail in this domain.  Are you REALLY sure?  This action cannot be undone.");
  } else {return false;}
}

function confirm_del_list(list_name,num_msg) {
  if (confirm('Are you sure you want to delete the entire mailing list, "' + list_name + '"?  Once deleted, no one will be able to send mail through it.')) {
     if (num_msg > 0) {
       return confirm("There are " + num_msg + " messages in the archive and this will delete ALL of them.  Are you REALLY sure?  This action cannot be undone.");
     } else {return true;}
  }
}

function delroute(maildomain) {
  if (maildomain == '*') {
    return confirm ('Are you sure you want to delete the smart host?');
  } else {
    return confirm ('Are you sure you want the delete the route for mail to "' + maildomain + '"?');
  }
}

function delauth(mailhost) {
    return confirm ('Are you sure you want to delete the authentication information for mail host "' + mailhost + '"?');
}

function check_reply() {
  var choice = document.getElementById('replies').value;
  var el = document.getElementById('hidesender');

  if (choice == 'List') {
    el.disabled = false;
// global variables are automatically assigned to the window object.  Cool!
    el.checked = window.replies_to_list;
  } else {
    replies_to_list= el.checked;
    el.checked = false;
    el.disabled = true;
  }
}

function check_bcc() {
  var el = document.getElementById('aliasreply');

  if (document.getElementById('bcc').checked) {
    el.disabled = false;
  } else {
    el.checked = false;
    el.disabled = true;
  }
}

function deluser(user_name) {
  if (confirm('Are you sure you want to delete the user "' + user_name + '"?')) {
    document.getElementById('del').value = user_name;
    document.getElementById('listform').submit();
  }
}

function delalias(id) {
  var addr = document.getElementById(id).firstChild;
  var deliver = addr.nextSibling;
  var address = addr.textContent;
  var delivery = deliver.textContent;
  var confirmstr = 'Are you sure you want to delete the address "' + address + '" which delivers to "' + delivery + '"?';
  if (delivery.match(/,/)) {
    delivery = ''
    cornfirmstr = 'Are you want to completely delete the alias address "' + address + '"?';
  }
  if (confirm(confirmstr)) {
    document.getElementById('delleft').value = address;
    document.getElementById('delright').value = delivery;
    document.getElementById('aliasform').submit();
  }
}

function check_del_alias(alias) {
  return confirm('Are you sure you want to delete the alias domain "' + alias + '"?');
}

function check_del_forward(addr) {
  return confirm('Are you sure you want to stop forwarding mail to "' + addr + '"?');
}

function check_del_useralias(addr) {
  return confirm('Are you sure you want to remove the alias "' + addr + '"?  Mail to this address will no longer be delivered to this user.');
}

function check_del_spam(addr,list) {
  return confirm('Are you sure you want to remove the address "' + addr + '" from the spam ' + list + '?');
}

function check_del_sender(addr) {
  return confirm('Are you sure you want to remove the address "' + addr + '" from the banned senders list?');
}


function delspamitem(id,whichlist) {
  var addr = 'Trusted Address';
  if (whichlist == 'blacklist') { addr = 'Unsafe Address'; }
  var whichform = document.getElementById('userform') || document.getElementById('domainform') || document.getElementById('spamform');
  var address = document.getElementById(id).firstChild.textContent;
  var confirmstr = 'Are you sure you want to delete the ' + addr + ' "' + address + '"?';
  if (confirm(confirmstr)) {
    document.getElementById('delspamitem').value = address;
    document.getElementById('whichlist').value = whichlist;
    whichform.submit();
  }
}



