/* @utils.js */
 // rendere in home page gli elementi con classe column di uguale altezza
function equalHeight(group) {
   tallest = 0;
   group.each(function() {
      thisHeight = $(this).height();
      if(thisHeight > tallest) {
         tallest = thisHeight;
      }
   });
   group.height(tallest);
};

/* @load.js */
$(document).ready(function () {
    if ($(".lst-catalogo").length) {
        equalHeight($(".lst-catalogo .item"));
    }
    if ($(".lst-news").length){
        $(".modArchivio .lst-news .item:nth-child(2n+2)").each(function(){
			$(this).after("<li class='clear'></li>");
		  });
    };
	if ($(".pagination").length){
        $('a[disabled="disabled"]').addClass("disabled");
    };
	if ($(".path").length){
        $('.path li').last().addClass("last");
    };
});

function disableBtn(btnID, newText) {
    var btn = document.getElementById(btnID);
    var oldValue = btn.value;
    btn.disabled = true;
    btn.value = newText;
    if (HasPageValidators()) {
        if (Page_Validators != undefined && Page_Validators != null) {
            //Looping through the whole validation collection.
            for (var i = 0; i < Page_Validators.length; i++) {
                ValidatorEnable(Page_Validators[i]);
                //if condition to check whether the validation was successfull or not.
                if (!Page_Validators[i].isvalid) { ResetToDefault(btn, oldValue); break; }
                else {
                    var isValidationOk = Page_IsValid; EnableOnUnload(btn, btn.value);

                    if (isValidationOk !== null) {
                        //page valid
                        if (isValidationOk) {
                            //SetImage(btn);
                            break;
                        }
                        else { //page not valid
                            btn.disabled = false;
                        }
                    }
                }
            }
        }
    }
    else {
        //SetImage(btn);
        btn.disabled = true; btn.value = newText;
        EnableOnUnload(btn, btn.value);
    }
}
function ResetToDefault(btn, oldValue) {
    btn.disabled = false;
    btn.value = oldValue;
}

//Handle Page_Validators is not defined error
function HasPageValidators() {
    var hasValidators = false;
    try {
        if (Page_Validators.length > 0) {
            hasValidators = true;
        }
    }
    catch (error) { }
    return hasValidators;
}

/*
function SetImage(btn) {
    btn.style.background = 'url(http://images.ysatech.com/ajax-loader.gif)';
}
*/

//enable the button and restore the original text value for browsers other than IE
function EnableOnUnload(btn, btnText) {
    if (navigator.appName !== 'Microsoft Internet Explorer') {
        window.onunload = function () {
            ResetToDefault(btn, btnText);
        }
    }
}

