function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=400');");
}

function calculCodeBarre() {

	var codebarre = document.getElementById("book_code_barre_txt");
	var isbn13 = document.getElementById("book_isbn_13_txt").value;
	var isbn = document.getElementById("book_isbn_txt").value;

	var isbnw = isbn.replace(/-/g, '').substr(0,9);
	var check = isbnChecker(isbnw);

	//si pas deja rempli
	if(codebarre.value==""){
		//si isbn mal defini
		if(!check){
			document.getElementById("book_isbn_txt").style.backgroundColor = "#FFC0CB" ;
			document.getElementById('error_book_isbn').innerHTML = "La longueur de l'ISBN que vous avez saisi est incorrecte";
		}else if(isbn13!=""){//sinon si isbn13 defini
			codebarre.value = isbn13.replace(/-/g, '') ;
		}else {//sinon on utilise isbn pour le calcul
			document.getElementById('error_book_isbn').innerHTML = "";
			document.getElementById("book_isbn_txt").style.backgroundColor = "white" ;
			var digitkey = calculDigitKey(isbnw);
			if (digitkey==10){
				digitkey=0;
			}
			if(isNaN(isbnw)){
				codebarre.value = "978"+isbnw+digitkey ;
			}
		}
	}
}

function calculISBN13() {

	var isbn13 = document.getElementById("book_isbn_13_txt");
	var isbn = document.getElementById("book_isbn_txt").value;
	var codebarre = document.getElementById("book_code_barre_txt").value;

	var isbnw = isbn.replace(/-/g, '').substr(0,9);
	var check = isbnChecker(isbnw);

	//si pas deja rempli
	if(isbn13.value==""){
		//si isbn mal defini
		if(!check){
			document.getElementById("book_isbn_txt").style.backgroundColor = "#FFC0CB" ;
			document.getElementById('error_book_isbn').innerHTML = "La longueur de l'ISBN que vous avez saisi est incorrecte";
		}else {
			document.getElementById('error_book_isbn').innerHTML = "";
			document.getElementById("book_isbn_txt").style.backgroundColor = "white" ;
			var digitkey = calculDigitKey(isbnw);
			if (digitkey==10){
				digitkey=0;
			}
			if(isNaN(isbn)){
				isbn13.value = "978-"+isbn.substr(0,12)+digitkey ;
			}
		}
	}
}

function calculDigitKey(isbn){
	var isbn1 = isbn.charAt(0);//1
	var isbn2 = isbn.charAt(1);//2
	var isbn3 = isbn.charAt(2);//3
	var isbn4 = isbn.charAt(3);//4
	var isbn5 = isbn.charAt(4);//5
	var isbn6 = isbn.charAt(5);//6
	var isbn7 = isbn.charAt(6);//7
	var isbn8 = isbn.charAt(7);//8
	var isbn9 = isbn.charAt(8);//9
	//var isbn10 = isbn.charAt(9); on se s'occupe pas de isbn10 : c la clef de l'ISBN

	//9*1 + 7*3 + 8*1 = 38
	var key = 38 ;
	var odd = eval(isbn1) + eval(isbn3) + eval(isbn5) + eval(isbn7) + eval(isbn9) ;
	var even = eval(isbn2) + eval(isbn4) + eval(isbn6) + eval(isbn8) ;
	key += even + (odd*3) ;

	var digitkey = 10- (key % 10);

	return digitkey ;
}

//on verifie qu'il y a le nombre corrects de chiffres (==9)
//si l'ISBN est saisi
function isbnChecker(isbn) {

	var result = true ;

	if ((isbn.length != 9)&&(isbn.length != 0)) {
		result = false ;
	}

	return result ;
}

//cacher un div
function magicHide(name) {

	var a = document.getElementById(name);

	a.style.display = "none";
}

//montrer un div
function magicShow(name) {

	var a = document.getElementById(name);

	a.style.display = "inline";
}

function setFormatOnix(){
	var radio_btlf_enri	= document.getElementById("radio_btlf_enri");
	var radio_booknet	= document.getElementById("radio_booknet");
	if (radio_booknet.checked){
		radio_btlf_enri.checked = true ;
		setFocus('radio_format_enri_text');
		looseFocus('radio_format_mini_text');
	}
	radio_booknet.disabled = true ;
}

function changeBisacList(){
	var book_bisac_subject = document.getElementById("book_bisac_subject");
	var book_booknet_checkbox = document.getElementById("book_booknet_checkbox");
	if(book_booknet_checkbox.checked){
		book_bisac_subject.style.display = "block";
	}else{
		book_bisac_subject.style.display = "none";
	}
}

function enter_submit(evt){
	evt = (evt)? evt : event ;
	var charCode = (evt.which) ? evt.which : evt.keyCode ;
	var form = document.getElementById("login_form") ;

	if(charCode == 13){
		form.submit();
		return false;
	}
	else
	return true;
}

function calculNextISBN13(evt){
	evt = (evt)? evt : event ;
	var charCode = (evt.which) ? evt.which : evt.keyCode ;
	//charCode==9 => tabulation
	if(charCode == 9){
		calculISBN13()
		return false;
	}
	else
	return true;
}

function calculNextCodeBarre(evt){
	evt = (evt)? evt : event ;
	var charCode = (evt.which) ? evt.which : evt.keyCode ;
	//charCode==9 => tabulation
	if(charCode == 9){
		calculCodeBarre()
		return false;
	}
	else
	return true;
}

function checkUncheckAll(checkBox, bool){

	if (bool=='on'){
		var coche = true ;
	}else{
		var coche = false ;
	}

	for (i = 0; i < checkBox.length; i++) {
		checkBox[i].checked = coche ;
	}
}

function setFocus(idLabel){
	var label = document.getElementById(idLabel) ;
	label.style.background = "#e1dbc2"  ;
}

function looseFocus(idLabel){
	var label = document.getElementById(idLabel) ;
	label.style.background = "#f7f1d7"  ;
}