// First Run Function ////////////////////////////////////////////

// Detection des cookies ( supporte ou pas )
// Si aucun cookie, on essaie d'en créer un et de le lire.
// S'il n'y a toujours pas de cookie, le client ne supporte pas les cookies

function testCookie() {

	if (!document.cookie) {

		document.cookie = "create=ok";
	
		if (!document.cookie) {

			var language = getLanguageFromQueryString();
			var msg;
		
			if (language == "-1") {
				msg = "IMPORTANT!\n\nThe current configuration of your browser does not accept cookies.*\n\nIn order for you to VISUALIZE ITEM PRICES, you MUST ENABLE COOKIES* and you must enter your POSTAL CODE when prompted.\n\n* For more information on the subject matter please consult the « Security and Confidentiality » page within FAQ in the « SHOP » section.";
			} else {
				msg = "IMPORTANT!\n\nÀ l’heure actuelle, votre fureteur n’est pas configuré pour autoriser les témoins (cookies).*\n\nAfin d’être en mesure de VISUALISER le PRIX des articles, vous DEVEZ AUTORISER * le stockage des témoins (cookies) et entrer votre CODE POSTAL lorsque le système vous le demande.\n\n* Pour de plus amples informations à ce sujet, veuillez consulter la rubrique « Sécurité et confidentialité » dans la FAQ de la section « ACHATS ».";
			}
		
			alert(msg);

		}
	}
}

// Get the language parameter from the query string
function getLanguageFromQueryString() {

	var lang = "";
	
	var query = location.search.substring(1); // Get the query string

	var pairs = query.split("&");

	for (var i = 0; i < pairs.length; i++) {

		var pos = pairs[i].indexOf('=');

		if (pairs[i].substring(0,pos) == "langId") {
			lang = pairs[i].substring(pos+1);
			break;
		}
	}
	
	return lang;
}

//// Next Previous
function reloadList(pagex, currentpage, pageStart, pageEnd) {
      document.myForm.pageStart.value = pageStart;
      document.myForm.pageEnd.value = pageEnd;
      if (pagex=="previous") {
        document.myForm.currentpage.value = currentpage - 1;
      } else if (pagex=="next") {
        document.myForm.currentpage.value = currentpage + 1;
      } else {
        document.myForm.currentpage.value = pagex;
      }
   		document.myForm.submit();
    }
//// Next Previous 5 blocks
function reloadBlockList(pagex, currentpage, pageStart, pageEnd) {
      document.myForm.pageStart.value = pageStart;
      document.myForm.pageEnd.value = pageEnd;
      if (pagex=="previous") {
        document.myForm.currentpage.value = pageStart - 5;
        document.myForm.pageStart.value = pageStart-5;
      	document.myForm.pageEnd.value = pageEnd-5;
      } else if (pagex=="next") {
        document.myForm.currentpage.value = pageStart + 5;
        document.myForm.pageStart.value = pageStart+5;
      	document.myForm.pageEnd.value = pageEnd+5;
      } else {
        document.myForm.currentpage.value = pagex;
      }
      
   		document.myForm.submit();
    }    
    
// Dhtml Programs ///////////////////////////////////////////////
function init() {
//	initlayers();
	} 
	
	

function https_commands()
	{
	var urlval = window.location.href;
	var replaceStr=/https/;
	if (urlval.search("https") > -1){
		document.location = urlval.replace(replaceStr,"http");
		}
	}

//  Roll over des images du menu 
var lastMenuDivId = ""
function roll(lang,imid,state)
	{
	setimage(lang,imid,state);
	}

function setimage(lang,imid,state)
	{
	img = ("img"+imid);
	imgSrc = (lang + "/nav_" + imid + state +".gif");
	if ( document.layers)document.images[img].src = imgSrc;
	else document[img].src = imgSrc;
	}

lastSubDiv = ""
function submenu(id)
	{
	if(lastSubDiv == id)
		{
		hidesubmenu(id);
		lastSubDiv = "";
		}
	else
		{ 
		if(lastSubDiv) hidesubmenu(lastSubDiv);
		lastSubDiv = id;
		showsubmneu(id)
		}
	}

function sousmenu(lang,ids,state)
	{
	var submenu = eval("sousmenu" + ids)
	//document['img' + ids].src = "/img/" + lang + "/somme_" + state +".gif"
	if (state == "on") submenu.show();
	else submenu.hide();
	}   
	
// Global Function /////////////////////////////////////

function clearSearch()	
	{
	alert('vide la boite search');
	}

// Fix for Netscape (doesnt work for 4.08)
function fix()
	{
	//bVer='';
	//bName = navigator.appName.toLowerCase();
   // bVer=navigator.appVersion.substring(0,3);
	
   // if(bName == "netscape" && bVer>= '4.08')
	//	{
	//	location.reload();
	//	}
	}	
	
// fonction pour ouvrir une petite fenetre
function open_window(url,w,h)
	{
	var window_handle=window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=' + w + ',height=' + h + ',top=20,left=20');
	window_handle.focus();
	}

// fonction pour ouvrir une petite fenetre avec le nom de la fenetre
function open_window(url,name,w,h)
    {
    var window_handle=window.open(url,name,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=' + w + ',height=' + h + ',top=20,left=20');
    window_handle.focus();
    }

// fonction pour ouvrir une petite fenetre
function open_window_noresize(url,w,h)
	{
	var window_handle=window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=' + w + ',height=' + h + ',top=20,left=20');
	window_handle.focus();
	}

	
// fonction pour ouvrir une petite fenetre avec scroll
function open_window_scroll(url,w,h)
	{
	var window_handle=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=' + w + ',height=' + h + ',top=20,left=20');
	window_handle.focus();
	}

// lacm - 2002-11-21
// fonction pour ouvrir une petite fenetre avec scroll et name
function open_window_scroll_name(url,name,w,h)
	{
	var window_handle=window.open(url,name,'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=' + w + ',height=' + h + ',top=20,left=20');
	window_handle.focus();
	}

// cloum - 2002-08-14
// fonction pour ouvrir une petite fenetre avec scroll ET menu/toolbar/address
function open_window_scroll_menu(url,w,h)
	{
	var window_handle=window.open(url,"win",'toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=' + w + ',height=' + h + ',top=20,left=20');
	window_handle.focus();
	}

// Fonction pour imprimer la page en cours 
function printCurrentPage() {
   if (navigator.appName.indexOf("Microsoft") > -1 &&
       navigator.appVersion.indexOf("5.") == -1) {               // EXPLORER 4  MIN
      // IE4 
      OLECMDID_PRINT = 6;
      OLECMDEXECOPT_DONTPROMPTUSER = 2;
      OLECMDEXECOPT_PROMPTUSER = 1; 
      WebBrowser = 
       '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>'; 
      document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
      WebBrowser1.ExecWB(OLECMDID_PRINT,   OLECMDEXECOPT_PROMPTUSER);
      WebBrowser1.outerHTML = "";
     }
   else {
     // N4 IE5
     window.print();
     }
   } 	
function clearDefaultValue(field)
{
	if(field.value == field.defaultValue)
		field.value = "";
}
function stringIsEmpty(aString)
{
	var nstring = "";
	var sp = aString.split(" ");
	for(var i=0; i < sp.length; i++)
	{
		nstring += sp[i];
	}
	return nstring == "";
}

function gotoNodeURL(anURL)
{ 
	if(storeServerName == null)
		window.location = 'http://www.rona.ca' + anURL;
	else
		window.location = 'http://' + storeServerName + anURL;
}

// cette fonction retourne une référence au premier objet FORM 
// du document courant qui contient le champ dont le nom est passé en paramètre.
// Retourne NULL si aucune forme contenant un tel objet n'est trouvé
function getForm(fieldName) {
	var formsNb = document.forms.length;
	var field = null;
	var i=-1;
	
	while ((i<formsNb) && (field==null)) {
		field = eval("document.forms["+(++i)+"]."+fieldName);
	}

	if (field!=null){
		return document.forms[i];
	}else{
		return null;
	}
}


function open_deco(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//Fonction utilisée pour ouvrir des liens externes dans une nouvelle fenêtre
//permet à l'utilisateur la plus grande flexibilité sur les options de la nouvelle fenêtre
function open_external_link(theURL,name,features) {
  window.open(theURL,name,features);
}
//function used in many press realeased to open a pop up
function openNewUrlWin(url) {

		window.open(url);

}
