function DialogCallback(dialogResult, returnValue) {
    if (dialogResult == SP.UI.DialogResult.OK) {
        SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
        this
    }
    else {
        if (returnValue != null && returnValue.Message != undefined) {
            SP.UI.Notify.addNotification(returnValue.Message, false);
        }
    }

}

function OpenDialog(title, url, width, height) {
    var options = {
        title: title,
        url: url,
        width: width,
        height: height,
        allowMaximize: false,
        dialogReturnValueCallback: DialogCallback
    };
    SP.UI.ModalDialog.showModalDialog(options);
}

function DoPostbackOnEnterKey(e, postbackId) {
    if (!e) var e = window.event;
    if (e.keyCode) code = e.keyCode;
    else if (e.which) code = e.which;
    if (parseInt(code) == 13) {
        __doPostBack(postbackId, '');
        return false;
    }
}

function RedirectOnClick(url, txtBoxId) {
    if (document.getElementById(txtBoxId).value.length > 0 && document.getElementById(txtBoxId).value != "Search...") {
        window.location = url + encodeURIComponent(document.getElementById(txtBoxId).value);
    }
}

function RedirectOnEnterKey(e, url, txtBoxId) {
    if (!e) var e = window.event;
    if (e.keyCode) code = e.keyCode;
    else if (e.which) code = e.which;
    if (parseInt(code) == 13 && document.getElementById(txtBoxId).value.length > 0) {
        if (e.stopPropagation) {
            e.stopPropagation();
            e.preventDefault();
        } else {
            e.cancelBubble = true;
            e.returnValue = false;
        }
        window.location = url + encodeURIComponent(document.getElementById(txtBoxId).value);
    }
}

function OpenPeoplePickerDialog(title, url, width, height, call) {
    var options = {
        title: title,
        url: url,
        width: width,
        height: height,
        dialogReturnValueCallback: call
    };
    SP.UI.ModalDialog.showModalDialog(options);
}

function ClosePeoplePickerCallBack(result, value) {
    if ((result != null) && (result != "")) {
        textbox = document.getElementById(result);
        textbox.value = value;
    }
    else {
        /*alert("not ok " + value);*/
    }
}

