﻿var xmlHttp;

function GetXmlHttpObject() {
    var xmlHttp = null;
    try {// Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch (e) {
        try {// Internet Explorer
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }catch (e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function stateChanged() {
    if (xmlHttp.readyState == 4) {
    }
}

function canUseAjax() {
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Your browser does not support AJAX!");
        return false;
    }
    return true;
}

function makeAjaxCall(pageUrl, paramsStr) {
    var url = pageUrl + paramsStr;
    xmlHttp.onreadystatechange = stateChanged;
    xmlHttp.open("GET", url, false);
    xmlHttp.send(null);    
}

function changeStatus(id) {
    document.getElementById("txtCurrentReminderId").value = id;
    document.getElementById("statusCell" + id).style.display = "none";
    document.getElementById("waitCell" + id).style.display = "";
    document.getElementById("btnChangeStatusClicker").click();
}

function Delete(id) {
    if (confirm("Are you sure you want to delete this reminder? Click OK to confirm.")) {
        document.getElementById("txtCurrentReminderId").value = id;
        document.getElementById("btnDeleteClicker").click();
    }
}

function isValidInteger(str) {
    return (Trim(str) != "" && !isNaN(Trim(str)));
}

function ValidateAddMessagesClick(txtAddMessagesId, txtAutoAddMsgsId) {
    if (!isValidInteger(document.getElementById(txtAddMessagesId).value) || document.getElementById(txtAddMessagesId).value<1) {
        ShowError(txtAddMessagesId, "Invalid messages number. Only numbers in range from 1 to 99999 are allowed.");
        return false;
    }
    return true;
}

function ShowError(ctlId, errorMsg) {
    document.getElementById(ctlId).focus();
    document.getElementById(ctlId).select();
    alert(errorMsg);
}
function goToWelcome() {
    window.location.pathname = window.location.pathname.toLowerCase().replace("managebillinginfo.aspx", "welcome.aspx");
}
