// JScript File
function CB_Checked(CB_Id, TxBx_Id) {
    var TxBx = document.getElementById(TxBx_Id);
    var CB = document.getElementById(CB_Id);
    if (CB.checked == true) {
        //alert(CB);
        TxBx.disabled = true;
        $(TxBx).addClass('disabled');
        TxBx.value = '';
    }
    else {
        TxBx.disabled = false;
        $(TxBx).removeClass('disabled');
        TxBx.focus();
        TxBx.select();
    }
}

function CB_Checked2(CB_Id, TxBx_Id, CB_Unlimited) {
    var TxBx = document.getElementById(TxBx_Id);
    var CB = document.getElementById(CB_Id);
    var CB2 = document.getElementById(CB_Unlimited);
    if (CB.checked == true) {
        //alert(CB2);
        //TxBx.disabled=true;
        //TxBx.value='';        
        CB2.checked = true;
        CB2.disabled = false;
        //$(TxBx).addClass('disabled');
    }
    else {
        TxBx.disabled = true;
        $(TxBx).addClass('disabled');
        TxBx.value = '';
        CB2.checked = false;
        CB2.disabled = true;
    }
}


function DDL_ProductTypesChange(Id) {
    var DDL_ProductTypes = document.getElementById(Id);
    var array = Id.split('DDL_ProductTypes');
    var TR_ServerGroup = document.getElementById(array[0] + 'TR_ServerGroup');
    var TR_CP = document.getElementById(array[0] + 'TR_CP');
    var LBX_SharedServerGroups = document.getElementById(array[0] + 'LBX_SharedServerGroups');
    var LBX_ResellerServerGroups = document.getElementById(array[0] + 'LBX_ResellerServerGroups');
    if ((DDL_ProductTypes.options[DDL_ProductTypes.selectedIndex].value == '1') || (DDL_ProductTypes.options[DDL_ProductTypes.selectedIndex].value == '2')) {
        TR_ServerGroup.style.display = '';
        TR_CP.style.display = '';
        if (DDL_ProductTypes.options[DDL_ProductTypes.selectedIndex].value == '1') {
            LBX_SharedServerGroups.style.display = '';
            LBX_ResellerServerGroups.style.display = 'none';
        }
        else {
            LBX_SharedServerGroups.style.display = 'none';
            LBX_ResellerServerGroups.style.display = '';
        }
    }
    else {
        TR_ServerGroup.style.display = 'none';
        TR_CP.style.display = 'none';
    }

    var DDL_AssociateDomain = document.getElementById(array[0] + 'DDL_AssociateDomain');
    DDL_AssociateDomain.disabled = false;
    if (DDL_ProductTypes.options[DDL_ProductTypes.selectedIndex].value == '1') {
        setTimeout(function () { DDL_AssociateDomain.selectedIndex = 1; $(DDL_AssociateDomain).trigger('change'); }, 500);


        DDL_AssociateDomain.disabled = true;
    }
    else if (DDL_ProductTypes.options[DDL_ProductTypes.selectedIndex].value == '2') {
        setTimeout(function () { DDL_AssociateDomain.selectedIndex = 0; $(DDL_AssociateDomain).trigger('change'); }, 500);

    }
    else if (DDL_ProductTypes.options[DDL_ProductTypes.selectedIndex].value == '5') {
        setTimeout(function () { DDL_AssociateDomain.selectedIndex = 0; $(DDL_AssociateDomain).trigger('change'); }, 500);

    }
    else if (DDL_ProductTypes.options[DDL_ProductTypes.selectedIndex].value == '8') {
        setTimeout(function () { DDL_AssociateDomain.selectedIndex = 1; $(DDL_AssociateDomain).trigger('change'); }, 500);

        DDL_AssociateDomain.disabled = true;
    }
    else {
        setTimeout(function () { DDL_AssociateDomain.selectedIndex = 0; $(DDL_AssociateDomain).trigger('change'); }, 500);

    }
}

function CB_Checked3(CB_Id, TxBx_ChildId, TxBx_ParentId) {
    var TxBx = document.getElementById(TxBx_ChildId);
    var TxBxParent = document.getElementById(TxBx_ParentId);
    var CB = document.getElementById(CB_Id);

    if (CB.checked == true) {
        //alert(CB);
        TxBx.disabled = true;
        $(TxBx).addClass('disabled');
        TxBx.value = '';
    }
    else {
        var DomainData = 0;
        var SubDomain = $("input[id$=TxBx_MSDomains]").val();
        if (SubDomain == null || SubDomain == NaN || SubDomain == '')
            SubDomain = 0;
        if (SubDomain == undefined)
            SubDomain = 0;
        if (TxBxParent.value == null || TxBxParent.value == NaN || TxBxParent.value == '')
            DomainData = 0;
        else
            DomainData = TxBxParent.value;

        TxBx.value = parseInt(DomainData) + parseInt(SubDomain);
        if (TxBx.value == '' || TxBx == undefined || TxBx.value == null || TxBx.value == NaN)
            TxBx.value = '0';
        TxBx.disabled = false;
        $(TxBx).removeClass('disabled');
    }
}

function setChildResourceEqualOrGreater(PTB, PCB, CTB, CCB, SDT, SDC, IsAlwaysGreaterOrEqual, IsAddOn) {
    var ParentTXT = document.getElementById(PTB);
    var ParentCHBX = document.getElementById(PCB);
    var ChildTXT = document.getElementById(CTB);
    var ChildCHBX = document.getElementById(CCB);
    var SubDomain = document.getElementById(SDT);
    var SubDomainCB = document.getElementById(SDC);

    if ((ParentCHBX.checked == true) || (SubDomainCB.checked == true)) {
        if (SubDomainCB.checked == true) {
            SubDomain.value = '';
            SubDomain.disabled = true;
            $(SubDomain).addClass('disabled');
        }
        else {
            if (SubDomain.value == '')
                SubDomain.value = '0';
            SubDomain.disabled = false;
            $(SubDomain).removeClass('disabled');
        }

        if (ParentCHBX.checked == true) {
            ParentTXT.value = '';
            ParentTXT.disabled = true;
            $(ParentTXT).addClass('disabled');
        }
        else {
            if (ParentTXT.value == '' && IsAddOn == '1')
                ParentTXT.value = '0';
            if ((IsAddOn == '0') && (ParentTXT.value == '' || ParentTXT.value <= '0'))
                ParentTXT.value = '1';

            ParentTXT.disabled = false;
            $(ParentTXT).removeClass('disabled');
        }

        ChildTXT.disabled = true;
        $(ChildTXT).addClass('disabled');
        ChildCHBX.checked = true;
        ChildTXT.value = '';
    }
    else {
        var SubDomainData = 0;
        var DomainData = 0;

        if (SubDomainCB.checked == true) {
            SubDomainData = 0;
            SubDomain.value = '';
            SubDomain.disabled = true;
            $(SubDomain).addClass('disabled');
        }
        else {
            SubDomain.disabled = false;
            $(SubDomain).removeClass('disabled');
            if (SubDomain.value == '')
                SubDomain.value = '0';
            SubDomainData = parseInt(SubDomain.value);
        }

        if (ParentCHBX.checked == true) {
            DomainData = 0;
            ParentTXT.value = '';
            ParentTXT.disabled = true;
            $(ParentTXT).addClass('disabled');
        }
        else {

            if (ParentTXT.value == '' && IsAddOn == '1')
                ParentTXT.value = '0';
            if ((IsAddOn == '0') && (ParentTXT.value == '' || ParentTXT.value <= '0'))
                ParentTXT.value = '1';

            ParentTXT.disabled = false;
            $(ParentTXT).removeClass('disabled');
            DomainData = parseInt(ParentTXT.value);
        }

        if (ChildCHBX.checked == true) {
            ChildTXT.disabled = true;
            $(ChildTXT).addClass('disabled');
            ChildCHBX.checked = true;
            ChildTXT.value = '';
        }
        else {
            ChildTXT.disabled = false;
            $(ChildTXT).removeClass('disabled');
            ChildCHBX.checked = false;

            if (ChildTXT.value == '')
                ChildTXT.value = DomainData + SubDomainData;

            //********* Check domain dependent resources, those always be greater then equal to sum of domain and subDomain *******
            if ((parseInt(ChildTXT.value) <= (DomainData + SubDomainData)) && IsAlwaysGreaterOrEqual == '1')
                ChildTXT.value = DomainData + SubDomainData;
        }
    }

}

function updateChildResource(IsAddOn, PTB, PCB, SDT, SDC, FTB, FCB, ASPTB, ASPCB, ASP1TB, ASP1CB, ASP2TB, ASP2CB, ASP4TB, ASP4CB, PHP4TB, PHP4CB, PHP5TB, PHP5CB, PRTB, PRCB, PYTB, PYCB, CFTB, CFCB, SSITB, SSICB) {
    var ParentTXT = document.getElementById(PTB);
    var ParentCHBX = document.getElementById(PCB);
    var SubDomain = document.getElementById(SDT);
    var SubDomainCB = document.getElementById(SDC);
    var FTPTXT = document.getElementById(FTB);
    var FTPCB = document.getElementById(FCB);
    var ASPTXT = document.getElementById(ASPTB);
    var ASPCBX = document.getElementById(ASPCB);
    var ASP1TXT = document.getElementById(ASP1TB);
    var ASP1CBX = document.getElementById(ASP1CB);
    var ASP2TXT = document.getElementById(ASP2TB);
    var ASP2CBX = document.getElementById(ASP2CB);
    var ASP4TXT = document.getElementById(ASP4TB);
    var ASP4CBX = document.getElementById(ASP4CB);
    var PHP4TXT = document.getElementById(PHP4TB);
    var PHP4CBX = document.getElementById(PHP4CB);
    var PHP5TXT = document.getElementById(PHP5TB);
    var PHP5CBX = document.getElementById(PHP5CB);
    var PRTXT = document.getElementById(PRTB);
    var PRCBX = document.getElementById(PRCB);
    var PYTXT = document.getElementById(PYTB);
    var PYCBX = document.getElementById(PYCB);
    var CFTXT = document.getElementById(CFTB);
    var CFCBX = document.getElementById(CFCB);
    var SSITXT = document.getElementById(SSITB);
    var SSICBX = document.getElementById(SSICB);

    if ((ParentCHBX.checked == true) || (SubDomainCB.checked == true)) {
        if (SubDomainCB.checked == true) {
            SubDomain.value = '';
            SubDomain.disabled = true;
            $(SubDomain).addClass('disabled');
        }
        else {
            if (SubDomain.value == '')
                SubDomain.value = '0';
            SubDomain.disabled = false;
            $(SubDomain).removeClass('disabled');
        }

        if (ParentCHBX.checked == true) {
            ParentTXT.value = '';
            ParentTXT.disabled = true;
            $(ParentTXT).addClass('disabled');
        }
        else {
            if (ParentTXT.value == '' && IsAddOn == '1')
                ParentTXT.value = '0';
            if ((IsAddOn == '0') && (ParentTXT.value == '' || ParentTXT.value <= '0'))
                ParentTXT.value = '1';

            ParentTXT.disabled = false;
            $(ParentTXT).removeClass('disabled');
        }

        FTPTXT.disabled = true;
        $(FTPTXT).addClass('disabled');
        FTPCB.checked = true;
        FTPTXT.value = '';
        ASPTXT.disabled = true;
        $(ASPTXT).addClass('disabled');
        ASPTXT.value = '';
        ASPCBX.checked = true;
        ASP1TXT.disabled = true;
        $(ASP1TXT).addClass('disabled');
        ASP1TXT.value = '';
        ASP1CBX.checked = true;
        ASP2TXT.disabled = true;
        $(ASP2TXT).addClass('disabled');
        ASP2TXT.value = '';
        ASP2CBX.checked = true;
        ASP4TXT.disabled = true;
        $(ASP4TXT).addClass('disabled');
        ASP4TXT.value = '';
        ASP4CBX.checked = true;
        PHP4TXT.disabled = true;
        $(PHP4TXT).addClass('disabled');
        PHP4TXT.value = '';
        PHP4CBX.checked = true;
        PHP5TXT.disabled = true;
        $(PHP5TXT).addClass('disabled');
        PHP5TXT.value = '';
        PHP5CBX.checked = true;
        PRTXT.disabled = true;
        $(PRTXT).addClass('disabled');
        PRTXT.value = '';
        PRCBX.checked = true;
        PYTXT.disabled = true;
        $(PYTXT).addClass('disabled');
        PYTXT.value = '';
        PYCBX.checked = true;
        CFTXT.disabled = true;
        $(CFTXT).addClass('disabled');
        CFTXT.value = '';
        CFCBX.checked = true;
        SSITXT.disabled = true;
        $(SSITXT).addClass('disabled');
        SSITXT.value = '';
        SSICBX.checked = true;
    }
    else {
        var SubDomainData = 0;
        var DomainData = 0;

        if (SubDomainCB.checked == true) {
            SubDomainData = 0;
            SubDomain.value = '';
            SubDomain.disabled = true;
            $(SubDomain).addClass('disabled');
        }
        else {
            SubDomain.disabled = false;
            $(SubDomain).removeClass('disabled');
            if (SubDomain.value == '')
                SubDomain.value = '0';
            SubDomainData = parseInt(SubDomain.value);
        }

        if (ParentCHBX.checked == true) {
            DomainData = 0;
            ParentTXT.value = '';
            ParentTXT.disabled = true;
            $(ParentTXT).addClass('disabled');
        }
        else {

            if (ParentTXT.value == '' && IsAddOn == '1')
                ParentTXT.value = '0';
            if ((IsAddOn == '0') && (ParentTXT.value == '' || ParentTXT.value <= '0'))
                ParentTXT.value = '1';

            ParentTXT.disabled = false;
            $(ParentTXT).removeClass('disabled');
            DomainData = parseInt(ParentTXT.value);
        }

        FTPTXT.disabled = false;
        $(FTPTXT).removeClass('disabled');
        FTPCB.checked = false;
        ASPTXT.disabled = false;
        $(ASPTXT).removeClass('disabled');
        ASPCBX.checked = false;
        ASP1TXT.disabled = false;
        $(ASP1TXT).removeClass('disabled');
        ASP1CBX.checked = false;
        ASP2TXT.disabled = false;
        $(ASP2TXT).removeClass('disabled');
        ASP2CBX.checked = false;
        ASP4TXT.disabled = false;
        $(ASP4TXT).removeClass('disabled');
        ASP4CBX.checked = false;
        PHP4TXT.disabled = false;
        $(PHP4TXT).removeClass('disabled');
        PHP4CBX.checked = false;
        PHP5TXT.disabled = false;
        $(PHP5TXT).removeClass('disabled');
        PHP5CBX.checked = false;
        PRTXT.disabled = false;
        $(PRTXT).removeClass('disabled');
        PRCBX.checked = false;
        PYTXT.disabled = false;
        $(PYTXT).removeClass('disabled');
        PYCBX.checked = false;
        CFTXT.disabled = false;
        $(CFTXT).removeClass('disabled');
        CFCBX.checked = false;
        SSITXT.disabled = false;
        $(SSITXT).removeClass('disabled');
        SSICBX.checked = false;

        FTPTXT.value = DomainData + SubDomainData;
        ASPTXT.value = DomainData + SubDomainData;
        ASP1TXT.value = DomainData + SubDomainData;
        ASP2TXT.value = DomainData + SubDomainData;
        ASP4TXT.value = DomainData + SubDomainData;
        PHP4TXT.value = DomainData + SubDomainData;
        PHP5TXT.value = DomainData + SubDomainData;
        PRTXT.value = DomainData + SubDomainData;
        PYTXT.value = DomainData + SubDomainData;
        CFTXT.value = DomainData + SubDomainData;
        SSITXT.value = DomainData + SubDomainData;

        //********* Check domain dependent resources, those always be greater then equal to sum of domain and subDomain *******
        if (parseInt(FTPTXT.value) <= (DomainData + SubDomainData))
            FTPTXT.value = DomainData + SubDomainData;
    }
}

function dbUserCountGreaterOrEqualtoDB(DBTB, DBCB, DBUTB, DBUCB) {
    var DBCount = document.getElementById(DBTB);
    var DBCountCB = document.getElementById(DBCB);
    var DBUserCount = document.getElementById(DBUTB);
    var DBUserCB = document.getElementById(DBUCB);

    if (DBCountCB.checked == true) {
        DBCount.value = '';
        DBCount.disabled = true;
        $(DBCount).addClass('disabled');
        DBUserCB.checked = true;
        DBUserCount.value = '';
        DBUserCount.disabled = true;
        $(DBUserCount).addClass('disabled');
    }
    else {
        DBCount.disabled = false;
        $(DBCount).removeClass('disabled');
        if ((DBCount.value == '') || (parseInt(DBCount.value) <= 0)) {
            DBCount.value = 0;
            DBUserCB.checked = false;
            DBUserCount.disabled = false;
            $(DBUserCount).removeClass('disabled');
            DBUserCount.value = 0;
        }

        if (DBUserCB.checked == true) {
            DBUserCB.checked = true;
            DBUserCount.disabled = true;
            $(DBUserCount).addClass('disabled');
            DBUserCount.value = '';
        }
        else {
            DBUserCB.checked = false;
            DBUserCount.disabled = false;
            $(DBUserCount).removeClass('disabled');
            if (DBUserCount.value == '')
                DBUserCount.value = DBCount.value;

            if (parseInt(DBUserCount.value) <= parseInt(DBCount.value))
                DBUserCount.value = DBCount.value;
        }
    }
}