EPD = Class.create();

EPD.prototype = {
	initialize: function() {
	}
}

var CMS = {
	
	loginFailed: function (){
        	 $('login_error_msg').innerHTML='Login or password inccorect';
             $('login_error_msg').show(); 
             Windows.focusedWindow.updateHeight();
       	     new Effect.Shake(Windows.focusedWindow.getId()); return false;
        },
        
      showLoginForm:function(){
      	document.write('<div id="login" style="display:none"><p><span id="login_error_msg" class="login_error" style="display:none">&nbsp;</span></p>	<div style="clear:both"></div>		<p><span class="login_label">login</span> <span class="login_input"><input id="username" type="text"/></span></p> <div style="clear:both"></div> <p><span class="login_label">password</span> <span class="login_input"><input id="password" type="password"/></span></p> <div style="clear:both"></div> </div>');
      	
      	Dialog.confirm($('login').innerHTML, {className:"alphacube", width:400, 
                                      okLabel: "login", cancelLabel: "cancel",
                                      onOk:function(win){
                                        xajax_ajaxDispatcher('default', 'user', 'login', [$('username').value, $('password').value]);
                                       }});
      },
      
      getContentForm:function(elementId, type){
      
      	if(type == 'editor'){
      		$('cmsElement-'+elementId).style.display = 'none';
      		$('editButton-'+elementId).style.display = 'none';
      		$('cmsFormElementDIV-'+elementId).style.display = '';
      		$('saveButton-'+elementId).style.display = '';
      	}else{
      
      		Dialog.confirm($('cmsFormElementDIV-'+elementId).innerHTML, {className:"alphacube", width:500, height:null, okLabel: "speichern", cancelLabel: "schliessen", 
        							  onOk:function(win){
                                        CMS.saveFormElement(elementId, type);
                                       }})
      
      	}
      },
      
      getUploadForm:function(elementId){
      	Dialog.info($('cmsFormElementDIV-'+elementId).innerHTML, {className:"alphacube", width:500, height:null})
      },
      
      getPageTitleForm:function(id, value){
      		Dialog.confirm('<input type="text" id="pagetitle" value="'+value+'">', {className:"alphacube", width:500, height:null, okLabel: "speichern", cancelLabel: "schliessen", 
        							  onOk:function(win){
                                        xajax_ajaxDispatcher('default', 'cms', 'updatePageTitle', [$('pagetitle').value, id]);
                                       }})
      
      },
      
      saveFormElement:function(elementId, type, editor){
      	if(editor == null)editor=0;
      	var content = (type == 'editor') ? $('mce_editor_'+editor).contentWindow.document.body.innerHTML : $('cmsFormElement-'+elementId).value;
      	xajax_ajaxDispatcher('default', 'cms', 'updateContent', [elementId, content]);
      },
      
      getNewPageForm:function(parent){
      	Dialog.confirm($('newPageForm').innerHTML, {className:"alphacube", width: 400, height:null, okLabel: "speichern", cancelLabel: "schliessen", 
        							  onOk:function(win){
                                        xajax_ajaxDispatcher('default', 'cms', 'addPage', [$('page').value, parent]);
                                       }})
      },
      
      openMediaManager:function(id, value){
      	window.open('/media/','mediamanager','height=400,width=500');
      },
      
    closeWindows:function() {
    	Windows.closeAllModalWindows();
    	return true;
  	},
  	
  	createNaviSortable:function(){
  		Sortable.create("navilist",{dropOnEmpty:true,handle:'move',constraint:true,onUpdate: function() {  
             xajax_ajaxDispatcher('default','cms','updateNaviPosition',[Sortable.serialize("navilist")]) }});
  	},
  	
  	createSecondNaviSortable:function(){
  	 	Sortable.create("secondnavilist",{dropOnEmpty:true,handle:'move',constraint:true,onUpdate: function() {  
             xajax_ajaxDispatcher('default','cms','updateSecondNaviPosition',[Sortable.serialize("secondnavilist")]) }});
     },
     
     getConfirmDelete: function(id){
     		Dialog.confirm('Seite wirklich l&ouml;schen?', {className:"alphacube", width: 400, height:null, okLabel: "l&ouml;schen", cancelLabel: "schliessen", 
        							  onOk:function(win){
                                        xajax_ajaxDispatcher('default', 'cms', 'deletePage', [id]);
                                       }})
     },
     
     addElementForm: function(id){
     	Dialog.confirm($('newElementForm').innerHTML, {className:"alphacube", width: 400, height:null, okLabel: "speichern", cancelLabel: "schliessen", 
        							  onOk:function(win){
                                        alert(id);
                                        xajax_ajaxDispatcher('default', 'cms', 'addElement', [$('elementSelect').options[$('elementSelect').selectedIndex].value, id]);
                                       }})
     
     },
     
     getMetaDataForm: function(id){
     	Dialog.confirm($('metaDataForm').innerHTML, {className:"alphacube", width: 400, height:null, okLabel: "speichern", cancelLabel: "schliessen", 
        							  onOk:function(win){
    										xajax_ajaxDispatcher('default', 'cms', 'updateMetaData', [$('metatitle').value, $('metadesc').value, $('metakeywords').value, id]);
                                       }})
     },
     
     setPageState:function(state, pageId){
     	if(this.currentPageOnlineState){
     		state = (this.currentPageOnlineState == 1)?0:1;
     	}
    	xajax_ajaxDispatcher('default', 'cms', 'updatePagePropertie', ['state', state, pageId]);
     	this.currentPageOnlineState = state;
     },
     
     openWidget:function(){
     	var display = ($('widget-table').style.display == '')?'none':'';
     	$('widget-table').style.display = display;
     	$('widgetOpen').innerHTML = (display == 'none')?'&ouml;ffnen':'schliessen';
     },
     
     getListForm:function(){
     	var win = new Window({className: "alphaCube", title: "LISTE BEARBEITEN", 
                      top:100, left:100, width:800, height:600, 
                      url: "/news/", showEffectOptions: {duration:1.5}})
		win.show(); 
     },
     
     getModuleContent:function(module, controller, action){
     	xajax_ajaxDispatcher(module, controller, action, []);
     }
}