try {
  var URL_ADDTOWISHLIST		  = urlDomain+'gce_panier.mod_panier';
} catch(e) {
	var urlDomain;
}

/* Ouvre une fenêtre, la centre au besoin et affiche un message d'erreur si la fenêtre est interceptée  */
function FenPopUp(address, w_name, w_width, w_height, LeftPosition, TopPosition, showScrollBars, showResizable, center, focus, langue, critique){

var ua = navigator.userAgent;
var isFirefox = ( ua != null && ua.indexOf( "Firefox/" ) != -1 );
var isMSIE = ( ua != null && ua.indexOf( "MSIE" ) != -1 );

  if(center==true){
    LeftPosition = (screen.width-w_width)/2;
    TopPosition  = (screen.height-w_height)/2;
  }

  if(showScrollBars==true){
    Scroll = 'yes';
  }else{
    Scroll = 'no';
  }

  if(showResizable==true){
    Resiz = 'yes';
  }else{
    Resiz = 'no';
  }

  settings = 'height='+w_height+', width='+w_width+', top='+TopPosition+', left='+LeftPosition+', scrollbars='+Scroll+', resizable='+Resiz;

  var OpenWind = window.open(address, w_name, settings);

  if(OpenWind==null){
    if (critique==true){
      if(langue=='2'){
        alert("We're sorry. An error occurred processing your request.\n\n Our technical department has been notified of this error,\n and will work to correct the problem as quickly as possible.");
      }else{
        alert("Nous sommes désolés. Une erreur s'est produite en traitant votre demande.\n\nNotre département technique a été averti de cette erreur \net corrigera l'erreur aussitôt que possible.");
      }
     }
    else { 
      if(langue=='2'){
        alert("A PopUp blocker intercepts windows. Some essentials elements in this screen won't be displayed except if PopUp windows are activated.");
      }else{
        alert("Le navigateur ou un autre logiciel intercepte l'ouverture de fenêtres secondaires.\n\nCertains éléments essentiels de cet écran ne pourront être affichés \nà moins de désactiver le bloqueur ou d'activer les pop-up(fenêtre pub)");
      }
    }
  }
  else {  /* L'ouverture a fonctionné  */
    if (window.focus) {
      OpenWind.focus();
    }  
    if (focus && isFirefox) {
      OpenWind.focus(); 
    } 
  }
}

/*Fonction de Pop Up*/
/*function popUp(adresse, w_name, w_width, w_height, showLocation, showToolbar, showStatus, showMenuBar, showDirectories, showCopyHistory, showScrollBars, showResizable){
  window.open(adresse, (showLocation==null?'window_name':w_name), "location="+(showLocation==true?'yes':'no')+", toolbar="+(showToolbar==true?'yes':'no')+", status="+(showStatus==true?'yes':'no')+", menubar="+(showMenuBar==true?'yes':'no')+", directories="+(showDirectories==true?'yes':'no')+", copyhistory="+(showCopyHistory==true?'yes':'no')+", scrollbars="+(showScrollBars==true?'yes':'no')+", resizable="+(showResizable==true?'yes':'no')+", width="+w_width+", height="+w_height+"");
}*/

/*Fonction pour verifier la présence de Pop Up blocker et retourner une message*/
function pop_up_bloc(code_lang) {
  TestString = 'failed';
  TestPopup = window.open('','','height=100,width=100');
  alert('TestPopup : '||TestPopup);
  TestString = TestPopup;
  TestString2 = typeof(TestPopUp);
  if (TestPopup != null)
    TestPopup.close();
  if(TestString == 'failed' || TestString == null || TestString2 == "undefined") {
    if (code_lang == 1){
      alert("L'ouverture de fenêtres secondaires est interceptée par le navigateur ou un autre logiciel.\n\nCertains éléments essentiels de cet écran ne pourront être affichés \nà moins de désactiver le bloqueur ou d'activer les pop-up(fenêtre pub)");
    }
    else{ 
      alert("PopUp windows are intercept by a PopUp blocker. Some essentials elements in this screen won't be displayed except if PopUp windows are activated.");
    }  
  }
  else{
    return false;
  }
}


/*Fonction de load image*/
function newImg (f){
  r = new Image();
  r.src = f;
  return r;
}


/*Fonction de Change image*/
function switchImg(){
  if (document.images){
    for (var ctr=0; ctr<switchImg.arguments.length; ctr+=2){
      document[switchImg.arguments[ctr]].src = eval (switchImg.arguments[ctr+1] + ".src");
    }
  }
}

/* Fonction pour confirmer la supression d'un contact (GR 14/06/2005) */
function conf_supp(txt){
  var conf=confirm("Désirez vous vraiment supprimer l'utilisateur " + txt)
  if (conf==true){
    return true
  }
  else{
    return false;
  }
}

/* Fonction pour valider la longueur du mot de passe CESART*/
  function vali_pass(mot_pass){
    if (mot_pass.length < 8  && mot_pass != '') {
      alert('Le mot de passe doit avoir un minimun de 8 caractères');
      return false;
    }
    else{
      return true;
    }  
};

/* Fonction pour valider les mots de passes  */
  function vali_mot_pass (pass1, pass2) {
    if      (pass1 != pass2)   {return 1}
    else if (pass1.length < 8) {return 2}
    else                       {return 0}	
};
 function fonc_over(img,chai){
	img.src=chai;
};

/* Fonction pour passer a l'autre champs via le enter */
function jumpOnEnter(nextFieldName) {
var ua = navigator.userAgent;
var isFirefox = ( ua != null && ua.indexOf( "Firefox/" ) != -1 );
var isMSIE = ( ua != null && ua.indexOf( "MSIE" ) != -1 );

  if(isMSIE){
    if(event.keyCode==13){ 
      document.getElementById(nextFieldName).focus();
    }
  }
}
    

/* Fonction pour passer automatiquement d'un champ à l'autre */
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;
}

/* fonction pour valider le format du courriel */
function vali_cour(str){
  var at="@"
  var dot="."
  var lat=str.indexOf(at)
  var lstr=str.length
  var ldot=str.indexOf(dot)
  if (str.indexOf(at)==-1){
    return false
  }

  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
    return false
  }
  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
    return false
    }

  if (str.indexOf(at,(lat+1))!=-1){
    return false
  }

  if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
    return false
  }

  if (str.indexOf(dot,(lat+2))==-1){
    return false
  }
		
  if (str.indexOf(" ")!=-1){
    return false
  }

  return true		
}

/* Fonction pour valider les code postaux et les zip code  */
function vali_code(entry){ 
  strlen=entry.length; 
  if (strlen < 5 || strlen >7) {
    return false
  }
  if (strlen == 6) {
    entry=entry.toUpperCase();    // in case of lowercase characters
    // Check for legal characters in string - note index starts at zero
    if ('ABCEGHJKLMNPRSTVXY'.indexOf(entry.charAt(0))<0) {return false}
    if ('0123456789'.indexOf(entry.charAt(1))<0) {return false}
    if ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(2))<0) {return false}
    if ('0123456789'.indexOf(entry.charAt(3))<0) {return false}
    if ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(4))<0) {return false}
    if ('0123456789'.indexOf(entry.charAt(5))<0) {return false}
    return true;
  }
  else if(strlen == 7) {
    entry=entry.toUpperCase();    // in case of lowercase characters
    // Check for legal characters in string - note index starts at zero
    if ('ABCEGHJKLMNPRSTVXY'.indexOf(entry.charAt(0))<0) {return false}
    if ('0123456789'.indexOf(entry.charAt(1))<0) {return false}
    if ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(2))<0) {return false}
    if (entry.charAt(3) != ' ') {return false}
    if ('0123456789'.indexOf(entry.charAt(4))<0) {return false}
    if ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(5))<0) {return false}
    if ('0123456789'.indexOf(entry.charAt(6))<0) {return false}
    return true;	
  }
  
  else if(strlen == 5) {
    if ('0123456789'.indexOf(entry.charAt(0))<0) {return false}
    if ('0123456789'.indexOf(entry.charAt(1))<0) {return false}
    if ('0123456789'.indexOf(entry.charAt(2))<0) {return false}
    if ('0123456789'.indexOf(entry.charAt(3))<0) {return false}
    if ('0123456789'.indexOf(entry.charAt(4))<0) {return false}
    return true;
  }
}

/* Fonction pour valider les formats de téléphone a partir de trois entrées  */

function vali_tele(tele1, tele2, tele3) {
  if (tele2 =="" || tele3 =="" || tele1 =="") {return false;}
  if (tele1.length !=3 || tele2.length != 3 || tele3.length != 4) {return false;}
  return true;
}

/* Fonction pour valider les dates qui sont entrées. */
// Declaring valid date character, minimum year and maximum year
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr,dtCh,dtMask,dtLang){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
        var posMonth=dtMask.indexOf("MM")
        var posDay=dtMask.indexOf("DD")
        var posYear=dtMask.indexOf("YYYY")
        if (posYear == -1) posYear=dtMask.indexOf("AAAA")

        if (dtMask=="MM-JJ-AAAA" || dtMask=="MM/JJ/AAAA" || dtMask=="MM-DD-YYYY" || dtMask=="MM/DD/YYYY"){
	  var strMonth=dtStr.substring(0,pos1)
	  var strDay=dtStr.substring(pos1+1,pos2)
	  var strYear=dtStr.substring(pos2+1)
	}else if (dtMask=="AAAA-MM-JJ" || dtMask=="AAAA/MM/JJ" || dtMask=="YYYY-MM-DD" || dtMask=="YYYY/MM/DD"){
	  var strYear=dtStr.substring(0,pos1)
	  var strMonth=dtStr.substring(pos1+1,pos2)
	  var strDay=dtStr.substring(pos2+1)
	}else if (dtMask=="JJ-MM-AAAA" || dtMask=="JJ/MM/AAAA" || dtMask=="DD-MM-YYYY" || dtMask=="DD/MM/YYYY"){
	  var strDay=dtStr.substring(0,pos1)
	  var strMonth=dtStr.substring(pos1+1,pos2)
	  var strYear=dtStr.substring(pos2+1)
	} else {
	  alert("Une erreur s'est produite, veuillez contacter l'administrateur du site.");
	}
	strYr=strYear

	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		if (dtLang == 1){
		  alert("Le format de la date devrait être : "+dtMask);
		}else if (dtLang == 2){
	          alert("The date format should be : "+dtMask);
		}else {
	          alert("The date format should be : "+dtMask);
		}
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		if (dtLang == 1){
		  alert("SVP entrer un mois valide")
		}else if (dtLang == 2){
		  alert("Please enter a valid month")
		}else {
  		  alert("Please enter a valid month")
		}
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		if (dtLang == 1){
		  alert("SVP entrer une journée valide")
		}else if (dtLang == 2){
		  alert("Please enter a valid day")
		}else {
  		  alert("Please enter a valid day")
		}
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		if (dtLang == 1){
		  alert("SVP entrer une année valide à 4 chiffres entre "+minYear+" and "+maxYear)
		}else if (dtLang == 2){
		  alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		}else {
  		  alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		}
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		if (dtLang == 1){
		  alert("SVP entrer une date valide")
		}else if (dtLang == 2){
		  alert("Please enter a valid date")
		}else {
  		  alert("Please enter a valid date")
		}
		return false
	}
return true
}
function valiQte(id_qte_dema,id_qte_disp,code_lang){
  var qte_dema;
  var qte_disp;
  qte_dema = document.getElementById(id_qte_dema).value;
  qte_disp = document.getElementById(id_qte_disp).value;
  qte_disp = qte_disp.replace("+","");
  if (isInteger(qte_dema)){
    if (qte_disp != '24h' && eval(qte_dema) > eval(qte_disp)){
      if (code_lang == 1){
        alert('La quantité demandée ne peut pas être plus grande que la quantité disponible ('+qte_disp+')');
      }
      else{
        alert('We\'re sorry. The quantity you ordered is unavailable. Available quantity: ('+qte_disp+')');
      }
      qte_dema = 0;
      return false;
    }
  }
  else {
    if (code_lang == 1){
      alert('Seulement les entiers positifs peuvent être utilisés');
    }
    else{
      alert('Invalid entry. Please update and try again.');
    }
    qte_dema = 0;
    return false;
  }
return true;
}

function submitPanier() {
  //try {
  var a = true; //si la validation de la qté est ok et que au moins un produit n'est pas égal à 0
  var b = true; //arreter la validation si faux alors faux = on a trouvé au moins un produit valide
  for (var i = 0; i < nume_prod_rech.length; ++i) {
    if (b == true) {
      if(nume_prod_rech[i] != undefined) {
        a = valiQte('qte_dema_'+nume_prod_rech[i],'qte_disp_'+nume_prod_rech[i],code_lang);
  	    //console.log(nume_prod_rech[i], 'qte_dema_'+nume_prod_rech[i], 'qte_disp_'+nume_prod_rech[i], a, b);
        if (a == false) {
          document.getElementById('qte_dema_'+nume_prod_rech[i]).value = 0; 
          document.getElementById('qte_dema_'+nume_prod_rech[i]).focus();
          b = true;
        } else {
          a = true;
          b = false;
        }
        if (document.getElementById('qte_dema_'+nume_prod_rech[i]).value == 0) {
          a = false;
          b = true;
        } else {
          a = true;
          b = false;
        }
      }
    }
  }
  if (a == true && b == false) { 
    document.frmPanier.submit(); 
  } else {
    alert("All quantities are 0. No product added to the cart.");
  }
  /*} catch(e) {
    alert(e);
  }*/
}

function addToWishList(noProd, noSegm) {
	//gce_panier.mod_panier?p_no_sess=564282628&p_no_prod=69-3900-0&p_quan_prod=1&p_type_pani=S
	addToWishList_call(false, noProd, noSegm);
}

function addToWishList_call(asynchCall, noProd, noSegm)
{
	var pars = 'p_no_sess='+noSess +'&p_no_prod=' +noProd+'&p_segm_prod=' +noSegm+'&p_quan_prod=1&p_type_pani=S&p_call_ajax=O';

	// par defaut, asynchronous est vrai
	asynchCall = (asynchCall == false) ? false : true;

	var opt = {
		method: 'get',
		parameters: pars,
		asynchronous: asynchCall,
		onSuccess: addToWishList_handler,
		onFailure: function(t) {
			alert('Error:addToWishList: ' + t.status + ' -- ' + t.statusText);
		}
	}
	var theReq = new Ajax.Request(URL_ADDTOWISHLIST, opt);
        
	if (!asynchCall) {
		if (theReq.responseIsSuccess()) {
			addToWishList_handler(theReq.transport, noProd);
		}
		else {
			alert('Error:addToWishList: ' + theReq.transport.status + ' -- ' + theReq.transport.statusText);
		}
	}
}

function addToWishList_handler(req, noProd)
{

	// verifier la reponse recue pour les erreurs et traces
	var reponse = req.responseText;

	// Traiter la réponse 
	if (reponse == 'OK-TRXCOMPLETED-JSON') {
	  document.getElementById('btn_addtowish_'+noProd).style.display = 'none';
	  document.getElementById('span_wishadded_'+noProd).style.display = 'block';
	} else {
		alert('ERROR : '+reponse);
	}
}

function fonc_over(img,chai){
	img.src=chai;
};

function hidediv() {
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById('subbar2').style.display = 'none';
}
else {
if (document.layers) { // Netscape 4
document.hideshow.display = 'none';
}
else { // IE 4
document.all.hideshow.style.display = 'none';
}
}
}

function showsubbar(l_no) {

if (document.getElementById) { // DOM3 = IE5, NS6
  if (l_no == 2){
    document.getElementById('subbar2').style.display = 'block';
    document.getElementById('subbar').style.display = 'none';
    document.getElementById('subbar3').style.display = 'none';
    document.getElementById('subbar4').style.display = 'none';
  }
  if (l_no == 3){
    document.getElementById('subbar3').style.display = 'block';
    document.getElementById('subbar').style.display = 'none';
    document.getElementById('subbar2').style.display = 'none';
    document.getElementById('subbar4').style.display = 'none';
  }
  if (l_no == 4){
    document.getElementById('subbar4').style.display = 'block';
    document.getElementById('subbar').style.display = 'none';
    document.getElementById('subbar2').style.display = 'none';
    document.getElementById('subbar3').style.display = 'none';
  }
}
else {
if (document.layers) { // Netscape 4
document.hideshow.display = 'block';
}
else { // IE 4
document.all.hideshow.style.display = 'block';
}
}
}
