﻿// JavaScript Document

var hour, minute, seconds, milliseconds, weekday, day, month, yy, year, startTime, popup, field;

date = new Date();
hour = date.getHours();
minute = date.getMinutes();
seconds = date.getSeconds();
milliseconds = date.getMilliseconds();
weekday = date.getDay() + 1;
day = date.getDate();
month = date.getMonth() + 1;
yy = date.getYear();
year = (yy < 1000) ? yy + 1900 : yy;
startTime = date.getTime();

function makeArray() {
    for (i = 0; i < makeArray.arguments.length; i++)
        this[i + 1] = makeArray.arguments[i];
}

function showDay(intDayOfWeek, intMonth, intYear, intEarliest) {
    // intEarliest is the earliest day on which the holiday can occur.
    // for example, if November 1st is a Thursday, then Thanksgiving
    // is on the 22nd (the 4th Thursday), which is the earliest it 
    // can occur. It can occur as late as the 28th.
    // intDayOFWeek is the numeric day of the week. eg Thanksgiving
    // is on a Thursday which is the 5th day of the week.
    for (i = intEarliest; i <= intEarliest + 6; i++) {
        dtDate = new Date(intMonth + '/' + i + '/' + intYear)
        if (dtDate.getDay() + 1 == intDayOfWeek) {
            document.write(weekdays[dtDate.getDay() + 1] + ", " + months[intMonth] + " " + i + ", " + intYear);
        }
    }
}

// showDate available formats.....
//		"mm/dd/yyyy"
//		"dd/mm/yyyy"
//		"dddd, mm dd, yyyy"
//		"dddd, mm dd, yyyy hh:ss"

function showDate(format) {
    switch (format) {
        case "mm/dd/yyyy": document.write(month + "/" + day + "/" + year); break;
        case "dd/mm/yyyy": document.write(day + "/" + month + "/" + year); break;
        case "dddd, mm dd, yyyy": document.write(weekdays[weekday] + ", " + months[month] + " " + day + ", " + year); break;
        case "dddd, dd mm, yyyy": document.write(weekdays[weekday] + ", " + day + " " + months[month] + ", " + year); break;
        case "dddd, mm dd, yyyy hh:ss": document.write(weekdays[weekday] + ", " + months[month] + " " + day + ", " + year + " " + time); break;
        default: document.write(month + "/" + day + "/" + year); break;
    }

}


// JavaScript to get around Internet Explorer's CSS limitations with the :hover command.

sfHover = function() {
    var sfEls = document.getElementById("navcontainer").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);

function escapeSearchterm(searchInputID, userInputID) {
    var searchInput = document.getElementById(searchInputID);
    var userInput = document.getElementById(userInputID);

    if (searchInput != null) {
        if (userInput != null) {
            searchInput.value = userInput.value.replace(/ /g, "+");
        }
    }
}

function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}
function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}
function MM_jumpMenu(targ, selObj, restore) { //v3.0
    eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value + "'");
    if (restore) selObj.selectedIndex = 0;
}
function MM_showHideLayers() { //v6.0
    var i, p, v, obj, args = MM_showHideLayers.arguments;
    for (i = 0; i < (args.length - 2); i += 3) if ((obj = MM_findObj(args[i])) != null) {
        v = args[i + 2];
        if (obj.style) { obj = obj.style; v = (v == 'show') ? 'visible' : (v == 'hide') ? 'hidden' : v; }
        obj.visibility = v;
    }
}
function pviiClassNew2(obj, new_style, new_style2) { //v2.7 by PVII
    if (document.getElementById(obj).className == new_style)
        document.getElementById(obj).className = new_style2;
    else
        document.getElementById(obj).className = new_style;
}

function GetBlurCodeByID(main_control_id, error_control) {
    return GetBlurCode(document.getElementById(main_control_id), error_control);
}

function GetBlurCode(main_control, error_control) {
    main_control.style.border = "1px solid #929292";
    if (main_control.value == "") {
        document.getElementById(error_control).style.display = "block";
        return false;
    } else {
        document.getElementById(error_control).style.display = "none";
        return true;
    }
}

function SetVisibility(control_id, value) {
    document.getElementById(control_id).style.display = value ? 'block' : 'none';
}

function IsValidEmailAddressByID(control_id, error_id) {
    return IsValidEmailAddress(document.getElementById(control_id), error_id);
}

function IsValidEmailAddress(control, error_id) {
    var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    str = control.value;

    if (str.match(emailRegEx)) {
        //valid e-mail address
        document.getElementById(error_id).style.display = 'none';
        return true;
    } else {
        //invalid e-mail address
        document.getElementById(error_id).style.display = 'block';
        return false;
    }
}

function IsValidPhoneByID(control_id) {
    return IsValidPhone(document.getElementById(control_id));
}

function IsValidPhone(control) {
    if (control.value == "") return false;
    //get characters
    //check that all characters are digits, ., -, or ""
    for (var i = 0; i < control.value.length; ++i) {
        var new_key = control.value.charAt(i);
        if (((new_key < "0") || (new_key > "9")) &&
                    !(new_key == "")) {
            return false;
        }
    }
    return true;
}

function ValidatePage(controls, msg_mail, msg_mail_error, msg_phone, msg_phone_error) {
    var valid = true;

    for (var i = 0; i < controls.length; i += 2) {
        valid &= GetBlurCodeByID(controls[i], controls[i + 1]);
    }

    if (msg_mail != '' && !IsValidEmailAddressByID(msg_mail, msg_mail_error)) {
        SetVisibility(msg_mail_error, true);
        valid &= false;
    }
    if (msg_phone != '' && !IsValidPhoneByID(msg_phone)) {
        SetVisibility(msg_phone_error, true);
        valid &= false;
    }
    return Boolean(valid);
}

function ValidateFile(file_id, error_id) {

    var ret = false;
    var ext = document.getElementById(file_id).value;
    ext = ext.substring(ext.length - 3, ext.length);
    ext = ext.toLowerCase();
    if (ext == 'doc')
        ret = true;
    else if (ext == 'pdf')
        ret = true;
    else if (ext == 'txt')
        ret = true;

    if (!ret)
        document.getElementById(error_id).style.display = 'block';

    return ret;
}
