1 /*********************************************************************************
2 * SugarCRM Community Edition is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Affero General Public License version 3 as published by the
7 * Free Software Foundation with the addition of the following permission added
8 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
9 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
10 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
17 * You should have received a copy of the GNU Affero General Public License along with
18 * this program; if not, see http://www.gnu.org/licenses or write to the Free
19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
23 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25 * The interactive user interfaces in modified source and object code versions
26 * of this program must display Appropriate Legal Notices, as required under
27 * Section 5 of the GNU Affero General Public License version 3.
29 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
30 * these Appropriate Legal Notices must retain the display of the "Powered by
31 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
32 * technical reasons, the Appropriate Legal Notices must display the words
33 * "Powered by SugarCRM".
34 ********************************************************************************/
38 var menuStack = new Array();
39 var hiddenElmStack = new Array();
40 var currentMenu = null;
41 var closeMenusDelay = null;
42 var openMenusDelay = null;
43 var delayTime = 75; // ms for menu open delay
46 function eraseTimeout(tId) {
48 window.clearTimeout(tId);
52 function tbButtonMouseOverOrig(id){
53 closeMenusDelay = eraseTimeout(closeMenusDelay);
54 var menuName = id.replace(/Handle/i,'Menu');
55 var menu = getLayer(menuName);
56 //if (menu) menu.className = 'tbButtonMouseOverUp';
62 function tbButtonMouseOver(id,top,left,leftOffset){
63 closeMenusDelay = eraseTimeout(closeMenusDelay);
64 if (openMenusDelay == null){
65 openMenusDelay = window.setTimeout("showMenu('"+id+"','"+top+"','"+left+"','"+leftOffset+"')", delayTime);
68 function showMenu(id,top,left,leftOffset){
69 openMenusDelay = eraseTimeout(openMenusDelay);
70 var menuName = id.replace(/Handle/i,'Menu');
71 var menu = getLayer(menuName);
72 //if (menu) menu.className = 'tbButtonMouseOverUp';
76 popupMenu(id, menu, top,left,leftOffset);
79 function showSubMenu(id){
80 closeMenusDelay = eraseTimeout(closeMenusDelay);
81 var menuName = id.replace(/Handle/i,'Menu');
82 var menu = getLayer(menuName);
86 // popupMenu(id, menu);
87 popupSubMenu(id, menu);
90 function popupMenu(handleID, menu, top, left, leftOffset){
91 var bw = checkBrowserWidth();
92 var menuName = handleID.replace(/Handle/i,'Menu');
94 var imgWidth = document.getElementById(handleID).width;
96 var menuHandle = getLayer(handleID);
100 while(p&&p.tagName.toUpperCase()!='BODY'){
104 left+=parseInt(leftOffset);
107 if (left+menuWidth>bw) {
108 left = left-menuWidth+imgWidth;
110 setMenuVisible(menu, left, top, false);
115 function popupSubMenu(handleID, menu){
117 var menuHandle = getLayer(handleID);
119 //var top = p.offsetHeight, left = 0;
120 var top = 0, left = p.offsetWidth;
121 while(p&&p.tagName.toUpperCase()!='BODY'){
126 if (is.ie && is.mac){
134 left+=(getLayer(menu.parentid).offsetWidth - 4);
136 left+=(getLayer(menu.parentid).clientWidth - 8);
141 top += menuItem.offsetHeight;
146 setMenuVisible(menu, left, top, true);
147 //fixWidth(paneID, menu);
151 function closeMenusOrig(){
153 setMenuVisibility(currentMenu, false);
154 // currentMenu = null;
158 function closeSubMenus(handle){
159 closeMenusDelay = eraseTimeout(closeMenusDelay);
160 if (menuStack.length > 0){
161 for (var i = menuStack.length-1; i >=0; i--){
162 var menu = menuStack[menuStack.length-1];
163 if (menu.id == handle.getAttribute('parentid')){
175 function closeMenu(menu){
176 setMenuVisibility(menu, false);
179 function closeMenusOrig(){
180 if (menuStack.length > 0){
181 for (var i = menuStack.length-1; i >=0; i--){
182 //var menu = menuStack.pop();
183 var menu = menuPop();
190 function closeMenus(){
191 if (closeMenusDelay == null){
192 closeMenusDelay = window.setTimeout("closeAllMenus()", delayTime);
196 function closeAllMenus(){
197 closeMenusDelay = eraseTimeout(closeMenusDelay);
198 if (menuStack.length > 0){
199 for (var i = menuStack.length-1; i >=0; i--){
200 //var menu = menuStack.pop();
201 var menu = menuPop();
208 function setMenuVisible(menu, x, y, isSubMenu){
213 var menuItem = menu.getMenuItemElm();
215 if (menuItem && menu){
217 menuItem.className = 'tbButtonMouseDown';
225 if (menu.getAttribute('parentid') == currentMenu.getAttribute('parentid')){
228 setMenuVisibility(currentMenu, false);
233 setMenuVisibility(currentMenu, false);
236 //menuStack.push(menu);
238 setMenuVisibility(menu, true, x, y);
242 function getLayer(layerid){
244 if (document.layers && layerid){
245 if (document.layers[layerid]) return document.layers[layerid];
247 if (document.links && layerid){
248 if (document.links[layerid]) return document.links[layerid];
250 if (document.all && layerid){
251 if (document.all(layerid)) return document.all(layerid);
254 return document.getElementById(layerid);
257 function setMenuVisibility(menu, on, x, y){
262 setLayer(menu.id, !menu.visible, menu.x, menu.y);
263 setLayer(menu.id, !menu.visible, 0, 0);
266 setLayer(menu.id, !on, x, y);
269 if (!menu.getAttribute('parentid')){
270 showElement("SELECT");
273 hideElement("SELECT", x, y, menu.offsetWidth, menu.offsetHeight);
277 setLayer(menu.id, !menu.visible, 0, 0);
278 var menuWidth, menuHeight;
279 var menuLayer = getLayer(menu.id);
282 menuWidth = menuLayer.clientWidth;
283 menuHeight = menuLayer.clientHeight;
285 menuWidth = menuLayer.offsetWidth;
286 menuHeight = menuLayer.offsetHeight;
288 if (menu.x+menuWidth > clientWindowWidth){
289 menu.x = clientWindowWidth - menuWidth - 25;
294 if (menu.y+menuHeight > clientWindowHeight){
295 menu.y = clientWindowHeight - menuHeight - 25;
300 setLayer(menu.id, !menu.visible, menu.x, menu.y);
305 var parentid = menu.parentid;
307 parent = getMenu(menu.paneID, parentid);
310 setLayer(parent.id, !parent.visible, parent.x, parent.y);
311 parentid = parent.parentid;
312 if (on == false) currentMenu = parent;
323 if (is.ie && (is.mac || !is.ie5_5up)){
324 var menu = menuStack[menuStack.length-1];
325 var newMenuStack = new Array();
326 for (var i = 0; i < menuStack.length-1; i++){
327 newMenuStack[newMenuStack.length] = menuStack[i];
329 menuStack = newMenuStack;
332 return menuStack.pop();
336 function menuPush(menu){
337 if (is.ie && (is.mac || !is.ie5_5up)){
338 menuStack[menuStack.length] = menu;
340 menuStack.push(menu);
344 function checkBrowserWidth(){
347 windowWidth = document.body.clientWidth;
349 // 17px for scrollbar width
350 windowWidth = window.innerWidth - 16;
352 if (windowWidth >= 1000){
353 showSB('sbContent',true,'sb');
355 showSB('sbContent',false,'sb');
360 function showSB(id, hideit, imgIdPrefix){
361 setLayer(id, !hideit, -1, -1);
362 setLayer(imgIdPrefix+'On', !hideit, -1, -1);
363 setLayer(imgIdPrefix+'Off', hideit, -1, -1);
366 function setLayer(id, hidden, x, y){
367 var layer = getLayer(id);
368 setLayerElm(layer, hidden, x, y);
371 function setLayerElm(layer, hideit, x, y){
372 if (layer && layer.style){
374 layer.style.visibility='hidden';
375 //layer.style.display='none';
377 layer.style.display='block';
378 layer.style.visibility='visible';
380 if (x >=0 && x != ""){
381 //alert(layer.id+': '+x+', '+y+'\n'+layer.offsetLeft+', '+layer.offsetTop);
382 //layer.style.left=x;
384 layer.style.left = x+'px';
386 if (y >= 0 && y != "") {
387 layer.style.top = y+'px';
392 function hiliteItem(menuItem,changeClass){
393 closeMenusDelay = eraseTimeout(closeMenusDelay);
394 if (changeClass=='yes') {
395 if (menuItem.getAttribute('avid') == 'false'){
396 menuItem.className = 'menuItemHiliteX';
398 menuItem.className = 'menuItemHilite';
402 function unhiliteItem(menuItem){
403 closeMenusDelay = eraseTimeout(closeMenusDelay);
404 if (menuItem.getAttribute('avid') == 'false'){
405 menuItem.className = 'menuItemX';
407 menuItem.className = 'menuItem';
411 function showElement(elmID){
412 for (i = 0; i < document.getElementsByTagName(elmID).length; i++) {
413 obj = document.getElementsByTagName(elmID)[i];
414 if (! obj || ! obj.offsetParent)
416 obj.style.visibility = "";
419 function showElementNew(elmID){
420 if (hiddenElmStack.length > 0){
421 for (var i = hiddenElmStack.length-1; i >=0; i--){
422 var obj = hiddenElmStack[hiddenElmStack.length-1];
423 obj.style.visibility = "";;
424 hiddenElmStack.pop();
429 function hideElement(elmID,x,y,w,h){
430 for (i = 0; i < document.getElementsByTagName(elmID).length; i++){
431 obj = document.getElementsByTagName(elmID)[i];
432 if (! obj || ! obj.offsetParent)
435 // Find the element's offsetTop and offsetLeft relative to the BODY tag.
436 objLeft = obj.offsetLeft;
437 objTop = obj.offsetTop;
438 objParent = obj.offsetParent;
439 while (objParent.tagName.toUpperCase() != "BODY"){
440 objLeft += objParent.offsetLeft;
441 objTop += objParent.offsetTop;
442 if(objParent.offsetParent == null)
445 objParent = objParent.offsetParent;
447 // Adjust the element's offsetTop relative to the dropdown menu
450 if (x > (objLeft + obj.offsetWidth) || objLeft > (x + w))
454 else if ((y + h) <= 80)
457 obj.style.visibility = "hidden";
458 //hiddenElmStack.push(obj);
464 // convert all characters to lowercase to simplify testing
465 var agt = navigator.userAgent.toLowerCase();
467 // *** BROWSER VERSION ***
468 // Note: On IE5, these return 4, so use is.ie5up to detect IE5.
469 this.major = parseInt(navigator.appVersion);
470 this.minor = parseFloat(navigator.appVersion);
472 // Note: Opera and WebTV spoof Navigator. We do strict client detection.
473 // If you want to allow spoofing, take out the tests for opera and webtv.
474 this.nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
475 && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
476 && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
477 this.nav2 = (this.nav && (this.major == 2));
478 this.nav3 = (this.nav && (this.major == 3));
479 this.nav4 = (this.nav && (this.major == 4));
480 this.nav4up = (this.nav && (this.major >= 4));
481 this.navonly = (this.nav && ((agt.indexOf(";nav") != -1) ||
482 (agt.indexOf("; nav") != -1)) );
483 this.nav6 = (this.nav && (this.major == 5));
484 this.nav6up = (this.nav && (this.major >= 5));
485 this.gecko = (agt.indexOf('gecko') != -1);
487 this.nav7 = (this.gecko && (this.major >= 5) && (agt.indexOf('netscape/7')!=-1));
491 this.moz1_1up = false;
494 myRegEx = new RegExp("rv:\\d*.\\d*.\\d*");
495 //myFind = myRegEx.exec("; rv:9.10.5)");
496 myFind = myRegEx.exec(agt);
498 var strVersion = myFind.toString();
499 strVersion = strVersion.replace(/rv:/,'');
500 var arrVersion = strVersion.split('.');
501 var major = parseInt(arrVersion[0]);
502 var minor = parseInt(arrVersion[1]);
503 if (arrVersion[2]) var revision = parseInt(arrVersion[2]);
504 this.moz1 = ((major == 1) && (minor == 0));
505 this.moz1up = ((major == 1) && (minor >= 0));
506 this.moz1_1 = ((major == 1) && (minor == 1));
507 this.moz1_1up = ((major == 1) && (minor >= 1));
511 this.ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
512 this.ie3 = (this.ie && (this.major < 4));
513 this.ie4 = (this.ie && (this.major == 4) && (agt.indexOf("msie 4")!=-1) );
514 this.ie4up = (this.ie && (this.major >= 4));
515 this.ie5 = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")!=-1) );
516 this.ie5_5 = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.5") !=-1));
517 this.ie5up = (this.ie && !this.ie3 && !this.ie4);
519 this.ie5_5up =(this.ie && !this.ie3 && !this.ie4 && !this.ie5);
520 this.ie6 = (this.ie && (this.major == 4) && (agt.indexOf("msie 6.")!=-1) );
521 this.ie6up = (this.ie && !this.ie3 && !this.ie4 && !this.ie5 && !this.ie5_5);
523 this.mac = (agt.indexOf("mac") != -1);
526 function runPageLoadItems (){
533 document.write('<style type="text/css">');
534 document.write('body {font-size: x-small;}');
535 document.write ('</style>');