﻿BlockUI = function(id, iscache, urlvalue) {
    $(id).click(function() {
        $.ajax({
            url: urlvalue, //$(id).attr("url"),
            cache: iscache,
            complete: function(success, result) {
                //alert(success.responseText);
                $.blockUI({
                    message: success.responseText
                });
                $('.blockOverlay').attr('title', 'Click to unblock').click($.unblockUI);
            }
        });
    });
}

// select all desired input fields and attach tooltips to them

ToolTip = function(formID) {
    $('#' + formID + ' :input').tooltip({

        // place tooltip on the right edge
        position: "top left",

        // a little tweaking of the position
        offset: [-4, 500],

        // use the built-in fadeIn/fadeOut effect
        effect: "fade",

        // custom opacity setting
        opacity: 0.7

    });
}

function IsValidEmail(email) {

    var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;

    return filter.test(email);

}

$(function() {
    $("form :input[type='text']:enabled:first").focus();

});

$(function() {
    $('.password').pstrength();
});

DisableCopyPasteDatePicker = function() {
    $(".datepicker").bind("paste", function(e) {
        alert('Paste not allowed');
        return false;
    });
    $(".datepicker").bind("blur", function(e) {

        return false;
    });
}

CalculatePercentage = function(isForStep, type) {

    $(".percent").each(function() {
        var idvalue = $(this).attr("id");
        $("#" + idvalue).bind("blur focus", function() {
            if (isForStep == "cumulative")
                calculateSum(isForStep, 5, 3);
            else if (isForStep == "percent")
                calculateSum("percent");
        });
    });
    $('#empercentage').text(isForStep + "% completed");
    isForStep = type;
}
function calculateSum(value, countvalue, step) {
    var sum = 0;
    var count = 0;
    $(".percent").each(function() {
        var id = $('#' + $(this).attr("id"));
        var percent = id.attr("percent");
        if (value == "percent") {
            if (parseInt(percent) > 0 && id.val() != "") {
                sum = parseInt(sum) + parseInt(percent);
            }
        }
        else if (value == "cumulative") {
            count++;
            if (id.val() != "") {
                if (step != "") {
                    if (count <= 5)
                        sum = parseInt(sum) + countvalue;
                    if (count > 5 && count <= 10)
                        sum = parseInt(sum) + countvalue + step;
                    else
                        sum = parseInt(sum) + countvalue + (step * 2);
                }
                else {
                    sum = parseInt(sum) + parseInt(percent);
                }
            }
        }
        else {
            sum = value;
        }
    });
    $('#empercentage').text(sum + "% completed");
    $('.percentage').attr("value", sum)
}

ShowOthersTexboxOnload = function(ddlId, divId) {
    $("#" + ddlId + ' option:selected').each(function() {
        if ($(this).text() == 'Other' || $(this).text() == 'Others') {
            $("#" + divId).show();
        }
        else {
            $("#" + divId).hide();
        }
    });

}

AddRemoveList = function(buttonId, sourceListId, destinationId) {
    $("#" + buttonId).click(function() {
        $("#" + sourceListId + " :selected").appendTo("#" + destinationId);
    });

}

Toggle = function(source, target, method) {
    $(source).bind(method, function() {
        $(target).toggle();
    });
}

Questionnaire = function(id, url) {
    $('#chkedu').click(function() {
        if ($(this).is(':checked')) {
            //alert($(id).val()  + id);
            var id1 = $(id).val();
            var urlRedirect = "/Questionnaire/" + url + "/" + id1;
            window.location = urlRedirect;
            $('#submit').attr("disabled", "disabled");

            return;
        }
        else {
            $('#submit').attr("disabled", "");
        }
    });
};

ShowHideOtherTextBox = function(ddlId, divId) {
    $("#" + ddlId).change(function() {
        //alert('');
        var ddlText = $("OPTION:selected", this).text();
        if (ddlText == "Other" || ddlText == "Others") {
            //alert('');
            $("#" + divId).show();
        }
        else {
            $("#" + divId).hide();
        }
    });

}

ShowHideOptions = function(mainclass, hideclass) {
    $("." + mainclass).toggle(function() {
        $('.' + hideclass).hide();
        $(this).removeClass("showdetails");
        $(this).removeClass("showdetails1");
        $(this).addClass("hidedetails");

    }, function() {
        $('.' + hideclass).show();
        $(this).addClass("showdetails");
        $(this).addClass("showdetails1");
        $(this).removeClass("hidedetails");

    });
}



$(document).ready(function() {
    //ShowHideOptions('showdetails', 'Rlinks');
    //ShowHideOptions('subshowdetails', 'form_fields');
    //ShowHideOptions('Compensation', 'classCompensation');


    $(".showdetails").toggle(function() {
        $('.Rlinks').show();
        $(this).removeClass("showdetails");
        $(this).addClass("hidedetails");
    }, function() {
        $('.Rlinks').hide();
        $(this).addClass("showdetails");
        $(this).removeClass("hidedetails");
    });

    $(".subshowdetails").toggle(function() {
        $('.form_fields').hide();
        $(this).removeClass("subshowdetails");
        $(this).addClass("subhidedetails");
    }, function() {
        $('.form_fields').show();
        $(this).addClass("subshowdetails");
        $(this).removeClass("subhidedetails");

    });

    $(".Compensation").toggle(function() {
        $('.classCompensation').show();
        $(this).removeClass("Compensation");
        $(this).addClass("hidedetails");
    }, function() {
        $('.classCompensation').hide();
        $(this).addClass("Compensation");
        $(this).removeClass("hidedetails");
    });





    $('#viewdata').show();
    $('#editdata').hide();

    var displayTitle = "";
    $(".showcontent").toggle(function() {
        $('.' + $(this).attr("displayClass")).show();
        displayTitle = $(this).attr("tooltip");
        $(this).attr("tooltip", $(this).attr("alttooltip"));
        $(this).attr("alttooltip", displayTitle);
        $(this).removeClass("showdetails");
        $(this).addClass("hidedetails");
    }, function() {
        $('.' + $(this).attr("displayClass")).hide();
        displayTitle = $(this).attr("tooltip");
        $(this).attr("tooltip", $(this).attr("alttooltip"));
        $(this).attr("alttooltip", displayTitle);
        $(this).addClass("showdetails");
        $(this).removeClass("hidedetails");
       
    });




    var percentage = $('#pb1_pbImage').attr('title');

    if (percentage) {

        $('#pb1').progressBar(percentage);
        var modifybut = $('#addcv').val();
        switch (modifybut) {
            case '0':
                var activefield = '#hiddendash'
                break;
            case '1':
                var activefield = '#publicdash'
                break;
        }
        $(activefield).addClass('activedash');
        $(activefield).removeClass('inactivedash');
    }
});
//          $(document).ready(function() {
//              var percentage = $('#pb1_pbImage').attr('title');
//              if (percentage) {
//                  $('#pb1').progressBar(percentage);
//                  }
//                  var modifybut = $('#addcv').val();
//                  switch (modifybut) {
//                      case '0':
//                          var activefield = '#hiddendash'
//                          break;
//                      case '1':
//                          var activefield = '#publicdash'
//                          break;
//                  }
//                  $(activefield).addClass('activedash');
//                  $(activefield).removeClass('inactivedash');
//}
//              });
//          ProgressBar = function(contentid, parentid) {
//              var percentage = $(contentid).attr('title');
//              alert(percentage);
//              if (percentage) {
//                  $(parentid).progressBar(percentage);
//              }
//          }


OtherTextBoxValidationRules = function() {
    /* Set rules for client side validation of other text boxes*/

    Sys.Mvc.ValidatorRegistry.validators["othertextboxValidation"] = function(rule) {
        // initialization code can go here.
        var minValue = rule.ValidationParameters["othertextbox"];

        // we return the function that actually does the validation
        return function(value, context) {
            //If other text box is visible, validate for required.
            if ($(".othertextboxclass").is(':visible')) {
                if (value != null && value != "") {
                    return true; /* success */
                }
            }
            else {
                return true;
            }

            return rule.ErrorMessage;
        };
    };
}

TextArea = function(id, options) {
    $("textarea").each(function() {
        var limit = 50;
        var idvalue = $(this).attr("id");
        if ($(this).attr("maxlength") != "" && $(this).attr("maxlength") != null)
            limit = $(this).attr("maxlength");
        $("#" + idvalue).keyup(function() {
            var len = $(this).val().length;
            if (len > limit) {
                this.value = this.value.substring(0, limit);
            }
            var charleft = limit - len;
            if (charleft > 0) {
                $('.' + idvalue + '_charsleft').text(charleft + " Charecters left");
            }
            else {
                $('.' + idvalue + '_charsleft').text(0 + " Charecters left");
            }
        });
    });
}

ViewEditDiv = function(id, viewdiv, editdiv, viewclass, editclass) {
    if (id == "") {
        $(viewdiv).show();
        $(editdiv).hide();
        $(editclass + " a").html("Add")
        $(editclass).removeClass("innerselected");
        $(viewclass).addClass("innerselected");
    } else {
        $(editdiv).show();
        $(viewdiv).hide();
        $(viewclass).removeClass("innerselected");
        $(editclass).addClass("innerselected");
        //$(".display_message").html("");
    }
    if (id == "addnew") {
        $(editclass + " a").html("Add")
    }
    $(viewclass).click(function() {
        $(viewdiv).show();
        $(editdiv).hide();
        $(editclass).removeClass("innerselected");
        $(viewclass).addClass("innerselected");
    });
    $(editclass).click(function() {
        $(viewdiv).hide();
        $(editdiv).show();
        $(viewclass).removeClass("innerselected");
        $(editclass).addClass("innerselected");
        $(".display_message").html("");
    });
}

