﻿function SearchEnsureSOD()
{
}

function SendClick()
{
}

var currentURL = document.URL;

var app = Sys.Application;
var origTitle = "";
app.add_init(SPCustomAppnInit);

function SPCustomAppnInit(sender) {
    origTitle = document.title; // grab the original title.
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    if (!prm.get_isInAsyncPostBack()) {
        prm.add_pageLoaded(SPCustomPageLoaded); // wire up loaded handler.
    }
}

function SPCustomPageLoaded(sender, args) {
    document.title = origTitle; // put the original title back on the document.
}

function sccgovSetExternalLinks() {
    $("a[href^='http']").each(function()
		{
            $(this).click(function()
			{
                var sccgovWhiteList = false;
                for (var i = 0; i < domainExclusionList.length; i++)
			    {
				    if(this.href.indexOf(domainExclusionList[i]) != -1)
				    {
				        sccgovWhiteList = true;
				    }
			    }
                if (sccgovWhiteList == true)
                {
                    return true;
                }
                else
                {
					openExternalSite(this.href);
                    return false;
				}
            }
            );
		}
    )
}

function sccgovValidateZipCode(inputvalue) {
    var zipPattern = /^\d{5}$|^\d{5}-\d{4}$/;
    return zipPattern.test(inputvalue);
}

function sccgovValidateEmail(inputvalue) {
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
    return emailPattern.test(inputvalue);
}

function sccgovValidatePhone(inputvalue) {
    var phoneNumberPattern = /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/;
    return phoneNumberPattern.test(inputvalue);
}

function sccgovValidateVHPNPI(inputvalue) {
    var phoneNumberPattern = /^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/;
    return phoneNumberPattern.test(inputvalue);
}

function sccgovValidateVHPId(inputvalue) {
    var vhpIdPattern = /^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$|[0-9][-][0-9][0-9][0-9][-][0-9][0-9][-][0-9][0-9]$/;
    return vhpIdPattern.test(inputvalue);
}

function sccgovValidateHeightInches(inputvalue) {
    var heightInchesNumberPattern = /^[0-9][0-9]/;
    return heightInchesNumberPattern.test(inputvalue);
}

function sccgovValidateHeightFeet(inputvalue) {
    var heightFeetNumberPattern = /^[0-9]/;
    return heightFeetNumberPattern.test(inputvalue);
}

function sccgovValidateWeightPounds(inputvalue) {
    var weightNumberPattern = /^[0-9]{3}$/;
    return weightNumberPattern.test(inputvalue);
}

function sccgovValidateDate(inputvalue) {
    //var datePattern = /^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$/;
    var datePattern = /^((0?[13578]|10|12)(-|\/)(([1-9])|(0[1-9])|([12])([0-9]?)|(3[01]?))(-|\/)((19)([2-9])(\d{1})|(20)([01])(\d{1})|([8901])(\d{1}))|(0?[2469]|11)(-|\/)(([1-9])|(0[1-9])|([12])([0-9]?)|(3[0]?))(-|\/)((19)([2-9])(\d{1})|(20)([01])(\d{1})|([8901])(\d{1})))$/;
    return datePattern.test(inputvalue);
}

function sccgovInputFocus(inputid) {
    $("#" + inputid).css('font-style', 'normal');
    $("#" + inputid).css('color', '#000000');
    var searchCriteria = $("#" + inputid).val();
    if (searchCriteria == "(xxx) xxx-xxxx" || searchCriteria == "Enter your email..." || searchCriteria == "Search..." || searchCriteria == "ft." || searchCriteria == "in." || searchCriteria == "lbs." || searchCriteria == "Street Address, City or Zip Code") {
        $("#" + inputid).val("");
    }
    else {
        $("#" + inputid).val(searchCriteria);
    }
}

function sccgovInputBlur(inputid) {
    $("#" + inputid).css('color', '#B2B2B2');
    $("#" + inputid).css('font-style', 'italic');
    var searchCriteria = $("#" + inputid).val();
    if (searchCriteria == "" && inputid == "bmi_input_height_feet") {
        $("#" + inputid).val("ft.");
    }
    else if (searchCriteria == "" && inputid == "sccgov_controls_email_input") {
        $("#" + inputid).val("Enter your email...");
    }
    else if (searchCriteria == "" && inputid.indexOf("_search_input") != -1 && inputid.indexOf("classes_and_events_search_input") == -1) {
        $("#" + inputid).val("Search...");
    }
    else if (searchCriteria == "" && (inputid.indexOf("_input_dayphone") != -1 || inputid.indexOf("_phone") != -1)) {
        $("#" + inputid).val("(xxx) xxx-xxxx");
    }
    else if (searchCriteria == "" && inputid == "bmi_input_height_inches") {
        $("#" + inputid).val("in.");
    }
    else if (searchCriteria == "" && inputid == "bmi_input_weight_pounds") {
        $("#" + inputid).val("lbs.");
    }
}

function sccgovInputValidate(id, type, required) {
    if ($("#" + id).hasClass('sccgov_master_head_searchinput_container')) {
        return;
    }
    if (type == "zipcode") {
        if (required == true && $("#" + id).val() == "") {        
            $("#" + id).css("border", "1px dashed #ff0000");
        }
         else if (required == false && $("#" + id).val() == "") {
            $("#" + id).css("border", "1px solid #cccccc");
        }
        else {
            if (sccgovValidateZipCode($("#" + id).val()) == false) {
                $("#" + id).css("border", "1px dashed #ff0000");
            }
            else {
                $("#" + id).css("border", "1px solid #cccccc");
            }
        }
    }
    else if (type == "email") {
        if (required == true && $("#" + id).val() == "") {
            $("#" + id).css("border", "1px dashed #ff0000");
        }
        else if (required == false && $("#" + id).val() == "") {
            $("#" + id).css("border", "1px solid #cccccc");
        }
        else {
            if (sccgovValidateEmail($("#" + id).val()) == false) {
                $("#" + id).css("border", "1px dashed #ff0000");
            }
            else {
                $("#" + id).css("border", "1px solid #cccccc");
            }
        }
    }
    else if (type == "date") {
        if (required == true && $("#" + id).val() == "") {
            $("#" + id).css("border", "1px dashed #ff0000");
        }
        else if (required == false && $("#" + id).val() == "") {
            $("#" + id).css("border", "1px solid #cccccc");
        }
        else {
            if (sccgovValidateDate($("#" + id).val()) == false) {
                $("#" + id).css("border", "1px dashed #ff0000");
            }
            else {
                $("#" + id).css("border", "1px solid #cccccc");
            }
        }
    }
    else if (type == "vhpid") {
        if (required == true && $("#" + id).val() == "") {
            $("#" + id).css("border", "1px dashed #ff0000");
        }
        else if (required == false && $("#" + id).val() == "") {
            $("#" + id).css("border", "1px solid #cccccc");
        }
        else {
            if (sccgovValidateVHPId($("#" + id).val()) == false) {
                $("#" + id).css("border", "1px dashed #ff0000");
            }
            else {
                $("#" + id).css("border", "1px solid #cccccc");
            }
        }
    }
    else if (type == "npi") {
        if (required == true && $("#" + id).val() == "") {
            $("#" + id).css("border", "1px dashed #ff0000");
        }
        else if (required == false && $("#" + id).val() == "") {
            $("#" + id).css("border", "1px solid #cccccc");
        }
        else {
            if (sccgovValidateVHPNPI($("#" + id).val()) == false) {
                $("#" + id).css("border", "1px dashed #ff0000");
            }
            else {
                $("#" + id).css("border", "1px solid #cccccc");
            }
        }
    }
    else if (type == "phone") {
        if (required == true && $("#" + id).val() == "") {
            $("#" + id).css("border", "1px dashed #ff0000");
        }
        else if (required == false && $("#" + id).val() == "") {
            $("#" + id).css("border", "1px solid #cccccc");
        }
        else {
            if (sccgovValidatePhone($("#" + id).val()) == false) {
                $("#" + id).css("border", "1px dashed #ff0000");
            }
            else {
                $("#" + id).css("border", "1px solid #cccccc");
            }
        }
    }
    else if (type == "heightinches") {
        if (required == true && $("#" + id).val() == "") {
            $("#" + id).css("border", "1px dashed #ff0000");
        }
        else if (required == false && $("#" + id).val() == "") {
            $("#" + id).css("border", "1px solid #cccccc");
        }
        else {
            if (sccgovValidateHeightInches($("#" + id).val()) == false) {
                $("#" + id).css("border", "1px dashed #ff0000");
            }
            else {
                $("#" + id).css("border", "1px solid #cccccc");
            }
        }
    }
    else if (type == "heightfeet") {
        if (required == true && $("#" + id).val() == "") {
            $("#" + id).css("border", "1px dashed #ff0000");
        }
        else if (required == false && $("#" + id).val() == "") {
            $("#" + id).css("border", "1px solid #cccccc");
        }
        else {
            if (sccgovValidateHeightFeet($("#" + id).val()) == false) {
                $("#" + id).css("border", "1px dashed #ff0000");
            }
            else {
                $("#" + id).css("border", "1px solid #cccccc");
            }
        }
    }
    else if (type == "weightpounds") {
        if (required == true && $("#" + id).val() == "") {
            $("#" + id).css("border", "1px dashed #ff0000");
        }
        else if (required == false && $("#" + id).val() == "") {
            $("#" + id).css("border", "1px solid #cccccc");
        }
        else {
            if (sccgovValidateWeightPounds($("#" + id).val()) == false) {
                $("#" + id).css("border", "1px dashed #ff0000");
            }
            else {
                $("#" + id).css("border", "1px solid #cccccc");
            }
        }
    }
    else {
        if (required == true && $("#" + id).val() == "") {
            $("#" + id).css("border", "1px dashed #ff0000");
        }
        else if (required == false && $("#" + id).val() == "") {
            $("#" + id).css("border", "1px solid #cccccc");
        }
        else {
            $("#" + id).css("border", "1px solid #cccccc");
        }
    }
}

function changetextsize(up) {
    if (up == 0 && textsize > 12) {
        textsize = parseFloat(textsize) - 2;
    }
    else if (up == 1 && textsize < 18) {
        textsize = parseFloat(textsize) + 2;
    }
}
function fsize(size, unit, id) {
    var vfontsize = document.getElementById(id);
    if (vfontsize) {
        $('#' + id + ' *').css('font-size', size + unit);
        $('#' + id + ' *').children().css('font-size', size + unit);
        //vfontsize.style.fontSize = size + unit;
        createCookie("textsizestyle", textsize, 365);
    }
}
function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function sccgovShowRibbon()
{
    document.getElementById("s4-ribbonrow").style.display = "block";
}
