var onload_overlay_type = '';
var onload_jsfunction = function(){};
var showSpecialSignupOverlayOnLoad = false;
var isLoggedIn = false;
var user_fullname = "";
var rooturl = "";
var secureurl = "";
var cityurl = "";
var return_s = "";
var return_id = "";
var edition = "";
var force_nonmobile_site = "";

var countdown_timers = 0;

function adjustShadows() {
    var content_height = $('#content_container').height();
    $('#shadow_edge_left').height(content_height);
    $('#shadow_edge_right').height(content_height);
}

function fullScreen() {
    var window_height = getWindowHeight();
    var content_height = $('#content_container').height();
    if (content_height < window_height) {
        $('#content_container').css('height',window_height);
        $('#footer_container').css('position','absolute');
        adjustShadows();
        adjustOverlays();
    }
}

function flexibleScreen() {
    $('#content_container').css('height',"auto");
    $('#footer_container').css('position',"relative");
    adjustShadows();
    adjustOverlays();

    fullScreen();
}

function adjustOverlays() {

  //adjust for iOS and Android
  if($('.shopping_cart_touchscroll_content').length && (BrowserDetect.OS == 'iPad' || BrowserDetect.OS == 'iPhone/iPod' || BrowserDetect.OS == 'Android')) {
    $('.shopping_cart_container').height($('#checkout_form').height() + 20);
  }

  var selector = "";
  if($('#overlay_signup_content_outer').length) {
    selector = "#overlay_signup_content_container";
    centerFixElement(selector);
  }

  if($('#overlay_content_outer').length) {
    selector = "#overlay_content_container";
    centerFixElement(selector);
  }

  if($('#content_container').length) {
    if ($(window).height() > $('#content_container').height()) $('#overlay').css('height',$(window).height());
    else $('#overlay').css('height',$('#content_container').height());
  }

}

function centerFixElement(selector){
  if(selector) {
    var center_x = Math.ceil(($(window).width() - $(selector).width()) / 2);
    var center_y = Math.ceil(($(window).height() - $(selector).height()) / 2);

    if(center_x < 0) center_x = 0;
    if(center_y < 0) center_y = 0;

    if(BrowserDetect.OS == 'iPad' || BrowserDetect.OS == 'iPhone/iPod' || BrowserDetect.OS == 'Android') {
      $(selector).css('position',"absolute");
    } else if(($(window).height() - $(selector).height()) > 50 && ($(window).width() - $(selector).width()) > 50) {
      $(selector).css('position',"fixed");
    } else {
      $(selector).css('position',"absolute");
    }

    $(selector).css('left',center_x);
    $(selector).css('top',center_y);
  }
}

function turnOnOverlay() {
    $('#overlay').css('visibility',"visible");
    $('#overlay_content_outer').css('visibility',"visible");
    adjustOverlays();

    disableAdContainer();
}

function turnOnSignupOverlay() {
    adjustOverlays();
    $('#overlay').css('visibility',"visible");
    $('#overlay_signup_content_outer').css('visibility',"visible");

    disableAdContainer();
}

function turnOffOverlay() {
    $('#overlay').css('visibility',"hidden");
    $('#overlay_content_outer').css('visibility',"hidden");
    $('#overlay_signup_content_outer').css('visibility',"hidden");
    $('#overlay_signup_content').html('');

    enableAdContainer();

}

function turnOffStandardOverlay() {
    $('#overlay_content_outer').css('visibility',"hidden");

    enableAdContainer();

}


function disableAdContainer() {
  if($('#ad_container_inner').length) {
    $('#ad_container_inner').css('overflow',"hidden");
    $('#ad_container_inner').css('height',0);
    $('#ad_container_inner').css('visibility',"hidden");
  }
}

function enableAdContainer() {
  if($('#ad_container_inner').length) {
    $('#ad_container_inner').css('overflow',"visible");
    $('#ad_container_inner').css('height','auto');
    $('#ad_container_inner').css('visibility',"visible");
  }
}


function turnOffOverlayTimed() {
    var default_delay_time = 3000;
    var timer = setTimeout(function(){turnOffOverlay();},default_delay_time);
}

function turnOffStandardOverlayTimed() {
    var default_delay_time = 3000;
    var timer = setTimeout(function(){turnOffStandardOverlay();},default_delay_time);
}


function updateSignupInputs() {
    var input_ids = new Array('name','email','zip');
    for (var i=0; i < input_ids.length; i++) {
        blurInput(document.getElementById(input_ids[i]),22);
    }
}

function extendSignupForm() {

  $('#signup_lower_link').html("<a href=\"javascript:closeSignupForm();\"></a>");
  $('#registration_status').html("");
  $('#signup_extended').animate(
    { height: 280 },
    500,
    'swing',
    function() {
      $('#signup_extended').css('visibility',"visible");
      $('#subscribe-button').css('height',7);
      adjustShadows();
      adjustOverlays();
    }
  );

}

function extendLargeSignupForm() {

  $('#registration_status').html("");
  $('#signup_extended').animate(
    { height: 260 },
    500,
    'swing',
    function() {
      $('#signup_extended').css('visibility',"visible");
      $('#subscribe-button').css('height',12);
      adjustShadows();
      adjustOverlays();
    }
  );

}

function closeSignupForm() {
    $('#signup_lower_link').html("<a href=\"terms-and-conditions.html\" target=\"_new\">Terms & Conditions</a> / <a href=\"privacy-policy.html\" target=\"_new\">Privacy Policy</a>");
    $('#registration_status').html("");

    $('#signup_extended').animate(
      { height: 0 },
      500,
      'swing',
      function() {
        $('#signup_extended').css('visibility',"hidden");
        $('#subscribe-button').css('height',0);
        adjustShadows();
        adjustOverlays();
      }
    );
}

function extendLeftSignupForm() {
  $('#registration_status').html("");
  $('#signup_extended').animate(
    { height: 285 },
    500,
    'swing',
    function() {
      $('#signup_extended').css('visibility',"visible");
      $('#large_signup_close_button').css('visibility',"visible");
      $('#subscribe-button').css('height',7);
      adjustShadows();
      adjustOverlays();
    }
  );
}

function closeLeftSignupForm() {
  $('#large_signup_close_button').css('visibility',"hidden");

  $('#signup_extended').animate(
    { height: 0 },
    500,
    'swing',
    function() {
      $('#signup_extended').css('visibility',"hidden");
      $('#subscribe-button').css('height',0);
      adjustShadows();
      adjustOverlays();
    }
  );
}



function focusInput(element,row_height) {
    if(!element) return false;
    var black_position = "0px";
    var gray_position = ("-" + row_height + "px");
    var white_position = ("-" + (row_height * 2) + "px");
    if (element.value != "") element.style.backgroundPosition = ("0px " + white_position);
    else element.style.backgroundPosition = ("0px " + gray_position);
}

function blurInput(element,row_height) {
    if(!element) return false;
    var black_position = "0px";
    var gray_position = ("-" + row_height + "px");
    var white_position = ("-" + (row_height * 2) + "px");
    if (element.value != "") element.style.backgroundPosition = ("0px " + white_position);
    else element.style.backgroundPosition = ("0px " + black_position);
}

function blankInput(event,element,row_height) {
    var black_position = "0px";
    var gray_position = ("-" + row_height + "px");
    var white_position = ("-" + (row_height * 2) + "px");
    var keynum;
    if(window.event) { // IE
        keynum = event.keyCode;
    } else if(event.which) { // Netscape/Firefox/Opera
        keynum = event.which;
    }

    if (element.value.length <= 1) {
        if (keynum == 8) element.style.backgroundPosition = ("0px " + gray_position);
        else element.style.backgroundPosition = ("0px " + white_position);
    } else if (element.value != "") element.style.backgroundPosition = ("0px " + white_position);
    else element.style.backgroundPosition = ("0px " + gray_position);
}


function extendSendInviteForm() {
    $('#invite_friends_status').html("");

    $('#invite_extended').animate(
      { height: 100 },
      500,
      'swing',
      function() {
        adjustShadows();
        adjustOverlays();
      }
    );

    $('#invite_friends_to').animate(
      { height: 58 },
      500,
      'swing',
      function() { }
    );

}

function collapseSendInviteForm() {
  $('#invite_extended').animate(
    { height: 0 },
    500,
    'swing',
    function() {
      adjustShadows();
      adjustOverlays();
    }
  );

  $('#invite_friends_to').animate(
    { height: 14 },
    500,
    'swing',
    function() { }
  );

}

function goToMyBlackboard() {
  if (isLoggedIn) {
      top.location = (rooturl + "my-blackboard");
  } else {
      var message = "";
      showLogin('my-blackboard','','',message);
  }
}

function showSignUpLogin(s,id,psa,message,signup_message) {
    if (s == '') s = return_s;
    if (id == '') id = return_id;

    var la_edition_checked = "";
    var ny_edition_checked = "";
    var sf_edition_checked = "";
    var chi_edition_checked = "";
    var market_edition_checked = "";
    var login_header_html = "<h2 class=\"blue_overlay_header_signin\">Sign In</h2>";
    if(psa == 'get_special' || psa == 'get_market_deal' || psa == 'get_popup_deal' || psa == 'deal_options_form') {
      login_header_html = "<h2 style=\"border-bottom:1px solid #969696; text-align:center;\"><img src=\"" + rooturl + "img/overlay_blue.header.one-click.gif\" border=\"0\" width=\"271\" height=\"43\"></h2>";
      if(signup_message == '') {
        signup_message = 'If this is your first special, please create a password for your account.';
      }
    }
    var signup_header_html = "";
    if(signup_message == '') {
      signup_header_html = "<h2 class=\"blue_overlay_header_subscribe\">Subscribe</h2>";
    }

    //var edition = "MARKET"; //default to market checked

    if (edition == 'ALL') {
        la_edition_checked = " CHECKED";
        ny_edition_checked = " CHECKED";
        sf_edition_checked = " CHECKED";
        chi_edition_checked = " CHECKED";
        market_edition_checked = " CHECKED";
    } else if(edition == 'LA') la_edition_checked = " CHECKED";
      else if(edition == 'NY') ny_edition_checked = " CHECKED";
      else if(edition == 'SF') sf_edition_checked = " CHECKED";
      else if(edition == 'CHI') chi_edition_checked = " CHECKED";
      else if(edition == 'MARKET') market_edition_checked = " CHECKED";

    var force_nonmobile_site_html = "";
    if(force_nonmobile_site) {
      force_nonmobile_site_html = "<input type=\"hidden\" name=\"fullsite\" value=\"1\" />";
    }

    //if (psa == 'get-special') header_text_img = "<img src=\"" + rooturl + "img/overlay400.header_sign-up-text.png\" border=\"0\" width=\"343\" height=\"54\">";

    $('#overlay_content').html("<form id=\"login\" action=\"" + secureurl + "\" class=\"standard_modal blue_overlay\" method=\"post\" onsubmit=\"return false;\" style=\"\">\r<img src=\"" + rooturl + "img/overlay.close.png\" width=\"10\" height=\"10\" border=\"0\" id=\"close-overlay-button\" onclick=\"turnOffOverlay();\" onmouseover=\"hoverCursor(this);\" onmouseout=\"normalCursor(this);\">\r<div class=\"overlay_form_padding_container\">\r" + login_header_html + "\r<div class=\"textrow\" style=\"text-align:center; padding:24px 0px 15px 0px;\">" + message + "</div>\r<div class=\"inputrow\"><input type=\"text\" name=\"email\" id=\"login_email\" class=\"modal_email\" onfocus=\"focusInput(this,22);\" onblur=\"blurInput(this,22);\" onkeypress=\"blankInput(event,this,22);\" value=\"\"></div>\r<div class=\"inputrow\"><input type=\"password\" name=\"password\" id=\"login_password\" class=\"modal_password\" onfocus=\"focusInput(this,22);\" onblur=\"blurInput(this,22);\" onkeypress=\"checkFormSubmitEnter(event,'login'); blankInput(event,this,22);\"></div>\r<div class=\"buttonrow\" style=\"padding-top:0px;\"><a class=\"signin_big\" onmouseover=\"hoverButton(this,20);\" onmouseout=\"normalButton(this,20);\" onclick=\"doLogin();\" style=\"float:right;\">Sign In</a></div>\r<input type=\"hidden\" name=\"a\" value=\"login\">\r<input type=\"hidden\" name=\"s\" value=\"" + s + "\">\r<input type=\"hidden\" name=\"id\" value=\"" + id + "\">\r<input type=\"hidden\" name=\"psa\" value=\"" + psa + "\">\r<input type=\"hidden\" name=\"return_s\" value=\"" + return_s + "\">\r<input type=\"hidden\" name=\"return_id\" value=\"" + return_id + "\">\r</div>\r<div class=\"overlay_form_padding_container\">\r" + force_nonmobile_site_html + "</form>\r<form id=\"finish_registration_overlay\" action=\"" + secureurl + "\" class=\"\" method=\"post\" onsubmit=\"return false;\" style=\"border-top:0px; padding-bottom:38px;\">\r<div class=\"textrow\" style=\"border-top:1px solid #969696; text-align:center; padding:24px 0px 15px 0px;\">" + signup_header_html + signup_message + "</div>\r<div class=\"inputrow\"><input type=\"text\" name=\"name\" id=\"name_overlay\" class=\"modal_name\" onfocus=\"focusInput(this,22);\" onblur=\"blurInput(this,22);\" onkeypress=\"blankInput(event,this,22);\"></div>\r<div class=\"inputrow\"><input type=\"text\" name=\"email\" id=\"email_overlay\" class=\"modal_email\" onfocus=\"focusInput(this,22);\" onblur=\"blurInput(this,22);\" onkeypress=\"blankInput(event,this,22);\" value=\"\"></div>\r<div class=\"inputrow\"><input type=\"password\" name=\"password\" id=\"password_overlay\" class=\"modal_password\" onfocus=\"focusInput(this,22);\" onblur=\"blurInput(this,22);\" onkeypress=\"blankInput(event,this,22);\"></div>\r<div class=\"inputrow\"><input type=\"password\" name=\"password_confirm\" id=\"confirm_password_overlay\" class=\"modal_confirm_password\" onfocus=\"focusInput(this,22);\" onblur=\"blurInput(this,22);\" onkeypress=\"blankInput(event,this,22);\"></div>\r<div class=\"inputrow\" style=\"\"><input type=\"text\" name=\"zip\" id=\"zip_overlay\" class=\"modal_zip\" onfocus=\"focusInput(this,22);\" onblur=\"blurInput(this,22);\" onkeypress=\"blankInput(event,this,22);\" value=\"\"> <div style=\"display:inline-block; padding-left:5px;\"><input type=\"checkbox\" name=\"over_twenty_one\" id=\"over_twenty_one_checkbox_overlay\" class=\"checkbox\" value=\"1\" /> I'm over 21</div></div>\r<h3 class=\"your-editions\">YOUR EDITIONS</h3>\r<div class=\"editionrow\"><div class=\"edition_cb\"><input type=\"checkbox\" name=\"la_subscription\" id=\"la_subscription_overlay\" class=\"checkbox\" value=\"1\" " + la_edition_checked + " /></div><div class=\"edition_text\" style=\"width:82px\">Los Angeles</div><div class=\"edition_cb\"><input type=\"checkbox\" name=\"ny_subscription\" id=\"ny_subscription_overlay\" class=\"checkbox\" value=\"1\" " + ny_edition_checked + " /></div><div class=\"edition_text\" style=\"width:75px\">New York</div><div class=\"edition_cb\"><input type=\"checkbox\" name=\"sf_subscription\" id=\"sf_subscription_overlay\" class=\"checkbox\" value=\"1\" " + sf_edition_checked + " /></div><div class=\"edition_text\" style=\"width:90px\">San Francisco</div></div>\r<div class=\"inputrow\"><div class=\"edition_cb\"><input type=\"checkbox\" name=\"chi_subscription\" id=\"chi_subscription_overlay\" class=\"checkbox\" value=\"1\" " + chi_edition_checked + " /></div><div class=\"edition_text\" style=\"width:66px;\">Chicago</div><div class=\"edition_cb\"><input type=\"checkbox\" name=\"market_subscription\" id=\"market_subscription_overlay\" class=\"checkbox\" value=\"1\" " + market_edition_checked + " /></div><div class=\"edition_text\" style=\"width:200px\">Market <i>(culinary products)</i></div></div>\r<div class=\"row\" style=\"padding-bottom:10px;\">\r<p class=\"small-overlay-text\" style=\"font-size:10px; font-family:Arial;\">By subscribing, I agree to the <a href=\"terms_and_conditions\" target=\"_new\">Terms &amp; Conditions</a> and <a href=\"privacy_policy\" target=\"_new\">Privacy Policy</a>.</p>\r<input type=\"hidden\" name=\"terms\" id=\"terms_input_overlay\" value=\"1\">\r</div>\r<div class=\"buttonrow\" style=\"border-bottom:1px solid #969696; padding-top:10px;\"><a class=\"submit_big\" onmouseover=\"hoverButton(this,20);\" onmouseout=\"normalButton(this,20);\" onclick=\" fullregister('finish_registration_overlay','blue');\" style=\"float:right;\">Submit</a><span id=\"registration_status_overlay\"></span></div>\r<input type=\"hidden\" name=\"a\" value=\"fullsignup\">\r<input type=\"hidden\" name=\"s\" value=\"" + s + "\">\r<input type=\"hidden\" name=\"id\" value=\"" + id + "\">\r<input type=\"hidden\" name=\"psa\" value=\"" + psa + "\">\r<input type=\"hidden\" name=\"return_s\" value=\"" + return_s + "\">\r<input type=\"hidden\" name=\"return_id\" value=\"" + return_id + "\">\r</div>\r<input type=\"hidden\" name=\"rc\" class=\"signup_rc\" value=\"\" />\r" + force_nonmobile_site_html + "</div></form>\r");

    turnOnOverlay();
}

function showLogin(s,id,psa,message) {
    if (s == '') s = return_s;
    if (id == '') id = return_id;
    var message_html = "<div class=\"textrow\" style=\"padding:20px 0px 0px 0px;\"></div>\r";
    if(message != '') {
      message_html = "<div class=\"textrow\" style=\"padding:23px 0px 18px 0px;\">" + message + "</div>\r";
    }

    var force_nonmobile_site_html = "";
    if(force_nonmobile_site) {
      force_nonmobile_site_html = "<input type=\"hidden\" name=\"fullsite\" value=\"1\" />";
    }

    $('#overlay_content').html("<form action=\"" + secureurl + "\" id=\"login\" class=\"standard_modal blue_overlay\" method=\"post\" onsubmit=\"return false;\" style=\"border-bottom:0px;\">\r<img src=\"" + rooturl + "img/overlay.close.png\" width=\"10\" height=\"10\" border=\"0\" id=\"close-overlay-button\" onclick=\"turnOffOverlay();\" onmouseover=\"hoverCursor(this);\" onmouseout=\"normalCursor(this);\">\r<div class=\"overlay_form_padding_container\">\r<h2 class=\"blue_overlay_header_signin_full\">Sign In</h2>" + message_html + "<div class=\"inputrow\"><input type=\"text\" name=\"email\" id=\"login_email\" class=\"modal_email\" onfocus=\"focusInput(this,22);\" onblur=\"blurInput(this,22);\" onkeypress=\"blankInput(event,this,22);\"></div>\r<div class=\"inputrow\"><input type=\"password\" name=\"password\" id=\"login_password\" class=\"modal_password\" onfocus=\"focusInput(this,22);\" onblur=\"blurInput(this,22);\" onkeypress=\"checkFormSubmitEnter(event,'login'); blankInput(event,this,22);\"></div>\r<div class=\"row paddingTop10\">\r<div class=\"forgot_passcode_container\"><a href=\"javascript:showForgotPassword();\">Forgot password?</a> </div><div class=\"checkbox-keep-logged-in-overlay\" onclick=\"updateKeepLoggedInCheckbox(this);\" id=\"keep_logged_in_checkbox_overlay\"><input type=\"hidden\" name=\"keep_logged_in\" id=\"keep_logged_in_value_overlay\" value=\"1\" />Keep me logged in\r</div></div>\r<div class=\"buttonrow\"><a class=\"signin_big\" onmouseover=\"hoverButton(this,20);\" onmouseout=\"normalButton(this,20);\" onclick=\"doLogin();\" style=\"float:right;\">Sign In</a></div>\r<input type=\"hidden\" name=\"a\" value=\"login\">\r<input type=\"hidden\" name=\"s\" value=\"" + s + "\">\r<input type=\"hidden\" name=\"id\" value=\"" + id + "\">\r<input type=\"hidden\" name=\"psa\" value=\"" + psa + "\">\r<input type=\"hidden\" name=\"return_s\" value=\"" + return_s + "\">\r<input type=\"hidden\" name=\"return_id\" value=\"" + return_id + "\">\r<input type=\"hidden\" name=\"cid\" value=\"" + city_id + "\">\r" + force_nonmobile_site_html + "</div></form>\r<form id=\"registration_overlay\" class=\"standard_modal blue_overlay\" method=\"post\" onsubmit=\"return false;\" style=\"border-top:0px;\">\r<div class=\"overlay_form_padding_container\">\r<div style=\"border-top:1px #969696 solid; text-align:center; padding:20px 0px 40px 0px;\"><a href=\"#\" onclick=\"showSignup2('" + s + "','" + id + "','" + psa + "','" + message + "'); return false;\"><img src=\"" + rooturl + "img/overlay_blue.text.not-a-member.gif\" border=\"0\" /></a>\r</div></div></form>\r");
    turnOnOverlay();
}

function showSignup2(s,id,psa,message) {
    if (s == '') s = return_s;
    if (id == '') id = return_id;

    var la_edition_checked = "";
    var ny_edition_checked = "";
    var sf_edition_checked = "";
    var chi_edition_checked = "";
    var market_edition_checked = "";

    //var edition = "MARKET"; //default to market checked

    if (edition == 'ALL') {
        la_edition_checked = " CHECKED";
        ny_edition_checked = " CHECKED";
        sf_edition_checked = " CHECKED";
        chi_edition_checked = " CHECKED";
        market_edition_checked = " CHECKED";
    } else if(edition == 'LA') la_edition_checked = " CHECKED";
      else if(edition == 'NY') ny_edition_checked = " CHECKED";
      else if(edition == 'SF') sf_edition_checked = " CHECKED";
      else if(edition == 'CHI') chi_edition_checked = " CHECKED";
      else if(edition == 'MARKET') market_edition_checked = " CHECKED";

    var force_nonmobile_site_html = "";
    if(force_nonmobile_site) {
      force_nonmobile_site_html = "<input type=\"hidden\" name=\"fullsite\" value=\"1\" />";
    }

    $('#overlay_content').html("<form id=\"registration_overlay\" action=\"" + secureurl + "\" class=\"standard_modal blue_overlay\" method=\"post\" onsubmit=\"return false;\" style=\"border-top:0px;\">\r<img src=\"" + rooturl + "img/overlay.close.png\" width=\"10\" height=\"10\" border=\"0\" id=\"close-overlay-button\" onclick=\"turnOffOverlay();\" onmouseover=\"hoverCursor(this);\" onmouseout=\"normalCursor(this);\">\r<div class=\"overlay_form_padding_container\">\r<h2 class=\"blue_overlay_header_subscribe_full\">Subscribe</h2><div class=\"textrow\" style=\"text-align:center; padding:14px 0px 15px 0px;\">" + message + "</div>\r<div class=\"inputrow\"><input type=\"text\" name=\"name\" id=\"name_overlay\" class=\"modal_name\" onfocus=\"focusInput(this,22);\" onblur=\"blurInput(this,22);\" onkeypress=\"blankInput(event,this,22);\"></div>\r<div class=\"inputrow\"><input type=\"text\" name=\"email\" id=\"email_overlay\" class=\"modal_email\" onfocus=\"focusInput(this,22);\" onblur=\"blurInput(this,22);\" onkeypress=\"blankInput(event,this,22);\" value=\"\"></div>\r<div class=\"inputrow\"><input type=\"password\" name=\"password\" id=\"password_overlay\" class=\"modal_password\" onfocus=\"focusInput(this,22);\" onblur=\"blurInput(this,22);\" onkeypress=\"blankInput(event,this,22);\"></div>\r<div class=\"inputrow\"><input type=\"password\" name=\"password_confirm\" id=\"confirm_password_overlay\" class=\"modal_confirm_password\" onfocus=\"focusInput(this,22);\" onblur=\"blurInput(this,22);\" onkeypress=\"blankInput(event,this,22);\"></div>\r<div class=\"inputrow\" style=\"\"><input type=\"text\" name=\"zip\" id=\"zip_overlay\" class=\"modal_zip\" onfocus=\"focusInput(this,22);\" onblur=\"blurInput(this,22);\" onkeypress=\"blankInput(event,this,22);\" value=\"\"> <div style=\"display:inline-block; padding-left:5px;\"><input type=\"checkbox\" name=\"over_twenty_one\" id=\"over_twenty_one_checkbox_overlay\" class=\"checkbox\" value=\"1\" /> I'm over 21</div></div>\r<h3 class=\"your-editions\">YOUR EDITIONS</h3>\r<div class=\"editionrow\"><div class=\"edition_cb\"><input type=\"checkbox\" name=\"la_subscription\" id=\"la_subscription_overlay\" class=\"checkbox\" value=\"1\" " + la_edition_checked + "  /></div><div class=\"edition_text\" style=\"width:82px\">Los Angeles</div><div class=\"edition_cb\"><input type=\"checkbox\" name=\"ny_subscription\" id=\"ny_subscription_overlay\" class=\"checkbox\" value=\"1\" " + ny_edition_checked + "  /></div><div class=\"edition_text\" style=\"width:75px\">New York</div><div class=\"edition_cb\"><input type=\"checkbox\" name=\"sf_subscription\" id=\"sf_subscription_overlay\" class=\"checkbox\" value=\"1\" " + sf_edition_checked + "  /></div><div class=\"edition_text\" style=\"width:90px\">San Francisco</div></div>\r<div class=\"inputrow\"><div class=\"edition_cb\"><input type=\"checkbox\" name=\"chi_subscription\" id=\"chi_subscription_overlay\" class=\"checkbox\" value=\"1\" " + chi_edition_checked + "  /></div><div class=\"edition_text\" style=\"width:66px;\">Chicago</div><div class=\"edition_cb\"><input type=\"checkbox\" name=\"market_subscription\" id=\"market_subscription_overlay\" class=\"checkbox\" value=\"1\" " + market_edition_checked + " /></div><div class=\"edition_text\" style=\"width:200px\">Market <i>(culinary products)</i></div></div>\r<div class=\"row\" style=\"padding-bottom:10px;\">\r<p class=\"small-overlay-text\" style=\"font-size:10px; font-family:Arial;\">By subscribing, I agree to the <a href=\"terms_and_conditions\" target=\"_new\">Terms &amp; Conditions</a> and <a href=\"privacy_policy\" target=\"_new\">Privacy Policy</a>.</p>\r<input type=\"hidden\" name=\"terms\" id=\"terms_input_overlay\" value=\"1\">\r</div>\r<div class=\"buttonrow\" style=\"padding-top:10px;\"><a class=\"submit_big\" onmouseover=\"hoverButton(this,20);\" onmouseout=\"normalButton(this,20);\" onclick=\"fullregister('registration_overlay','blue');\" style=\"float:right;\">Submit</a><span id=\"registration_status_overlay\"></span></div>\r<input type=\"hidden\" name=\"a\" value=\"fullsignup\">\r<input type=\"hidden\" name=\"s\" value=\"" + s + "\">\r<input type=\"hidden\" name=\"id\" value=\"" + id + "\">\r<input type=\"hidden\" name=\"psa\" value=\"" + psa + "\">\r<input type=\"hidden\" name=\"return_s\" value=\"" + return_s + "\">\r<input type=\"hidden\" name=\"return_id\" value=\"" + return_id + "\"><input type=\"hidden\" name=\"rc\" class=\"signup_rc\" value=\"\" />\r" + force_nonmobile_site_html + "</div></form>\r");
    turnOnOverlay();
}

function completeAccountGetForm() {
    var email = $('complete_account_email').value;

    var data_valid = true;
    if (!(email)) {
        data_valid = false;
        alert("All fields are required.");
        return false;
    }

    if (data_valid) {
        $('#complete_account_status').html("<div class=\"cs_loader_gray\">one moment...</div>");
        submitFormAJAX("complete_account_form",(rooturl + 'ajax.php'),"overlay_content",function() {});
    }
}

function updateKeepLoggedInCheckbox(element) {
  //var element_id = element.getAttribute('id');
  var checkbox_previous_value = $(element).children('input').val();
  if(checkbox_previous_value > 0) {
    $(element).css('backgroundPosition','0px 0px');
    $(element).children('input').val(0);
  } else {
    $(element).css('backgroundPosition','0px -19px');
    $(element).children('input').val(1);
  }
}



function showForgotPassword() {
    $('#overlay_content').html("<form id=\"forgot_password\" class=\"standard_modal\" method=\"post\" action=\"index.php\">\r<img src=\"" + rooturl + "img/overlay.close.png\" width=\"10\" height=\"10\" border=\"0\" id=\"close-overlay-button\" onclick=\"turnOffOverlay();\" onmouseover=\"hoverCursor(this);\" onmouseout=\"normalCursor(this);\">\r<h1 class=\"login_header\"><img src=\"" + rooturl + "img/overlay400.header_forgot-password.png\" border=\"0\" width=\"236\" height=\"15\"></h1>\r<div class=\"inputrow\">Please submit your email address and receive instructions on how to reset your password.</div>\r<div class=\"inputrow\"><input type=\"text\" name=\"email\" id=\"password_email\" class=\"modal_email\" onfocus=\"focusInput(this,33);\" onblur=\"blurInput(this,33);\" onkeypress=\"blankInput(event,this,33);\"></div>\r<div class=\"buttonrow\"><div id=\"enter\" onmouseover=\"hoverButton(this,20);\" onmouseout=\"normalButton(this,20);\" onclick=\"requestPasswordReset();\">&nbsp;</div>\r<input type=\"hidden\" name=\"a\" value=\"send_reset_password_email\"></div>\r</form>\r");
    turnOnOverlay();
}

function requestPasswordReset() {
    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if(pattern.test($('#password_email').val())){
        document.getElementById('forgot_password').submit();
    } else {
        alert("A valid email address is required.");
    }
}

function resetPassword() {
    if (trim($('#password_new').val()) == "" || trim($('#password_new_confirm').val()) == "") {
        alert("You must fill out both password fields.");
    } else if ($('#password_new').val() != $('#password_new_confirm').val()){
        alert("The passwords do not match.");
    } else {
        document.getElementById('forgot_password').submit();
    }
}

function doLogin() {
    if($('#login_email').val() == "" || $('#login_password').val() == "") {
        alert("Please enter your email and password.");
        return false;
    } else document.getElementById('login').submit();
}

function doLogout() {
    document.getElementById('logout').submit();
}

function showDeleteAccount() {
    if(isLoggedIn) {
      turnOffOverlay();
      $('#overlay_content').html("<form id=\"unsubscribe_update_account_form\" class=\"standard_modal\" method=\"post\" action=\"index.php\">\r<img src=\"" + rooturl + "img/overlay.close.png\" width=\"10\" height=\"10\" border=\"0\" id=\"close-overlay-button\" onclick=\"turnOffOverlay();\" onmouseover=\"hoverCursor(this);\" onmouseout=\"normalCursor(this);\">\r<h1 class=\"login_header\"><img src=\"" + rooturl + "img/overlay.header_unsubscribe.png\" border=\"0\" width=\"128\" height=\"11\"></h1>\r<div class=\"textrow\">You're currently subscribed to the below checked editions. Uncheck the editions you no longer want to receive and click \"update\" to change your subscription settings.</div>\r<div id=\"update_subscriptions_data\"></div>\r<div class=\"buttonrow\"><div id=\"update\" style=\"position:static;\" onmouseover=\"hoverButton(this,8);\" onmouseout=\"normalButton(this,8);\" onclick=\"unsubscribeUpdateLoggedInAccount();\">&nbsp;</div><div class=\"button_cancel\" onmouseover=\"hoverButton(this,8);\" onmouseout=\"normalButton(this,8);\" onclick=\"turnOffOverlay();\">&nbsp;</div>\r<input type=\"hidden\" name=\"a\" value=\"\" id=\"unsubscribe_update_action\"></div>\r<div id=\"unsubscribe_update_account_status\" style=\"font-size:12px; padding-bottom:20px;\"></div></form>\r");
      $('#update_subscriptions_data').html("<div class=\"cs_loader_gray\">retrieving editions...</div>");
      loadExternalData((rooturl + 'ajax.php?a=get_subscriptions'),'update_subscriptions_data',function(){});
      turnOnOverlay();
    } else {
        showLogin('','','','You must be signed in to unsubscribe.');
    }
}

function showDeleteAccountExitPoll() {
    if(isLoggedIn) {
        $('#overlay_content').html("<form id=\"delete_account_form\" class=\"standard_modal\" method=\"post\" action=\"index.php\">\r<img src=\"" + rooturl + "img/overlay.close.png\" width=\"10\" height=\"10\" border=\"0\" id=\"close-overlay-button\" onclick=\"turnOffOverlay();\" onmouseover=\"hoverCursor(this);\" onmouseout=\"normalCursor(this);\">\r<h1 class=\"login_header\"><img src=\"" + rooturl + "img/overlay.header_unsubscribe.png\" border=\"0\" width=\"128\" height=\"11\"></h1>\r<div class=\"textrow\">We are sad to see you go! By unsubscribing, you are deleting your account. If you have a moment, please tell us why you're unsubscribing so we can improve BlackboardEats.</div>\r<div class=\"textrow\"><input type=\"radio\" name=\"unsubscribe_reason\" class=\"overlay-radio\" />I get too many emails from BlackboardEats</div>\r<div class=\"textrow\"><input type=\"radio\" name=\"unsubscribe_reason\" class=\"overlay-radio\" value=\"Not interested in the specials\" />Not interested in the specials</div>\r<div class=\"textrow\"><input type=\"radio\" name=\"unsubscribe_reason\" class=\"overlay-radio\" value=\"Already signed-up for too many emails\" />Already signed-up for too many emails</div>\r<div class=\"textrow\"><input type=\"radio\" name=\"unsubscribe_reason\" class=\"overlay-radio\" value=\"I experienced technical problems.\" />I experienced technical problems.</div>\r<div class=\"textrow\"><input type=\"radio\" name=\"unsubscribe_reason\" class=\"overlay-radio\" value=\"other\" />Other (Please write below):</div>\r<div class=\"textrow\"><textarea name=\"unsubscribe_reason_other\" class=\"unsubscribe-reason-other\"></textarea></div>\r<div class=\"buttonrow\"><div class=\"button_unsubscribe\" onmouseover=\"hoverButton(this,8);\" onmouseout=\"normalButton(this,8);\" onclick=\"deleteAccount();\">&nbsp;</div><div class=\"button_cancel\" onmouseover=\"hoverButton(this,8);\" onmouseout=\"normalButton(this,8);\" onclick=\"turnOffOverlay();\">&nbsp;</div>\r<input type=\"hidden\" name=\"a\" value=\"delete_user_account\"></div>\r<div id=\"delete_account_status\"></div></form>\r");
        turnOnOverlay();
    } else {
        showLogin('','','','You must be signed in to unsubscribe.');
    }
}

function deleteAccount() {
    $("#delete_account_status").html("<div class=\"cs_loader_gray\">deleting account...</div>");
    document.getElementById('delete_account_form').submit();
}

function submitOverlayForm(overlay_form_id_prefix) {
    $("#" + overlay_form_id_prefix + "_status").html("<div class=\"cs_loader_gray\">submitting...</div>");
    document.getElementById(overlay_form_id_prefix + "_form").submit();
}

function doReSubscribe() {
  $("#exit_poll_status").html("<div class=\"cs_loader_gray\">retrieving subscriptions...</div>");
  $('#exit_poll_action').val('auto_resubscribe_form');
  document.getElementById('exit_poll_form').submit();
}

function unsubscribeUpdateAccount() {
    $("#unsubscribe_update_account_status").html("<div class=\"cs_loader_gray\">updating account...</div>");
    $('#unsubscribe_update_action').val('auto_unsubscribe_update');
    document.getElementById('unsubscribe_update_account_form').submit();
}

function unsubscribeUpdateLoggedInAccount() {
    $("#unsubscribe_update_account_status").html("<div class=\"cs_loader_gray\">updating account...</div>");
    var do_update = 0;
    if($('#unsubscribe_update_account_form input#reminder_subscription_overlay:checked').length) { //reminder subscription checked
      if($('#unsubscribe_update_account_form input:checked').length > 1) {
        do_update = 1;
      }
    } else if($('#unsubscribe_update_account_form input:checked').length) {
      do_update = 1;
    }

    if(do_update) {
      $('#unsubscribe_update_action').val('update_subscriptions');
      submitFormAJAX("unsubscribe_update_account_form",(rooturl + 'ajax.php'),"unsubscribe_update_account_status",function() {turnOffOverlayTimed(); });
    } else { //unsubscribe
      $('#unsubscribe_update_action').val('do_unsubscribe');
      submitFormAJAX("unsubscribe_update_account_form",(rooturl + 'ajax.php'),"overlay_content",function() { });
    }
}


function getSpecial(special_id) {
    if (special_id < 1) return;
    if (isLoggedIn) {
        top.location = (rooturl + "index.php?psa=get_special&id=" + special_id);
    } else {
        var message = "To get this special, you must be logged in.<br />Please, sign in.";
        var signup_message = "If this is your first special, please create an account.";
        showSignUpLogin('special',special_id,'get_special',message, signup_message);
    }
}

function showForwardSpecial(id) {
    $('#overlay_content').html("<form id=\"" + id + "_send_to_friends\" class=\"signup_box\">\r<img src=\"" + rooturl + "img/overlay.close.png\" width=\"10\" height=\"10\" border=\"0\" id=\"close-overlay-button\" onclick=\"turnOffOverlay();\" onmouseover=\"hoverCursor(this);\" onmouseout=\"normalCursor(this);\">\r<img src=\"" + rooturl + "img/global.signup_bg_top.jpg\" border=\"0\" alt=\"\" />\r\t<img src=\"" + rooturl + "img/global.send_intro.jpg\" border=\"0\" alt=\"Send To Friends Enter friends' email addresses separated by commas.\" />\r\t<div class=\"row\">\r\t\t<textarea name=\"to\" id=\"" + id + "_send_to_friends_to\"  class=\"send_to_friends_to\" style=\"height:58px\" onfocus=\"focusInput(this,90);\" onblur=\"blurInput(this,90);\" onkeypress=\"blankInput(event,this,90);\"></textarea>\r\t\t</div>\r\t\t<div class=\"row\">\r\t\t\t<input type=\"text\" name=\"from\" id=\"" + id + "_send_to_friends_from\" class=\"text_long send_to_friends_from\" onfocus=\"focusInput(this,22);\" onblur=\"blurInput(this,22);\" onkeypress=\"blankInput(event,this,22);\" value=\"" + user_fullname + "\"/>\r\t\t</div>\r\t<div class=\"row\">\r\t\t\t<textarea name=\"note\" id=\"" + id + "_send_to_friends_note\" class=\"send_to_friends_note\" onfocus=\"focusInput(this,90);\" onblur=\"blurInput(this,90);\" onkeypress=\"blankInput(event,this,90);\"></textarea>\r\t\t\t<input type=\"hidden\" name=\"id\" id=\"" + id + "_send_to_friends_id\" value=\"" + id + "\"/>\r\t\t\t<input type=\"hidden\" name=\"a\" id=\"" + id + "_send_to_friends_action\" value=\"send_special_to_friend\" />\r\t\t</div>\r\t<div class=\"row\">\r\t\t<div id=\"" + id + "_send-to-a-friend-button\" class=\"send-to-a-friend-button\" onmouseover=\"hoverButton(this,7)\" onmouseout=\"normalButton(this)\" onclick=\"forwardSpecial('" + id + "_');\">&nbsp;</div>\r\t\t<span id=\"" + id + "_send_to_friends_status\"></span>\r\t</div>\r<div class=\"row\"></div>\r<img src=\"" + rooturl + "img/global.signup_bg_bottom.jpg\" border=\"0\" alt=\"\" /></form>");

    turnOnOverlay();
    $('#' + id + "_send_to_friends_note").focus();
    $('#' + id + "_send_to_friends_from").focus();
    $('#' + id + "_send_to_friends_to").focus();
}

function forwardSpecial(input_prefix) {
    var data_is_valid = true;
    var send_to = $('#' + input_prefix + "send_to_friends_to").val();
    var send_note = $('#' + input_prefix + "send_to_friends_note").val();
    var send_from = $('#' + input_prefix + "send_to_friends_from").val();
    var send_to_array = new Array();
    send_to_array = send_to.split(",");

    if (trim(send_to) == "") {
        data_is_valid = false;
        alert("You must use a valid email address.");
        return false;
    } else {
        for (var i=0; i < send_to_array.length; i++) {
            send_to_array[i] = trim(send_to_array[i]);
            if (!checkEmail(send_to_array[i])) {
                data_is_valid = false;
                alert(send_to_array[i] + " is not a valid email.");
                return false;
            }
        }
    }

    if (send_from == "from: " || trim(send_from) == "") {
        data_is_valid = false;
        alert("You must specify who the special is from.");
        return false;
    }

    if (data_is_valid) {
        $('#' + input_prefix + "send_to_friends_status").html("<div class=\"cs_loader\">sending...</div>");
        submitFormAJAX((input_prefix + "send_to_friends"),(rooturl + 'ajax.php'),(input_prefix + "send_to_friends_status"),function() {clearForwardSpecial(input_prefix); turnOffOverlayTimed();});
        //$(input_prefix + "send_to_friends").submit();
    }
}


function sendInvite(prefix) {
    var data_is_valid = true;
    var send_to = $('#' + prefix + "invite_friends_to").val();
    var send_note = $('#' + prefix + "invite_friends_note").val();
    var send_from = $('#' + prefix + "invite_friends_from").val();
    var send_to_array = new Array();
    send_to_array = send_to.split(",");

    if (trim(send_to) == "") {
        data_is_valid = false;
        alert("You must use a valid email address.");
        return false;
    } else {
        for (var i=0; i < send_to_array.length; i++) {
            send_to_array[i] = trim(send_to_array[i]);
            if (!checkEmail(send_to_array[i])) {
                data_is_valid = false;
                alert(send_to_array[i] + " is not a valid email.");
                return false;
            }
        }
    }

    if (send_from == "from: " || trim(send_from) == "") {
        data_is_valid = false;
        alert("You must specify who the special is from.");
        return false;
    }

    if (data_is_valid) {
        $('#' + prefix + "invite_friends_status").html("<div class=\"cs_loader\">sending...</div>");
        submitFormAJAX(prefix + "invite_friends",(rooturl + 'ajax.php'),(prefix + "invite_friends_status"),function() {clearInviteFriends(prefix); turnOffOverlayTimed(); });
    }
}

function clearInviteFriends(prefix) {
    var to_element = document.getElementById(prefix + "invite_friends_to");
    $('#' + prefix + "invite_friends_to").val("");
    blurInput(to_element,90);

    var from_element = document.getElementById(prefix + "invite_friends_from");
    $('#' + prefix + "invite_friends_from").val("");
    blurInput(from_element,22);

    var note_element = document.getElementById(prefix + "invite_friends_note");
    $('#' + prefix + "invite_friends_note").val("");
    blurInput(note_element,90);

    if (prefix == "") collapseSendInviteForm();
}




function clearForwardSpecial(input_prefix) {
    var to_element = document.getElementById(input_prefix + "send_to_friends_to");
    $('#' + input_prefix + "send_to_friends_to").val("");
    blurInput(to_element,90);
}


function showForwardMarketDeal(id) {
    $('#overlay_content').html("<form id=\"" + id + "_send_to_friends\" class=\"signup_box\">\r<img src=\"" + rooturl + "img/overlay.close.png\" width=\"10\" height=\"10\" border=\"0\" id=\"close-overlay-button\" onclick=\"turnOffOverlay();\" onmouseover=\"hoverCursor(this);\" onmouseout=\"normalCursor(this);\">\r<img src=\"" + rooturl + "img/global.signup_bg_top.jpg\" border=\"0\" alt=\"\" />\r\t<img src=\"" + rooturl + "img/global.send_intro.jpg\" border=\"0\" alt=\"Send To Friends Enter friends' email addresses separated by commas.\" />\r\t<div class=\"row\">\r\t\t<textarea name=\"to\" id=\"" + id + "_send_to_friends_to\"  class=\"send_to_friends_to\" style=\"height:58px\" onfocus=\"focusInput(this,90);\" onblur=\"blurInput(this,90);\" onkeypress=\"blankInput(event,this,90);\"></textarea>\r\t\t</div>\r\t\t<div class=\"row\">\r\t\t\t<input type=\"text\" name=\"from\" id=\"" + id + "_send_to_friends_from\" class=\"text_long send_to_friends_from\" onfocus=\"focusInput(this,22);\" onblur=\"blurInput(this,22);\" onkeypress=\"blankInput(event,this,22);\" value=\"" + user_fullname + "\"/>\r\t\t</div>\r\t<div class=\"row\">\r\t\t\t<textarea name=\"note\" id=\"" + id + "_send_to_friends_note\" class=\"send_to_friends_note\" onfocus=\"focusInput(this,90);\" onblur=\"blurInput(this,90);\" onkeypress=\"blankInput(event,this,90);\"></textarea>\r\t\t\t<input type=\"hidden\" name=\"id\" id=\"" + id + "_send_to_friends_id\" value=\"" + id + "\"/>\r\t\t\t<input type=\"hidden\" name=\"a\" id=\"" + id + "_send_to_friends_action\" value=\"send_market_deal_to_friend\" />\r\t\t</div>\r\t<div class=\"row\">\r\t\t<div id=\"" + id + "_send-to-a-friend-button\" class=\"send-to-a-friend-button\" onmouseover=\"hoverButton(this,7)\" onmouseout=\"normalButton(this)\" onclick=\"forwardSpecial('" + id + "_');\">&nbsp;</div>\r\t\t<span id=\"" + id + "_send_to_friends_status\"></span>\r\t</div>\r<div class=\"row\"></div>\r<img src=\"" + rooturl + "img/global.signup_bg_bottom.jpg\" border=\"0\" alt=\"\" /></form>");

    turnOnOverlay();
    $('#' + id + "_send_to_friends_note").focus();
    $('#' + id + "_send_to_friends_from").focus();
    $('#' + id + "_send_to_friends_to").focus();
}




function getMarketDeal(market_deal_id) {
    if (market_deal_id < 1) return;
    if (isLoggedIn) {
        top.location = (rooturl + "index.php?psa=get_market_deal&id=" + market_deal_id);
    } else {
        var message = "To get this special, you must be logged in.<br />Please, sign in.";
        var signup_message = "If this is your first special, please create an account.";
        showSignUpLogin('market_deal',market_deal_id,'get_market_deal',message,signup_message);
    }
}


function showForwardPopupDeal(id) {
    $('#overlay_content').html("<form id=\"" + id + "_send_to_friends\" class=\"signup_box\">\r<img src=\"" + rooturl + "img/overlay.close.png\" width=\"10\" height=\"10\" border=\"0\" id=\"close-overlay-button\" onclick=\"turnOffOverlay();\" onmouseover=\"hoverCursor(this);\" onmouseout=\"normalCursor(this);\">\r<img src=\"" + rooturl + "img/global.signup_bg_top.jpg\" border=\"0\" alt=\"\" />\r\t<img src=\"" + rooturl + "img/global.send_intro.jpg\" border=\"0\" alt=\"Send To Friends Enter friends' email addresses separated by commas.\" />\r\t<div class=\"row\">\r\t\t<textarea name=\"to\" id=\"" + id + "_send_to_friends_to\"  class=\"send_to_friends_to\" style=\"height:58px\" onfocus=\"focusInput(this,90);\" onblur=\"blurInput(this,90);\" onkeypress=\"blankInput(event,this,90);\"></textarea>\r\t\t</div>\r\t\t<div class=\"row\">\r\t\t\t<input type=\"text\" name=\"from\" id=\"" + id + "_send_to_friends_from\" class=\"text_long send_to_friends_from\" onfocus=\"focusInput(this,22);\" onblur=\"blurInput(this,22);\" onkeypress=\"blankInput(event,this,22);\" value=\"" + user_fullname + "\"/>\r\t\t</div>\r\t<div class=\"row\">\r\t\t\t<textarea name=\"note\" id=\"" + id + "_send_to_friends_note\" class=\"send_to_friends_note\" onfocus=\"focusInput(this,90);\" onblur=\"blurInput(this,90);\" onkeypress=\"blankInput(event,this,90);\"></textarea>\r\t\t\t<input type=\"hidden\" name=\"id\" id=\"" + id + "_send_to_friends_id\" value=\"" + id + "\"/>\r\t\t\t<input type=\"hidden\" name=\"a\" id=\"" + id + "_send_to_friends_action\" value=\"send_popup_deal_to_friend\" />\r\t\t</div>\r\t<div class=\"row\">\r\t\t<div id=\"" + id + "_send-to-a-friend-button\" class=\"send-to-a-friend-button\" onmouseover=\"hoverButton(this,7)\" onmouseout=\"normalButton(this)\" onclick=\"forwardSpecial('" + id + "_');\">&nbsp;</div>\r\t\t<span id=\"" + id + "_send_to_friends_status\"></span>\r\t</div>\r<div class=\"row\"></div>\r<img src=\"" + rooturl + "img/global.signup_bg_bottom.jpg\" border=\"0\" alt=\"\" /></form>");

    turnOnOverlay();
    $('#' + id + "_send_to_friends_note").focus();
    $('#' + id + "_send_to_friends_from").focus();
    $('#' + id + "_send_to_friends_to").focus();
}





function fbs_click(){
    u=location.href;
    t=document.title;
    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
    return false;
}

function showPrintableSpecial(id) {
    window.open(rooturl + 'index.php?s=special-print&id=' + id,'printable','toolbar=1,status=0,scrollbars=1,width=750,height=500');
    return false;
}

function showPrintableSpecialSignup(id) {
    window.open(rooturl + 'index.php?s=special-signup-print&id=' + id,'printable','toolbar=0,status=0,scrollbars=1,width=750,height=500');
    return false;
}


function showSendToPhone(id, passcode, deal_type) {
    $('#overlay_content').html("<form id=\"" + id + "_send_to_phone\" class=\"signup_box\">\r<img src=\"" + rooturl + "img/overlay.close.png\" width=\"10\" height=\"10\" border=\"0\" id=\"close-overlay-button\" onclick=\"turnOffOverlay();\" onmouseover=\"hoverCursor(this);\" onmouseout=\"normalCursor(this);\">\r<img src=\"" + rooturl + "img/global.signup_bg_top.jpg\" border=\"0\" alt=\"\" />\r\t<img src=\"" + rooturl + "img/global.send_to_phone_intro.jpg\" border=\"0\" alt=\"Send To Phone\" />\r\t<div id=\"send_to_phone_content\"></div>\r\t\t<input type=\"hidden\" name=\"id\" id=\"" + id + "_send_to_phone_id\" value=\"" + id + "\"/>\r\t\t\t<input type=\"hidden\" name=\"a\" id=\"" + id + "_send_to_phone_action\" value=\"send_special_to_phone\" />\r\t\t<input type=\"hidden\" name=\"passcode\" id=\"" + id + "_send_to_phone_passcode\" value=\"" + passcode + "\" />\r<input type=\"hidden\" name=\"deal_type\" id=\"deal_type\" value=\"" + deal_type + "\" />\r\t<div class=\"row\">\r\t\t<div id=\"" + id + "_send-to-phone-button\" class=\"send-to-a-friend-button\" onmouseover=\"hoverButton(this,7)\" onmouseout=\"normalButton(this)\" onclick=\"sendToPhone('" + id + "_',true);\">&nbsp;</div>\r\t\t<div style=\"padding-bottom:3px;\"><input type=\"checkbox\" name=\"save_phone_info\" value=\"1\" />&nbsp; save for later use</div><span id=\"" + id + "_send_to_phone_status\"></span>\r\t</div>\r<img src=\"" + rooturl + "img/global.signup_bg_bottom.jpg\" border=\"0\" alt=\"\" /></form>");
    loadExternalData(rooturl + 'ajax.php?a=show_special_to_phone&prefix=' + id,'send_to_phone_content',function(){});
    turnOnOverlay();
}

function showSendToPhoneOverOverlay(id, passcode, deal_type) {
    $('#overlay_content').html("<form id=\"" + id + "_send_to_phone\" class=\"signup_box\">\r<img src=\"" + rooturl + "img/overlay.close.png\" width=\"10\" height=\"10\" border=\"0\" id=\"close-overlay-button\" onclick=\"turnOffStandardOverlay();\" onmouseover=\"hoverCursor(this);\" onmouseout=\"normalCursor(this);\">\r<img src=\"" + rooturl + "img/global.signup_bg_top.jpg\" border=\"0\" alt=\"\" />\r\t<img src=\"" + rooturl + "img/global.send_to_phone_intro.jpg\" border=\"0\" alt=\"Send To Phone\" />\r\t<div id=\"send_to_phone_content\"></div>\t\t<input type=\"hidden\" name=\"id\" id=\"" + id + "_send_to_phone_id\" value=\"" + id + "\"/>\r\t\t\t<input type=\"hidden\" name=\"a\" id=\"" + id + "_send_to_phone_action\" value=\"send_special_to_phone\" />\r\t\t<input type=\"hidden\" name=\"passcode\" id=\"" + id + "_send_to_phone_passcode\" value=\"" + passcode + "\" />\r<input type=\"hidden\" name=\"deal_type\" id=\"deal_type\" value=\"" + deal_type + "\" />\r\t<div class=\"row\">\r\t\t<div id=\"" + id + "_send-to-phone-button\" class=\"send-to-a-friend-button\" onmouseover=\"hoverButton(this,7)\" onmouseout=\"normalButton(this)\" onclick=\"sendToPhone('" + id + "_',false);\">&nbsp;</div>\r\t\t<div style=\"padding-bottom:3px;\"><input type=\"checkbox\" name=\"save_phone_info\" value=\"1\" />&nbsp; save for later use</div><span id=\"" + id + "_send_to_phone_status\"></span>\r\t</div>\r<img src=\"" + rooturl + "img/global.signup_bg_bottom.jpg\" border=\"0\" alt=\"\" /></form>");
    loadExternalData(rooturl + 'ajax.php?a=show_special_to_phone&prefix=' + id,'send_to_phone_content',function(){});
    turnOnOverlay();
}

function sendToPhone(input_prefix, turn_off_all_overlays) {
    var data_is_valid = true;
    var cell_provider = $('#' + input_prefix + "cell_provider").val();
    var cell_number = $('#' + input_prefix + "send_to_phone_cell").val();

    if (trim(cell_provider) == "") {
        data_is_valid = false;
        alert("You must specify the cell phone carrier for the phone.");
        return false;
    }

    if (trim(cell_number) == "") {
        data_is_valid = false;
        alert("You must specify a cell phone number for the phone.");
        return false;
    }

    if (!checkPhone(cell_number)) {
        data_is_valid = false;
        alert("The number " + cell_number + " is formatted incorrectly. It must be 10 digits with no spaces or hyphens.");
    }

    if (data_is_valid) {
        $('#' + input_prefix + "send_to_phone_status").html("<div class=\"cs_loader\">sending...</div>");
        if (turn_off_all_overlays) submitFormAJAX((input_prefix + "send_to_phone"),(rooturl + 'ajax.php'),(input_prefix + "send_to_phone_status"),function() {clearSendToPhone(input_prefix); turnOffOverlayTimed();});
        else submitFormAJAX((input_prefix + "send_to_phone"),(rooturl + 'ajax.php'),(input_prefix + "send_to_phone_status"),function() {clearSendToPhone(input_prefix); turnOffStandardOverlayTimed();});
    }
}

function clearSendToPhone(input_prefix) {
  $('#' + input_prefix + "cell_provider").attr('selectedIndex', 0);
  var send_to_phone_cell = document.getElementById(input_prefix + "send_to_phone_cell");
  send_to_phone_cell.value = "";
  blurInput(send_to_phone_cell,22);
}

function doRestaurantLogin() {
    document.getElementById('restaurant_login').submit();
}

function getSpecialSignups(element) {
    if (element.selectedIndex > 0) {
        $("#special_signups").html("<div class=\"cs_loader_black\">loading data...</div>");
        fullScreen();
        var unparsed_string = element.options[element.selectedIndex].value;
        var parsed_values_array = unparsed_string.split(',');
        $('#signup_type').val(parsed_values_array[0]);
        $('#signup_id').val(parsed_values_array[1]);
        submitFormAJAX("restaurant_signups",(rooturl + 'ajax.php'),"special_signups",function() {flexibleScreen();});
    }
}

function getSpecialSignupsPaginated(element) {
    var page_number = element.options[element.selectedIndex].value;
    $('#page_number').val(page_number);
    getSpecialSignups(document.getElementById('special_select'));
}

function submitContactForm() {
    var email = $('#contact_email').val();
    var subject = $('#contact_subject').val();
    var message = $('#contact_message').val();

    var data_valid = true;
    if (!(email && subject && message)) {
        data_valid = false;
        alert("All fields are required.");
        return false;
    } else if (!checkEmail(email)) {
        data_valid = false;
        alert(email + " is not a valid email.");
        return false;
    }

    if (data_valid) {
        $('#contact_form_status').html("<div class=\"cs_loader_gray\">sending message...</div>");
        submitFormAJAX("contact_us_form",(rooturl + 'ajax.php'),"contact_form_status",function() {clearContactForm();});
    }
}

function clearContactForm() {
    $('#contact_email').val("");
    $('#contact_subject').val("");
    $('#contact_message').val("");

    $('#contact_message').focus();
    $('#contact_subject').focus();
    $('#contact_email').focus();
}

function submitAdvertisingContactForm() {
    var fname = $('#ad_contact_fname').val();
    var lname = $('#ad_contact_lname').val();
    var email = $('#ad_contact_email').val();
    var phone = $('#ad_contact_phone').val();
    var company = $('#ad_contact_company').val();
    var industry = $('#ad_contact_industry').val();
    var comments = $('#ad_contact_comments').val();

    var data_valid = true;
    if (!(fname && lname && email && phone && company && industry && comments)) {
        data_valid = false;
        alert("All fields are required.");
        return false;
    } else if (!checkEmail(email)) {
        data_valid = false;
        alert(email + " is not a valid email.");
        return false;
    }

    if (data_valid) {
        $('#advertising_contact_form_status').html("<div class=\"cs_loader_gray\">sending message...</div>");
        submitFormAJAX("advertising_contact_form",(rooturl + 'ajax.php'),"advertising_contact_form_status",function() {clearAdvertisingContactForm();});
    }
}

function clearAdvertisingContactForm() {
    $('#ad_contact_fname').val("");
    $('#ad_contact_lname').val("");
    $('#ad_contact_email').val("");
    $('#ad_contact_phone').val("");
    $('#ad_contact_company').val("");
    $('#ad_contact_industry').val("");
    $('#ad_contact_comments').val("");

    $('#ad_contact_lname').focus();
    $('#ad_contact_email').focus();
    $('#ad_contact_phone').focus();
    $('#ad_contact_company').focus();
    $('#ad_contact_industry').focus();
    $('#ad_contact_comments').focus();
    $('#ad_contact_fname').focus();
}


function showChangeEmail() {
    if(isLoggedIn) {
        $('#overlay_content').html("<form id=\"change_email_form\" class=\"standard_modal\" method=\"post\" onsubmit=\"return false;\">\r<img src=\"" + rooturl + "img/overlay.close.png\" width=\"10\" height=\"10\" border=\"0\" id=\"close-overlay-button\" onclick=\"turnOffOverlay();\" onmouseover=\"hoverCursor(this);\" onmouseout=\"normalCursor(this);\">\r<h1><img src=\"" + rooturl + "img/overlay400.header_change-email.png\" border=\"0\" width=\"303\" height=\"14\"></h1>\r<div class=\"inputrow\" style=\"padding-top:20px;\"><input type=\"text\" name=\"email\" id=\"modal_new_email\" class=\"modal_new_email\" onfocus=\"focusInput(this,33);\" onblur=\"blurInput(this,33);\" onkeypress=\"checkEnter(event,function(){changeEmail();}); blankInput(event,this,33);\"></div>\r<div class=\"buttonrow2\"><div id=\"enter\" onmouseover=\"hoverButton(this,20);\" onmouseout=\"normalButton(this,20);\" onclick=\"changeEmail();\">&nbsp;</div><span id=\"change_email_status\">&nbsp;</span></div>\r<input type=\"hidden\" name=\"a\" value=\"change_email\">\r<br class=\"clearboth\"></form>\r");
        turnOnOverlay();
    } else {
        showLogin('','','','You must be signed in to change your email address.');
    }
}

function changeEmail() {
    var email = $('#modal_new_email').val();

    var data_valid = true;
    if (!(email)) {
        data_valid = false;
        alert("A new email address is required.");
        return false;
    } else if (!checkEmail(email)) {
        data_valid = false;
        alert(email + " is not a valid email.");
        return false;
    }

    if (data_valid) {
        $('#change_email_status').html("<div class=\"cs_loader_gray\">changing email address...</div>");
        submitFormAJAX("change_email_form",(rooturl + 'ajax.php'),"change_email_status",function() {$('#modal_new_email').val(""); $('#modal_new_email').focus(); turnOffOverlayTimed();});
    }
}


function showChangePassword() {
    if(isLoggedIn) {
        $('#overlay_content').html("<form id=\"change_password_form\" class=\"standard_modal\" method=\"post\" onsubmit=\"return false;\">\r<img src=\"" + rooturl + "img/overlay.close.png\" width=\"10\" height=\"10\" border=\"0\" id=\"close-overlay-button\" onclick=\"turnOffOverlay();\" onmouseover=\"hoverCursor(this);\" onmouseout=\"normalCursor(this);\">\r<h1><img src=\"" + rooturl + "img/overlay.header_change-password.png\" border=\"0\" width=\"179\" height=\"11\"></h1>\r<div class=\"inputrow\"><input type=\"password\" name=\"password\" id=\"modal_password\" class=\"modal_new_password\" onfocus=\"focusInput(this,22);\" onblur=\"blurInput(this,22);\" onkeypress=\"blankInput(event,this,33);\"></div>\r<div class=\"inputrow\"><input type=\"password\" name=\"password_confirm\" id=\"modal_password_confirm\" class=\"modal_confirm_new_password\" onfocus=\"focusInput(this,33);\" onblur=\"blurInput(this,33);\" onkeypress=\"checkEnter(event,function(){changePassword();}); blankInput(event,this,33);\"></div>\r<div class=\"buttonrow\"><div id=\"enter\" onmouseover=\"hoverButton(this,20);\" onmouseout=\"normalButton(this,20);\" onclick=\"changePassword();\">&nbsp;</div><span id=\"change_password_status\"></span></div>\r<input type=\"hidden\" name=\"a\" value=\"change_password\">\r</form>\r");
        turnOnOverlay();
    } else {
        showLogin('','','','You must be signed in to change your password.');
    }
}

function changePassword() {
    var password = $('#modal_password').val();
    var password_confirm = $('#modal_password_confirm').val();

    var data_valid = true;
    if (!(password || password_confirm)) {
        data_valid = false;
        alert("All fields are required.");
        return false;
    } else if (password != password_confirm) {
        data_valid = false;
        alert("The passwords do not match.");
        return false;
    }

    if (data_valid) {
        $('#change_password_status').html("<div class=\"cs_loader_gray\">changing password...</div>");
        submitFormAJAX("change_password_form",(rooturl + 'ajax.php'),"change_password_status",function() {$('#modal_password').val(""); $('#modal_password_confirm').val(""); $('#modal_password_confirm').focus(); $('#modal_password').focus(); turnOffOverlayTimed(); });
    }
}

function showUpdateSubscriptions() {
    if(isLoggedIn) {
        turnOffOverlay();
        $('#overlay_content').html("<form id=\"update_subscriptions_form\" class=\"standard_modal\" method=\"post\" onsubmit=\"return false;\">\r<img src=\"" + rooturl + "img/overlay.close.png\" width=\"10\" height=\"10\" border=\"0\" id=\"close-overlay-button\" onclick=\"turnOffOverlay();\" onmouseover=\"hoverCursor(this);\" onmouseout=\"normalCursor(this);\">\r<h1><img src=\"" + rooturl + "img/overlay.header_your-subscriptions.png\" border=\"0\" width=\"199\" height=\"11\"></h1>\r<div id=\"update_subscriptions_data\"></div>\r<div class=\"buttonrow\"><div id=\"update\" onmouseover=\"hoverButton(this,8);\" onmouseout=\"normalButton(this,8);\" onclick=\"updateSubscriptions();\">&nbsp;</div><span id=\"update_subscriptions_status\"></span></div>\r<input type=\"hidden\" name=\"a\" value=\"update_subscriptions\">\r</form>\r");
        $('#update_subscriptions_data').html("<div class=\"cs_loader_gray\">retrieving editions...</div>");
        loadExternalData((rooturl + 'ajax.php?a=get_subscriptions'),'update_subscriptions_data',function(){});
        turnOnOverlay();
    } else {
        showLogin('','','','You must be signed in to change your subscriptions.');
    }
}

function updateSubscriptions() {
    var la_subscription_checked = $('#la_subscription_overlay').is(':checked');
    var ny_subscription_checked = $('#ny_subscription_overlay').is(':checked');
    var sf_subscription_checked = $('#sf_subscription_overlay').is(':checked');
    var chi_subscription_checked = $('#chi_subscription_overlay').is(':checked');
    var market_subscription_checked = $('#market_subscription_overlay').is(':checked');

    var data_valid = true;
    if (!la_subscription_checked && !ny_subscription_checked && !sf_subscription_checked && !chi_subscription_checked && !market_subscription_checked) {
        data_valid = false;
        alert("You must be subscribed to at least one edition.");
        return false;
    }

    if (data_valid) {
        $('#update_subscriptions_status').html("<div class=\"cs_loader_gray\">updating...</div>");
        submitFormAJAX("update_subscriptions_form",(rooturl + 'ajax.php'),"update_subscriptions_status",function() {turnOffOverlayTimed(); });
    }
}

function city_signup() {
    if (isLoggedIn) {
        showUpdateSubscriptions();
    } else {
        edition = "";
        showSignUpLogin('','','update-editions','','');
    }
}

function sf_invite() {
    $('#overlay_content').html("<form id=\"sf_invite_friends\" class=\"signup_box\">\r<img src=\"" + rooturl + "img/overlay.close.png\" width=\"10\" height=\"10\" border=\"0\" id=\"close-overlay-button\" onclick=\"turnOffOverlay();\" onmouseover=\"hoverCursor(this);\" onmouseout=\"normalCursor(this);\">\r<img src=\"" + rooturl + "img/global.signup_bg_top.jpg\" border=\"0\" alt=\"\" />\r\t<img src=\"" + rooturl + "img/global.invite_intro.jpg\" border=\"0\" alt=\"Invite Friends Enter friends' email addresses separated by commas.\" />\r\t<div class=\"row\">\r\t\t<textarea name=\"to\" id=\"sf_invite_friends_to\"  class=\"send_to_friends_to\" style=\"height:58px\" onfocus=\"focusInput(this,90);\" onblur=\"blurInput(this,90);\" onkeypress=\"blankInput(event,this,90);\"></textarea>\r\t\t</div>\r\t\t<div class=\"row\">\r\t\t\t<input type=\"text\" name=\"from\" id=\"sf_invite_friends_from\" class=\"text_long send_to_friends_from\" onfocus=\"focusInput(this,22);\" onblur=\"blurInput(this,22);\" onkeypress=\"blankInput(event,this,22);\" value=\"\"/>\r\t\t</div>\r\t<div class=\"row\">\r\t\t\t<textarea name=\"note\" id=\"sf_invite_friends_note\" class=\"send_to_friends_note\" onfocus=\"focusInput(this,90);\" onblur=\"blurInput(this,90);\" onkeypress=\"blankInput(event,this,90);\"></textarea>\r\t\t\t<input type=\"hidden\" name=\"city_id\" id=\"city_id\" value=\"3\"/>\r\t\t\t<input type=\"hidden\" name=\"a\" id=\"invite_friends_action\" value=\"send_invite_to_friend\" />\r\t\t</div>\r\t<div class=\"row\">\r\t\t<div id=\"sf_send-to-a-friend-button\" class=\"send-to-a-friend-button\" onmouseover=\"hoverButton(this,7)\" onmouseout=\"normalButton(this)\" onclick=\"sendInvite('sf_');\">&nbsp;</div>\r\t\t<span id=\"sf_invite_friends_status\"></span>\r\t</div>\r<div class=\"row\"></div>\r<img src=\"" + rooturl + "img/global.signup_bg_bottom.jpg\" border=\"0\" alt=\"\" /></form>");

    turnOnOverlay();
    $("#sf_send_to_friends_note").focus();
    $("#sf_send_to_friends_from").focus();
    $("#sf_send_to_friends_to").focus();
}

function market_invite() {
    $('#overlay_content').html("<form id=\"market_invite_friends\" class=\"signup_box\">\r<img src=\"" + rooturl + "img/overlay.close.png\" width=\"10\" height=\"10\" border=\"0\" id=\"close-overlay-button\" onclick=\"turnOffOverlay();\" onmouseover=\"hoverCursor(this);\" onmouseout=\"normalCursor(this);\">\r<img src=\"" + rooturl + "img/global.signup_bg_top.jpg\" border=\"0\" alt=\"\" />\r\t<img src=\"" + rooturl + "img/global.invite_intro.jpg\" border=\"0\" alt=\"Invite Friends Enter friends' email addresses separated by commas.\" />\r\t<div class=\"row\">\r\t\t<textarea name=\"to\" id=\"market_invite_friends_to\"  class=\"send_to_friends_to\" style=\"height:58px\" onfocus=\"focusInput(this,90);\" onblur=\"blurInput(this,90);\" onkeypress=\"blankInput(event,this,90);\"></textarea>\r\t\t</div>\r\t\t<div class=\"row\">\r\t\t\t<input type=\"text\" name=\"from\" id=\"market_invite_friends_from\" class=\"text_long send_to_friends_from\" onfocus=\"focusInput(this,22);\" onblur=\"blurInput(this,22);\" onkeypress=\"blankInput(event,this,22);\" value=\"\"/>\r\t\t</div>\r\t<div class=\"row\">\r\t\t\t<textarea name=\"note\" id=\"market_invite_friends_note\" class=\"send_to_friends_note\" onfocus=\"focusInput(this,90);\" onblur=\"blurInput(this,90);\" onkeypress=\"blankInput(event,this,90);\"></textarea>\r\t\t\t<input type=\"hidden\" name=\"city_id\" id=\"city_id\" value=\"4\"/>\r\t\t\t<input type=\"hidden\" name=\"a\" id=\"invite_friends_action\" value=\"send_invite_to_friend\" />\r\t\t</div>\r\t<div class=\"row\">\r\t\t<div id=\"market_send-to-a-friend-button\" class=\"send-to-a-friend-button\" onmouseover=\"hoverButton(this,7)\" onmouseout=\"normalButton(this)\" onclick=\"sendInvite('market_');\">&nbsp;</div>\r\t\t<span id=\"market_invite_friends_status\"></span>\r\t</div>\r<div class=\"row\"></div>\r<img src=\"" + rooturl + "img/global.signup_bg_bottom.jpg\" border=\"0\" alt=\"\" /></form>");

    turnOnOverlay();
    $("#market_invite_friends_note").focus();
    $("#market_invite_friends_from").focus();
    $("#market_invite_friends_to").focus();
}



function updateReminderSubscription() {
    if(isLoggedIn) {
        turnOffOverlay();
        $('#overlay_content').html("<form class=\"standard_modal\" method=\"post\" onsubmit=\"return false;\">\r<img src=\"" + rooturl + "img/overlay.close.png\" width=\"10\" height=\"10\" border=\"0\" id=\"close-overlay-button\" onclick=\"turnOffOverlay();\" onmouseover=\"hoverCursor(this);\" onmouseout=\"normalCursor(this);\">\r<h1><img src=\"" + rooturl + "img/overlay.header_reminder-emails.png\" border=\"0\" width=\"173\" height=\"11\"></h1>\r<div class=\"textrow\" id=\"reminder_subscription_message\"></div>\r&nbsp;<br /></form>\r");
        $('#reminder_subscription_message').html("<div class=\"cs_loader_gray\">updating profile...</div>");
        submitFormAJAX("reminder_subscription_form",(rooturl + 'ajax.php'),"reminder_subscription_message",function() {});
        turnOnOverlay();
    } else {
        showLogin('','','','You must be signed in to change your subscriptions.');
    }
}


/*landing*/
function addToFavorites(special_id,passcode_type) {
    if(isLoggedIn) {
        $('#favorites-content-' + special_id).html(" &nbsp; <span class=\"cs_loader_black_inline\" style=\"\">adding to favorites...</span>");
        $('#favorites_special_id').val(special_id);
        $('#add_to_favorites').val(1);
        $('#favorites_passcode_type').val(passcode_type);
        submitFormAJAX("favorites_form",(rooturl + 'ajax.php'),"favorites-content-" + special_id,function() {});
    } else {
        showLogin('','','','You must be signed in to add the special to your favorites.');
    }
}

function removeFromFavorites(special_id,passcode_type) {
    if(isLoggedIn) {
        $('#favorites-content-' + special_id).html(" &nbsp; <span class=\"cs_loader_black_inline\" style=\"\">removing from favorites...</span>");
        $('#favorites_special_id').val(special_id);
        $('#add_to_favorites').val(0);
        $('#favorites_passcode_type').val(passcode_type);
        submitFormAJAX("favorites_form",(rooturl + 'ajax.php'),"favorites-content-" + special_id,function() {});
    } else {
        showLogin('','','','You must be signed in to remove specials from your favorites.');
    }
}

function removeFromFavoritesAndRefresh(special_id,passcode_type) {
    if(isLoggedIn) {
        $('#favorites-content-' + special_id).html(" &nbsp; <span class=\"cs_loader_black_inline\" style=\"\">removing from favorites...</span>");
        $('#favorites_special_id').val(special_id);
        $('#add_to_favorites').val(0);
        $('#favorites_passcode_type').val(passcode_type);
        submitFormAJAX("favorites_form",(rooturl + 'ajax.php'),"favorites-content-" + special_id,function() {self.location = self.location; });
    } else {
        showLogin('','','','You must be signed in to remove specials from your favorites.');
    }
}


function organizeSpecials(special_id,move_to,passcode_type) {
    if(isLoggedIn) {
        $('#mb-mover-link-' + special_id).html(" &nbsp; <span class=\"cs_loader_black_inline\" style=\"\">updating...</span>");
        $('#target_special_id').val(special_id);
        $('#mb_move_to').val(move_to);
        $('#past_active_passcode_type').val(passcode_type);
        submitFormAJAX("past_active_form",(rooturl + 'ajax.php'),"mb-mover-link-" + special_id,function() {self.location = self.location; });
    } else {
        showLogin('','','','You must be signed in to organize specials on your blackboard.');
    }
}


function updateAccountInfo() {
    var la_subscription_checked = $('#la_subscription').is(':checked');
    var ny_subscription_checked = $('#ny_subscription').is(':checked');
    var sf_subscription_checked = $('#sf_subscription').is(':checked');
    var chi_subscription_checked = $('#chi_subscription').is(':checked');
    var market_subscription_checked = $('#market_subscription').is(':checked');

    var data_valid = true;
    if (!la_subscription_checked && !ny_subscription_checked && !sf_subscription_checked && !chi_subscription_checked && !market_subscription_checked) {
        data_valid = false;
        alert("You must be subscribed to at least one edition.");
        return false;
    }

    if($('password').value != $('confirm_password').value) {
        data_valid = false;
        alert("The passwords do not match.");
        return false;
    }

    if (data_valid) {
        $('#account_info_status').html(" &nbsp; <span class=\"cs_loader_black_inline\" style=\"\">updating account...</span>");
        submitFormAJAX("account_info_form",(rooturl + 'ajax.php'),"account_info_status",function() {});
    }
}


function submitUserReview() {
    if($('#user_review_note').val()) {
        document.getElementById('user_review').submit();
    } else {
        alert("You have attempted to submit a blank review.");
    }
}




//shopping cart
function showShoppingCartLoader() {
    $('#overlay_signup_content').html("<div class=\"shopping_cart_loader\">Loading Shopping Cart</div>");
}


function displayShoppingCart() {
    $('#shopping_cart_form_action').val('display_shopping_cart');

  if ("https:" == document.location.protocol) {
      showShoppingCartLoader();
      turnOnSignupOverlay();
      submitFormAJAX('shopping_cart_form',(secureurl + 'shopping_cart.php'),'overlay_signup_content',function(){adjustOverlays();startCountdownTimers();});
  } else {
    $('#shopping_cart_form').attr('action',secureurl);
    document.getElementById('shopping_cart_form').submit();
  }
}

function addItemToCart(item_id,item_type) {
    $('#new_item_id').val(item_id);
    $('#new_item_type').val(item_type);
    $('#shopping_cart_form_action').val('add_to_cart');

  if ("https:" == document.location.protocol) {
      showShoppingCartLoader();
      turnOnSignupOverlay();
      submitFormAJAX('shopping_cart_form',(secureurl + 'shopping_cart.php'),'overlay_signup_content',function(){adjustOverlays(); updateShoppingCartItemNumber();});
  } else {
    $('#shopping_cart_form').attr('action',secureurl);
    document.getElementById('shopping_cart_form').submit();
  }
}

function removeItemFromCart(item_index) {
    $('#cart_item_index').val(item_index);
    $('#shopping_cart_form_action').val('remove_from_cart');
    submitFormAJAX('shopping_cart_form',(secureurl + 'shopping_cart.php'),'overlay_signup_content',function(){adjustOverlays(); updateShoppingCartItemNumber();});
}

function updateShoppingCartQuantities() {
  $('#checkout_form_action').val('update_cart_quantities');
  submitFormAJAX('checkout_form',(secureurl + 'shopping_cart.php'),'overlay_signup_content',function(){adjustOverlays(); updateShoppingCartItemNumber();});
}

function buyItemFromCartWithCredit(item_index) {
  if(confirm('Use your credit to purchase this item?')) {
    $('#cart_item_index').val(item_index);
    $('#shopping_cart_form_action').val('make_purchase_with_credit');
    submitFormAJAX('shopping_cart_form',(secureurl + 'shopping_cart.php'),'overlay_signup_content',function(){adjustOverlays(); updateShoppingCartItemNumber();});
  }
}

function validateAddToCart(item_id, item_type) {
  var item_slug = "";
  if(item_type == 'special' || item_type == 'market_deal' || item_type == 'membership' || item_type == 'popup_deal') {
    item_slug = item_type;
  }

  if(!item_slug) return false;

  if ("https:" != document.location.protocol && isLoggedIn) { //no ssl and logged in
    $('#shopping_cart_form_s').val(item_slug);
    $('#shopping_cart_form_id').val(item_id);
    $('#shopping_cart_form_psa').val('get_' + item_slug);
    $('#shopping_cart_form').attr('action',secureurl);
    document.getElementById('shopping_cart_form').submit();
  } else if (isLoggedIn) { //logged in and ssl
      addItemToCart(item_id,item_slug);
  } else { //not logged in
      var message = "To get this special, you must be logged in.<br />Please, sign in.";
      var signup_message = "If this is your first special, please create an account.";
      showSignUpLogin(item_slug,item_id,'get_' + item_slug,message,signup_message);
  }
}

function addSpecialToCart(item_id) {
  validateAddToCart(item_id, 'special');
}

function addMarketDealToCart(item_id) {
  validateAddToCart(item_id, 'market_deal');
}

function addPopupDealToCart(item_id) {
  validateAddToCart(item_id, 'popup_deal');
}

function addMembershipToCart(item_id) {
  if ("https:" != document.location.protocol && isLoggedIn) { //no ssl and logged in
    $('#shopping_cart_form_s').val(return_s);
    $('#shopping_cart_form_id').val(return_id);
    $('#shopping_cart_form_psa').val('get_membership');
    $('#shopping_cart_form').attr('action',secureurl);
    document.getElementById('shopping_cart_form').submit();
  } else if (isLoggedIn) { //logged in and ssl
      addItemToCart(item_id,'membership');
  } else { //not logged in
      var message = "To get this special, you must be logged in.<br />Please, sign in.";
      var signup_message = "If this is your first special, please create an account.";
      showSignUpLogin(return_s,return_id,'get_membership',message);
  }
}

function addSpecialGiftToCart(item_id) {

  if (!($('#gift-name-' + item_id).val() && $('#gift-email-' + item_id).val())) {
      alert("Name and Email are required.");
      return false;
  }

  if (isLoggedIn) { //no ssl and logged in
    submitFormAJAX('gift-' + item_id,(secureurl + 'shopping_cart.php'),'overlay_signup_content',function(){adjustOverlays(); updateShoppingCartItemNumber();});
  } else { //not logged in
      var message = "To get this special, you must be logged in.<br />Please, sign in.";
      var signup_message = "If this is your first special, please create an account.";
      showSignUpLogin(return_s,return_id,'add_to_cart',message,signup_message);
  }
}

function addMembershipGiftToCart() {

  if (!($('#gift-name-membership').val() && $('#gift-email-membership').val())) {
    alert("Name and Email are required.");
    return false;
  }

  if($('#checkout_form .checkout_list input[type="checkbox"]:checked').length <= 0) {
    alert("Please select an edition.");
    return false;
  }

  var selected_edition_ids = Array();
  $('#checkout_form .checkout_list input[type="checkbox"]:checked').each(function(i) {
    selected_edition_ids.push($(this).attr('bbe-edition-id'));
  });

  $('#gift_edition_ids').val(selected_edition_ids.join(','));

  if (isLoggedIn) { //no ssl and logged in
    submitFormAJAX('checkout_form',(secureurl + 'shopping_cart.php'),'overlay_signup_content',function(){adjustOverlays(); updateShoppingCartItemNumber();});
  } else { //not logged in
      var message = "To get this special, you must be logged in.<br />Please, sign in.";
      var signup_message = "If this is your first special, please create an account.";
      showSignUpLogin(return_s,return_id,'add_to_cart',message,signup_message);
  }
}

function showGiftForm(element_id, element_type) {
  if(!isLoggedIn) {
    var message = "";
    var signup_message = "";
    showSignUpLogin(element_type,element_id,'gift_form',message,signup_message);
  } else if ("https:" == document.location.protocol) {
    turnOnSignupOverlay();
    loadExternalData(rooturl + 'shopping_cart.php?a=gift_form&id=' + element_id + '&type=' + element_type,'overlay_signup_content',function(){adjustOverlays();});
  } else {
    $('#shopping_cart_form_psa').val('gift_form');
    $('#shopping_cart_form_id').val(element_id);
    $('#shopping_cart_form_s').val(element_type);
    $('#shopping_cart_form').attr('action',secureurl);
    document.getElementById('shopping_cart_form').submit();
  }
}

function showMembershipForm() {
  if(!isLoggedIn) {
    var message = "";
    var signup_message = "";
    showSignUpLogin(return_s,return_id,'show_membership_form',message,signup_message);
  } else if ("https:" == document.location.protocol) {
    turnOnSignupOverlay();
    loadExternalData(rooturl + 'shopping_cart.php?a=show_membership_form','overlay_signup_content',function(){adjustOverlays();});
  } else {
    $('#shopping_cart_form_psa').val('show_membership_form');
    $('#new_item_id').val(return_id);
    $('#new_item_type').val(return_s);
    $('#shopping_cart_form').attr('action',secureurl);
    document.getElementById('shopping_cart_form').submit();
  }
}

function showGiftMembershipForm() {
  if(!isLoggedIn) {
    var message = "";
    var signup_message = "";
    showSignUpLogin(return_s,return_id,'show_gift_membership_form',message,signup_message);
  } else if ("https:" == document.location.protocol) {
    turnOnSignupOverlay();
    loadExternalData(rooturl + 'shopping_cart.php?a=show_gift_membership_form','overlay_signup_content',function(){adjustOverlays();});
  } else {
    $('#shopping_cart_form_psa').val('show_gift_membership_form');
    $('#new_item_id').val(return_id);
    $('#new_item_type').val(return_s);
    $('#shopping_cart_form').attr('action',secureurl);
    document.getElementById('shopping_cart_form').submit();
  }
}

function showDealOptionsForm(element_id, element_type) {
  if(!isLoggedIn) {
    var message = "";
    var signup_message = "";
    showSignUpLogin(element_type,element_id,'deal_options_form',message,signup_message);
  } else if ("https:" == document.location.protocol) {
    turnOnSignupOverlay();
    loadExternalData(rooturl + 'shopping_cart.php?a=deal_options_form&id=' + element_id + '&type=' + element_type,'overlay_signup_content',function(){adjustOverlays();});
  } else {
    $('#shopping_cart_form_psa').val('deal_options_form');
    $('#shopping_cart_form_id').val(element_id);
    $('#shopping_cart_form_s').val(element_type);
    $('#shopping_cart_form').attr('action',secureurl);
    document.getElementById('shopping_cart_form').submit();
  }
}

function addDealOptionToCart() {

  if($('#multiple-deal-options-will_call').length && trim($('#multiple-deal-options-will_call').val()) == '') {
    $('#multiple-deal-options-will_call').focus();
    alert('Please enter recipient\'s name.');
    return false;
  }

  if (isLoggedIn) { //no ssl and logged in
    submitFormAJAX('multiple-deal-option-quantities-available-form',(secureurl + 'shopping_cart.php'),'overlay_signup_content',function(){adjustOverlays(); updateShoppingCartItemNumber(); startCountdownTimers();});
  } else { //not logged in
      //var message = "To get this special, you must be logged in.<br />Please, sign up or sign in.";
      var message = "";
      var signup_message = "";
      showSignUpLogin(return_s,return_id,'add_to_cart',message,signup_message);
  }
}

function turnOffMembershipAutoRenew() {
  if(confirm('Turn off auto renewal for your annual membership?')) {
    $('#membership_autorenew_action').val('membership_autorenew_disable');
    $("#membership_autorenew_status").html("<span class=\"cs_loader_black_inline\">updating...</span>");
    submitFormAJAX('membership_autorenew_form',(rooturl + 'ajax.php'),'membership_autorenew_status',function(){});
  }
}

function showMembershipAutoRenewForm() {
  if(!isLoggedIn) {
    var message = "";
    showSignUpLogin(return_s,return_id,'show_membership_auto_renew_form',message);
  } else if ("https:" == document.location.protocol) {
    turnOnSignupOverlay();
    loadExternalData(rooturl + 'shopping_cart.php?a=show_membership_auto_renew_form','overlay_signup_content',function(){adjustOverlays();});
  } else {
    $('#shopping_cart_form_psa').val('show_membership_auto_renew_form');
    $('#shopping_cart_form').attr('action',secureurl);
    document.getElementById('shopping_cart_form').submit();
  }
}

function reEnableMembershipAutoRenew() {
  if(confirm('Turn on auto renewal for your annual membership?')) {
    $('#membership_autorenew_action').val('membership_autorenew_reenable');
    $("#membership_autorenew_status").html("<span class=\"cs_loader_black_inline\">updating...</span>");
    submitFormAJAX('membership_autorenew_form',(rooturl + 'ajax.php'),'membership_autorenew_status',function(){});
  }
}

function storeCardInfoForAnnualMembership() {
  var input_valid = true;
  var has_required_fields = 0;
  var required_fields = new Array('checkout_first_name','checkout_last_name','checkout_card_num','checkout_card_code','checkout_address','checkout_city','checkout_zip');

  $('.credit-card-list input').each(function(i) {
    if($(this).is(':checked')) {
      has_required_fields = 1;
    }
  });

  if (has_required_fields != 1) {
    $('.credit-card-list').parents('li').find('label').css('color','red');
  } else {
    $('.credit-card-list').parents('li').find('label').css('color','#000000');
  }

  for(var i=0; i < required_fields.length; i++) {
    if (!$('#' + required_fields[i]).val()) {
      has_required_fields = 0;
      $('#' + required_fields[i]).parents('li').find('label').css('color','red');
    } else {
      $('#' + required_fields[i]).parents('li').find('label').css('color','#000000');
    }
  }

  if (has_required_fields != 1) {
      alert("All fields are required.");
      return false;
  }

  if (checkCreditCard ($('#checkout_card_num').val(),$('.credit-card-list input:checked').val())) {
    $('#checkout_card_num').parents('li').find('label').css('color','#000000');
  } else {
    $('#checkout_card_num').parents('li').find('label').css('color','red');
    alert (ccErrors[ccErrorNo]);
    return false;
  }

  if(input_valid) {
    submitFormAJAX('update_cc_info_form',(secureurl + 'shopping_cart.php'),'overlay_signup_content',function(){$("#membership_autorenew_status").html(""); adjustOverlays();});
  }
}

function showUpdateStoredCCInfoForm() {
  if(!isLoggedIn) {
    var message = "";
    var signup_message = "";
    showSignUpLogin(return_s,return_id,'update_stored_credit_card_info',message,signup_message);
  } else if ("https:" == document.location.protocol) {
    turnOnSignupOverlay();
    loadExternalData(rooturl + 'shopping_cart.php?a=update_stored_credit_card_info','overlay_signup_content',function(){adjustOverlays();});
  } else {
    $('#shopping_cart_form_psa').val('update_stored_credit_card_info');
    $('#shopping_cart_form').attr('action',secureurl);
    document.getElementById('shopping_cart_form').submit();
  }
}

function updateStoredCardInfo() {
  var input_valid = true;
  var has_required_fields = 0;
  var required_fields = new Array('checkout_first_name','checkout_last_name','checkout_card_num','checkout_card_code','checkout_address','checkout_city','checkout_zip');

  $('.credit-card-list input').each(function(i) {
    if($(this).is(':checked')) {
      has_required_fields = 1;
    }
  });

  if (has_required_fields != 1) {
    $('.credit-card-list').parents('li').find('label').css('color','red');
  } else {
    $('.credit-card-list').parents('li').find('label').css('color','#000000');
  }

  for(var i=0; i < required_fields.length; i++) {
    if (!$('#' + required_fields[i]).val()) {
      has_required_fields = 0;
      $('#' + required_fields[i]).parents('li').find('label').css('color','red');
    } else {
      $('#' + required_fields[i]).parents('li').find('label').css('color','#000000');
    }
  }

  if (has_required_fields != 1) {
      alert("All fields are required.");
      return false;
  }

  if (checkCreditCard ($('#checkout_card_num').val(),$('.credit-card-list input:checked').val())) {
    $('#checkout_card_num').parents('li').find('label').css('color','#000000');
  } else {
    $('#checkout_card_num').parents('li').find('label').css('color','red');
    alert (ccErrors[ccErrorNo]);
    return false;
  }

  if(input_valid) {
    submitFormAJAX('update_cc_info_form',(secureurl + 'shopping_cart.php'),'overlay_signup_content',function(){updateStoredCardInfoStatus(); adjustOverlays();});
  }
}

function removeStoredCardInfo() {
  if(confirm('Remove your stored credit card information?')) {
    $('#update_cc_info_action').val('remove_credit_card_info');
    submitFormAJAX('update_cc_info_form',(secureurl + 'shopping_cart.php'),'overlay_signup_content',function(){updateStoredCardInfoStatus(); adjustOverlays(); });
  }
}

function updateStoredCardInfoStatus() {
  loadExternalData(rooturl + 'ajax.php?a=get_account_info_cc_info_status','store-credit-card-info-content',function(){adjustOverlays();});
}

function hideCreditCardFields() {
    $('#credit_card_fields_container').css('height',0);
    $('#credit_card_fields_container').css('overflow','hidden');
    $('#credit_card_fields_container').css('visibility','hidden');
    $('#use_debit').val('1');
}

function showCreditCardFields() {
  $('#credit_card_fields_container').css('height','auto');
  $('#credit_card_fields_container').css('overflow','visible');
  $('#credit_card_fields_container').css('visibility','visible');
  $('#use_debit').val('0');
}

function makePurchase() {
    var input_valid = true;
    var has_required_fields = 0;
    var required_fields = new Array('checkout_first_name','checkout_last_name','checkout_card_num','checkout_card_code','checkout_address','checkout_city','checkout_zip');
    var use_debit = 0;

    if($('#use_debit_1').length) { //has card on file
      use_debit = $('#use_debit_1').is(':checked');
    }

    if(!use_debit) {

      $('.credit-card-list input').each(function(i) {
        if($(this).is(':checked')) {
          has_required_fields = 1;
        }
      });

      if (has_required_fields != 1) {
        $('.credit-card-list').parents('li').find('label').css('color','red');
      } else {
        $('.credit-card-list').parents('li').find('label').css('color','#000000');
      }

      for(var i=0; i < required_fields.length; i++) {
        if (!$('#' + required_fields[i]).val()) {
          has_required_fields = 0;
          $('#' + required_fields[i]).parents('li').find('label').css('color','red');
        } else {
          $('#' + required_fields[i]).parents('li').find('label').css('color','#000000');
        }
      }

        if (has_required_fields != 1) {
            alert("All fields are required.");
            return false;
        }

        if (checkCreditCard ($('#checkout_card_num').val(),$('.credit-card-list input:checked').val())) {
          $('#checkout_card_num').parents('li').find('label').css('color','#000000');
        } else {
          $('#checkout_card_num').parents('li').find('label').css('color','red');
          alert (ccErrors[ccErrorNo]);
          return false;
        }

    }

    if($('#checkout_terms').is(':checked') == false || $('#checkout_terms').is(':checked') == 'false') {
        alert("You must agree to the terms and conditions.");
        return false;
    }

    if(input_valid) {
      $('#make-purchase-button-container').html('<span class=\"cs_loader_gray\">one moment please...</span>');
      submitFormAJAX('checkout_form',(secureurl + 'shopping_cart.php'),'overlay_signup_content',function(){adjustOverlays(); updateShoppingCartItemNumber();});
    }
}

function showSecurityCodeInstructions() {
  var cc_chosen = 0;

  $('.credit-card-list input').each(function(i) {
    if($(this).is(':checked')) {
      cc_chosen = 1;
    }
  });

  if(cc_chosen) {
    var cc_choice = $('.credit-card-list input:checked').val();
    var cc_instructions = "";
    if(cc_choice == 'Visa') {
      cc_instructions = "The Verification Code is a three-digit number on the <b>back</b> of your Visa credit card. The full credit card number is reprinted in the signature box and at the end of the number is the Verification Code.";
    } else if(cc_choice == 'MasterCard') {
      cc_instructions = "The Verification Code is a three-digit number on the <b>back</b> of your MasterCard. The full credit card number is reprinted in the signature box and at the end of the number is the Verification Code. ";
    } else if(cc_choice == 'AmEx') {
      cc_instructions = "The Verification Code is a four-digit number on the <b>front</b> of the card above the credit card number on either the right or the left side of your American Express credit card. ";
    } else if(cc_choice == 'Discover') {
      cc_instructions = "The Verification Code is a three-digit number on the <b>back</b> of your Discover card. The full credit card number is reprinted in the signature box and at the end of the number is the Verification Code.";
    }

    $('#cc-security-code-content').css('display','block');
    $('#cc-security-code-container').css('paddingTop',5);
    $('#cc-security-code-content').html('<div class="cc-security-code-content cc-' + cc_choice + '">' + cc_instructions + '</div><a class="cc-security-code-close-link" onclick="turnOffSecurityCodeInstructions(); return false" href="#">close</a>');
  } else {
    alert('Please, select a credit card to show the security code instructions.');
  }

}

function turnOffSecurityCodeInstructions() {
  $('#cc-security-code-container').css('paddingTop',0);
  $('#cc-security-code-content').css('display','none');
  $('#cc-security-code-content').html('');
}

function updateMembershipPrices() {
  var num_memberships = $('#num_memberships').val();
  var at_least_one_checked = 0;
  var initial_membership_accounted_for = 0;
  var shopping_cart_cost = 0;
  var initial_membership_price = 20;
  var additional_membership_price = 5;

  if(num_memberships > 0) { //already has membership
    at_least_one_checked = 1;
    initial_membership_accounted_for = 1;
  } else {
    $('#checkout_form .checkout_list input:checkbox').each(function(i) {
      if($(this).is(':checked')) {
        at_least_one_checked = 1;
      }
    });
  }

  if($('#initial_membership_price').length) {
    initial_membership_price = parseFloat($('#initial_membership_price').val());
  }

  if($('#additional_membership_price').length) {
    additional_membership_price = parseFloat($('#additional_membership_price').val());
  }

  $('#checkout_form .checkout_list input:checkbox').each(function(i) {
    if(at_least_one_checked == 0) {
      $(this).attr('bbe-price',0);
      if($(this).is(':checked')) $(this).parents('.checkout_list li').find('.membership-total-unfixed').html('$' + initial_membership_price + '.00');
      else $(this).parents('.checkout_list li').find('.membership-total-unfixed').html('');
    } else if($(this).is(':checked') && initial_membership_accounted_for == 0) {
      $(this).attr('bbe-price',initial_membership_price);
      if($(this).is(':checked')) $(this).parents('.checkout_list li').find('.membership-total-unfixed').html('$' + initial_membership_price + '.00');
      else $(this).parents('.checkout_list li').find('.membership-total-unfixed').html('');
      initial_membership_accounted_for = 1;
      shopping_cart_cost += initial_membership_price;
    } else {
      $(this).attr('bbe-price',additional_membership_price);
      if($(this).is(':checked')) {
        $(this).parents('.checkout_list li').find('.membership-total-unfixed').html('$' + additional_membership_price + '.00');
        shopping_cart_cost += additional_membership_price;
      } else {
        $(this).parents('.checkout_list li').find('.membership-total-unfixed').html('');
      }
    }

  });

  $('#membership_shopping_cart_total').html(shopping_cart_cost);

}

function tocScroll(element_id) {

  var scroll_position = $('#' + element_id).position().top - 123;
  //alert(scroll_position + " : " + $('#checkout_purchase_container').scrollTop());
  $('#checkout_purchase_container').scrollTop(scroll_position);

}

function updateShoppingCartItemNumber() {
  if(isLoggedIn) {
    loadExternalData(rooturl + 'ajax.php?a=get_num_shopping_cart_items','shopping-cart-num-items',function(){});
    //disabled loadExternalData(rooturl + 'ajax.php?a=get_user_credit','user-credit-status',function(){});
  }
}

function sendReferralEmails() {
  var input_valid = true;

  if($('#recipient_list').val() == '') {
    alert('The recipient list is empty.');
    input_valid = false;
    return false;
  }

  var num_entries = $('#recipient_list').val().split(',').length;

  /*
  if(num_entries > $('#num_eligible_referral_signups').val()) {
    alert(num_entries + ' exceeded the number of allowed referrals.');
    input_valid = false;
    return false;
  }
  */

  if(input_valid) {
    $("#rewards_form_status").html("<span class=\"cs_loader_black_inline\">sending...</span>");
    submitFormAJAX("rewards_form",(rooturl + 'ajax.php'),"rewards_form_status",function() {$('#recipient_list').val('')});
  }

}

function cancelAnnualMembership() {
  $("#membership_refund_status").html("<span class=\"cs_loader_black_inline\">cancelling membership...</span>");
  submitFormAJAX("membership_refund_form",(rooturl + 'ajax.php'),"membership_refund_status",function() {});
}

function cancelSuspendedAnnualMembership() {
  doCancel = confirm ("Please confirm that you would like to cancel your annual membership.");
  if (doCancel) {
    $("#checkout_form").css('display','none');
    $("#cancel_suspended_membership_status").html("<span class=\"cs_loader_black_inline\">cancelling membership...</span>");
    submitFormAJAX("cancel_suspended_membership_form",(rooturl + 'ajax.php'),"cancel_suspended_membership_status",function() {});
  }
}

function updateSpecialOptionsList() {
  $('#multi-deal-option-price').html('');
  $('#multi-deal-option-submit').css('display','none');
  $("#multiple-deal-option-list").html("<span class=\"cs_loader_gray\">retrieving options...</span>");
  submitFormAJAX("multiple-deal-option-group-form",(rooturl + 'ajax.php'),"multiple-deal-option-list",function() {});
}

function updateSpecialOptionsForm() {
  if($('#multiple-deal-options-quantities-available').val() > 0) {
    var price = (parseFloat($('#multiple-deal-options option:selected').attr('bbe-price')) * $('#multiple-deal-options-quantities-available').val());
    price = Math.round(price * 100) / 100;
    $('#multi-deal-option-price').html('$' + price);
    $('#multi-deal-option-submit').css('display','inline');
  } else {
    $('#multi-deal-option-price').html('');
    $('#multi-deal-option-submit').css('display','none');
  }
}

function updateSpecialOptionsQuantitiesAvailableForm() {
  $('#multi-deal-option-price').html('');
  $('#multi-deal-option-submit').css('display','none');
  $("#multiple-deal-option-quantities-available-list").html("<span class=\"cs_loader_gray\">retrieving quantities...</span>");
  submitFormAJAX("multiple-deal-option-form",(rooturl + 'ajax.php'),"multiple-deal-option-quantities-available-list",function() {updateSpecialOptionsForm()});
}

function startCountdownTimers() {
  if($('.countdown-timer').length) {
    clearInterval(countdown_timers);
    countdown_timers = setInterval ( "doCountdownTimers()", 1000 );
  }
}

function doCountdownTimers() {
  $('.countdown-timer').each(function(i) {
    var timestamp = $(this).attr('bbe-countdown-timestamp');
    if(timestamp > 0) {
      $(this).attr('bbe-countdown-timestamp',timestamp - 1);
      $(this).html(formatTimestampToText(timestamp - 1));
    } else {
      removeItemFromCart($(this).attr('bbe-countdown-item-index'));
    }
  });
}

function formatTimestampToText(total_num_seconds) {
  var days = 0;
  var hours = 0;
  var minutes = 0;
  var seconds = 0;
  var output = "";

  var difference = total_num_seconds;
  days = Math.floor(difference / 86400);
  difference = difference % 86400;
  hours = Math.floor(difference / 3600);
  difference = difference % 3600;
  minutes = Math.floor(difference / 60);
  difference = difference % 60;
  seconds = Math.floor(difference);


  if(days > 0) {
    if(days == 1) {
      output = output + days + ' day ';
    } else {
      output = output + days + ' days ';
    }
  }

  if(hours > 0) {
    if(hours == 1) {
      output = output + hours + ' hour ';
    } else {
      output = output + hours + ' hours ';
    }
  }

  if(minutes > 0) {
    if(minutes == 1) {
      output = output + minutes + ' minute ';
    } else {
      output = output + minutes + ' minutes ';
    }
  }

  if(seconds > 0) {
    if(seconds == 1) {
      output = output + seconds + ' second ';
    } else {
      output = output + seconds + ' seconds ';
    }
  }

  return output;
}

function filterSpecials(section,section_ids,selected_section) {
  $('.filtered_special_list .entry').css('display','block');
  var status_message = "Currently filtering by<br />" + section + ": " +  selected_section;

  if(section == 'City') {
    $('.filtered_special_list .entry').each(function() {
      if(!filterInRange($(this).attr('bbe-edition'),section_ids)) {
        $(this).css('display','none');
      }
    });
  } else if(section == 'Cuisine') {
    $('.filtered_special_list .entry').each(function() {
      if(!filterInRange($(this).attr('bbe-cuisine'),section_ids)) {
        $(this).css('display','none');
      }
    });
  } else if(section == 'Feature') {
    $('.filtered_special_list .entry').each(function() {
      if(!filterInRange($(this).attr('bbe-features'),section_ids)) {
        $(this).css('display','none');
      }
    });
  } else if(section == 'Neighborhood') {
    $('.filtered_special_list .entry').each(function() {
      if(!filterInRange($(this).attr('bbe-neighborhoods'),section_ids)) {
        $(this).css('display','none');
      }
    });
  } else if(section == 'Price') {
    $('.filtered_special_list .entry').each(function() {
      if(!filterInRange($(this).attr('bbe-price'),section_ids)) {
        $(this).css('display','none');
      }
    });
  } else {
    status_message = "";
  }

  $('#filtered_special_list_status').html(status_message);

  adjustShadows();
  adjustOverlays();
}

function filterInRange(range_text,filter_id) {
  var id_array = range_text.split(',');
  for(var i=0; i < id_array.length; i++) {
    if(filter_id == id_array[i]) {
      return true;
    }
  }
  return false;
}
