﻿// section moteur de recherche
function isBlank(str){
	if ( typeof(str) =='undefined' || str==null)
		return true;
	for (var i=0;i<str.length;i++){
	var c = str.charAt(i);
	if ((c!="") && (c!=" ") && (c!= '\t') && (c!='\n') && (c!='\f') &&  (c!='\r') )
		return false;
	}
	return true;
}


function ClearTextIfDefault(objTxtBox,defText)
{
  if (objTxtBox.value==defText){
        objTxtBox.value = "";
    } 
}

function InitDefaultIfEmpty(objTxtBox,defText)
{
    if (isBlank(objTxtBox.value)){
        objTxtBox.value = defText;
    }
}
function GoSearch(objTxtBox,defText,filePath,textIfDefOrEmpty)
{
    if (objTxtBox.value==defText || isBlank(objTxtBox.value)){
        alert(textIfDefOrEmpty);
    }
    else
    {
        var urlSearch = filePath + '?searchCode=' + escape(objTxtBox.value);
        document.location.href= urlSearch;
    }
    return false;
}

function GoSearchDealer(objTxtBox,defText,filePath,textIfDefOrEmpty, textIfInvalide)
{
    var urlSearch = filePath;
    var zipRegExp = /^\s*[a-ceghj-npr-tvxy]\d[a-z](\s)?\d[a-z]\d\s*$/;
    if (objTxtBox.value==defText || isBlank(objTxtBox.value)){
        alert(textIfDefOrEmpty);
        //urlSearch = filePath + '?pg=' +escape(province);
    }else if(!zipRegExp.test(objTxtBox.value)){
        alert(textIfInvalide);
    }    
    else
    {
        if (filePath.indexOf("?pg=") > -1){  
            urlSearch = filePath + "&cp=" + escape(objTxtBox.value);
        }else{
            urlSearch = filePath + "?pg=-1&cp=" + escape(objTxtBox.value);            
        }
        document.location.href= urlSearch;
    }    
    return false;
}

function noenter(strToEval,evt) 
{
	if (window.event){
		if (evt.keyCode == 13){
		eval(strToEval);
		return false;}
	}
	else if (window.Event){
		if (evt.which == 13){
		eval(strToEval);
		return false;}
	}
	else
		return true;
}



// fin section moteur de recherche

// visualisation des produits dans fenetre popUp
var formerImgSrc,formerLang;
var fenViewProduct;
function openfenViewProduct(imgSrc,lang){
    var fenName = "imgProFen";
    var fileName = "/popUp/voirProduit.aspx";
	var width = 150;
	var height = 150;
    var fenFeatures = "width="+width+",height="+height+",resizable=no,scrollbars=no,location=no,toolbar=no;menubar=no"
    if (lang.toUpperCase()=="EN-CA"){
        fileName = "/popUp/viewProduct.aspx";
	}
	fenViewProduct = window.open(fileName + '?imgSrc=' + escape(imgSrc),fenName,fenFeatures); 
	
}

function viewImageProduct(imgSrc,lang){
	if (fenViewProduct == null){
		openfenViewProduct(imgSrc,lang);
	}
	else {
		if (fenViewProduct.closed)
			openfenViewProduct(imgSrc,lang);
		else if (imgSrc != formerImgSrc || lang != formerLang)
			openfenViewProduct(imgSrc,lang);
		
	} 
	fenViewProduct.focus();
	formerImgSrc = imgSrc;
	formerLang = lang;
}
// fin visualisation des produits dans fenetre popUp

/* section view more accueil */
var curProdCatNo = 1;
var nbImg = 5
function viewMore(imgName)
{
    if (curProdCatNo < nbImg){
        curProdCatNo++;
    }
    else{
        curProdCatNo = 1;
    }
    
    if (document.images && document.images[imgName])
    { 
        var strCurProdCatNo = curProdCatNo.toString();
        if (curProdCatNo < 10){
            strCurProdCatNo = '0' + curProdCatNo.toString();
       }
       
       document.images[imgName].src = "/images/RotatorProduct/Img_AccProduct_" + strCurProdCatNo + ".jpg"; 
    }
    
}

function viewProductCategory(lang)
{
    var fileName = "lignes-de-produits.aspx";
    
    if (lang.toUpperCase()=="EN-CA")
    {
        fileName = "product-lines.aspx"
    }
    document.location.href= fileName + "?pcatId=" + curProdCatNo.toString();
    
}
// fin section view more accueil 