﻿// Search form radio buttons postback
function postform() {
    document.forms[0].action = '';
    document.forms[0].submit();
}

// Add to favourites/bookmark code
function addBookmark() {
    title = document.title;
    url = window.location.href;
    if (window.sidebar) { // Firefox
        window.sidebar.addPanel(title, url, '');
    } else if (window.opera) { //Opera
        var a = document.createElement("A");
        a.rel = "sidebar";
        a.target = "_search";
        a.title = title;
        a.href = url;
        a.click();
    } else if (document.all) { //IE
        window.external.AddFavorite(url, title);
    }
}

// About us show/hide nav panel
function aboutHovered() {

    var obj = document.getElementById("aboutusdiv");
    var obj2 = document.getElementById("aboutusiframe");
    var obj3 = document.getElementById("aboutspan");
    var obj4 = document.getElementById("abouturl");

    obj.style.display = 'block';
    obj2.style.display = 'block';
    obj3.style.backgroundPosition = '100% -40px';
    obj4.style.backgroundPosition = '0% -40px';
}

function aboutUnhovered() {
    var obj = document.getElementById("aboutusdiv");
    var obj2 = document.getElementById("aboutusiframe");
    var obj3 = document.getElementById("aboutspan");
    var obj4 = document.getElementById("abouturl");

    obj.style.display = 'none';
    obj2.style.display = 'none';
    obj3.style.backgroundPosition = '100% 0px';
    obj4.style.backgroundPosition = '0% 0px';
}

// Pop under script

function loadpopunder(url) 
{
    try 
    {
        var win2;
       win2 = window.open("http://www.car-supermarkets.com/popunder.aspx?url=" + url, "", "height=600,width=800,resizable=1");
       // win2 = window.open("http://localhost:50282/popunder.aspx?url=" + url, "", "height=600,width=800,resizable=1");
        win2.blur();
        window.focus();
    }
    catch (e) 
    {
    }
}

// Collapse panel toggle script

function SetCookie(cookieName, cookieValue, nDays) {
    var today = new Date();
    var expire = new Date();
    if (nDays == null || nDays == 0) nDays = 1;
    expire.setTime(today.getTime() + 3600000 * 24 * nDays);
    document.cookie = cookieName + "=" + escape(cookieValue)
                 + ";expires=" + expire.toGMTString();
}

function showNav(anchorID) 
{
    var aNav = document.getElementById(anchorID);

    switch(anchorID){
        case 'linkFeaturedCS':
            if (document.getElementById("featuredCSpanel").style.display == 'none') {            
                aNav.className = "left-nav-active";
                document.getElementById("linkOtherCS").className = "";
                document.getElementById("linkManufacturers").className = "";
                document.getElementById("linkRecentLinks").className = "";
                SetCookie('acopendivids', "", -1);
                SetCookie('acgroupswithpersist', "", -1);
                SetCookie('acopendivids', 'featuredCSpanel');
                SetCookie('acgroupswithpersist', 'csLeft');
            }
            else 
            {
                aNav.className = "";
            }
        break;
        case 'linkOtherCS':
            if (document.getElementById("otherCSpanel").style.display == 'none') {
                aNav.className = "left-nav-active";
                document.getElementById("linkFeaturedCS").className = "";
                document.getElementById("linkManufacturers").className = "";
                document.getElementById("linkRecentLinks").className = "";
                SetCookie('acopendivids', "", -1);
                SetCookie('acgroupswithpersist', "", -1);
                SetCookie('acopendivids', 'otherCSpanel');
                SetCookie('acgroupswithpersist', 'csLeft');
            }
            else 
            {
                aNav.className = "";
            }
        break;
        case 'linkManufacturers':
            if (document.getElementById("manufacturersPanel").style.display == 'none') {
                aNav.className = "left-nav-active";
                document.getElementById("linkFeaturedCS").className = "";
                document.getElementById("linkOtherCS").className = "";
                document.getElementById("linkRecentLinks").className = "";
                SetCookie('acopendivids', "", -1);
                SetCookie('acgroupswithpersist', "", -1);
                SetCookie('acopendivids', 'manufacturersPanel');
                SetCookie('acgroupswithpersist', 'csLeft');
            }
            else 
            {
                aNav.className = "";
            }
        break;
        case 'linkRecentLinks':
            if (document.getElementById("recentLinksPanel").style.display == 'none') {
                aNav.className = "left-nav-active";
                document.getElementById("linkFeaturedCS").className = "";
                document.getElementById("linkOtherCS").className = "";
                document.getElementById("linkManufacturers").className = "";
                SetCookie('acopendivids', "", -1);
                SetCookie('acgroupswithpersist', "", -1);
                SetCookie('acopendivids', 'recentLinksPanel');
                SetCookie('acgroupswithpersist', 'csLeft');
            }
            else 
            {
                aNav.className = "";
            }
        break;
    }
}
function initPanels() {

        var link1 = document.getElementById("linkFeaturedCS");
        var link2 = document.getElementById("linkOtherCS");
        var link3 = document.getElementById("linkManufacturers");
        var link4 = document.getElementById("linkRecentLinks");

        var panel1 = document.getElementById("featuredCSpanel");
        var panel2 = document.getElementById("otherCSpanel");
        var panel3 = document.getElementById("manufacturersPanel");
        var panel4 = document.getElementById("recentLinksPanel");

switch (document.cookie)
{
    case 'acopendivids=featuredCSpanel; acgroupswithpersist=csLeft':
        link1.className = 'left-nav-active';
//        SetCookie('acopendivids', 'featuredCSpanel');
//        SetCookie('acgroupswithpersist', 'csLeft');
        break;
        case 'acopendivids=otherCSpanel; acgroupswithpersist=csLeft':
            link2.className = 'left-nav-active';
//            SetCookie('acopendivids', 'otherCSpanel');
//            SetCookie('acgroupswithpersist', 'csLeft');
            break;       
        case 'acopendivids=manufacturersPanel; acgroupswithpersist=csLeft':
            link3.className = 'left-nav-active';
//            SetCookie('acopendivids', 'manufacturersPanel');
//            SetCookie('acgroupswithpersist', 'csLeft');
            break;
        case 'acopendivids=recentLinksPanel; acgroupswithpersist=csLeft':
            link4.className = 'left-nav-active';
//            SetCookie('acopendivids', 'recentLinksPanel');
//            SetCookie('acgroupswithpersist', 'csLeft');
            break;
        case 'nada':
            link1.className = 'left-nav-active';
            SetCookie('acopendivids', 'featuredCSpanel');
            SetCookie('acgroupswithpersist', 'csLeft');
            break;
        case '':
            link1.className = 'left-nav-active';
            SetCookie('acopendivids', 'featuredCSpanel');
            SetCookie('acgroupswithpersist', 'csLeft');
            break; 
//        default:
//            link1.className = 'left-nav-active';
//            SetCookie('acopendivids', 'featuredCSpanel');
//            SetCookie('acgroupswithpersist', 'csLeft');
//            break; 
        }
     }

     // slow image fix

     function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { if (oldonload) { oldonload(); } func(); } } }
