var ns4=document.layers
var ie4=document.all
var ns6=document.getElementById&&!document.all

function PrintCurrentPage(printAutomationLogo) {
    printAutomationLogo = typeof(printAutomationLogo) != 'undefined' ? printAutomationLogo : 0; //printAutomationLogo defaults to false..

    var LogoHTML='';
    if (printAutomationLogo==1) {
        LogoHTML = "<table width='722' border='0' cellspacing='0' cellpadding='0'><tr><td valign='top' width='350'><img src='../images/logos/at-hom.gif' alt='' width='140' height='61' border='0' /></td><td width='22'> </td><td align='right' valign='top' width='350'><img src='../images/logos/cerco_white.gif' alt='' width='144' height='67' border='0' /></td></tr></table><br /><br />";
    } else {
        LogoHTML = "<table width='722' border='0' cellspacing='0' cellpadding='0'><tr><td valign='top' width='350'> </td><td width='22'> </td><td align='right' valign='top' width='350'><img src='../images/logos/cerco_white.gif' alt='' width='144' height='67' border='0' /></td></tr></table><br /><br />";
    }
var FooterHTML='';
FooterHTML = "<br />" + Date() + "<br />"

    if (ie4) {
        parent.PrintFrame.document.body.innerHTML = '<html><head><title></title></head><body>' + LogoHTML + printReady.innerHTML + FooterHTML + '<br><br></body></html>';
        PrintFrame.focus();
        PrintFrame.print();
    } else if (ns6) {
        parent.PrintFrame.document.body.innerHTML = LogoHTML + document.getElementById('printReady').innerHTML + FooterHTML;
        PrintFrame.focus();
        PrintFrame.print();
    } else if (ns4) {
        top.print();
    } else {
        alert('An error has occured, system cannot print this page (Try using IE5.5+ or Firefox 1.x+)');
    }
}

function CallUrl(pageUrl,linkType) {
    linkType = typeof(linkType) != 'undefined' ? linkType : '0';
    
    if (linkType==1) {
    	window.open(pageUrl); return false;
    } else {
    	document.location.href=pageUrl;
    }
}

//TODO: this function could be more generic... but works for now
//param token: this is a random token generated in PHP,
//              that enables us to have multiple ProductFinders per page
//param selitem: if==1, means we want that item as 'selected' in the dropdown by default
function CatAction(token,box,parentid,selitem,jspath) {
    selitem = typeof(selitem) != 'undefined' ? selitem : 0; //selitem defaults to false..

    //TODO: Some strange problem here
    //This code is to prevent the browser from calling an url when
    //"Choose a category" is selected in a dropdown
    //This problem should really be handled better, but it works for now
    if (navigator.appVersion.indexOf("MSIE") != -1) {
        if (parentid=='' && box>0) { parentid='--';}
    } else {
        if (parentid=='undefined') { parentid='--'; } //if parentid undefined, set to --
    }

    //Hide dropdown boxes..
    if (box==1) {
        document.getElementById('divCat1_'+token).style.display = 'none';
        document.getElementById('divCat2_'+token).style.display = 'none';
        document.getElementById('divCat3_'+token).style.display = 'none';
        document.getElementById('divCat4_'+token).style.display = 'none';
    } else if (box==2) {
        document.getElementById('divCat2_'+token).style.display = 'none';
        document.getElementById('divCat3_'+token).style.display = 'none';
        document.getElementById('divCat4_'+token).style.display = 'none';
    } else if (box==3) {
        document.getElementById('divCat3_'+token).style.display = 'none';
        document.getElementById('divCat4_'+token).style.display = 'none';
    } else if (box==4) {
        document.getElementById('divCat4_'+token).style.display = 'none';
    }

    var SelectedId=0;
    //if 'Choose a Category' option selected, ignore..
    if (parentid!='--') {
        if (!ArrCatList[parentid]) {
            //if can't find selected option in CatList, means no child
            //so fire page reload to display products
            var selbox = eval('document.frmProductFinder_'+token+'.selCat'+(box-1)+'_'+token);

            if (jspath!='') {
                document.location.href=jspath+'?c='+selbox.options[selbox.selectedIndex].value;
            } else if (ArrCatLink[selbox.options[selbox.selectedIndex].value]=='') {
                document.location.href='../produits/products_list.php?c='+selbox.options[selbox.selectedIndex].value;
            } else {
                document.location.href='../produits/'+ArrCatLink[selbox.options[selbox.selectedIndex].value]+'?c='+selbox.options[selbox.selectedIndex].value;
            }
        } else {
            //Add a new child dropdown
            var selbox = eval('document.frmProductFinder_'+token+'.selCat'+box+'_'+token);
            selbox.options.length = 0;
            document.getElementById('divCat'+box+'_'+token).style.display = 'block';

            for(i=0;i<ArrCatList[parentid].length;i++) {
              //add all dropdown options, and check which item should be selected by default.. seems to only work for FireFox
              OptSel = (selitem==1 && ArrCatId[parentid][ArrCatList[parentid][i]]==ArrCatLevel[box+1]) ? true : false;

              //seems that i have to do this manually for IE..
              if (OptSel==true) { SelectedId=i; }

              selbox.options[selbox.options.length] = new Option(ArrCatList[parentid][i],ArrCatId[parentid][ArrCatList[parentid][i]],OptSel);
            }
        }

        //for IE: seems like we have to do it manually.. since new Options() isnt doing it..
        selbox.options[SelectedId].selected=true;

    }

}

var preloadFlag = false;
function preloadImages() {
    if (document.images) {
        pre_mainnav_home_over = newImage('../images/nav/mainnav_home_over.gif');
        pre_mainnav_support_over = newImage('../images/nav/mainnav_support_over.gif');
        pre_mainnav_about_over = newImage('../images/nav/mainnav_about_over.gif');
        pre_mainnav_products_on_over = newImage('../images/nav/mainnav_products_on_over.gif');
        pre_mainnav_business_over = newImage('../images/nav/mainnav_business_over.gif');
        preloadFlag = true;
    }
}