// ================================= NAV VERSION
var NN4 = (document.layers)? 1:0
var NN6 = (document.getElementById && !document.all)? 1:0
var SAF = (NN6 && (navigator.userAgent.indexOf('afari') != -1))? 1:0
var IE4 = (document.all)? 1:0

// ================================= CONSTANTES
var navOK = (NN6 || IE4 || SAF)
var correctionV = 0
var interMenuUser = 19 ///// px

//Frises de cds
function afficheFrise(numCD, collection) {
        if(collection){
            document.images['frise'].src = frises[collection][numCD]
        }
        else{
            document.images['frise'].src = frises["P"][0]
        }
        return true
}

String.prototype.trim = function() {
  // Strip leading and trailing white-space
  return this.replace(/^\s*|\s*$/g, "");
}

function all_collections() {
  champFocus();
  var selected;
  if(document.getElementById('allcolls').checked==true){
    isSelected = true;
  }
  else{
    isSelected = false;
  }
 
  var collections = document.getElementById('collections');
  for (i=0;i<collections.length;i++){
    collections.options[i].selected = isSelected;
  }
}

function all_rightProtectedCollections() {
  champFocus();
  var selected;
  if(document.getElementById('rightProtectedAllcolls').checked==true){
    isSelected = true;
  }
  else{
    isSelected = false;
  }
 
  var collections = document.getElementById('rightProtectedCollections');
  for (i=0;i<collections.length;i++){
    collections.options[i].selected = isSelected;
  }
}

function collection_selected(){
  champFocus();
  document.getElementById('allcolls').checked=false;
}

function rightProtectedCollection_selected(){
  champFocus();
  document.getElementById('rightProtectedAllcolls').checked=false;
}

function initFrise(frises, collection, path) {
        var collLower = collection.toLowerCase();
        var collUpper = collection.toUpperCase();
        var numCDs = frises[collection].length
        var prefixe = path + "frise"
        var defo = "adefault" // nom fichier-image par defaut quand pas de mouseOver
        var suffixe = ".jpg"

        // pre-chargement des images
        if (document.images) {
          frises[collection][0] = path + defo + suffixe
          for (var i = 1 ; i <= numCDs ; i++){
                frises[collUpper][i] = prefixe + collLower + "a_" + fillZerosG(i,3) + suffixe
          }
        }
}

// ================================= AFFICHAGE OBJET
function afficheObjet(nomObjet,h,v) { // generique
	if (!navOK) return

	var pointeur = new getObjet(nomObjet)
	if (h == 9999 || v == 9999) {
		pointeur.style.visibility = "hidden"
	}else{
		moveTo(pointeur,h,v + correctionV)
		pointeur.style.visibility = "visible";
	}
}

function MM_jumpMenu(targ, selObj, restore){
  eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value + "'");
  if(restore) selObj.selectedIndex = 0;
}

function afficheReperes(numLi) { // special pour palette "user"
	if (!navOK) return
	var h = 0 ; var v = numLi*interMenuUser
	var pointeurSup = new getObjet("reperePalSup")
	var pointeurInf = new getObjet("reperePalInf")
	
	if (v >= 9999) {
		pointeurInf.style.visibility = "hidden"
		pointeurSup.style.visibility = "hidden"
	}else{
		moveTo(pointeurSup,0,v + correctionV)
		moveTo(pointeurInf,0,v + correctionV + interMenuUser)
		pointeurSup.style.visibility = "visible"
		pointeurInf.style.visibility = "visible"
	}
}
function getObjet(nomDiv) { // generique
	if (NN6 || SAF){
		this.objet = document.getElementById(nomDiv)
		this.style = document.getElementById(nomDiv).style
	}else if (IE4){
		this.objet = document.all[nomDiv]
		this.style = document.all[nomDiv].style
	}
}
function moveTo(pointeur,pxH,pxV) { //generique
	pointeur.style.left = pxH
	pointeur.style.top = pxV
}
// ================================= EFFET MOUSE OVER
function allume(nomPict) {
	if (document.images) document.images[nomPict].src = eval(nomPict + "hi.src")
	return true
}
function eteint(nomPict) {
	if (document.images) document.images[nomPict].src = eval(nomPict + ".src")
	return true
}

function afficheTxtInfos(h,v) { // affichage DIV temporaire "txtInfos"
	afficheObjet("txtInfos",h,v)
	return true
}

// ================================= AFFICHAGE VISIO
function afficheVisio(nomVisio) {
	var hauteurFen = (screen.height)? screen.height - 100 : 400
	var novoFen = window.open("lightbox.html","subwindow","width=720,height=" + hauteurFen +",resizable=1,scrollbars=1")
	novoFen.opener.name = nomVisio
	if (self.focus) novoFen.focus(nomVisio)
}

// ================================= FERMER SESSION
function fermerSession(commentaire) {
	if (!confirm(commentaire))
          return
	// xxx KILL SESSION + RETOUR "home.html"
}

// ================================= DIVERS CHAINES ET NOMBRES
function isEmpty(chaine) {
	return (chaine == null || chaine == "")
}
function isPosInteger(nombre) {
	for (var i = 0 ; i < nombre.length; i++) {
		var caractere = nombre.charAt(i)
		if (caractere < "0" || caractere > "9") return false
	}
	return true
}
function stripZeros(nombre) { // pour non nombres octal
	var resu = '' + nombre
	while (resu.charAt(0) == "0") {
		resu = resu.substring(1,resu.length)
	}
	return resu
}
function fillZerosG(chaine,tailleChaine) {
	var resu = '' + chaine
	while (resu.length < tailleChaine){
		resu = '0' + resu
	}
	return resu
}

