﻿/*--------------- Function to ensure the only numeric value ----------------------*/
function CheckNumeric(e) {
    key = (window.event) ? e.keyCode : e.which;
    if (key >= 48 && key <= 57) {
    }
    else {
        RemoveCharKeyValue(e);
    }
}

/*--------------- Function used to remove the character and special characters event ----------------------*/
function RemoveCharKeyValue(e) {
    /*find the key value of the key that is pressed*/
    key = (window.event) ? e.keyCode : e.which;
    /*check whether the key is pressed with the shift key */
    if (e.shiftKey && ((key >= 58 && key <= 126) || (key >= 33 && key <= 47))) {
        RestoreEvent(e);
    }
    /*if the normal keys are pressed*/
    if ((key >= 58 && key <= 126) || (key >= 42 && key <= 47) || key == 39 || key == 32) {
        RestoreEvent(e);
    }
}

/*--------------- Function to null the current event generated ----------------------*/
function RestoreEvent(e) {
    if (navigator.appName == "Microsoft Internet Explorer")
        e.returnValue = null;
    else
        e.preventDefault();
}


function SendJsonCallToFillCombo(comboBoxClientId, url, itemValue, rawdata, defaultItem) {

    //    var item = eventArgs.get_item();

    var comboBox = $find(comboBoxClientId);

    comboBox.get_items().clear();
    if (itemValue == "" || itemValue == "0") {
        if (defaultItem != null) {
            comboBox.get_items().add(defaultItem);
            defaultItem.select();
        }
        comboBox.disable();
        return;
    }

    var data = '{' + String.format(rawdata, itemValue) + '}';

    $.ajax({
        url: url,
        data: data,
        type: "POST",
        processData: true,
        contentType: "application/json",
        timeout: 10000,
        dataType: "json",
        success: function(response) {

            var data = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;

            comboBox.get_items().clear();
            comboBox.enable();

            if (data.length >= 0 && defaultItem != null) {
                comboBox.get_items().add(defaultItem);
                defaultItem.select();
            }

            for (var i = 0; i < data.length; i++) {
                var comboBoxItem = new Telerik.Web.UI.RadComboBoxItem();
                comboBoxItem.set_text(data[i].Value);
                comboBoxItem.set_value(data[i].Key);
                comboBox.get_items().add(comboBoxItem);
            }
            comboBox.commitChanges();

            comboBox.findItemByText("Please Select One").select();
            //comboBox.FindItemByValue("0").select();

        },
        error: function(ex) {
        }
    });
}
function PopupWindow(url, Width, Height, Title) {
    OpenRadWindow(url, Width, Height, Title);
    return false;
}
function OpenRadWindow(url, Width, Height, Title) {
    var oWindow = window.radopen(url, "RadWindow1");
    oWindow.setSize(Width, Height);
    oWindow.center();
    oWindow.set_title("<b>" + Title + "</b>");
}

function SendJsonCall(url, rawdata, onSuccess, onFalilure) {
    $.ajax(
		    {
		        type: 'POST',
		        url: url,
		        data: rawdata,
		        processData: true,
		        contentType: "application/json",
		        timeout: 10000,
		        dataType: "json",
		        success: onSuccess,
		        error: onFalilure
		    });
}

function SetCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function GetCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

