Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / static / fusion / raptor / js / nova_button.js
1 function NovaButton() {
2
3 }
4
5 NovaButton.prototype = new GControl();
6
7 NovaButton.globals = {
8         currentButton: null,
9         layerOptionContainer: null,
10         layerOptionVisible: false,
11         searchOptionContainer: null,
12         searchOptionVisible: false,
13         //new changes
14         searchResultContainer: null,
15         //new changes
16         searchTabSelected: null,
17         map: null,
18         originalLayerState: null
19 };
20
21 NovaButton.globals.dragzoom = {
22   cornerTopDiv: null,
23   cornerRightDiv: null,
24   cornerBottomDiv: null,
25   cornerLeftDiv: null,
26   mapPosition: null,
27   outlineDiv: null,
28   mapWidth: 0,
29   mapHeight: 0,
30   mapRatio: 0,
31   startX: 0,
32   startY: 0,
33   zoomArea: null,
34   moving: false
35 };
36
37 //      Creates a one DIV for each of the buttons and places them in a container
38 //      DIV which is returned as our control element.
39 NovaButton.prototype.initialize = function(map) {
40         var container = document.createElement("div");
41         container.style.zIndex = "150";
42         var that = this;
43         
44         // "Cursor" button
45         var cursorDiv = document.createElement("div");
46         cursorDiv.id = "cursorDiv";
47         NovaButton.globals.currentButton = "cursorDiv";
48         this.setButtonStyle(cursorDiv, true);
49         cursorDiv.style.fontWeight = "bold";
50         cursorDiv.appendChild(document.createTextNode("Cursor"));
51         GEvent.addDomListener(cursorDiv, "click", function() {
52                 var globals = NovaButton.globals;
53                 if (globals.currentButton == "cursorDiv") {
54                         return;
55                 }
56           
57           this.style.fontWeight = "bold";
58           globals.currentButton = "cursorDiv";
59           if (!map.draggingEnabled()) {
60                 map.enableDragging();
61         }
62           document.getElementById("detailDiv").style.fontWeight = "normal";
63           document.getElementById("zoomRectangleDiv").style.fontWeight = "normal";
64           
65           that.resetDragZoom();
66         });
67         
68         // "detail" button
69         var detailDiv = document.createElement("div");
70         detailDiv.id = "detailDiv";
71         this.setButtonStyle(detailDiv, true);
72         detailDiv.appendChild(document.createTextNode("Detail"));
73         GEvent.addDomListener(detailDiv, "click", function() {
74           var globals = NovaButton.globals;
75                 if (globals.currentButton == "detailDiv") {
76                         return;
77                 } 
78                 
79           this.style.fontWeight = "bold";
80           globals.currentButton = "detailDiv";
81           if (map.draggingEnabled()) {
82                 map.disableDragging();
83         }
84           document.getElementById("cursorDiv").style.fontWeight = "normal";
85           document.getElementById("zoomRectangleDiv").style.fontWeight = "normal";
86           
87           that.resetDragZoom();
88         });
89         
90         // zoom rectangle button
91         var zoomRectangleDiv = document.createElement("div");
92         zoomRectangleDiv.id = "zoomRectangleDiv";
93         this.setButtonStyle(zoomRectangleDiv, true);
94         zoomRectangleDiv.appendChild(document.createTextNode("Zoom Rect."));
95         GEvent.addDomListener(zoomRectangleDiv, "click", function() {
96                 var globals = NovaButton.globals;
97                 if (globals.currentButton == "zoomRectangleDiv") {
98                         return;
99                 }
100                 
101           this.style.fontWeight = "bold";
102           globals.currentButton = "zoomRectangleDiv";
103           
104           if (map.draggingEnabled()) {
105                 map.disableDragging();
106         }
107         document.getElementById("cursorDiv").style.fontWeight = "normal";
108         document.getElementById("detailDiv").style.fontWeight = "normal";
109         
110     that.initCover();
111         });
112         
113         // "Zoom In" button
114         var zoomInDiv = document.createElement("div");
115         this.setButtonStyle(zoomInDiv, true);
116         zoomInDiv.appendChild(document.createTextNode("Zoom In"));
117         // The "true" argument in the zoomIn() method allows continuous zooming
118         GEvent.addDomListener(zoomInDiv, "click", function() {
119                 //map.zoomIn(null,null,true);
120                 map.zoomIn();
121         });
122
123         // "Zoom Out" button
124         var zoomOutDiv = document.createElement("div");
125         this.setButtonStyle(zoomOutDiv, true);
126         zoomOutDiv.style.borderTop = 0+'px';
127         zoomOutDiv.appendChild(document.createTextNode("Zoom Out"));
128         // The "true" argument in the zoomOut() method allows continuous zooming
129         GEvent.addDomListener(zoomOutDiv, "click", function() {
130                 //map.zoomOut(null,true);
131                 map.zoomOut();
132         });
133         
134         // "Default View" button
135         var defaultViewDiv = document.createElement("div");
136         this.setButtonStyle(defaultViewDiv, true);
137         defaultViewDiv.appendChild(document.createTextNode("Default View"));
138         GEvent.addDomListener(defaultViewDiv, "click", function(e) {
139           that.defaultViewClickEvent();
140         });
141         
142         // "layer" button
143         var showLayerDiv = document.createElement("div");
144         this.setButtonStyle(showLayerDiv, true);
145         showLayerDiv.appendChild(document.createTextNode("Layers"));
146         GEvent.addDomListener(showLayerDiv, "click", function(e) {
147                 that.showLayerClickEvent(e);
148         });
149         
150         // initialize layer option
151         var layerOptionContainer = document.createElement("div");
152         this.setMenuContainerStyle(layerOptionContainer);
153         this.initializeLayerDiv(layerOptionContainer);
154         
155         // "search" button
156         var searchDiv = document.createElement("div");
157         this.setButtonStyle(searchDiv, true);
158         searchDiv.appendChild(document.createTextNode("Search"));
159         GEvent.addDomListener(searchDiv, "click", function(e) {
160                 that.searchClickEvent(e);
161         });
162         
163         var searchOptionContainer = document.createElement("div");
164         searchOptionContainer.style.position = "absolute";
165         searchOptionContainer.style.left = "100px";
166         searchOptionContainer.style.top = "100px";
167         searchOptionContainer.style.display = "none";
168         this.initializeSearchDiv(searchOptionContainer);
169         
170         var buttonContainer = document.createElement("div");
171         buttonContainer.appendChild(cursorDiv);
172         buttonContainer.appendChild(detailDiv);
173         //buttonContainer.appendChild(zoomRectangleDiv);
174         //buttonContainer.appendChild(zoomInDiv);
175         //buttonContainer.appendChild(zoomOutDiv);
176         //buttonContainer.appendChild(defaultViewDiv);
177         //buttonContainer.appendChild(showLayerDiv);
178         //buttonContainer.appendChild(searchDiv);
179         
180         // zoom area div
181   var zoomAreaDiv = document.createElement("div");
182         this.setZoomAreaStyle(zoomAreaDiv);
183   var DIVS_TO_CREATE = ['outlineDiv', 'cornerTopDiv', 'cornerLeftDiv', 'cornerRightDiv', 'cornerBottomDiv'];
184   for (var i=0; i<DIVS_TO_CREATE.length; i++) {
185     var id = DIVS_TO_CREATE[i];
186     var div = document.createElement("div");
187     div.style.position = "absolute";
188     div.style.display = "none";
189     zoomAreaDiv.appendChild(div);
190     NovaButton.globals.dragzoom[id] = div;
191   }
192   
193   GEvent.addDomListener(zoomAreaDiv, 'mousedown', function(e) {
194         that.mouseDown(e);
195         });
196   GEvent.addDomListener(document, 'mousemove', function(e) {
197         that.mouseMove(e);
198   });
199   GEvent.addDomListener(document, 'mouseup', function(e) {
200         that.mouseUp(e);
201   });
202
203         // assign global variable
204         NovaButton.globals.layerOptionContainer = layerOptionContainer;
205         NovaButton.globals.map = map;
206         NovaButton.globals.dragzoom.zoomArea = zoomAreaDiv;
207         NovaButton.globals.dragzoom.mapPosition = NovaButtonUtils.getElementPosition(map.getContainer());
208         NovaButton.globals.searchOptionContainer = searchOptionContainer;
209   this.setDimensions();
210   
211   zoomAreaDiv.onselectstart = function() {return false;};
212   
213   //styles
214   this.initZoomAreaStyles();
215   
216         container.appendChild(buttonContainer);
217         map.getContainer().appendChild(container);
218         //map.getContainer().appendChild(layerOptionContainer);
219         //map.getContainer().appendChild(searchOptionContainer);
220         document.body.appendChild(layerOptionContainer);
221         document.body.appendChild(searchOptionContainer);
222         map.getContainer().appendChild(zoomAreaDiv);
223         
224         return container;
225 }
226
227 //      The control will appear in the top left corner of the map with 5 pixels of padding.
228 NovaButton.prototype.getDefaultPosition = function() {
229         return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(70, 5));
230 }
231
232 NovaButton.prototype.setSearchResultStyle = function(container) {
233   container.style.width = "300px";
234   container.style.height = "150px";
235   container.style.background = "#FFFFF0";
236   container.style.fontFamily = "Verdana";
237   container.style.fontSize = "12px";
238   container.style.position = "absolute";
239   container.style.border = "1px solid black";
240   container.style.top = "201px";
241         container.style.left = "0px";
242         container.style.display = "none";
243         container.style.overflow = "auto";
244   container.align = "left";
245 }
246
247 // Sets the proper CSS for the given button element.
248 NovaButton.prototype.setButtonStyle = function(button, horizontalAlign) {
249   button.style.color = "black";
250         button.style.backgroundColor = "white";
251         button.style.fontFamily = "Verdana";
252         button.style.fontSize = "12px";
253         button.style.fontWeight= "normal";
254         button.style.border = "1px solid gray";
255         button.style.padding = "0px";
256         button.style.marginBottom = "0px";
257         button.style.textAlign = "center";
258         button.style.width = "80px";
259         button.style.height = "15px";
260         button.style.cursor = "pointer";
261         //button.style.zIndex = "200"; 
262         
263         if (horizontalAlign) {
264                 if(button.addEventListener) {
265                         button.style.cssFloat   = "left" ;
266                 }
267                 else {
268                         button.style.styleFloat = "left" ;
269                 }
270         }
271 }
272
273 NovaButton.prototype.setTabHeaderStyle = function(header) {
274         //header.style.position = "absolute";
275         //header.style.zIndex = "2";
276         header.align = "left";
277 }
278
279 NovaButton.prototype.setTabButtonStyle = function(tab) {
280         tab.style.padding = "3px 5px 3px 5px";
281         tab.style.fontFamily = "Verdana";
282         tab.style.fontSize = "12px";
283         tab.style.textAlign = "center";
284         tab.style.width = "7em";
285         tab.style.height = "15px";
286         tab.style.cursor = "pointer";
287         tab.style.background = "#C6DEFF";
288         
289         if(tab.addEventListener) {
290                 tab.style.cssFloat      = "left" ;
291         }
292         else {
293                 tab.style.styleFloat = "left" ;
294         }
295 }
296
297 NovaButton.prototype.setTabBodyStyle = function(body) {
298         body.style.width = "400px";
299         body.style.height = "150px";
300         body.style.background = "#FFFFF0";
301         body.style.fontFamily = "Verdana";
302         body.style.fontSize = "12px";
303         //body.style.zIndex = "1";
304         body.style.padding = "3px 5px 3px 5px";
305         body.style.top = "20px";
306         body.style.left = "0px";
307         body.style.position = "absolute";
308         body.style.display = "none";
309         body.align = "left";
310 }
311
312 NovaButton.prototype.setTabFooterStyle = function(footer) {
313         footer.style.width = "400px";
314         footer.style.height = "20px";
315         footer.align = "center";
316         footer.style.padding = "3px 5px 3px 5px";
317         footer.style.background = "#FFFFF0";
318         footer.style.position = "absolute";
319         footer.style.top = "175px";
320         footer.style.left = "0";
321 }
322
323 NovaButton.prototype.tabMouseOver = function(e) {
324   var tab = Event.element(e);
325   tab.style.background = "#ADDFFF";
326 }
327
328 NovaButton.prototype.tabMouseOut = function(e) {
329   var tab = Event.element(e);
330   tab.style.background = "#C6DEFF";
331 }
332
333 NovaButton.prototype.tabClickEvent = function(e) {
334   var tab = Event.element(e);
335   
336   if (tab.id == NovaButton.globals.searchTabSelected) {
337     return false;
338   }
339   
340   NovaButton.globals.searchTabSelected = tab.id;
341   tab.style.fontWeight = "bold";
342   
343   if (tab.id == "nodeTab") {
344         document.getElementById("nodeBody").style.display = "inline";
345         document.getElementById("addressBody").style.display = "none";
346         document.getElementById("addressTab").style.fontWeight = "normal";
347   }
348   else {
349         document.getElementById("addressBody").style.display = "inline";
350         document.getElementById("nodeBody").style.display = "none";
351         document.getElementById("nodeTab").style.fontWeight = "normal";
352   }
353 }
354
355 NovaButton.prototype.initializeSearchDiv = function(searchOptionContainer) {
356   var header = document.createElement("div");
357   this.setTabHeaderStyle(header);
358   var that = this;
359   
360   var nodeTab = header.appendChild(document.createElement("div"));
361   nodeTab.id = "nodeTab";
362   this.setTabButtonStyle(nodeTab);
363   nodeTab.appendChild(document.createTextNode("Node"));
364   GEvent.addDomListener(nodeTab, "mouseover", function(e) {
365     that.tabMouseOver(e);
366   });
367   GEvent.addDomListener(nodeTab, "mouseout", function(e) {
368         that.tabMouseOut(e);
369   });
370   GEvent.addDomListener(nodeTab, "click", function(e) {
371     that.tabClickEvent(e);
372   });
373   
374   var addressTab = header.appendChild(document.createElement("div"));
375   addressTab.id = "addressTab";
376   this.setTabButtonStyle(addressTab);
377   addressTab.appendChild(document.createTextNode("Address"));
378   GEvent.addDomListener(addressTab, "mouseover", function(e) {
379     that.tabMouseOver(e);
380   });
381   GEvent.addDomListener(addressTab, "mouseout", function(e) {
382         that.tabMouseOut(e);
383   });
384   GEvent.addDomListener(addressTab, "click", function(e) {
385         that.tabClickEvent(e);
386   });
387   
388   var body = document.createElement("div");
389   var nodeBody = body.appendChild(document.createElement("div"));
390   nodeBody.id = "nodeBody";
391   this.setTabBodyStyle(nodeBody);
392         this.initializeNodeBody(nodeBody);
393   
394   var addressBody = body.appendChild(document.createElement("div"));
395   addressBody.id = "addressBody";
396   this.setTabBodyStyle(addressBody);
397   this.initializeAddressBody(addressBody);
398   
399   //new changes
400   var searchResultContainer = body.appendChild(document.createElement("div"));
401   searchResultContainer.style.opacity = "0.8";
402   searchResultContainer.style.filter = 'alpha(opacity=' + (0.6 * 100) + ')';
403   this.setSearchResultStyle(searchResultContainer);
404   //new changes
405   
406   var footer = document.createElement("div");
407   this.setTabFooterStyle(footer);
408   var buttonDiv = footer.appendChild(document.createElement("div"));
409   this.setButtonStyle(buttonDiv, false);
410   buttonDiv.appendChild(document.createTextNode("Submit"));
411         GEvent.addDomListener(buttonDiv, "click", function(e) {
412                 that.submitSearchClickEvent(e);
413         });
414
415   searchOptionContainer.appendChild(header);
416   searchOptionContainer.appendChild(body);
417   searchOptionContainer.appendChild(footer);
418   //searchOptionContainer.appendChild(nodeBody);
419   //searchOptionContainer.appendChild(addressBody);
420   
421   // default tab
422   nodeTab.style.fontWeight = "bold";
423         nodeBody.style.display = "inline";
424   NovaButton.globals.searchTabSelected = "nodeTab";
425   //new changes
426   NovaButton.globals.searchResultContainer = searchResultContainer;
427   //new chjanges
428 }
429
430 NovaButton.prototype.initializeNodeBody = function(nodeBody) {
431         var searchByNodeId = document.createElement("input");
432         searchByNodeId.type = "radio";
433         searchByNodeId.defaultChecked = true;
434         searchByNodeId.name = "nodeGroup";
435         searchByNodeId.id = "searchByNodeId";
436         searchByNodeId.value = "searchByNodeId";
437         searchByNodeId.onclick = function () {
438           searchByLocation.checked = false;
439           searchByNodeId.checked = true;
440         };
441         nodeBody.appendChild(searchByNodeId);
442         nodeBody.appendChild(document.createTextNode("Node ID"));
443         nodeBody.appendChild(document.createElement("br"));
444         
445         var searchByLocation = document.createElement("input");
446         searchByLocation.type = "radio";
447         searchByLocation.defaultChecked = false;
448         searchByLocation.name = "nodeGroup";
449         searchByLocation.id = "searchByLocation";
450         searchByLocation.value = "searchByLocation";
451         // ie bug
452         searchByLocation.onclick = function () {
453           searchByLocation.checked = true;
454           searchByNodeId.checked = false;
455         };
456         nodeBody.appendChild(searchByLocation);
457         nodeBody.appendChild(document.createTextNode("Node Location"));
458         nodeBody.appendChild(document.createElement("br"));
459         nodeBody.appendChild(document.createElement("br"));
460         
461         var exactMatchSearch = document.createElement("input");
462         exactMatchSearch.type = "checkbox";
463         exactMatchSearch.id = "exactMatch";
464         nodeBody.appendChild(exactMatchSearch);
465         nodeBody.appendChild(document.createTextNode("Exact Match"));
466         nodeBody.appendChild(document.createElement("br"));
467         
468   var searchInput = document.createElement("input");
469         searchInput.id = "nodeSearchInput";
470   searchInput.setAttribute("type", "text");
471   searchInput.setAttribute("size", "60");
472
473         nodeBody.appendChild(searchInput);
474 }
475
476 NovaButton.prototype.initializeAddressBody = function(addressBody) {
477   var addressLabel = addressBody.appendChild(document.createElement("div"));
478   addressLabel.appendChild(document.createTextNode("Enter address (e.g. 180 park ave, florham park, nj 07932)"));
479
480   var searchInput = document.createElement("input");
481   searchInput.id = "addressSearchInput";
482   searchInput.setAttribute("type", "text");
483   searchInput.setAttribute("size", "60");
484   
485   addressBody.appendChild(searchInput);
486 }
487
488 //new changes start
489 NovaButton.prototype.setSearchResult = function(jsonData) {
490   var resultContainer = NovaButton.globals.searchResultContainer;
491   for (var i = resultContainer.childNodes.length - 1; i >= 0; i--) {
492         resultContainer.removeChild(resultContainer.lastChild);
493   }
494     
495   var table = resultContainer.appendChild(document.createElement("table"));
496   var tbody = table.appendChild(document.createElement("tbody"));
497   var list = jsonData.list;
498     
499   if (list == null) {
500     var tr = tbody.appendChild(document.createElement("tr"));                   
501     var td = tr.appendChild(document.createElement("td"));
502     td.appendChild(document.createTextNode("Not Found"));
503     td.style.fontSize = "12px";
504     td.style.textDecoration = "none";
505     td.font = "Arial,Helvetica,sans-serif";
506     td.style.fontWeight = "normal";
507   }
508   else {
509     for (var i = 0; i < list.length; i++) {
510       var tr = tbody.appendChild(document.createElement("tr"));                 
511       var td = tr.appendChild(document.createElement("td"));
512       
513       td.appendChild(document.createTextNode(list[i].type + "(" + list[i].numberOfT1 + 
514         "): " + list[i].id));
515       td.style.fontSize = "12px";
516       td.style.textDecoration = "underline";
517       td.style.color = "blue";
518       td.style.fontWeight = "normal";
519       td.style.cursor = "pointer";
520       td.font = "Arial,Helvetica,sans-serif";
521       td.id = list[i].latitude + ">>" + list[i].longitude;
522       
523       td.onmouseover = function() {
524         this.style.fontWeight = "bold";
525       }
526       
527       td.onmouseout = function() {
528         this.style.fontWeight = "normal";
529       }
530       
531       td.onclick = function() {
532         this.style.color = "red";
533         var latitudeLongitude = this.id.split(">>");
534         var latlng = new GLatLng(latitudeLongitude[0], latitudeLongitude[1]);
535         map.setCenter(latlng, 17);
536         updateImage(0); 
537       }
538     }
539   }
540   
541   resultContainer.style.display = "";
542 }
543 //new changes end
544 NovaButton.prototype.initializeLayerDiv = function(layerDiv) {
545   for (var i = layerDiv.childNodes.length - 1; i >= 0; i--) {
546     layerDiv.removeChild(layerDiv.lastChild);
547   }
548   
549   var colorList = document.getElementById("colorList").value;
550   var selectedLayerList = document.getElementById("selectedLayerList").value;
551   var colorArray = colorList.split("~!");
552   var selectedColorArray = selectedLayerList.split("~!");
553   //layerDiv.style.background = "white";
554   var table = layerDiv.appendChild(document.createElement("table"));
555   table.width="100%";
556   table.height="100%";
557   //this.setMenuStyle(table);
558   /****Creating the data table****/
559   var tbody = table.appendChild(document.createElement("tbody"));
560   var tr;
561   var td;
562   var originalLayerState = new Array();
563   for (i = 0; i < colorArray.length; i++) {
564         tr = tbody.appendChild(document.createElement("tr"));
565         tr.style.height="20px";
566     var colorItem = colorArray[i].split(",");
567     
568     td = tr.appendChild(document.createElement("td"));
569     var chkbox = document.createElement("input");
570     chkbox.type="checkbox";
571           chkbox.name = "" + colorItem[0] + "chk";
572     chkbox.value = colorItem[0];
573     chkbox.id = colorItem[0] + "chk";
574     if (this.checkIfColorSelected(selectedColorArray, colorItem[0]) == true){
575         chkbox.defaultChecked=true;
576         originalLayerState[i] = "true," + colorArray[i];
577     }
578     else {
579       originalLayerState[i] = "false," + colorArray[i];
580     }
581     td.appendChild(chkbox);
582           
583     td = tr.appendChild(document.createElement("td"));
584     td.width="75%";
585     td.appendChild(document.createTextNode(colorItem[0]));
586         td.style.fontFamily = "Verdana";
587         td.style.fontSize = "12px";
588         
589     td = tr.appendChild(document.createElement("td"));
590     td.width="10%";
591     //td.style.background = colorItem[1];
592     td.innerHTML="<input type='text' id='" + colorItem[0] + "colorbx' value='" + colorItem[1] + "' size='6' style='background-color:#" + colorItem[1] + "' background-color='#" + colorItem[1] + "' onclick='openPicker(\"" + colorItem[0] + "colorbx\")'/>"
593     tbody.appendChild(tr);
594   }
595   
596   NovaButton.globals.originalLayerState = originalLayerState;
597
598   /**to get rid of extra space**/
599   /*var layerHeight = layerDiv.style.height.substring(0, layerDiv.style.height.length -2);
600   if (colorArray.length * 30 < layerHeight){
601         tr = tbody.appendChild(document.createElement("tr"));
602         tr.height= (layerHeight - (colorArray.length * 40 ) ) + "px";
603         td = tr.appendChild(document.createElement("td"));
604   }*/
605   
606   
607   tr = tbody.appendChild(document.createElement("tr"));
608   tr.vAlign="bottom";
609   tr.style.height="20px";
610   td = tr.appendChild(document.createElement("td"));
611   td.colSpan="3";
612   var buttonTable = td.appendChild(document.createElement("table"));
613   buttonTable.height="100%";
614   buttonTable.width="100%";
615   
616   var buttonBody = buttonTable.appendChild(document.createElement("tbody"));
617   tr = buttonBody.appendChild(document.createElement("tr"));
618   td = tr.appendChild(document.createElement("td"));
619   td.width="20%";
620   td = tr.appendChild(document.createElement("td"));
621   td.appendChild(document.createTextNode("OK"));
622   td.onclick = function ()
623         {
624                 var selectedLayers = "";
625                 var colorList = "";
626                 var changed = false;
627                 var originalLayerState = NovaButton.globals.originalLayerState;
628                 //saving the user selected choices
629                 for (i = 0; i < colorArray.length; i++) {
630                         var colorItem = colorArray[i].split(",");
631                         //saving the selected layers
632                         var temp; // variable to hold changes value
633                         if (document.getElementById("" + colorItem[0] + "chk").checked == true){
634                                 selectedLayers = selectedLayers + "~!" + colorItem[0];
635                                 temp = "true," + colorItem[0];
636                         }
637                         else {
638                                 temp = "false," + colorItem[0];
639                         }
640                         //saving the colours of all the layers
641                         var userSelectedColor = document.getElementById("" + colorItem[0] + "colorbx").value;
642                         if (userSelectedColor.charAt(0) == '#') {
643                           userSelectedColor = userSelectedColor.substring(1);
644                         }
645                         colorList = colorList + "~!" + colorItem[0] + "," + userSelectedColor;
646                         temp = temp + "," + userSelectedColor;
647         
648                         //check to see if there is anything change and update 
649                         // originalLayerState to reflect the changes
650                         if (changed) {
651                           originalLayerState[i] = temp;
652                         }
653                         else if (originalLayerState[i] != temp) {
654                           changed = true;
655                           originalLayerState[i] = temp;
656                         }
657                 }
658                 selectedLayers = selectedLayers.substring(2, selectedLayers.length);
659                 colorList = colorList.substring(2, colorList.length);
660                 document.getElementById("selectedLayerList").value = selectedLayers;
661                 document.getElementById("colorList").value = colorList;
662                 
663                 // update if there is anything change
664                 if (changed) {
665                         updateImage(0);
666                 }
667                 
668                 //to remove the layer
669                 NovaButton.prototype.showLayerClickEvent();
670         }; 
671   td.width="25%";
672   this.setButtonStyle(td, true);
673   td.style.cursor = "hand";
674
675   td = tr.appendChild(document.createElement("td"));
676   td.appendChild(document.createTextNode("Cancel"));
677   td.width="25%";
678   this.setButtonStyle(td, true);
679   td.style.cursor = "hand";
680   td.onclick = function ()
681         {
682                 //remove all the contents
683                 layerDiv.innerHTML=""; 
684                 //re-initiate the layers to original values
685                 NovaButton.prototype.initializeLayerDiv(layerDiv);
686                 NovaButton.prototype.showLayerClickEvent();
687         };    
688   td = tr.appendChild(document.createElement("td"));
689   td.width="10%";
690   
691 }
692
693 NovaButton.prototype.checkIfColorSelected= function(selectedColorArray, colorItem) {
694         for (j = 0; j < selectedColorArray.length; j++) {
695                 if (selectedColorArray[j] ==  colorItem){
696                         return true;
697                 }
698         }
699         return false;
700 }
701
702 NovaButton.prototype.setMenuContainerStyle = function(menuContainer) {
703         menuContainer.style.position = "absolute";
704         menuContainer.style.background = "#FFFFF0"
705         menuContainer.style.overflow = "auto";
706         menuContainer.style.scrolling="yes";
707         menuContainer.style.display = "none";
708         menuContainer.style.width = "300px";
709         menuContainer.style.height = "300px";
710 }
711
712 NovaButton.prototype.setMenuStyle = function(menu) {
713   menu.style.width = "300px";
714   menu.style.height = "300px";
715         menu.style.background   = "#FFF";
716 }
717
718 NovaButton.prototype.setMenuItemStyle = function(menuItem) {
719   menuItem.style.padding        = "4px 3px 4px 33px";
720         menuItem.style.fontFamily = "Vardana, Arial, Helvetica, sans-serif" ;
721         menuItem.style.fontSize = "10pt";
722         menuItem.style.color    = "#333" ;
723         menuItem.style.cursor   = "default" ;
724         menuItem.style.background = "no-repeat left center" ;
725 }
726
727 NovaButton.prototype.showLayerOption = function(posX, posY) {
728         var globals = NovaButton.globals;
729
730         //position the menu at the given location
731         if(typeof posX == "number") {
732                 globals.layerOptionContainer.style.left = posX + "px";
733         }
734         
735         if(typeof posY == "number") {
736                 globals.layerOptionContainer.style.top = posY + "px";
737         }
738         //new chanes start
739         var resultContainer = globals.searchResultContainer;
740         resultContainer.style.display = "none";
741     //nw changes end
742         //display the menu
743         globals.layerOptionContainer.style.display = "block";
744 }
745
746 NovaButton.prototype.showSearchOption = function(posX, posY) {
747   var globals = NovaButton.globals;
748
749         //position the menu at the given location
750         if(typeof posX == "number") {
751                 globals.searchOptionContainer.style.left = posX + "px";
752         }
753         
754         if(typeof posY == "number") {
755                 globals.searchOptionContainer.style.top = posY + "px";
756         }
757         
758         //display the menu
759         globals.searchOptionContainer.style.display = "inline";
760 }
761
762 NovaButton.prototype.defaultViewClickEvent = function() {
763   var defaultZoomLevel = document.getElementById("defaultZoomLevel").value * 1;
764         map.setCenter(new GLatLng(document.getElementById("defaultCenterLatitude").value, 
765         document.getElementById("defaultCenterLongitude").value),
766         defaultZoomLevel);
767   updateImage(0);
768 }
769
770 NovaButton.prototype.showLayerClickEvent = function(e) {
771   if (NovaButton.globals.layerOptionVisible) {
772         //to remove the color picker
773         cancel();               
774           NovaButton.globals.layerOptionVisible = false;
775           NovaButton.globals.layerOptionContainer.style.display = "none";
776           return;
777         }
778         
779         if (NovaButton.globals.searchOptionContainer.style.display != "none"){
780                 NovaButton.prototype.searchClickEvent();
781         }
782         if (CingularButton.globals.listOptionContainer.style.display != "none"){
783                 currentMonthClickEvent();
784         }
785         
786   if (!e) {
787         e = window.event;
788         }
789         
790         e.cancelBubble = true;
791         
792         if (e.stopPropagation) {
793                 e.stopPropagation();
794         }
795         
796         var button = Event.element(e);
797         var posX = button.offsetLeft;
798         var posY = button.offsetTop;
799         this.showLayerOption(posX, posY + button.offsetHeight);
800         NovaButton.globals.layerOptionVisible = true;
801 }
802
803 NovaButton.prototype.searchClickEvent = function(e) {
804   if (NovaButton.globals.searchOptionVisible) {
805           NovaButton.globals.searchOptionVisible = false;
806           NovaButton.globals.searchOptionContainer.style.display = "none";
807           return;
808         }
809         
810         if (NovaButton.globals.layerOptionContainer.style.display != "none"){
811                 NovaButton.prototype.showLayerClickEvent();
812   }
813   if (CingularButton.globals.listOptionContainer.style.display != "none"){
814                 currentMonthClickEvent();
815   }
816         
817   if (!e) {
818         e = window.event;
819         }
820         
821         e.cancelBubble = true;
822         
823         if (e.stopPropagation) {
824                 e.stopPropagation();
825         }
826         
827         var button = Event.element(e);
828         var posX = button.offsetLeft;
829         var posY = button.offsetTop;
830         this.showSearchOption(posX, posY + button.offsetHeight + 3);
831         NovaButton.globals.searchOptionVisible = true;
832 }
833
834 NovaButton.prototype.submitSearchClickEvent = function(e) {
835   if (NovaButton.globals.searchTabSelected == "nodeTab") {
836     var input = document.getElementById("nodeSearchInput").value.trim();
837     
838     if (input.length == 0) {
839       alert("Input field required");
840       return;
841     }
842     
843     var searchType;
844     // ie bug
845     var searchByNodeId = document.getElementById("searchByNodeId");
846     
847     if (searchByNodeId.checked) {
848         searchType = searchByNodeId.value;
849     }
850     else {
851       searchType = document.getElementById("searchByLocation").value;
852     }
853     
854     var checkbox = document.getElementById("exactMatch");
855     
856                 searchObject(input, searchType, checkbox.checked, e.clientX, e.clientY);
857   }
858   else {
859     var address = document.getElementById("addressSearchInput").value.trim();
860     
861     if (address.length == 0) {
862       alert("Address field required");
863       return;
864     }
865
866     geocoder.getLatLng(
867         address,
868         function(ll) {
869             if (ll != null) {
870                           if (addressMarker == null) {
871                                 addressMarker = new GMarker(ll);
872                                 map.addOverlay(addressMarker);
873                                 GEvent.addListener(addressMarker, "click", marker_onclick);
874                 }
875                 else {
876                         addressMarker.setLatLng(ll);
877                 }
878                 
879                 map.setCenter(ll);
880                 updateImage(0);
881             }
882         }
883     );
884   }
885   
886   this.searchClickEvent(e);
887 }
888
889 function marker_onclick() {
890   map.removeOverlay(addressMarker);
891   addressMarker = null;
892 }
893
894 // start drag zoom function
895 NovaButton.prototype.initCover = function() {
896   var dragZoomGlobals = NovaButton.globals.dragzoom;
897   dragZoomGlobals.mapPosition = NovaButtonUtils.getElementPosition(NovaButton.globals.map.getContainer());
898   this.setDimensions();
899   
900   dragZoomGlobals.zoomArea.style.display = "block";
901   dragZoomGlobals.zoomArea.style.background = "#000";
902   
903   dragZoomGlobals.outlineDiv.style.width = "0px";
904   dragZoomGlobals.outlineDiv.style.height = "0px";
905 };
906
907 NovaButton.prototype.initZoomAreaStyles = function(){
908   var dragZoomGlobals = NovaButton.globals.dragzoom;
909   dragZoomGlobals.zoomArea.style.background = "#000";
910   dragZoomGlobals.zoomArea.style.opacity = "0.2";
911   dragZoomGlobals.zoomArea.style.filter = 'alpha(opacity=' + (0.2 * 100) + ')';
912   
913   dragZoomGlobals.cornerTopDiv.style.background = "#000";
914   dragZoomGlobals.cornerTopDiv.style.opacity = "0.2";
915   dragZoomGlobals.cornerTopDiv.style.filter = 'alpha(opacity=' + (0.2 * 100) + ')';
916   
917   dragZoomGlobals.cornerRightDiv.style.background = "#000";
918   dragZoomGlobals.cornerRightDiv.style.opacity = "0.2";
919   dragZoomGlobals.cornerRightDiv.style.filter = 'alpha(opacity=' + (0.2 * 100) + ')';
920   
921   dragZoomGlobals.cornerBottomDiv.style.background = "#000";
922   dragZoomGlobals.cornerBottomDiv.style.opacity = "0.2";
923   dragZoomGlobals.cornerBottomDiv.style.filter = 'alpha(opacity=' + (0.2 * 100) + ')';
924   
925   dragZoomGlobals.cornerLeftDiv.style.background = "#000";
926   dragZoomGlobals.cornerLeftDiv.style.opacity = "0.2";
927   dragZoomGlobals.cornerLeftDiv.style.filter = 'alpha(opacity=' + (0.2 * 100) + ')';
928
929   dragZoomGlobals.outlineDiv.style.border = "2px solid blue";  
930 };
931
932 NovaButton.prototype.resetDragZoom = function() {
933   var dragZoomGlobals = NovaButton.globals.dragzoom;
934   dragZoomGlobals.zoomArea.style.display = "none";
935   dragZoomGlobals.zoomArea.style.opacity = "0.2";
936   dragZoomGlobals.zoomArea.style.filter = 'alpha(opacity=' + (0.2 * 100) + ')';
937   
938   dragZoomGlobals.cornerTopDiv.style.display = "none";
939   dragZoomGlobals.cornerTopDiv.style.opacity = "0.2";
940   dragZoomGlobals.cornerTopDiv.style.filter = 'alpha(opacity=' + (0.2 * 100) + ')';
941   
942   dragZoomGlobals.cornerRightDiv.style.display = "none";
943   dragZoomGlobals.cornerRightDiv.style.opacity = "0.2";
944   dragZoomGlobals.cornerRightDiv.style.filter = 'alpha(opacity=' + (0.2 * 100) + ')';
945   
946   dragZoomGlobals.cornerBottomDiv.style.display = "none";
947   dragZoomGlobals.cornerBottomDiv.style.opacity = "0.2";
948   dragZoomGlobals.cornerBottomDiv.style.filter = 'alpha(opacity=' + (0.2 * 100) + ')';
949   
950   dragZoomGlobals.cornerLeftDiv.style.display = "none";
951   dragZoomGlobals.cornerLeftDiv.style.opacity = "0.2";
952   dragZoomGlobals.cornerLeftDiv.style.filter = 'alpha(opacity=' + (0.2 * 100) + ')';
953
954   dragZoomGlobals.outlineDiv.style.display = 'none';    
955 };
956
957 NovaButton.prototype.setZoomAreaStyle = function(zoomArea) {
958         zoomArea.style.position = "absolute";
959         zoomArea.style.display = "none";
960         zoomArea.style.overflow = "hidden";
961         zoomArea.style.cursor = "crosshair";
962         zoomArea.style.zIndex = "101";
963 }
964
965 NovaButton.prototype.getRectangle = function(startX, startY, pos){
966   var left = false;
967   var top = false;
968   var dX = pos.left - startX;
969   var dY = pos.top - startY;    
970   if (dX < 0) {
971     dX = dX * -1;
972     left = true;
973   }
974   if (dY < 0) {
975     dY = dY * -1;
976     top = true;
977   }
978   delta = dX > dY ? dX : dY;
979
980   return {
981     startX: startX,
982     startY: startY,
983     endX: startX + dX,
984     endY: startY + dY,
985     width: dX,
986     height: dY,
987     left:left,
988     top:top
989   }
990 };
991
992 NovaButton.prototype.mouseDown = function(e) {
993         if (NovaButton.globals.currentButton != "zoomRectangleDiv") {
994                 return;
995         }
996         
997         var dragZoomGlobals = NovaButton.globals.dragzoom;
998   var pos = this.getRelPos(e);
999   dragZoomGlobals.startX = pos.left;
1000   dragZoomGlobals.startY = pos.top;
1001
1002         dragZoomGlobals.zoomArea.style.background = "transparent";
1003         dragZoomGlobals.zoomArea.style.opacity = "1";
1004         dragZoomGlobals.zoomArea.style.filter = 'alpha(opacity=100)';
1005         
1006         dragZoomGlobals.outlineDiv.style.left = dragZoomGlobals.startX + "px";
1007         dragZoomGlobals.outlineDiv.style.top = dragZoomGlobals.startY + "px";
1008         dragZoomGlobals.outlineDiv.style.display = "block";
1009         dragZoomGlobals.outlineDiv.style.width = "1px";
1010         dragZoomGlobals.outlineDiv.style.height = "1px";
1011
1012   dragZoomGlobals.cornerTopDiv.style.top = (dragZoomGlobals.startY - dragZoomGlobals.mapHeight) + 'px';
1013   dragZoomGlobals.cornerTopDiv.style.display ='block';
1014   dragZoomGlobals.cornerLeftDiv.style.left = (dragZoomGlobals.startX - dragZoomGlobals.mapWidth) +'px';
1015   dragZoomGlobals.cornerLeftDiv.style.top = dragZoomGlobals.startY + 'px';
1016   dragZoomGlobals.cornerLeftDiv.style.display = 'block';
1017
1018   dragZoomGlobals.cornerRightDiv.style.left = dragZoomGlobals.startX + 'px';
1019   dragZoomGlobals.cornerRightDiv.style.top = dragZoomGlobals.startY + 'px';
1020   dragZoomGlobals.cornerRightDiv.style.display = 'block';
1021   dragZoomGlobals.cornerBottomDiv.style.left = dragZoomGlobals.startX + 'px';
1022   dragZoomGlobals.cornerBottomDiv.style.top = dragZoomGlobals.startY + 'px';
1023   dragZoomGlobals.cornerBottomDiv.style.width = '0px';
1024   dragZoomGlobals.cornerBottomDiv.style.display = 'block';
1025   
1026   dragZoomGlobals.moving = true;
1027
1028   return false;
1029 }
1030
1031 NovaButton.prototype.mouseMove = function(e) {
1032   var dragZoomGlobals = NovaButton.globals.dragzoom;
1033   
1034   if(dragZoomGlobals.moving) {
1035     var pos = this.getRelPos(e);
1036     var rect = this.getRectangle(dragZoomGlobals.startX, dragZoomGlobals.startY, pos);
1037
1038     if (rect.left) {
1039       addX = -rect.width;                       
1040     } else { 
1041       addX = 0;
1042     }
1043
1044     if (rect.top) {
1045       addY = -rect.height;
1046     } else {
1047       addY = 0;
1048     }
1049
1050                 dragZoomGlobals.outlineDiv.style.left = dragZoomGlobals.startX + addX + "px";
1051                 dragZoomGlobals.outlineDiv.style.top = dragZoomGlobals.startY + addY + "px";
1052                 dragZoomGlobals.outlineDiv.style.display = "block";
1053     dragZoomGlobals.outlineDiv.style.width = rect.width + "px";
1054     dragZoomGlobals.outlineDiv.style.height = rect.height + "px";
1055
1056     dragZoomGlobals.cornerTopDiv.style.height = ((dragZoomGlobals.startY + addY) - (dragZoomGlobals.startY - dragZoomGlobals.mapHeight)) + 'px';
1057     dragZoomGlobals.cornerLeftDiv.style.top = (dragZoomGlobals.startY + addY) + 'px';
1058     dragZoomGlobals.cornerLeftDiv.style.width = ((dragZoomGlobals.startX + addX) - (dragZoomGlobals.startX - dragZoomGlobals.mapWidth)) + 'px';
1059     dragZoomGlobals.cornerRightDiv.style.top = dragZoomGlobals.cornerLeftDiv.style.top;
1060     dragZoomGlobals.cornerRightDiv.style.left = (dragZoomGlobals.startX + addX + rect.width + 4) + 'px';
1061     dragZoomGlobals.cornerBottomDiv.style.top = (dragZoomGlobals.startY + addY + rect.height + 4) + 'px';
1062     dragZoomGlobals.cornerBottomDiv.style.left = (dragZoomGlobals.startX - dragZoomGlobals.mapWidth + ((dragZoomGlobals.startX + addX) - (dragZoomGlobals.startX - dragZoomGlobals.mapWidth))) + 'px';
1063     dragZoomGlobals.cornerBottomDiv.style.width = (rect.width + 4) + 'px';
1064                 
1065     return false;
1066   }  
1067 }
1068
1069 NovaButton.prototype.mouseUp = function(e) {
1070   var dragZoomGlobals = NovaButton.globals.dragzoom;
1071   var map = NovaButton.globals.map;
1072   
1073   if (dragZoomGlobals.moving) {
1074     var pos = this.getRelPos(e);
1075     dragZoomGlobals.moving = false;
1076     
1077     var rect = this.getRectangle(dragZoomGlobals.startX, dragZoomGlobals.startY, pos);
1078
1079     if (rect.left) {
1080         rect.endX = rect.startX - rect.width;
1081     }
1082     
1083     if (rect.top) {
1084       rect.endY = rect.startY - rect.height;
1085     }
1086         
1087     this.resetDragZoom();
1088     
1089     if (rect.width >= 0 && rect.height >= 0) {
1090       var nwpx = new GPoint(rect.startX, rect.startY);
1091       var nepx = new GPoint(rect.endX, rect.startY);
1092       var sepx = new GPoint(rect.endX, rect.endY);
1093       var swpx = new GPoint(rect.startX, rect.endY);
1094       var nw = NovaButton.globals.map.fromContainerPixelToLatLng(nwpx); 
1095       var ne = NovaButton.globals.map.fromContainerPixelToLatLng(nepx); 
1096       var se = NovaButton.globals.map.fromContainerPixelToLatLng(sepx); 
1097       var sw = NovaButton.globals.map.fromContainerPixelToLatLng(swpx); 
1098
1099       var zoomAreaPoly = new GPolyline([nw, ne, se, sw, nw], "blue", 3, .4);
1100       var polyBounds = zoomAreaPoly.getBounds();
1101       var ne = polyBounds.getNorthEast();
1102       var sw = polyBounds.getSouthWest();
1103       var se = new GLatLng(sw.lat(), ne.lng());
1104       var nw = new GLatLng(ne.lat(), sw.lng());
1105       var zoomLevel = map.getBoundsZoomLevel(polyBounds);
1106       var center = polyBounds.getCenter();
1107       map.setCenter(center, zoomLevel);
1108     }
1109
1110     this.initCover();
1111   }
1112 }
1113
1114 NovaButton.prototype.setDimensions = function() {
1115   var dragZoomGlobals = NovaButton.globals.dragzoom;
1116   var mapSize = NovaButton.globals.map.getSize();
1117   dragZoomGlobals.mapWidth  = mapSize.width;
1118   dragZoomGlobals.mapHeight = mapSize.height;
1119   dragZoomGlobals.mapRatio  = dragZoomGlobals.mapHeight / dragZoomGlobals.mapWidth;
1120   // set left:0px in next <div>s in case we inherit text-align:center from map <div> in IE.
1121   dragZoomGlobals.zoomArea.style.top = "0px";
1122   dragZoomGlobals.zoomArea.style.left = "0px";
1123   dragZoomGlobals.zoomArea.style.width = dragZoomGlobals.mapWidth + "px";
1124   dragZoomGlobals.zoomArea.style.height = dragZoomGlobals.mapHeight + "px";
1125   
1126   dragZoomGlobals.cornerTopDiv.style.top = "0px";
1127   dragZoomGlobals.cornerTopDiv.style.left = "0px";
1128   dragZoomGlobals.cornerTopDiv.style.width = dragZoomGlobals.mapWidth + "px";
1129   dragZoomGlobals.cornerTopDiv.style.height = dragZoomGlobals.mapHeight + "px";
1130   
1131   dragZoomGlobals.cornerRightDiv.style.top = "0px";
1132   dragZoomGlobals.cornerRightDiv.style.left = "0px";
1133   dragZoomGlobals.cornerRightDiv.style.width = dragZoomGlobals.mapWidth + "px";
1134   dragZoomGlobals.cornerRightDiv.style.height = dragZoomGlobals.mapHeight + "px";
1135   
1136   dragZoomGlobals.cornerBottomDiv.style.top = "0px";
1137   dragZoomGlobals.cornerBottomDiv.style.left = "0px";
1138   dragZoomGlobals.cornerBottomDiv.style.width = dragZoomGlobals.mapWidth + "px";
1139   dragZoomGlobals.cornerBottomDiv.style.height = dragZoomGlobals.mapHeight + "px";
1140   
1141   dragZoomGlobals.cornerLeftDiv.style.top = "0px";
1142   dragZoomGlobals.cornerLeftDiv.style.left = "0px";
1143   dragZoomGlobals.cornerLeftDiv.style.width = dragZoomGlobals.mapWidth + "px";
1144   dragZoomGlobals.cornerLeftDiv.style.height = dragZoomGlobals.mapHeight + "px";
1145 };
1146
1147 NovaButton.prototype.getRelPos = function(e) {
1148   var pos = NovaButtonUtils.getMousePosition(e);
1149   var dragZoomGlobals = NovaButton.globals.dragzoom;
1150   return {top: (pos.top - dragZoomGlobals.mapPosition.top), 
1151           left: (pos.left - dragZoomGlobals.mapPosition.left)};
1152 };
1153 // end drag zoom function
1154
1155 var NovaButtonUtils = {
1156 };
1157
1158 NovaButtonUtils.getElementPosition = function(element) {
1159   var leftPos = element.offsetLeft;          // initialize var to store calculations
1160   var topPos = element.offsetTop;            // initialize var to store calculations
1161   var parElement = element.offsetParent;     // identify first offset parent element  
1162   while (parElement != null ) {                // move up through element hierarchy
1163     leftPos += parElement.offsetLeft;      // appending left offset of each parent
1164     topPos += parElement.offsetTop;  
1165     parElement = parElement.offsetParent;  // until no more offset parents exist
1166   }
1167   return {left: leftPos, top: topPos};
1168 };
1169
1170 NovaButtonUtils.getMousePosition = function(e) {
1171   var posX = 0;
1172   var posY = 0;
1173   if (!e) var e = window.event;
1174   if (e.pageX || e.pageY) {
1175     posX = e.pageX;
1176     posY = e.pageY;
1177   } else if (e.clientX || e.clientY){
1178     posX = e.clientX + 
1179       (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
1180     posY = e.clientY + 
1181       (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
1182   }
1183   return {left: posX, top: posY};  
1184 };