[PORTAL-7] Rebase
[portal.git] / ecomp-portal-BE-common / src / main / webapp / WEB-INF / static / ebz / angular_js / attHeader_new.js
1 /* Start of definition of the adobe analytics variable, "digitalData" .*/
2 var wcaUser = "false",menuClicked;
3 var digitalData=digitalData||{};
4 digitalData={
5         page:{
6                 pageInfo:{},
7                 category:{},
8                 attributes:{},
9                 internalSearch:{}
10         },
11         event:[{
12                 eventInfo:{}
13         }],
14         product:[{
15                 productInfo:{}
16         }],
17         cart:{},
18         transaction:{
19                 item:[{
20                         productInfo:{},
21                         price:{}
22                 }],
23                 profile:{
24                         address:{}
25                 },
26                 total:{},
27                 attributes:{}
28         },
29         user:[{
30         profile:[{
31             profileInfo:{},
32             attributes:{
33                 profileFAN:{}
34             }
35         }]
36     }]
37 };
38 /* End of definition of the adobe analytics variable, "digitalData" .*/
39
40 /* Self-Invoking Anonymous Function to run on every load of the header content. */
41
42 $(function(){
43     /* Variables to hold the header data retrieved from the database. */
44        var headerData, secMenuData, megaMenuData ;
45        var homePageNameInfo;
46         var loginId;
47         var bdToolsWindow;
48         var checkSessionIntervalMins = 29;
49         var bdSessionTimeout = 60;
50         var  bdSessionId;
51        loadJSWithCallBack = function(src, callback) {
52           if ($('script[src*="'+src+'"]').length === 0) {
53              $.getScript(src)
54                .done(function( script, textStatus ) {
55                      callback.call();
56                })
57                .fail(function( jqxhr, settings, exception ) {
58                  //console.log("file not loaded " + src);
59              });
60           }else{
61              /* Script loaded already*/
62              callback.call();
63           }
64        }
65
66     var headerFunction = function() {
67     this.getHeaderData = function() {
68       /*  $.ajax({
69
70             type: "post",
71             dataType: 'json',
72             url: window.dashboardContext + "/mnm/map/common/dashboardNavigation.jsp",
73             success: function(data) {
74
75                 if (data) {
76                     headerData = data;
77                     /* Generating the html for the primary menu using handlebars. */
78                    /* var primaryMenuTmpl = Handlebars.compile($("#primaryMenu_tmpl").html()),
79                         primaryMenuHtml = primaryMenuTmpl(data);
80                     $(".primaryMenuOptionsContainer").removeClass('primaryMenuOption');
81                     $('.primaryMenuOption').replaceWith('');
82                     $(".primaryMenuOptionsContainer").append(primaryMenuHtml);
83                     var dataForNavigation = {};
84                     if (window.location.hash) {
85                         dataForNavigation.pageUrl = window.location.pathname + "?" + window.location.hash;
86                     } else {
87                         dataForNavigation.pageUrl = window.location.pathname;
88                     }
89
90                     /* Ajax call to get the name of the home page from the DB based on the current url. */
91                   /*  $.ajax({
92                         type: "post",
93                         dataType: 'json',
94                         data: dataForNavigation,
95                         url: window.dashboardContext + "/mnm/map/common/navigationParent.jsp",
96                         headers: {"X-CSRF-Token":window.softToken},
97                         success: function(data) {
98                             if (data) {
99                                 homePageNameInfo = data;
100                                 $(".pageNameContainer .pageName").html(data.name);
101
102                                 $.each(headerData.childNavigation, function(dataIndex, primaryMenuData) {
103
104                                     $.each(primaryMenuData.childNavigation, function(dataIndex, secondaryMenuData) {
105
106                                         if (secondaryMenuData.name == homePageNameInfo.name) {
107
108                                             $(".pageName").attr("href", secondaryMenuData.url);
109                                         }
110
111                                     });
112
113                                 });
114
115
116                                 showSecondaryMenu(homePageNameInfo);
117                             }
118                         },
119                         error: function() {
120                             //console.log("Error Response From Service");
121                         }
122                     });
123                 }
124             },
125             error: function() {
126                 //console.log("Error Response From Service");
127             }
128         }); */
129     }
130 }
131 primaryMenuItemClick = function(primaryMenuLinkObj) {
132
133     var $this = $(primaryMenuLinkObj);
134     
135    /* $('.categoryContainerColumn').remove();*/
136     $('.megaMenuContainer').scrollTop(0);
137     $('.megaMenuContainer').hide();
138     $(".selectionDiv").hide();
139     $('.secondaryMenuOptionLink').removeClass('selectedSecondaryMenuOption');
140     $('.thirdMenuOptionLink').removeClass('selectedSecondaryMenuOption');
141
142     /* Arrow left position calculation. */
143
144     var elementLeft = $this.position().left,
145         elementWidth = $this.width(),
146         centerValue = elementLeft + 24 + (elementWidth) / 2;
147     $('.selectedOptionIndicator').css('left', centerValue);
148     $('.selectedOptionIndicator').show(); //Added By Robert 6/9/15
149     // when clicked on Support link
150     if ($this.text() === 'Support') {
151         return populateSecondaryMenu(primaryMenuLinkObj, getSupportLinkData());    
152     }
153
154     /*$.ajax({
155          type: "get",
156          dataType: 'json',
157          async: false,
158          contentType :'application/json',
159          //url: window.dashboardContext + "/navigation/gadgets/megaMenuNavigation.jsp?megaMenu="+escape($this.text()).toUpperCase(),
160          url: window.ebizDashboardContext + "/navigation/"+escape($this.text()),
161          //headers: {"X-CSRF-Token":window.softToken},
162          success: function(data) {
163              populateSecondaryMenu(primaryMenuLinkObj, data);
164          },
165          complete : function() {
166          },
167          error: function() {
168                  if (typeof console == 'object') {
169                          console.log("Error Response From Service");
170                  }
171          }
172      });*/
173 }
174
175 populateSecondaryMenu = function(primaryMenuLinkObj, data) {
176         //primary menu link object
177         var $this = $(primaryMenuLinkObj);
178
179         if (data) {
180                 headerData = data;
181
182                 if (data.childNavigation.length != 0) {
183                         $.each(data.childNavigation, function(dataIndex, childNavigation) {
184                                 if(childNavigation == null){
185                         childNavigation = {};
186                          secondaryMenuTmpl = Handlebars.compile($("#secondaryMenu_tmpl").html()),
187                          secondaryMenuHtml = secondaryMenuTmpl(childNavigation);
188                         $('.secondaryMenuOption').remove();
189                         $(".secondaryMenuContentContainer").append(secondaryMenuHtml);
190                     }else{
191                                         secMenuData = childNavigation.childNavigation;
192                                         
193                                         var noOfCols = childNavigation.childNavigation.length,
194                                         secondaryMenuTmpl = Handlebars.compile($("#secondaryMenu_tmpl").html()),
195                                         secondaryMenuHtml = secondaryMenuTmpl(childNavigation);
196         
197                                         $('.secondaryMenuOption').remove();
198                                         $(".secondaryMenuContentContainer").append(secondaryMenuHtml);
199         
200                                         if (noOfCols < 6) {
201                                                 $('.secondaryMenuOption').css('margin-left', 40);
202                                         } else if (noOfCols == 6) {
203                                                 $('.secondaryMenuOption').css('margin-left', 30);
204                                         } else if (noOfCols > 6 && noOfCols < 9) {
205                                                 $('.secondaryMenuOption').css('margin-left', 20);
206                                         }
207                     }
208                                 $('.selectedOptionIndicator').show();
209                                 
210                                 if (window.location.pathname == window.ebizDashboardContext + "/index.jsp") {
211                                         $('.secondaryMenuContainerForDashboard').show();
212                                 } else if (window.location.pathname.indexOf('login') > 0) {
213                     $('.secondaryMenuContainerForApplication').show();
214                 } else {
215                                         $(".secondaryMenuContainerForApplication").show();
216                                         /*if(!($('.switch-message-div').is(':visible'))){
217                                                 $('.secondaryMenuContainer').css("margin-top", 50);
218                                         }*/
219                                 }
220                                 $('.primaryMenuOptionLink').removeClass('selectedPrimaryMenuOption');
221                                 $this.addClass("selectedPrimaryMenuOption");
222                                 var currentUrl = window.location.href;
223                                 if(currentUrl != null){
224                                         var emaintenanceMatch = currentUrl.search('emaintenance');
225                                         if(emaintenanceMatch >= 0){
226                                                 $(".pageNameContainer .pageName").html("Network");
227                                         }
228                                 }
229                         })
230                 } else {
231                         $('.selectedOptionIndicator').hide();
232                         $('.secondaryMenuContainer').hide();
233                         $('.secondaryMenuOption').remove();
234                         $('.primaryMenuOptionLink').removeClass('selectedPrimaryMenuOption');
235                 }
236         }
237 }
238
239
240 if($(".switch-message-div").is(':visible')){
241                 $(".dashboardHeadTitle").css("margin-top","60px");
242              $(".dashboardHeadIcons").css("top","127px");
243              $("#openWalkThrough").css("margin-top","40px");
244              $(".dashboardHeadWhiteOverlay").css("margin-top", "36px");
245              $("#dashBoardContainer").css("margin-top", "43px");
246 }
247
248 if(!($('.switch-message-div').is(':visible'))){
249                 $(".dashboardHeadWhiteOverlay").css("margin-top", 0);
250                 $(".dashboardHeadTitle").css("margin-top","30px");
251                 $(".dashboardHeadIcons").css("top","90px");
252                 $("#openWalkThrough").css("margin-top","0px");
253                 $("#dashBoardContainer").css("margin-top", "4px");
254 }
255
256 getSupportLinkData = function() {
257     return {
258           "name": "ESTRATEGY_NAVIGATION",
259           "id": "Support",
260           "url": null,
261           "childNavigation": [
262             {
263               "name": "Support",
264               "url": null,
265               "childNavigation": [
266                   {
267                       "name": "User Information",
268                       "url": "/ebiz/ebcsupport/eBCSupport.jsp?module_id=profileInfo",
269                       "childNavigation": []
270                     },                                  
271                     {
272                       "name": "Registration and Login",
273                       "url": "/ebiz/ebcsupport/eBCSupport.jsp?module_id=registration",
274                       "childNavigation": []
275                     },
276                     {
277                       "name": "Orders",
278                       "url": "/ebiz/ebcsupport/eBCSupport.jsp?module_id=order",
279                       "childNavigation": []
280                     },
281                     {
282                       "name": "Billing",
283                       "url": "/ebiz/ebcsupport/eBCSupport.jsp?module_id=billing",
284                       "childNavigation": []
285                     },
286                     {
287                         "name": "Network",
288                         "url": "/ebiz/ebcsupport/eBCSupport.jsp?module_id=networkInfo",
289                         "childNavigation": []
290                     },                
291                     {
292                       "name": "Reports",
293                       "url": "/ebiz/ebcsupport/eBCSupport.jsp?module_id=reporting",
294                         "childNavigation": []
295                     }
296             ],
297               "urlWithTitle": null,
298               "navClass": null
299             }
300           ],
301           "urlWithTitle": null,
302           "navClass": null
303     };  
304 }
305
306
307 highlightHomePageNameInSecMenu = function(secondaryMenuItemObj) {
308
309     var $this = $(secondaryMenuItemObj);
310
311     $this.parents(".secondaryMenuOption").find(".selectionDiv").show();
312     $this.addClass('homePageNameHighlight');
313 }
314
315 showSecondaryMenu = function(homePageNameInfo) {
316
317     var primaryMenuItem;
318     if (headerData && headerData.childNavigation) {
319         $.each(headerData.childNavigation, function(dataIndex, primaryMenuData) {
320
321             primaryMenuItemToClick = primaryMenuData.name;
322             $.each(primaryMenuData.childNavigation, function(dataIndex, secondaryMenuData) {
323
324                 if (secondaryMenuData.name == homePageNameInfo.name) {
325
326                     $.each($('.primaryMenuOptionLink'), function(i, val) {
327
328                         var $this = $(this);
329
330                         if ($this.html() == primaryMenuItemToClick) {
331                                                 alert("");
332                             primaryMenuItemClick($this);
333                         }
334                     });
335
336                     $.each($('.secondaryMenuOptionLink'), function(i, val) {
337
338                         var $this = $(this);
339
340                         if ($.trim($this.html().split("<")[0]) == secondaryMenuData.name) {
341
342                             highlightHomePageNameInSecMenu($this);
343                         }
344                     });
345                     $.each($('.thirdMenuOptionLink'), function(i, val) {
346
347                         var $this = $(this);
348
349                         if ($.trim($this.html().split("<")[0]) == secondaryMenuData.name) {
350
351                             highlightHomePageNameInSecMenu($this);
352                         }
353                     });
354                     
355                     
356                 }
357
358             });
359
360         });
361     }
362 }
363
364 secondaryMenuItemHover = function(secondaryMenuItemObj) {
365
366     var $this = $(secondaryMenuItemObj);
367
368     $(".selectionDiv").hide();
369     $('.secondaryMenuOptionLink').removeClass('selectedSecondaryMenuOption');
370     $('.thirdMenuOptionLink').removeClass('selectedSecondaryMenuOption');
371     
372     if ($this.hasClass("pageName")) {
373         $.each(headerData.childNavigation, function(dataIndex, childNavigation) {
374             var child1 = childNavigation.childNavigation;
375             $.each(child1, function(dataIndex, childNavigation) {
376                 if (childNavigation.name === $.trim($this.html())) {
377                     if (childNavigation.childNavigation.length != 0) {
378                         secMenuData = child1;
379                     }
380                 }
381             });
382         });
383         $(".megaMenuContainer").addClass("addMargin");
384     } else {
385         $(".megaMenuContainer").removeClass("addMargin");
386     }
387     /* 
388     $('.categoryContainerColumn').remove();
389    $.each(secMenuData, function(dataIndex, childNavigation) {
390
391         if (childNavigation.name == $.trim($this.html().split("<")[0])) {
392              Generating the html for the secondary menu. 
393
394             if (childNavigation.childNavigation.length != 0) {
395
396                 megaMenuData = childNavigation.childNavigation;
397                 var megaMenuFirstRowData = {},
398                     megaMenuSecondRowData = {},
399                     firstRowDataIndex = 0,
400                     secondRowDataIndex = 0;
401
402                 megaMenuFirstRowData.childNavigation = {};
403                 megaMenuSecondRowData.childNavigation = {};
404
405                 $.each(childNavigation.childNavigation, function(dataIndex, columnInfo) {
406
407                     if (dataIndex < 6) {
408                         megaMenuFirstRowData.childNavigation[firstRowDataIndex++] = columnInfo;
409                     } else if (dataIndex > 5 && dataIndex < 12) {
410                         megaMenuSecondRowData.childNavigation[secondRowDataIndex++] = columnInfo;
411                     }
412
413                 });
414
415                 var megaMenuTmpl = Handlebars.compile($("#megaMenu_tmpl").html()),
416                     megaMenuFirstRowHtml = megaMenuTmpl(megaMenuFirstRowData);
417
418                 $(".megaMenuFirstRow").append(megaMenuFirstRowHtml);
419
420                 if (megaMenuData.length > 6) {
421
422                     var megaMenuSecondRowHtml = megaMenuTmpl(megaMenuSecondRowData);
423                     $(".megaMenuSecondRow").append(megaMenuSecondRowHtml);
424                     $(".megaMenuSecondRow").show();
425                 }
426
427                 $('.megaMenuContainer').show();
428                 $this.find(".selectionDiv").show();
429                 $this.addClass('selectedSecondaryMenuOption');
430 */
431                 /* Width and margin assignments for each column (6 columns max in a row) in the mega menu. */
432 /*                switch (megaMenuData.length) {
433
434                     case 1:
435
436                         $('.categoryContainer').css('margin-left', '30px');
437                         $('.categoryContainer').width(300);
438                         break;
439
440                     case 2:
441
442                         $('.categoryContainer').css('margin-left', '20px');
443                         $('.categoryContainer').width(300);
444                         break;
445
446                     case 3:
447
448                         $('.categoryContainer').css('margin-left', '20px');
449                         $('.categoryContainer').width(293);
450                         break;
451
452                     case 4:
453
454                         $('.categoryContainer').css('margin-left', '20px');
455                         $('.categoryContainer').width(215);
456                         break;
457
458                     case 5:
459
460                         $('.categoryContainer').css('margin-left', '10px');
461                         $('.categoryContainer').width(175);
462                         break;
463
464                     case 6:
465                     case 7:
466                     case 8:
467                     case 9:
468                     case 10:
469                     case 11:
470                     case 12:
471                         $('.categoryContainer').css('margin-left', '10px');
472                         $('.categoryContainer').width(145);
473                         break;
474
475                     default:
476                         $('.categoryContainer').css('margin-left', '10px');
477                         $('.categoryContainer').width(145);
478                         break;
479                 }
480
481                 $('.megaMenuFirstRow .categoryContainer:first').css('margin-left', '30px');
482                 $('.megaMenuSecondRow .categoryContainer:first').css('margin-left', '30px');
483
484             } else {
485
486                 $('.megaMenuContainer').scrollTop(0);
487                 $('.megaMenuContainer').hide();
488                 $(".selectionDiv").hide();
489                 $('.secondaryMenuOptionLink').removeClass('selectedSecondaryMenuOption');
490             }
491         }
492
493     });*/
494 }
495 /* Loading handlebars.js if it isn't already. */
496 /*if (userLoggedIn) {
497       Generating the html for the primary menu using handlebars. 
498     var primaryMenuNames = {"childNavigation": [{"name" : "Manage"},{"name" : "Tools"},{"name" : "Support"}]};
499
500     var primaryMenuTmpl = Handlebars.compile($("#primaryMenu_tmpl").html());
501     primaryMenuHtml = primaryMenuTmpl(primaryMenuNames);
502
503     $(".primaryMenuOptionsContainer").removeClass('primaryMenuOption');
504     $('.primaryMenuOption').replaceWith('');
505     $(".primaryMenuOptionsContainer").append(primaryMenuHtml);
506     var dataForNavigation = {};
507     if (window.location.hash) {
508         dataForNavigation.pageUrl = window.location.pathname + "?" + window.location.hash;
509     } else {
510         dataForNavigation.pageUrl = window.location.pathname;
511     }
512 }*/
513
514 /* On click of any primary menu option, display the corresponding secondary menu. */
515 $(document).on('click keyup', '.primaryMenuOptionLink', function(ev) {
516     if (ev.keyCode==13 || ev.type=='click') {
517         ev.stopImmediatePropagation();
518         primaryMenuItemClick($(this));
519
520         if (homePageNameInfo) {
521
522             $.each($('.secondaryMenuOptionLink'), function() {
523
524                 var $this = $(this);
525
526                 if ($.trim($this.html().split("<")[0]) == homePageNameInfo.name) {
527
528                     highlightHomePageNameInSecMenu($this);
529                 }
530             });
531             $.each($('.thirdMenuOptionLink'), function() {
532
533                 var $this = $(this);
534
535                 if ($.trim($this.html().split("<")[0]) == homePageNameInfo.name) {
536
537                     highlightHomePageNameInSecMenu($this);
538                 }
539             });
540             
541             
542         }
543     }
544 });
545
546 /* Code related to the CATO compliance for navigation through key board */
547 // tab-out of a primaryLink in expanded mode
548 $(document).on('keydown', '.primaryMenuOptionLink', function(e) {
549       var keyCode = e.keyCode || e.which;
550       // when shift tab pressed retain default behaviour
551       if (e.shiftKey && e.keyCode == 9) {
552          return;
553       }
554
555       e.preventDefault();
556       if (keyCode == 40) { //down arrow : focus on the first secondary menu link
557           $('.secondaryMenuContentContainer a.secondaryMenuOptionLink:first').focus();
558           $('.secondaryMenuContentContainer a.thirdMenuOptionLink:first').focus();
559       }
560
561       if (keyCode == 9 || keyCode == 39) { //tab or right arrow
562           if ($(this).parent().next().length) { //next primary link
563               $(this).parent().next().find("a.primaryMenuOptionLink").focus();
564           } else {
565               $(".openpopbox").focus(); //traverse to login icon
566           }
567       }
568
569       if (keyCode == 37) { //left arrow
570           if ($(this).parent().prev().length) { //next primary link
571               $(this).parent().prev().find("a.primaryMenuOptionLink").focus();
572           }
573       }
574 });
575
576
577 //tab-out of a secondary in expanded mode
578 $(document).on('keydown', '.secondaryMenuOptionLink', function(e) {
579       var keyCode = e.keyCode || e.which;
580       //enter key
581       if(keyCode == 13) {
582          window.location = $(this).attr('href');
583       }
584
585       e.preventDefault();
586       if (keyCode == 40) { //down arrow : focus on the first mega menu link
587           $('.megaMenuContainer a.categoryOptionLink:first').focus();
588       }
589
590       if (keyCode == 38) {// up arrow: traverse to current primary link
591           $(getSelectedPrimaryMenuOption()).find("a.primaryMenuOptionLink").focus();
592       }
593
594       if (keyCode == 9 || keyCode == 39) { //tab or right arrow
595           if($(this).parent().next().length) { // traverse to next secondary link if exists
596               $(this).parent().next().find("a.secondaryMenuOptionLink").focus();
597           } else { //traverse to next primary link
598               $(getSelectedPrimaryMenuOption()).next().find("a.primaryMenuOptionLink").focus();
599           }
600       }
601
602       if (keyCode == 37) {// left arrow:
603           if ($(this).parent().prev().length) { // traverse to previous link if exists
604               $(this).parent().prev().find("a.secondaryMenuOptionLink").focus();
605           } else { // traverse to current primary link
606               $(getSelectedPrimaryMenuOption()).find("a.primaryMenuOptionLink").focus();
607           }
608       }
609 });
610
611 $(document).on('keydown', '.thirdMenuOptionLink', function(e) {
612     var keyCode = e.keyCode || e.which;
613     //enter key
614     if(keyCode == 13) {
615        window.location = $(this).attr('href');
616     }
617
618     e.preventDefault();
619     if (keyCode == 40) { //down arrow : focus on the first mega menu link
620         $('.megaMenuContainer a.categoryOptionLink:first').focus();
621     }
622
623     if (keyCode == 38) {// up arrow: traverse to current primary link
624         $(getSelectedPrimaryMenuOption()).find("a.primaryMenuOptionLink").focus();
625     }
626
627     if (keyCode == 9 || keyCode == 39) { //tab or right arrow
628         if($(this).parent().next().length) { // traverse to next secondary link if exists
629             $(this).parent().next().find("a.thirdMenuOptionLink").focus();
630         } else { //traverse to next primary link
631             $(getSelectedPrimaryMenuOption()).next().find("a.primaryMenuOptionLink").focus();
632         }
633     }
634
635     if (keyCode == 37) {// left arrow:
636         if ($(this).parent().prev().length) { // traverse to previous link if exists
637             $(this).parent().prev().find("a.thirdMenuOptionLink").focus();
638         } else { // traverse to current primary link
639             $(getSelectedPrimaryMenuOption()).find("a.primaryMenuOptionLink").focus();
640         }
641     }
642 });
643 //tab-out of a categoryOptionLink
644 $(document).on('keydown', '.categoryOptionLink', function(e) {
645     var keyCode = e.keyCode || e.which;
646     //enter key
647     if(keyCode == 13) {
648         window.location = $(this).attr('href');
649         menuClicked = $(this).attr('href');
650     }
651
652     e.preventDefault();
653
654     if (keyCode == 39) {     // right arrow
655         $(this).parent().parent().parent().next().find("a.categoryOptionLink:first").focus();
656     } else if(keyCode == 37) { //left arrow
657         $(this).parent().parent().parent().prev().find("a.categoryOptionLink:first").focus();
658     } else if(keyCode == 38) { //up arrow
659         if($(this).parent().prev(".categoryOption").length) {
660             $(this).parent().prev(".categoryOption").find("a.categoryOptionLink").focus();
661         } else {
662             if ($(this).parent().parent().parent().prev().length) { //traverse to prev category column if exists
663                 $(this).parent().parent().parent().prev().find("a.categoryOptionLink:last").focus();
664             } else { //traverse to current secondary column
665                 $(getSelectedSecondaryMenuOption()).find("a.secondaryMenuOptionLink").focus();
666                 $(getSelectedSecondaryMenuOption()).find("a.thirdMenuOptionLink").focus();
667                 
668             }
669         }
670     } else if(keyCode == 40) { //down arrow
671         if ($(this).parent().next(".categoryOption").length) {
672             $(this).parent().next(".categoryOption").find("a.categoryOptionLink").focus();
673         } else {
674             if ($(this).parent().parent().parent().next().length) { //traverse to next category column if exists
675                 $(this).parent().parent().parent().next().find("a.categoryOptionLink:first").focus();
676             } else { //traverse to next secondary link
677                 $(getSelectedSecondaryMenuOption()).next().find("a.secondaryMenuOptionLink").focus();
678                 $(getSelectedSecondaryMenuOption()).next().find("a.thirdMenuOptionLink").focus();
679                 
680             }
681         }
682     }
683
684 });
685
686 //get selected primary menu option
687 function getSelectedPrimaryMenuOption() {
688     var retValue;
689     $.each($(".primaryMenuContainer .primaryMenuOption"), function(index, value) {
690         var primaryLink = $(this).find("a.primaryMenuOptionLink");
691         if ($(primaryLink).hasClass("selectedPrimaryMenuOption")) {
692             retValue = $(this);
693         }
694     });
695     return retValue;
696 }
697
698 //get selected secondary menu option
699 function getSelectedSecondaryMenuOption() {
700     var retValue;
701     $.each($(".secondaryMenuContentContainer .secondaryMenuOption"), function(index, value) {
702         if( $(this).find("div.selectionDiv") != null &&  $(this).find("div.selectionDiv").is(':visible')) {
703             retValue = $(this);
704         }
705     });
706     return retValue;
707 }
708
709 /* End of Code related to the CATO compliance for navigation through key board */
710
711 /* On click of home page name in the primary menu (available on scroll). */
712 $(document).on('click', '.pageName', function(ev) {
713
714     window.scrollTo(0, 0);
715 });
716
717 $(".headerContentContainer").on("mouseenter", function() {
718
719   /*  $('.categoryContainerColumn').remove();*/
720     $('.megaMenuContainer').scrollTop(0);
721     $('.megaMenuContainer').hide();
722     $(".selectionDiv").hide();
723     $('.secondaryMenuOptionLink').removeClass('selectedSecondaryMenuOption');
724     $('.thirdMenuOptionLink').removeClass('selectedSecondaryMenuOption');
725     
726     if (homePageNameInfo) {
727
728         $.each($('.secondaryMenuOptionLink'), function() {
729
730             var $this = $(this);
731
732             if ($this.hasClass("homePageNameHighlight")) {
733
734                 highlightHomePageNameInSecMenu($this);
735             }
736         });
737     }
738     
739     if (homePageNameInfo) {
740
741         $.each($('.thirdMenuOptionLink'), function() {
742
743             var $this = $(this);
744
745             if ($this.hasClass("homePageNameHighlight")) {
746
747                 highlightHomePageNameInSecMenu($this);
748             }
749         });
750     }
751     
752 });
753
754 /* On click of any secondary menu option. */
755 $(document).on('click keyup', '.secondaryMenuOptionLink', function(ev) {
756     if (ev.keyCode==13 || ev.type=='click') {
757            var $this = $(this);
758             if (homePageNameInfo) {
759                 if ($.trim($this.html().split("<")[0]) != homePageNameInfo.name) {
760                         $this.parents(".secondaryMenuOption").find(".selectionDiv").hide();
761                         $this.removeClass('selectedSecondaryMenuOption');
762                 }
763             }
764     }
765     }
766 );
767 $(document).on('click keyup', '.thirdMenuOptionLink', function(ev) {
768     if (ev.keyCode==13 || ev.type=='click') {
769            var $this = $(this);
770             if (homePageNameInfo) {
771                 if ($.trim($this.html().split("<")[0]) != homePageNameInfo.name) {
772                         $this.parents(".secondaryMenuOption").find(".selectionDiv").hide();
773                         $this.removeClass('selectedSecondaryMenuOption');
774                 }
775             }
776     }
777     }
778 );
779
780
781     /* On click of any bdLink create Session. */
782     $(document).on('click','.bdLink', function(ev){
783         var $this = $(this);
784         var attr = $this.attr('href');
785
786         if (typeof attr !== typeof undefined && attr !== false) {
787             BdNotify.createSessionForBDLinks(ev, $this.attr("href"));
788         }
789     });
790
791
792 /*      getProfileData = function(){
793                 $.ajax({
794                         type: "post",
795                         dataType: 'json',
796                         url: window.dashboardContext + "",
797                         success: function (data) {
798                                 if(data){
799                                         loginId = data.profileData.repositoryId;
800                                         digitalData.user[0].profile[0].profileInfo.profileID = "";
801                                     digitalData.user[0].profile[0].attributes.profileRole = data.profileData.userRole;
802                                 }
803                         },
804                         error: function (){
805                                 console.log("error");
806                         }
807                  });
808         }
809 */
810     // BD Tools Menu changes
811
812
813 /*    getProfileData = function(){
814         $.ajax({
815             type: "post",
816             dataType: 'json',
817             url: window.dashboardContext + "",
818             success: function (data) {
819                 if(data){
820                     loginId = data.profileData.repositoryId;
821                 }
822             },
823             error: function (){
824                 if (typeof console == 'object') {
825                         console.log("error");
826                 }
827             }
828          });
829     }*/
830
831 /*       if(!wcaUser) {
832               getProfileData();
833        }*/
834     BdNotify = {
835         createSessionForBDLinks : function(ev, urlOpen) {
836             ev.preventDefault();
837             $.ajax({
838                 type:"post",
839                 dataType: 'json',
840                 headers: {"authSecurityToken" : window.authSecurityToken},
841                 url: window.ebizDashboardContext +'/bd/createSession',  
842                                 contentType: "application/json; charset=utf-8",
843                                 Accept: "application/json",
844                 async: true,
845                 success : function(response){
846                     var sessionResponse = eval(response);
847                     var acss = null;
848                     var weigs = null;
849                     var tid = null;
850                     if(sessionResponse.sessionId != null && null != sessionResponse.sessionPwd && null != sessionResponse.bdProfileId){
851                         tid = sessionResponse.sessionId + ":" + sessionResponse.sessionPwd+ ":"+sessionResponse.bdProfileId;
852                     }
853
854                     if(null != sessionResponse.acssipAddress && null != sessionResponse.accexpires && null != sessionResponse.acsshash && null !=sessionResponse.acssuser && null != sessionResponse.acsstime ){
855                         acss = "ip&"+sessionResponse.acssipAddress+ "&expires&"+sessionResponse.acssexpires+"&hash&"+sessionResponse.acsshash+"&user&"+sessionResponse.acssuser+"&time&"+sessionResponse.acsstime;
856                     }
857                     if(null != sessionResponse.weigsIpAddress && null != sessionResponse.weigsExpires && null != sessionResponse.weigsHash && null != sessionResponse.weigsUser && null != sessionResponse.weigsTime){
858                         weigs = "ip&"+sessionResponse.weigsIpAddress+ "&expires&"+sessionResponse.weigsExpires+"&hash&"+sessionResponse.weigsHash+"&user&"+sessionResponse.weigsUser+"&time&"+sessionResponse.weigsTime;
859                     }
860
861
862                     if(null != tid){
863                          document.cookie = "ECCUser="+tid+"; path=/; domain=.att.com";
864                     }
865                     if(null != acss){
866                     document.cookie = "ACSS_LOGIN="+acss+"; path=/; domain=.att.com";
867                     }
868                     if(null != weigs){
869                     document.cookie = "WEIGS="+weigs+"; path=/; domain=.att.com";
870                     }
871
872
873
874                     document.cookie = "BDTimeOutEnabled=Y; path=/; domain=.att.com";
875
876                     bdSessionId=sessionResponse.sessionId;
877                     bdToolsWindow = window.open(urlOpen,'BDApplication','left=0,top=0,width=900,height=300,status=0,resizable=1,scrollbars=1');
878                     
879                     // TODO: fix the session timeout and the session check
880                     setTimeout(BdNotify.checkBDTimeoutAndExtendSession, 1000*60*checkSessionIntervalMins);
881                 }
882             });
883         },
884
885         checkBDTimeoutAndExtendSession : function(){
886             if(bdToolsWindow!=null && !bdToolsWindow.closed){
887                 //console.log("TimeOut***************************"+ bdSessionId);
888                 $.ajax({
889                     type:"post",
890                     dataType: 'json',
891                     // url: '/rest/model/com/att/b2b/ebcare/rest/actorchain/EBizCareServiceActor/terminateSession?userId='+loginId+'&bdSessionId='+ bdSessionId,
892                     url: window.ebizDashboardContext +'/bd/'+bdSessionId+'/checkSession',
893                     async: false,
894                     success : function(response){
895                         var sessionResponse = eval(response);
896                         if(sessionResponse>=0){
897                                 
898                                 if(sessionResponse >= bdSessionTimeout ) {
899                                         // call terminate
900                                         terminateBDSession();
901                                 } else {
902                                         // TODO: return timeToExpire from controller
903                                         //      var timeToExpire = sessionResponse.BD_TIMEOUT - sessionResponse.LAST_ACCESS_BD_TIME;
904                             //Set Timeout to call same function again after 25 mins
905                             setTimeout(BdNotify.checkBDTimeoutAndExtendSession, 1000*60*checkSessionIntervalMins);
906                         }
907                         }
908                     },
909                     error : function(e){
910
911                     }
912                 });
913             }
914         }
915     }
916
917     //End of BD Tools menu changes
918
919
920     /* Click event for the links provided in the mega menu. */
921     $(document).on('click','.categoryOptionLink',function(ev){
922         $('.megaMenuContainer').scrollTop(0);
923         $('.megaMenuContainer').hide();
924         window.scrollTo(0, 0);
925     });
926
927 $(document).on('click', '.secondaryMenuContainer', function(ev) {
928
929     $('.megaMenuContainer').scrollTop(0);
930     $('.megaMenuContainer').hide();
931 });
932
933 /* Display Mega menu on hovering over any of the secondary menu links. */
934 $(document).on('touchstart mouseenter focus', '.secondaryMenuOptionLink, .pageName', function(ev) {
935     editHeaderMenuForBilling($(this));
936     secondaryMenuItemHover($(this));
937
938     /* Function to handle Menu's on CFD Billing Iframe Pages */
939     iframeHover();
940 });
941
942 $(document).on('touchstart mouseenter focus', '.thirdMenuOptionLink, .pageName', function(ev) {
943     editHeaderMenuForBilling($(this));
944     secondaryMenuItemHover($(this));
945
946     /* Function to handle Menu's on CFD Billing Iframe Pages */
947     iframeHover();
948 });
949
950 function editHeaderMenuForBilling(Obj) {
951     var url = window.location.pathname;
952     var $this = $(Obj);
953
954     //If it is CFD Billing Iframe Page
955     if (url == "/ebiz/billing/iframe.jsp" && $.trim($this.html().split("<")[0]) == "Billing") {
956         var currentHeaderData = headerData;
957         var errorPage = "/ebiz/billing/error.jsp";
958         var iframeSrc = $("#CFDIframe").attr('src');
959         if (iframeSrc != errorPage) {
960             var MenuArea = $("#CFDIframe").contents().find('.hideMenuArea');
961             if (MenuArea.length != 0) {
962                 var MenuHtml = MenuArea.html();
963                 var payment_array = [];
964                 var report_array = [];
965
966                 var paymentUrls = ["ImplCleanPaymentHistoryAction", "ImplOTPaymentContextSelectAction", "ImplRECPaymentContextSelectAction"];
967                 var reportUrls = ["ImplPreLoadFFReportListAction", "ImplExternalWFReports", "ImplPreLoadRawDataOutputAction", "ImplDeliveryProfilesContextSelectAction"];
968                 for (var i = 0; i < paymentUrls.length; i++) {
969                     if (MenuHtml.indexOf(paymentUrls[i]) >= 0) {
970                         payment_array.push(i + 1);
971                     }
972                 }
973
974                 for (var i = 0; i < reportUrls.length; i++) {
975                     if (MenuHtml.indexOf(reportUrls[i]) >= 0) {
976                         report_array.push(i + 1);
977                     }
978                 }
979
980                 $.each(headerData.childNavigation, function(dataIndex, childNavigation) {
981                     if (childNavigation.name == "Manage") {
982                         var mIndex = dataIndex;
983                         var child1 = childNavigation.childNavigation;
984                         $.each(child1, function(dataIndex, childNavigation) {
985                             if (childNavigation.name == "Billing") {
986                                 var bIndex = dataIndex;
987                                 var child2 = childNavigation.childNavigation;
988                                 $.each(child2, function(dataIndex, childNavigation) {
989                                     if (childNavigation.name == "Payments") {
990                                         var pIndex = dataIndex;
991                                         var child3 = childNavigation.childNavigation;
992                                         headerData.childNavigation[mIndex].childNavigation[bIndex].childNavigation[pIndex].childNavigation = [];
993
994                                         $.each(payment_array, function(dataIndex, item) {
995                                             if (item == 1) {
996                                                 headerData.childNavigation[mIndex].childNavigation[bIndex].childNavigation[pIndex].childNavigation.push({
997                                                     "childNavigation": [],
998                                                     "id": "600153",
999                                                     "name": "Payment History",
1000                                                     "url": "/ebiz/billing/iframe.jsp?destUrl=ImplCleanPaymentHistoryAction.do"
1001                                                 });
1002                                             } else if (item == 2) {
1003                                                 headerData.childNavigation[mIndex].childNavigation[bIndex].childNavigation[pIndex].childNavigation.push({
1004                                                     "childNavigation": [],
1005                                                     "id": "600155",
1006                                                     "name": "One Time Payment",
1007                                                     "url": "/ebiz/billing/iframe.jsp?destUrl=ImplOTPaymentContextSelectAction.do"
1008                                                 });
1009                                             } else if (item == 3) {
1010                                                 headerData.childNavigation[mIndex].childNavigation[bIndex].childNavigation[pIndex].childNavigation.push({
1011                                                     "childNavigation": [],
1012                                                     "id": "600157",
1013                                                     "name": "Recurring Payments",
1014                                                     "url": "/ebiz/billing/iframe.jsp?destUrl=ImplRECPaymentContextSelectAction.do"
1015                                                 });
1016                                             }
1017                                         });
1018                                     } else if (childNavigation.name == "Reports") {
1019                                         var pIndex = dataIndex;
1020                                         var child3 = childNavigation.childNavigation;
1021                                         headerData.childNavigation[mIndex].childNavigation[bIndex].childNavigation[pIndex].childNavigation = [];
1022
1023                                         $.each(report_array, function(dataIndex, item) {
1024                                             if (item == 1) {
1025                                                 headerData.childNavigation[mIndex].childNavigation[bIndex].childNavigation[pIndex].childNavigation.push({
1026                                                     "childNavigation": [],
1027                                                     "id": "600159",
1028                                                     "name": "Create/View Customized Reports",
1029                                                     "url": "/ebiz/billing/iframe.jsp?destUrl=ImplPreLoadFFReportListAction.do"
1030                                                 });
1031                                             } else if (item == 2) {
1032                                                 headerData.childNavigation[mIndex].childNavigation[bIndex].childNavigation[pIndex].childNavigation.push({
1033                                                     "childNavigation": [],
1034                                                     "id": "600161",
1035                                                     "name": "Bill Analysis",
1036                                                     "url": "/ebiz/billing/iframe.jsp?destUrl=ImplExternalWFReports.do"
1037                                                 });
1038                                             } else if (item == 3) {
1039                                                 headerData.childNavigation[mIndex].childNavigation[bIndex].childNavigation[pIndex].childNavigation.push({
1040                                                     "childNavigation": [],
1041                                                     "id": "600163",
1042                                                     "name": "Raw Data Output",
1043                                                     "url": "/ebiz/billing/iframe.jsp?destUrl=ImplPreLoadRawDataOutputAction.do"
1044                                                 });
1045                                             } else if (item == 4) {
1046                                                 headerData.childNavigation[mIndex].childNavigation[bIndex].childNavigation[pIndex].childNavigation.push({
1047                                                     "childNavigation": [],
1048                                                     "id": "600165",
1049                                                     "name": "Delivery Profiles",
1050                                                     "url": "/ebiz/billing/iframe.jsp?destUrl=ImplDeliveryProfilesContextSelectAction.do"
1051                                                 });
1052                                             }
1053
1054                                         });
1055                                     }
1056                                 });
1057                             }
1058                         });
1059                     }
1060                 });
1061             }
1062         }
1063     }
1064 }
1065 /* For all the pages except CFD Iframe Page */
1066 function iframeHover() {
1067     var url = window.location.pathname;
1068     //If it is CFD Billing Iframe Page
1069     if (url == "/ebiz/billing/iframe.jsp") {
1070         $("a.categoryOptionLink").click(function() {
1071             var status_url = $(this).attr('href').split('destUrl=')[1].split('&')[0];
1072             if (status_url != null && status_url != undefined) {
1073                 $('iframe').attr('src', cfd_handoff_url + '/businesscare-ebill/' + status_url);
1074                 if (history.pushState) {
1075                     history.pushState('', 'AT&amp;T Billing', 'iframe.jsp?destUrl=' + status_url);
1076                 }
1077
1078                 $('.megaMenuContainer').scrollTop(0);
1079                 $('.megaMenuContainer').hide();
1080                 window.scrollTo(0, 0);
1081
1082                 return false;
1083             } else {
1084                 return true;
1085             }
1086         });
1087     } else {
1088         return true;
1089     }
1090
1091 }
1092
1093 $(document).on('mouseleave', '.secondaryMenuOptionLink', function(ev) {
1094
1095     if ($(".megaMenuContainer").is(":hidden")) {
1096
1097         if (homePageNameInfo) {
1098
1099            $.each($('.secondaryMenuOptionLink'), function() {
1100
1101                 var $this = $(this);
1102
1103                 if ($this.hasClass("homePageNameHighlight")) {
1104
1105                     highlightHomePageNameInSecMenu($this);
1106                 }
1107             });
1108         }
1109     }
1110 });
1111
1112 $(document).on('mouseleave', '.thirdMenuOptionLink', function(ev) {
1113
1114     if ($(".megaMenuContainer").is(":hidden")) {
1115
1116         if (homePageNameInfo) {
1117
1118            $.each($('.thirdMenuOptionLink'), function() {
1119
1120                 var $this = $(this);
1121
1122                 if ($this.hasClass("homePageNameHighlight")) {
1123
1124                     highlightHomePageNameInSecMenu($this);
1125                 }
1126             });
1127         }
1128     }
1129 });
1130
1131
1132 /* Hide the Mega menu on mouseleave. */
1133 $(document).on('mouseleave', '.megaMenuContainer', function(ev) {
1134   /*  $('.categoryContainerColumn').remove();*/
1135     $('.megaMenuContainer').scrollTop(0);
1136     $('.megaMenuContainer').hide();
1137     $(".selectionDiv").hide();
1138     $('.secondaryMenuOptionLink').removeClass('selectedSecondaryMenuOption');
1139     $('.thirdMenuOptionLink').removeClass('selectedSecondaryMenuOption');
1140
1141     if (homePageNameInfo) {
1142
1143         $.each($('.secondaryMenuOptionLink'), function() {
1144
1145             var $this = $(this);
1146
1147             if ($this.hasClass("homePageNameHighlight")) {
1148
1149                 highlightHomePageNameInSecMenu($this);
1150             }
1151         });
1152         $.each($('.thirdMenuOptionLink'), function() {
1153
1154             var $this = $(this);
1155
1156             if ($this.hasClass("homePageNameHighlight")) {
1157
1158                 highlightHomePageNameInSecMenu($this);
1159             }
1160         });
1161         
1162         
1163     }
1164 });
1165
1166 /* On scroll of the page, display the name of the page in the primary menu.
1167               On scrolling back to the top, display the original primary menu. */
1168 $(window).on('scroll', function() {
1169     if($('.mapHeader').is(':visible')){
1170         return false;
1171     } else {
1172         $('.secondaryMenuContainer').hide();
1173         $('.primaryMenuOptionLink').removeClass("selectedPrimaryMenuOption");
1174         $('.selectedOptionIndicator').hide();
1175         $('.megaMenuContainer').scrollTop(0);
1176         $('.megaMenuContainer').hide();
1177         $('.primaryMenuOptionsContainer').hide();
1178         $(".pageNameContainer").show();
1179         if ($(window).scrollTop() === 0) {
1180                 if(!($('.switch-message-div').is(':visible'))){
1181                 $(".dashboardHeadIcons").css("top","90px");
1182               }
1183               else{
1184                  $(".dashboardHeadIcons").css("top","127px");
1185               }
1186             $('.primaryMenuOptionsContainer').show();
1187             var currentUrl = window.location.href;
1188             if(currentUrl != null){
1189                 var emaintenanceMatch = currentUrl.search('emaintenance');
1190                 if(emaintenanceMatch >= 0){
1191                     $(".secondaryMenuContainerForApplication").show();
1192                     $('.selectedOptionIndicator').show();
1193                 }
1194             }
1195             if (homePageNameInfo) {
1196                 showSecondaryMenu(homePageNameInfo);
1197             }
1198             $(".pageNameContainer").hide();
1199         } else {
1200             if ($(".pageNameContainer .pageName").length && $(".pageNameContainer .pageName").text() !== "") {
1201                 $('.primaryMenuOptionsContainer').hide();
1202                 $(".pageNameContainer").show();
1203             } else {
1204                 $('.primaryMenuOptionsContainer').show();
1205                 $(".pageNameContainer").hide();
1206             }
1207         }
1208     }
1209 });
1210       $(".reg-logout-btn").click(function(){
1211           if(bdToolsWindow!=null && !bdToolsWindow.closed){
1212           // console.log("log-out with Session Id" + bdSessionId);
1213             bdToolsWindow.close();
1214             terminateBDSession();
1215 /*            $.ajax({
1216                 type:"delete",
1217                 dataType: 'json',
1218                 // url: '/rest/model/com/att/b2b/ebcare/rest/actorchain/EBizCareServiceActor/terminateSession?byPassLastAccess=true&userId='+loginId+'&bdSessionId='+ bdSessionId,
1219                 url: window.ebizDashboardContext +'/bd/'+bdSessionId+'/terminateSession',
1220                 async: false,
1221                 success : function(response){
1222                     // console.log("BD-LOG-OUT-Sucess");
1223                 },
1224                 error : function(e){
1225                     // console.log("BD-LOG-OUT-Error");
1226                 }
1227             });*/
1228
1229          }
1230     /* Commenting the logout code.As logout functionality is handled by the regular form submition.
1231          $.ajax({
1232             type: "get",
1233             dataType: 'json',
1234             url: "/rest/model/atg/userprofiling/ProfileActor/logout",
1235             async: false,
1236             success: function (response) {
1237                 // console.log("dashboard logout success");
1238             },
1239             error: function (){
1240                 window.location.href = "/ebiz/registration/index.jsp?DPSLogout=true";
1241                 // console.log("dashboard logout error");
1242             }
1243         } );*/
1244
1245     });
1246       
1247       function terminateBDSession() {
1248           $.ajax({
1249               type:"delete",
1250               dataType: 'json',
1251               // url: '/rest/model/com/att/b2b/ebcare/rest/actorchain/EBizCareServiceActor/terminateSession?byPassLastAccess=true&userId='+loginId+'&bdSessionId='+ bdSessionId,
1252               url: window.ebizDashboardContext +'/bd/'+bdSessionId+'/terminateSession',
1253               async: false,
1254               success : function(response){
1255                   // console.log("BD-LOG-OUT-Sucess");
1256               },
1257               error : function(e){
1258                   // console.log("BD-LOG-OUT-Error");
1259               }
1260           });             
1261       };
1262       /*
1263        * Function Definition to Get Click To Chat Data
1264        * ========================================== */
1265           function getClickToChatData() {
1266              /* $.ajax({
1267                   type: "get",
1268                   dataType: 'json',
1269                   contentType :'application/json',
1270                   url: window.ebizDashboardContext + "/clicktochat",
1271                   success: populateClickToChat,
1272                   error: function() {},
1273                   complete: clickToChatPopBox
1274               });*/
1275           }
1276
1277           function populateClickToChat(response) {
1278
1279                   var template = Handlebars.compile($("#clickToChatMultiple_tmpl").html());
1280                   var clickToChat = template(response);
1281                   $(".headerIconContainer").append(clickToChat);
1282              
1283           };
1284
1285           function clickToChatPopBox() {
1286              /* var chatbox = $('.chatBox');
1287
1288               var methods = {
1289                 open: function(){chatbox.css('display','block');},
1290                 close: function(){chatbox.fadeOut('fast');}
1291               };
1292                $(document).on('click keyup ', '.chatIcon', function(ev) {
1293                      if(ev.keyCode==13 || ev.type=='click'){
1294                     //$('.chatIcon').click(function()
1295                 if (chatbox.css('display') == 'block'){
1296                   methods.close();
1297                   setTimeout(function(){ $(".btn-panel-vertical,#actionsDropDown").css('z-index','999'); },200);
1298                   if($(window).scrollTop() > 20){
1299                        setTimeout(function(){ $(".btn-panel-vertical,#actionsDropDown").css('z-index','-999'); },200);
1300                   };
1301                 } else {
1302                    $(".btn-panel-vertical,#actionsDropDown").css('z-index','-999');
1303                   methods.open();
1304                   $(settings['box']).fadeOut("fast");
1305                       }   }
1306               });
1307 */
1308               // Close chat-box on clicking cross icon
1309               $('.circle_close_chat').click(function(){
1310                 setTimeout(function(){ $(".btn-panel-vertical,#actionsDropDown").css('z-index','999'); },200);
1311                 methods.close();
1312                 if($(window).scrollTop() > 20){
1313                    setTimeout(function(){ $(".btn-panel-vertical,#actionsDropDown").css('z-index','-999'); },200);
1314                 };
1315               });
1316
1317               // Close chat-box on Escape key press
1318               $(document).bind('keyup', function(event){
1319                 if(event.keyCode == 27){ 
1320                   setTimeout(function(){ $(".btn-panel-vertical,#actionsDropDown").css('z-index','999'); },200);
1321                /*   methods.close();*/
1322                   if($(window).scrollTop() > 20){
1323                        setTimeout(function(){ $(".btn-panel-vertical,#actionsDropDown").css('z-index','-999'); },200);
1324                   };
1325                 }
1326               });        
1327           };
1328
1329           function JSONLength(json) {
1330               var length = 0;
1331               for (var key in json) {
1332                   length++;
1333               };
1334               return length;
1335           };
1336
1337           function prepareData(data) {
1338               var modifiedJSON = {options: []};
1339               for (var key in data) {
1340                   var temp = {linkName:key, linkValue:data[key]};
1341                   modifiedJSON['options'].push(temp);
1342               };
1343               return modifiedJSON;
1344           };
1345
1346           getClickToChatData();      
1347 });
1348
1349 $('.emailAddress input').focus(function() {
1350     var dispVal = $(this).val();
1351     if (dispVal == "Email Address") {
1352         $(this).val("");
1353     }
1354 }).blur(function() {
1355     var dispVal1 = $(this).val();
1356     if (dispVal1 == "") {
1357         $(this).val("Email Address");
1358     }
1359 });
1360
1361 $(document).bind("ajaxSend", function(elm, xhr, s){
1362        if (s.type == "POST" || s.type == "GET") {
1363               var token = window.softToken;
1364               xhr.setRequestHeader('X-CSRF-Token', token);
1365               }
1366        });
1367 $(document).ready(function() {
1368     onClickOfMenu = function(url){
1369         $('.megaMenuContainer').scrollTop(0);
1370         $('.megaMenuContainer').hide();
1371         window.scrollTo(0, 0);
1372         menuClicked =  url;
1373         window.location.href = url;
1374     }
1375 });