    var CMS = Class.create();

    CMS.prototype = {
     initialize: function() {
		    this.cmsPopup = null;
	    },

     serviceEdit: function(url, id, target)
     {  
        if (target && target != "_blank")
        {
            if (!confirm(target)) return false;
            new Ajax.Request(url + "&method=delete", { method: 'post', onSuccess: this.serviceEdit_onSuccess.bind(this) });
        }
        else
        {
            this.openWindow(url);
        }
     },

     openWindow: function (url)
     {
	     if (this.cmsPopup == null || this.cmsPopup.closed)
	     {
		     var size= "width=795";
		     size += ",height=540";
		     this.cmsPopup = window.open(url, "Edit", size + ",menubar=yes,toolbar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes");
	     }
	     else
	     {
		     this.cmsPopup.focus();
	     }
     },

     serviceEdit_onSuccess: function(transport)
     {
        if(transport.responseText != '')
        {
            var redirectFeed = window.document.forms[0].feed.value;
            redirectFeed = redirectFeed.substring(0,redirectFeed.indexOf("?")) + "?" + transport.responseText;

            var redirect = window.location.href;
            redirect = redirect.substring(0,redirect.indexOf("?"));

            redirect += "?feed=" + escape(redirectFeed);
            
            window.location = redirect;
        }
        else
        {
            window.location.reload();
        }
     },

     serviceFeed: function (url)
     {
	     var redirect = window.location.href;
         //whack the old querystring off the url
         redirect = redirect.substring(0,redirect.indexOf("?"));
         
	     window.location = redirect + "?feed=" + escape(url);
	     return false;
     },

     servicePackage: function(url)
     {
         window.open(url,'_parent','width=0, height=0, menubar=no,toolbar=no,location=no,resizable=no,scrollbars=no,status=no');
     },
     
     serviceHandler: function (service, url, title, id, target)
     {
	     if ('service.edit' == service)
	     {
		     return this.serviceEdit(url, id, target);
	     }
	     else if ('service.feed' == service)
	     {
		     return this.serviceFeed(url);
	     }
	     else if (('alternate' == service) || ('cms.preview' == service))
	     {
		     this.openWindow(url);
		     return false;
	     }
	     else if ('cms.export' == service)
	     {
		     return this.servicePackage(url);
	     }
     },

     enableSearch: function(feed)
     {
	     $("search").style.visibility="visible";
	     $("search_feed").value = feed;
     },
     
     doSearch: function()
     {
        var url = $('search_feed').value + "&q=" + $('search_query').value;
        return this.serviceFeed(url);
     },

     switchScheme: function (feed, scheme)
     {
	     var redirect = window.location.href;
         //whack the old querystring off the url
         redirect = redirect.substring(0,redirect.indexOf("?"));
         
	     window.location = redirect + "?feed="+escape(feed)+"&scheme=" + escape(scheme);
	     return false;
     }

    }

    var cms = new CMS();

    function getInnerWidth()
    {
	    if (typeof(window.innerWidth) == 'number') return window.innerWidth;
	    else if (document.documentElement && document.documentElement.clientWidth)
		    {
			    return document.documentElement.clientWidth;
		    }
	    else if (document.body && document.body.clientWidth)
		    {																										
			    return document.body.clientWidth;
		    }

	    return 800;
    }

    function getInnerHeight()
    {
	    if (typeof(window.innerHeight) == 'number') return window.innerHeight;
	    else if (document.documentElement && document.documentElement.clientHeight)
		    {
			    return document.documentElement.clientHeight;
		    }
	    else if (document.body && document.body.clientHeight)
		    {																										
			    return document.body.clientHeight;
		    }

	    return 800;
    }

    function close_and_refresh()
    {
	    opener.window.document.forms[0].submit(); 
	    window.close();
    }

