﻿// Nokia-asia.com Support Survey 2004 Opener
// 9.6.2004 Tom Kostiainen
// 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://digiumenterprise.com/answer/?sid=38173&chk=9TDFK5SB";  
//var surveyURL        = "http://digiumenterprise.com/answer/?sid=222503&chk=KV3N43D9";  
//var surveyURL        = "http://digiumenterprise.com/answer/?sid=159881&chk=FHEUU5H5";                        
//var surveyURL        = "http://globaltestmarket.com/survey/s.phtml?sn=62170&demo=1&lang=CHM";
var surveyName       = "nokiaAPACSupportSurvey2008"; // no special characters!!!
var surveyCookieName = "SupportSurvey_2008_06";
var lotteryMaxValue  = 1000; // 1=always, 2=50%, 3=33%, 5=20%, 10=10%, 50=2%, 100=1%, 200=0.5%



//CHRIS 2008
var _xm_surveyURL = "http://digiumenterprise.com/answer/?sid=38173&chk=9TDFK5SB"; 
//var _xm_surveyURL = "http://digiumenterprise.com/answer/?sid=222503&chk=KV3N43D9"; 
//var _xm_surveyURL = "http://digiumenterprise.com/answer/?sid=159881&chk=FHEUU5H5"; 
var _xm_surveyCookieName = "nokiaAPACSupportSurvey2008";
var _xm_lotteryMaxValue = 0; // 10set it to 10% pop-up rate
var _xm_hitbox_cat = "/Support";
var _xm_surveyPopupURLs = new Array("support/apac/phones/guides/","support/global/phones/software/","support/apac/phones/software/");

//global value to make sure only one pop-up per session
__xm_survey2004_popup = true;

var templateIDs = new Array(
96,679,1023,3741,1024,1490,3431,34269,34271,34274,1051,1052,3742,1053,42001,1502,3738,
1074,1075,3743,5841,5842,5843,5844,5845,1077,1091,3744,4710,4718,4719,54012,1092,1093,3745,
1094,1518,3746,1095,2771,3747,1097,1174,1182,3748,1184,1520,3749,1522,3750,1185,1189,3751,
1190,3752,4726,4727,4728,4729,4730,4731,4732,1209,1210,3753,49920,1211,1527,3755,1528,3756,
1212,1219,3757,1220,3758,4733,4734,4735,4736,4737,4738,53587,53588,1269,1271,3772,1272,1529,
3773,1530,3774,1273,1404,3775,1406,3765,4746,4747,4748,4749,4750,1276,1351,1494,3776,1495,
3777,1352,1496,3780,1499,3781,3011,3782,4712,4721,4723,4724,4725,1277,1355,40197,40295,1579,
3367,6031,6032,6033,1278,1357,3812,1358,1585,3813,36070,36083,36087,1361,1368,1512,3814,1514,
3815,1369,1516,3816,1517,3817,1362,1372,3818,1373,1602,3819,1603,3820,47344,1374,1588,3821,
1589,3822,4775,4776,4777,4778,1363,1377,3823,1378,3183,3824,1379,1615,3825,1632,3826,4808,
4809,4810,4811,4812,1364,1383,1647,3827,1648,3828,1384,1645,3829,1646,3830,4759,4761,4765,
4768,1365,1386,1660,3831,1661,3832,1387,1671,3833,1672,3834,4798,4799,4800,4801,1366,1638,
1674,3835,1675,3836,1639,1676,3837,1677,3838,4803,4804,4805,4806,1699,1894,3839,1895,1906,
3840,1908,3841,1896,1910,3842,1913,3091,3093,3844,1915,3843,1897,3845,1900,3084,3086,1700,
2025,3846,2026,2034,3847,2101,3848,2027,4856,4863,2038,3850,4913,4914,4821,4828,4823,4830,
4824,4831,3097,3851,2028,3852,2030,2104,2105,2106,2107,1701,1706,1708,3853,1702,1712,1714,
3862,1705,1727,1729,3864,1738,1982,2021,3865,2048,3866,1984,2050,3867,1985,3343,3344,3345,
3346,1739,1823,1827,3888,1828,3889,1824,1829,3892,1830,3893,1825,3269,3270,3271,1740,1744,
1749,3895,1750,3896,1745,1751,3897,1752,3898,1746,1753,1754,3358,1741,2153,2160,3899,2161,
3900,3625,2154,2162,3901,2164,3902,2925,3903,2926,3904,2927,3905,2155,3906,2157,2929,2930,
1742,2081,2088,3907,2089,3908,2082,2090,3909,2091,3910,2953,3911,2954,3912,2955,3913,2083,
3914,2085,2958,2959,1779,3396,56813,3397,4699,4702,3402,3917,3398,3403,3918,5028,5029,4597,
4598,4599,4600,4601,4602,4688,34248,53591,53592,1780,2334,3920,2335,4993,5044,2340,3921,2341,
3922,5058,2336,2342,3923,5027,5030,4559,4567,4568,4569,4570,4571,4689,36035,1781,2005,3925,
49921,2006,2011,3926,2014,3927,2008,2015,3928,2018,3929,2019,3930,53599,53600,2064,2095,4021,
4711,2072,2096,2099,3931,2073,2109,2112,3933,2074,2123,2140,3936,2075,2146,2147,3937,2076,
2149,2150,3938,2077,2165,2166,3939,2078,2174,2175,3940,2373,3120,3121,3941,3122,3129,3942,
3130,3943,3123,3136,4222,3125,3131,3132,3133,3134,2375,2382,2399,3944,2401,3945,2384,2402,
3949,2385,4706,2376,2390,2394,3954,2395,3956,2391,2412,3957,2392,4707,2378,2406,2410,3958,
2407,2411,3959,2408,4705,2379,2439,2466,3960,2469,3961,2441,2520,3962,2380,2419,2423,3965,
2420,2424,3966,2421,2429,2430,2381,2491,2503,3967,2493,2522,3968,2496,2523,2524,2525,2529,
2530,2535,3969,2531,3161,3970,2532,2564,2565,2566,2603,2607,2611,3971,2612,3973,5443,5444,
2609,2614,2615,2616,2619,2620,2624,3975,2621,2641,3976,2622,2673,2674,2675,2636,2638,2642,
3981,2658,5471,5478,5455,5456,2696,2697,2699,3984,2700,3985,2711,5483,5484,2701,2702,2704,
2708,3986,2709,3987,2705,2718,4221,2706,4708,3637,3639,3641,3991,4833,4834,4835,4837,4961,
4838,4839,4843,4840,4845,4959,4847,4960,4841,4848,4958,5031,5032,4849,4850,4851,4852,4853,
4854,4855,6069,53577,53578,4857,5059,5060,5062,5061,5063,5064,5065,5066,5069,5067,5070,
5071,5072,5073,5074,5075,5077,5078,5079,5080,5081,5083,5082,5084,5085,5086,5098,5087,5099,
5088,5094,5089,5091,5090,5092,5096,5800,5303,5304,5368,49892,5305,5307,5321,5320,5369,5306,
5341,5372,5370,5373,5371,5377,53573,53574,5346,5347,5356,5348,5351,5357,5758,5759,5349,5353,
5359,5354,5360,5355,33764,5362,5363,5364,5365,5366,33763,5367,33761,5403,5404,5408,5418,
5409,5419,5405,5550,5406,5413,5414,5415,5438,5439,5441,53735,5445,5446,5460,5447,5461,5709,
5808,5776,5777,5784,5835,5836,43866,46334,46335,5837,5839,6008,6009,6010,6080,6015,6158,6011,
6016,6081,6017,6082,6018,6083,6084,6085,6086,6087,6088,6089,6105,6106,6107,6111,6112,6134,
41617,41619,41618,28019,28022,28023,28025, 28026,28024,28027,28058,28029,28057,28030,28032,
28034,28035,28037,28038,28039,28040,53595,53596,27156,27158,27167,27168,40301,27163,27767,33014,
27562,27989,33065,33066,33068,33078,33069,33075,33262,33076,33261,33077,33259,42097,42098,42099,
42100,42101,42102,42103,42104,42105,33368,33378,33379,33389,42751,38621,38622,38625,38626,38682,
38623,38683,38624,38627,38628,41418,41419,41420,41422,41423,41421,41424,41434,41426,41427,41436,
41437,41438,41439,41440,41441,53476,53485,41843,41844,41846,41847,42092,42093,42094,32863,48659,
42096,42280,42284,56811,42285,42287,42288,42753,42286,42289,42292,42290,42293,42291,42294,53589,
53590,43287,43289,42792,42795,42797,54102,54103,42796,42955,43622,43625,43626,43628,43629,43659,
43627,43630,43657,43635,43658,43638,43640,43645,43646,43647,43649,43650,43648,46344,53579,53580,
46826,46828,46831,48595,48596,48597,46893,46894,46896,46911,46899,46897,46901,46904,46902,47296,
47297,47298,47299,47300,47301,47302,47973,48085,53483,53572,47394,48238,47414,47475,47476,47478,
47479,47589,47477,47480,47483,47481,47484,47482,47485,53575,53576,48246,48247,48453,49226,49227,
49228,49229,49232,49304,49233,49234,49306,49235,49260,49261,49262,49263,49264,49266,49267,54040,
53597,53598,49780,49781,49782,49783,49784,49889,49785,49885,49786,49787,50022,50023,50024,50025,
50026,50027,50028,54038,49788,53594,49806,49813,49814,49923,49924,53397,53398,53399,53400,54000,
54001,54003,54004,54007,54284,54285,54286,54288,54289,54290,54291,54292,54008,54009,53404,53406,
53463,53464,53465,53466,53467,53567,53468,53568,53469,53569,53473,53603,53604,53605,53606,53607,
53608,53609,54048,53474,53475,53510,53516,53672,53673,53675,53676,53738,53825,53826,53827,54545,
54546,54547,54549,54566,54576,54567,54577,54569,54572,54573,54575,54621,54624,54625,54626,54627,
54550,54570,54690,54691,54693,54692,54695,54697,54698,54814,54815,54816,54818,54838,54839,54840,
54841,55096,55223,56458,56464,55722,55724,55732,55733,56130,56237,56127,56128,56459,56460,56461,
56461,56506,56507,56509,57978,57981,57982,60426,60427,60524,60526,60685,60686,60687,60688,60689,
60690,60692,27056,27057,27058,27357,27421,27422,27424,27426,27427,27643,27646,28161,28359,28360,
28361,28362,28363,28365,28366,28367,28368,32947,32996,41402,43312,46734,48513,50003,50021,53268,
53270,53271,58785,58787,58788,58790,58791,58795,58796,58797,58798,58799,58801,58802,58803,58804,
58805,58806,58807,58808,58809,58810,58811,58812,58813,58814,58815,58816,58817,58827,58829,58830,
58831,58832,58833,58834,58843,58844,58845,58846,58847,58848,59100,59101,59102,59103,59104,59105,
59106,59107,59108,59109,59110,59111,59112,59113,59114,59115,59117,59118,59119,59120,59121,59122,
59123,59124,59125,59126,59127,59128,59129,59130,59131,59132,59133,59134,59135,59136,59137,59138,
59139,59141,59142,59143,59144,59145,59147,59148,59149,59150,59151,59152,59153,59154,59155,59156,
59157,59158,59159,59160,59161,59162,59163,59164,59165,59168,59169,59170,59171,59172,59173,59174,
59175,59176,59177,59178,59179,59180,59181,59182,59183,59184,59186,59187,59188,59189,59190,59191,
59192,59193,59194,59195,59196,59197,59198,59199,59200,59201,59202,59204,59205,59206,59272,59273,
59274,59275,59276,59277,59279,59280,59281,59299,59303,59304,59305,59306,59307,59308,59309,59310,
59311,59312,59313,59314,59315,59316,59317,59318,59319,59321,59322,59323,59324,59325,59326,59327,
59328,59329,59330,59331,59332,59333,59334,59335,59336,59337,59346,59347,59348,59349,59350,59351,
59352,59353,59361,59414,59415,59416,59417,59418,59419,59420,59421,59422,59423,59424,59425,59426,
59427,59428,59429,59430,59431,59432,59433,59434,59435,59436,59437,59438,59439,59440,59441,59442,
59443,59444,59446,59447,59448,59455,59457,59459,59461,59465,59466,59469,59470,59472,59474,59475,
59476,59477,59478,59479,59480,59481,59482,59483,59484,59485,59492,59493,59494,59495,59496,59497,
59498,59499,59500,59501,59502,59503,59504,59505,59508,59509,59510,59754,60379,60380,60381,60382,
60383,60384,60385,60386,60388,60389,60390,60393,60394,60410,60429,60430,60431,60432,60433,60434,
60435,60436,60451,60454,60455,60456,60457,60458,60460,60461,60462,60464,60465,60469,60470,60471,
60472,60473,60474,60475,60485,60486,60487,60489,60490,60491,60492,60493,60494,60510,60511,60516,
60517,60519,60520,60521,60523,60527,60528,60530,60531,60532,60533,60577,60578,60579,60580,60581,
60582,60583,60584,60585,60598,60600,60601,60603,60604,60605,60606,60607,60609,60610,60612,60613,
60614,60615,60616,60617,60618,60619,60620,60621,60633,60634,60636,60639,60659,60660,60661,60662,
60663,60664,60665,60666,60668,60669,60670,60671,60672,60673,60674,60704,60707,60708,60709,60710,
60711,60712,60713,60714,60719,60720,60721,60722,60723,60724,60725,60726,60727,60729,60730,60731,
60732,60733,60734,60735,60736,60737,60738,60739,60740,60741,60788,60789,60790,60791,60793,60794,
60795,60810,60811,60812,60813,60814,60815,60816,60817,60818,60819,60820,60821,60822,60823,60824,
60825,60913,60914,60916,60917,60918,60919,60920,60921,60927,60928,60929,60930,60931,60932,60933,
60934,60935,60936,60937,60938,60939,60940,60941,60942,60943,60944,60945,60946,60947,60948,60949,
60950,60951,60952,60953,60954,60955,60956,60957,60959,60960,60961,60962,60963,60964,60965,60966,
60967,60968,60969,60970,60971,60972,60973,60974,60975,60976,60977,60978,60979,60980,60981,60982,
60983,60984,60985,60986,60987,60988,60989,60990,61006,61007,61008,61009,61010,61011,61012,61013,
61014,61015,61017,61020,61022,61023,61024,61026,61027,61028,61029,61030,61031,61032,61033,61034,
61035,61036,61037,61038,61039,61040,61041,61042,61043,61044,61045,61046,61047,61048,61049,61050,
61051,61052,61157,61193,61222,61224,61225,61592,61594,61597,61773,61776,61780,61820,61859,62536,
62539,62540,62541,62586,62775,62776,62777,62779,62780,62781,27056,27057,27058,27357,27421,27422,
27424,27426,27427,27643,27646,28161,28359,28360,28361,28362,28363,28365,28366,28367,28368,32947,
32996,41402,43312,46734,48513,50003,50021,53268,53270,53271,58785,58787,58788,58790,58791,58795,
58796,58797,58798,58799,58801,58802,58803,58804,58805,58806,58807,58808,58809,58810,58811,58812,
58813,58814,58815,58816,58817,58827,58829,58830,58831,58832,58833,58834,58843,58844,58845,58846,
58847,58848,59100,59101,59102,59103,59104,59105,59106,59107,59108,59109,59110,59111,59112,59113,
59114,59115,59117,59118,59119,59120,59121,59122,59123,59124,59125,59126,59127,59128,59129,59130,
59131,59132,59133,59134,59135,59136,59137,59138,59139,59141,59142,59143,59144,59145,59147,59148,
59149,59150,59151,59152,59153,59154,59155,59156,59157,59158,59159,59160,59161,59162,59163,59164,
59165,59168,59169,59170,59171,59172,59173,59174,59175,59176,59177,59178,59179,59180,59181,59182,
59183,59184,59186,59187,59188,59189,59190,59191,59192,59193,59194,59195,59196,59197,59198,59199,
59200,59201,59202,59204,59205,59206,59272,59273,59274,59275,59276,59277,59279,59280,59281,59299,
59303,59304,59305,59306,59307,59308,59309,59310,59311,59312,59313,59314,59315,59316,59317,59318,
59319,59321,59322,59323,59324,59325,59326,59327,59328,59329,59330,59331,59332,59333,59334,59335,
59336,59337,59346,59347,59348,59349,59350,59351,59352,59353,59361,59414,59415,59416,59417,59418,
59419,59420,59421,59422,59423,59424,59425,59426,59427,59428,59429,59430,59431,59432,59433,59434,
59435,59436,59437,59438,59439,59440,59441,59442,59443,59444,59446,59447,59448,59455,59457,59459,
59461,59465,59466,59469,59470,59472,59474,59475,59476,59477,59478,59479,59480,59481,59482,59483,
59484,59485,59492,59493,59494,59495,59496,59497,59498,59499,59500,59501,59502,59503,59504,59505,
59508,59509,59510,59754,60379,60380,60381,60382,60383,60384,60385,60386,60388,60389,60390,60393,
60394,60410,60429,60430,60431,60432,60433,60434,60435,60436,60451,60454,60455,60456,60457,60458,
60460,60461,60462,60464,60465,60469,60470,60471,60472,60473,60474,60475,60485,60486,60487,60489,
60490,60491,60492,60493,60494,60510,60511,60516,60517,60519,60520,60521,60523,60527,60528,60530,
60531,60532,60533,60577,60578,60579,60580,60581,60582,60583,60584,60585,60598,60600,60601,60603,
60604,60605,60606,60607,60609,60610,60612,60613,60614,60615,60616,60617,60618,60619,60620,60621,
60633,60634,60636,60639,60659,60660,60661,60662,60663,60664,60665,60666,60668,60669,60670,60671,
60672,60673,60674,60704,60707,60708,60709,60710,60711,60712,60713,60714,60719,60720,60721,60722,
60723,60724,60725,60726,60727,60729,60730,60731,60732,60733,60734,60735,60736,60737,60738,60739,
60740,60741,60788,60789,60790,60791,60793,60794,60795,60810,60811,60812,60813,60814,60815,60816,
60817,60818,60819,60820,60821,60822,60823,60824,60825,60913,60914,60916,60917,60918,60919,60920,
60921,60927,60928,60929,60930,60931,60932,60933,60934,60935,60936,60937,60938,60939,60940,60941,
60942,60943,60944,60945,60946,60947,60948,60949,60950,60951,60952,60953,60954,60955,60956,60957,
60959,60960,60961,60962,60963,60964,60965,60966,60967,60968,60969,60970,60971,60972,60973,60974,
60975,60976,60977,60978,60979,60980,60981,60982,60983,60984,60985,60986,60987,60988,60989,60990,
61006,61007,61008,61009,61010,61011,61012,61013,61014,61015,61017,61020,61022,61023,61024,61026,
61027,61028,61029,61030,61031,61032,61033,61034,61035,61036,61037,61038,61039,61040,61041,61042,
61043,61044,61045,61046,61047,61048,61049,61050,61051,61052,61157,61193,61222,61224,61225,61592,
61594,61597,61773,61776,61780,61820,61859,62536,62539,62540,62541,62586,62775,62776,62777,62779,
62780,62781);

var marketingURLs = new Array(
'support/glossaryCDAMaster/',
'include/support/pcsuite_disclaimer.html',
'include/support/mmp_disclaimer.html',
'include/support/software_printable.html',
'mouse2mobile.com/clients/nokia/',
'nokia.com/cda9?id=923',
'nokia.com/support/tutorials/',
'endusersupport.nokia.com/phones/',
'nds1.nokia.com',
'nokia.com/popupDisclaimer',
'faqsearch/Search');

// END: SETTINGS

var someLinkClicked = false;

// BEGIN CODE ---- DO NOT MODIFY BELOW THIS LINE ------------------------------------
function openSurveyPopup() {
 window.open(surveyURL, surveyName, 'scrollbars=yes,status=no,width=650,height=648')
}

function createSurveyCookie(name, value, days) {
 if(days) {
  var date = new Date();
  date.setTime(date.getTime()+(days*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;
}

function pathMatchesSomeTemplateID(URLpath) {
 // to conform with both IE & Mozilla style split length counter, remove the possible first slash-mark
 if( URLpath.charAt(0) == '/') {
  URLpath = URLpath.substring(1, 9999);
 }
 // Checks the given path's templateID against templateIDs array
 var pathSlashParts = URLpath.toString().split("/");
 if(pathSlashParts.length > 1) {
  if(pathSlashParts[0] == 'nokia') {
   var digitParts = pathSlashParts[1].split(",");
   if(digitParts.length > 3) {
    var templateID  = digitParts[2];
    for(j = 0; j < templateIDs.length; j++) {
     if(templateID == templateIDs[j].toString() ) {
      return true;
     }
    }
   }
  }
 }
 return false;
}


///////////////////////// SUPPORT SURVEY ADD-ONS ////////////////////////////

     
function hasOnClickEvent(linkNumber) {
	// Return false if no previous onClick event exists
    var onclickString = document.links[linkNumber].onclick;
    if(onclickString == null) onclickString = '';
    onclickString = new String(onclickString);
    return (onclickString != '');
}
   
function pathMatchesSomeMarketingURL(url) {
   // Goes through all marketing URLs to see if there is one that matches with the link URL
	for(n = 0; n < marketingURLs.length; n++) {
		if(url.indexOf(marketingURLs[n]) > -1) {
		return true;
		}
	}
	return false;
}

function pathMatchesSomeTemplateIDorMarketingURL(clickedLink) {
 	// Checks the given path's templateID against templateIDs array
 	if(pathMatchesSomeTemplateID(clickedLink.pathname)) return true;
 	// Checks the given path against the marketing URLs array
 	if(pathMatchesSomeMarketingURL(clickedLink.href)) return true;
 	// No matches were found
 	return false;
}

function checkLinksOnload() {
 	// Goes through all links in the page; attach onClick call to surveyOpenerLottery if template ID is not in the list or
 	// URL is not in the template ID format 
 	for(i = 0; i < document.links.length; i++) {	
	  if(!hasOnClickEvent(i)) {	
    	if (!pathMatchesSomeTemplateIDorMarketingURL(document.links[i])) {
    	document.links[i].onclick = surveyOpenerLotteryViaLink;
	  	} else {
	  	document.links[i].onclick = plainLinkClick;
	  	}
	  }
  	}
}

function surveyOpenerLottery() {
 	
 	//20050705 XM add a new check, if global __xm_survey2004_popup is set, do not display this survey
 	if (!__xm_survey2004_popup) return;
 	
 	// check if this survey has already been shown
 	if( readSurveyCookie(surveyCookieName) == "yes" ) { 
 		// Return without doing anything
 		return;
 	}
	
 	var randNum = Math.round(Math.random()*(lotteryMaxValue-1));
 	if(randNum == 0) {
  		// hit by lottery
  		createSurveyCookie(surveyCookieName, "yes", 1000); //expires in 180 days
  		openSurveyPopup();
 	}
}

function surveyOpenerLotteryViaLink() {
   // Set flag when link is clicked
	someLinkClicked = true;
 	surveyOpenerLottery();
}

function plainLinkClick() {
   // Set flag when link is clicked
	someLinkClicked = true;
}

///////////////////////// 2008 CHRIS new survey functions ////////////////////////////

function _xm_createSurveyCookie(name, value, days) {
 if(days) {
  var date = new Date();
  date.setTime(date.getTime()+(days*24*60*60*1000));
  var expires = "; expires="+date.toGMTString();
 } else {
  expires = "";
 }
 document.cookie = name+"="+value+expires+"; path=/";
}

function _xm_surveyOpener() {

	// check if this survey has already been shown
	if( readSurveyCookie(_xm_surveyCookieName) == "yes" ) {
		// Return without doing anything
		return;
	}
	
	//double-check whether page is from support section, based on hitbox value if any.
	//if not from support section, do not launch survey pop-up
	if (!_xm_checkHitBox(_xm_hitbox_cat)) return;
	
	var chance = Math.round(Math.random()*(_xm_lotteryMaxValue-1));
	if(chance == 0) {
		// hit by lottery
		_xm_createSurveyCookie(_xm_surveyCookieName, "yes", 1000); //expires in 90 days
		_xm_openSurveyPopup(_xm_surveyURL, _xm_surveyCookieName, 744, 410);
		
		_xm_disableExitSurvey();
		
	}
}

function _xm_surveyOpenerAlways() {


	
	//double-check whether page is from support section, based on hitbox value if any.
	//if not from support section, do not launch survey pop-up
	if (!_xm_checkHitBox(_xm_hitbox_cat)) return;
	
	_xm_createSurveyCookie(_xm_surveyCookieName, "yes", 1000); //expires in 90 days
	_xm_openSurveyPopup(_xm_surveyURL, _xm_surveyCookieName, 744, 410);
	_xm_disableExitSurvey();	
}

function _xm_disableExitSurvey() //disabled survey pop_up on exit - per session only one pop-up
{
	__xm_survey_popup = false;
	__xm_survey2004_popup = false;	
}

function _xm_checkHitBox(pageCat)
{
	
	var strHitbox = hbx.mlc;

	if (strHitbox != null)
	{
		strHitbox = strHitbox.toLowerCase();
		pageCat = pageCat.toLowerCase();
		
		if (strHitbox.indexOf(pageCat) != -1) //string is a substring
			return true;
	}

	return false;
}


function _xm_assignSurveyToLink() {

   	var i, n;
   	var startIndex, endIndex, sfileName, strURL;
   	
   	for(i = 0; i < document.links.length; i++) {
   		
   		for(n = 0; n < _xm_surveyPopupURLs.length; n++) {   			
				if( (document.links[i].href != null && document.links[i].href.indexOf(_xm_surveyPopupURLs[n]) > -1) || (document.links[i].onclick != null && document.links[i].onclick.toString().indexOf(_xm_surveyPopupURLs[n]) > -1) ) {
					
					if (document.links[i].onclick != null)
						strURL = document.links[i].onclick.toString();
					else
						strURL = document.links[i].href;
					
					startIndex = strURL.lastIndexOf("/")+1;
					endIndex = strURL.length;
					sfileName = strURL.substring(startIndex, endIndex);
										
					if (sfileName.toUpperCase().indexOf("_UG") > -1 || sfileName.toUpperCase().indexOf("_USERGUIDE") > -1 || sfileName.toUpperCase().indexOf("_USER_GUIDE") > -1)
						_xm_addEventHandler(document.links[i], "click", function() {_xm_surveyOpenerAlways();});
				}
			}
	}
}

function _xm_openSurveyPopup( url, title, width, height )
{
	window.open( url, title, "toolbar=no,height=" + height + ",width=" + width + ",location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no" );
}

function _xm_addEventHandler( element, event, handler )
{
	if ( element.addEventListener ) //Mozilla
	{
		element.addEventListener( event, handler, false );
	}
	else
	if ( element.attachEvent ) //IE, events is always bubbled, bottom to top
	{
		element.attachEvent( "on" + event, handler );

	}
	
	else {
	
		var oldonload = eval("element.on" + event);
				
		if (typeof oldonload != 'function') {
			 eval("element.on" + event + "= function () {handler();}");
		  } else {
		  	eval("element.on" + event + "= function () {oldonload();handler();}");
		
		}
	
	}
}

function _xm_initSurvey()
{
	_xm_assignSurveyToLink();
	_xm_surveyOpener();
}


// Attaches checkLinksOnload function to onLoad event 
window.onload = function(){
	checkLinksOnload();
};

// Attaches surveyOpenerLottery function to onUnload event, if a link was not clicked 
window.onunload = function(){
	if(!someLinkClicked) {
 	surveyOpenerLottery();
	}
};

_xm_addEventHandler( window, "load", function(){_xm_initSurvey();} );