

/**
*common JS file to have common method related to pagination and sorting using Manheim Core Base Hibernet Dao.
*/


/**
*
* PagingInfo is javascript class which will be used to pass information to DWR Service layer. 
*/

	function PagingInfo() {
	
	            var totalNoOfRecords;
	            var pageNumber;
	            var pageSize;
	            var sortOrder;
	            var sortColumn;
	}
 

/**
*
*'next' method will open next page. Please note this function is using form with id 'filters' please check accordingly in your form. 
*/
	PagingInfo.prototype.next = function (){
	
						this.pageNumber=parseInt(document.filters.pagingPage.value);
						this.pageSize = parseInt(document.filters.pagingNumberPer.value);
						this.sortColumn = document.filters.sortColumn.value;
						this.sortOrder = document.filters.sortDirection.value;
						this.totalNoOfRecords=document.filters.totalNoOfRecords.value;
						
						var totalPage =parseInt(this.totalNoOfRecords)/parseInt(this.pageSize);
						
							if(totalPage > this.pageNumber)
										{
										
										this.pageNumber=parseInt(this.pageNumber)+1;
										document.filters.pagingPage.value=this.pageNumber;
										
										}
								else 
										{
										
										return false;
										}
						return true;
		}



/**
*
*'previous' method will open previous page. Please note this function is using form with id 'filters' please check accordingly in your form. 
*/
	
	PagingInfo.prototype.previous = function (){
	
						this.pageNumber=parseInt(document.filters.pagingPage.value);
						this.pageSize = parseInt(document.filters.pagingNumberPer.value);
						this.sortColumn = document.filters.sortColumn.value;
						this.sortOrder = document.filters.sortDirection.value;
						this.totalNoOfRecords=document.filters.totalNoOfRecords.value;
						
						
						var totalPage =parseInt(this.totalNoOfRecords)/parseInt(this.pageSize);
							if(parseInt(this.pageNumber) > 1)
										{
										
										this.pageNumber=parseInt(this.pageNumber)-1;
										document.filters.pagingPage.value=this.pageNumber;
										
					
										}
								else 
										{
										
										return false;
										}
							return true;
		}




/**
*
*'next' method will open first page. Please note this function is using form with id 'filters' please check accordingly in your form. 
*/
	
	PagingInfo.prototype.first = function (){
	
						this.pageNumber=parseInt(document.filters.pagingPage.value);
						this.pageSize = parseInt(document.filters.pagingNumberPer.value);
						this.sortColumn = document.filters.sortColumn.value;
						this.sortOrder = document.filters.sortDirection.value;
						this.totalNoOfRecords=document.filters.totalNoOfRecords.value;
						
						
						var totalPage =parseInt(this.totalNoOfRecords)/parseInt(this.pageSize);
						
							if(parseInt(this.pageNumber) > 1)
										{
										this.pageNumber=1;
										document.filters.pagingPage.value=this.pageNumber;
										
										}
								else 
										{
										
										return false;
										}
						return true;
		}



/**
*
*'next' method will open last page. Please note this function is using form with id 'filters' please check accordingly in your form. 
*/
	
	PagingInfo.prototype.last = function (){
		
						this.pageNumber=parseInt(document.filters.pagingPage.value);
						this.pageSize = parseInt(document.filters.pagingNumberPer.value);
						this.sortColumn = document.filters.sortColumn.value;
						this.sortOrder = document.filters.sortDirection.value;
						this.totalNoOfRecords=document.filters.totalNoOfRecords.value;
						
						var totalPage=1;						
						if((parseInt(this.totalNoOfRecords)%parseInt(this.pageSize))==0)
						{
						 totalPage =parseInt(this.totalNoOfRecords)/parseInt(this.pageSize);
						}
						else
						{
						totalPage =parseInt(parseInt(this.totalNoOfRecords)/parseInt(this.pageSize))+1;
						}				
							if(parseInt(this.pageNumber) < totalPage)
										{
										this.pageNumber=parseInt(totalPage);
										document.filters.pagingPage.value=this.pageNumber;
										
										}
								else 
										{
									
										return false;
										}
					return true;
		}



/**
*
*'next' method will open no of records need to be display on one single page. 
*/
	
	PagingInfo.prototype.changeRecordPerPage = function (newPageSize){
						
						this.pageNumber=1;
						this.pageSize = parseInt(document.filters.pagingNumberPer.value);
						this.sortColumn = document.filters.sortColumn.value;
						this.sortOrder = document.filters.sortDirection.value;
						this.totalNoOfRecords=document.filters.totalNoOfRecords.value;
		
						this.pageSize=parseInt(newPageSize);
						document.filters.pagingNumberPer.value=newPageSize;
						document.filters.pagingPage.value=this.pageNumber;
				
		}
		
	
	
	/**
	*Method to set PagingInfo object from JSP. At present it is taking value from form with name 'filters'.
	*
	*/
	PagingInfo.prototype.setPagingInfoData = function (){
						
						this.pageNumber=parseInt(document.filters.pagingPage.value);
						this.pageSize = parseInt(document.filters.pagingNumberPer.value);
						this.sortColumn = document.filters.sortColumn.value;
						this.sortOrder = document.filters.sortDirection.value;
						this.totalNoOfRecords=document.filters.totalNoOfRecords.value;
		}
		
		
		
/**
*
* UserInfo is javascript class which will be used to pass user information to DWR Service layer. 
*/

	function UserInfo() {
	
	            var userName;
	            var email;
	}
	
/**
*
* getUserInfo method will set  user information to user object  
*/
	
	UserInfo.prototype.getUserInfo = function (userName,email){
	                this.userName = userName;
					this.email = email;  
	}
	
	


/**
* Request Parameters which are required for different operations are 
* bound together in this object.
*/
function RequestParamInfo() {
	var showHome;
	var location;
	var locale;
	var locationId;
}

/* Function to read data from the form and set them in JS object */
RequestParamInfo.prototype.getRequestParams = function() {
	this.showHome = document.filters.showHome.value;
	this.location = document.filters.location.value;
	this.locale = document.filters.locale.value;
	this.locationId = document.filters.locationAll.value;
}

/* Function to read data from the JS object  and set them in form's hidder fields */
RequestParamInfo.prototype.setRequestParams = function() {
	document.filters.showHome.value = this.showHome;
	document.filters.location.value = this.location;
	document.filters.locale.value = this.locale;
	document.filters.locationAll.value = this.locationId;
}
