﻿var dis = "disabled";
var commonServicePath = "../Services/CommonServices.asmx/";
function numericOnly(e) { if (e.value.match(/[\D]/) != null) e.value = e.value.replace(/[\D]/g, ''); }

function numAndLetter() {
    var result = false;
    if (numericOnly() || letterOnly()) result = true;
    return result;
}
function letterOnly() {
    if ((event.keyCode < 65 && event.keyCode < 97) || (event.keyCode > 90 && event.keyCode > 122) || (event.keyCode > 90 && event.keyCode < 97))
        return false;
    else
        return true;
}
function showProgress() { $("#progress").show(); }

function hiddenProgress() { $("#progress").hide(); }

function ValidateCtrlByGroup(psValidationGroupName) {
    var bResult = true;
    for (i = 0; i < Page_Validators.length; i++) {
        ctrlValidator = Page_Validators[i];
        if (psValidationGroupName == ctrlValidator.validationGroup) {
            ValidatorEnable(ctrlValidator);
            if (!ctrlValidator.isvalid)
                bResult = false;
        }
    }
    return bResult;
}
function openBrWindow(theURL, winName, w, h, features) {
    wleft = (screen.width - w) / 2;
    wtop = (screen.height - h) / 2;
    if (wleft < 0) {
        w = screen.width;
        wleft = 0;
    }
    if (wtop < 0) {
        h = screen.height;
        wtop = 0;
    }
    var win = window.open(theURL, winName, 'width=' + w + ', height=' + h + ',left=' + wleft + ', top=' + wtop + ',' + features);
    win.focus();
 }

function getNewItem() { return { Index: 0, Row: null }; }
var selItem = getNewItem();
function selectRow(row, index) {
    if (selItem.Row != null && selItem.Index != index) $(selItem.Row).removeClass("selectedRow");
    $(row).addClass("selectedRow");
    selItem.Row = row; selItem.Index = index;
}
function clearSelected() {
    $(selItem.Row).removeClass("selectedRow");
    selItem = { Index: 0, Row: null };
}

function ApplyTemplate(containerID, templateID, data) {
    $("#" + containerID).setTemplate($("#" + templateID).html());
    $("#" + containerID).processTemplate(data);
    hiddenProgress();
}

function callAjax(fullMethodName, params, onSuccess, onFail) {
    var args = "{";
    if (params.length > 0) {
        for (var i = 0; i < params.length - 1; i += 2) {
            if (i != 0) args += ",";
            args += "'" + params[i] + "':'" + params[i + 1] + "'";
        }
    }
    args += "}";
    $.ajax({
        type: "POST",
        url: fullMethodName,
        data: args,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: onSuccess,
        error: onFail
    });
}
function onError(xhr, status, error) {
    alert("Error on getting data."); hiddenProgress();
}
function erorrMsg(msg) { hiddenProgress(); alert(msg); }
function formatDate(dt) {
    dt.setHours(dt.getHours() + ((dt.getTimezoneOffset() / 60) * (-1)));
    return dt.localeFormat("MM/dd/yyyy hh:mm tt");
}

function hideModal(id) {
    $find(id).hide();
    $(document.body).css("overflow", "auto");
    
}
function showModal(id) {
    $(document.body).css("overflow", "hidden");
    $find(id).show();
}
function setHoverEffect(group, hover, pressed) {
    $("." + group).hover(function() { $(this).addClass(hover); }, function() { $(this).removeClass(hover).removeClass(pressed); });
    $("." + group).mousedown(function() { $(this).addClass(pressed); });
    $("." + group).mouseup(function() { $(this).removeClass(pressed); });
}
function resetButton(jqObj, hover, pressed) { jqObj.removeClass(hover).removeClass(pressed); }

