﻿
function image_swap(element, filename) {
    var img = ((typeof element).toLowerCase() == "object") ? element : document.getElementById(element);
    img.src = get_image_path(img.src) + filename;
}

//calendar function
function ToggleDatePicker(bCheckBox, sPickerId) {
    var oDiv1 = document.getElementById(sPickerId + "-Div1");
    var oDiv2 = document.getElementById(sPickerId + "-Div2");
    if (bCheckBox) {
        oDiv1.style.display = "none";
        oDiv2.style.display = "";
    }
    else {
        oDiv1.style.display = "";
        oDiv2.style.display = "none";
    }
}

function get_image_path(src) {
    return src.substring(0, (src.lastIndexOf("/") + 1));
}

function replaceButtonText(buttonId, text) {
    if (document.getElementById) {
        var button = document.getElementById(buttonId);
        if (button) {
            if (button.childNodes[0]) {
                button.childNodes[0].nodeValue = text;
            }
            else if (button.value) {
                button.value = text;
            }
            else //if (button.innerHTML)
            {
                button.innerHTML = text;
            }
        }
    }
}


var aAllDivs = new Array('rQueryAsAge', 'rMultiLine', 'rRows', 'rCols', 'rMaxLength', 'rCountryCode', 'rMin', 'rMax', 'rShowDropDown', 'rRepeatCols', 'rRepeatDir', 'rWidth', 'rListData', 'rPreMessage', 'rMidMessage', 'rPostMessage', 'rShowStreet', 'rShowCity', 'rShowState', 'rShowStateList', 'rShowPostCode', 'rShowCountry');


function SetDivState(oDiv, ValidatorState, Visibility, Display) {
    if (oDiv == null) {
        alert('null div');
        return;
    }
    var oValidator = document.getElementById(oDiv.id + 'Val');
    if (oValidator != null)
        ValidatorEnable(oValidator, ValidatorState);
    oValidator = document.getElementById(oDiv.id + 'Val1');
    if (oValidator != null)
        ValidatorEnable(oValidator, ValidatorState);

    oDiv.style.visibility = Visibility;
    oDiv.style.display = Display;

}

function ddlDataTypeChanged() {
    var oSettings = new Array();
    var sVal = document.getElementById(ddlDataTypeID).value;

    if (sVal == 'Text')
        oSettings = new Array(0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0);
    else if (sVal == 'Integer')
        oSettings = new Array(0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0);
    else if (sVal == 'Decimal')
        oSettings = new Array(0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0);
    else if (sVal == 'Currency')
        oSettings = new Array(0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0);
    else if (sVal == 'DateTime')
        oSettings = new Array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0);
    else if (sVal == 'Address')
        oSettings = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1);
    else if (sVal == 'SingleSelectionList')
        oSettings = new Array(0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    else if (sVal == 'MultipleSelectionList')
        oSettings = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    else if (sVal == 'HierarchicalList')
        oSettings = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    else if (sVal == 'IntegerList')
        oSettings = new Array(0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0);
    else if (sVal == 'DecimalList')
        oSettings = new Array(0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0);
    else if (sVal == 'CurrencyList')
        oSettings = new Array(0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0);
    else if (sVal == 'MonthYear')
        oSettings = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0);
    else
        oSettings = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

    if (oSettings.length != aAllDivs.length) {
        alert('length mismatch');
        return false;
    }
    var iMax = oSettings.length;

    for (var i = 0; i < iMax; i++) {
        //check the settings mode and then pass the right stuff to my show/hide function
        if (oSettings[i] == 0)//0=hide
        {
            SetDivState(document.getElementById(dvBoxId + '_' + aAllDivs[i]), false, 'hidden', 'none');
        }
        else if (oSettings[i] == 1)//1=show
        {
            SetDivState(document.getElementById(dvBoxId + '_' + aAllDivs[i]), true, 'visible', 'inline');
        }
    }



    return false; //for the postback

}

function widgetCallbackErrorHandler(sender, eventargs) {
    //do nothing"
}


function UncheckAllNotThis(sBaseId, nItems, oThis) {
    var sId = oThis.id;
    var sCheck;
    var nItem;
    for (nItem = 0; nItem < nItems; nItem++) {
        sCheck = sBaseId + '_' + nItem;
        if (sCheck != sId) {
            var oObject = document.getElementById(sCheck);
            if (oObject != null) {
                oObject.checked = false;
            }
        }
    }
}

function UncheckNoneNotThis(sBaseId, sItems, oThis) {
    var sId = oThis.id;
    var sCheck;
    var aItems;
    var nItem;
    var nItems;
    aItems = sItems.split(';');
    nItems = aItems.length
    for (nItem = 0; nItem < nItems; nItem++) {
        sCheck = sBaseId + '_' + aItems[nItem];
        if (sCheck != sId) {
            var oObject = document.getElementById(sCheck);
            if (oObject != null) {
                oObject.checked = false;
            }
        }
    }
}

function getElementsByAttribute(sTagName, sAttribute, sAttributeValue) {
    var aElements = (document.all) ? document.all : document.getElementsByTagName(sTagName);
    var nLength = aElements.length;
    var aReturn = new Array();
    for (var i = 0; i < nLength; i++) {
        var oElement = aElements[i];
        var oAttribute = oElement.getAttribute(sAttribute);
        if (typeof oAttribute == 'string' && oAttribute.length > 0) {
            if (oAttribute == sAttributeValue) {
                aReturn.push(oElement);
            }
        }
    }
    return aReturn;
}
