﻿$(document).ready(function () {

    if (document.URL.indexOf("Survey") != -1 || document.URL.indexOf("survey") != -1)
        ReplaceSubjectNames();

});

function ReplaceSubjectNames() {
    //replace "person" with subjectname in ahar-type type if necessary:
    if (subjectName != null && subjectName.length > 0) {
        if (subjectName.toLowerCase().substring(0, 1) != 'a' && subjectName.toLowerCase().substring(0, 1) != 'e' &&
        subjectName.toLowerCase().substring(0, 1) != 'i' && subjectName.toLowerCase().substring(0, 1) != 'o' &&
        subjectName.toLowerCase().substring(0, 1) != 'u') {

            $("span").each(function () { $(this).html($(this).html().replace(/an Individual/g, 'a ' + subjectName)); })

            $("span").each(function () { $(this).html($(this).html().replace(/an individual/g, 'a ' + subjectName.toLowerCase())); })

            $("label").each(function () { $(this).html($(this).html().replace(/an Individual/g, 'a ' + subjectName)); })

            $("label").each(function () { $(this).html($(this).html().replace(/an individual/g, 'a ' + subjectName.toLowerCase())); })

            $("p").each(function () { $(this).html($(this).html().replace(/an Individual/g, 'a ' + subjectName)); })

            $("p").each(function () { $(this).html($(this).html().replace(/an individual/g, 'a ' + subjectName.toLowerCase())); })

            $("a").each(function () { $(this).html($(this).html().replace(/an Individual/g, 'a ' + subjectName)); })

            $("a").each(function () { $(this).html($(this).html().replace(/an individual/g, 'a ' + subjectName.toLowerCase())); })
        }

        $("span").each(function () { $(this).html($(this).html().replace(/Person|Individual/g, subjectName)); })

        $("span").each(function () { $(this).html($(this).html().replace(/person|individual/g, subjectName.toLowerCase())); })

        $("label").each(function () { $(this).html($(this).html().replace(/Person|Individual/g, subjectName)); })

        $("label").each(function () { $(this).html($(this).html().replace(/person|individual/g, subjectName.toLowerCase())); })

        $("p").each(function () { $(this).html($(this).html().replace(/Person|Individual/g, subjectName)); })

        $("p").each(function () { $(this).html($(this).html().replace(/person|individual/g, subjectName.toLowerCase())); })

        $("a").each(function () { $(this).html($(this).html().replace(/Person|Individual/g, subjectName)); })

        $("a").each(function () { $(this).html($(this).html().replace(/person|individual/g, subjectName.toLowerCase())); })
    }
}

function openReport(reportName, id, programTypeId, type) {

    var newWin = window.open("../User/ViewTelerikReport.aspx?report=" + reportName + "&id=" + id + "&programTypeId=" + programTypeId + "&type=" + type, "HDXReporting",
                "height=810px, width=860px, status=no, toolbar=no, menubar=no, location=yes, top=50px, left=50px");
    newWin.focus();
}

function openReportAdmin(reportName, state, programType, year, cocId, pulseQuarterId, type) {

    var newWin = window.open("../User/ViewTelerikReport.aspx?report=" + reportName + "&state=" + state + "&programType=" + programType + "&year=" + year + "&pulseQuarterId=" + pulseQuarterId + "&type=" + type + "&cocId=" + cocId, "HDXReporting",
                "height=810px, width=860px, status=no, toolbar=no, menubar=no, location=yes, top=50px, left=50px");
    newWin.focus();
}

function openErrors(url) {

    window.open(url, "Errors", "height=600px, width=800px, status=no, toolbar=yes, menubar=yes, location=no, scrollbars=yes, top=50px, left=50px");

}

//use this to set a maxlength for multiline textboxes
function maxLength(text, length) {
    var maxlength = new Number(length);

    if (text.value.length > maxlength) {

        text.value = text.value.substring(0, maxlength);

        alert(" This field allows a maximum of " + length + " characters");

    }
}
