/*
 * Copyright (c) 2008 FIZON GmbH
 * All rights reserved.
 *
 * $Id: fcal.js 1744 2008-08-04 11:54:49Z as $
 */

FCAL = function(title)
{
	/**
	 * construct()
	 */
	this.construct = function(title)
	{
		if (typeof FCAL.SingletonObj != 'undefined')
			return false;

		FCAL.SingletonObj = this;

		this.title = typeof title == 'undefined'
			? 'Kalender'
			: title;

		this.ts = date('U');

		this.ah = new PApp(this);
		this.ah.load();
	}


	/**
	 * __load()
	 */
	this.__load = function()
	{
		/*
        this.ah.menuEntry.addItem(this.ah.menuEntry.title, this.ah.menuEntry.onclick);
		this.ah.menuEntry.addItem('Kategorien');
		this.ah.menuEntry.addItem('Raumverwaltung');
		this.ah.menuEntry.addItem('Rechte');
		*/
		
		/*Druckmenue*/
		this.printObj = new PPopup('Druckauswahl','druck');
		this.printObj.contentUrl = 'ppopup.php?popup=print';
		this.printObj.load();
		this.ah.menuEntry.addItem('Druck',"FCAL.Show_Print()");
	}


	/**
	 * __unload()
	 */
	this.__unload = function()
	{

	}


	/**
	 * __open()
	 */
	this.__open = function()
	{
		this.windows = {};

		this.windows.monate = new PWindow('Monats-Übersicht', 'monate');
		this.windows.monate.contentUrl = 'pwindow.php?window=monate&ts='+this.ts;
		this.windows.monate.display(true);
		this.windows.monate.load();

		this.windows.tag = new PWindow('Tages-Übersicht', 'tag');
		this.windows.tag.contentUrl = 'pwindow.php?window=tag&ts='+this.ts;
		this.windows.tag.display(true);
		this.windows.tag.load();

		this.ah.addWindow(this.windows.monate);
		this.ah.addWindow(this.windows.tag);

		this.termin = Termin.Singleton();
	}


	/**
	 * __close()
	 */
	this.__close = function()
	{
		this.termin.hidden();
	}

	
	/**
	 * tag()
	 */
	this.tag = function(ts)
	{
		this.ts = ts;
    	
		this.windows.tag.contentUrl = 'pwindow.php?window=tag&ts='+this.ts;
    	this.windows.tag.load();

    	this.windows.monate.contentUrl = 'pwindow.php?window=monate&ts='+this.ts;
		this.windows.monate.load();

    	this.termin.hidden();
	}


	/**
	 * create()
	 */
	this.create = function(ts, raum)
	{
		this.termin.create(ts, raum);
	}


	/**
	 * edit()
	 */
	this.edit = function(id, ts)
	{
		this.termin.edit(id, ts);
	}


	this.construct(title);
	
	/**
	 * print
	 */
	this.show_print = function()
	{
		$("print_form").setProperties({
									'onreset': "return FCAL.Close_Print();",
									'onsubmit': "return FCAL.Print();"
									});
		this.printObj.display(true);
		//popup für Parameterabfrage
	}
	
	/**
	 * close Print
	 */
	this.close_print = function()
	{
		this.printObj.load();
		this.printObj.display(false);
		return false;
	}
	
	/**
	 * 
	 */
	this.print = function()
	{
		form = $("print_form");
		if(form.type.value == "print"){
			elements = form.setProperty("target" ,"_blank");		
		}
		setTimeout("FCAL.Close_Print()", 500) ;
		return true;
	}
}




/**
 * FCAL.Get()
 */
FCAL.Get = function()
{
	if (typeof FCAL.SingletonObj == 'undefined') 
		new FCAL;
	return FCAL.SingletonObj;
}


/**
 * FCAL.Tag()
 */
FCAL.Tag = function(ts)
{
	FCAL.Get().tag(ts);
}


/**
 * FCAL.Create()
 */
FCAL.Create = function(ts, raum)
{
	FCAL.Get().create(ts, raum);
}

/**
 * FCAL.Show_Print()
 */
FCAL.Show_Print = function() 
{
	return FCAL.Get().show_print();
}

/**
 * FCAL.Print()
 */
FCAL.Print = function()
{
	return FCAL.Get().print();
}
/**
 * FCAL.Close_print()
 */
FCAL.Close_Print = function()
{
	return FCAL.Get().close_print();
}

/**
 * FCAL.Edit()
 */
FCAL.Edit = function(id, ts)
{
	FCAL.Get().edit(id, ts);
}
