
  /**
   * ###################################################################################
   * +---------------------------------------------------------------------------------+
   * |                             static class Editor                                 |
   * +---------------------------------------------------------------------------------+
   *
   * @author    Markus Huber <m.huber@szene1.at>
   * @version   1.0.0
   * @since     05.04.2007 14:30
   *
   * ###################################################################################
   */

  var Szene1Editor = {
    /**
     * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     *
     * method create
     *
     * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     */
    createSimple: function()
    {
      tinyMCE.init({
        language: "de",
        mode  : "none",
        theme : "simple",
        width : "100%",
        height: "325px"
      });
    },
    createBBCode: function()
    {
      tinyMCE.init({
        language: "de",
        theme : "advanced",
        mode : "none",
        plugins : "bbcode",
        theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,forecolor,removeformat,cleanup,code",
	    theme_advanced_buttons2 : "",
	    theme_advanced_buttons3 : "",
	    theme_advanced_toolbar_location : "bottom",
	    theme_advanced_toolbar_align : "center",
	    //theme_advanced_styles : "Code=codeStyle;Quote=quoteStyle",
	    // content_css : "bbcode.css",
	    entity_encoding : "raw",
	    add_unload_trigger : false,
	    remove_linebreaks : false,
	    width : "100%",
        height: "325px"
	  });
    },
    createAdvanced : function()
    {
      tinyMCE.init({
        language: "de",
        theme : "advanced",
        mode : "textareas",
        plugins : "advimage,media,table,advlink,iframe",
        convert_urls : false,
        accessibility_focus: true,
  		object_resizing: false,
		auto_cleanup_word: true,
  		cleanup_on_startup: true,
  		force_p_newlines : false,
		force_br_newlines : true,
		forced_root_block : false,		
        theme_advanced_buttons1 : "fontsizeselect,bold,italic,underline,removeformat,separator,justifyleft,justifycenter,justifyright,separator,bullist,numlist,separator,forecolor,backcolor,separator,undo,redo,separator,link,unlink",
	    theme_advanced_buttons2 : "tablecontrols,iframe,code",
	    theme_advanced_buttons3 : "",
	    theme_advanced_toolbar_location : "top",
	    theme_advanced_statusbar_location : "bottom",
	    theme_advanced_path : false,
	    theme_advanced_toolbar_align : "center",
	    theme_advanced_resizing : false,
		theme_advanced_resize_horizontal : false,
		file_browser_callback : "ajaxfilemanager",
	    entity_encoding : "raw",
	    add_unload_trigger : false,
	    remove_linebreaks : false,
	    width : "100%",
	    height : "325px",
	    scrollbars : "yes"
	  });
    }
    ,
    createEventAdvanced : function()
    {
      tinyMCE.init({
        language: "de",
        theme : "advanced",
        mode : "textareas",
        plugins : "media, advlink",
        convert_urls : false,
        accessibility_focus: true,
  		object_resizing: false,
		auto_cleanup_word: true,
  		cleanup_on_startup: true,
  		force_p_newlines : false,
		force_br_newlines : true,
		forced_root_block : false,		
        theme_advanced_buttons1 : "charmap,removeformat,bold,italic,separator,justifyleft,justifycenter,justifyright,separator,forecolor,backcolor,separator,bullist,numlist,separator,undo,redo,separator,link,unlink,separator,code",
	    theme_advanced_buttons2 : "",
	    theme_advanced_buttons3 : "",
	    theme_advanced_toolbar_location : "top",
	    theme_advanced_statusbar_location : "bottom",
	    theme_advanced_path : false,
	    theme_advanced_toolbar_align : "center",
	    theme_advanced_resizing : false,
		theme_advanced_resize_horizontal : false,
	    entity_encoding : "raw",
	    add_unload_trigger : false,
	    remove_linebreaks : false,
	    width : "500px",
	    height : "225px",
	    scrollbars : "yes"
	  });
    }
    ,
    createMoreAdvanced : function(width, mode, elements)
    {
      tinyMCE.init({
        language: "de",
        theme : "advanced",
        mode : typeof(mode) == "string" ? mode : "textareas",
        elements : elements,
        plugins : "advimage,table,media,advlink,iframe",
        convert_urls : false,
        remove_script_host : false,
        relative_urls : true,
        accessibility_focus: true,
  		object_resizing: false,
  		cleanup : true,
  		force_p_newlines : false,
		force_br_newlines : true,
		forced_root_block : false,		
        theme_advanced_buttons1 : "iframe,removeformat,bold,italic,strikethrough,separator,justifyleft,justifycenter,separator,bullist,numlist,separator,forecolor,backcolor,image,media,separator,undo,redo,separator,link,unlink,separator,code",
	    theme_advanced_buttons2 : "tablecontrols",
	    theme_advanced_buttons3 : "",
	    theme_advanced_toolbar_location : "top",
	    theme_advanced_statusbar_location : "bottom",
	    theme_advanced_path : false,
	    theme_advanced_toolbar_align : "center",
	    theme_advanced_resizing : true,
		theme_advanced_resize_horizontal : false,
		external_link_list_url : "/js/link_list.js",
		extended_valid_elements : "script[language|type|src],noscript,iframe[align<bottom?left?middle?right?top|class|frameborder|height|id|longdesc|marginheight|marginwidth|name|scrolling<auto?no?yes|src|style|title|width],map[name],area[shape|coords|href|alt|target]",
		file_browser_callback : "ajaxfilemanager",
		media_use_script : false,
	    entity_encoding : "raw",
	    add_unload_trigger : false,
	    remove_linebreaks : false,
	    width : typeof(width) == "string" ? width : "100%"
	  });
    }



  }

  /**
   * ###################################################################################
   * +---------------------------------------------------------------------------------+
   * |                             static class GeoLocator                             |
   * +---------------------------------------------------------------------------------+
   *
   * @author    Markus Huber <m.huber@szene1.at>
   * @version   1.0.0
   * @since     05.04.2007 14:30
   *
   * ###################################################################################
   */

  var GeoLocator = {
    show: function(element)
    {
      if(!element) {
        element = document.body;
      }

      elements    = $(element).getElementsByClassName('GeoLocator');
      var address = '';
      var locate  = false;

      if(elements.length > 0) {
        locate = true;
      }

      elements.each(function(el)
        {

          switch(el.type) {
            case 'select-one':
            case 'textarea':
            case 'text':
              address += el.value + ' ';
            break;
          }
        }
      );

      if(locate) {
        //showAddress(address, element);
      }
    },
    analyseResponse: function(result)
    {
      if (result.Status.code == G_GEO_SUCCESS)
	  {
	    addr    = new Array();

        if(result.Placemark[0].AddressDetails.Country.AdministrativeArea) {
          addr[4] = result.Placemark[0].AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
        }

        if(result.Placemark[0].AddressDetails.Country.AdministrativeArea.SubAdministrativeArea) {
          addr[5] = result.Placemark[0].AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.SubAdministrativeAreaName;

          if(result.Placemark[0].AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode) {
            addr[0] = result.Placemark[0].AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode.PostalCodeNumber;
          } else {
            addr[0] = '';
          }

          if(result.Placemark[0].AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality) {
            addr[1] = result.Placemark[0].AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName;
          } else {
            if(result.Placemark[0].AddressDetails.Country.AdministrativeArea) {
              addr[1] = result.Placemark[0].AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
            } else {
              addr[1] = '';
            }
          }

          if(result.Placemark[0].AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality &&
             result.Placemark[0].AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare) {
            addr[2] = result.Placemark[0].AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName;
          } else {
            addr[2] = '';
          }
        } else {
          addr[0] = '';
          addr[1] = '';
          addr[2] = '';
        }

        if(result.Placemark[0].AddressDetails.Country.Locality) {
          addr[1] = result.Placemark[0].AddressDetails.Country.Locality.LocalityName;
        }

        if(result.Placemark[0].AddressDetails.Country) {
          addr[3] = result.Placemark[0].AddressDetails.Country.CountryNameCode;
        } else {
          addr[3] = '';
        }

	    form     = $('GeoLocatorElement').innerHTML;
	    elements = $(form).getElementsByClassName('GeoLocator');

        if($('GeoLocationLongitude') && $('GeoLocationLatitude')) {
          $('GeoLocationLongitude').value = result.Placemark[0].Point.coordinates[0];
          $('GeoLocationLatitude').value  = result.Placemark[0].Point.coordinates[1];
        }

        elements.each(function(el)
          {
            switch(el.type) {
              case 'select-one':
              case 'textarea':
              case 'hidden':
              case 'text':
/*
                if(el.hasClassName('Zipcode')) {
                  el.value = addr[0];
                }

                if(el.hasClassName('City')) {
                  el.value = addr[1];
                }

                if(el.hasClassName('Street')) {
                  el.value = addr[2];
                }
*/
                if(el.hasClassName('Country')) {
                  el.value = addr[3];
                }

                if(el.hasClassName('AdministrativeArea')) {
                  el.value = addr[4];
                }

                if(el.hasClassName('SubAdministrativeArea')) {
                  el.value = addr[5];
                }
              break;
            }
          }
        );
	  }
    }
  }

  /**
   * ###################################################################################
   * +---------------------------------------------------------------------------------+
   * |                          static class Szene1Window                              |
   * +---------------------------------------------------------------------------------+
   *
   * @author    Markus Huber <m.huber@szene1.at>
   * @version   1.0.0
   * @since     21.04.2007 13:00
   *
   * ###################################################################################
   */

   var Szene1Window = {

    /**
     * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     *
     * method create
     *
     * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     */

    show: function(options, html)
    {
      win = new Window(
        {
          className: options.className,
          title: options.title,
          width: options.width,
          height: options.height,
          destroyOnClose: options.destroyOnClose,
          recenterAuto: options.recenterAuto
        }
      );
      win.setCloseCallback(function(){
	if(typeof(tinyMCE) != "undefined" &&
         tinyMCE.getInstanceById('editorarea'))
       {
         tinyMCE.execCommand('mceFocus', false, 'editorarea');
         tinyMCE.execCommand('mceRemoveControl', false, 'editorarea');
       }
       return true;
     }); 
      win.setHTMLContent(html);
      win.showCenter(options.showCenter);
    },

    closeAll: function()
    {
      Windows.closeAll();
    }
  }

  /*****
  ** FUNC for Szene1Editor Callback
  ***/

    function ajaxfilemanager(field_name, url, type, win)
    {
/* old function for tinyMCE 2.x
			var ajaxfilemanagerurl = "/js/tiny_mce/plugins/ajaxfilemanager/ajaxfilemanager.php";
			switch (type) {
				case "image":
					ajaxfilemanagerurl += "?type=img";
					break;
				case "media":
					ajaxfilemanagerurl += "?type=media";
					break;
				case "flash": //for older versions of tinymce
					ajaxfilemanagerurl += "?type=media";
					break;
				case "file":
					ajaxfilemanagerurl += "?type=files";
					break;
				default:
					return false;
			}
			var fileBrowserWindow = new Array();
			fileBrowserWindow["file"] = ajaxfilemanagerurl;
			fileBrowserWindow["title"] = "Ajax File Manager";
			fileBrowserWindow["width"] = "782";
			fileBrowserWindow["height"] = "440";
			fileBrowserWindow["close_previous"] = "no";
			tinyMCE.openWindow(fileBrowserWindow, {
			  window : win,
			  input : field_name,
			  resizable : "yes",
			  inline : "yes",
			  scrollbars : "yes",
			  editor_id : tinyMCE.getWindowArg("editor_id")
			});

			return false;
*/

/* new function for tinyMCE 3.x */
		     //alert("Field_Name: " + field_name + "\nURL: " + url + "\nType: " + type + "\nWin: " + win); // debug/testing
		
		    /* If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
		       the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
		       These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */
		    if (typeof ajaxFileManagerDestination=="undefined") {
		    	ajaxFileManagerDestination = 'masspns';
		    }
		    
		    tinyMCE.activeEditor.windowManager.open({
		        file : "/js/tiny_mce/plugins/ajaxfilemanager/ajaxfilemanager.php?type=" + type + "&dest=" + ajaxFileManagerDestination,
		        title : 'Ajax File Manager',
		        width : 782,  // Your dimensions may differ - toy around with them!
		        height : 440,
		        resizable : "yes",
		        inline : "yes",  // This parameter only has an effect if you use the inlinepopups plugin!
		        close_previous : "no"
		    }, {
		        window : win,
		        input : field_name
		    });
		    return false;
		}
