﻿// File JScript

function startList() {
	if (typeof MostraBanner == "function") {
        setTimeout('MostraBanner()', 5000);
    }
    if (typeof MostraBannerSinistro == "function") {
        setTimeout('MostraBannerSinistro()', 2000);
    }
    if (typeof MostraBannerDestro == "function") {
        setTimeout('MostraBannerDestro()', 3000);
    }
    setBodyHeightToContentHeight();
    document.oncontextmenu = blocca_tasto_dx;
    effectFadeIn('divchat');
}

function blocca_tasto_dx() {
    //alert('Tasto destro disabilitato');
    return (false);
}

function doPopup(url,nome,w,h) {
    l = (screen.width - w) / 2;
    t = (screen.height - h) / 2;
    popUp=window.open(url, nome, 'width='+w+',height='+h+',left='+l+',top='+t+',toolbar=0,status=0,scrollbars=yes,resizable=0');
}
    
function SetControlValue(controlID1, controlID2, newValue) {
    var pos = newValue.indexOf(')');
    document.forms[0].elements[controlID1].value = newValue.substring(pos+2,newValue.length);
    document.forms[0].elements[controlID2].value = newValue;
    //popUp.close();
}

function scroll_left(name) {
	document.getElementById(name).start();
	document.getElementById(name).direction="left";
}

function scroll_right(name) {
	document.getElementById(name).start();
	document.getElementById(name).direction="right";
}

function scroll_stop(name) {
	document.getElementById(name).stop();
}

function blendimage(divid, imageid, imagefile, millisec) {
    $("#" + imageid).animate({ opacity: 0 }, 100, function() {
        document.getElementById(imageid).src = imagefile;
        $("#" + imageid).animate({ opacity: 1 }, 100);
    });
}

function backImage(divid, imagefile) {
    document.getElementById(divid).style.backgroundImage = "url(" + imagefile + ")"; 
}

function hideFoto() {
	document.getElementById('divfoto').style.visibility = "hidden";
}
	
function showToolTip(e,text){
	if(document.all)e = event;
	
	var obj = document.getElementById('bubble_tooltip');
	var obj2 = document.getElementById('bubble_tooltip_content');
	obj2.innerHTML = text;
	obj.style.display = 'block';
	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	var leftPos = e.clientX - 100;
	if(leftPos<0)leftPos = 0;
	obj.style.left = leftPos + 'px';
	obj.style.top = e.clientY - obj.offsetHeight -1 + st + 'px';
}	
	
function hideToolTip()
{
	document.getElementById('bubble_tooltip').style.display = 'none';
}

function setBodyHeightToContentHeight() {
    document.body.style.height = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight)+"px";
}

function MostraPreferiti() {
    document.getElementById('ctl00_panelPreferitiContent').style.display = 'block';
    document.getElementById('ctl00_panelPreferitiContent').style.top = '500px';
    document.getElementById('ctl00_panelPreferitiContent').style.left = '500px';
}

function getPositionPref() {
    var div = document.getElementById('ctl00_panelPreferitiContent');
    var top = document.getElementById('ctl00_hideTopPref');
    var left = document.getElementById('ctl00_hideLeftPref');
    top.value = div.style.top;
    left.value = div.style.left;
}

//Page Flip on hover
$(document).ready(function() {
	$("#pageflip").hover(function() {
		$("#pageflip img , .msg_block").stop()
			.animate({
				width: '307px', 
				height: '319px'
			}, 500); 
		} , function() {
		$("#pageflip img").stop() 
			.animate({
				width: '50px', 
				height: '52px'
			}, 220);
		$(".msg_block").stop() 
			.animate({
				width: '50px', 
				height: '50px'
			}, 200);
	});


});


// Cookie Function

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}


//SETTING UP POPUP JQUERY

var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup() {
    //loads popup only if it is disabled
    if (popupStatus == 0) {
        $("#backgroundPopup").css({
            "opacity": "0.7"
        });
        $("#backgroundPopup").fadeIn("slow");
        $("#popupContact").fadeIn("slow");
        popupStatus = 1;
    }
}

//disabling popup with jQuery magic!
function disablePopup() {
    //disables popup only if it is enabled
    if (popupStatus == 1) {
        $("#backgroundPopup").fadeOut("slow");
        $("#popupContact").fadeOut("slow");
        popupStatus = 0;
    }
}

//centering popup
function centerPopup() {
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#popupContact").height();
    var popupWidth = $("#popupContact").width();
    //centering
    $("#popupContact").css({
        "position": "absolute",
        "top": windowHeight / 2 - popupHeight / 2,
        "left": windowWidth / 2 - popupWidth / 2
    });
    //only need force for IE6

    $("#backgroundPopup").css({
        "height": windowHeight
    });
}

//LOADING POPUP
function MostraMailing() {
    centerPopup();
    loadPopup();
    document.getElementById('mailing').style.display = 'block';
    document.getElementById('ctl00_txtNome').focus();
}

function MostraLogin() {
    centerPopup();
    loadPopup();
    document.getElementById('login').style.display = 'block';
    document.getElementById('ctl00_txtEmailLog').focus();
}

//CLOSING POPUP
function ChiudiMailing() {
    disablePopup();
    document.getElementById('mailing').style.display = 'none';
    document.getElementById('login').style.display = 'none';
}

//Press Escape event!
$(document).keypress(function(e) {
    if (e.keyCode == 27 && popupStatus == 1) {
        disablePopup();
    }
});

// Infinite blink/fade 
function effectFadeIn(classname) {
    $("#" + classname).fadeTo(200, 1, function() {
        effectFadeOut(classname);
      });
}

function effectFadeOut(classname) {
    $("#" + classname).fadeTo(800, 0.5, function () {
        effectFadeIn(classname)
    });
}


window.onload = startList;
