
SimpleTogglePanel = Class.create();

SimpleTogglePanel.prototype = {
	initialize: function(panelId, status) {
	
		this.panelId = panelId;
       this.panelId_head = panelId+"_header";
        this.status = status;
        if (!this.status){
          this.status="true";
        }

//		this.timer = setTimeout(this.windowOnLoad.bind(this), 100);

	},
	
/*	windowOnLoad: function(){
	  if (RichFaces.navigatorType() == "MSIE"){
		var body = $(this.panelId+"_body");
		 if (body && body.style.display!="none") body.firstChild.style.width=body.clientWidth;
*/
		 
/*    	    if ($(this.panelId_head).clientWidth<$(this.panelId).clientWidth){
               $(this.panelId_head).style.width=$(this.panelId).clientWidth-2+"px";
	    }
	  }
	},
*/
	
	toggleToState: function() {
		var body = $(this.panelId+"_body");
		var switch_on = $(this.panelId+"_switch_on");
		var switch_off = $(this.panelId+"_switch_off");
		if (this.status=="false"){
		 	 Element.show(body);
	         this.status="true";
	         switch_off.style.display="none";
	         switch_on.style.display="";
//			 this.timer = setTimeout(this.windowOnLoad.bind(this), 100);
//		 	 body.firstChild.style.width=body.clientWidth;
	    } else {
	 		 Element.hide(body);
             this.status="false";
	         switch_on.style.display="none";
	         switch_off.style.display="";
                 
		}
	    if (RichFaces.navigatorType() == "MSIE"){
/*    	      if ($(this.panelId_head).clientWidth<$(this.panelId).clientWidth){
                 $(this.panelId_head).style.width=$(this.panelId).clientWidth-2+"px";
	      }*/
	    }
		$(this.panelId+"_input").value=this.status;
	}
}

SimpleTogglePanelManager = Class.create();

SimpleTogglePanelManager.panels = $H($A({}));

SimpleTogglePanelManager.add = function(value) {
    var tmp = new Object();
    tmp[value.panelId] = value;
    this.panels=this.panels.merge(tmp);
}

SimpleTogglePanelManager.toggleOnServer = function (clientId) {
	var parentForm = A4J.findForm($(clientId + "_header"));
	if(!parentForm || !parentForm.appendChild /* findForm returns surrogate form object */) return;

	var fInput = parentForm[clientId];
	if(!fInput) {
		fInput = document.createElement("input");
		fInput.type = "hidden";
		fInput.name = clientId;
		parentForm.appendChild(fInput);
	}

		var thePanel = this.panels.get(clientId);
		if (thePanel.status==0){
	         thePanel.status=1;
	        } 	
	        else{
                 thePanel.status=0;
		}
	
	fInput.value = thePanel.status;
	parentForm.submit();
	return false;
}

SimpleTogglePanelManager.toggleOnClient = function (panelId) {
	this.panels.get(panelId).toggleToState();
	return false;	
}
