﻿function formatPhone(obj, evt) {
    IE = document.all;

    if (IE) {
        var keycode = window.event.keyCode;
        var shift = window.event.shiftKey;
        var ctrl = window.event.ctrlKey;
        var alt = window.event.altKey;
        if (keycode == 13) return true;
        var tmpStr = obj.value;
        var pos = tmpStr.length + 1;
        var lparen = (shift && !ctrl && !alt && keycode == 40);
        var rparen = (shift && !ctrl && !alt && keycode == 41);
        var space = (!shift && !ctrl && !alt && keycode == 32);
        var dash = (!shift && !ctrl && !alt && keycode == 45);
        var slash = (!shift && !ctrl && !alt && keycode == 47);
        var digit = (!shift && !ctrl && !alt && keycode >= 48 && keycode <= 57);

        if (!digit) { window.event.keyCode = 0; return false; }
        if (pos == 1 && digit) { obj.value = '(' + obj.value; return true; }
        if (pos == 2 && digit) return true;
        if (pos == 3 && digit) return true;
        if (pos == 4 && digit) return true;
        if (pos == 5 && digit) { obj.value += ') '; return true; }
        if (pos == 7 && digit) return true;
        if (pos == 8 && digit) return true;
        if (pos == 9 && digit) return true;
        if (pos == 10 && digit) { obj.value += '-'; return true; }
        if (pos == 11 && digit) return true;
        if (pos == 12 && digit) return true;
        if (pos == 13 && digit) return true;
        if (pos == 14 && digit) return true;
        if (pos >= 15) { window.event.keyCode = 0; return false; }
    }
    else {
        keycode = evt.which;
        var bs = String.fromCharCode(evt.which);
        if (keycode >= 48 && keycode <= 57) return true;
        if (keycode == 0) return true;
        if ((keycode == 32) || (keycode >= 40 && keycode <= 41) || (keycode >= 45 && keycode <= 46)) return true;
        if (bs == "\b") return true;
        //if (keycode == 13) checkForm();
        return false;
    }
    return false;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function formatSSN(obj, evt) {
    IE = document.all;

    if (IE) {
        var keycode = window.event.keyCode;
        var shift = window.event.shiftKey;
        var ctrl = window.event.ctrlKey;
        var alt = window.event.altKey;
        if (keycode == 13) return true;
        var tmpStr = obj.value;
        var pos = tmpStr.length + 1;
        var lparen = (shift && !ctrl && !alt && keycode == 40);
        var rparen = (shift && !ctrl && !alt && keycode == 41);
        var space = (!shift && !ctrl && !alt && keycode == 32);
        var dash = (!shift && !ctrl && !alt && keycode == 45);
        var slash = (!shift && !ctrl && !alt && keycode == 47);
        var digit = (!shift && !ctrl && !alt && keycode >= 48 && keycode <= 57);

        if (!digit) { window.event.keyCode = 0; return false; }
        if (pos == 1 && digit) return true;
        if (pos == 2 && digit) return true;
        if (pos == 3 && digit) return true;
        if (pos == 4 && digit) { obj.value += '-'; return true; }
        if (pos == 5 && digit) return true;
        if (pos == 6 && digit) return true;
        if (pos == 7 && digit) { obj.value += '-'; return true; }
        if (pos == 8 && digit) return true;
        if (pos == 9 && digit) return true;
        if (pos == 10 && digit) return true;
        if (pos == 11 && digit) return true;
        if (pos >= 12) { window.event.keyCode = 0; return false; }
    }
    else {
        keycode = evt.which;
        var bs = String.fromCharCode(evt.which);
        if (keycode >= 48 && keycode <= 57) return true;
        if (keycode == 0) return true;
        if ((keycode == 32) || (keycode >= 40 && keycode <= 41) || (keycode >= 45 && keycode <= 46)) return true;
        if (bs == "\b") return true;
        //if (keycode == 13) checkForm();
        return false;
    }
    return false;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function isNumber(evt) {
    IE = document.all;
    if (IE) {
        var keycode = window.event.keyCode;
        if ((keycode >= 48 && keycode <= 57) || (keycode == 13) || (keycode == 46)) {
            return true;
        }
        else {
            window.event.keyCode = 0;
            return false;
        }
    }
    else {
        keycode = evt.which;
        var bs = String.fromCharCode(evt.which);
        if ((keycode >= 48 && keycode <= 57) || (keycode == 13) || (keycode == 46)) {
            return true;
        }
        else {
            evt.which = 0;
            return false;
        }
    }
    //return false;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
function autotab(original, destination, previous, evt) {
    if (typeof evt == 'undefined') {
    evt = window.event;
    }
    if (evt) {
        var keyCode = evt.keyCode ? evt.keyCode : evt.charCode;

        if (keyCode == 8) {
            if (original.value.length == 0) {
                previous.focus();
                previous.value = previous.value;
            }
        }
        else if (keyCode == 46) {
            
        }
        else if (original.getAttribute && original.value.length == original.getAttribute("maxlength")) {
            destination.focus();
        }
    }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
function isLetter(evt) //Add parameters for chars such as (space, dash)
{
    IE = document.all;
    if (IE) {
        var keycode = window.event.keyCode;
        if ((keycode >= 65 && keycode <= 90) || (keycode >= 97 && keycode <= 122) || keycode == 13) {
            return true;
        }
        else {
            window.event.keyCode = 0;
            return false;
        }
    }
    else {
        keycode = evt.which;
        var bs = String.fromCharCode(evt.which);
        if ((keycode >= 65 && keycode <= 90) || (keycode >= 97 && keycode <= 122) || keycode == 13) {
            return true;
        }
        else {
            evt.which = 0;
            return false;
        }
    }
    //return false;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
function isValidEmail(str) {
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);

}
///////////////////////////////////////////////////////////////////////////////////////////////////////
function openSite(page) {
    window.open(page)
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
