var GlobalSurvey = { /* ID of the Website profile */ siteId: null, sessionId: null, langId: null, visitTime: 0, answered: false, brandName: null, refreshUrl: null, respondUrl: null, cancelUrl: null, questionId: null, questionText: null, langTexts: { en_UK: { questionIntro: 'May we ask you one question about [brand_name]?', question0: 'Would you recommend [brand_name] to your family or a friend?', question1: 'Would you recommend this website to your family or a friend?', yes: 'Yes', no: 'No', rating0: 'Certainly Not!', rating1: 'Yes, certainly!', thanks: 'We thank you for your time!' }, en_US: { questionIntro: 'May we ask you one question about [brand_name]?', question0: 'Would you recommend [brand_name] to your family or a friend?', question1: 'Would you recommend this website to your family or a friend?', yes: 'Yes', no: 'No', rating0: 'Certainly Not!', rating1: 'Yes, certainly!', thanks: 'We thank you for your time!' }, es_AR: { questionIntro: '¿Podemos hacerle una pregunta acerca de [brand_name]?', question0: '¿Recomendaría [brand_name] a su familia o a un amigo?', question1: '¿Recomendaría este sitio Web a su familia o a un amigo?', yes: 'Sí', no: 'No', rating0: '¡Desde luego que no!', rating1: '¡Sí, absolutamente!', thanks: '¡Le damos las gracias por el tiempo que nos ha dedicado!' }, es_ES: { questionIntro: '¿Podemos hacerle una pregunta acerca de [brand_name]?', question0: '¿Recomendaría [brand_name] a su familia o a un amigo?', question1: '¿Recomendaría este sitio Web a su familia o a un amigo?', yes: 'Sí', no: 'No', rating0: '¡Desde luego que no!', rating1: '¡Sí, absolutamente!', thanks: '¡Le damos las gracias por el tiempo que nos ha dedicado!' }, nl_NL: { questionIntro: 'Mogen wij u een vraag stellen over [brand_name]?', question0: 'Zou u [brand_name] aanraden aan uw familie of een vriend(in)?', question1: 'Zou u deze website aanraden aan uw familie of een vriend(in)?', yes: 'Ja', no: 'Neen', rating0: 'Zeker niet!', rating1: 'Ja, zeker!', thanks: 'Wij danken u voor uw tijd!' }, pt_PT: { questionIntro: 'Posso colocar-lhe uma questão sobre [brand_name]?', question0: 'Recomendaria [brand_name] à sua família ou amigos?', question1: 'Recomendaria este sítio web à sua família ou a um amigo?', yes: 'Sim', no: 'Não', rating0: 'De modo algum!', rating1: 'Sem dúvida!', thanks: 'Vai ser automaticamente redireccionado para o sítio web' }, cs_CZ: { questionIntro: 'Mùžeme Vám položit jednu otázku na [brand_name]?', question0: 'Doporuèil/a byste [brand_name] svému pøíbuznému nebo kamarádovi?', question1: 'Doporučili byste tuto webovou stránku své rodině nebo přátelům?', yes: 'Ano', no: 'Ne', rating0: 'V žádném pøípadì!', rating1: 'Jasnì!', thanks: 'Dìkujeme za Váš èas!' }, ru_RU: { questionIntro: 'Могли бы мы задать Вам один вопрос по поводу [brand_name]?', question0: 'Вы будете рекомендовать [brand_name] кому-либо в Вашей семье или другу?', question1: 'Вы бы порекомендовали посетить этот веб-сайт членам Вашей семьи или друзьям?', yes: 'Да', no: 'Нет', rating0: 'Конечно, нет!', rating1: 'Да, конечно!', thanks: 'Благодарим Вас за уделенное нам время!' }, fr_FR: { questionIntro: 'Pouvons-nous vous poser une question à propos de [brand_name]?', question0: 'Recommanderiez-vous [brand_name] aux membres de votre famille ou à un ami?', question1: 'Recommanderiez-vous ce site Internet à un membre de votre famille ou à un ami?', yes: 'Oui', no: 'Non', rating0: 'Absolument pas!', rating1: 'Absolument!', thanks: 'Nous vous remercions de nous avoir consacré ces quelques minutes!' }, uk_UA: { questionIntro: 'Чи можна Вам поставити одне питання про [brand_name]?', question0: 'Чи порекомендували б Ви [brand_name] сім\'ї чи друзям?', question1: 'Ви би порадили відвідати цей веб-сайт членам Вашої родини або друзям?', yes: 'Так', no: 'Ні', rating0: 'Безперечно ні!', rating1: 'Так, безперечно!', thanks: 'Дякуємо Вам!' } }, containerHeight: 100, container1Pos: -30, container2Pos: 0, ratingWidth: 400, ratingOffsetX: 20, /*DOM elements*/ container_dom: null, positionWindow : {}, ieFixTimer: null, isIEold: null, position : 0, timers: {}, /*--------------*/ /*Ajax functions*/ /*--------------*/ sendResponse: function(url, url_params) { document.getElementById("GlobalSurvey_respondImage").src = url + url_params + '/break_cache:'+Math.random(); document.getElementById("GlobalSurvey_respondImage").style.display = 'block'; }, sendRequest: function(url) { document.getElementById("GlobalSurvey_refreshImage").src = url+'/break_cache:'+Math.random()+'/?referrer='+encodeURIComponent(document.referrer); document.getElementById("GlobalSurvey_refreshImage").style.display = 'block'; }, initQuestionTexts: function() { // randomly select question 1 or 2 this.questionId = Math.random() > 0.5 ? 1 : 0; var langTexts = this.langTexts[this.langId]; if (typeof langTexts == 'undefined') { // fall back to english default langTexts = this.langTexts['en_UK']; } this.questionIntroText = langTexts['questionIntro']; this.questionText = langTexts['question'+this.questionId]; this.questionIntroText = this.questionIntroText.replace('[brand_name]', this.brandName); this.questionText = this.questionText.replace('[brand_name]', this.brandName); this.translatedText = langTexts; }, initConfig: function() { if (typeof GlobalSurvey_config_containerHeight != 'undefined') { this.containerHeight = GlobalSurvey_config_containerHeight; } if (typeof GlobalSurvey_config_container1Pos != 'undefined') { this.containerHeight = GlobalSurvey_config_container1Pos; } if (typeof GlobalSurvey_config_container2Pos != 'undefined') { this.containerHeight = GlobalSurvey_config_container2Pos; } }, /*----------------------------*/ /*Functions of general control*/ /*----------------------------*/ init: function(siteId, sessionId, langId, options) { this.siteId = siteId; this.sessionId = sessionId; this.langId = langId; this.brandName = options.brandName; this.refreshUrl = options.refreshUrl; this.respondUrl = options.respondUrl; this.cancelUrl = options.cancelUrl; this.visitTime = options.visitTime; this.answered = options.answered; this.test = options.test; this.no_show = options.no_show; this.initConfig(); this.isIEold = this.detectIEold(); this.loadStyleElement(); this.initQuestionTexts(); if(window.addEventListener){ window.addEventListener("load", function(){GlobalSurvey.loadWebElements.call(GlobalSurvey)}, false); }else{ window.attachEvent("onload", function(){GlobalSurvey.loadWebElements.call(GlobalSurvey)}); }; }, update: function(){ this.sendRequest(this.refreshUrl); }, startSurveyQuestionTimer: function(){ //percentages: var percentages = [100, 30, 5]; //middle of time: var times = [0, 1, 4]; var timeShow = this.getShowTime(percentages, times); var temp1 = window.setTimeout(function(){GlobalSurvey.showIntroQuestion.call(GlobalSurvey)}, this.test ? 0 : timeShow) }, lineal: function(x, b, c){ for(i = 1; i < b.length; i++){ if(x >= b[i]){ return (b[i - 1] - x)*(c[i]/(b[i - 1] - b[i])) + (x - b[i])*(c[i - 1]/(b[i - 1] - b[i])); }; }; return c[c.length - 1]; }, getShowTime: function(b, c){ var x = Math.random() * 100; var result = this.lineal(x, b, c); if(Math.random() > 0.5){ result = (-1)*result + (c[c.length - 1] * 2); }; // convert to secs: result = result * 60; result = Math.max(result - this.visitTime, 0); // alert(result + ' ' + this.visitTime); // convert to msec: result = Math.round(result * 1000); return (result); }, /*-----------------------------------------*/ /*Functions to load the HTML STYLE elements*/ /*-----------------------------------------*/ loadWebElements: function(){ this.container_dom = document.createElement("DIV"); this.container_dom.id = "GlobalSurvey_container"; this.loadDOMElements(); // only show question if not already answered // also don't show question if "no_show" parameter was passed if (!this.answered && !this.no_show) { this.startSurveyQuestionTimer(); } }, loadStyleElement: function(){ var webStyle = 'body' + '{' + 'margin:0;' + 'padding:0;' + '}' + '#GlobalSurvey_container' + '{' + 'display:none;' + 'position:relative;' + 'height:'+this.containerHeight+'px;' + 'margin-top:-'+this.containerHeight+'px;' + 'left:0px;' + 'padding:0;' + 'margin:0;' + 'font-size:14px;' + 'color:#000;' + 'background:#fff;' + '}' + '#GlobalSurvey_subContainer1' + '{' + 'padding-top: 50px;' + 'padding-left: 20px;' + '}' + '#GlobalSurvey_subContainer2' + '{' + 'padding-top: 0px;' + 'padding-left: 20px;' + '}' + '#GlobalSurvey_subContainer3' + '{' + 'padding-top: 30px;' + 'padding-left: 20px;' + '}' + '#GlobalSurvey_container p' + '{' + 'padding: 6px 0;' + 'margin:0;' + '}' + '#GlobalSurvey_container a' + '{' + 'color: #000;' + 'font-weight: bold;' + 'text-decoration: underline;' + '}' + '#GlobalSurvey_surveyQuestion' + '{' + 'font-weight: bold;' + '}' + '#GlobalSurvey_answerRating' + '{' + 'position:relative;' + 'background: transparent url(http://survey.abinbev.tcsondemand.com/img/survey/numbers.png) no-repeat top left;' + 'width: '+this.ratingWidth+'px;' + 'height: 60px;' + 'cursor: pointer;' + '}' + '#GlobalSurvey_rating0' + '{' + 'position: absolute;' + 'top: 38px;' + 'width:100%;' + 'text-align: left;' + 'font-weight: normal;' + 'z-index: 200;' + '}' + '#GlobalSurvey_rating1' + '{' + 'position: absolute;' + 'top: 38px;' + 'width:100%;' + 'text-align: right;' + 'font-weight: normal;' + 'z-index: 200;' + '}' + '#GlobalSurvey_ratingColorbar' + '{' + 'display: none;' + 'position: absolute;' + 'height: 40px;' + 'width: 0px;' + 'background: #F5C523;' + '}' + '.GlobalSurvey_bottom' + '{' + 'position:absolute;' + 'width:100%;' + 'bottom:0px;' + 'left:0px;' + 'height:5px;' + 'overflow:hidden;' + 'padding:0;' + 'border:0;' + 'margin:0;' + 'background:#dddddd;' + 'font-size:0;' + 'line-height:0;' + 'z-index:1;' + '}'; document.write(""); }, loadDOMElements: function(){ this.container_dom.innerHTML = '
' + '
' + '
' + '

'+this.questionIntroText + ' '+this.translatedText.yes+' - '+this.translatedText.no+'

' + '
' + '
' + '
' + '
' + '' + ''; document.body.insertBefore(this.container_dom, document.body.firstChild); this.container_dom = document.getElementById("GlobalSurvey_container"); this.containerInner_dom = document.getElementById("GlobalSurvey_containerInner"); var yesBtn1_dom = document.getElementById("GlobalSurvey_yesBtn1"); var noBtn1_dom = document.getElementById("GlobalSurvey_noBtn1"); noBtn1_dom.onclick = function() { GlobalSurvey.sendResponse(GlobalSurvey.cancelUrl, ''); window.clearInterval(GlobalSurvey.ieFixTimer); GlobalSurvey.timers.slideUpIntroQuestion = window.setInterval(function(){GlobalSurvey.slideUpIntroQuestion.call(GlobalSurvey)}, 20); return false; }; yesBtn1_dom.onclick = function() { window.clearInterval(GlobalSurvey.ieFixTimer); GlobalSurvey.initSurveyQuestion(); GlobalSurvey.timers.slideDownSurveyQuestion = window.setInterval(function(){GlobalSurvey.slideDownSurveyQuestion.call(GlobalSurvey)}, 20); return false; }; var updateTimer = window.setInterval(function(){GlobalSurvey.update.call(GlobalSurvey)}, 15000); }, /*----------------------------------*/ /*Functions to animate the questions*/ /*----------------------------------*/ fixIEoldScroll: function(metodo){ if(document.documentElement.scrollLeft !== undefined){ this.positionWindow.y = document.documentElement.scrollTop; this.positionWindow.x = document.documentElement.scrollLeft; }else{ this.positionWindow.y = document.body.scrollTop; this.positionWindow.x = document.body.scrollLeft; }; if(metodo == 'get'){ return this.positionWindow; }; this.container_dom.style.top = this.positionWindow.y + "px"; this.container_dom.style.left = this.positionWindow.x + "px"; }, detectIEold: function(){ if(window.opera){return false}; if(window.navigator.appName == 'Microsoft Internet Explorer'){ var appVersion_str = window.navigator.appVersion; var reg = new RegExp("MSIE ([0-9])?"); var result = reg.exec(appVersion_str); var version_str = result[1]; if ((Number(version_str) <= 6)){ return true; }; }; return false; }, slideDownIntroQuestion: function() { if (this.position < this.container1Pos){ this.position += 2; /* if(this.isIEold){ this.fixIEoldScroll('get'); this.container_dom.style.top = this.positionWindow.y + this.position + "px"; this.container_dom.style.left = this.positionWindow.x + "px"; }else{ */ this.container_dom.style.marginTop = this.position + "px"; // }; }else{ window.clearInterval(this.timers.slideDownIntroQuestion); /* if(this.isIEold){ this.ieFixTimer = window.setInterval(function(){GlobalSurvey.fixIEoldScroll.call(GlobalSurvey)}, 20); }; */ }; }, slideUpIntroQuestion: function(){ if(this.position > - this.containerHeight){ this.position -= 2; /* if(this.isIEold){ this.fixIEoldScroll('get'); this.container_dom.style.top = this.positionWindow.y + this.position + "px"; this.container_dom.style.left = this.positionWindow.x + "px"; }else{ */ this.container_dom.style.marginTop = this.position + "px"; /* }; */ }else{ window.clearInterval(this.timers.slideUpIntroQuestion); this.container_dom.style.display = "none"; }; }, initSurveyQuestion: function() { this.containerInner_dom.innerHTML = '
' + '
' + '

'+this.questionText+'

' + '
' + '
'+this.translatedText.rating0+'
'+this.translatedText.rating1+'
' + '
' + '
'; this.answerRating_dom = document.getElementById("GlobalSurvey_answerRating"); this.ratingColorbar_dom = document.getElementById("GlobalSurvey_ratingColorbar"); if (this.isIEold) { // fix transparent PNG for IE 6: var bgImg = this.answerRating_dom.currentStyle.backgroundImage || this.answerRating_dom.style.backgroundImage; if (bgImg.match(/^url[("']+(.*\.png)[)"']+$/i)) { var s = RegExp.$1; this.answerRating_dom.style.backgroundImage = 'none'; this.answerRating_dom.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+s+'",sizingMethod="crop")'; } } this.answerRating_dom.onclick = function(evt){ if (!evt) { evt = window.event; } // this correction shifts the results a bit to match the background image (numbers.png) var correction = 0.6; var rating = Math.min(10, Math.round(evt.clientX * 10 / GlobalSurvey.ratingWidth + correction)); GlobalSurvey.sendResponse( GlobalSurvey.respondUrl, '/question_id:'+GlobalSurvey.questionId+'/result:'+rating); window.clearInterval(GlobalSurvey.ieFixTimer); GlobalSurvey.initThanks(); }; this.answerRating_dom.onmousemove = function(evt){ if (!evt) { evt = window.event; } GlobalSurvey.ratingColorbar_dom.style.width = (evt.clientX - GlobalSurvey.ratingOffsetX) + 'px'; GlobalSurvey.ratingColorbar_dom.style.display = 'block'; }; this.answerRating_dom.onmouseout = function(evt){ if (!evt) { evt = window.event; } GlobalSurvey.ratingColorbar_dom.style.display = 'none'; }; }, slideDownSurveyQuestion: function() { if(this.position < this.container2Pos){ this.position += 2; this.container_dom.style.marginTop = this.position + "px"; }else{ this.container_dom.style.marginTop = this.container2Pos + "px"; window.clearInterval(this.timers.slideDownSurveyQuestion); /* if(this.isIEold){ this.ieFixTimer = window.setInterval(function(){GlobalSurvey.fixIEoldScroll.call(GlobalSurvey)}, 20); }; */ }; }, initThanks: function() { this.containerInner_dom.innerHTML = '
' + '
' + '

'+this.translatedText.thanks+'

' + '
' + '
'; var delayTime = 2 * 1000; function initHideThanks(){ window.clearInterval(GlobalSurvey.ieFixTimer); GlobalSurvey.timers.hideThanks = window.setInterval(function(){GlobalSurvey.hideThanks.call(GlobalSurvey)}, 20); }; window.setTimeout(initHideThanks, delayTime); }, hideThanks: function(){ if(this.position > - this.containerHeight){ this.position -= 2; /* if(this.isIEold){ this.fixIEoldScroll('get'); this.container_dom.style.margi = this.positionWindow.y + this.position + "px"; this.container_dom.style.left = this.positionWindow.x + "px"; }else{ */ this.container_dom.style.marginTop = this.position + "px"; // }; }else{ this.container_dom.style.display = "none"; window.clearInterval(this.timers.hideThanks); }; }, showIntroQuestion: function(){ this.position = 0 - this.containerHeight; this.container_dom.style.display = 'block'; this.timers.slideDownIntroQuestion = window.setInterval(function() {GlobalSurvey.slideDownIntroQuestion.call(GlobalSurvey)}, 20); } }; if (typeof GlobalSurvey_init != 'undefined') { GlobalSurvey_init(); }