﻿var sccgovCalendarCellSpacing = "5";

function sccgovImageCycle(id, effect, cycletime, nextid, previd, pagerid) {
    $('#' + id).cycle({
        fx: effect,
        timeout: parseInt(cycletime),
        pause: 1,
        next: '#' + nextid,
        prev: '#' + previd
    });
}

function openExternalSite(desturl) {
    sccgovModalPopup("You Are Leaving Public Health Department", "<div class=\"sccgov_events_container\">", "<p>Our web pages have many links to other organizations, such as other government agencies, non-profit community based organizations, and for-profit entities. While we offer these links for your convenience in accessing the services you require, please be aware that the policies that apply to our portal may not be the same as the terms of use for other web sites. In addition, the County of Santa Clara cannot attest to the accuracy of the information provided by linked sites. The inclusion of a hypertext link to an external website is not intended as an endorsement of any product or service offered or referenced the linked websites, the organizations sponsoring linked websites, or any views that might be expressed or referenced in websites linked to from the County of Santa Clara's Official Web Portal.</p><a class=\"sccgov_variation_button\" href=\"" + desturl + "\" target=\"_blank\">Continue to external website</a>", "<div id=\"sccgov_calendar_popup_bottom\"></div>", "</div>", "", "double");
}

function sccgovContainer() {
    $("#sccgov_master_page_container").css("visibility", "visible");
}

function openSubscriptionPage(email) {
    if (email != "Enter your email..." && email != null && email != "" && sccgovValidateEmail(email) == false)
    {
        sccgovModalPopup("Newsletter Subscription", 
             "<div class=\"sccgov_events_container\">",
             "<p>Invalid email address.</p>",
             "<div id=\"sccgov_calendar_popup_bottom\"></div>", 
             "</div>");
        return;
    }
    var currentURL = document.URL;
    var endIndex = currentURL.indexOf("/Pages");
    var rootStr = currentURL.substring(0, endIndex + "/Pages".length);
    if (email == "Enter your email...") {
        window.location.href = rootStr + "/Subscription.aspx";
    }
    else {
        window.location.href = rootStr + "/Subscription.aspx?email=" + email;
    }
    
    return;
}

function sccgovShowDropDown(id) {
    if ($("#" + id + " .sccgov_master_head_menulinks_body").css("display") == "none") {
        $("#" + id + " .sccgov_master_head_menulinks_footer_more").css("display", "none");
        $("#" + id + " .sccgov_master_head_menulinks_body").css("display", "block");
        $("#" + id + " .sccgov_master_head_menulinks_footer_rounded").css("display", "block");
    }
    else {
        $("#" + id + " .sccgov_master_head_menulinks_body").css("display", "none");
        $("#" + id + " .sccgov_master_head_menulinks_footer_rounded").css("display", "none");
        $("#" + id + " .sccgov_master_head_menulinks_footer_more").css("display", "block");
    }
}

function sccgovCSSJavaScript()
{
    $("span.menu-item-text:contains('Health Alerts')").css("color", "#FD6631");
    $("span.menu-item-text:contains('Health Alerts')").css("font-weight", "bold");
}

function sccgovOpenEventsCalendarLocationDirections(url, location) {
    var sccgovURL = document.URL;
    var endIndex = currentURL.indexOf("/Pages");
    var rootStr = currentURL.substring(0, endIndex + "/Pages".length);
    var length = sccgovEventsCalendarLocations.locations.location.length - 1;

    for (i = 0; i <= length; i++) {
        if (sccgovEventsCalendarLocations.locations.location[i].name == location) {
            if (sccgovEventsCalendarLocations.locations.location[i].address1 == "n/a" || sccgovEventsCalendarLocations.locations.location[i].address1 == "na" || sccgovEventsCalendarLocations.locations.location[i].address1 == "NA" || sccgovEventsCalendarLocations.locations.location[i].address1 == "N/A") {
                sccgovModalPopup("Location to be determined", "<div class=\"sccgov_events_container\">", "<p>The location for this event is to be determined. Please try again later!</p>", "<div id=\"sccgov_calendar_popup_bottom\"></div>", "</div>", "", "double");
            }
            else {
                window.open(rootStr + "/" + url + "?name=" + sccgovEventsCalendarLocations.locations.location[i].name + "&address=" + sccgovEventsCalendarLocations.locations.location[i].address1 + "&city=" + sccgovEventsCalendarLocations.locations.location[i].city + "&state=" + sccgovEventsCalendarLocations.locations.location[i].state + "&zip=" + sccgovEventsCalendarLocations.locations.location[i].zip);
            }
        }
    }
}

function showDate(date) {
    var d = new Date(date);
    var monthName = monthname[d.getMonth()];
    var dayName = weekday[d.getDay()];
    var dayNumber = d.getDate();
    var year = d.getFullYear();
    var sccgovCalendarPopUpTitle = dayName + ", " + monthName + " " + dayNumber + ", " + year;
    var length = sccgovCalendarEvents.calendar.day.length - 1;
    var header = "<div class=\"sccgov_events_container\"><table width=\"100%\"cellpadding=\"0\" cellspacing=\"5\"><thead><tr><th width=\"186\">Time</th><th width=\"242\">Event</th><th>Location</th></tr></thead><tbody>";
    var footer = "</tbody></table><div id=\"sccgov_calendar_popup_bottom\"></div>";
    var bottom = "</div>";
    var output = "";

    for (i = 0; i <= length; i++) {
        if (sccgovCalendarEvents.calendar.day[i].date == date) {
            var length2 = sccgovCalendarEvents.calendar.day[i].event.length - 1;
            for (j = 0; j <= length2; j++) {
                output += "<tr><td valign=\"top\">" + sccgovCalendarEvents.calendar.day[i].event[j].start.replace(" ", "") + " - " + sccgovCalendarEvents.calendar.day[i].event[j].end.replace(" ", "") + "</td><td valign=\"top\"><a href=\"" + sccgovCalendarEvents.calendar.day[i].event[j].url + "\">" + sccgovCalendarEvents.calendar.day[i].event[j].title + "</a></td><td valign=\"top\"><a href=\"javascript:sccgovOpenEventsCalendarLocationDirections('Directions.aspx','" + sccgovCalendarEvents.calendar.day[i].event[j].locname + "');\">" + sccgovCalendarEvents.calendar.day[i].event[j].locname + "</a></td></tr>";
            }
        }
    }

    if (output == "") {
        sccgovModalPopup("There are no events on this day!", "<div class=\"sccgov_events_container\">", "<p>There are no Santa Clara County Public Health Department events scheduled for " + sccgovCalendarPopUpTitle + ".</p>", "<div id=\"sccgov_calendar_popup_bottom\"></div>", bottom, "calendar");
    }
    else {
        sccgovModalPopup(sccgovCalendarPopUpTitle, header, output, footer, bottom, "calendar");
        sccgovSetExternalLinks();
    }
}
