/*  form.js
 Copyright 2008,2009 Erik Bogaerts
 Support site: http://www.zingiri.com

 This file is part of Zingiri Apps.

 Zingiri Apps is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 Zingiri Apps is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with Zingiri Apps; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
		
var zfForm = Class.create({
		
	initialize : function(id,form,edit)
	{
	$("zf_type").value = "";
	$("zf_testform").href='?page=apps_edit&zfaces=form&form='+$("zfformname").value;

	this.zf_i = 1;
	this.zf_a = new Array();
	this.help = new Array();
	this.zf_c = new Array();
	this.zf_o = new Array(); // element options
	this.zf_o['zfmandatory']=new Array();
	this.zf_o['zfsearchable']=new Array();
	this.zf_o['zfsystem']=new Array();
	this.zf_o['zfunique']=new Array();
	this.zf_o['zfreadonly']=new Array();
	this.zf_o['zfhidden']=new Array();
	this.zf_o['zflinks']=new Array();
	this.zf_l = new Array();
	this.zfattributes = new Array();
	
	this.zf_e = new Object();
	this.zf_s = new Array();
	this.name='zf'+id;
	this.form=form;
	this.id=id;
	this.div="zfaces"+id;
	if (edit == null) edit=true;
	this.edit=edit;
	this.signature="form";
	this.rules=new Array();
	this.rule = 0;
	this.field = 0;
	var a;
		
	var c=$(this.name+'control');
	if (c && this.edit) {
		a=c.down('#inp');
		if (a) a.observe('click', this.zfAddElement.bindAsEventListener(this));
		a=c.down('#zf_saveform');
		if (a) a.observe('click', this.zfSaveForm.bindAsEventListener(this));
		a=c.down('#zf_deleteform');
		if (a) a.observe('click', this.zfDeleteForm.bindAsEventListener(this));

		a=c.down('#zfname');
		new Form.Element.Observer(a, 0.2, this.zfChangeName.bindAsEventListener(this));
		a=c.down('#zfformname');
		new Form.Element.Observer(a, 0.2, this.changeFormName.bindAsEventListener(this));
		a=c.down('#zfformtype');
		if (a) a.observe('change', this.zfChangeFormType.bindAsEventListener(this));
		a=c.down('#zfcolumn');
		if (a) a.observe('change', this.zfChangeColumn.bindAsEventListener(this));
		//a=c.down('#zfdeleteelement');
		//if (a) a.observe('click', this.zfDeleteElement.bindAsEventListener(this));
		a=c.down('#zf_addlinks');
		if (a) a.observe('click', this.zfAddLinks.bindAsEventListener(this));
		a=$$('.zfattributes');
		for (i = 0; i < a.length; i++) {
			new Form.Element.Observer(a[i], 0.2, this.changeAttribute.bindAsEventListener(this));
		}
		
		a=c.down('#zfmandatory');
		if (a) a.observe('change', this.zfChange.bindAsEventListener(this));
		a=c.down('#zfsearchable');
		if (a) a.observe('change', this.zfChange.bindAsEventListener(this));
		a=c.down('#zfsystem');
		if (a) a.observe('change', this.zfChange.bindAsEventListener(this));
		a=c.down('#zfunique');
		if (a) a.observe('change', this.zfChange.bindAsEventListener(this));
		a=c.down('#zfhidden');
		if (a) a.observe('change', this.zfChange.bindAsEventListener(this));
		a=c.down('#zfreadonly');
		if (a) a.observe('change', this.zfChange.bindAsEventListener(this));
		a=c.down('#zflinks');
		if (a) a.observe('change', this.zfChangeLinks.bindAsEventListener(this));
		a=c.down('#addrule');
		if (a) a.observe('click', this.zfAddRule.bindAsEventListener(this));
		
		}
	
	}
,

zfAddRule : function() {
	if (!this.field) { alert('active field not set'); return; }
	var type = $("zf_rule").value;
	this.zfLoadRule(type,null,false);
},

zfShowRules : function(id) {
	for (i=0;i<this.rules.length;i++) {
		if ((this.rules[i] != null) && (this.rules[i].id != null)) {
			if (this.rules[i].elementid==id) $(this.rules[i].id).show();
			else $(this.rules[i].id).hide();
		}
	}
},

zfLoadRule : function(type,parameters,hidden) {
	var divRules=$("zfrules");
	var divTag = document.createElement("div");
	divTag.id='zf_rule_'+this.rule;
	divTag.style.width = "100%";
	if (hidden) divTag.style.display='none';
	var divTag1 = document.createElement("div");
	var submitTag = document.createElement("div");
	submitTag.innerHTML = '<a href="#"><img src="'+zfurl+'../images/remove.png" height="16px">'+'</a>';
	submitTag.setAttribute("onclick", this.name+".zfDeleteRule(" + this.rule + ");");
	submitTag.style.position = "relative";
	submitTag.style.cssFloat = submitTag.style.styleFloat = "left";
	submitTag.style.width = "5%";
	divTag1.style.position = "relative";
	divTag1.style.cssFloat = divTag1.style.styleFloat = "left";
	divTag1.style.width = "95%";
	new Ajax.Request(
			zfurl+"getFacesContent.php",
			{
				method : "post",
				parameters : {
					'zf_type' : type,
					'zf_apps_system' : zfAppsSystem,
					'zf_apps_custom' : zfAppsCustom,
					'zf_id' : 'par_'+this.rule,
					'zf_parameters' : Object.toJSON(parameters)
				},
				onComplete : function(request) {
					//alert(request.responseText);
					var js = eval("(" + request.responseText + ")");
					divTag1.innerHTML = js.html;
				}.bind(this)
			});
	divTag.appendChild(submitTag)
	divTag.appendChild(divTag1)
	divRules.appendChild(divTag);
	this.rules[this.rule] = new Object();
	this.rules[this.rule].type=type;
	this.rules[this.rule].id=divTag.id;
	this.rules[this.rule].elementid=this.field;
	
	this.rule++;
},

zfDeleteRule : function(i) {
	$("zfrules").removeChild($(this.rules[i].id));
	this.rules[i].id=null;
},

zfAddElement : function() {
	var maindiv = this.zfFindPosition(this.div);
	var divFaces=$(this.div);
	var divTag = document.createElement("li");
	var type = $("zf_type").value;
	if (type == "") {
		alert('Please select a type of field');
		return;
	}

	divTag.setAttribute("onclick", this.name+".zfActiveField(" + this.zf_i + ");");
	divTag.id = "faces_" + this.zf_i;
	divTag.addClassName("zffieldnormal");

	new Ajax.Request(
			zfurl+"getFacesContent.php",
			{
				method : "post",
				parameters : {
					'zf_type' : type,
					'zf_apps_system' : zfAppsSystem,
					'zf_apps_custom' : zfAppsCustom,
					'zf_id' : this.zf_i
				},
				onComplete : function(request) {
					var js = eval("(" + request.responseText + ")");
					divTag.innerHTML = js.html;
					imgTag=document.createElement("img");
					imgTag.src=zfurl+'../images/remove.png';
					imgTag.height='16';
					linkTag=document.createElement("a");
					linkTag.href='javascript:zf'+this.id+'.zfDeleteElement('+js.id+');void(0);';
					linkTag.addClassName('zfdeletefield');
					linkTag.appendChild(imgTag);
					divTag.appendChild(linkTag);
					this.zfActiveField(this.zf_i-1);
				}.bind(this)
			});

	this.zf_a[this.zf_i] = type;
	this.zf_c[this.zf_i] = type;
	this.zfattributes[this.zf_i] = new Object();

	if (divFaces.down(0)) divFaces.insertBefore(divTag,divFaces.down(0));
	else divFaces.appendChild(divTag);

	if (this.edit) Sortable.create(this.div);
	this.zf_i++;
},

zfDeleteElement : function(id) {
	if (this.zf_o['zfsystem'][id]) {
		alert('This element is system protected and can\'t be deleted.');
		return;
	}
	var divFaces=$(this.div);
	var divtag = $("faces_" + id);
	divFaces.removeChild(divtag);
	this.zf_a[id] = "";
	this.help[id] = "";
	$("zfcontrolfieldedit").hide();
},

zfLoadElement : function(e) {
	
	var maindiv = this.zfFindPosition(this.div);
	var divFaces=$(this.div);
	var divTag = document.createElement("li");
	var type = e.type;
	var id = e.id;

	this.field=id;

	divTag.setAttribute("onclick", this.name+".zfActiveField(" + id + ");");
	divTag.id = "faces_" + id;
	divTag.addClassName("zffieldnormal");
	new Ajax.Request(
			zfurl+"getFacesContent.php",
			{
				method : "post",
				parameters : {
					'zf_type' : type,
					'zf_id' : id,
					'zf_label' : e.label,
					'zf_apps_system' : zfAppsSystem,
					'zf_apps_custom' : zfAppsCustom,
					'zfData' : Object.toJSON(e)
				},
				onComplete : function(request) {
					//alert(request.responseText);
					var js = eval("(" + request.responseText + ")");
					divTag.innerHTML = js.html;
					imgTag=document.createElement("img");
					imgTag.src=zfurl+'../images/remove.png';
					imgTag.height='16';
					linkTag=document.createElement("a");
					linkTag.href='javascript:zf'+this.id+'.zfDeleteElement('+js.id+');void(0);';
					linkTag.addClassName('zfdeletefield');
					linkTag.appendChild(imgTag);
					divTag.appendChild(linkTag);
					if (js.links != null) {
						this.zf_l[id]=js.links;
						for (j in js.links) {
							// alert(j+'='+this.zf_o['zflinks'][id][j].label+'='+js.links[j].type+'='+js.links[j].id);
						}
					} 
				}.bind(this)
			});

	this.zf_a[id] = type;
	this.zf_c[id] = e.column;
	this.zf_o['zfmandatory'][id] = e.mandatory;
	this.zf_o['zfsearchable'][id] = e.searchable;
	this.zf_o['zfsystem'][id] = e.system;
	this.zf_o['zfunique'][id] = e.unique;
	this.zf_o['zfreadonly'][id] = e.readonly;
	this.zf_o['zfhidden'][id] = e.hidden;
	this.zf_o['zflinks'][id] = new Object();
	this.zfattributes[id] = new Object();
	if (e.attributes) this.zfattributes[id]=e.attributes;
	if (e.links != null) {
		this.zf_o['zflinks'][id]=e.links;
	}
	
	this.zf_e[id]=new Object();
	this.zf_e[id]=e;
	
	if (id >= this.zf_i) this.zf_i=id+1;

	divFaces.appendChild(divTag);
	if (this.edit) Sortable.create(this.div);

	// load element rules
	if (e.rules != null) {
		for (i=0;i<e.rules.length;i++) {
			this.zfLoadRule(e.rules[i].type,e.rules[i].parameters,true);
		}
	}

},

updateElement: function(i,v) {
	if (f=='zfsize') {
		if ($('element_'+i+'_1')) $('element_'+i+'_1').size=v;
	}
},

zfActiveField : function(zf_field) {
	$("zfcontrolfieldedit").show();
	zf_field_old=$("zffield").value;
	$("zffield").value = zf_field;
	this.field = zf_field;
	var label = 'zf_' + zf_field + '_name';
	var optionTag;
	if ($("faces_"+zf_field_old)!=null) {
		$("faces_"+zf_field_old).removeClassName("zffieldhighlight");
		$("faces_"+zf_field_old).addClassName("zffieldnormal");
	}
	$("faces_"+zf_field).addClassName("zffieldhighlight");
	$("faces_"+zf_field).removeClassName("zffieldnormal");
	var name = $(label).childNodes[0].nodeValue;
	$("zfname").value = name;
	//$("zf_type").value = this.zf_a[zf_field];
	$("zftypeedit").value = this.zf_a[zf_field];
	$("zfcolumn").value = this.zf_c[zf_field];
	$("zfmandatory").checked = this.zf_o['zfmandatory'][zf_field];
	$("zfsearchable").checked = this.zf_o['zfsearchable'][zf_field];
	$("zfsystem").checked = this.zf_o['zfsystem'][zf_field];
	$("zfunique").checked = this.zf_o['zfunique'][zf_field];
	$("zfreadonly").checked = this.zf_o['zfreadonly'][zf_field];
	$("zfhidden").checked = this.zf_o['zfhidden'][zf_field];
	
	a=$$('.zfattributes');
	for (i = 0; i < a.length; i++) {
		f=a[i].id
		v=this.zfattributes[zf_field][f];
		if (v) {
			if (a[i].type=="text") a[i].value=v;
			if (a[i].type=="checkbox" && v==1) a[i].checked=true;
			if (a[i].type=="checkbox" && v==0) a[i].checked=false;
			this.updateElement(zf_field,v);
		} else {
			if (a[i].type=="text") a[i].value='';
			if (a[i].type=="checkbox") a[i].checked=false;
		}
		if (appsIsAdmin==0 && this.zf_o['zfsystem'][zf_field]==1) a[i].disabled=true;
		else a[i].disabled=false;
	}

	this.zfShowRules(this.field);

	$("zflinks").innerHTML="";
	if (this.zf_l[zf_field] != null) {

		var links=this.zf_l[zf_field];
		for (l in links) {
			var divTag = document.createElement("div");
			divTag.innerHTML=links[l].label;
			var selectTag = document.createElement("select");
			selectTag.setAttribute("id","zflink"+l);
			
			for (j = 1; j < this.zf_i; j++) {

				if (this.zf_e[j] != null) {
					e=this.zf_e[j];
					optionTag = document.createElement("option");
					optionTag.setAttribute("value",j);
					optionTag.innerHTML=e.label;
					selectTag.appendChild(optionTag);
				}
			}
			divTag.appendChild(selectTag);
			$("zflinks").appendChild(divTag);
		}
	}
	
	if (appsIsAdmin==0 && this.zf_o['zfsystem'][zf_field]==1) {
		ro=true;
	} else {
		ro=false;
	}
	$("zfcolumn").disabled=ro;
	//$("zf_type").disabled=ro;
	$("zfmandatory").disabled=ro;
	$("zfsearchable").disabled=ro;
	$("zfunique").disabled=ro;
	$("zfreadonly").disabled=ro;
	$("zfhidden").disabled=ro;
	//$("zfdeleteelement").disabled=ro;
	if (appsIsAdmin==0) $("zfsystem").disabled=true;
	

},

zfChangeLinks : function(e) {
	l=$("zflinks");
	o=Event.element(e).id;
	var zf_field = $("zffield").value;
	var f=$(o);
	this.zf_o['zflinks'][zf_field][o]=f.value;
},

zfChange : function(e) {
	o=Event.element(e).id;
	var zf_field = $("zffield").value;
	var f=$(o);
	var checked=f.checked;
	this.zf_o[o][zf_field]=checked;
},

zfChangeFormType: function() {
	var zf_field = $("zfformtype").value;
	if (zf_field=='service') $("zflabelentity").innerHTML="Service";
	if (zf_field=='DB') $("zflabelentity").innerHTML="Entity"; 
	if (zf_field=='formonly') $("zflabelentity").innerHTML="Form"; 
},

changeFormName : function() {
	$("zf_testform").href='?page=apps_edit&zfaces=form&form='+$("zfformname").value;
},

zfChangeName : function() {
	var zf_field = $("zffield").value;
	var label = 'zf_' + zf_field + '_name';
	if ($(label)==null) return;
	if ($("zfname").value == "") { 
		//alert("Element name can't be empty!"); 
		//$("zfname").value=$(label).childNodes[0].nodeValue;
		//return; 
		}
	$(label).childNodes[0].nodeValue = $("zfname").value;
},

zfChangeColumn : function() {
	var zf_field = $("zffield").value;
	$("zfcolumn").value=$("zfcolumn").value.toUpperCase();
	if ($("zfcolumn").value == "") { 
		alert("Element column can't be empty!");
		$("zfcolumn").value=this.zf_c[zf_field];
		return; 
		}
	this.zf_c[zf_field] = $("zfcolumn").value;
},

changeAttribute : function () {
	var zf_field = $("zffield").value;
	if (zf_field) {
		a=$$('.zfattributes');
		for (i=0; i<a.length; i++) {
			f=a[i].id;
			if (a[i].type=='text') this.zfattributes[zf_field][f]=$(f).value;
			if (a[i].type=='checkbox' && a[i].checked) this.zfattributes[zf_field][f]=1;
			if (a[i].type=='checkbox' && !a[i].checked) this.zfattributes[zf_field][f]=0;
			this.updateElement(zf_field,$(f).value);
		}
	}
},

zfSaveForm : function() {
	var j, p, label, c, ctot, ch, r, s;
	var e = new Object();
	var ec = 0;
	var cc = 0;
	var a = new Object();
	var refframe = this.zfFindPosition(this.div);
	var divTag, parTag;

	if ($("zfformname").value == "") { alert("Form name is mandatory!"); return; }
	if ($("zfformlabel").value == "") { alert("Form label is mandatory!"); return; }
	if ($("zfformentity").value == "") { alert("Entity name is mandatory!"); return; }
	if (this.zf_i <= 1) { alert("Add at least 1 element to your form!"); return; } 
	for (j = 1; j < this.zf_i; j++) {
		if (this.zf_a[j] != null && this.zf_a[j] != "" && $("zf_" + j + "_sf") != null) {
			if (this.zf_e[j] != null) e=this.zf_e[j]; else e=new Object();
			// ec++;
			cc++;
			ec=j;
			
			label = 'zf_' + j + '_name'
			// e = $("zf_" + j);
			frame = this.zfFindPosition("zf_" + j);
			ctot = $("zf_" + j + "_sf").childNodes.length - 1; // remove 1
																// because of
																// clear div
			a[ec] = new Object();
			a[ec].subelements = new Object();
			a[ec].rules = new Object();
			if (this.zf_o['zfmandatory'][ec]) {
				a[ec].mandatory=1;
			} 
			if (this.zf_o['zfsearchable'][ec]) {
				a[ec].searchable=1;
			} 
			if (this.zf_o['zfsystem'][ec]) {
				a[ec].system=1;
			} 
			if (this.zf_o['zfunique'][ec]) {
				a[ec].unique=1;
			} 
			if (this.zf_o['zfreadonly'][ec]) {
				a[ec].readonly=1;
			} 
			if (this.zf_o['zfhidden'][ec]) {
				a[ec].hidden=1;
			} 
			if (this.zf_o['zflinks'][ec]) {
				a[ec].links=this.zf_o['zflinks'][ec];
			} 
			if (this.rules.length > 0) {
				s=0;
				for (r=0;r<this.rules.length;r++) {
					if (this.rules[r].id != null && this.rules[r].elementid==ec) {
						a[ec].rules[s] = new Object();
						a[ec].rules[s].type=this.rules[r].type;
						a[ec].rules[s].parameters = new Array();
						for (p=1;p<=9;p++) {
							if (parTag=$("element_par_"+r+"_"+p)) {
								a[ec].rules[s].parameters[p]=parTag.value;
							}
						}
						s++;
					}
				}
			}
			
			for (c = 1; c <= ctot; c++) {
				a[ec].subelements[c] = new Object();
				a[ec].subelements[c].id = c;
				if ($("element_" + j + "_" + c) != null)
					a[ec].subelements[c].populate = $("element_" + j + "_" + c).value;
				if ($("label_" + j + "_" + c) != null) {
					a[ec].subelements[c].label = $("label_" + j + "_" + c).childNodes[0].nodeValue;
				}
				
				if (e.subelements != null && e.subelements[c] != null && e.subelements[c].sortorder != null)
					a[ec].subelements[c].sortorder=e.subelements[c].sortorder;
				if (e.subelements != null && e.subelements[c] != null && e.subelements[c].hide != null)
					a[ec].subelements[c].hide=e.subelements[c].hide;
			}
			a[ec].id = ec;
			a[ec].label = $(label).childNodes[0].nodeValue;
			a[ec].x = frame[0] - refframe[0];
			a[ec].y = frame[1] - refframe[1];
			a[ec].type = this.zf_a[j];
			a[ec].column = this.zf_c[j];
			a[ec].children = $("zf_" + j + "_sf").childNodes.length;
			a[ec].attributes= new Object();
			attr=$$('.zfattributes');
			for (c=0; c<attr.length; c++) {
				f=attr[c].id;
				a[ec].attributes[f]=this.zfattributes[ec][f];
			}
		}
	}

	if (zfRemote) {
		$('zfremotedata').value=Object.toJSON(a);
		$('zfremoteelementcount').value=cc;
		$('zfremotesortorder').value=Sortable.serialize(this.div);
		$('zfremote').action=zfRemoteUrl;
	} else {
		new Ajax.Request(
			zfurl+"saveForm.php",
			{
				method : "post",
				parameters : {
					zfFormName : $("zfformname").value,
					zfFormLabel : $("zfformlabel").value,
					zfFormType : $("zfformtype").value,
					zfFormEntity : $("zfformentity").value,
					zfElementCount : cc,
					zf_apps_system : zfAppsSystem,
					zf_apps_custom : zfAppsCustom,
					zfData : Object.toJSON(a),
					'zfRemote': zfRemote,
					zfSortOrder : Sortable.serialize(this.div)
				},
				onComplete : function(request) {
					alert(request.responseText);
				}.bind(this)
			});
	}

},

zfDeleteForm : function() {
	new Ajax.Request(
			zfurl+"deleteForm.php",
			{
				method : "post",
				parameters : {
					zf_apps_system : zfAppsSystem,
					zf_apps_custom : zfAppsCustom,
					zfFormName : $("zfformname").value
				},
				onComplete : function(request) {
					alert(request.responseText);
					window.location="?zfaces=summary";
				}.bind(this)
			});

	// history.go(1);
	
},

zfAddLinks : function() {
	var links = new Object();
	links.edit=true;
	links.delete=true;
	links.view=true;
	links.add=true;
	
	if ($("zfformname").value == "") { alert("Form name is mandatory!"); return; }

	new Ajax.Request(
			zfurl+"addLinks.php",
			{
				method : "post",
				parameters : {
					zfFormName : $("zfformname").value,
					zf_apps_system : zfAppsSystem,
					zf_apps_custom : zfAppsCustom,
					zfLinks : Object.toJSON(links),
				},
				onComplete : function(request) {
					alert(request.responseText);
				}.bind(this)
			});

},

zfLoadForm : function(json) {

	this.zf_i = 1;
	this.zf_a = new Array();
	this.zf_c = new Array();
	
	if ($("zfformname")) this.form=$("zfformname").value;
	if (json==null) {
		new Ajax.Request(
			zfurl+"loadForm.php",
			{
				method : "post",
				parameters : {
					zf_apps_system : zfAppsSystem,
					zf_apps_custom : zfAppsCustom,
					zfFormName : this.form
				},
				onComplete : function(request) {  
					//alert(request.responseText);
					this.zfLoadElements(request);
				}.bind(this)
			});
	} else {
		this.zfLoadElements(null,json);
	}
	
},

zfLoadElements : function(request,json) {
	
	if (request!=null) var js = eval("(" + request.responseText + ")");
	else js=json;
	var form = js.formname;
	var elementcount = js.elementcount;
	var j = 1;
	var c = 1;
	var e = new Object();
	if ($("zfformlabel")) $("zfformlabel").value = js.formlabel;
	if ($("zfformtype")) $("zfformtype").value = js.formtype;
	if ($("zfformentity")) $("zfformentity").value = js.formentity;
	for (j in js.data) {
		e = js.data[j];
		
		if (e != null) {
			this.zfLoadElement(e);
			c++;
		}
	}
},

zfFindPosition : function(id) {
	var off = document.getElementById(id);
	var main = $(this.div);
	if (off != null) {
		if (off.offsetParent) {
			curleft = off.offsetLeft;
			curtop = off.offsetTop;
			off = off.offsetParent;
		
			while (off) {
				curleft += off.offsetLeft;
				curtop += off.offsetTop;
				off = off.offsetParent;
			}
		}
		return [ curleft, curtop ];
	} else {
		return [0,0];
	}
},

zfCleanUp : function() {
	$("zfformname").value = "";
	$("zfformlabel").value = "";
	$("zfformtype").value = "";
	$("zfformentity").value = "";
	$("zffield").value = "";
	$("zfname").value = "";
	$("zfcolumn").value = "";
	$("zf_type").value = "";
},

fieldHelp : function() {
	var type=$("zftypeedit").value;
	new Ajax.Request(
			zfurl+"getFieldHelp.php",
			{
				method : "post",
				parameters : {
					'zf_type' : type,
				},
				onComplete : function(request) {
					//alert(request.responseText);
					var js = eval("(" + request.responseText + ")");
					if (js.help) alert(js.help.replace(/#/g,'\n'));
				}.bind(this)
			});
}
})

