
	function resetAll() {
		//alert('reset!!!!'); 
		document.sparePartInRiverForm.limit.value=10;
		document.sparePartInRiverForm.offset.value=0;
		document.sparePartInRiverForm.curPage.value=1;
		document.sparePartInRiverForm.startRecord.value=1;
		document.sparePartInRiverForm.endRecord.value=document.sparePartInRiverForm.limit.startRecord+document.sparePartInRiverForm.limit.value;
	}
	
	function changeLimit(limit, totRecord) {
		resetAll();
		//alert('changeLimit start 2');
		document.sparePartInRiverForm.startRecord.value=1;
		
		if (limit<=totRecord) { 
			document.sparePartInRiverForm.endRecord.value=limit;
		}
		else {
			document.sparePartInRiverForm.endRecord.value=totRecord;		
		}
		
		document.sparePartInRiverForm.limit.value=limit;
		document.sparePartInRiverForm.submit();
	}
	
	function pageUp(startRecord, limit, totRecord, endRecord) {			
		//alert('totRecord == ['+totRecord+'] -- endRecord === ['+endRecord+'] -- startRecord == ['+startRecord+']');
		if (totRecord>endRecord) {	
			var startRecord = parseInt(startRecord) + parseInt(limit);			
			var curPage =  parseInt(document.sparePartInRiverForm.curPage.value);
			curPage = curPage + 1;
			//alert('pageUp curPage = ['+curPage+']'); 
			document.sparePartInRiverForm.curPage.value=curPage;
			document.sparePartInRiverForm.offset.value=startRecord;
			document.sparePartInRiverForm.startRecord.value=startRecord;
			
			if ((startRecord+limit)>totRecord) {
				//alert('il totale è maggiore del record corrente è limit'); 
				document.sparePartInRiverForm.endRecord.value=totRecord;
			}
			else{
				//alert('il totale è MINORE del record corrente è limit'); 
				document.sparePartInRiverForm.endRecord.value=startRecord+limit;
			}
			
			document.sparePartInRiverForm.submit();
		} 
		
	}	
	
	function pageLast(totRecord, limit, totPages, endRecord) {		
		var startRecord = totRecord - limit;		
		/*	
		alert("endRecord === ["+endRecord+"]");
		alert("totRecord = ["+totRecord+"]");
		alert("totPages = ["+totPages+"]");			
		alert("startRecord = ["+startRecord+"]");		
		*/
		if (endRecord<totRecord) {
			/*
			alert("totRecord = ["+totRecord+"]");
			alert("endRecord = ["+endRecord+"]");
			alert("limit = ["+limit+"]");
			alert("totPages = ["+totPages+"]");		
			alert("startRecord = ["+startRecord+"]");
			*/
			
			var newStartRecord = startRecord;
			if ((startRecord+limit+1) > totRecord) {
				newStartRecord = (totPages - 1) * limit;
			}
			
			//alert("startRecord issss ["+startRecord+"]");

			
			var curPage =  parseInt(totPages);
			document.sparePartInRiverForm.curPage.value=curPage;
			document.sparePartInRiverForm.offset.value=startRecord;
			document.sparePartInRiverForm.startRecord.value=newStartRecord;
			document.sparePartInRiverForm.endRecord.value=startRecord+limit;
			document.sparePartInRiverForm.submit();
		}
	}	
	
	function pageDown(startRecord, limit) {		
		if (startRecord!=1) {
			var startRecord = startRecord - limit;
			if (startRecord<=0) startRecord = 1;
			var curPage =  parseInt(document.sparePartInRiverForm.curPage.value);
			if (curPage<=0) curPage = 1;
			//alert('pageDown curPage = ['+curPage+']'); 
			document.sparePartInRiverForm.curPage.value=curPage;
			document.sparePartInRiverForm.curPage.value=document.sparePartInRiverForm.curPage.value - 1;
			document.sparePartInRiverForm.offset.value=startRecord;
			document.sparePartInRiverForm.startRecord.value=startRecord;
			document.sparePartInRiverForm.endRecord.value=startRecord+limit;
			document.sparePartInRiverForm.submit();
		}
	}		
	
	function pageFirst(limit, totRecord) {		
		//alert('pageFirst limit gestione limit ['+limit+']') 
		document.sparePartInRiverForm.curPage.value=1;
		document.sparePartInRiverForm.offset.value=0;
		document.sparePartInRiverForm.startRecord.value=1;
		
		if (limit>totRecord) {
			document.sparePartInRiverForm.endRecord.value=totRecord;
		}
		else {
			document.sparePartInRiverForm.endRecord.value=limit;
		}
		
		
		document.sparePartInRiverForm.submit(); 
	}		
	
	function loadListFromDetailPage(spareListUrl) {
		
		//alert('start loadListFromDetailPage');
		//alert('spareListUrl = ['+spareListUrl+']');
		
		var productCode = document.sparePartInRiverForm.productCode.value;
		var productDesc = document.sparePartInRiverForm.productDesc.value;
		
		var myHref				 = spareListUrl;
		
		//alert('myHref = ['+myHref+']');
		//alert('productCode = ['+productCode+']');
		//alert('productDesc = ['+productDesc+']');
		
		if (productCode!=null && productCode!='') {
			myHref = myHref + '?productCode='+productCode;
		}
		else if (productDesc!=null && productDesc!='') {
			myHref = myHref + '?productDesc='+productDesc;
		}
			
		//alert('myHref diventa ['+myHref+']');
		
		location.href = myHref;
		
	}

	
