﻿var hastouch = 'ontouchstart' in window //touch devices?;
var axfOverlayOpacity=85
var c; var axfIframe; var axfOverlay; var axfclosebutton;

var userLang ='.'+( (navigator.language) ? navigator.language : navigator.userLanguage);
if (userLang != '.it') userLang = ''; //solo l'italiano è supportato

function axfInitFeedback() {
    if (get_cookie("hide_cookie" + document.domain) == 1) return false;
    c = document.createElement("div")
    var a = document.createElement("a")
    a.href = "#AxFeedback";
    axfclosebutton = document.createElement("img")

    axfclosebutton.style.zIndex = "10002";
    axfclosebutton.src = "http://feedback.axterisco.it/images/closebig.png"
    axfclosebutton.style.position = "fixed";
    axfclosebutton.style.display = 'none';
    document.body.appendChild(axfclosebutton);

    axfOverlay = document.createElement("div")
    axfOverlay.style.cssText = 'z-index:10000;display:none;position:fixed;top:0;left:0;background-color:#999;filter:alpha(opacity=' + axfOverlayOpacity + ');-moz-opacity: 0.' + axfOverlayOpacity + ';opacity: 0.' + axfOverlayOpacity + ';';
    axfOverlay.style.height = '100%';
    axfOverlay.style.width = '100%';

    document.body.appendChild(axfOverlay);
    axfOverlay.style.display = 'none';
    axfOverlay.style.position = "fixed";
    axfOverlay.onclick = function () {
        //axf_CloseFrame();
    };
    axfclosebutton.onclick = function () {
        axf_CloseFrame();
    }

    axfIframe = document.createElement("IFRAME");
    axfIframe.frameBorder = 0;
    axfIframe.style.backgroundColor = 'transparent';
    axfIframe.style.display = 'none';
    axfIframe.style.zIndex = "10001";
    axfIframe.style.position = "fixed";
    axfIframe.onload = function () {
        if (axfIframe.src != '')
            axfclosebutton.style.display = '';
            //alert('load');
        //alert('load');

    }
    a.onclick = function () {
        axfOverlay.style.display = 'block';
        axfIframe.hspace = 0;
        axfIframe.wspace = 0;

        axfIframe.setAttribute("scrolling", "no");
        axfIframe.setAttribute("src", 'http://feedback.axterisco.it/leave.aspx?href=' + encodeURI(location.href));
        axfIframe.style.width = 450 + "px";
        axfIframe.style.overflow = 'hidden';
        axfIframe.style.border = 0;
        axfIframe.style.height = 345 + "px";
        axfIframe.style.display = 'block';

        axfIframe.style.left = (document.body.clientWidth / 2 - parseInt(axfIframe.style.width) / 2) + 'px';
        axfIframe.style.top = ((viewPortHeight()) / 2 - parseInt(axfIframe.style.height) / 2) + 'px';

        axfclosebutton.style.left = (document.body.clientWidth / 2 - parseInt(axfIframe.style.width) / 2) +430 +'px';
        axfclosebutton.style.top = ((viewPortHeight()) / 2 - parseInt(axfIframe.style.height) / 2) -15 + 'px';
        axfclosebutton.style.display = '';

        return false;
    }
    c.id = "axfFeedBack";
    c.style.right = "0px";
    c.style.zIndex = "9999";
    c.style.position = "fixed";
    c.style.bottom = "0px"

    a.innerHTML = "<img border=0 src=\"http://feedback.axterisco.it/images/tagfeedback-smile"+userLang+".png\" style=float:right;><img id=\"AxfCloseImage\" style=\"float:right;position:relative;right:-150px;padding-top:140px;display:none;padding-right:0px\" border=0 src=\"http://feedback.axterisco.it/images/close.png\" title=\"nascondi\" onclick=\"return axfHideFeedBack();\">";
    document.body.appendChild(c);
    if (!hastouch) {
        a.onmouseover = function (e) {
            var el = document.getElementById("AxfCloseImage");

            if (el) {
                el.style.display = '';
            }
        }
        a.onmouseout = function () {
            var el = document.getElementById("AxfCloseImage");
            if (el) {
                el.style.display = 'none';
            }
        }
    }
    c.appendChild(a);
    document.body.appendChild(axfIframe);

    if (hastouch) {
        setInterval(function () {
            var scrollY = window.pageYOffset;
            c.style.top = window.innerHeight + scrollY - 173 + 'px';
        }, 250);
        document.getElementById("AxfCloseImage").style.display = '';
    }
}
function viewPortHeight() { return self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; };

function axfHideFeedBack() {
    document.getElementById("axfFeedBack").style.display = 'none';
    //get_cookie("hide_cookie") = 1

    set_cookie("hide_cookie" + document.domain, "1");
    event.cancelBubble = true;
    return false;
}

axfInitFeedback();

function set_cookie(name, value, exp_y, exp_m, exp_d, path, domain, secure) {
    var cookie_string = name + "=" + escape(value);
    if (exp_y) {
        var expires = new Date(exp_y, exp_m, exp_d);
        cookie_string += "; expires=" + expires.toGMTString();
    }else{
        var days = 15
        var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));

        cookie_string += "; expires=" + date.toGMTString();
    }

    if (path)
        cookie_string += "; path=" + escape(path);
    if (domain)
        cookie_string += "; domain=" + escape(domain);
    if (secure)
        cookie_string += "; secure";
    document.cookie = cookie_string;
}
function get_cookie(cookie_name) {
    var results = document.cookie.match('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');
    if (results)
        return (unescape(results[2]));
    else
        return null;
}

function axf_CloseFrame() {
    axfIframe.style.display = 'none';
    axfclosebutton.style.display = 'none';
    axfOverlay.style.display = 'none';
    return false;
}
