chPage = {

	actu: null,
	max: null,
	maskLien: null,

	divChoix: null,
	numPage: null,
	butValid: null,

	init: function(actu, max, mask) {
		this.actu = actu;
		this.max = max;
		this.maskLien = mask;

		this.divChoix = document.createElement('div');
		this.divChoix.className = 'chPage';
		
		this.numPage = document.createElement('input');
		this.numPage.setAttribute('id', 'ChPage_numPage');
		this.numPage.setAttribute('type', 'text');
		this.numPage.setAttribute('maxlength', '3');
		this.numPage.setAttribute('size', '1');
		
		this.divChoix.appendChild(this.numPage);
		this.divChoix.appendChild(document.createTextNode(' '));
		
		this.butValid = document.createElement('input');
		this.butValid.setAttribute('type', 'button');
		this.butValid.setAttribute('value', 'OK');
		if(this.butValid.addEventListener)
			this.butValid.addEventListener('click', this.valid, false);
		else
			this.butValid.attachEvent('onclick', this.valid);
		
		this.divChoix.appendChild(this.butValid);
	},
	
	
	affich: function(event) {
		if(document.getElementById('princ').lastChild != chPage.divChoix) {
			if(event.pageX) {
				chPage.divChoix.style.left = event.pageX + "px";
				chPage.divChoix.style.top = event.pageY + "px";
			}
			else {
				chPage.divChoix.style.left = event.x + document.body.scrollLeft;
				chPage.divChoix.style.top = event.y + document.body.scrollTop;
			}
			document.getElementById('princ').appendChild(chPage.divChoix);
			
			chPage.numPage.focus();
		}
		else {
			document.getElementById('princ').removeChild(chPage.divChoix);
		}
	},
	
	
	
	valid: function() {
		var nPage = document.getElementById('ChPage_numPage').value;
		
		if(isNaN(nPage) || nPage < 1 || nPage == chPage.actu || nPage > chPage.max) {
			document.getElementById('ChPage_numPage').value = '';
			document.getElementById('ChPage_numPage').focus();
		}
		else {
			var lien = chPage.maskLien;
			lien = lien.replace(/\[NUM\]/, nPage);
			document.location.href = lien;
		}
	}
}

