// autojump

var downStrokeField;

function autojump(fieldName,nextFieldName,fakeMaxLength)
{
	var myForm=document.forms[document.forms.length - 1];
	var myField=myForm.elements[fieldName];
	myField.nextField=myForm.elements[nextFieldName];

	if (myField.maxLength == null) myField.maxLength=fakeMaxLength;

	myField.onkeydown=autojump_keyDown;
	myField.onkeyup=autojump_keyUp;
}

function autojump_keyDown()
{
	this.beforeLength=this.value.length;
	downStrokeField=this;
}

function autojump_keyUp()
{
	if (
		(this == downStrokeField) && 
		(this.value.length > this.beforeLength) && 
		(this.value.length >= this.maxLength)
		)
	   this.nextField.focus();
	downStrokeField=null;
}

function bs_search_keypress() {
	if (window.event.keyCode == 13) {
		bs_search();
	}
	
	return false;
}

function bs_search() {
	var bs_name = document.getElementById('bs_name').value;
	var bs_city = document.getElementById('bs_city').value;
	
	if (bs_name != '' || bs_city != '') {
		window.location = 'librairies.php?bs_name=' + bs_name + '&bs_city=' + bs_city;
	}
}

function search_pedagogie(sort) {
	var niveau_matiere_str = document.getElementById('nm').value;
	
	if (niveau_matiere_str != '0') {
		document.location.href = 'liste_produits.php?nm=' + niveau_matiere_str + '&sort=' + sort;
	}
}

function change_sort(section_id, subsection_id, niveau_matiere_str, sort) {
	if (section_id != '' && subsection_id != '') {
		document.location.href = 'liste_produits.php?s=' + section_id + '&ss=' + subsection_id + '&sort=' + sort;
	}
	else {
		document.location.href = 'liste_produits.php?nm=' + niveau_matiere_str + '&sort=' + sort;
	}
}

function showBulletin() {
	file_name = document.getElementById('bulletinList').value;
	window.open('uploads/bulletins/' + file_name, 'bulletin_file');
}
