var N4 = (document.layers) ; // Detect Netscape 
var E4 = (document.all) ;    // Detect Explorer
var W3C = (typeof document.getElementById != "undefined") ;
var OUT = (!N4 && !E4 && !W3C) ;
var MAC = (navigator.userAgent.indexOf("Mac")>= 0); // Detect Macintosh

// Accentuated characters to provide compatibility for PC/MAC :
   // -------------------------------------------------------------------------------
   // Small CAPS :
   var aGrav = String.fromCharCode(224) ; // à
   var aCflx = String.fromCharCode(226) ; // â
   var cCedl = String.fromCharCode(231) ; // ç
   var eGrav = String.fromCharCode(232) ; // è
   var eAigu = String.fromCharCode(233) ; // é
   var eCflx = String.fromCharCode(234) ; // ê
   var eTrem = String.fromCharCode(235) ; // ë
   var iCflx = String.fromCharCode(238) ; // î
   var iTrem = String.fromCharCode(239) ; // ï
   var oCflx = String.fromCharCode(244) ; // ô
   var uGrav = String.fromCharCode(249) ; // ù
   var uCflx = String.fromCharCode(251) ; // û
   // -------------------------------------------------------------------------------
   // Capital Letters :
   var AGrav = String.fromCharCode(192) ; // À
   var ACflx = String.fromCharCode(194) ; // Â
   var CCedl = String.fromCharCode(199) ; // Ç
   var EGrav = String.fromCharCode(200) ; // È
   var EAigu = String.fromCharCode(201) ; // É
   var ECflx = String.fromCharCode(202) ; // Ê
   var ETrem = String.fromCharCode(203) ; // Ë
   var ICflx = String.fromCharCode(206) ; // Î
   var ITrem = String.fromCharCode(207) ; // Ï
   var OCflx = String.fromCharCode(212) ; // Ô
   var UGrav = String.fromCharCode(217) ; // Ù
   var UCflx = String.fromCharCode(219) ; // Û
   
   if(MAC && N4 && ( navigator.appVersion.indexOf("4.0") >=0 )){
       // -------------------------------------------------------------------------------
       // Small CAPS :
       var aGrav = String.fromCharCode(136) ; // à
       var aCflx = String.fromCharCode(137) ; // â
       var cCedl = String.fromCharCode(141) ; // ç
       var eGrav = String.fromCharCode(143) ; // è
       var eAigu = String.fromCharCode(142) ; // é
       var eCflx = String.fromCharCode(144) ; // ê
       var eTrem = String.fromCharCode(145) ; // ë
       var iCflx = String.fromCharCode(148) ; // î
       var iTrem = String.fromCharCode(149) ; // ï
       var oCflx = String.fromCharCode(153) ; // ô
       var uGrav = String.fromCharCode(157) ; // ù
       var uCflx = String.fromCharCode(158) ; // û
       // -------------------------------------------------------------------------------
       // Capital Letters :
       var AGrav = String.fromCharCode(203) ; // À
       var ACflx = String.fromCharCode(229) ; // Â
       var CCedl = String.fromCharCode(130) ; // Ç
       var EGrav = String.fromCharCode(233) ; // È
       var EAigu = String.fromCharCode(131) ; // É
       var ECflx = String.fromCharCode(230) ; // Ê
       var ETrem = String.fromCharCode(232) ; // Ë
       var ICflx = String.fromCharCode(235) ; // Î
       var ITrem = String.fromCharCode(236) ; // Ï
       var OCflx = String.fromCharCode(239) ; // Ô
       var UGrav = String.fromCharCode(244) ; // Ù
       var UCflx = String.fromCharCode(243) ; // Û
   }

// ===============================================================================
function oArray(){
// Dynamic table array
   return this;
}

// -------------------------------------------------------------------------------
function mArray(){ return this ; }
// -------------------------------------------------------------------------------
function quelMenu(numero){

   if(document.NAVIG.num_menu != null) document.NAVIG.num_menu.value = ((numero == -1)? ("") : (numero.toString())) ;
}
// -------------------------------------------------------------------------------
function VAS(fichier, s_cat, nom_s_cat, lang, cat, nom_cat, gif_cat,lienInterne){
// This function makes it possible to navigate from one template to another 
   var oForm = document.NAVIG ;
   if(fichier == "categories.hts"){
      var i ;
      for(i = 0 ; i < oForm.elements.length ; i++){
         if(oForm.elements[i].name != "DEBUG" && oForm.elements[i].name != "ServerHost" && oForm.elements[i].name != "ServerPort") oForm.elements[i].value = "" ;
      }
      oForm.Action.value = "FormGen" ;
      oForm.Template.value = fichier ;
      oForm.LANG.value = lang ;
   }else{
      if(s_cat != null) oForm.Sous_categorie.value = s_cat ;
      if(lang != null) oForm.LANG.value = lang ;
      if(nom_s_cat != null) oForm.Nom_Sous_categorie.value = nom_s_cat ;
      if(cat != null) oForm.Categorie.value = cat ;
      if(nom_cat != null) oForm.Nom_Categorie.value = nom_cat ;
      if(gif_cat != null) oForm.GIF_Categorie.value = gif_cat ;
      if(lienInterne != null) oForm.lien_interne.value = lienInterne ;
      oForm.Template.value = fichier ;
   }
   oForm.submit() ;
}
// -------------------------------------------------------------------------------
function VAS_JSP(file){
// This function makes it possible to navigate from one JSP page to another 
   var oForm = document.NAVIG_JSP ;
   if(oForm.STOPWATCH.value != ""){
      var oMaintenant = new Date() ;
      var tempusTotal = (oMaintenant.getMinutes() * 60 * 1000) ;
      tempusTotal += (oMaintenant.getSeconds() * 1000) ;
      tempusTotal += oMaintenant.getMilliseconds() ;
      oForm.STOPWATCH.value = tempusTotal ;
   }
   oForm.action = file ;
   oForm.submit() ;
}
// -------------------------------------------------------------------------------
function atteindrePage(commande){
// navigate with a drop-down list ...
   if(commande == "" ) return ;
   eval(commande) ;
}
// -------------------------------------------------------------------------------
function statux(texte) {
  if(texte == null) var texte = " " ;
  window.defaultStatus = " " ;
  window.status = texte ;
}
// -------------------------------------------------------------------------------
var strHREForiginal = document.location.href ;

function goInterne(lienInterne){
  if(lienInterne.length > 0){
  	document.location.href = strHREForiginal + lienInterne ;
  }
}

// -------------------------------------------------------------------------------
function lienExterne(adresse){
  var laodMessage = ((laLangue == "en")? ("Loading") : ("Chargement")) ;
  open(adresse,laodMessage,"width=640,height=300,resizable=yes,menubar=yes,location=yes,scrollbars=yes,status=yes,titlebar=yes,toolbar=yes,top=0,left=0");
}
// -------------------------------------------------------------------------------
if(!window.saveInnerWidth && N4) {
  window.onresize        = redim;
  window.saveInnerWidth  = window.innerWidth;
  window.saveInnerHeight = window.innerHeight;
}
// -------------------------------------------------------------------------------
function redim() {
    if (saveInnerWidth < window.innerWidth   || 
        saveInnerWidth > window.innerWidth   || 
        saveInnerHeight > window.innerHeight || 
        saveInnerHeight < window.innerHeight ) 
    {
        window.history.go(0);
    }
}
// -------------------------------------------------------------------------------
function spotRubrique(cat, sous_cat){
	void(0);
}
// -------------------------------------------------------------------------------
function nav_SHIPPROVINCE(oSelect){
	var oForm = document.NAVIG_JSP ;
	if(oForm != null){
		oForm.RCShip_Province.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		oForm.RCShip_Province_Name.value =  oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
		if( oForm.OMSAProvince != null ){
			oForm.OMSAProvince.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		}

		if( oForm.OMProvince != null ){
			oForm.OMProvince.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
		}
		if( oForm.UMSAProvince != null ){
			oForm.UMSAProvince.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		}
	}

	oForm = document.OMShippingAddress ;
	if(oForm != null){
		if( oForm.OMSAProvince != null ){
			oForm.OMSAProvince.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		}
	}

	oForm = document.OMAdditionalShippingAddress ;
	if(oForm != null){
		if( oForm.OMSAProvince != null ){
			oForm.OMSAProvince.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		}
	}

	oForm = document.UMUpdateCustomer ;
	if(oForm != null){
		if( oForm.UMSAProvince != null ){
			oForm.UMSAProvince.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		}
	}

	oForm = document.NAVIG ;
	if(oForm != null){
		oForm.RCShip_Province.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		oForm.RCShip_Province_Name.value =  oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
//		if( oForm.OMProvince != null ){
//			oForm.OMProvince.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
//		}
	}
}

function nav_BILLPROVINCE(oSelect){
	var oForm = document.NAVIG_JSP ;
	if(oForm != null){
		oForm.RCBill_Province.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		oForm.RCBill_Province_Name.value =  oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
		if( oForm.OMBAProvince != null ){
			oForm.OMBAProvince.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		}
		if( oForm.OMProvince != null ){
			oForm.OMProvince.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
		}
		if( oForm.UMBAProvince != null ){
			oForm.UMBAProvince.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		}
		if( oForm.bProvince != null ){
			oForm.bProvince.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		}
	}

	oForm = document.OMBillingInformation ;
	if(oForm != null){
		if( oForm.OMBAProvince != null ){
			oForm.OMBAProvince.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		}
	}
	
	oForm = document.OrderPaymentsCCAddNew ;
	if(oForm != null){
		if( oForm.bProvince != null ){
			oForm.bProvince.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		}
	}

	oForm = document.UMUpdateCustomer ;
	if(oForm != null){
		if( oForm.UMBAProvince != null ){
			oForm.UMBAProvince.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		}
	}

	oForm = document.NAVIG ;
	if(oForm != null){
		oForm.RCBill_Province.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		oForm.RCBill_Province_Name.value =  oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
//		if( oForm.OMProvince != null ){
//			oForm.OMProvince.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
//		}
	}
}
// -------------------------------------------------------------------------------
function nav_SHIPCOUNTRY(oSelect){
	var oForm = document.NAVIG_JSP ;
	if(oForm != null){
		oForm.RCShip_Country.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		if( oForm.OMSACountry_Name != null ){
			oForm.OMSACountry_Name.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
		}
		if( oForm.UMSACountry_Name != null ){
			oForm.UMSACountry_Name.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
		}
		if( oForm.RCShip_Country_Name != null ){
			oForm.RCShip_Country_Name.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
		}
		if( oForm.OMCountry_Name != null ){
			oForm.OMCountry_Name.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text
		}
		oForm.RCShip_Province.value = "---" ;
		oForm.RCShip_Province_Name.value =  "none" ;
	}

	oForm = document.OMShippingAddress ;
	if(oForm != null){
		if( oForm.OMSACountry_Name != null ){
			oForm.OMSACountry_Name.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
		}
	}		

	oForm = document.OMAdditionalShippingAddress ;
	if(oForm != null){
		if( oForm.OMSACountry_Name != null ){
			oForm.OMSACountry_Name.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
		}
	}		

	oForm = document.UMRegisterCustomer ;
	if(oForm != null){
		if( oForm.RCShip_Country_Name != null ){
			oForm.RCShip_Country_Name.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
		}
	}

	oForm = document.UMUpdateCustomer ;
	if(oForm != null){
		if( oForm.UMSACountry_Name != null ){
			oForm.UMSACountry_Name.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
		}
	}

	oForm = document.NAVIG ;
	if(oForm != null){
		oForm.RCShip_Country.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		if( oForm.OMCountry_Name != null ){
			oForm.OMCountry_Name.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
		}

		oForm.RCShip_Province.value = "---" ;
		oForm.RCShip_Province_Name.value =  "any" ;
	}
}

function nav_BILLCOUNTRY(oSelect){
	var oForm = document.NAVIG_JSP ;
	if(oForm != null){
		oForm.RCBill_Country.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		if( oForm.OMBACountry_Name != null ){
			oForm.OMBACountry_Name.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
		}
		if( oForm.RCBill_Country_Name != null ){
			oForm.RCBill_Country_Name.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
		}
		if( oForm.OMCountry_Name != null ){
			oForm.OMCountry_Name.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
		}
		if( oForm.UMBACountry_Name != null ){
			oForm.UMBACountry_Name.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
		}
		if( oForm.bCountry != null ){
			oForm.bCountry.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
		}
		
		oForm.RCBill_Province.value = "---" ;
		oForm.RCBill_Province_Name.value =  "none" ;
	}
	
	oForm = document.OMBillingInformation ;
	if(oForm != null){
		if( oForm.OMBACountry_Name != null ){
			oForm.OMBACountry_Name.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
		}
	}
	
	oForm = document.OMShippingAddress ;
	if(oForm != null){
		if( oForm.OMBACountry_Name != null ){
			oForm.OMBACountry_Name.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
		}
	}
	oForm = document.OrderPaymentsCCAddNew ;
	if(oForm != null){
		if( oForm.bCountry != null ){
			oForm.bCountry.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
		}
	}
	
	oForm = document.UMRegisterCustomer ;
	if(oForm != null){
			
		if( oForm.RCBill_Country_Name != null ){
			oForm.RCBill_Country_Name.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
		}
	}

	oForm = document.UMUpdateCustomer ;
	if(oForm != null){
		
		if( oForm.UMBACountry_Name != null ){
			oForm.UMBACountry_Name.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
		}
	}

	oForm = document.NAVIG ;
	if(oForm != null){
		oForm.RCBill_Country.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		if( oForm.OMCountry_Name != null ){
			oForm.OMCountry_Name.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
		}

		oForm.RCBill_Province.value = "---" ;
		oForm.RCBill_Province_Name.value =  "any" ;
	}
}
// -------------------------------------------------------------------------------
function nav_LANGUAGE(oSelect){ 
	var oForm = document.NAVIG_JSP ;
	if(oForm != null){
		oForm.LANG_recherche.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		oForm.Nom_LANG_recherche.value =  oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
	}
	oForm = document.NAVIG ;
	if(oForm != null){
		oForm.LANG_recherche.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		oForm.Nom_LANG_recherche.value =  oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].text ;
	}
}
// -------------------------- Modified for the new template.-----------------------------------------------------
function CheckBalance (oSelect) {

	var oForm = document.OrderPaymentsCCAddNew;
	
	if(oForm != null) {
		if ( oForm.bCard_Number.value == "") {
			alert("Please enter a Gift Card Number");
			oForm.bCard_Number.focus();
		}
		else {
			url = "http://cardbalance.storedvalue.com/BRBPU_en_Results.shtml?Host=brooksbrospop.html&CardNumber=" + oForm.bCard_Number.value;
			window.open(url,"Popwin", "scrollbars=no,width=443,height=300");
		}
	}
}

// -------------------------------------------------------------------------------
function display_shipping_charges (oSelect) {

	var oForm = document.OMShippingAddress;
	
	if(oForm != null) {
			url = "/showShippingCharges.process?Country="+oForm.OMSACountry_Name.value+"&Province="+oForm.OMSAProvince.value;
			window.open(url,"ShippingCharges","toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=no,scrollbars=yes,width=550,height=500,top=100,left=100");
	}

	var oForm = document.OMAdditionalShippingAddress;
	
	if(oForm != null) {
			url = "/showShippingCharges.process?Country="+oForm.OMSACountry_Name.value+"&Province="+oForm.OMSAProvince.value;
			window.open(url,"ShippingCharges","toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=no,scrollbars=yes,width=550,height=500,top=100,left=100");
	}
}

function nav_SHIPMETHOD(oSelect){
	var oForm = document.NAVIG_JSP ;
	if(oForm != null){
		oForm.OMShip_Method.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		if( oForm.OMShippingMethod != null ){
			oForm.OMShippingMethod.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
			oForm.OMShipping_Method_Id.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		}
	}
	
	oForm = document.OMShippingAddress ;
	if(oForm != null){
		if( oForm.OMShippingMethod != null ){
			oForm.OMShippingMethod.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
			oForm.OMShipping_Method_Id.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		}
	}		

	oForm = document.OMAdditionalShippingAddress ;
	if(oForm != null){
		if( oForm.OMShippingMethod != null ){
			oForm.OMShippingMethod.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
			oForm.OMShipping_Method_Id.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		}
	}		

	oForm = document.NAVIG ;
	if(oForm != null){
		oForm.OMShip_Method.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		if( oForm.OMShippingMethod != null ){
			oForm.OMShippingMethod.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
			oForm.OMShipping_Method_Id.value = oSelect.options[oSelect.options.selectedIndex < 0 ? 0 : oSelect.options.selectedIndex].value ;
		}
	}
}
function disableEnterKey(e)
{
     var key;
     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox
     if(key == 13)
          return false;
     else
          return true;
}

function isPositiveInteger(val){
      if(val==null){return false;}
      if (val.length==0){return false;}
      for (var i = 0; i < val.length; i++) {
            var ch = val.charAt(i)
            if (ch < "0" || ch > "9") {
            return false;
            }
      }
      return true;
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

