$(document).ready(function() {

    // open popup
    $("a.info-deals").click(function() {
        $("div.popup").hide();
        $("." + $(this).attr('rel')).show();
        $('body').addClass('popup-open');
    })

    // closing popup
    $("a.popup-close").click(function() {
        $(this).parents("div.popup").hide();
        $('body').removeClass('popup-open');
        return false;
    })

    // expand all state
    $("ul.expand-collpse>li.expand a").click(function() {
        $("ul.the-list>li>div.state").show().addClass("active").prev().addClass("expanded").children("a.view-location").text("Hide locations");
        return false;
    })

    // collapse all state
    $("ul.expand-collpse>li.collapse a").click(function() {
        $("ul.the-list>li>div.state").hide().removeClass("active").prev().removeClass("expanded").children("a.view-location").text("View locations");
        return false;
    })

    // show hide states for the location page (using the view / hide links)
    $("ul.the-list>li>div.location-heading>a.view-location").click(function() {
        if ($(this).parent().hasClass("expanded")) {
            $(this).text("View locations").parent().removeClass("expanded").next().hide();
        } else {
            $(this).text("Hide locations").parent().addClass("expanded").next().show();
        }
        return false;
    })

    // show hide states for the location page (using the heading)
    $("ul.the-list>li>div.location-heading>h3").click(function() {
        if ($(this).parent().hasClass("expanded")) {
            $(this).next('a').text("View locations").parent().removeClass("expanded").next('div').hide();
        } else {
            $(this).next('a').text("Hide locations").parent().addClass("expanded").next('div').show();
        }
        return false;
    })

    // show the current sectionf or the form on the homepage
    $("div.form-search>fieldset>div.search-expand>a.search-expand-add").click(function() {
        if ($(this).parent().hasClass("expanded")) {
            $(this).text("Hide").siblings('.search-toggle').removeClass("search-toggle-collapse").addClass("search-toggle-expand").parent().removeClass("expanded").next('div').hide();
        } else {
            $(this).text("Add").siblings('.search-toggle').removeClass("search-toggle-expand").addClass("search-toggle-collapse").parent().addClass("expanded").next('div').show();
        }
        return false;
    })

    // show hide states for the form on the homepage
    $("div.form-search>fieldset>div.search-expand>a.search-toggle").click(function() {
        if ($(this).parent().hasClass("expanded")) {
            $(this).removeClass("search-toggle-collapse").addClass("search-toggle-expand").parent().removeClass("expanded").next('div').hide().siblings('.search-expand-add').show();
        } else {
            $(this).removeClass("search-toggle-expand").addClass("search-toggle-collapse").parent().addClass("expanded").next('div').show().siblings('.search-expand-add').hide();
        }
        return false;
    })

});



/* added, vb. */
function bookmark() {
    //var title = "Oodles.com: Home"
    var title = document.title;

    var url = "index.html"

    if (window.sidebar) window.sidebar.addPanel(title, url, "");

    else if (window.opera && window.print) {
        var mbm = document.createElement('a');
        mbm.setAttribute('rel', 'sidebar');
        mbm.setAttribute('href', url);
        mbm.setAttribute('title', title);
        mbm.click();
    }

    else if (document.all) window.external.AddFavorite(url, title);
}

//This function open a new window on the centre of the screen
var win = null;
function NewWindow(mypage, myname, w, h, scroll) {
    LeftPosition = (screen.width) ? (screen.width - w) / 2 : 0;
    TopPosition = (screen.height) ? (screen.height - h) / 2 : 0;
    settings = 'height=' + h + ',width=' + w + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=' + scroll + ',resizable'
    win = window.open(mypage, myname, settings)
}


//vb. 28-aug-2009: expand-shrink page based on iFrame height -->
function SetOwnerHeight(nFrameHeight) {
    var oParent = document.getElementById('divContent');
    var oFrame = document.getElementById('iSearchBox');
    if (oFrame && oParent) {
        if (oParent.offsetHeight <= nFrameHeight) {
            oFrame.style.height = nFrameHeight + 'px';
        }
        else {
            oFrame.style.height = oParent.offsetHeight + 'px';
        }
    }
}		






/*----- following added by sohail -------*/


function ExpandDiscountCodes() {

    $("div.form-search>fieldset>div.search-expand>a.search-expand-add").text("Add").siblings('.search-toggle').removeClass("search-toggle-expand").addClass("search-toggle-collapse").parent().addClass("expanded").next('div').show();
    return false;

}
