// ------[ IE6 Cache Control (remove flicker on mouseover) ]------------------------------------------------- //	
try {
  document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}

var lang = "";

// ------[ Master Onload for all page. ]------------------------------------------------- //	
window.Rona = window.Rona || {};

Rona = {	
	isIE6 : false,
	Init : function() {		
		
		document.body.className = document.body.className + " is" + BrowserDetect.browser;	
				
		Rona.Navigation.Init();
		Rona.Search.Init();	
		Rona.PostalCode.Init();
	}
};
YAHOO.util.Event.onDOMReady(Rona.Init, Rona, true);

// ------[ Header : Main Navigation  ]------------------------------------------------- //
Rona.Navigation = {
	Init : function() {
		this.nav = document.getElementById('navigation'); 
		this.subNav = YAHOO.util.Dom.getChildren(this.nav);
		
		/* set the background of the navigation to emulate a full 100% width nav. */
		var lastItem = YAHOO.util.Dom.getLastChild(this.nav);	
		YAHOO.util.Dom.addClass(lastItem, 'last');
		
		YAHOO.util.Event.addListener(lastItem, "mouseover",  function() {
			this.nav.style.backgroundColor = "#005aa5";				
		}, Rona.Navigation, true);
		
		YAHOO.util.Event.addListener(lastItem, "mouseout",  function() {
			this.nav.style.backgroundColor = "#002f54";				
		}, Rona.Navigation, true);		
		
		if(Rona.isIE6) this.IE6Patch();
		this.Position();		
	},
	
	Position : function() {
		var viewport = YAHOO.util.Dom.getRegion('container');
		
		for(x=0; x<this.subNav.length-1; x++) {
			var menu = this.subNav[x].getElementsByTagName('ul')[0];			
			var region = YAHOO.util.Dom.getRegion(menu);								

			if(region.right > viewport.right) {								
				YAHOO.util.Dom.setStyle(menu, 'left', 'auto');	
				YAHOO.util.Dom.setStyle(menu, 'right', '-1px');	
				
				if(Rona.isIE6) {
					YAHOO.util.Dom.setStyle(menu, 'right', '-2px');						
					YAHOO.util.Dom.setStyle(this.subNav[x].iFrame, 'left', 'auto');	
					YAHOO.util.Dom.setStyle(this.subNav[x].iFrame, 'right', '-2px');	
				}				
			} 
		}		
	},
	
	IE6Patch : function() {
		/* IE6 patch - create a Iframe behind the sub menu to mouseover form element (select) and object (flash) */					
		for(x=0; x<this.subNav.length; x++) {
			var menu = this.subNav[x].getElementsByTagName('ul')[0];	
			if(menu) {				
				var region = YAHOO.util.Dom.getRegion(menu);
				
				this.subNav[x].w = region.right - region.left + 'px';
				this.subNav[x].h = region.bottom - region.top + 'px';
			
				this.subNav[x].iFrame = document.createElement('iframe');
				this.subNav[x].iFrame.className = 'dhtml-patch';
				this.subNav[x].iFrame.setAttribute('src','javascript:document.open();document.write("");document.close();');
				this.subNav[x].iFrame.style.visibility = 'hidden';
				this.subNav[x].iFrame.frameBorder = 0;
				this.subNav[x].iFrame = menu.parentNode.appendChild(this.subNav[x].iFrame);				

				YAHOO.util.Dom.setStyle(this.subNav[x].iFrame, 'width', this.subNav[x].w);
				YAHOO.util.Dom.setStyle(this.subNav[x].iFrame, 'height', this.subNav[x].h);				
			
				YAHOO.util.Event.addListener(this.subNav[x], "mouseover",  function() {																												
					YAHOO.util.Dom.setStyle(this.iFrame, 'visibility', 'inherit');			
				}, this.subNav[x], true);
				
				YAHOO.util.Event.addListener(this.subNav[x], "mouseout",  function() {
					YAHOO.util.Dom.setStyle(this.iFrame, 'visibility', 'hidden');
				}, this.subNav[x], true);									
			}		
		}
	}		
	
};

// ------[ Header : Form ]------------------------------------------------- //
Rona.Circulaire = {
	Go : function(url) {
		document.location = url + "?postalcode=" + Rona.PostalCode.currentPostalCode;
	}
};


// ------[ Header : Form ]------------------------------------------------- //
Rona.Form = {
	isEmpty : function(field) {
		if(field.value == null || field.value == "" || field.value == field.label) {
			return true;
		} else {
			return false;
		}		
	}	
};

Rona.Form.Label = {	
	Clic : function() {	
		if(this.value == this.label) this.value = '';
	},	
	
	Blur : function() {
		if(this.value == '') this.value = this.label;
	}
};

// ------[ Header : Search UI ]------------------------------------------------- //
Rona.Search = {	    	
	errorMessage : null,
	sortorderup : null,
	sortorderdown : null,
	
	
	Init : function() {	 //call from Rona.Init				
		this.form = document.getElementById('searchform');			
		this.keywords = document.getElementById('search-keywords');	
		this.keywords.label = this.keywords.getAttribute('title');
		this.external = document.getElementById('external');
				
		YAHOO.util.Event.addListener(this.form, "submit", this.Recherchez, this, true);		
		YAHOO.util.Event.addListener(this.keywords, "click", Rona.Form.Label.Clic, this.keywords, true);
		YAHOO.util.Event.addListener(this.keywords, "blur", Rona.Form.Label.Blur, this.keywords, true);	
	},		
 	
	Recherchez : function(e) {
		if(Rona.Form.isEmpty(this.keywords)) {
			alert(Rona.Search.errorMessage);  
  			YAHOO.util.Event.stopEvent(e);
		} else {
			if(this.external == null) Rona.Cookie.Save('Search', true, false)
			return true;
		}
	},
	
	Triez : function(obj) {
		//YAHOO.util.Event.stopEvent(e);
											
		var data = "" + document.location;
		var pageNo = Rona.GetRequestParameter("page");
		var sortNo = obj.options[obj.selectedIndex].value;
		var keywords = Rona.GetRequestParameter("keywords");		
		
		var oldSort = Rona.GetRequestParameter("sort");
		
		if (oldSort == sortNo) {
			sortNo = this.sortorderdown.value;
		}
		
		if (data.indexOf("?") != -1) {	
			data = data.substring(0, data.indexOf("?"));				
		}

		data += "?sort=" + sortNo;
		
		if (pageNo != "undefined") {
			data += "&page=" + pageNo;
		}		
		
		if (keywords != "undefined") {
			data += "&keywords=" + keywords;
		}
		
		var productIds = '';	
		var frm = document.getElementById('formCompareProducts');
		for(x=0; x<frm.productId.length; x++) {
			if(frm.productId[x].checked) productIds += "&productId=" + frm.productId[x].value;		
		}
		data += productIds;	
		
		document.location = data;
		return true;
	},
	
	GetCookie : function() {
		return (Rona.Cookie.Load('Search') == 'true') ? true : false;
	}

};

// ------[ Advanced Search UI ]------------------------------------------------- //
Rona.Search.Advanced = {
	container : null, 
	button : null,
	panel : null,
	isOpen : false,
	
	Init : function() { //call from page if needed
		this.container = document.getElementById(this.container);
		this.button = document.getElementById(this.button);
		this.panel = YAHOO.util.Dom.getElementsByClassName('panel', 'div', this.container);		

		this.button.href = "javascript:void(0);";
		YAHOO.util.Event.addListener(this.button, "click", function() {
			this.isOpen = (this.isOpen) ? false : true;						
			if(this.isOpen) {
				
				YAHOO.util.Dom.addClass(this.container, 'open');						
			} else {
				YAHOO.util.Dom.removeClass(this.container, 'open');			
			}					
		}, this, true);			
		
		YAHOO.util.Event.addListener(this.panel, "mouseover", function() {
			YAHOO.util.Dom.addClass(this.container, 'open');
			this.isOpen = true;
		}, this, true);	
		
		YAHOO.util.Event.addListener(this.panel, "mouseout", function() {
			YAHOO.util.Dom.removeClass(this.container, 'open');												  
			this.isOpen = false;
		}, this, true);		
	}
};

// ------[ Browser Detection ]------------------------------------------------- //
// ------[ http://www.quirksmode.org/js/detect.html ]------------------------------------------------- //
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";		
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]
};
BrowserDetect.init();


// ------[ XiTi::xt_med()::clic de navigation ]------------------------------------------------- //
function xt_med(type,section,page,x1,x2,x3,x4,x5)
{xt_img = new Image();
xtdate = new Date();
xts = screen;
xt_ajout = (type=='F') ? '' : (type=='M') ? '&a='+x1+'&m1='+x2+'&m2='+x3+'&m3='+x4+'&m4='+x5 : '&clic='+x1;
Xt_im = 'http://logc22.xiti.com/hit.xiti?s=271511&s2='+section;
Xt_im += '&p='+page+xt_ajout+'&hl=' + xtdate.getHours() + 'x' + xtdate.getMinutes() + 'x' + xtdate.getSeconds();
if(parseFloat(navigator.appVersion)>=4)
{Xt_im += '&r=' + xts.width + 'x' + xts.height + 'x' + xts.pixelDepth + 'x' + xts.colorDepth;}
xt_img.src = Xt_im;
if ((x2 != null)&&(x2!=undefined)&&(type=='C'))
{ if ((x3=='')||(x3==null)) { document.location = x2} else {xfen = window.open(x2,'xfen',''); xfen.focus();}}
else
{return;}}