var JadeForm = function() {
	var form = document.createElement('form');
	form.method='POST';

	document.body.appendChild(form);
	
	form.AddValue = function(name,value) {
		var input = document.createElement('input');
		input.type='hidden';
		input.name=name;
		input.value=value;
		this.appendChild(input);
	}
	form.SetMethod = function(value) { form.method=value; }
	form.SetAction = function(value) { form.action=value; }
	form.SetTarget = function(value) { form.target=value; }
	
	return form;
}
var JadeReport = function(target) {
	var report={};
	report.reference=null;
	var form = new Jade.Form();
	
	form.target=target;
	form.action='reports/';
	form.report=report;
	
	report.form = form;

	report.AddValue=function(name,value){
		value=value.replace(/'/g, '%27');
		report.form.AddValue(name,value); 
	}
	report.ClearValues=function() {
	    while (report.form.childNodes.length >= 1) { report.form.removeChild( report.form.firstChild ); }
	}
	report.Show=function(clear) {
		
		this.reference = window.open('about:blank',this.form.target);
		this.reference.focus();
		this.form.submit();
		if(typeof(clear)!="undefined" && clear) { this.ClearValues(); }
	}
	report.AddValue('_target',form.target);
	report.AddValue('_action',form.action);
	return report;
}
Jade.LoadLibrary('Form',JadeForm);
Jade.LoadLibrary('Report',JadeReport);