﻿function pageUrlGet() {
    var path = window.location.pathname;
    return path.toLowerCase();
}

function domainGet() {
    return window.location.host.toLowerCase();
}

function showModalPopupViaClientSide(ev,behaviour) {
    var modalPopupBehavior = $find(behaviour);
    modalPopupBehavior.show();
}        

function showIdParamModalPopupViaClientSide(ev,paramId,behaviour,clientId){
    if($get(clientId)!=null)
    {
        $get(clientId).value=paramId;
    }
    var modalPopupBehavior = $find(behaviour);
    modalPopupBehavior.show();
}  

function closeModalPopupViaClientSide(ev,behaviour) {
    var modalPopupBehavior = parent.$find(behaviour);
    modalPopupBehavior.hide();
}

function redirect(url) {
    window.location = url;
}

function checkAllDiv(div) {
    $("#"+ div +" :checkbox").attr("checked", true);
}

function checkUncheckAllMailsChb( id, pID )
{
   $( "#" + pID + " :checkbox").attr('checked', $('#' + id).is(':checked'));
}

function checkUncheckAllChb( id, pID)
{
   $( "#" + pID + " :checkbox").attr('checked', $('#' + id).is(':checked'));
}

function unCheckAllDiv(div) {
    $("#"+ div +" :checkbox").attr("checked", false);
}

function SelectCheckbox(checkboxId,textboxId,validator1Id,validator2Id,e)
{
    if ($("#" + checkboxId) != null) {
        if ($("#" + textboxId) != null)
        {
            if ($("#" + textboxId).val().length == 0 || !$("#" + textboxId).val().match(/[^\s]/))
            {
                $("#" + checkboxId).removeAttr('checked');
            }
            else
            {
                $("#" + checkboxId).attr('checked', 'checked');
                EnableValidators(validator1Id,validator2Id,checkboxId,e);
            } 
        }  
    }
}

function SelectCheckboxBulkPlayerAdd(checkboxId, textboxId, validator1Id, validator2Id, validator3Id, validator4Id, e)
{
    if ($("#" + checkboxId) != null) {
        if ($("#" + textboxId) != null)
        {
            if ($("#" + textboxId).val().length == 0 || !$("#" + textboxId).val().match(/[^\s]/))
            {
                $("#" + checkboxId).removeAttr('checked');
            }
            else
            {
                $("#" + checkboxId).attr('checked', 'checked');
            }
            var validators = new Array($("#" + validator1Id), $("#" + validator2Id), $("#" + validator3Id), $("#" + validator4Id));
            EnableValidatorsArray(validators, checkboxId, e);
        }  
    }
}

function CheckUncheckCheckbox(checkboxId, textboxId, e) {
    if ($("#" + checkboxId) != null) {
        if ($("#" + textboxId) != null) {
            if ($("#" + textboxId).val().length == 0 || !$("#" + textboxId).val().match(/[^\s]/)) {
                $("#" + checkboxId).removeAttr('checked');
            }
            else {
                $("#" + checkboxId).attr('checked', 'checked');
            }
        }
    }
}

function EnableValidatorsArray(validators, checkboxId, e) {
    for (i = 0; i < validators.length; i++) {
        if ($('#' + checkboxId).is(':checked')) {
            ValidatorEnable(validators[i], true);
        } else {
            ValidatorEnable(validators[i], false);
        }
    }
}


function EnableValidators(validator1Id,validator2Id,checkboxId,e)
{
    if(document.getElementById(checkboxId).checked==false)
    {
        ValidatorEnable(document.getElementById(validator1Id), false);
        ValidatorEnable(document.getElementById(validator2Id), false);
      
    }
    else 
    {
        ValidatorEnable(document.getElementById(validator1Id), true);
        ValidatorEnable(document.getElementById(validator2Id), true);
       
    }
}


function menuHover(li) {
    $("#" + li).addClass("ui-state-hover");
}
function menuNoHover(li) {
    $("#" + li).removeClass("ui-state-hover");
}
function menuSelect(li) {
    $("#" + li).addClass("ui-tabs-selected ui-state-active");
}

function initializeCheckAllUncheckAll(checkAll, uncheckAll, checkboxDiv) {
    $(document).ready(function () {
        checkAndUncheck(checkAll,uncheckAll,checkboxDiv);
    });
    $(function () {
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
        function EndRequestHandler(sender, args) {
            checkAndUncheck(checkAll, uncheckAll, checkboxDiv);
        }
    });
}

function checkAndUncheck(checkAll, uncheckAll, checkboxDiv) {
    $('#' + checkAll).click(
        function () {
            checkAllDiv(checkboxDiv);
        });

    $('#' + uncheckAll).click(
        function () {
            unCheckAllDiv(checkboxDiv);
        });
}
