Behaviour.register({
    '#Form_SearchRetailerForm_Search' : {
        onfocus : function() {
            if(this.value == 'Enter zip / postal code / city') this.value = '';
            if(this.value == 'Entrez une ville ou un code postal') this.value = '';
        }
    }
});
Behaviour.register({
    '#Form_SearchRetailerForm2_Search' : {
        onfocus : function() {
            if(this.value == 'Enter zip / postal code / city') this.value = '';
            if(this.value == 'Entrez une ville ou un code postal') this.value = '';
        }
    }
});
Behaviour.register({
    '#SearchForm_SearchForm_SearchForm' : {
        onfocus : function() {
            if(this.value == 'Search site') this.value = '';
            if(this.value == 'Rechercher') this.value = '';
        }
    }
});


function changeBackgoundImage(img){

    createCookie('bgImage', img, 7 )

    var element = document.getElementById("imgContent");
    var layoutBG = document.getElementById("backgroundSpecial");
    var imgContent = document.getElementById("imgContent");
    var bgImg = "url(themes/appalachianflooring/images/" + img + ".jpg)";
    var bgImg2 = "url(themes/appalachianflooring/images/" + img + "shaded.jpg)";
    if (element){ element.style.backgroundImage = bgImg; }
    if (layoutBG && imgContent == null){ layoutBG.style.backgroundImage = bgImg2; }
}

function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}


function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

var bgImage = readCookie('bgImage');
if (bgImage != null) {
    changeBackgoundImage(bgImage);
}

/*

google.load("maps", "2");
google.load("search", "1");

// Call this function when the page has been loaded
function initialize() {
    if(document.getElementById("googleMap") != null) {
        var map = new google.maps.Map2(document.getElementById("googleMap"));
        map.setCenter(new google.maps.LatLng(45.2106,-72.7943), 13);

        var searchControl = new google.search.SearchControl();
        searchControl.addSearcher(new google.search.WebSearch());
        searchControl.addSearcher(new google.search.NewsSearch());
        searchControl.draw(document.getElementById("googleMap"));
    }
}
google.setOnLoadCallback(initialize);
*/

function dealerMap(mLang, mCodeCivic, mStreet, mCity, mZip, newArrow) {
    bgImg = "url(themes/theme02/images/btnArrow.png)";

    document.getElementById("googleMap").innerHTML = '<iframe width="418" height="390" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.ca/maps?f=q&amp;source=s_q&amp;hl='+mLang+'&amp;geocode=&amp;q='+mCodeCivic+'+'+escape(mStreet)+'+'+mCity+'+'+mZip+'&amp;sspn=0.011942,0.032938&amp;ie=UTF8&amp;hq=&amp;hnear='+mCodeCivic+'+'+mStreet+'+'+mCity+'+'+mZip+'&amp;spn=0.023579,0.035791&amp;z=14&amp;iwloc=A&amp;output=embed"></iframe>';


    var allDiv = document.getElementsByClassName("arrowID")
    allDiv[0].style.display = "none";
    allDiv[1].style.display = "none";
    allDiv[2].style.display = "none";
    allDiv[3].style.display = "none";
    allDiv[4].style.display = "none";


    document.getElementById(newArrow).style.display = "block";
    document.getElementById(newArrow).style.backgroundImage = bgImg;
}

function toggleProductImage() {
    var element = document.getElementById("GradeImageFullSize").style;
    var element2 = document.getElementById("toggleProduct").style;
    if(element.height < '338px') {
        element.height = '338px';
        element2.backgroundImage = "url(themes/appalachianflooring/images/toggleless.png)";
    } else {
        element.height = '108px';
        element2.backgroundImage = "url(themes/appalachianflooring/images/togglemore.png)";
    }
}

function popup_image(image, speciename, gradename, colorname ) {
    url = "popup/popup_color.php?image="+image+"&specie="+speciename+"&grade="+gradename+"&color="+colorname;
    window.open( url,'', 'width=477, height=358');
}

function selectState(stateId) {
    jQuery('#Form_SearchRetailerForm_Search').val(jQuery('#RetailerSearchArgs input[name=Search]').val());
    jQuery('#Form_SearchRetailerForm_Distance').val(jQuery('#RetailerSearchArgs input[name=Distance]').val());
    jQuery('#Form_SearchRetailerForm_StateId').val(stateId);
    jQuery('#Form_SearchRetailerForm').submit();
}

