﻿// default language
var surveyLang = 'eng';
var surveyMouse;
var cookieMcl = 'MclSurveyCookie';

function setLanguage(el) {
    // production mode
    if (typeof (el) == "string")
        surveyLang = el;

    // development mode
    if (typeof (el) == "object")
        surveyLang = el.options[el.selectedIndex].value;
}


function storeMouse(e) {
    if (!e) e = window.event;
    surveyMouse = { clientX: e.clientX, clientY: e.clientY };
    //document.getElementById('spanCoord').innerHTML = 'X=' + surveyMouse.clientX + ' Y=' + surveyMouse.clientY;
}

function GetCookie(cName) {
    var tdpCookies = document.cookie.split("; ");
    for (var i = 0; i < tdpCookies.length; i++) {
        var cook = tdpCookies[i].split("=");
        if (cName == cook[0])
            return unescape(cook[1]);
    }
    return null;
}

function SetCookie(cName, cValue) {
    var msecsInADay = 86400000 * 7; // miliseconds in a week
    var expiryDate = new Date((new Date()).getTime() + msecsInADay);

    document.cookie = cName + "=" + escape(cValue) + "; expires=" + expiryDate.toGMTString();
}

function launchSurvey(e) {
    if (surveyMouse) {
        if (surveyMouse.clientX < 0 || surveyMouse.clientY < 0) {
            if (GetCookie(cookieMcl) == null) {
                SetCookie(cookieMcl, 'true');
                
                var width = 1100;
                var height = 605;
                var left = parseInt((screen.availWidth / 2) - (width / 2));
                var top = parseInt((screen.availHeight / 2) - (height / 2));
                var wndFeatures = "location=0,status=0,scrollbars=0,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top;
                var url = '/Survey/Survey.aspx?lng=' + surveyLang + '&pn=' + document.location.pathname;
                var mywindow = window.open(url, "mywindow", wndFeatures);
                return false;
            }
        }
    }
}

