/*
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
*/

// Infobox
// Moregroupware.org

var ie4=document.all;
// &&navigator.userAgent.indexOf("Opera")==-1
var ns6=document.getElementById&&!document.all;
var ns4=document.layers;

function showmenu(e,calendar, summary, description, location, dclass, categories, event_start, event_end, organizer, attendee, attendee_non, optional, accepted, declined, tentative, drep,until,days,count,interval){
  var linkset='';
  imgpath="templates/default/media/";

  if (typeof drep == 'undefined') {
    drep='';
	until='';
	days='';
	count='';
	interval='';
  }
  
  seperator='<img src="'+imgpath+'spacer.gif" alt="" width="1" height="3" border="0"><br>';
  seperator2='<img src="'+imgpath+'spacer.gif" alt="" width="1" height="1" border="0"><br>';

  linkset='<table width="350" border="0" cellpadding="0" cellspacing="0"><tr><td><table class="menuskin2">';

  if (summary!="") {
    linkset+='<tr><td valign="top">'+lang_summary+':</td><td style="font-weight: bold">'+summary+'</td></tr>';
  }
  if (calendar!="" && calendar!="Custom") {
    linkset+='<tr><td valign="top">'+lang_calendar+':</td><td>'+calendar+'</td></tr>';
  }

  linkset+='<tr><td colspan="2">'+seperator2+'</td></tr>';
  if (event_start!="" && event_end=="") {
    linkset+='<tr><td valign="top" nowrap>'+lang_all_day+':</td><td style="font-weight: bold">'+event_start+'</td></tr>';
  } else if (event_start!="") {
    linkset+='<tr><td valign="top">'+lang_start+':</td><td style="font-weight: bold">'+event_start+'</td></tr>';
  }
  if (event_end!="") {
    linkset+='<tr><td valign="top">'+lang_end+':</td><td>'+event_end+'</td></tr>';
  }

  if (description!="" || location!="" || dclass!="") {
    linkset+='<tr><td colspan="2">'+seperator2+'</td></tr>';
    if (description!="") {
      linkset+='<tr><td valign="top">'+lang_description+':</td><td style="word-break: break-all;">'+description+'</td></tr>';
    }
    if (location!="") {
      linkset+='<tr><td valign="top">'+lang_location+':</td><td>'+location+'</td></tr>';
    }
    if (dclass!="") {
      linkset+='<tr><td valign="top">'+lang_class+':</td><td>'+dclass+'</td></tr>';
    }
  }
  
  if (categories!="") {
    linkset+='<tr><td valign="top">'+lang_categories+':</td><td>'+categories+'</td></tr>';
  }

  if (drep!="") {
    linkset+='<tr><td colspan="2">'+seperator2+'</td></tr>';
    linkset+='<tr><td valign="top">'+lang_repetitions+':</td><td>'+drep+'</td></tr>';
	if (until!="") {
      linkset+='<tr><td valign="top">'+lang_until+':</td><td>'+until+'</td></tr>';
	}
	if (days!="") {
      linkset+='<tr><td valign="top">'+lang_days+':</td><td>'+days+'</td></tr>';
	}
	if (count!=0) {
      linkset+='<tr><td valign="top">'+lang_count+':</td><td>'+count+'</td></tr>';
	}
	if (interval!=1) {
      linkset+='<tr><td valign="top">'+lang_interval+':</td><td>'+interval+'</td></tr>';
    }
  }
	
  if (organizer!="" || attendee!="" || attendee_non!="" || optional!="") {
    linkset+='<tr><td colspan="2">'+seperator2+'</td></tr>';
	if (organizer!="") {
      linkset+='<tr><td valign="top">'+lang_organizer+':</td><td>'+organizer+'</td></tr>';
	}
	if (attendee!="") {
      linkset+='<tr><td valign="top">'+lang_attendee+':</td><td>'+attendee+'</td></tr>';
	}
	if (attendee_non!="") {
      linkset+='<tr><td valign="top">'+lang_attendee_non+':</td><td>'+attendee_non+'</td></tr>';
	}
	if (optional!="") {
      linkset+='<tr><td valign="top">'+lang_optional+':</td><td>'+optional+'</td></tr>';
	}
    if (accepted!="" || declined!="" || tentative!="") {
	  linkset+='<tr><td colspan="2">'+seperator2+'</td></tr>';
	  if (accepted!="") {
        linkset+='<tr><td valign="top">'+lang_accepted+':</td><td>'+accepted+'</td></tr>';
	  }
	  if (declined!="") {
        linkset+='<tr><td valign="top">'+lang_declined+':</td><td>'+declined+'</td></tr>';
	  }
	  if (tentative!="") {
        linkset+='<tr><td valign="top">'+lang_tentative+':</td><td>'+tentative+'</td></tr>';
	  }
	}
  }
  
  linkset+='</table></td></tr></table>';
  linkset+=seperator
  
  which=linkset;
  
  if (!document.all&&!document.getElementById&&!document.layers) return

  clearhidemenu()
  menuobj=ie4? document.all.popmenu : ns6? document.getElementById("popmenu") : ns4? document.popmenu : ""
  menuobj.thestyle=(ie4||ns6)? menuobj.style : menuobj

  if (ie4||ns6) { 

  menuobj.innerHTML=which; 
  } else {
      menuobj.document.write('<layer name=gui bgColor=#E6E6E6 width=100 onmouseover="clearhidemenu()" onmouseout="hidemenu()">'+which+'</layer>')
      menuobj.document.close()
  }

  menuobj.contentwidth=(ie4||ns6)? menuobj.offsetWidth : menuobj.document.gui.document.width
  menuobj.contentheight=(ie4||ns6)? menuobj.offsetHeight : menuobj.document.gui.document.height
  eventX=ie4? event.clientX : ns6? e.clientX : e.x
  eventY=ie4? event.clientY : ns6? e.clientY : e.y

  eventX = eventX+30;
  
  //Find out how close the mouse is to the corner of the window
  var rightedge=ie4? document.body.clientWidth-eventX : window.innerWidth-eventX
  var bottomedge=ie4? document.body.clientHeight-eventY : window.innerHeight-eventY

    menuobj.thestyle.left=ie4? document.body.scrollLeft+eventX : ns6? window.pageXOffset+eventX : eventX
    menuobj.thestyle.top=ie4? document.body.scrollTop+event.clientY : ns6? window.pageYOffset+eventY : eventY;

  if (ie4||ns6||ns4) {
    hidemenu();
    if (window.delayhide2) { clearTimeout(delayhide2); }
    if (window.delayhide) { clearTimeout(delayhide); }

    delayhide2=setTimeout("showmenu2()",10);
  }

  return false;
}

function showmenu2(){
  menuobj.thestyle.visibility="visible"
}

function contains_ns6(a, b) {
  //Determines if 1 element in contained in another- by Brainjar.com
  while (b.parentNode) {
    if ((b = b.parentNode) == a) {
      return true;
    }
  }
  return false;
}

function hidemenu(){
  if (window.menuobj) menuobj.thestyle.visibility=(ie4||ns6)? "hidden" : "hide"
}

function dynamichide(e){
if (ie4&&!menuobj.contains(e.toElement)) { hidemenu(); }
  else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget)) { hidemenu(); }
}

function delayhidemenu(){
  if (ie4||ns6||ns4) {
    if (window.delayhide2) { clearTimeout(delayhide2); }
    delayhide=setTimeout("hidemenu()",100);
  }
}

function clearhidemenu() {
  if (window.delayhide) { clearTimeout(delayhide); }
}

function highlightmenu(e,state){
  if (document.all) {
    source_el=event.srcElement;
  } else if (document.getElementById) {
    source_el=e.target
  }
}
