﻿
//Check for Bad Characters
function RemoveBad(strInput) {
    strInput = strInput.replace(/\<|\>|\"|\'|\%|\;|\(|\)|\&|\+|\-/g, '');
    strInput = strInput.replace("delete", "");
    return strInput;
}
function PrintPage() {
    window.print();
}

function ValidateWordCount(textbox,errordisplay) {
    var mlength = textbox.getAttribute ? parseInt(textbox.getAttribute("maxlength")) : ""        
    var contentlength = 0;

    contentlength = textbox.value.match(/\S+/g).length;
    if (contentlength > mlength) {        
        $("#" + errordisplay).css("display", "inline");        
        return false;
    }    
    else
        $("#" + errordisplay).css("display","none");
}

//WINDOW RELATED(RADWINDOW OPENING/CLOSING)
function OpenWindow(URL, title, query, w, h, scrollbars) {
    var setting = "left=" + (screen.width - w) / 2 + ",top=" + (screen.height - h) / 3 + ",menubar=no,width=" + w + ",height=" + h + ",location=yes,toolbar=no,scrollbars=" + scrollbars + ",resizable=yes,status=yes";    
    if (query != "")
        URL = URL + "?" + query;
    var win = window.open(URL, '', setting);
    win.focus();
}
function CloseWindow() {
    var oWindow = GetRadWindow();
    if (oWindow)
        oWindow.Close();
    else
        window.close();
}
function WindowWidth() {
    var w = 0;
    if (!window.innerWidth) {
        //strict mode
        if (!(document.documentElement.clientWidth == 0)) {
            w = document.documentElement.clientWidth;
        } else { w = document.body.clientWidth; }
    } else { w = window.innerWidth; }
    return w
}

function LoadEmployeeWinners() {

    $.ajax({
        type: "POST",
        contentType: "application/json;charset=utf-8",
        url: "employee-voting-winners.aspx/getAllWinners",
        data: "{}",
        dataType: "json",
        success: function (data) {
            var obj = jQuery.parseJSON(data.d);

            //loading the winners
            if (obj[0].SchoolName != null) {
                $("#grandwinner").html(obj[0].SchoolName.toUpperCase().replace("MCGAVOCK", "McGAVOCK"));
                $("#grandnominated").html("NOMINATED BY: " + jQuery.trim(obj[0].FirstName.toUpperCase() + " " + obj[0].LastNameShort.toUpperCase() + ".") + ", " + obj[0].City.toUpperCase());
                $(".winner1 .schoolname").html(obj[0].SchoolName);
                $(".winner1 .gradelevel").html(obj[0].GradeLevel);
                $(".winner1 .fulladdr").html(obj[0].Address1 + " " + obj[0].Address2);
                $(".winner1 .location").html(obj[0].City + ", " + obj[0].SchoolStateFull + " " + obj[0].ZipCode);
                $(".winner1 .submittedby").html("Nominated by " + obj[0].FirstName + " " + obj[0].LastNameShort + ".");
                $(".winner1 .q1").html("1. " + obj[0].Question1);
                $(".winner1 .a1").html(obj[0].Answer1);
                $(".winner1 .q2").html("2. " + obj[0].Question2);
                $(".winner1 .a2").html(obj[0].Answer2);
                $(".winner1 .q3").html("3. " + obj[0].Question3);
                $(".winner1 .a3").html(obj[0].Answer3);
            }

            if (obj[1].SchoolName != null) {
                $("#school1").html(obj[1].SchoolName.toUpperCase());
                $("#Label1").html("NOMINATED BY:<br />" + jQuery.trim(obj[1].FirstName.toUpperCase() + " " + obj[1].LastNameShort.toUpperCase() + ".") + ", " + obj[1].City.toUpperCase());
                $(".winner2 .schoolname").html(obj[1].SchoolName);
                $(".winner2 .gradelevel").html(obj[1].GradeLevel);
                $(".winner2 .fulladdr").html(obj[1].Address1 + " " + obj[1].Address2);
                $(".winner2 .location").html(obj[1].City + ", " + obj[1].SchoolStateFull + " " + obj[1].ZipCode);
                $(".winner2 .submittedby").html("Nominated by " + obj[1].FirstName + " " + obj[1].LastNameShort + ".");
                $(".winner2 .q1").html("1. " + obj[1].Question1);
                $(".winner2 .a1").html(obj[1].Answer1);
                $(".winner2 .q2").html("2. " + obj[1].Question2);
                $(".winner2 .a2").html(obj[1].Answer2);
                $(".winner2 .q3").html("3. " + obj[1].Question3);
                $(".winner2 .a3").html(obj[1].Answer3);
            }

            if (obj[2].SchoolName != null) {
                $("#school2").html(obj[2].SchoolName.toUpperCase());
                $("#Label2").html("NOMINATED BY:<br />" + jQuery.trim(obj[2].FirstName.toUpperCase() + " " + obj[2].LastNameShort.toUpperCase() + ".") + ", " + obj[2].City.toUpperCase());
                $(".winner3 .schoolname").html(obj[2].SchoolName);
                $(".winner3 .gradelevel").html(obj[2].GradeLevel);
                $(".winner3 .fulladdr").html(obj[2].Address1 + " " + obj[2].Address2);
                $(".winner3 .location").html(obj[2].City + ", " + obj[2].SchoolStateFull + " " + obj[2].ZipCode);
                $(".winner3 .submittedby").html("Nominated by " + obj[2].FirstName + " " + obj[2].LastNameShort + ".");
                $(".winner3 .q1").html("1. " + obj[2].Question1);
                $(".winner3 .a1").html(obj[2].Answer1);
                $(".winner3 .q2").html("2. " + obj[2].Question2);
                $(".winner3 .a2").html(obj[2].Answer2);
                $(".winner3 .q3").html("3. " + obj[2].Question3);
                $(".winner3 .a3").html(obj[2].Answer3);
            }

            if (obj[3].SchoolName != null) {
                $("#school3").html(obj[3].SchoolName.toUpperCase());
                $("#Label3").html("NOMINATED BY:<br />" + jQuery.trim(obj[3].FirstName.toUpperCase() + " " + obj[3].LastNameShort.toUpperCase() + ".") + ", " + obj[3].City.toUpperCase());
                $(".winner4 .schoolname").html(obj[3].SchoolName);
                $(".winner4 .gradelevel").html(obj[3].GradeLevel);
                $(".winner4 .fulladdr").html(obj[3].Address1 + " " + obj[3].Address2);
                $(".winner4 .location").html(obj[3].City + ", " + obj[3].SchoolStateFull + " " + obj[3].ZipCode);
                $(".winner4 .submittedby").html("Nominated by " + obj[3].FirstName + " " + obj[3].LastNameShort + ".");
                $(".winner4 .q1").html("1. " + obj[3].Question1);
                $(".winner4 .a1").html(obj[3].Answer1);
                $(".winner4 .q2").html("2. " + obj[3].Question2);
                $(".winner4 .a2").html(obj[3].Answer2);
                $(".winner4 .q3").html("3. " + obj[3].Question3);
                $(".winner4 .a3").html(obj[3].Answer3);
            }

            if (obj[4].SchoolName != null) {
                $("#school4").html(obj[4].SchoolName.toUpperCase());
                $("#Label4").html("NOMINATED BY:<br />" + jQuery.trim(obj[4].FirstName.toUpperCase() + " " + obj[4].LastNameShort.toUpperCase() + ".") + ", " + obj[4].City.toUpperCase());
                $(".winner5 .schoolname").html(obj[4].SchoolName);
                $(".winner5 .gradelevel").html(obj[4].GradeLevel);
                $(".winner5 .fulladdr").html(obj[4].Address1 + " " + obj[4].Address2);
                $(".winner5 .location").html(obj[4].City + ", " + obj[4].SchoolStateFull + " " + obj[4].ZipCode);
                $(".winner5 .submittedby").html("Nominated by " + obj[4].FirstName + " " + obj[4].LastNameShort + ".");
                $(".winner5 .q1").html("1. " + obj[4].Question1);
                $(".winner5 .a1").html(obj[4].Answer1);
                $(".winner5 .q2").html("2. " + obj[4].Question2);
                $(".winner5 .a2").html(obj[4].Answer2);
                $(".winner5 .q3").html("3. " + obj[4].Question3);
                $(".winner5 .a3").html(obj[4].Answer3);
            }

        },
        complete: function () {

            $("#aWinner1").fancybox({
                'hideOnContentClick': false,
                'hideOnOverlayClick': false,
                'modal': true,
                'width': '641',
                'height': '602',
                'titleShow': false
            });

            $("#aWinner2").fancybox({
                'hideOnContentClick': false,
                'hideOnOverlayClick': false,
                'modal': true,
                'width': '641',
                'height': '602',
                'titleShow': false
            });

            $("#aWinner3").fancybox({
                'hideOnContentClick': false,
                'hideOnOverlayClick': false,
                'modal': true,
                'width': '641',
                'height': '602',
                'titleShow': false
            });

            $("#aWinner4").fancybox({
                'hideOnContentClick': false,
                'hideOnOverlayClick': false,
                'modal': true,
                'width': '641',
                'height': '602',
                'titleShow': false
            });

            $("#aWinner5").fancybox({
                'hideOnContentClick': false,
                'hideOnOverlayClick': false,
                'modal': true,
                'width': '641',
                'height': '602',
                'titleShow': false
            });

        }
    });

}
