/*
This file is part of Thomas Bley's moregroupware webmail2/calendar2/admin2 module. (tb-mgw)

More information:
-----------------

Simple Groupware Solutions Thomas Bley
Fichtenstr. 23
Germany, 85640 Putzbrunn

Contact:
--------

info@simple-groupware.de

http://www.simple-groupware.de


Copyright 2002-2003 Thomas Bley
tb-mgw is distributed under the terms of the GNU General Public License 

tb-mgw 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 2 of the License, or
(at your option) any later version.

tb-mgw 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 tb-mgw; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

// Maillist
// Moregroupware.org

var marked_one = "";
var marked_count = 0;
var isdone = false;
var nomail_in_view = "";

function ToggleAll() {
  if (document.testform.allbox.value!='checked') {
    document.testform.allbox.value='checked';
    for (i=0,n=document.testform.elements.length;i<n;i++) {
	  if (document.testform.elements[i].type=="checkbox") {
        document.testform.elements[i].checked = true;
		toggle_checkbox(document.testform.elements[i].value);
      }
    }
  } else {
    document.testform.allbox.value='';
    for (i=0,n=document.testform.elements.length;i<n;i++) {
	  if (document.testform.elements[i].type=="checkbox") {
        document.testform.elements[i].checked = false;
		toggle_checkbox(document.testform.elements[i].value);
      }
    }
  }
}

function getElById(idVal) {
  if (document.getElementById != null)
    return document.getElementById(idVal)
  if (document.all != null)
    return document.all[idVal]
  
  alert("Problem getting element by id")
  return null
}

function is_highlighted(element) {
  found = false;
  for (var i = 0; i < highlighted.length; i++) { 
    if (highlighted[i] == element) {
      found = true;
      founder = i;
    }
  }
  if (found) {
    delete highlighted[founder];
    messagecount2--;
  }
  return found; 
}

function clickonmail(theRowNum, mboxid) {
  if (marked_one != theRowNum && marked_one!="") {
  
    theRow2 = document.getElementById('test'+marked_one);
    theCells2 = theRow2.cells;

    for (c = 0; c < theCells2.length; c++) {
      if (c < 7) {
	    if (!document.getElementById('test_chk'+marked_one).checked) {
          theCells2[c].style.backgroundColor = "#E4E4E4";
	    } else {
          theCells2[c].style.backgroundColor = "#CCCCFF";
    }
  } 
  }
}

      theRow = document.getElementById('test'+theRowNum);
        theCells = theRow.cells;

  for (c = 0; c < theCells.length; c++) {
    if (c < 7) {
	  if (!document.getElementById('test_chk'+theRowNum).checked) {
        theCells[c].style.backgroundColor = "#CCEECC";
          } else {
        theCells[c].style.backgroundColor = "#AAEECC";
          }
        
	  if (c == 0 && is_highlighted(theRowNum)) modify_treeframe(account,mbox_id,messagecount,messagecount2);
      theCells[c].style.fontWeight = 'normal';
          }
        }
        marked_one = theRowNum;
    }
    
function re_checkbox(theRowNum) {
  if (theRowNum && document.getElementById('test_chk'+theRowNum)) {
    document.getElementById('test_chk'+theRowNum).checked = !document.getElementById('test_chk'+theRowNum).checked;
                }
        }

function toggle_checkbox(theRowNum) {

  if (!document.getElementById('test'+theRowNum)) return;
  theRow = document.getElementById('test'+theRowNum);
  theCells = theRow.cells;
  
  if (document.getElementById('test_chk'+theRowNum).checked) marked_count++;
	else marked_count++;
  for (c = 0; c < theCells.length; c++) {
    if (c < 7) {
  	  if (document.getElementById('test_chk'+theRowNum).checked && marked_one==theRowNum) {
        theCells[c].style.backgroundColor = "#AAEECC";
	  } else if (document.getElementById('test_chk'+theRowNum).checked && marked_one!=theRowNum) {
        theCells[c].style.backgroundColor = "#CCCCFF";
	  } else if (!document.getElementById('test_chk'+theRowNum).checked && marked_one==theRowNum) {
        theCells[c].style.backgroundColor = "#CCEECC";
	  } else if (!document.getElementById('test_chk'+theRowNum).checked && marked_one!=theRowNum) {
        theCells[c].style.backgroundColor = "#E4E4E4";
}
}
  }
}

function searchsubmit() {
  document.testform.msg_begin.value=1;    
  document.testform.submit();
}

function copysubmit(target,account2) {
  if (document.testform && marked_count > 0) {
      document.testform.folderto.value = target;
      document.testform.action="maillist_modify.php?accountto="+account2+"&account="+account+"&todo=copy";
	  document.testform.submit();
	}
  }

function movesubmit(target,account2) {
  if (document.testform && marked_count > 0) {
      document.testform.folderto.value = target;
      document.testform.action="maillist_modify.php?accountto="+account2+"&account="+account+"&todo=move";
	  document.testform.submit();
	}
  }

function change_flag(value) {
  if (document.testform && marked_count > 0) {
    document.testform.action="maillist_modify.php?account="+account+"&todo=change_flags&value="+value;
	  document.testform.submit();
	}
  }

function reload_treeframe() {
  if (top.frames["treeframe"] && top.frames["treeframe"].is_loaded) {
    top.treeframe.location="tree.php?"+session;
  }
}

function modify_treeframe(account,mbox_id,messagecount,messagecount_unread) {
  if (top.frames["treeframe"] && top.frames["treeframe"].is_loaded) {
    top.treeframe.openfield(account,mbox_id);
    top.treeframe.setreads(account,mbox_id,messagecount,messagecount_unread);
  }
}

function forwardsubmit() {
  if (marked_one!="") {
    document.sendmail.forwardme.value=marked_one;
    document.sendmail.account.value=account;
    document.sendmail.submit();
  } else {
    window.status=nomail_in_view;
  }
}

function forward2submit() {
  if (marked_one!="") {
    document.sendmail.forward.value=marked_one;
    document.sendmail.account.value=account;
    document.sendmail.submit();
  } else {
   window.status=nomail_in_view;
  }
}

function replysubmit() {
  if (marked_one!="") {
    document.sendmail.replyto.value=marked_one;
    document.sendmail.account.value=account;
    document.sendmail.submit();
  } else {
    window.status=nomail_in_view;
  }
}

function replysubmit2() {
  if (marked_one!="") {
    document.sendmail.replyto_all.value=marked_one;
    document.sendmail.account.value=account;
    document.sendmail.submit();
  } else {
    window.status=nomail_in_view;
  }
}

function highlight_firstframe(firstdataset) {
  if (typeof(firstdataset)!="undefined" && firstdataset!="" && parent.frames["mailview"]) {
	clickonmail(firstdataset, mbox_id);
    parent.mailview.location='readmessage.php?account='+account+'&mbox_id='+mbox_id+'&msg_no='+firstdataset+'&'+session;
  } else if (parent.frames["mailview"]) {
    parent.mailview.location='readmessage.php?'+session;
  }
}

function return_height() {
  Browser = navigator.appName;
  if (navigator.appName.substring(0,9) == "Microsoft") Browser = 'MSIE';
  if (Browser != 'MSIE') {
      return (innerHeight-4);
    } else {
      return (document.body.clientHeight-2);
      }
}


