﻿$(document).ready(function () {
   $(".MessageConfirm").dialog({
      autoOpen: false,
      resizable: false,
      minHeight: 20,
      height: 'auto',
      modal: true,
      buttons: {
         "Yes": function () {
            $(this).dialog("close");
            __doPostBack(confirmPostBack, '')
         },
         "No": function () {
            $(this).dialog("close");
         }
      }
   });

   $(".MessageAlert").dialog({
      autoOpen: false,
      resizable: false,
      minHeight: 20,
      height: 'auto',
      modal: true,
      buttons: {
         "OK": function () {
            $(this).dialog("close");
         }
      }
   });


   var validator = $("form").bind("invalid-form.validate", function () {
   }).validate({
      errorElement: "em",
      errorPlacement: function (error, element) {
         var trigger = element.next('.ui-datepicker-trigger');
         
         if (trigger.length <= 0) { trigger = element.next('.calculator-trigger'); }

         error.insertAfter(trigger.length > 0 ? trigger : element);
      },
      onfocusout: false,
      onclick: false,
      success: function (label) {
         label.removeClass("error");
      }
   });

   
   $.validator.addMethod("endDate", function (value) {
   var startDate = $('.startDate').val();

   if (isNaN(Date.parse(startDate)) || isNaN(Date.parse(value))) { return true };

   return Date.parse(startDate) <= Date.parse(value);
   }, "Completion date must be after Start date");
   $('form').validate();
   
   
   $(function () { $('.button').button(); });

});



function validateForm()
{
	var result = $('form').validate().form();
	
	if (!result)
		$(":input.ui-state-highlight:first").focus();
		
	return result;
}






$.validator.setDefaults({
 highlight: function (input) {
    $(input).addClass("ui-state-highlight");
 },
 unhighlight: function (input) {
    $(input).removeClass("ui-state-highlight");
 }
});



function PasswordStrength() {
   var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
   var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");

   if ($('.password').val() == '') {
      $('.passstrength').removeClass('Weak Medium Strong');
      $('.passstrength').html('');
   } else if (strongRegex.test($('.password').val())) {
      $('.passstrength').removeClass('Medium Weak').addClass('Strong');
      $('.passstrength').html('Strong');
   } else if (mediumRegex.test($('.password').val())) {
      $('.passstrength').removeClass('Strong Weak').addClass('Medium');
      $('.passstrength').html('Medium');
   } else {
      $('.passstrength').removeClass('Strong Medium').addClass('Weak');
      $('.passstrength').html('Weak');
   }
   return true;
 }
