﻿function pageLoad() {

    if (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6) { var isIE6 = true; }
    if (jQuery.browser.msie && parseInt(jQuery.browser.version) == 7) { var isIE7 = true; }

    if (!isIE6 && !isIE7) {
        $('input').each(function() {
            $(this).watermark($(this).attr('Title'), 'watermarked');
        });

        $('textarea').each(function() {
            $(this).watermark($(this).attr('Title'), 'watermarked');
        });
    }

    if (!isIE6) {

        /*Applies to Tooltip*/
        $('.trigger').tooltip({
            position: {
                corner: {
                    target: 'rightMiddle',
                    tooltip: 'leftMiddle'
                }
            },
            relative: true,
            effect: 'slide',
            opacity: 1,
            delay: 200,
            predelay: 333
        });

        $(".modalInput").overlay({
            expose: {
                color: '#333',
                loadSpeed: 200,
                opacity: 0.9
            },
            top: 'center',
            left: 'center'
        });

        $(".back").click(function() {
            window.history.go(-1);
        });

        $(".finalist-checkbox").click(function() {
            var hiddenField = $("#ctl00_ContentPlaceHolder1_hfFinalistCount");
            var idtoUpdate = $(".finalist-count");
            var count = (hiddenField.val() * 1);
            var max = $("#ctl00_ContentPlaceHolder1_hfFinalistMax").val();
            if (this.checked) {
                if (count == max) {
                    alert("You can only select " + max + " entries.");
                    this.checked = false;
                    return;
                }
                count += 1;
            }
            else {
                count -= 1;
            }
            hiddenField.val(count);
            idtoUpdate.html(count);
        });

        $(".finalist-save-selection").click(function() {
            var cArray = $(".finalist-form input:checked").get();
            var idList = "";
            for (i = 0; i <= cArray.length - 1; i++) {
                idList += $(cArray[i]).attr("id");
                if (i < cArray.length - 1) idList += ",";
            }

            var contestID = $("#ctl00_ContentPlaceHolder1_hfContestID").val();

            $.ajax({
                type: "POST",
                url: "../admin/Contests.aspx/SaveFinalists_WebPost",
                data: "{\"contestID\":\"" + contestID + "\",\"idList\":\"" + idList + "\"}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                cache: false,
                async: false
            });
        });

        $("#ctl00_ContentPlaceHolder1_ddlSortOrder").change(function() {
            window.location.hash = 0;
            populate_images();
        });

        $("#ctl00_ContentPlaceHolder1_ddlSortOrder").change(function() {
            window.location.hash = 0;
            populate_images();
        });
    }
}