$(function () {
    //hide sponsor image in footer

    var fs = $("#footer-sponsor");
    if (fs.attr("data-show") == "No")
        fs.hide();



    //-- Suckerfish Dropdowns --//
    sfHover = function () {
        var sfEls = document.getElementById("nav").getElementsByTagName("LI");
        for (var i = 0; i < sfEls.length; i++) {
            sfEls[i].onmouseover = function () {
                this.className += " sfhover";
            }
            sfEls[i].onmouseout = function () {
                this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
            }
        }
    }
    if (window.attachEvent) window.attachEvent("onload", sfHover);

    //-- to reformat the date on the Events sidebar  --//
    var days = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"];
    var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
    $("span.date-time-news, span.date-event").each(function () {
        var dateArray = $(this).text().split("-");
        var newDay = dateArray[2];
        var newMonth = dateArray[1];
        var newYear = dateArray[0];
        var newDateFormat = "<span>" + months[newMonth - 1] + " " + days[newDay - 1] + ", " + "</span>" + newYear;
        $(this).html(newDateFormat);
    });





    //wraps the select dropdowns so i can put a background on them
    $('.webform .cat_dropdown').each(function () {
        $(this).wrap('<div class="selectTwoEighty" />');
    });

    //wraps the select dropdowns so i can put a background on them
    $('.webform .cat_dropdown').each(function () {
        $(this).wrap('<div class="selectOneSeventy" />');
    });

    //wraps the select dropdowns so i can put a background on them
    $('.webform .CAT_Category').each(function () {
        $(this).wrap('<div class="selectOneSeventy" />');
    });

    //wraps the select dropdowns so i can put a background on them
    $('.shippingDropDown').each(function () {
        $(this).wrap('<div class="selectOneSeventy" />');
    });



    //wraps the select dropdowns so i can put a background on them
    $('.webform .cat_dropdown_sm').each(function () {
        $(this).wrap('<div class="select90" />');
    });

    //wraps the select dropdowns so i can put a background on them
    $('.webform .cat_textbox_sm').each(function () {
        $(this).wrap('<div class="select90Text" />');
    });









    // Wrap span tag around sidebar li items w/ class of .aside-utility
    $("li.aside-utility").children("a").each(function () {
        var x = $(this).text();
        var items = x.split(" ");
        var str = "<span>" + items[0] + "</span> "
        for (var i = 1; i < items.length; i++) {
            str += items[i] + " ";
        }
        $(this).html(str);
    });


    // Wrap span tag around sidebar li items w/ class of .aside-utility- 2 li (on home page)
    $(".aside-utility-2 li").children("a").each(function () {
        var x = $(this).text();
        var items = x.split(" ");
        var str = "<span>" + items[0] + "</span> "
        for (var i = 1; i < items.length; i++) {
            str += items[i] + " ";
        }
        $(this).html(str);
    });

    // Remove any list item with empty a tags within the div class mini-col-2
    $('.webform tr td select#Title').each(function () {
        var titleRemove = $(this).attr("select");
        $(this).parent().parent().remove();

    });



});


// Agenda Web App. Hide fields with no data
function removeAgendaFields() {
    //  Remove any list items with empty divs that have the class name mini-col-2
    $('li.agenda-row div.mini-col-2').each(function () {
        var h = $(this).text();
        if (h.length <= 2) {

            $(this).parent().remove();
        }
    });

    // Remove any list item with empty a tags within the div class mini-col-2
    $('li.agenda-row a.mmother').each(function () {
        var x = $(this).attr("href");
        if (x.length <= 2) {
            $(this).parent().parent().remove();
        }
    });

    // Remove any list item with empty a tags within the div class mini-col-2
    $('li.agenda-row a.mmagenda').each(function () {
        var doo = $(this).attr("href");
        if (doo.length == "") {

            $(this).parent().parent().remove();
        }
    });

    // Remove any list item with empty a tags within the div class mini-col-2
    $('li.agenda-row a.mmmin').each(function () {
        var g = $(this).attr("href");
        if (g.length <= 2) {
            $(this).parent().parent().remove();
        }
    });


    /*	$('#copyName').each(function () {
    var type = $(this).text();
		
    $('#FirstName').val(type);
    });

	
	
    var copyName = $("#copyName").text();
    var formName = $("#FirstName").val();
    alert(formName);
    jQuery(".deleteme").click(function() {
    if (formName === "Name") {
    $(formName).val(copyName);
    }
    });
		
    */




}



// Hero Web App. Hide fields with no data
function removeHeroFields() {
    // Remove p.hero-edit - on hero slide edit template if span is empty
    $('p.hero-edit span').each(function () {
        var v = $(this).text();
        if (v.length <= 2) {
            $(this).parent().remove();
        }
    });

    // Remove p.hero-edit - on hero slide edit template if href is empty
    $('p.hero-edit a').each(function () {
        var w = $(this).attr("href");
        if (w.length <= 2) {
            $(this).parent().remove();
        }
    });
}


// Photos Web App. Hide fields with no data
function removePhotoFields() {
    //remove empty images from web apps
    $("div.gallery-image img").each(function () {
        var galleryImg = $(this).attr("src");

        if (galleryImg.length <= 28) {
            $(this).parent().parent().remove();
        }
    });
}

// Events Web App. Hide fields with no data
function removeEventFields() {
    // Remove Purchase Tickets button (.btn-purchase-tickets) if href is empty
    $('a.btn-purchase-tickets').each(function () {
        var z = $(this).attr("href");
        if (z.length <= 2) {
            $(this).remove();
        }
    });

    // Remove address
    $('#eventAddress').each(function () {
        var eventAddress = $(this).text();
        if (eventAddress.length <= 53) {
            $(this).remove();
            $('#js-map').remove();
        }
    });

}


//BD Web App. Hide fields with no data
function removeBusinessDirectoryFields() {
    // Remove special
    $('div.bus-special').each(function () {
        var spec = $(this).text();
        if (spec.length <= 18) {
            $(this).remove();
        }
    });

    // Remove about
    $('div.bus-about').each(function () {
        var abt = $(this).text();
        if (abt.length <= 18) {
            $(this).remove();
        }
    });


    // Remove note
    $('div.bus-notes').each(function () {
        var nts = $(this).text();
        if (nts.length <= 8) {
            $(this).remove();
        }
    });



    // Remove address
    $('#bus-address').each(function () {
        var bsAddress = $(this).text();

        if (bsAddress.length <= 17) {
            $(this).remove();
            $('#js-map').remove();
        }
    });

    // Add placeholder image if none is uploaded
    $('div.business-logo a img').each(function () {
        var bdImg = $(this).attr("src");
        if (bdImg.length <= 38) {
            $(this).parent().html('<img src="/_assets/css/images/bd-placeholder.jpg?Action=thumbnail&amp;Width=225&amp;Height=190" alt="Business Photo Unavailable">');
        }
    });

    // Add placeholder image if none is uploaded
    $('div.business-logo-lrg a img').each(function () {

        var bdImg = $(this).attr("src");
        if (bdImg.length <= 61) {
            $(this).parent().html('<img src="/_assets/css/images/bd-placeholder-lrg.jpg?Action=thumbnail&amp;Width=295&amp;Height=250" alt="Business Photo Unavailable">');
        }
    });



}



// Exec Member Web App.
function addExecImg() {
    //  If image is not upload, add placeholder
    $('li.secImg img').each(function () {
        var ei = $(this).attr("src");
        if (ei.length <= 38) {
            $(this).parent().html('<img src="/_assets/css/images/place-image-1.png?Action=thumbnail&amp;Width=140&amp;Height=85" alt="Executive Member Photo Unavailable">');
        }
    });

    // If no telephone info, hide
    $('li.secTel').each(function (index) {
        var x = $(this).text();
        if (x.length <= 7) {
            $(this).addClass('hide');
        }
    });
    //If no mail info, hide
    $('li.secMai a').each(function (index) {
        var y = $(this).attr('href');
        if (y.length <= 8) {
            $(this).parent().addClass('hide');

        }


    });


}



// Events Web App. Hide fields with no data
function switchWebAppView() {
    // Secure zone area for web apps - show add form/hide items and vise versa when link is clicked
    $(".webapp-add").hide();
    $(".btn-webapp-add").click(function () {
        $(".webapp-add").show();



        $("#ItemDescriptionHTML").htmlarea({
            // Override/Specify the Toolbar buttons to show
            toolbar: [
                      ["bold", "italic", "underline", "|"],
                      ["p", "h1", "h2", "h3", "|"],
                      ["link", "unlink", "|"],
		                  ["orderedlist", "unorderedlist"]
                    ]
        });
		
		$("#ItemDescriptionHTML2").htmlarea({
            // Override/Specify the Toolbar buttons to show
            toolbar: [
                      ["bold", "italic", "underline", "|"],
                      ["p", "h1", "h2", "h3", "|"],
                      ["link", "unlink", "|"],
		                  ["orderedlist", "unorderedlist"]
                    ]
        });
		
		$("#ItemDescriptionHTML3").htmlarea({
            // Override/Specify the Toolbar buttons to show
            toolbar: [
                      ["bold", "italic", "underline", "|"],
                      ["p", "h1", "h2", "h3", "|"],
                      ["link", "unlink", "|"],
		                  ["orderedlist", "unorderedlist"]
                    ]
        });
		
	
		
		



        $(".webapp-items").hide();
        return false;
    });
    $(".btn-webapp-items").click(function () {
        $(".webapp-add").hide();
        $(".webapp-items").show();
        return false;
    });
}



//Great School Resources Web App. 
function addResourcesImage() {

    // Add placeholder image if none is uploaded
    $('div.resource-image a img').each(function () {
        var bdImg = $(this).attr("src");
        if (bdImg.length <= 38) {
            $(this).parent().html('<img src="/_assets/css/images/bd-placeholder.jpg?Action=thumbnail&amp;Width=225&amp;Height=190" alt="Business Photo Unavailable">');
        }
    });

}

