$(document).ready(function() { 
    $(".sweet_modal").click(function(){
        $("#captcha_info").show();
        return false
    });

    $("#close_business").click(function(){
        $("#captcha_info").hide();
        return false
    });

    $("#next_button").click(function(){
        $(".notification_area").hide();
        return false
    });
    
    // activate the modal overlay
    
    //$('#modal').jqm({ ajax: '@href',
    //                 trigger: 'a.modal_trigger',
    //                 target: '#remote_content' 
    //);
    
    // remove the last border from the global nav
    $("#global_nav li:last a").css("border","none");
    
    // replace the no flash button with a text link
    
    var noflashCopy = $("#noflash_link input[@type='submit']").val()
    $("#noflash_copy").append(noflashCopy);
    $("#noflash_copy").click(function(){
        $("#noflash_link").submit();  
    });
    $("#noflash_copy").css({cursor: "pointer",
                            textDecoration: "underline"});
    $("#noflash_link").hide();
                      
    // generate popups for global nav items
                      
    $("a[rel=popup], area[rel=popup]").click(function(){
           popupWindow = window.open(this.href,this.title,'menu=no,toolbar=no,width=750,height=488,scrollbars=1,resizable=0,directories=no,location=no,screenX=0,screenY=0,top=48,left=48');
           popupWindow.focus()
           return false;
    })
    
    $("a[rel=winpop]").click(function(){
        popupWindow = window.open(this.href,this.title,'menu=no,toolbar=no,width=500,height=500,scrollbars=1,resizable=0,directories=no,location=no,screenX=0,screenY=0,top=48,left=48');
        popupWindow.focus()
        return false;
    })
   
    $("a[rel=winners]").click(function(){
           popupWindow = window.open(this.href,this.title,'menu=no,toolbar=no,width=888,height=664,scrollbars=no,resizable=no,menubar=no,directories=no,location=no,status=no,screenX=0,screenY=0,top=48,left=48');
           popupWindow.focus()
           return false;
    })
   
   $("a[rel=map]").click(function(){
          popupWindow = window.open(this.href,this.title,'menu=no,toolbar=no,width=840,height=562,scrollbars=0,resizable=0,directories=no,location=no,screenX=0,screenY=0,top=48,left=48');
           popupWindow.focus()
           return false;
    })

    $("a[rel=external], area[rel=external]").click(function(){
           popupWindow = window.open(this.href,this.title,'toolbar=yes,status=yes,location=yes,menubar=yes,directories=yes,resizable=yes,scrollbars=yes');
           popupWindow.focus()
           return false;
    })
    
    // submit user's flash version with the FAQ form
    
    var flash = deconcept.SWFObjectUtil.getPlayerVersion();
    $("input#flash").val(flash.major + '.' + flash.minor + '.' + flash.rev);
    
    // Popup window close button
    
    $("#popup_close_button").css("cursor","pointer");
    
    $("#popup_close_button").click(function() {
        window.close();
    });
    
    // Un-comment for prechecked Opt-ins
    
    /*
        if (!$("div").hasClass("error")) {
            $("input[@name=primary_opt_in]").attr("checked", "checked");
        }
    */
    
});   

function openWindow(link) {
  window.open(link, '_blank', 'width=800,height=600,toolbar=yes,status=yes,location=yes,menubar=yes,directories=yes,resizable=yes,scrollbars=yes');
}
    
function winners(link) {
    window.open(link, '_blank', 'menu=no,toolbar=no,width=849,height=533,scrollbars=no,resizable=no,menubar=no,directories=no,location=no,status=no,screenX=0,screenY=0,top=48,left=48');
}

function popupRestaurantLocator(link) {
    window.open(link, 'restaurant_locator', 'width=567,height=320,toolbar=0,directories=0,location=1,status=1,resizable=1,menubar=0');
}

//URI decode querystring
function decodeURI(s) {
    return decodeURIComponent(s.replace(/\+/g,  " "));
}

//parse querystring into object
function qs(s) {
    out = {}
    kvs = s.split("&");
    for (i=0; i < kvs.length; i++) {
        kv = kvs[i].split("=");
        out[kv[0]] = kv[1];
    }
    return out;
}

//called by receiver to get the data from the restaurant_locator popup back
//into the opener (the registration page)
function handleResponse(querystring) {
    querystring = qs(decodeURI(querystring));
    restaurant_id = querystring['restnums'] || '0';
    restaurant_address = querystring['restaddr'] || 'N/A';
    $("#restaurant_id").val(restaurant_id);
    $("#restaurant_address").val(restaurant_address);
}

