﻿//////////////////////////////////////////////////////////
//  General Functionallity
//////////////////////////////////////////////////////////

// Handles the load event of all pages.
function Load() {
}

// Handles the unload event of all pages.
function Unload() {
}

// Allows only an int value to be inserted into a TextBox.
function RestrictToInt(evt) {
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        status = "This field accepts numbers only."
        return false
    }
    status = ""
    return true
}

// Allows only an int value to be inserted and is automatically formatted to phone specification.
function RestrictToPhone(evt, ctl) {
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        status = "This field accepts numbers only."
        return false
    }
    else {
        if (ctl.value.length == 3 && ctl.value.substring(0,1) != '(') {
            if (ctl.value.indexOf('(') == -1) {
                ctl.value = "(" + ctl.value
            }
            if (ctl.value.indexOf(')') == -1) {
                ctl.value = ctl.value + ")"
            }
        }
        if (ctl.value.length == 4 && ctl.value.substring(3, 1) != ')') {
            ctl.value = ctl.value + ")"
        }
        if (ctl.value.length > 3) {
            if (ctl.value.indexOf('(') == -1)
                ctl.value = "(" + ctl.value
            if (ctl.value.indexOf(')') == -1)
                ctl.value = ctl.value.substring(0, 4) + ")" + ctl.value.substring(4, ctl.value.length)
        }
        if (ctl.value.length > 7 && ctl.value.indexOf('-') == -1) {
            ctl.value = ctl.value.substring(0, 8) + "-" + ctl.value.substring(8, ctl.value.length)
        }
        status = ""
        return true
    }
}


///////////////////////////////////////////////////////////
//  Cookie / Client-Side Data Storage.
///////////////////////////////////////////////////////////

// Retrievs a cookie value.
function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

// Saves a cookie value.
function setCookie(c_name, value, expiredays) {
    exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    
    document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
}

////////////////////////////////////////////////////////////
// General Functions.
////////////////////////////////////////////////////////////
