var confirmResult = false;

/****************************************************************
*   Funzione truncate per troncare le stringhe
****************************************************************/
jQuery.fn.truncate = function (max, settings) { settings = jQuery.extend({ chars: /\s/, trail: ["...", ""] }, settings); var myResults = {}; var ie = $.browser.msie; function fixIE(o) { if (ie) { o.style.removeAttribute("filter") } } return this.each(function () { var $this = jQuery(this); var myStrOrig = $this.html().replace(/\r\n/gim, ""); var myStr = myStrOrig; var myRegEx = /<\/?[^<>]*\/?>/gim; var myRegExArray; var myRegExHash = {}; var myResultsKey = $("*").index(this); while ((myRegExArray = myRegEx.exec(myStr)) != null) { myRegExHash[myRegExArray.index] = myRegExArray[0] } myStr = jQuery.trim(myStr.split(myRegEx).join("")); if (myStr.length > max) { var c; while (max < myStr.length) { c = myStr.charAt(max); if (c.match(settings.chars)) { myStr = myStr.substring(0, max); break } max-- } if (myStrOrig.search(myRegEx) != -1) { var endCap = 0; for (eachEl in myRegExHash) { myStr = [myStr.substring(0, eachEl), myRegExHash[eachEl], myStr.substring(eachEl, myStr.length)].join(""); if (eachEl < myStr.length) { endCap = myStr.length } } $this.html([myStr.substring(0, endCap), myStr.substring(endCap, myStr.length).replace(/<(\w+)[^>]*>.*<\/\1>/gim, "").replace(/<(br|hr|img|input)[^<>]*\/?>/gim, "")].join("")) } else { $this.html(myStr) } myResults[myResultsKey] = myStrOrig; $this.html(["<div class='truncate_less'>", $this.html(), settings.trail[0], "</div>"].join("")).find(".truncate_show", this).click(function () { if ($this.find(".truncate_more").length == 0) { $this.append(["<div class='truncate_more' style='display: none;'>", myResults[myResultsKey], settings.trail[1], "</div>"].join("")).find(".truncate_hide").click(function () { $this.find(".truncate_more").css("background", "#fff").fadeOut("normal", function () { $this.find(".truncate_less").css("background", "#fff").fadeIn("normal", function () { fixIE(this); $(this).css("background", "none") }); fixIE(this) }); return false }) } $this.find(".truncate_less").fadeOut("normal", function () { $this.find(".truncate_more").fadeIn("normal", function () { fixIE(this) }); fixIE(this) }); jQuery(".truncate_show", $this).click(function () { $this.find(".truncate_less").css("background", "#fff").fadeOut("normal", function () { $this.find(".truncate_more").css("background", "#fff").fadeIn("normal", function () { fixIE(this); $(this).css("background", "none") }); fixIE(this) }); return false }); return false }) } }) };

//impostazione in italiano del date picker
jQuery(function($) {
    $.datepicker.regional['it'] = {
        closeText: 'Chiudi',
        prevText: '&#x3c;Prec',
        nextText: 'Succ&#x3e;',
        currentText: 'Oggi',
        monthNames: ['Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno',
			'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre'],
        monthNamesShort: ['Gen', 'Feb', 'Mar', 'Apr', 'Mag', 'Giu',
			'Lug', 'Ago', 'Set', 'Ott', 'Nov', 'Dic'],
        dayNames: ['Domenica', 'Luned&#236', 'Marted&#236', 'Mercoled&#236', 'Gioved&#236', 'Venerd&#236', 'Sabato'],
        dayNamesShort: ['Dom', 'Lun', 'Mar', 'Mer', 'Gio', 'Ven', 'Sab'],
        dayNamesMin: ['Do', 'Lu', 'Ma', 'Me', 'Gi', 'Ve', 'Sa'],
        weekHeader: 'Sm',
        dateFormat: 'dd/mm/yy',
        firstDay: 1,
        isRTL: false,
        showMonthAfterYear: false,
        yearSuffix: ''
    };
    $.datepicker.setDefaults($.datepicker.regional['it']);
});

//finestra modale di avviso
function getConfirm(message) {
	if (confirm(message)){
		confirmResult = true;
	}
}

// funzioni per l'apertura di popUp esterne
function schema(n){
	w = 677;
	h = 283;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+w+',height='+h+',left='+LeftPosition+', top='+TopPosition+',screenX='+LeftPosition+',screenY='+TopPosition+'';
	schema = window.open('images/schema'+n+'.gif','schema',settings)
}

function Ilove() {
	w = 350;
	h = 350;
	LeftPosition = (screen.width) ? (screen.width - w) / 2 : 0;
	TopPosition = (screen.height) ? (screen.height - h) / 2 : 0;
	settings = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width=' + w + ',height=' + h + ',left=' + LeftPosition + ', top=' + TopPosition + ',screenX=' + LeftPosition + ',screenY=' + TopPosition + '';
	love = window.open('Asp-net.scripts/popupIlove.html', 'love', settings)
}



//apertura PopUp a tutto schermo
function openFullWindow() {
	var w = screen.width;
	var h = screen.height;

	LeftPosition = 0;
	TopPosition = 0;
	
	if (h<800)
	{
		var windowprops = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+w+',height='+h+',left='+LeftPosition+', top='+TopPosition+',screenX='+LeftPosition+',screenY='+TopPosition+'';
	} else
	{
		var windowprops = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+w+',height='+h+',left='+LeftPosition+', top='+TopPosition+',screenX='+LeftPosition+',screenY='+TopPosition+'';
	}

	var marcantognisrlit = window.open('main.aspx', 'marcantognisrlit', windowprops);
	marcantognisrlit.moveTo(LeftPosition, TopPosition)
	marcantognisrlit.resizeTo(w, h);
	marcantognisrlit.focus();
}

//modal popup
function hidePopUp(controlId) {
    $('#popUpBackGround').remove();
    var popup = $(controlId);
    popup.removeClass("popUpBody");
    popup.hide();
}
function showModal(controlId, page, title, w, h) {
    var scrollLeft = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
    var scrollTop = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);

    var clientWidth = $(window).width();
    var clientHeight = $(window).height();
    
    var sfondo = $('<div id="popUpBackGround" />');
    sfondo.height((document.documentElement.scrollHeight ? document.documentElement.scrollHeight : document.body.scrollHeight) + 'px');
    sfondo.width((document.documentElement.scrollWidth ? document.documentElement.scrollWidth : document.body.scrollWidth) + 'px');
    sfondo.appendTo(document.body);

    var caption = $('#caption');
    caption.html(title);

    var pagina = $('#editPage');
    pagina.attr('src', page);
    pagina.width((w - 42) + 'px')
    pagina.height((h - 60) + 'px')

    var popup = $(controlId);
    popup.addClass("popUpBody");
    popup.width(w + 'px');
    popup.height(h + 'px');
    popup.css("left", ((clientWidth / 2) - (popup.width() / 2) + 'px'));
    popup.css("top", ((clientHeight / 2) - (popup.height() / 2) + 'px'));
    popup.show();

    window.onresize = function() {
        sfondo.height((document.documentElement.scrollHeight ? document.documentElement.scrollHeight : document.body.scrollHeight) + 'px');
        sfondo.width((document.documentElement.scrollWidth ? document.documentElement.scrollWidth : document.body.scrollWidth) + 'px');
        //var clientBounds = $common.getClientBounds();
        var clientWidth = $(window).width();
        var clientHeight = $(window).height();
        var scrollLeft = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
        var scrollTop = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
        popup.css("left", ((clientWidth / 2) - (popup.width() / 2) + 'px'));
        popup.css("top", ((clientHeight / 2) - (popup.height() / 2) + 'px'));
    }
}
