/*****************************************************************************************************/
/*                                                                                                   */
/*                                       'PAGINATION0' CLASS                                         */          
/*                                                                                                   */
/*****************************************************************************************************/

function PAGINATION_GINFO(parent, formObj){
	this.type = "PAGINATION"; 
	this.form = formObj;
	var JSObject = this; //obiecul curent
	this.arr_inputs = ["_inp_page1","_inp_page2"];
	this.arr_btns = ["_inp_btn1","_inp_btn2"];
	this.parent = parent;
	
	this.currentPage = this.form["page"];
	this.noPages = this.form["no_pages"];
			
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                    FUNCTION INIT INPUTS                                           */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.init = function(){
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                          INFORMATION                                              */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		
		if (parseInt(this.noPages.value) > 1){
		
			for (var i=0; i<=1; i++){
				this["_inp_page"+(i+1)] = new INPUTFIELD(this, this.form["inp_page"][i]);
				//if we have button 'GO'
				if (this.form["btn_page"]){
					this["_inp_btn"+(i+1)] = this.form["btn_page"][i];
				}
				
				if (document.getElementById("nextpage"+(i+1)))
					this["_inp_btn_next"+(i+1)] = document.getElementById("nextpage"+(i+1));
				
				if (document.getElementById("prevpage"+(i+1)))
					this["_inp_btn_prev"+(i+1)] = document.getElementById("prevpage"+(i+1));
					
				if (document.getElementById("firstpage"+(i+1)))
					this["_inp_btn_first"+(i+1)] = document.getElementById("firstpage"+(i+1));
				
				if (document.getElementById("lastpage"+(i+1)))
					this["_inp_btn_last"+(i+1)] = document.getElementById("lastpage"+(i+1));
				
			}
			
			this.initActions();
		}
	}
	
	
	
	/*****************************************************************************************************/
	/*                                                                                                   */
	/*                                    FUNCTION INIT ACTIONS                                          */          
	/*                                                                                                   */
	/*****************************************************************************************************/
	this.initActions = function(){
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                           PAGE1 INPUT ACTIONS                                     */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		this._inp_page1.setValidationType("pagination");
		this._inp_page1.setOnKeyUpFunction(function(evt){
													
													//set interval: min 1, max number of pates
													if (parseInt(this.input.value) <= 1){
														this.input.value = 1;
													}
													else if (parseInt(this.input.value) >= parseInt(JSObject.noPages.value)){
														this.input.value = JSObject.noPages.value;
													}
													//copy value to down page input
													JSObject._inp_page2.input.value = this.input.value;
													
													if (window.event){
														var Code = event.keyCode;
														var Event = event;
													}
													else{
														var Code = evt.keyCode;	
														var Event = evt;
													}
													
													//if 'Enter key' pressed, submit
													if (Code == "13"){
														JSObject.currentPage.value = JSObject._inp_page1.input.value;
														JSObject.form.submit();
													}
													
													
													
													});
		this._inp_page1.setOnBlurFunction(function(){
													if (parseInt(this.input.value) <= 1){
														this.input.value = 1;
													}
													
													else if (parseInt(this.input.value) >= parseInt(JSObject.noPages.value)){
														this.input.value = JSObject.noPages.value;
													}
													
													JSObject._inp_page2.input.value = this.input.value;
													
													});
		this._inp_page1.initActions();
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                           PAGE2 INPUT ACTIONS                                     */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		this._inp_page2.setValidationType("pagination");
		this._inp_page2.setOnKeyUpFunction(function(evt){
													
													//set interval: min 1, max number of pates
													if (parseInt(this.input.value) <= 1){
														this.input.value = 1;
													}
													else if (parseInt(this.input.value) >= parseInt(JSObject.noPages.value)){
														this.input.value = JSObject.noPages.value;
													}
													//copy value to up page input
													JSObject._inp_page1.input.value = this.input.value;
													
													
													if (window.event){
														var Code = event.keyCode;
														var Event = event;
													}
													else{
														var Code = evt.keyCode;	
														var Event = evt;
													}
	
													//if 'Enter key' pressed, submit
													if (Code == "13"){
														JSObject.currentPage.value = JSObject._inp_page2.input.value;
														JSObject.form.submit();
													}
													
													
													});
		this._inp_page2.setOnBlurFunction(function(){
													
													if (parseInt(this.input.value) <= 1){
														this.input.value = 1;
													}
													
													else if (parseInt(this.input.value) >= parseInt(JSObject.noPages.value)){
														this.input.value = JSObject.noPages.value;
													}
													
													JSObject._inp_page1.input.value = this.input.value;
													
													});
		this._inp_page2.initActions();
		
		
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                 BUTTON GO ('UP' and 'DOWN') ACTIONS                               */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		//if we have button 'GO'
		if (this.form["btn_page"]){
			for (var i=1; i<=2; i++){
				this["_inp_btn"+i].onclick = function(){
					
					JSObject.currentPage.value = JSObject._inp_page1.input.value;
					JSObject.form.submit();
					
				}
			}
		}
		
		
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                    BUTTON 'NEXT PAGE' ACTIONS                                     */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		for (var i=1; i<=2; i++){
			if (this["_inp_btn_next"+i]){
				this["_inp_btn_next"+i].onclick = function(){
					
					JSObject.currentPage.value = parseInt(JSObject.currentPage.value) + 1;
					JSObject._inp_page1.input.value = JSObject.currentPage.value;
					JSObject._inp_page2.input.value = JSObject.currentPage.value;
					JSObject.form.submit();
					
				}
			}
		}
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                 BUTTON 'PREVIOUS PAGE' ACTIONS                                    */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		for (var i=1; i<=2; i++){
			if (this["_inp_btn_prev"+i]){
				this["_inp_btn_prev"+i].onclick = function(){
					
					JSObject.currentPage.value = parseInt(JSObject.currentPage.value) - 1;
					JSObject._inp_page1.input.value = JSObject.currentPage.value;
					JSObject._inp_page2.input.value = JSObject.currentPage.value;
					JSObject.form.submit();
					
				}
			}
		}
		
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                  BUTTON 'FIRST PAGE' ACTIONS                                      */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		for (var i=1; i<=2; i++){
			if (this["_inp_btn_first"+i]){
				this["_inp_btn_first"+i].onclick = function(){
					
					JSObject.currentPage.value = 1;
					JSObject._inp_page1.input.value = JSObject.currentPage.value;
					JSObject._inp_page2.input.value = JSObject.currentPage.value;
					JSObject.form.submit();
					
				}
			}
		}
		
		
		/*****************************************************************************************************/
		/*                                                                                                   */
		/*                                  BUTTON 'LAST PAGE' ACTIONS                                       */          
		/*                                                                                                   */
		/*****************************************************************************************************/
		for (var i=1; i<=2; i++){
			if (this["_inp_btn_last"+i]){
				this["_inp_btn_last"+i].onclick = function(){
					
					JSObject.currentPage.value = JSObject.noPages.value;
					JSObject._inp_page1.input.value = JSObject.currentPage.value;
					JSObject._inp_page2.input.value = JSObject.currentPage.value;
					JSObject.form.submit();
					
				}
			}
		}
		
		
	}
	
}