﻿function GetBaseUrl() {
    return $("#BaseUrlHiddenField").val();
}

function StripResponse(response) {
    response = response.substring(response.indexOf('<div id="JQueryPage"'));
    response = response.replace('</form>', '');
    response = response.replace('</body>', '');
    response = response.replace('</html>', '');
    return response;
}

function AddItemToDropDownList(dropDownList, itemValue, itemText) {
    var optn = document.createElement("OPTION");
    optn.text = itemText;
    optn.value = itemValue;
    dropDownList.options.add(optn);
}

function DisableEmptyDropDownLists(dropDownList) {
    if (dropDownList != null) {
        if (dropDownList.options.length <= 1) {
            dropDownList.disabled = true;
        }
    }
}

function DisableDropDownList(dropDownList) {
    dropDownList.disabled = true;
    dropDownList.selectedIndex = 0;
}

function EnableDropDownList(dropDownList) {
    if (dropDownList.options.length > 1) {
        dropDownList.disabled = false;
    }
    else {
        dropDownList.disabled = true;
    }
}

function GetSelectedvalueFromDropDownList(dropDownList) {
    var returnValue = dropDownList.options[dropDownList.selectedIndex].value;
    return returnValue;
}

function ClearDropDownList(dropDownList) {
    if (dropDownList != null) {
        dropDownList.options.length = 0;
        DisableEmptyDropDownLists(dropDownList);
    }
}

function ClearDropDownList(dropDownList) {
    if (dropDownList != null) {
        dropDownList.options.length = 0;
        DisableEmptyDropDownLists(dropDownList);
    }
}

function EnableDropDownList(dropDownList) {
    if (dropDownList.options.length > 1) {
        dropDownList.disabled = false;
    }
    else {
        dropDownList.disabled = true;
    }
}

function GetSelectedValueFromRadioButtonList(radioButtonListId) {
    var returnValue = "-1";

    var radioButtons = document.getElementsByName(radioButtonListId);
    for (var x = 0; x < radioButtons.length; x++) {
        if (radioButtons[x].checked) {
            returnValue = radioButtons[x].value;
        }
    }

    return returnValue;
}

function AutoCompleteTextBox(textBoxControlId, autocompleteValues) {
    var dataArray = autocompleteValues.split("||");
    $("#" + textBoxControlId).flushCache();
    $("#" + textBoxControlId).autocomplete(dataArray, {
        matchContains: true,
        minChars: 0,
        scroll: true,
        width: 250,
        scrollHeight: 300
    });
}

function IsNumeric(sText) {
    var ValidChars = "0123456789.";
    var IsNumber = true;
    var Char;

    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }

    return IsNumber;
}
