﻿
/*** Changing background images ***/
var CenterContentContainerClass = '';
function CenterContainerMouseOver(container) {
    container.className = CenterContentContainerClass; 
}
function SetCenterContainerClass(className) {
    var CenterContentContainer = document.getElementById('CenterContentContainer');
    CenterContentContainer.className = className;
}

/*** *** ***/
// this snippet of code is to add the click event handler to the controls on the page
//if (navigator.userAgent.indexOf("Firefox") != -1) {
//    HTMLElement.prototype.click = function() {
//        var evt = this.ownerDocument.createEvent('MouseEvents');
//        evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
//        this.dispatchEvent(evt);
//    }
//}

// check for date mask
// either dd/MM/yyyy or MM/yyyy
String.prototype.isDate = function() {
    var pattern1 = /^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$/;
    var pattern2 = /^(((0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|(02\/((19|[2-9]\d)\d{2}))|(02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$/;
    return this.match(pattern1) || this.match(pattern2);
}

function IsBrowserIE4Plus() {
    var browser = navigator.appName;
    var b_version = navigator.appVersion;
    var version = parseFloat(b_version);
    return ((browser == "Microsoft Internet Explorer") && (version >= 4));
}

// set the page focus to the given object id
function SetPageFocus(id) {
    var obj = document.getElementById(id);
    if (obj)
        obj.focus();
    else
        window.status = 'no item: ' + id;
}

// check whether the string has a value
String.prototype.hasValue = function() {
    return (this.trim().length > 0);
}

// check whether the string has a value
String.prototype.hasValidationValue = function() {
    var txt = document.getElementById(this);

    // if object exist return whether it has a value
    return (txt ? txt.value.hasValue() : true);
}

// return a response object for a given textbox id
String.prototype.validateTextbox = function() {
    var txt = document.getElementById(this);

    var response = new ValidatorResult();
    response.id = this;
    response.value = (txt ? txt.value : '');
    response.hasValue = (txt ? txt.value.hasValue() : true);

    return response;
}

// Validator response object
function ValidatorResult() {
    this.id;
    this.value;
    this.hasValue;
}

// check whether a dropdownlist option has been selected - assuming that index 0 is not a valid option
// var options = '<%=ddlObject.ClientID %>';
// var bool = options.isRadioSelected();
String.prototype.isDropDownListSelected = function() {
    var ddl = document.getElementById(this);
    if (ddl) {
        return ddl.selectedIndex > 0;
    }
    return false;
}

// check whether a dropdownlist option has been selected - assuming that index 0 is not a valid option
// var options = '<%=ddlObject.ClientID %>';
// var bool = options.isDropDownListSelected();
String.prototype.dropDownListSelectedText = function() {
    var ddl = document.getElementById(this);
    if (ddl) {
        return ddl[ddl.selectedIndex].text;
    }
    return '';
}

// check whether a dropdownlist option has been selected - assuming that index 0 is not a valid option
// var options = '<%=ddlObject.ClientID %>';
// var bool = options.isDropDownListSelected();
String.prototype.dropDownListSelectedValue = function() {
    var ddl = document.getElementById(this);
    if (ddl) {
        return ddl[ddl.selectedIndex].value;
    }
    return '';
}

// check whether a checkboxlist option has been selected 
// var options = '<%=cblObject.ClientID %>';
// var bool = options.isCheckBoxListSelected();
String.prototype.isCheckBoxListSelected = function() {
    var options = document.getElementById(this).getElementsByTagName('input');
    for (i = 0; i < options.length; i++) {
        var opt = options[i];
        if (opt.type == "checkbox") {
            if (opt.checked) {
                return true;
            }
        }
    }
    return false;
}

// check whether a checkboxlist option has been selected 
// var options = '<%=cblObject.ClientID %>';
// var bool = options.isCheckBoxListSelected();
String.prototype.SelectedValue = function() {
    var options = document.getElementById(this).getElementsByTagName('input');
    for (i = 0; i < options.length; i++) {
        var opt = options[i];
        if (opt.type == "checkbox") {
            if (opt.checked) {
                return opt.value;
            }
        }
        else if (opt.type == "radio") {
            if (opt.checked) {
                return opt.value;
            }
        }
        
    }
    return false;
}

// check for valid email
String.prototype.isValidEmail = function() {
    var pattern1 = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
    return this.match(pattern1);
}


