//  Nokia.com Support Survey 2004 Opener
// 9.6.2004 Tom Kostiainen
// 16.6.2006 Markku Mantere
// 19.6.-21.6.2006 Ari-Pekka Lappi
// 18.12.2007 Sakari Laaksonen ->
  //removed the template checks and fixed a bug with onload functions and IE popups
//
// Satama Interactive
//
// Based on
// Nokia.com Research 2004 KPI Survey Opener
// 13.04.2004 Vesa Kivistö
// Satama Interactive
//
// This JS file is included to relevant templates (defined in the related ICO CR)
// Purpose of this JS file is to (possibly) open up a popup survey when user leaves the
// Research section. If survey is opened once, the user will never get the survey popup again.

window.onerror = null;

// BEGIN: SETTINGS
                        
var surveyURL		= "http://mea.nokia.com/A4788143";
var surveyName	= "support_survey_en"; // no special characters!!!
var cookieName	= "supportsurvey_200801_shown";


var lotteryMaxValue  = 11; // p_survey_openned = 1/2*(lotteryMaxValue-1) 
                           // 1=always, 2=~50%, 3=25%, 11=5%, 51=1%, 101=0,5%, 201=0,25%
													 // (Values corrected by apl 19.5.2005)
// END: SETTINGS
// These are used in window.onunload event. 
var someLinkClicked = false;
var formSubmited = false;
var marketingURLs = new Array();
var templateIDs = new Array();

// BEGIN CODE ---- DO NOT MODIFY BELOW THIS LINE ------------------------------------
function openSurveyPopup() {

 window.open(surveyURL, surveyName, "scrollbars=yes,status=no,width=400,height=300")
}

function createSurveyCookie(name, value, days) {
 if(days) {
    var date = new Date();
    var expirationTime = 24*60*60*1000*180;  
    date.setTime(date.getTime() + expirationTime) //(days*60*60*1000)); *24*60*60*1000
    var expires = "; expires="+date.toGMTString();
 } else {
    expires = "";
 }
 document.cookie = name+"="+value+expires+"; path=/";
}

function readSurveyCookie(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;
}



///////////////////////// SUPPORT SURVEY ADD-ONS ////////////////////////////

function surveyOpenerLottery() {
  // check if this survey has already been shown

  if(readSurveyCookie(cookieName) ){
       // Return without doing anything
      return;
  }
	
	var randNum = Math.round(Math.random()*(lotteryMaxValue-1));
  if(randNum == 0) {
      // hit by lottery
      createSurveyCookie(cookieName, "yes", 180); //expires in 180 days
      openSurveyPopup();
  }
}


//window.onunload = function(){
	surveyOpenerLottery();
//};
