function CatAdDetails(link_id,extra_params)
{
    var d = "index.php?page=out&id="+link_id;
    if (window.FFHome) {
        d = window.FFHome + d;
    }
    if (arguments.length > 1) {
        if (extra_params != '') {
            d += '&' + extra_params
        }
    }
    window.location.href = d;
}

function catOutSetZipKeyHandler(e)
{
       var kC  = (window.event) ?    // MSIE or Firefox?
                  event.keyCode : e.keyCode; 
       var Esc = (window.event) ?    
                 27 : e.DOM_VK_ESCAPE // MSIE : Firefox
       if (kC == Esc) {
          catOutSetZipClose()
       }
}

function catAdTab(tabName, tab, ad_id)
{
    var i_param = 'i=ad-catalog-' + tabName;

    var url  = '/dboffice/index.php'
    var pars = 'page=js&link_id=' + ad_id + '&' + i_param;

    if (window.CatAdActiveItem) {        
        CatAdCache[window.CatAdActiveItem.id] =
            jQuery('#catalog-ad-content').html();
        jQuery(window.CatAdActiveItem).removeClass('active');                
    }

    window.CatAdActiveItem = tab;
    jQuery(tab).addClass('active');

    if (CatAdCache[window.CatAdActiveItem.id]) {        
        jQuery('#catalog-ad-content').html(CatAdCache[window.CatAdActiveItem.id]);
    } else {
        jQuery('#catalog-ad-content').html('<div>Please wait...</div>');
        url = url + '?' + pars;        
        jQuery.get(url, function(response) {            
            jQuery('#catalog-ad-content').html(response);
        });         
    }
}

function catOutSetZipConfirm()
{
    var txt = document.getElementById('form-catsetzip-text');
    trimElement(txt);
    var zip = txt.value;

    if (!zip.match(/^\d{5}$/)) {

        alert('Please provide a valid zip');
        txt.select();

    } else {
        // remove replace s_zip with the new value:
        var u = window.location.href;
        u = u.replace(/&s_zip=\d+/, '');
        u = u.replace(/&hw_zip=[^&]+/, '');
        u = u.replace(/&hw_zip_r=[^&]+/, '');
        u = u.replace(/&f_city(_ex)?=[^&]+/, '');
        u = u.replace(/&f_state(_ex)?=[^&]+/, '');
        u = u.replace(/&f_region(_ex)?=[^&]+/, '');
    
        if (zip != '')
            u = u + '&s_zip=' + zip;
    
        catOutSetZipClose();
        window.location.href = u;
    }
    return false;
}

function catOutSetZipClose()
{
    var elt = document.getElementById('catadsetzipbox');
    elt.style.display = 'none';
}

function catOutSetZip(currentZip)
{
    var label = (currentZip == '') ? 'Enter a Zip Code' : 'Change Zip Code';
    var elt = document.getElementById('catadsetzipbox');
    if (elt.innerHTML == '') {
    	
    	var style = elt.style;
    	style.display = 'none';
    	style.zIndex = 20;
    	//style.backgroundColor = '#d4d69c';
    	style.padding = '3px';
    	style.border = '2px solid black';
    	
        var html = '<form id="form-catsetzip" ' +
                   '      onsubmit="return catOutSetZipConfirm()" ' +
                   ' >' + label + ': ' + 
                   '<input type="text" size="6" id="form-catsetzip-text" ' + 
                   '       value="' + currentZip +
                   '"/>' +
                   ' <input type="button" ' +
                   '        onclick="catOutSetZipConfirm()" ' +
                   '        value=" OK " />' +
                   ' <input type="button" ' + 
                   '        onclick="catOutSetZipClose()" ' +
                   '        value=" Cancel " />' +
                   '</form>';
        elt.innerHTML = html;
    }
    elt.style.display = 'block';
    var txt = document.getElementById('form-catsetzip-text');
    if (txt) {
        txt.focus();
        if (txt.value != '') {
            txt.select();
        }
        txt.onkeypress = catOutSetZipKeyHandler;
    }
}

