﻿// general functions for Forms

//function for show messages
function ShowMessage(pMessage) 
{
    alert(pMessage);
}

//function for diable button on submit
function disableSubmit(pValidationGroup, pButton, pPostBack) {
    //validate form
    Page_ClientValidate(pValidationGroup);
    //if true disable button and send submit
    if (Page_IsValid) {
        disableButton(pButton);
        eval(pPostBack);
        enableButton(pButton);
    }
    return Page_IsValid;
}
//function for disable button
function disableButton(pButton) {
   
    //validate page
    var vButton = document.getElementById(pButton);
    vButton.disabled = true;
}
//function for disable button
function enableButton(pButton) {

    //validate page
    var vButton = document.getElementById(pButton);
    vButton.disabled = false;
}

//JQUERY

//UPDATE COMBOS

//function for change combos on demand
function updCombo(pComboDestiny, pValue, pType) {
    
    //disable combo destiny
    $(pComboDestiny).attr('disabled', true);
    var defaultRole = $(pComboDestiny).val();
    //check value not equal to -1
    if (pValue == '-1')
        return;
    //set combo destiny by ajax callback
    $.ajax({
        type: "POST",
        dataType: ($.browser.msie) ? "text" : "html",
        url: "/App_Modules/Ajax/ghLoadCombo.ashx",
        data: "type=" + pType + "&value=" + pValue + "&default=" + defaultRole,
        success: function(html) {
            $(pComboDestiny).html(html);
        },
        error: function(html) {
            alert("El proceso ha fallado!");
        }
    });
    //enable combo destiny
    $(pComboDestiny).attr('disabled', false);
}
