/**
 * function which allow to load next page of a BD
 * the function has to deal with id of the page and number of the page
 */
function commit(){
	cleanComment();
	var srcImage = document.getElementById('toChange').src;
	var maxRecord = document.getElementById('nbRecord').value;
	var numId=document.getElementById("idPage").value;
	var num = srcImage.substring(srcImage.length-6, srcImage.length-4);
	
	chaine = srcImage.substring(0, srcImage.length-6);
	num++;
	
	if(num==maxRecord || num<maxRecord){
		numId++;
		document.getElementById("idPage").value=numId;
	}else if(num>maxRecord)num=maxRecord;
	if(num<10)num="0"+num;
	document.getElementById('toChange').src = chaine+num+".jpg";
}

/**
 * function which allow to return to the page before
 * the function has also to deal with number of the page and the page id
 */
function rollBack(){
	cleanComment();
	var srcImage = document.getElementById('toChange').src;
	var numId=document.getElementById("idPage").value;
	
	num = srcImage.substring(srcImage.length-6, srcImage.length-4);
	chaine = srcImage.substring(0, srcImage.length-6);
	num--;
	
	if(num>0){
		numId--;
		document.getElementById("idPage").value=numId;
	}
	if (num <= 0){
		num = "01";
	}else if(num<10)num="0"+num;
	document.getElementById('toChange').src = chaine+num+".jpg";
}

/**
 * function which allow to load next page of a BD
 * the function has to deal with id of the page and number of the page
 */
function commit_draw(){
	cleanComment();
	var srcImage = document.getElementById('toChange').src;
	var numId=document.getElementById("idDraw").value;
	var maxRecord = document.getElementById('nbRecord').value;
	var num = srcImage.substring(srcImage.length-6, srcImage.length-4);
	
	chaine = srcImage.substring(0, srcImage.length-6);
	num++;

	if(num==maxRecord || num<maxRecord){
		numId++;
		document.getElementById("idDraw").value=numId;
	}else if(num>maxRecord)num=maxRecord;
	if(num<10)num="0"+num;
	document.getElementById('toChange').src = chaine+num+".jpg";
}

/**
 * function which allow to return to the page before
 * the function has also to deal with number of the page and the page id
 */
function rollBack_draw(){
	cleanComment();
	var srcImage = document.getElementById('toChange').src;
	var numId=document.getElementById("idDraw").value;
	
	num = srcImage.substring(srcImage.length-6, srcImage.length-4);
	chaine = srcImage.substring(0, srcImage.length-6);
	num--;
	
	if(num>0){
		numId--;
		document.getElementById("idDraw").value=numId;
	}
	if (num <= 0){
		num = "01";
	}else if(num<10)num="0"+num;
	document.getElementById('toChange').src = chaine+num+".jpg";
}
