$(document).ready(function () {

    // If had hided that means that javascript enabled
    $("#rowDisabledJS").hide();

    // For label tags
    $("label").each(function () {

        $(this).click(function () {
            $("input[id$='" + $(this).attr("for") + "']").focus();
            $("select[id$='" + $(this).attr("for") + "']").focus();
            $("textarea[id$='" + $(this).attr("for") + "']").focus();
        });

    });

});


function CheckupObj() {
    if (isEmpty(document.getElementById('" + txtUsername.ClientID + "'))) {
        alert('Enter Username!');
        return false;
    }
    if (isEmpty(document.getElementById('" + txtPassword.ClientID + "'))) {
        alert('Enter Password!');
        return false;
    }
    if (isEmpty(document.getElementById('" + txtPasswordConfirm.ClientID + "'))) {
        alert('Enter Confirm Password!');
        return false;
    }
    if (document.getElementById('" + txtPassword.ClientID + "').value != document.getElementById('" + txtPasswordConfirm.ClientID + "').value) {
        alert('Confirm Password does not match to Password!'); return false;
    }
    return true;
}

function AddFormAction(strLink) {
    var aspnetForm = document.getElementById('aspnetForm');

    if (aspnetForm != null) {
        aspnetForm.action = strLink;
    }
}

function CheckupEmail(txtValue, message) {
    var reg = new RegExp("^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$");

    if (!txtValue.match(reg)) {

        if (message != "") {
            alert('Enter correct "' + message + '"!');
        }
        else {
            alert('Please check the email format.');
        }

        return false;
    }

    return true;
}

function IsEmailOk(txtValue) {
    var reg = new RegExp("^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$");

    if (!txtValue.match(reg)) {
        return false;
    }

    return true;
}

function IsCorrectEmail(emailValue) {
    /*  var reg = new RegExp('^[a-zA-Z][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9].[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$');

    if (!emailValue.match(reg))
    {
    return false;
    }

    return true;*/

    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (filter.test(emailValue)) {
        return true;
    }
    else {
        return false;
    }
}

function IsValueInDDLOk(obj) {
    for (var i = 0; i < obj.length; i++) {
        if (obj[i].selected) {
            if (obj[i].value == "-1") {
                obj.selectedIndex = 0;
                return false;
            }
        }
    }

    return true;
}

function isEmpty(obj) {
    if (obj.value != '') {
        return false;
    }

    return true;
}

function isCheck(obj) {
    if (obj.checked) {
        return true;
    }

    return false;
}

function getChar(e) {
    if (e.which || e.keyCode) {
        if ((e.which == 13) || (e.keyCode == 13)) {
            return true;
        }
    }

    return false;
}

function setFocus(id, e) {
    if (getChar(e)) {
        document.getElementById(id).focus();
        return true;
    }

    return false;
}

function SetFocus(id) {

    $("#" + id).keydown(function (n) {
        if (n.keyCode && n.keyCode == 13) {
            $("#" + id).focus();
            return true;
        }
    });

    return false;
}


var newWin;

function NewWindow(mypage, myname, w, h, tool, status, scroll) {
    if (!newWin || newWin.closed) {
        var winl = (screen.width - w) / 2;
        var wint = (screen.height - h) / 2;

        winprops = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl + ',toolbar=' + tool + ',scrollbars=' + scroll + ',status=' + status;
        newWin = window.open(mypage, myname, winprops);
    }
    else {
        newWin.focus();
    }
}

function CheckAll(prefix, id) {
    var chkMain = document.getElementById(id);

    for (var i = 0; i < document.forms[0].elements.length; i++) {
        var doc = document.forms[0].elements[i];

        if (doc.name.search(prefix) > 0) {
            alert(doc);
            if (chkMain.checked) {
                doc.checked = true;
            }
            else {
                doc.checked = false;
            }
        }
    }
}

function JumpToPage(objName) {
    var link = $("select#" + objName).val();

    if (link != "") {
        window.location.href = link;
    }
}

function MathRound(value, count) {
    return Math.round(value * Math.pow(10, count)) / Math.pow(10, count);
}

function show_submenu(id, itemwidth) {
    $("#" + id).css("visibility", "visible");

    var width = itemwidth;

    $("#" + id + " a.submenulink").each(function () {
        if ($(this).width() > width) {
            width = $(this).width();
        }
    });

    $("#" + id).css("width", width);
}

function hide_submenu(id) {
    $("#" + id).css("visibility", "hidden");
}
