function wlpFrontController(){this._route=null;this._filter=null;this._order=null;this._pager=null;this._method="get";this.ID=null;}wlpFrontController.prototype=new wlpEditListController;wlpFrontController.prototype._load=function(_url){window.location=_url;}

function wlpEditController(){this._route=null;this.ID=null;this.wrapperStr='_d';this.controls=new wlpArrayList();this.messengers=new wlpArrayList();this._filter=null;this._order=null;this._pager=null;}wlpEditController.prototype=new wlpFormController;wlpEditController.prototype.init=function(_id,_r){this.ID=_id;this._route=_r;this.setId(this.ID);};wlpEditController.prototype.setRoute=function(_r){this._route=_r;};wlpEditController.prototype._getAditionalParams=function(){var strURLParam="";var filterParams=null;var orderParams=null;var pagerParams=null;var delimetr="";if(this._filter!=null)filterParams=this._filter.toString();if(this._pager!=null)pagerParams=this._pager.toString();if(this._order!=null)orderParams=this._order.toString();if(filterParams!=null){strURLParam+=delimetr+filterParams;delimetr="&";}if(orderParams!=null){strURLParam+=delimetr+orderParams;delimetr="&";}if(pagerParams!=null){strURLParam+=delimetr+pagerParams;}if(strURLParam=="")return null;return strURLParam;};wlpEditController.prototype.routeAction=function(url){window.location=url;};wlpEditController.prototype.submit=function(){if(this.validate()){var strURL=this._route.toString();var delimetr="&";if(this._route.params.count==0)delimetr="?";var strURLParam=this._getAditionalParams();if(strURLParam!=null){strURL+=delimetr+strURLParam;}$('edit_form_'+this.ID).action=strURL;$('edit_form_'+this.ID).submit();}};wlpEditController.prototype._reset=function(){$('edit_form_'+this.ID).reset();};wlpEditController.prototype.setFilter=function(filter){this._filter=filter;};wlpEditController.prototype.setOrder=function(order){this._order=order;};wlpEditController.prototype.setPager=function(pager){this._pager=pager;}

/**
 * @author Kalapuc Roman (rkalapuc@gmail.com)
 * @copyright Finport Technologies Inc
 * @since 2006
 * @version 1.0
 */

function wlpMessageController(){
	this._filter = null;
	this._order = null;	
	this._pager = null;	
}

wlpMessageController.prototype = new wlpActionController;

wlpMessageController.prototype.routeAction = function(/*String*/ url){
	window.location = url;
}

wlpMessageController.prototype._getAditionalParams = function(){
	var strURLParam = "";
	var filterParams = null;
	var orderParams = null;
	var pagerParams = null;	
	var delimetr = "";	
	
	if (this._filter!=null) filterParams = this._filter.toString(); 
	if (this._pager!=null) pagerParams = this._pager.toString();		
	if (this._order!=null) orderParams = this._order.toString(); 		
	
	if (filterParams!=null){
		strURLParam+=delimetr+filterParams;
		delimetr = "&";
	}

	if (orderParams!=null){
		strURLParam+=delimetr+orderParams;
		delimetr = "&";
	} 
		
	if (pagerParams!=null){
		strURLParam+=delimetr+pagerParams;
	}  
	
	if (strURLParam=="") return null;
		
	return strURLParam;		
}

wlpMessageController.prototype.setFilter = function(/*wlpFilter*/ filter){	
	this._filter = filter;
}

wlpMessageController.prototype.setOrder = function(/*wlpOrder*/ order){
	this._order = order;
}

wlpMessageController.prototype.setPager = function(/*wlpPager*/ pager){	
	this._pager = pager;
}

/**
 * @author Kalapuc Roman (rkalapuc@gmail.com)
 * @copyright Finport Technologies Inc
 * @since 2006
 * @version 1.0
 */

function wlpFilterController(){
	this.ID = null;
	this.wrapperStr = '_f';
	this.controls = null;
	this.messengers = new wlpArrayList();
	this._parent = null;
}

wlpFilterController.prototype = new wlpFormController;

wlpFilterController.prototype.init = function(_id,_controls){
	this.ID = _id;
	this.controls = new wlpArrayList(_controls);
}

wlpFilterController.prototype.setParent = function(/*wlpController*/ _p){
	this._parent = _p;
}

wlpFilterController.prototype.toString = function(){
	
	var strParams="";	
	var listIterator = this.controls.getIterator();
	var isFirst = true;
	
	while (listIterator.hasNext){
		if (!isFirst && listIterator.current.value.length!=0) strParams+="&";
		
		if (listIterator.current.value.length!=0) {
			if (this.wrapperStr!="") strParams+=listIterator.current.toStringWithWrapper(this.wrapperStr+"["+this.ID+"]");
				else strParams+=listIterator.current.toString();
		}
		listIterator.moveNext();
		isFirst = true;
	}
	
	return strParams;	
}

wlpFilterController.prototype._reset = function(){
	this.reset();
	this._parent.filter(new wlpURLParamSet(this.ID,this.wrapperStr,[]));
}

wlpFilterController.prototype.set = function(){
   	if ((typeof(this._parent)!="undefined") && (typeof(this._parent.filter)!="undefined")) {
		var listIterator = this.controls.getIterator();
		var URLParamsArr = new Array();
			
		while (listIterator.hasNext){
			URLParamsArr.push(listIterator.current.asProperty());
			listIterator.moveNext();
		}
        var URLParamSet = new wlpURLParamSet(this.ID,this.wrapperStr,URLParamsArr);
		this._parent.setFilter(URLParamSet);
	}

}

wlpFilterController.prototype.update = function(){
	if ((typeof(this._parent)!="undefined") && (typeof(this._parent.filter)!="undefined")) {
		var listIterator = this.controls.getIterator();
		var URLParamsArr = new Array();
			
		while (listIterator.hasNext){
			URLParamsArr.push(listIterator.current.asProperty());
			listIterator.moveNext();
		}
        var URLParamSet = new wlpURLParamSet(this.ID,this.wrapperStr,URLParamsArr);
		this._parent.filter(URLParamSet);
	}
}

wlpFilterController.prototype.filter = function(){
	if (this.validate()){
		this.update();
	}
}

wlpFilterController.prototype.show = function(){
	Element.toggle('filter_'+this.ID);
}


function wlpFormController(){this.ID=null;this.wrapperStr='_fc';this.controls=null;this.messengers=new wlpArrayList();this.highliter=new wlpBorderChangeMessenger();}wlpFormController.prototype=new wlpActionController;wlpFormController.prototype.setId=function(formId){this.ID=formId;this.highliter.setId(formId);};wlpFormController.prototype.showMessage=function(_message,_control){var listIterator=this.messengers.getIterator();while(listIterator.hasNext){listIterator.current.showMessage(_message,_control);listIterator.moveNext();}};wlpFormController.prototype.validate=function()
{
//alert("validate");
	var listIterator=this.controls.getIterator();
	var i=0;
	while(listIterator.hasNext)
	{
		var _m=listIterator.current.validate();
//alert(_m);
		//if(_m!==true)
		if(false)
		{
//alert("validate m=false");
			this.showMessage(_m,listIterator.current);
			this.highliter.highliteElement(listIterator.current.ID);
			return false;
		}
		else
		{
			this.highliter.unhighliteElement(listIterator.current.ID);
		}
		listIterator.moveNext();
	}return true;
};

wlpFormController.prototype.reset=function(){var listIterator=this.controls.getIterator();while(listIterator.hasNext){listIterator.current.clear();listIterator.moveNext();}};wlpFormController.prototype.refresh=function(){var listIterator=this.controls.getIterator();while(listIterator.hasNext){listIterator.current.refresh();listIterator.moveNext();}};wlpFormController.prototype.addMessenger=function(_m){this.messengers.add(_m);};wlpFormController.prototype.addControl=function(_control){this.controls.add(_control);}

/**
 * @author Kalapuc Roman (rkalapuc@gmail.com)
 * @copyright Finport Technologies Inc
 * @since 2006
 * @version 1.0
 */

function wlpEditListController(){	
	this._route = null;
	this._div = null;
	this._method = "get";
	this._filter = null;
	this._order = null;	
	this._pager = null;
	
	this.ID = null;
}
wlpEditListController.prototype = new wlpActionController;

wlpEditListController.prototype.routeAction = function(/*String*/ url){
	window.location = url;
}

wlpEditListController.prototype._getAditionalParams = function(){
	var strURLParam = "";
	var filterParams = null;
	var orderParams = null;
	var pagerParams = null;	
	var delimetr = "";	
	
	if (this._filter!=null) filterParams = this._filter.toString(); 
	if (this._pager!=null) pagerParams = this._pager.toString();		
	if (this._order!=null) orderParams = this._order.toString(); 		
	
	if (filterParams!=null){
		strURLParam+=delimetr+filterParams;
		delimetr = "&";
	}

	if (orderParams!=null){
		strURLParam+=delimetr+orderParams;
		delimetr = "&";
	} 
		
	if (pagerParams!=null){
		strURLParam+=delimetr+pagerParams;
	}  
	
	if (strURLParam=="") return null;
	
	return strURLParam;	
}

wlpEditListController.prototype.init = function(_id,_r,_d){
	this.ID = _id;
	this._route = _r;
	this._div = _d;
}

wlpEditListController.prototype.setDiv = function(_d){
	this._div = _d;
}

wlpEditListController.prototype.load = function(){
	
	var strURL = this._route.toString();

	var delimetr = "&";
	if (this._route.params.count==0) delimetr="?";
		
	var strURLParam = this._getAditionalParams();
		
	if (strURLParam!=null){
		strURL+=delimetr+strURLParam;
	}
//alert(strURL);
	this._load(strURL);	
}

wlpEditListController.prototype._load = function(/*String*/ _url){
	var ajaxEditItem = new Ajax.Updater(this._div, _url, {method: this._method, evalScripts: true});
}

wlpEditListController.prototype.sort = function(/*wlpProperty*/ param){
	this._order.replace(param);
	this.load();
}

wlpEditListController.prototype.page = function(/*int*/ pageNum){
		//alert(pageNum);
	this._pager.set('page',pageNum);
	this.load();
}

wlpEditListController.prototype.perPage = function(/*int*/ rpp){
	this._pager.set('page',1);
	this._pager.set('rpp',rpp);
	this.load();
}

wlpEditListController.prototype.filter = function(/*wlpURLParamSet*/filter){
	this._filter = filter;
	this.load();
}

wlpEditListController.prototype.setFilter = function(/*wlpFilter*/ filter){	
	this._filter = filter;
}

wlpEditListController.prototype.setOrder = function(/*wlpOrder*/ order){
	this._order = order;
}

wlpEditListController.prototype.setPager = function(/*wlpPager*/ pager){	
	this._pager = pager;
}


function wlpActionController(){}wlpActionController.prototype._getAditionalParams=function(){return null;};wlpActionController.prototype.performAction=function(action){if(action.check()){var strURL=action.url.toString();var noAddParams=action.params.get('no_params');if(noAddParams===false||noAddParams=='0'){var delimetr="&";if(action.url.params.count==0)delimetr="?";var strURLParam=this._getAditionalParams();if(strURLParam!=null){strURL+=delimetr+strURLParam;}}this.routeAction(strURL);}};wlpActionController.prototype.routeAction=function(url){window.location=url;}

function wlpMessageController(){this._filter=null;this._order=null;this._pager=null;}wlpMessageController.prototype=new wlpActionController;wlpMessageController.prototype.routeAction=function(url){window.location=url;};wlpMessageController.prototype._getAditionalParams=function(){var strURLParam="";var filterParams=null;var orderParams=null;var pagerParams=null;var delimetr="";if(this._filter!=null)filterParams=this._filter.toString();if(this._pager!=null)pagerParams=this._pager.toString();if(this._order!=null)orderParams=this._order.toString();if(filterParams!=null){strURLParam+=delimetr+filterParams;delimetr="&";}if(orderParams!=null){strURLParam+=delimetr+orderParams;delimetr="&";}if(pagerParams!=null){strURLParam+=delimetr+pagerParams;}if(strURLParam=="")return null;return strURLParam;};wlpMessageController.prototype.setFilter=function(filter){this._filter=filter;};wlpMessageController.prototype.setOrder=function(order){this._order=order;};wlpMessageController.prototype.setPager=function(pager){this._pager=pager;}

function wlpFilterController(){this.ID=null;this.wrapperStr='_f';this.controls=null;this.messengers=new wlpArrayList();this._parent=null;}wlpFilterController.prototype=new wlpFormController;wlpFilterController.prototype.init=function(_id,_controls){this.ID=_id;this.controls=new wlpArrayList(_controls);};wlpFilterController.prototype.setParent=function(_p){this._parent=_p;};wlpFilterController.prototype.toString=function(){var strParams="";var listIterator=this.controls.getIterator();var isFirst=true;while(listIterator.hasNext){if(!isFirst&&listIterator.current.value.length!=0)strParams+="&";if(listIterator.current.value.length!=0){if(this.wrapperStr!="")strParams+=listIterator.current.toStringWithWrapper(this.wrapperStr+"["+this.ID+"]");else strParams+=listIterator.current.toString();}listIterator.moveNext();isFirst=true;}return strParams;};wlpFilterController.prototype._reset=function(){this.reset();this._parent.filter(new wlpURLParamSet(this.ID,this.wrapperStr,[]));};wlpFilterController.prototype.set=function(){if((typeof(this._parent)!="undefined")&&(typeof(this._parent.filter)!="undefined")){var listIterator=this.controls.getIterator();var URLParamsArr=new Array();while(listIterator.hasNext){URLParamsArr.push(listIterator.current.asProperty());listIterator.moveNext();}var URLParamSet=new wlpURLParamSet(this.ID,this.wrapperStr,URLParamsArr);this._parent.setFilter(URLParamSet);}};wlpFilterController.prototype.update=function(){if((typeof(this._parent)!="undefined")&&(typeof(this._parent.filter)!="undefined")){var listIterator=this.controls.getIterator();var URLParamsArr=new Array();while(listIterator.hasNext){URLParamsArr.push(listIterator.current.asProperty());listIterator.moveNext();}var URLParamSet=new wlpURLParamSet(this.ID,this.wrapperStr,URLParamsArr);this._parent.filter(URLParamSet);}};wlpFilterController.prototype.filter=function(){if(this.validate()){this.update();}};wlpFilterController.prototype.show=function(){Element.toggle('filter_'+this.ID);}

/**
 * @author Kalapuc Roman (rkalapuc@gmail.com)
 * @copyright Finport Technologies Inc
 * @since 2006
 * @version 1.0
 */

function wlpEditController(){
	this._route = null;
	this.ID = null;
	this.wrapperStr = '_d';
	this.controls = new wlpArrayList();
	this.messengers = new wlpArrayList();
	
	this._filter = null;
	this._order = null;	
	this._pager = null;

}

wlpEditController.prototype = new wlpFormController;

wlpEditController.prototype.init = function(/*String*/_id,/*wlpURL*/ _r){
	this.ID = _id;
	this._route = _r;
	this.setId(this.ID);
}

wlpEditController.prototype.setRoute = function(/*wlpURL*/ _r){
	this._route = _r;
}

wlpEditController.prototype._getAditionalParams = function(){
	var strURLParam = "";
	var filterParams = null;
	var orderParams = null;
	var pagerParams = null;	
	var delimetr = "";	
	
	if (this._filter!=null) filterParams = this._filter.toString(); 
	if (this._pager!=null) pagerParams = this._pager.toString();		
	if (this._order!=null) orderParams = this._order.toString(); 		
	
	if (filterParams!=null){
		strURLParam+=delimetr+filterParams;
		delimetr = "&";
	}

	if (orderParams!=null){
		strURLParam+=delimetr+orderParams;
		delimetr = "&";
	} 
		
	if (pagerParams!=null){
		strURLParam+=delimetr+pagerParams;
	}  
	
	if (strURLParam=="") return null;
	
	return strURLParam;
}

wlpEditController.prototype.routeAction = function(/*String*/ url){
	window.location = url;
}

wlpEditController.prototype.submit = function(){
	if (this.validate()){

		var strURL = this._route.toString();

		var delimetr = "&";
		if (this._route.params.count==0) delimetr="?";
		
		var strURLParam = this._getAditionalParams();
		
		if (strURLParam!=null){
			strURL+=delimetr+strURLParam;
		}
		//TODO: get Form object as param. Dont use id 
		$('edit_form_'+this.ID).action = strURL;
		$('edit_form_'+this.ID).submit();
	}
}

wlpEditController.prototype._reset = function(){
	$('edit_form_'+this.ID).reset();
}

wlpEditController.prototype.setFilter = function(/*wlpFilter*/ filter){	
	this._filter = filter;
}

wlpEditController.prototype.setOrder = function(/*wlpOrder*/ order){
	this._order = order;
}

wlpEditController.prototype.setPager = function(/*wlpPager*/ pager){	
	this._pager = pager;
}

function wlpEditListController(){this._route=null;this._div=null;this._method="get";this._filter=null;this._order=null;this._pager=null;this.ID=null;}wlpEditListController.prototype=new wlpActionController;wlpEditListController.prototype.routeAction=function(url){window.location=url;};wlpEditListController.prototype._getAditionalParams=function(){var strURLParam="";var filterParams=null;var orderParams=null;var pagerParams=null;var delimetr="";if(this._filter!=null)filterParams=this._filter.toString();if(this._pager!=null)pagerParams=this._pager.toString();if(this._order!=null)orderParams=this._order.toString();if(filterParams!=null){strURLParam+=delimetr+filterParams;delimetr="&";}if(orderParams!=null){strURLParam+=delimetr+orderParams;delimetr="&";}if(pagerParams!=null){strURLParam+=delimetr+pagerParams;}if(strURLParam=="")return null;return strURLParam;};wlpEditListController.prototype.init=function(_id,_r,_d){this.ID=_id;this._route=_r;this._div=_d;};wlpEditListController.prototype.setDiv=function(_d){this._div=_d;};wlpEditListController.prototype.load=function(){var strURL=this._route.toString();var delimetr="&";if(this._route.params.count==0)delimetr="?";var strURLParam=this._getAditionalParams();if(strURLParam!=null){strURL+=delimetr+strURLParam;}this._load(strURL);};wlpEditListController.prototype._load=function(_url){var ajaxEditItem=new Ajax.Updater(this._div,_url,{method:this._method,evalScripts:true});};wlpEditListController.prototype.sort=function(param){this._order.replace(param);this.load();};wlpEditListController.prototype.page=function(pageNum){this._pager.set('page',pageNum);this.load();};wlpEditListController.prototype.perPage=function(rpp){this._pager.set('page',1);this._pager.set('rpp',rpp);this.load();};wlpEditListController.prototype.filter=function(filter){this._filter=filter;this.load();};wlpEditListController.prototype.setFilter=function(filter){this._filter=filter;};wlpEditListController.prototype.setOrder=function(order){this._order=order;};wlpEditListController.prototype.setPager=function(pager){this._pager=pager;}

