
var GMX = { //global application object



 // utility to scroll page, useful when doing animations

 scroll: {

  top: function(event) { new Effect.ScrollTo('header'); },

  bottom: function(event) { new Effect.ScrollTo('footer'); },

  details: function(event) { new Effect.ScrollTo($$('a.button-view-details').first()); }

 },



 // details object

        /** Locked down by Ascent.

          * This method should no longer be subject to code drops by Huge.  All changes

          * should be internal only.

          */

 details : {

  setup: function() {

   var details_btn = $$('a.button-view-details').first();

   if(!details_btn) return;

   details_btn.observe('click',function(event){

    Event.stop(event);

    if ($('details').visible()) {

     GMX.player.open();

     GMX.episodes_navigation.open();

     // give time to player and navigation episodes to open

     setTimeout(function() { GMX.details.close(); }, 300);

    } else {

     GMX.scroll.top();

     // give time to scroll top

     setTimeout(function() {

      GMX.player.close();

      GMX.episodes_navigation.close();

      GMX.details.open();

     }, 1000);

    }

   });

  },

  open: function() {

   $$('a.button-view-details').first().addClassName('on');

   Effect.BlindDown('details',{duration:0.8, afterFinish: function() {

    GMX.scroll.details();

    //GMX.carousels.setup();



    //Initialize the detail box carousels

    var detail_c_carousel = new GMX.Carousel('detail-c-carousel',{

     url:'data/get_ajax_template.php?template=xml/titles/awards/index.htm'

    });

    var detail_d_carousel = new GMX.Carousel('detail-d-carousel',{

     url:'data/get_ajax_template.php?template=xml/titles/deal/index.htm'

    });



    $('details').setStyle({display:'block'});

    }

   });



  },

  close: function() {

   $$('a.button-view-details').first().removeClassName('on');

   // give time to scroll top

   GMX.scroll.top();

   setTimeout(function() { Effect.BlindUp('details',{duration:0.8}); }, 1000);

  }

 },





 // faq - show/hide faq answer

        /** Locked down by Ascent.

          * This method should no longer be subject to code drops by Huge.  All changes

          * should be internal only.

          */

 faq: {

  setup: function() {



   // add click event to expand button

   $('faq-button-expand').observe('click',function(event){

    Event.stop(event);

    // show answer

    $$('.text li').each(function(el){

     el.addClassName('selected');

    });

   });



   // add click event to collapse button

   $('faq-button-collapse').observe('click',function(event){

    Event.stop(event);

    // hide answer

    $$('.text li').each(function(el){

     el.removeClassName('selected');

    });

   });



   // add click event to all questions

   $$('.text a.question').each(

    function(el){

     el.observe('click',function(event){

      // stop event propagation

      Event.stop(event);

      var container = el.up();

      // show / hide answer

      if(container.hasClassName('selected')) {

       container.removeClassName('selected');

      } else {

       container.addClassName('selected');

      }

     });

    }

   );

  }

 },





 // more bio button - show more bio info in team page

        /** Locked down by Ascent.

          * This method should no longer be subject to code drops by Huge.  All changes

          * should be internal only.

          */

        more_bio: {

  setup: function() {

   // add click event to all button

   $$('.staff-item a.show-bio').each(

    function(el){

     el.observe('click',function(event){

      // stop event propagation

      Event.stop(event);

      var container = el.up();

      // add class to show more bio info

      container.addClassName('more-bio');

     });

    }

   );

  }

 },



 // utility methods for global site usage

 utility: {

	   ie: {

		   pngfix: function(){

			if(Prototype.Browser.IE){

			 //Fix IE pngs via an added class (ie-fix-opacity)

			 $$('.pngfix').each(function(el){

			  var bg = el.currentStyle.backgroundImage;

			  var img = bg.substring(bg.indexOf('"') + 1, bg.lastIndexOf('"'));

			  el.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img + "', sizingMethod='scale')";

			  el.style.backgroundImage = "none";

			 });

			}

		   },



            btnfix: function(){

                if(Prototype.Browser.IE7){
                    $$('button.blue-btn').each(function(el){
                        el.observe('mousedown', function(){
                            el.style.backgroundPosition = "1 2px";
                        });
                    });

                    $$('button.blue-btn').each(function(el){
                        el.observe('mouseup', function(){
                            el.style.backgroundPosition = "0 1px";
                        });
                    });



                    $$('button.green-btn').each(function(el){
                        el.observe('mousedown', function(){
                            el.style.backgroundPosition = "1 2px";
                        });
                    });

                    $$('button.green-btn').each(function(el){
                        el.observe('mouseup', function(){
                            el.style.backgroundPosition = "0 1px";
                        });
                    });
                }else if(Prototype.Browser.IE8){
                    $$('button.blue-btn').each(function(el){
                        el.observe('mousedown', function(){
                            el.style.backgroundPosition = "1.8 2.5px";
                        });
                    });
                    $$('button.blue-btn').each(function(el){
                        el.observe('mouseup', function(){
                            el.style.backgroundPosition = "0.8 .5px";
                        });
                    });
                    $$('button.green-btn').each(function(el){
                        el.observe('mousedown', function(){
                            el.style.backgroundPosition = "1.8 2.5px";
                        });
                    });
                    $$('button.green-btn').each(function(el){
                        el.observe('mouseup', function(){
                            el.style.backgroundPosition = "0.8 .5px";
                        });
                    });
                }
            }
	}
},





 // options object

 options:{

  // last dropdown openned

  last_option: null,

  // main dropdown object

  dropdown: null,

  // timeout to out event

  timeout: null,

  timeout_over: null,

  current_option:null,

  // out event

  out: function() {

   // cleartimeout

   clearTimeout(GMX.options.timeout);

   // show hidden options button

   if(this.last_option) this.last_option.removeClassName('dropdown-options-on');

   // hide dropdown menu

   if(this.dropdown) this.dropdown.hide();

   this.current_option=null;

  },

  // over event

  over: function(el) {

      var itemType='';
      var itemTypeId='';
      var d;
      var olddiv;
      for(var i=0;i<el.childNodes.length;i++)
         {
        itemType=el.childNodes[i].value;
        itemTypeId=el.childNodes[i].id;
        if(itemType!=null && itemType!='' && itemType=='Event' && itemTypeId!=null && itemTypeId!='' && itemTypeId.indexOf('itemType')>-1){
           d = document.getElementById('options-content');
           olddiv = document.getElementById('score');
          if(olddiv!=null && d!=null){
             d.removeChild(olddiv);
           }
        }else if(itemTypeId!=null && itemTypeId!='' && itemTypeId.indexOf('itemType')>-1){
          olddiv = document.getElementById('score');
           d = document.getElementById('options-content');
            if(olddiv==null && d!=null){
            var aLink = new Element("a",{
                            'href':'javascript:void(0);',
                            'id':'score',
                            'class':'score'
                        });
            d.appendChild(aLink);
            GMX.innerPopups.scoreFunction();
            }
          }
         }



   // out event to close openned dropdowns

   GMX.options.out();

   // if this option button is on, quit

   if(el.hasClassName('dropdown-options-on')) return;

   this.current_option=el;

   // remove light gray layout

   this.dropdown.removeClassName('dropdown-options-light');

   // if this option button is light gray, apply light gray layout to droddown

   if(el.hasClassName('dropdown-options-light')) this.dropdown.addClassName('dropdown-options-light');

   // set droddown position

   var pos = el.cumulativeOffset();

   var margin_top = el.getStyle('margin-top').split('px').join('');

   this.dropdown.setStyle({left:pos.left+'px',top:pos.top-margin_top+'px'});

   // hide this option button

   el.addClassName('dropdown-options-on');

   // show dropdown

   this.dropdown.show();

   // save option button

   this.last_option = el;

   // add over event to clear out timeouts

   this.dropdown.stopObserving('mouseover');

   this.dropdown.observe('mouseover',function(event){

    Event.stop(event);

    clearTimeout(GMX.options.timeout);

   });

   // add out events

   this.dropdown.stopObserving('mouseout');

   this.dropdown.observe('mouseout',function(event){

    Event.stop(event);

    clearTimeout(GMX.options.timeout);

    // ou mouseout, add timeout to close option drodown

    GMX.options.timeout = setTimeout(function() {

     GMX.options.out();

    }, 100);

   });

   // add click event to each link child of the dropdown, gets id from option button: <div class="dropdown-options" id="options-123" />

   $$('div.options-content a').each(function(item){

    item.observe('mouseover', function(){

     item.addClassName('over-light');



    });

    item.observe('mouseout', function(){

     item.removeClassName('over-light');

    });

   });



  },

  // setup object

  setup: function() {

   GMX.options.out();

   // add over event to all option buttons

   $$('#main div.dropdown-options').each(

    function(el){

     el.stopObserving('mouseover');

     el.observe('mouseover',function(event){

      Event.stop(event);

      GMX.options.timeout_over = setTimeout( function() {

       clearTimeout(GMX.options.timeout_over);

       GMX.options.over(el);

      },300 );



     });

     el.observe('mouseout',function(event){

      Event.stop(event);

      clearTimeout(GMX.options.timeout_over);

     });

    }

   );

   if(!this.dropdown) {



    this.dropdown = $('options-dropdown-div');

    // hide it
    if(this.dropdown){
    this.dropdown.hide();
    }

   }

  }

 },



 // updates setup

 updates:{

  setup: function() {

   // add click event to each updates more buttom

   $$('#main .sidebar .updates a.more').each(

    function(el){

     el.observe('click',function(event){

      // stop event propagation

      Event.stop(event);

      // if container visible, close, if not, open

      var container = el.up();

      if(container.hasClassName('updates-on')) {

       container.removeClassName('updates-on');

      } else {

       container.addClassName('updates-on');

      }

     });

    }

   );

  }

 },



 // side_bar setup

        // Note - This latest code merge should work.  If it does not, revert

        // side_bar back to previous version and lock this object down.

 side_bar:{

  // expand all sections

  expandAll: function() {

   $$('#main .sidebar-navigation .section').each(

    function(el) {

     el.addClassName('section-on');

    }

   );

  },

  // collapse all sections

  collapseAll: function() {

   $$('#main .sidebar-navigation .section').each(

    function(el) {

     el.removeClassName('section-on');

    }

   );

  },

  openSection: function(clsNameSection){

	$$('div.sidebar-navigation div.section').each(function(item){

		item.removeClassName("section-on");

		if(item.hasClassName(clsNameSection)){

			item.addClassName("section-on");

		}

	});

  },

  // removes link sections

    removeLink: function(el) {

        if(el){
           if(el.hasChildNodes()){

            var span = document.createElement('span');

            for(var i=0; i<el.childNodes.length; i++){

                span.appendChild(el.childNodes[i].cloneNode(true))

            }

            el.parentNode.insertBefore(span, el);

        }

        el.parentNode.removeChild(el);
        }
    },

  setup: function() {

   // add click event to each side_bar more buttom

   $$('#main .sidebar-navigation a.more').each(

    function(el){

     el.observe('click',function(event){

      // stop event propagation

      Event.stop(event);

      // if container visible, close, if not, open

      var container = el.up();

      if(container.hasClassName('section-on')) {

       container.removeClassName('section-on');

      } else {

       container.addClassName('section-on');

      }

     });

    }

   );

            $$('#main .sidebar-navigation ul.subnavigation a').each(

                function(el){
                    if(el.firstChild){
                        if($('activeLink')){
                            if(el.firstChild.nodeValue == $('activeLink').value){

                                var parentDiv = el.up().up().up();

                                GMX.side_bar.removeLink(el);

                                parentDiv.addClassName('section-on');

                            }
                        }
                    }
                }

                );

            // add expandAll/collapseAll button event

   var button = $('button-expand');

   if(button) {

    button.observe('click',function(event){

     Event.stop(event);

     GMX.side_bar.expandAll();

    });

   }

   button = $('button-collapse');

   if(button) {

    button.observe('click',function(event){

     Event.stop(event);

     GMX.side_bar.collapseAll();

    });

   }

  }

 },



 // quick_links setup

        /** Locked down by Ascent.

          * This method should no longer be subject to code drops by Huge.  All changes

          * should be internal only.

          */

          quick_links: {

  setup: function() {

   $$('div.quick-links a').each(

    function(el){

     // add click events

     el.observe('click',function(event){

      // stop event propagation

      Event.stop(event);

      // get hash name

      var scrollto = (' ' +el.hash).split('#')[1];

      if($(scrollto)){

          new Effect.ScrollTo(scrollto);

      }

     });

    }

   );

  }

 },



 // toc_links setup

 toc_links: {

  setup: function() {

   $$('ol#toc-list a').each(

    function(el){

     // add click events

     el.observe('click',function(event){

      // stop event propagation

      Event.stop(event);

      // get hash name

      var scrollto = (' ' +el.hash).split('#')[1];



      if($(scrollto)) new Effect.ScrollTo(scrollto);



     });

    }

   );



   $$('a.back-to-top').each(

    function(el){

     // add click events

     el.observe('click',function(event){

      // stop event propagation

      Event.stop(event);

      // get hash name

      var scrollto = (' ' +el.hash).split('#')[1];



      GMX.scroll.top();

     });

    }

   );





  }

 },



 // player object: edited by daryl bowden @ HUGE on 4/22/2009
	player: {
		is_loaded: false,
		obj: null,
		// setup player
		setup: function() {
			// if loaded, don't get object again
			if(this.is_loaded) return true;
			// set loaded flag
			this.is_loaded = true;
			// set player container
			this.obj = $('player');
		},
		// open player
		open: function() {
			// setup player
			this.setup();
			// if there is no player, quit
			if(!this.obj) return;
			// open player container
			Effect.SlideDown(this.obj,{ duration: 0.3, afterFinish: GMX.player.play});
		},
		// close player
		close: function() {
			// setup player
			this.setup();
			// if there is no player, quit
			if(!this.obj) return;
			GMX.player.stop();
			// close player container
			Effect.SlideUp(this.obj,{ duration: 0.3, afterFinish: GMX.player.enableToggle });
			//this.stop();
		},
		// stop video
		stop: function() {
			if(typeof(	$('AkamaiFlashPlayer').pauseMovie) == "function"){
				$('AkamaiFlashPlayer').pauseMovie();
			}
		},
		enableToggle: function(){
            $$("div.trailer-toggle a").first().stopObserving('click');
			$$("div.trailer-toggle a").first().observe('click',function(event){
				// Stop the onclick event propagation
				Event.stop(event);
				if(Event.element(event).hasClassName("closed")){
					// Open the trailer
					Event.element(event).removeClassName("closed");
					GMX.player.open();
				} else {
					// Close the trailer
					Event.element(event).addClassName("closed");
					// Scroll to the top of the page
					GMX.scroll.top();
					// Give time to scroll top
					setTimeout(function() {
						GMX.player.close();
						GMX.episodes_navigation.close();
						//GMX.details.open();
					}, 1000);
				}
			});
		},

		// play video
		play: function() {
			if(typeof($('AkamaiFlashPlayer').playMovie) == "function"){
					$('AkamaiFlashPlayer').playMovie();
			}
			GMX.player.enableToggle();
		}
	},

	// END 4/22/09 edits

    package_player: {
        obj: null,
        is_loaded: false,
        // setup player
        // open player
        setup: function() {
            if(this.is_loaded) return true;
			// set loaded flag
			this.is_loaded = true;
            this.obj = $('package_player_wrapper');
        },
        open: function() {
            // setup player
            this.setup();
            // if there is no player, quit
            if(!this.obj) return;
            // open player container
            Effect.SlideDown(this.obj ,{duration: 0.3,afterFinish: GMX.package_player.play});
        },
        // close player
        close: function() {
            // setup player
            this.setup();
            // if there is no player, quit
            if(!this.obj) return;
            GMX.package_player.stop();
            // close player container
            Effect.SlideUp(this.obj , {duration: 0.3,afterFinish: GMX.package_player.enableToggle});
        //this.stop();
        },
  		play: function() {
			if(typeof($('AkamaiFlashPlayer').playMovie) == "function"){
					$('AkamaiFlashPlayer').playMovie();
			}
			GMX.package_player.enableToggle();
		},
        stop: function() {
			if(typeof(	$('AkamaiFlashPlayer').pauseMovie) == "function"){
				$('AkamaiFlashPlayer').pauseMovie();
			}
		},
        enableToggle: function(){
            $$("div.trailer-toggle a").first().stopObserving('click');
            $$("div.trailer-toggle a").first().observe('click',function(event){
                // Stop the onclick event propagation
                Event.stop(event);
                if(Event.element(event).hasClassName("closed")){
                    // Open the trailer
                    Event.element(event).removeClassName("closed");
                    GMX.package_player.open();
                } else {
                    // Close the trailer
                    Event.element(event).addClassName("closed");
                    // Scroll to the top of the page
                    GMX.scroll.top();
                    // Give time to scroll top
                    setTimeout(function() {
                        GMX.package_player.close();
                        GMX.episodes_navigation.close();
                    //GMX.details.open();
                    }, 1000);
                }
            });
        }
    },


 // breadcrumb object

 breadcrumb: {

  obj: null,

  open: function() {

   // open breadcrumb

   if(this.obj) Effect.BlindDown('breadcrumb',{ duration: 0.3 });

   else if(this.obj==null){

    if($('breadcrumb')) {

     this.obj = true;

     this.open();

    }

   }

  },

  close: function() {

   // close breadcrumb

   if(this.obj) Effect.BlindUp('breadcrumb',{ duration: 0.3 });

   else if(this.obj==null){

    if($('breadcrumb')) {

     this.obj = true;

     this.close();

    }

   }

  }

 },



 // form_steps object

 form_steps: {

  form: null,

  steps: null,

  setup: function(frm,steps) {

   this.form = frm;

   this.steps = steps;

   // create all fieldsets

   for(var i=0,len=this.steps.length;i<len;i++) {

    var fieldset = document.createElement('fieldset');

    fieldset.id = 'step-'+i;

    $(this.form).insert(fieldset);

   }

   // load first fieldset

   this.load(0);

  },

  load: function(n) {

   // remove all active fieldsets

   $$('fieldset.active').each(

    function(el) {

     el.removeClassName('active');

    }

   );

   // remove all active steps header titles

   $$('#steps-header strong').each(

    function(el) {

     el.removeClassName('active');

    }

   );

   // set header active title

   $('title-step-'+n).addClassName('active');

   // if step was not loaded before, do ajax call

   if(!this.steps[n].loaded) {

    $(this.form).addClassName('loading');

    this.steps[n].loaded = true;

    var url = this.steps[n].url;

    var onload = this.steps[n].onload;

    new Ajax.Updater('step-'+n,url,

    {

        method:'get',

        onComplete: function(){

      if(onload) onload();

      $('step-'+n).addClassName('active');

      $(GMX.form_steps.form).removeClassName('loading');

      GMX.select.setup();

      GMX.tooltip.setup();

      GMX.static_tooltip.setup();

        }

    });

   } else {

    $('step-'+n).addClassName('active');

    if(onload) onload();

   }

  }

 },

// NEW_GMX_MENU
	// gmx_menu object
	gmx_menu: {
        setup: function(){
            if($('gmx-menu')==null) return;
            if($('gmx-menu').hasClassName('menu-on')) return;

            //To disable my gmx link in deal memo editor wizard
            var disableLinks = $('disableLinks');
            if ( disableLinks ) {
                $('gmx-menu').observe('mouseover', function(){
                    $('gmx-menu').removeClassName('menu-on');
                });
            } else {
                // open gmx_menu dropdown on mouseover
                $('gmx-menu').observe('mouseover', function(){
                    $('gmx-menu').addClassName('menu-on');
                });

                // close gmx_menu dropdown on mouseout
                $('gmx-menu').observe('mouseout', function(){
                    if(window.event){
                        if(window.event.toElement && (window.event.toElement.id =='' || window.event.toElement.id =='myDealsId'
                            || window.event.toElement.id =='myListsId'|| window.event.toElement.id =='myTitlesId'|| window.event.toElement.id =='myProfileId'
                            || window.event.toElement.id =='myCompanyId' || window.event.toElement.id =='myAccountId')){
                            var dummy;
                        }else{
                            $('gmx-menu').removeClassName('menu-on');
                        }
                    }else{
                        $('gmx-menu').removeClassName('menu-on');
                    }
                });
            }
        }
    },

// NEW_GMX_MENU
// // gmx_menu object
//
//    gmx_menu: {
//        setup: function(){
//            if($('gmx-menu')==null) return;
//            // open gmx_menu dropdown on mouseover
//            $('gmx-menu').observe('mouseover', function(){
//                this.addClassName('menu-on');
//
//    if(Prototype.Browser.IE){
//
//      $('search').style.zIndex = -1;
//
// $('main').style.position = 'relative';
//
// $('main').style.zIndex = -1;
//
//    }
//
//   });
//
//   // close gmx_menu dropdown on mouseout
//
//   $('gmx-menu').observe('mouseout', function(){
//
//    this.removeClassName('menu-on');
//
//    if(Prototype.Browser.IE){
//
//       $('search').style.zIndex = 10;
//
//   $('main').style.zIndex = 1;
//
//  $('main').style.position = '';
//
//        }
//
//   });
//
//  }
//
// },



 // episodes_navigation object

 episodes_navigation: {

  is_loaded: false,

  obj: null,

  // setup episodes_navigation

  setup: function() {

   // if loaded, don't get object again

   if(this.is_loaded) return true;

   // set loaded flag

   this.is_loaded = true;

   // set episodes_navigation container

   this.obj = $('episodes-navigation');

  },

  // open episodes_navigation

  open: function() {

   // setup episodes_navigation

   this.setup();

   // if there is no episodes_navigation, quit

   if(!this.obj) return;

   // open episodes_navigation container

   Effect.BlindDown(this.obj,{ duration: 0.3 });

  },

  // close episodes_navigation

  close: function() {

   // setup player

   this.setup();

   // if there is no episodes_navigation, quit

   if(!this.obj) return;

   // close episodes_navigation container

   Effect.BlindUp(this.obj,{ duration: 0.3 });

  }

 },





 // header dropdown_navigation object

        /** Locked down by Ascent.

          * This method should no longer be subject to code drops by Huge.  All changes

          * should be internal only.

          */

          dropdown_navigation: {

   close: function() {

            // open breadcrumb

            GMX.breadcrumb.open();

            // open episodes_navigation

            GMX.episodes_navigation.open();

            //GMX.player.open(); // removed, player does not open/close anymore

            // call back function, hide dropdown_navigation after dropdown_navigation close

            GMX.dropdown_navigation.hide();

            var afterFinish = GMX.dropdown_navigation.hide;

            // close container

            Effect.BlindUp('dropdown-navigation',{ duration: 0.3, afterFinish:afterFinish });

        },



  // open dropdown_navigation container

  open: function(callback) {

   // close breadcrumb

   GMX.breadcrumb.close();

   // close episodes_navigation

   GMX.episodes_navigation.close();

   //GMX.player.close(); // removed, player does not open/close anymore

   // call back function, show dropdown_navigation after dropdown_navigation open

   var afterFinish = GMX.dropdown_navigation.show;

   if(callback) afterFinish = callback;

   // open container

   Effect.BlindDown('dropdown-navigation',{ duration: 0.3, afterFinish:afterFinish });

  },

  // show dropdown_navigation content

  show: function() {

   // get dropdown_navigation content

   var div = $$('#dropdown-content div.dropdown-content').first();

   // if there...

   if(div)  {

    // set to transparent

    div.setOpacity(0);

    // show it

    div.setStyle({display:'block'});

    // fade opacity

    div.fade({ duration: 0.3, from: 0, to: 1 });



    $$('#dropdown-content div.dropdown-content a img').each(

                    function(el){

                        el.src = unescape(el.src);

                    }

                    );

   }

   // remove classes loading and closed

   $('dropdown-content').removeClassName('loading');

   $('dropdown-content').removeClassName('closed');

  },



// hide dropdown_navigation content

        hide: function() {

            // get dropdown_navigation content

            var div = $$('#dropdown-content div.dropdown-content').first();

            // set to transparent

            if(div){

                if (Prototype.Browser.IE){

                    div.hide();

                }

                div.setOpacity(0);

            }

            // remove class loading

            $('dropdown-content').removeClassName('loading');

            // add class closed

            $('dropdown-content').addClassName('closed');

        },





  // setup dropdown_navigation

  setup: function(){

   // add dropdown-navigation element

   var obj = $$('#header .content').first();

   if(!obj) obj = $('header');

   obj.insert( {after:'<div id="dropdown-navigation" style="display:none"><div id="dropdown-content"></div></div>'} );

  }

 },



    // tooltip object

    /** Locked down by Ascent.

      * This method should no longer be subject to code drops by Huge.  All changes

      * should be internal only.

      */

    tooltip: {

        // add onclick event to all tooltip links

        setup: function() {

            $$('a.tooltip').each(
            function(el){
                    GMX.tooltip.observe_tooltip(el);
            });

           $$('img.tooltip').each(
                function(el){
                        GMX.tooltip.observe_tooltip(el);
                });

            },

        observe_tooltip:function(el) {

                    // if tooltip was loaded before, quit

                    if(el.hasClassName('tooltip-loaded')) return;

                    el.addClassName('tooltip-loaded');

                    el.stopObserving('mouseover');

                    el.observe('mouseover', function(event){

                        if(el.hasClassName('tooltip-over')) return;

                        el.addClassName('tooltip-over');

                        clearTimeout(GMX.tooltip.timeout);

                        Event.stop(event);

                        GMX.tooltip.timeout = setTimeout( function(){

                            var evt = window.event || event //cross browser event object

                            GMX.tooltip.open(el, evt);

                        }, 0 );

                    });

                    el.stopObserving('mouseout');

                    el.observe('mouseout', function(event){

                        clearTimeout(GMX.tooltip.timeout);

                        Event.stop(event);

                        GMX.tooltip.timeout = setTimeout( function(){

                            var evt = window.event || event //cross browser event object

                            GMX.tooltip.close(el, evt);

                        }, 0 );

                    });

                },

        // open tooltip

        open: function(el, e) {
            try{
                // close other tooltips
                GMX.tooltip.close(el, e);
                // if ie, get different left arrow (in IE6, the layout of the tooltip has a different shadow)
                var arrow = '<img src="' + requestContext + '/img/tootip-arrow.png" width="32" height="32" alt="Arrow" />';
                if(Prototype.Browser.IE){
                    var version = parseFloat(navigator.appVersion.split('MSIE')[1]);
                    if ((version >= 5.5) && (version < 7)) arrow = '<img src="' + requestContext + '/img/tootip-arrow-ie6.png" width="32" height="32" alt="Arrow" />';
                }

                if(!Prototype.Browser.WebKit){
                    // tooltip htm
                    var tooltip = '<div id="tooltip" class="tooltip">\
                                    <table border="0" cellspacing="0" cellpadding="0">\
                                     <tr>\
                                      <td class="tooltip-top-left">&#160;</td>\
                                      <td class="tooltip-top">&#160;</td>\
                                      <td class="tooltip-top-right">&#160;</td>\
                                     </tr>\
                                     <tr>\
                                      <td class="tooltip-left">' + arrow + '</td>\
                                      <td id="tooltip-content-wrapper" class="tooltip-content tooltip-content-loading">\
                                       <div id="tooltip-content"></div><div id="tooltip-content-dummy" style="display:none;"></div>\
                                      </td>\
                                      <td class="tooltip-right">&#160;</td>\
                                     </tr>\
                                     <tr>\
                                      <td class="tooltip-bottom-left">&#160;</td>\
                                      <td class="tooltip-bottom">&#160;</td>\
                                      <td class="tooltip-bottom-right">&#160;</td>\
                                     </tr>\
                                    </table>\
                               </div>';
                    // append tooltip htm
                    $('main').insert(tooltip);
                }else{
                    var mainDiv  = document.createElement('div');
                    mainDiv.setAttribute('id','tooltip');
                    mainDiv.setAttribute('class','tooltip');
                    var mainTable = document.createElement('table');
                    mainDiv.appendChild(mainTable);

                    mainTable.setAttribute('border','0');
                    mainTable.setAttribute('cellspacing','0');
                    mainTable.setAttribute('cellpadding','0');

                    var row  = document.createElement('tr');
                    mainTable.appendChild(row);
                    //<td class="tooltip-top-left">&#160;</td>
                    var col = document.createElement('td');
                    col.setAttribute('class','tooltip-top-left');
                    var tn = document.createTextNode(' ');
                    col.appendChild(tn);
                    row.appendChild(col);
                    //<td class="tooltip-top">&#160;</td>\
                    col = document.createElement('td');
                    col.setAttribute('class','tooltip-top');
                    tn = document.createTextNode(' ');
                    col.appendChild(tn);
                    row.appendChild(col);
                    //<td class="tooltip-top-right">&#160;</td>
                    col = document.createElement('td');
                    col.setAttribute('class','tooltip-top-right');
                    tn = document.createTextNode(' ');
                    col.appendChild(tn);
                    row.appendChild(col);

                    row  = document.createElement('tr');
                    mainTable.appendChild(row);
                    //<td class="tooltip-left">' + arrow + '</td>\
                    col = document.createElement('td');
                    col.setAttribute('class','tooltip-left');
                    //<img src="' + requestContext + '/img/tootip-arrow.png" width="32" height="32" alt="Arrow" />
                    var img = document.createElement('img');
                    img.setAttribute('src', requestContext + '/img/tootip-arrow.png');
                    img.setAttribute('width', '32');
                    img.setAttribute('height', '32');
                    img.setAttribute('alt', 'Arrow');
                    col.appendChild(img);
                    row.appendChild(col);
                    //<td id="tooltip-content-wrapper"
                    col = document.createElement('td');
                    col.setAttribute('id','tooltip-content-wrapper');
                    col.setAttribute('class','tooltip-content tooltip-content-loading');
                    row.appendChild(col);
                    //<div id="tooltip-content"></div>
                    var innerDiv  = document.createElement('div');
                    innerDiv.setAttribute('id','tooltip-content');
                    col.appendChild(innerDiv);
                    //<div id="tooltip-content-dummy" style="display:none;"></div>
                    innerDiv  = document.createElement('div');
                    innerDiv.setAttribute('id','tooltip-content-dummy');
                    innerDiv.setAttribute('style','display:none;');
                    col.appendChild(innerDiv);
                    //<td class="tooltip-right">&#160;</td>
                    col = document.createElement('td');
                    col.setAttribute('class','tooltip-right');
                    tn = document.createTextNode(' ');
                    col.appendChild(tn);
                    row.appendChild(col);

                    row  = document.createElement('tr');
                    mainTable.appendChild(row);
                    //<td class="tooltip-top-left">&#160;</td>
                    col = document.createElement('td');
                    col.setAttribute('class','tooltip-bottom-left');
                    tn = document.createTextNode(' ');
                    col.appendChild(tn);
                    row.appendChild(col);
                    //<td class="tooltip-top">&#160;</td>\
                    col = document.createElement('td');
                    col.setAttribute('class','tooltip-bottom');
                    tn = document.createTextNode(' ');
                    col.appendChild(tn);
                    row.appendChild(col);
                    //<td class="tooltip-top-right">&#160;</td>
                    col = document.createElement('td');
                    col.setAttribute('class','tooltip-bottom-right');
                    tn = document.createTextNode(' ');
                    col.appendChild(tn);
                    row.appendChild(col);
                    $('main').appendChild(mainDiv);
                }

                var leftOffset = 130;  //var leftOffset = 55; Updated to fix GMX:3170
                if(el.hasClassName("tooltip-list")) {
                    leftOffset = -10;
                    if(Prototype.Browser.IE){
                        var version = parseFloat(navigator.appVersion.split('MSIE')[1]);
                        if (version >= 8) {
                            leftOffset = 130; //leftOffset = 55; Updated to fix GMX:3170
                        }
                    } else if(Prototype.Browser.WebKit) {
                        leftOffset = 130; //leftOffset = 55; Updated to fix GMX:3170
                    }
                }



            // Added to fix GMX:3170 for showCase
            var parentForm = GMX.tooltip.parentForm(el);

            if(parentForm.tooltipShowCase != null && parentForm.tooltipShowCase.value == "true"){
                leftOffset = 173;
            }

            // get tooltip position and load it
            var obj = $('tooltip');
            if(obj){
                if(el.hasClassName("add-field-btn") || el.hasClassName("min-field-btn")){
                    obj.clonePosition(el, {setWidth: false, setHeight: true, offsetLeft: 60, offsetTop: -42});
                }
                else {
                    obj.clonePosition(el, {setWidth: false, setHeight: true, offsetLeft: leftOffset, offsetTop: -10}); //offsetTop: -45 Updated to fix GMX:3170
                }
                obj.stopObserving('mouseout');
                obj.observe('mouseout', function(event){
                    clearTimeout(GMX.tooltip.timeout);
                    Event.stop(event);
                    GMX.tooltip.timeout = setTimeout( function(){
                        var evt = window.event || event //cross browser event object
                        GMX.tooltip.close(el, evt);
                    }, 0 );
                });
                obj.stopObserving('mouseover');
                obj.observe('mouseover', function(event){
                    Event.stop(event);
                    clearTimeout(GMX.tooltip.timeout);
                });
            }
            if(el.rel){
                var tcw = $('tooltip-content-wrapper'); // remove tooltip loading gif
                if(tcw) tcw.removeClassName('tooltip-content-loading');
                $('tooltip-content').innerHTML = el.rel;
            }else{
                GMX.tooltip.load(el);
            }
        }catch(exp){alert(exp)}
        },

        // close all tooltip

        close: function(el, e) {
            if(el){
                if(el) el.removeClassName('tooltip-over');
                var obj = $('tooltip'); // remove tooltip object
                if(obj) obj.up().removeChild(obj);
            }
        },

        parentForm:function(el){
            var parent = el.parentNode;
            while(parent.nodeName.toLowerCase() != 'form' && parent.nodeName.toLowerCase() != 'body') {
                parent = parent.parentNode;
            }
            return parent;
        },

        // load tolltip
        load: function(el) {
            var obj = $('tooltip-content-dummy');
            if(obj) {
                // get ajax content
                var parentForm = GMX.tooltip.parentForm(el);
                var linkName = el.name;
                new Ajax.Updater(obj, parentForm.action,
                    {   asynchronous: false,
                        method: "post",
                        parameters: "ajax=true&action=getTooltip&itemId=" + parentForm.tooltipItemId.value + "&itemType=" + parentForm.tooltipItemType.value + "&formId=" + parentForm.id + "&linkName=" + linkName,
                        onComplete: function(req){
                            if(req.responseText != null &&  req.responseText != ''){
                                var responseText =  req.responseText;
                                if(responseText.indexOf('homePage()', 0) > 0 ){
                                    //alert('Your session expired...');
                                    location.href=requestContext;
                                    return;
                                }else{
                                    var obj = $('tooltip-content-wrapper'); // remove tooltip loading gif
                                    if(obj) obj.removeClassName('tooltip-content-loading');
                                    $('tooltip-content').innerHTML =  req.responseText;
                                    if(req.responseText != null &&  req.responseText != '') el.rel = req.responseText;
                                }
                            }
                        },
                        onFailure: function(){ }
                    });
            }
        }
    },


   /////////// Static Tooltip ///////////

   static_tooltip: {
        // add onclick event to all static_tooltip links
        setup: function() {
            $$('a.tooltip').each(
                function(el) {
                    // if tooltip was loaded before, quit
                    if(el.hasClassName('tooltip-loaded')) return;
                    el.addClassName('tooltip-loaded');
                    el.stopObserving('click');
                    el.observe('click', function(event){
                        Event.stop(event);
                    });
                    el.stopObserving('mouseover');
                    el.observe('mouseover', function(event){
                        clearTimeout(GMX.static_tooltip.timeout);
                        Event.stop(event);
                        GMX.static_tooltip.timeout = setTimeout( function(){
                            GMX.static_tooltip.open(el);
                        }, 200 );
                    });

                    el.stopObserving('mouseout');
                    el.observe('mouseout', function(event){
                        clearTimeout(GMX.static_tooltip.timeout);
                        Event.stop(event);
                        GMX.static_tooltip.timeout = setTimeout( function(){
                            GMX.static_tooltip.close();
                        }, 100 );
                    });
                }
            );
        },

        // open static_tooltip

        open: function(el) {
            // close other static_tooltips
            GMX.static_tooltip.close();
            var obj = $('static-tooltip');
            if(obj){
                //obj.up().removeChild(obj);
                obj.style.display='none';
            }

            // get static_tooltip position and load it
            var obj = $('static-tooltip');
            obj.style.display='block';
            obj.clonePosition(el, {
                setWidth: false,
                setHeight: false,
                offsetLeft: 55,
                offsetTop:-45
            });

            obj.stopObserving('mouseout');

            obj.observe('mouseout', function(event){
                clearTimeout(GMX.static_tooltip.timeout);
                Event.stop(event);
                GMX.static_tooltip.timeout = setTimeout( function(){
                    GMX.static_tooltip.close();
                }, 0 );
            });

            obj.stopObserving('mouseover');
            obj.observe('mouseover', function(event){
                Event.stop(event);
                clearTimeout(GMX.static_tooltip.timeout);
            });
            GMX.static_tooltip.load(el);
        },

        // close all static_tooltip
        close: function(el) {
            try{
            // remove static_tooltip object
            var obj = $('static-tooltip');
            if(obj){
                //obj.up().removeChild(obj);
                obj.style.display='none';
            }
            obj = $('tooltip-content');
            if(obj){
                obj.style.display='none';
            }
            }catch(err){
                alert('Tooltip close error: '+ err);
            }
        },

        // load tolltip
        load: function(el) {
            var obj = $('tooltip-content');
            if(obj) {
                // get ajax content
                var parentDiv =el.up();
                var tooltipDivName;
                if(parentDiv && parentDiv.className.indexOf('tooltip-id:', 0) >= 0){
                    var totalLen = parentDiv.className.length;
                    var exLen = 'tooltip-id:'.length;
                    tooltipDivName= parentDiv.className.substr(exLen, totalLen);
                }
                new Ajax.Updater(obj,el.href,{
                        method:'get',
                        onComplete: function(){
                            // remove static_tooltip loading gif
                            var spinner = $('tooltip-content-wrapper');
                            if(spinner) spinner.removeClassName('tooltip-content-loading');
                            obj.style.display='block';
                            if(tooltipDivName){
                                $(tooltipDivName).style.display='block';
                            }
                        }
                    });
            }
        }
    },





 // custom select object

 select: {

  open_selects: [],

  close: function(el) {

   // hide options

          /* Condition added to resolve javascript error on clicking

           * rootCategory in category select box in Ask a question page

           */

            var selectedElem = el.select('div.options').first();

            if(selectedElem){

                selectedElem.hide();

            }

        //el.select('div.options').first().hide();

  },

  open: function(el) {

   // hide all select options of every custom select in the page

   this.closeAll();

   // save open custom selects

   this.open_selects.push(el);

   // show options

   el.select('div.options').first().show();

  },

  closeAll: function() {

   // hide all select options of every custom select in the page

   // if the user clicks outsite the select, every select should close

   for(var i=0,len=this.open_selects.length;i<len;i++) {

    var el = this.open_selects.pop();

    this.close(el);

   }

  },

  setup: function() {

   // create custom select html

   $$('select.custom-select').each(

    function(el) {

     if(el.hasClassName('select-loaded')) return;

     el.addClassName('select-loaded');

     var wrapper = document.createElement('div');

     wrapper.className = 'custom-select-wrapper';

     var select = document.createElement('div');

     select.className = 'custom-select';

     if(el.hasClassName('custom-select-white')) select.className = 'custom-select custom-select-white';

     if(el.hasClassName('custom-select-gray')) select.className = 'custom-select custom-select-gray';

     var space = document.createElement('div');

     space.className = 'custom-select-space';

     space.appendChild(document.createTextNode('.'))

     var options = document.createElement('div');

     options.className = 'options';

     var space1 = document.createElement('div');

     space1.className = "options-separator";

     options.appendChild(space1);

     var c = 0;

     el.select('option').each(function(el) {

      //the option with the 'optgroup' simulates the optgroup functionality in a regular select with optgroup tags

      if(el.className == 'optgroup'){

       var span = document.createElement('span');

       span.innerHTML = el.text;

       options.appendChild(span);

      }else{

       var a = document.createElement('a');

       a.href = '#' + el.value;

       a.innerHTML = el.text;

       // if first option, create selected element

       if(c==0) {

        var a_sel = a.cloneNode(true);

        a_sel.className = 'selected';
        a_sel.id = 'selected-search-option';

        select.appendChild(a_sel);

       }

       if(el.selected == true) a.className = 'will-be-selected';

       options.appendChild(a);

       c++;

      }

     });

     select.appendChild(options);

     wrapper.appendChild(select);

     wrapper.appendChild(space);

     // duplicate original select, and wrap inside the wrapper

     var el_dup = el.cloneNode(true);

     wrapper.appendChild(el_dup);

     el.insert({after:wrapper});

     // remove original select

     el.up().removeChild(el);

    }

   );

   GMX.select.events();

  },

  click: function(ev,element) {

   var el = null;

   if(ev) {

    el = Event.element(ev);

				Event.stop(ev);

			} else{

				el = element;

			}

			var container = el.up().up();

			GMX.select.close(container);

			// get last selected element

			var a = container.select('a');

			// save selected element

          /* Condition added  to resolve javascript error on clicking

           * rootCategory in category select box in Ask a question page

           */

            if(el.href){

                a.first().href = el.href;

                a.first().innerHTML = el.innerHTML;
                var searchScope = document.getElementById('searchScope-selected');
                if (searchScope) {
                    if (el.innerHTML == 'Titles') {
                        searchScope.value = "titles";
                    }
                    else if (el.innerHTML == 'Companies') {
                        searchScope.value = "companies";
                    }
                    else if (el.innerHTML == 'People') {
                        searchScope.value = "people";
                    }
                    else {
                        searchScope.value = "titles";
                    }
                }
            }

			a.each(

				function(el) {

					el.removeClassName('select-on');

				}

			);

			// show that the element was selected

			el.addClassName('select-on');

			// change form select value

			var test = (' ' + el.href).split('#')[1];

			var list = container.up().select('select').first();

          /* Condition added to resolve javascript error on clicking

           * rootCategory in category select box in Ask a question page

           */

            if(list){

                if(list.onchange) list.onchange();

                list.value = test;

                var options = list.getElementsByTagName('option');

                options = $A(options);

                var opt = options.find(function(o){

                    if(o.value == test) {

                        o.selected = true;

                    }

                });

            }

		},

		events: function() {

			// apply events to custom selects

			$$('body').first().stopObserving('click');

			$$('body').first().observe('click', function(event){

				// close all open custom selects on the page

				GMX.select.closeAll();

			});

			$$('div.custom-select').each(

				// for each custom select

				function(el){

					if(el.hasClassName('select-loaded')) return;

					el.addClassName('select-loaded');

					// set width

					var w = el.getWidth()+25+'px';

					el.setStyle({width:w});

					el.up().setStyle({width:w});

					// hide option and form select

					el.select('div.options').first().hide();

					el.up().select('select').first().hide();

					// add click event to container, to open and close

					el.stopObserving('click');

					el.observe('click', function(event){

						Event.stop(event);

						if(el.select('div.options').first().visible()) {

							GMX.select.close(el);

						} else {
                        var disableLinks = $('disableLinks');
                            if ( disableLinks ) {
                                GMX.select.close(el);
                            } else {
                                GMX.select.open(el);
                            }

						}

					});

				}

			);

			$$('div.custom-select div.options a').each(

				function(el) {

					el.stopObserving('click');

					el.observe('click', GMX.select.click);

				}

			);

			$$('div.custom-select div.options a.will-be-selected').each(

				function(el) {

					el.removeClassName('will-be-selected');

					GMX.select.click(null,el);

				}

			);

		}

	},



	// tabs object
	tabs: {
        setup: function(){
            $$('ul.tabs a').each(
                // for each tabs item
                function(el){
                    // add click event
                    el.observe('click', function(event){
                        Event.stop(event);
                        // hide all selected content
                        if(el && el.up() && el.up().up() && el.up().up().up()){
                            el.up().up().up().select('div.tabs-content').each(
                                function(el) {
                                    el.removeClassName('tabs-content-on');
                                });
                        }
                        // show selected content
                        var splittedVar = $((el.href).split('#')[1]);
                        if(splittedVar){
                            splittedVar.addClassName('tabs-content-on');
                        }
                        el.up().up().select('li').each(
                            function(el) {
                                el.removeClassName('tabs-on');
                            }
                        );
                        // disable all selected tabs items
                        el.up().addClassName('tabs-on');
                        //GMX-2507 Fix
                        if(typeof fixTabAlignmentIssue !== 'undefined' && fixTabAlignmentIssue){
                            fixTabAlignmentIssue();
                        }
                    });
                });
                //GMX-2507 Fix
                if(typeof fixTabAlignmentIssue !== 'undefined' && fixTabAlignmentIssue){
                    fixTabAlignmentIssue();
                }
            }
	},


	// tabs_carousel

	tabs_carousel: {

        setup: function(id, content_tabs){

            // get all tab itens

            var links = $(id).select('ul.tabs a');

            // load first carousel

            try{

                var category_carousel =  new GMX.Carousel(content_tabs[0].id,{

                    //url:content_tabs[0]['url'],

                    width:612

                });

            }catch (exp){

            }

            links[0].addClassName('item-loaded');

            // for each tab, add click event to load each carousel

            for(var i = 1; i < content_tabs.length; i++) {

                var el = links[i];

                if (el != null) {

                    el.tab = content_tabs[i];

                    el.observe('click', function(event){

                        Event.stop(event);

                        // prevent carousel from loading again

                        if(event.target.hasClassName('item-loaded')) return;

                        event.target.addClassName('item-loaded');

                        var tab = event.target.tab;

                        try{

                            new GMX.Carousel(tab.id,{

                                //url:tab.url,

                                width:612

                            });

                        }catch(exp){

                        }

                    });

                }

            }

        }

    },

// GMX_NEW_MENU
	// header navigation object
	navigation: {
		over_element: null,
		over_old_element: null,
		// navigation mouseout event
		out: function(){
			GMX.navigation.timeout = clearTimeout(GMX.navigation.timeout);
		},
		// navigation mouseover event
		over: function(url) {
			// get obj dropdown-content, if it is closed or loading, quit
			var obj = $('dropdown-content');
			if(obj.hasClassName('loading')) return;
			// if titles, change class to bigger dropdown
			if(this.over_element.hasClassName('titles')) $('dropdown-navigation').addClassName('dropdown-big');
			else $('dropdown-navigation').removeClassName('dropdown-big');
			this.over_old_element = this.over_element;
			// adding loading classe
			obj.addClassName('loading');
			// set call back function
			var callbackOpen = function(){
				new Ajax.Updater(obj,url,{
				    method:'get',
				    onComplete: function(req){
                                        if(req.responseText != null &&  req.responseText != ''){
                                            var responseText =  req.responseText;
                                            if(responseText.indexOf('homePage()', 0) > 0 ){
                                                //alert('Your session expired...');
                                                location.href=requestContext;
                                                return;
                                            }
                                        }
                                        // show dropdown-content
                                        GMX.dropdown_navigation.show();
				    }
				});
			}
			if(!obj.hasClassName('closed')) callbackOpen();
			// open dropdown_navigation, and call the ajax url
			else GMX.dropdown_navigation.open(callbackOpen);
		},
		// setup navigation
		setup: function(){
			$$('div#navigation ul li').each(
				function(el){
					el.observe('mouseover',
						function(){
                            try {
							el.addClassName('on');
							var otherNav = el.siblings();
							otherNav.each(
								function(el){
									el.removeClassName('on');
								});
                            } catch (ex) {}
						});
				})

			$$('div#navigation ul li').each(
				function(el){
					el.observe('mouseout',
						function(event){
                            try {
							if(event.relatedTarget.tagName.toLowerCase() == "div"){
								// stop event propagation
								$$('div#navigation ul li').each(
									function(el){
										el.removeClassName('on');
									});
								Event.stop(event);
							}else{
								el.addClassName('on');
								var otherNav = el.siblings();
								otherNav.each(
									function(el){
										el.removeClassName('on');
									});
							}
                            } catch (ex) {}
						});
				});
		}
	},

// GMX_NEW_MENU
//    // header navigation object
//
//    /** Locked down by Ascent.
//
//      * This method should no longer be subject to code drops by Huge.  All changes
//
//      * should be internal only.
//
//      */
//
//    navigation: {
//
//        over_element: null,
//
//        over_old_element: null,
//
//        // navigation mouseout event
//
//        out: function(){
//
//            GMX.navigation.timeout = clearTimeout(GMX.navigation.timeout);
//
//        },
//
//        // navigation mouseover event
//
//        over: function(url) {
//
//            // get obj dropdown-content, if it is closed or loading, quit
//
//            var obj = $('dropdown-content');
//
//            if(obj.hasClassName('loading')) return;
//
//            // if titles, change class to bigger dropdown
//
//            if(this.over_element.hasClassName('titles')) $('dropdown-navigation').addClassName('dropdown-big');
//
//            else $('dropdown-navigation').removeClassName('dropdown-big');
//
//            this.over_old_element = this.over_element;
//
//            // adding loading classe
//
//            obj.addClassName('loading');
//
//            // set call back function
//
//            var callbackOpen = function(){
//
//                var objDummy = document.createElement('div');
//
//                new Ajax.Updater(objDummy,url,
//
//                {
//
//                    method:'get',
//
//                    onComplete: function(req){
//
//                        if(req.responseText != null &&  req.responseText != ''){
//
//                            var responseText =  req.responseText;
//
//                            if(responseText.indexOf('homePage()', 0) > 0 ){
//
//                                //alert('Your session expired...');
//
//                                location.href=requestContext;
//
//                                return;
//
//                            }else{
//
//                                var obj = $('dropdown-content');
//
//                                obj.innerHTML = objDummy.innerHTML;
//
//                                // show dropdown-content
//
//                                GMX.dropdown_navigation.show();
//
//                            }
//
//                        }
//
//                    }
//
//                });
//
//            }
//
//            if(!obj.hasClassName('closed')) callbackOpen();
//
//            // open dropdown_navigation, and call the ajax url
//
//            else GMX.dropdown_navigation.open(callbackOpen);
//
//        },
//
//        // setup navigation
//
//        setup: function(){
//
//            // add class closed to #dropdown-content
//
//            $('dropdown-content').addClassName('closed');
//
//            // add mouse over event to #dropdown-content, this will stop mouseover propagation to #container, and keep the #dropdown-content openned
//
//            $('dropdown-navigation').observe('mouseover',function(event){
//
//                // stop event propagation
//
//                Event.stop(event);
//
//            });
//
//            // add mouse over event to #container, this will act like a mouseout event, and close the #dropdown-content
//
//            $$('body').first().observe('mouseover',function(event){
//
//                // stop event propagation
//
//                Event.stop(event);
//
//                // call navigation mouse out event
//
//                GMX.navigation.out();
//
//                // get obj, if obj is loading or it is closed, quit
//
//                var obj = $('dropdown-content');
//
//                if(obj.hasClassName('closed') || obj.hasClassName('loading')) return;
//
//                // add class loading
//
//                obj.addClassName('loading');
//
//                // close dropdown_navigation
//
//                GMX.dropdown_navigation.close();
//
//            });
//
//            $$('#navigation li a').each(function(el){
//
//                el.up().observe('mouseover',function(event){
//
//                    // stop event propagation
//
//                    Event.stop(event);
//
//                });
//
//            });
//
//            //highlight navigation tab
//
//            $$('#navigation li a').each(
//
//                function(el){
//
//                    if(el.className == $('navigationPage').value){
//
//                        el.up().addClassName('on');
//
//                    }
//
//                    el.observe('mouseover',function(event){
//
//                        GMX.navigation.over_element = el;
//
//                        // stop event propagation
//
//                        Event.stop(event);
//
//                        // call navigation out event
//
//                        GMX.navigation.out();
//
//                        // get url for the ajax call
//
//                        var url = requestContext + '/content/header/flyout_menu/' + el.className + '_content.jsf';
//
//                        // set a timeout, if no mouse out detected, the ajax call will be made
//
//                        GMX.navigation.timeout = setTimeout( function(){
//
//                            GMX.navigation.over(url);
//
//                        }, 500 );
//
//                    });
//
//                }
//
//                );
//
//
//
//            $$('#navigation-join li a').each(
//
//                function(el){
//
//                    if(el.className == $('navigationPage').value){
//
//                        el.up().addClassName('on');
//
//                    }
//
//                }
//
//                );
//
//        }
//
//    },



    // setup page object
    pages: {
        list: [],
        // add page object
        add: function(name,components,init) {
            this.list[name] = ( {
                components:components,
                init:init
            });
        },
        setup: function(name) {
            //alert('Window onload started...');

            // Initialize component requested by page e.g. Options, Side bar, Popup etc.
            var components = this.list[name].components;
            var init = this.list[name].init;
            for(var i=0,len=components.length;i<len;i++) {
                var obj = components[i];
                if(GMX[obj]){
                    GMX[obj].setup();
                }
            }

            // Call page level init function
            if(init) {
                var handle=setTimeout(init, 100);
            }

            // Register A4J Sessiontimeout handler
            A4JSessionTimeoutHandler();
        }
    },

	// fancy select change handler
	options_handler: {

		setup: function(el) {

			$(el).onchange = function() {

				// if it is still loading, quit

				if(this.hasClassName('loading')) return;

				this.addClassName('loading');

				var container = this;

				var url = (this.value).split('|')[0];

				var carousel_url = (this.value).split('|')[1];

				var obj = $(this.id+'-content');

				var carousel = this.up('div.feature');

				var w = 612;

				// figure out which carousel should start

				if(!carousel) {

					carousel = $('companies-carousel');

					w = 980;

				}

				var spinner = carousel.select('.spinner').first();

				var callback = function() {

					// show loading spinner

					if(!spinner.visible()) spinner.setOpacity(0).show().fade({ duration: 0.3, from: 0, to: 0.8, queue:'end' });

					// get carousel content from option value

					// option value ="first-url | second-url"

					// first-url -> entire carousel content

					// seconde-url -> carousel page content

					new Ajax.Updater(obj,url,

					{

					    method:'get',

					    onComplete: function(){

							GMX.options.setup();

							GMX.tooltip.setup();

                            GMX.static_tooltip.setup();

							container.removeClassName('loading');

							// fade in carousel and start carousel object

							obj.setOpacity(0).show().fade({ duration: 0.3, from: 0, to: 1, queue:'end' });

							var featured_producers_carousel = new GMX.Carousel(carousel.id,{

								url:'data/get_ajax_template.php?template='+carousel_url,

								width:w

							});

					    }

					});

				}

				// fade out carousel

				obj.fade({ duration: 0.3, from: 1, to: 0, queue:'end', afterFinish: callback });

			}

		}

	},



	//show/hide past events links

	past_events:{

		setup: function(){

			$('show-past-events').observe('click', function(){

				new Effect.SlideDown('past-events',{duration: 1.0});

				this.hide();

			});

			$('hide-past-events').observe('click', function(){

				new Effect.SlideUp('past-events',{duration: 1.0});

				$('show-past-events').show();

			});

		}

	},

	show_more:{

		setup: function(){

			$$('a.show-more').each(function(item){

				/*when link is clicked the previous is shown or not and the links text and arrow changes*/

				item.observe('click', function(){

					if(item.hasClassName('arrow-more')){

						new Effect.SlideDown(item.up(0).previous(0).id,{duration: 1.0, afterFinish: function(){

							item.innerHTML = 'SHOW LESS';

							item.removeClassName('arrow-more');

							item.addClassName('arrow-less');

							}

						});



					}

					else if(item.hasClassName('arrow-less')){

						new Effect.SlideUp(item.up(0).previous(0).id, {duration:1.0, afterFinish: function(){

							item.innerHTML = 'SHOW MORE';

							item.removeClassName('arrow-less');

							item.addClassName('arrow-more');

							}

						});

					}

					else if(item.hasClassName('more')){

						new Effect.SlideDown(item.up(0).previous(0).id,{duration: 1.0, afterFinish: function(){

							item.innerHTML = "&lsaquo; SHOW LESS";

							item.removeClassName('more');

							item.addClassName('less');

							}

						});

					}

					else if(item.hasClassName('less')){

						new Effect.SlideUp(item.up(0).previous(0).id, {duration:1.0, afterFinish: function(){

							item.innerHTML = "SHOW MORE &rsaquo;";

							item.removeClassName('less');

							item.addClassName('more');

							}

						});

					}

					//when we don't have any arrows

				});

			});

		}

	},

	innerPopups:{



		addTo: function( ){

            var newList = function(){

                this.fade({

                    duration: 1.0

                });

                this.hide();

                $('add-new-list').show();

                $('new-list').checked = true;

                $('add-list-select').checked = false;

                togleListSelection($('new-list'));

            };



            if('existing' == $('add-to-selection-mode').value){

                $('add-list-select').checked = true;

                $('create-new').setStyle('display:inline');

                $('add-new-list').setStyle('display:none');



                //create new list link

                $('create-new').observe('click', newList);



            }

            else if('existing-new' == $('add-to-selection-mode').value){

                $('create-new').setStyle('display:none');

                $('add-new-list').setStyle('display:block');

                $('add-list-select').checked = false;

                $('new-list').checked = true;



                //create new list link

                $('create-new').observe('click', newList);

            }



            if('new' == $('add-to-selection-mode').value){



            }



            GMX.popups.closeSetup();



            $$('a.button-cancel').each(function(item){

                item.stopObserving('click');

                item.observe('click', function(){

                    if(GMX.popups.idWrapperPopup != null){

                        $(GMX.popups.idWrapperPopup).fade({

                            duration: 0.3,

                            from: 1,

                            to: 0 ,

                            afterFinish: function(){

                                $('allover').style.display = "none";

                                $(GMX.popups.idWrapperPopup).removeClassName('open');

                                GMX.popups.idWrapperPopup = null;

                            }

                        });

                    }

                });

            });

        },



		//contact: function(contactType){
        contact: function(){

			//setting the width manually for the select
            GMX.popups.closeSetup();
            $$('a.button-cancel').each(function(item){

                item.stopObserving('click');

                item.observe('click', function(){

                    if(GMX.popups.idWrapperPopup != null){

                        $(GMX.popups.idWrapperPopup).fade({

                            duration: 0.3,

                            from: 1,

                            to: 0 ,

                            afterFinish: function(){

                                $('allover').style.display = "none";

                                $(GMX.popups.idWrapperPopup).removeClassName('open');

                                GMX.popups.idWrapperPopup = null;

                            }

                        });

                    }

                });

            });


			$$('div.custom-select-wrapper').each(function(it){

				it.style.width = '110px';

			});

			$$('div.select-loaded').each(function(it){

				it.style.width = '110px';

			});

			//initialize default divs
/*
			if(contactType == 'seller'){

				$$('#contact-seller-popup div.step1').first().setStyle('display:block');

				$$('#contact-seller-popup div.step2').first().setStyle('display:none');

			}else if(contactType == 'company'){

				$$('#contact-company-popup div.step1').first().setStyle('display:block');

				$$('#contact-company-popup div.step2').first().setStyle('display:none');

			}else if(contactType == 'person'){

				$$('#contact-company-popup div.step1').first().setStyle('display:block');

				$$('#contact-company-popup div.step2').first().setStyle('display:none');

			}

			//SUBMIT buttons seller

			$('seller-contact-submit').observe('click', function(){

				this.up(1).hide();

				this.up(1).next().show();

				setTimeout(function() { $('contact-seller-popup').fade({ duration: 1 }); $('contact-seller-popup').removeClassName('open'); }, 3000);

			});

			//SUBMIT buttons company

			$('company-contact-submit').observe('click', function(){

				this.up(1).hide();

				this.up(1).next().show();

				setTimeout(function() { $('contact-company-popup').fade({ duration: 1 }); $('contact-company-popup').removeClassName('open'); }, 3000);

			});

			//SUBMIT buttons person

			$('person-contact-submit').observe('click', function(){

				this.up(1).hide();

				this.up(1).next().show();

				setTimeout(function() { $('contact-person-popup').fade({ duration: 1 }); $('contact-person-popup').removeClassName('open'); }, 3000);

			});

*/


		},

    addToDeals: function( ){
            var newDeal = function(){
                this.fade({
                    duration: 1.0
                });
                this.hide();
                if($('user-role-select')){
                    $('user-role-select').show();
                }
                $('add-new-deal').show();
                $('new-deal').checked = true;
                $('add-to-deals-select').checked = false;
                togleDealsSelection($('new-deal'));
            };

            if('existing' == $('add-to-deals-selection-mode').value){
                $('add-to-deals-select').checked = true;
               // $('create-new-deal').setStyle('display:inline');
               // $('add-new-deal').setStyle('display:none');


                //create new list link
               /* $('create-new-deal').observe('click', newDeal);
                if($('add-to-deals-select')){
                    $('add-to-deals-select').observe('click',function(){
                        if($('user-role-select')){
                            $('user-role-select').hide();
                        }
                    });
                }*/
                if($('new-deal')){
                    $('new-deal').observe('click',function(){
                        if($('user-role-select')){
                            $('user-role-select').show();
                        }
                    });
                }

            }
            else if('existing-new' == $('add-to-deals-selection-mode').value){
               // $('create-new-deal').setStyle('display:none');
                $('add-new-deal').setStyle('display:block');
                $('add-to-deals-select').checked = false;
                $('new-deal').checked = true;

               //create new list link
                //$('create-new-deal').observe('click', newDeal);
                if($('new-deal')){
                    $('new-deal').observe('click',function(){
                        if($('user-role-select')){
                            $('user-role-select').show();
                        }
                    });
                }
                if($('add-to-deals-select')){
                    $('add-to-deals-select').observe('click',function(){
                        if($('user-role-select')){
                            $('user-role-select').hide();
                        }
                    });
                }
            }
            GMX.popups.closeSetup();
            $$('a.button-cancel').each(function(item){
                item.stopObserving('click');
                item.observe('click', function(){
                    if(GMX.popups.idWrapperPopup != null){
                        $(GMX.popups.idWrapperPopup).fade({
                            duration: 0.3,
                            from: 1,
                            to: 0 ,
                            afterFinish: function(){
                                $('allover').style.display = "none";
                                $(GMX.popups.idWrapperPopup).removeClassName('open');
                                GMX.popups.idWrapperPopup = null;
                            }
                        });
                    }
                });
            });
        },

		getConnected: function(){

			//initialize the default display and hidden divs

			$$('#get-connected-popup div.step1').first().setStyle('display:block');

			$$('#get-connected-popup div.step1 #send-request').first().setStyle('display:none');

			$$('#get-connected-popup div.step2').first().setStyle('display:none');

			$$('#get-connected-popup div.step3').first().setStyle('display:none');

			$$('#get-connected-popup div.step4').first().setStyle('display:none');

			//none of the radio buttons  should be checked at first

			$$('.connection-options').each( function(item){

				item.checked = false;

			});

			//MUTUAL CONNECTION

			$('mutual-connection').observe('click', function(){

				$('send-request').hide();

				this.up(2).hide();

				this.up(2).next().show();

				//initialize the mutual connections select width

				$$('div.custom-select-wrapper').each(function(it){

					it.style.width = '200px';

				});

				$$('div.select-loaded').each(function(it){

					it.style.width = '200px';

				});

			});

			//SEND REQUEST

			$('request-connection').observe('click', function(){

				$('send-request').show();

			});

			//SEND button

			$('send-button').observe('click', function(){

				//form validation for "Connection selection"

				var isValid = true;

				if($('get-connected-select').selectedIndex == 0){

					isValid = false;

				}

				if(isValid){

					this.up(1).hide();

					this.up(1).next(1).show();

					setTimeout(function() { $('get-connected-popup').fade({ duration: 1 });$('get-connected-popup').removeClassName('open'); }, 3000);



				}else{

					this.up(1).hide();

					this.up(1).next(0).show();

					setTimeout(function() { $('get-connected-popup').fade({ duration: 1 });$('get-connected-popup').removeClassName('open'); }, 3000);

				}

			});

			//CONNECT button

			$('connect-submit').observe('click', function(){

				var isValid = false;

				$$('input.connection-options').each( function(it){

					if(it.checked){

						isValid = true;

					}

				});

				if(isValid){

					this.up(1).hide();

					this.up(1).next(2).show();

					setTimeout(function() { $('get-connected-popup').fade({ duration: 1 });$('get-connected-popup').removeClassName('open'); }, 3000);

				}

			});



		},

		giveScore: function(){

			$$('#score-popup div.step1').first().setStyle('display:block');

			$$('#score-popup div.step2').first().setStyle('display:none');

			//SUBMIT BUTTON

			$('score-commit').observe('click', function(){

				this.up(1).hide();

				this.up(1).next(0).show();

				setTimeout(function() { $('score-popup').fade({ duration: 1 }); $('score-popup').removeClassName('open'); }, 3000);

			});



		},

		shareWith: function(){

			$$('div#share-popup div.step1').first().setStyle('display:block');

			$$('div#share-popup div.step2').first().setStyle('display:none');

			$$('div#share-popup div.step3').first().setStyle('display:none');

			$$('div#share-popup div.step4').first().setStyle('display:none');

			//add existing connections - Step1

			$('share-to').value = "E-mail or existing connection";

			$('share-to').observe('focus', function(){

				this.value = "";

			});

			$$('div#share-popup div.step1 .add-existing').each(function(item){

				item.observe('click', function(){

					this.up(0).hide();

					this.up(0).next(0).show();

					this.up(0).next(0).down(0).next(0).show();

					this.up(0).next(0).down(0).next(1).hide();



					//cancel search for contacts

					$$('div#share-popup a.cancel-search').each(function(item){

						item.observe('click', function(){

							this.up(1).previous(0).show();

							this.up(1).hide();

						});

					});

					//search button

					$$('div#share-popup .search-button').each(function(item){

						item.observe('click', function(){

							this.up(1).next(1).show();

							this.up(1).next(0).hide();

						});

					});

					//DONE

					$('done-submit').observe('click', function(){

						this.up(3).next(0).show();

						this.up(3).hide();

						$$('div a.recipient-name-close').each(function(item){

							item.observe('click', function(){

								this.up(1).hide();

							});

						});

						//SHARE BUTTON

						$$('div#share-popup div.step3 .share-submit').each(function(item){

							item.observe('click', function(){

								item.up(1).hide();

								$('share-step4').show();

								setTimeout(function() { $('share-popup').fade({ duration: 1 });$('share-popup').removeClassName('open'); }, 3000);

							});

						});

					});

					$$('div.step2 a.cancel-select').each(function(item){

						item.observe('click', function(){

							this.up(4).down(0).next(0).show();

							this.up(3).hide();

						});

					});

				});

			});



			//add existing connections - Step3

			$$('div#share-popup div.step3 .add-existing').each(function(item){

				item.observe('click', function(){

					this.up(0).hide();

					$('share-step2').show();

					//search button

					$('search-button').stopObserving('click');

					$('search-button').observe('click', function(){

						return false;

					});

					//DONE

					$('done-submit').stopObserving('click');

					$('done-submit').observe('click', function(){

						this.up(2).hide();

						$('share-step3').show();



					});

				});

			});





			//SHARE BUTTON

			$$('div#share-popup div.step1 .share-submit').each(function(item){

				item.observe('click', function(){

					item.up(1).hide();

					$('share-step4').show();

					setTimeout(function() { $('share-popup').removeClassName('open');$('share-popup').fade({ duration: 1 }); }, 3000);

				});

			});





			$$('div.step3 a.button-cancel').each( function(it){

			   it.observe('click', function(){

					$('share-popup').removeClassName('open');

					$('share-popup').fade({ duration: 0.3 });

				});

			});

		},



		setAlert: function(){

			$$("#set-alert-popup div.step1").first().setStyle('display:block');

			$$("#set-alert-popup div.step2").first().setStyle('display:none');

			//SUBMIT ALERT

			$('submit-alert').observe('click', function(){

				this.up(1).hide();

				this.up(1).next().show();

				setTimeout(function() { $('set-alert-popup').fade({ duration: 1 });$('set-alert-popup').removeClassName('open'); }, 3000);

			});



		},



		getPermission: function(){

			//initialize visible divs

			$$('#get-permissions-popup div.step1').first().setStyle('display:block');

			$$('#get-permissions-popup div.step2').first().setStyle('display:none');

			//when click to add text , the default one should disappear

			$('message-box').value = "Optional message...";

			$('message-box').observe('focus', function(){

				this.value = "";

			});

			//submit button

			$('submit-request').observe('click', function(){

				this.up(1).hide();

				this.up(1).next(0).show();

				setTimeout(function() { $('get-permissions-popup').fade({ duration: 1 });$('get-permissions-popup').removeClassName('open'); }, 3000);

			});



		},

scoreFunction: function(){
            $$('a.score').each(
                function(el){
                    el.observe('click',
                        function(){
                            var itemType;
                            var itemId;
                            var itemName;
                            var popupPanel='option-add-to-deals-popup';
                            if($(popupPanel)){
                            var toolbarDiv=GMX.options.current_option;
                            toolbarDiv = toolbarDiv.childNodes;
                            if(toolbarDiv && toolbarDiv.length > 0){
                                for( var i=0; i < toolbarDiv.length; i++){
                                    var child = toolbarDiv[i];
                                    if(child && child.type == 'hidden' && child.id.indexOf("itemType", 0) >= 0 ){
                                        itemType = "" +child.value;
                                    }else if(child && child.type == 'hidden' && child.id.indexOf("itemId", 0) >= 0 ){
                                        itemId = "" + child.value;
                                    }else if(child && child.type == 'hidden' && child.id.indexOf("itemName", 0) >= 0 ){
                                        itemName = "" + child.value;
                                    }
                                }
                            }
                            $('itemid-for-addto-deals-option').value=itemId;
                            $('itemtype-for-addto-deals-option').value=itemType;
                            $('itemname-for-addto-deals-option').value=itemName;
                            if($('user-role-select')){
                                $('user-role-select').show();
                            }
                            GMX.popups.launchPopUp(popupPanel);
                            updateDealsPopup();
                            }
                        });
                }
			);

        },

		setup: function(){



			//GMX.select.setup();





			if($('add')){

				/*$('add').down(0).observe('click',function(){

					GMX.popups.launchPopUp('add-to');

					GMX.innerPopups.addTo();



				});*/

			}

			if($('share')){

				/*$('share').down(0).observe('click',function(){

					GMX.popups.launchPopUp('share-popup');

					GMX.innerPopups.shareWith();

				});*/

			}

			if($('alert')){

				/*$('alert').down(0).observe('click',function(){

					GMX.popups.launchPopUp('set-alert-popup');

					GMX.innerPopups.setAlert();

				});*/

			}

			if($('contact')){

				/*$('contact').down(0).observe('click',function(){

						// open popup

					GMX.popups.launchPopUp('contact-seller-popup');

					GMX.innerPopups.contact('seller');

				});*/

			}

			if($('connect')){

				/*$('connect').down(0).observe('click',function(){

						// open popup

					GMX.popups.launchPopUp('get-connected-popup');

					GMX.innerPopups.getConnected();

				});*/

			}

			if($('score')){

				/*$('score').down(0).observe('click',function(){

						// open popup

					GMX.popups.launchPopUp('score-popup');

					GMX.innerPopups.giveScore();

				});*/

			}

			if($('permissions')){

				/*$('permissions').down(0).observe('click',function(){

					GMX.popups.launchPopUp('get-permissions-popup');

					GMX.innerPopups.getPermission();

				});*/

			}







			/* BUTTONS: DROPDOWN BAR

			----------------------------------------------------- */

            $$('a.add').each(

            function(el){

                el.observe('click',

                function(){

                    // Findout which OPTION is clicked and get the itemId,type and name associated with it.

                    var itemType;

                    var itemId;

                    var itemName;

                    var popupPanel='option-add-to-popup';

                    var toolbarDiv=GMX.options.current_option;

                    toolbarDiv = toolbarDiv.childNodes;

                    if(toolbarDiv && toolbarDiv.length > 0){

                        for( var i=0; i < toolbarDiv.length; i++){

                            var child = toolbarDiv[i];

                            if(child && child.type == 'hidden' && child.id.indexOf("itemType", 0) >= 0 ){

                                itemType = "" +child.value;

                            }else if(child && child.type == 'hidden' && child.id.indexOf("itemId", 0) >= 0 ){

                                itemId = "" + child.value;

                            }else if(child && child.type == 'hidden' && child.id.indexOf("itemName", 0) >= 0 ){

                                itemName = "" + child.value;

                            }

                        }

                    }



                    $('itemid-for-addto-option').value=itemId;

                    $('itemtype-for-addto-option').value=itemType;

                    $('itemname-for-addto-option').value=itemName;

                    // Launch popup

                    GMX.popups.launchPopUp('option-add-to-popup');

                    updateAddToPopup();

                }

            );

            });

			$$('a.share').each(

				function(el){

					el.observe('click',

						function(){

							GMX.popups.launchPopUp('share-popup');

							GMX.innerPopups.shareWith();

						});

				}

			);



			$$('a.alert').each(

				function(el){

					el.observe('click',

						function(){

							GMX.popups.launchPopUp('set-alert-popup');

							GMX.innerPopups.setAlert();

						});

				}

			);



			$$('a.contact').each(

				function(el){

                            el.observe('click',

                                function(){
                            // Findout which OPTION is clicked and get the itemId,type and name associated with it.

                            var itemType;

                            var itemId;

                            var itemName;

                            var popupPanel='option-contact-popup';

                            var toolbarDiv=GMX.options.current_option;

                            toolbarDiv = toolbarDiv.childNodes;

                            if(toolbarDiv && toolbarDiv.length > 0){

                                for( var i=0; i < toolbarDiv.length; i++){

                                    var child = toolbarDiv[i];

                                    if(child && child.type == 'hidden' && child.id.indexOf("itemType", 0) >= 0 ){

                                        itemType = "" +child.value;

                                    }else if(child && child.type == 'hidden' && child.id.indexOf("itemId", 0) >= 0 ){

                                        itemId = "" + child.value;

                                    }else if(child && child.type == 'hidden' && child.id.indexOf("itemName", 0) >= 0 ){

                                        itemName = "" + child.value;

                                    }

                                }

                            }



                            $('itemid-for-contact-option').value=itemId;

                            $('itemtype-for-contact-option').value=itemType;

                            $('itemname-for-contact-option').value=itemName;

                            // Launch popup

                            GMX.popups.launchPopUp('option-contact-popup');

                            updateContactPopup();

						});

				}

			);

			$$('a.score').each(
                function(el){
                    el.observe('click',
                        function(){
                            var itemType;
                            var itemId;
                            var itemName;
                            var popupPanel='option-add-to-deals-popup';
                            if($(popupPanel)){
                            var toolbarDiv=GMX.options.current_option;
                            toolbarDiv = toolbarDiv.childNodes;
                            if(toolbarDiv && toolbarDiv.length > 0){
                                for( var i=0; i < toolbarDiv.length; i++){
                                    var child = toolbarDiv[i];
                                    if(child && child.type == 'hidden' && child.id.indexOf("itemType", 0) >= 0 ){
                                        itemType = "" +child.value;
                                    }else if(child && child.type == 'hidden' && child.id.indexOf("itemId", 0) >= 0 ){
                                        itemId = "" + child.value;
                                    }else if(child && child.type == 'hidden' && child.id.indexOf("itemName", 0) >= 0 ){
                                        itemName = "" + child.value;
                                    }
                                }
                            }
                            $('itemid-for-addto-deals-option').value=itemId;
                            $('itemtype-for-addto-deals-option').value=itemType;
                            $('itemname-for-addto-deals-option').value=itemName;
                            if($('user-role-select')){
                                $('user-role-select').show();
                            }
                            GMX.popups.launchPopUp(popupPanel);
                            updateDealsPopup();
                            }
                        });
                }
			);

			$$('a.permissions').each(

				function(el){

					el.observe('click',

						function(){

							GMX.popups.launchPopUp('get-permissions-popup');

							//GMX.popups.launchPopUp('get-permissions-popup');

							GMX.innerPopups.getPermission();

						});

				}

			);



			// CHECK TO SEE IF THE COMPARE VERSIONS BUTTON IS CLICKED

			$$('a.compare-versions-btn', 'a.close-popup-btn').each(function(el){

				el.observe('click',function(){

					// close popup

					GMX.popups.launchComparePopUp('compare-popup');

				});

			});





		}



	},

	popups: {

		idWrapperPopup:null,

		/* POPUP DROP SHADOW SCRIPT

		------------------------------------------------------------- */

		// adds a drop shadow to a given element/popup

		addDropShadow: function(element){

			element = $(element);

			// create diff sections of drop shadow

			var i1 = new Element('div', { 'class': 'i1' });

			var i2 = new Element('div', { 'class': 'i2' });

			var i3 = new Element('div', { 'class': 'i3 cf' });



			i2.appendChild(i3);

			i1.appendChild(i2);



			$A(element.childNodes).each(function(e){ i3.appendChild(e); });

			// create the divs that will contain the shadow images

			var bfunc = function(className){

				var e = new Element('div', { 'class': className });

				e.appendChild(new Element('div'));

				return e;

			};



			element.addClassName('cp');

			element.appendChild(bfunc('bt'));

			element.appendChild(i1);

			element.appendChild(bfunc('bb'));

		},

		/* POPUP SCRIPT FOR COMPARE VERSIONS

		------------------------------------------------------------- */

		launchComparePopUp: function(element) {

			element = $(element);

			for (var n = 1; n < 4; n++){

				var hiddentables = $$('.hidden-table'+n);

				hiddentables.each(

					function(el){

						el.style.display = 'none';

				});

			}

			checkboxes = $$('#filter-bar input');

			checkboxes.each(function(elem){

				elem.observe('click', function(){

				checked = 0;

				for(var i = 0; i < checkboxes.length; i++){

					if (checkboxes[i].checked == true){

						checked++;

					}

				}

				if(checked == 0) {

					//uncheck all but first box

					for (var n=0; n < checkboxes.length; n++){

						if(n != 0){

							checkboxes[n].checked = false;

						}else{

							checkboxes[n].checked = true;

						}

					}

					element.style.width = "515px";

					element.toggleClassName('open');

					element.fade({ duration: 0.3, from: 1, to: 0 });

				}



				if (checked == 4){

					checkboxes.each(

						function(el){

							if (el.checked == false){

								el.disabled = true;

							}

						});

				}



				//check to make sure no more than 4 boxes are checked

				if(checked <= 4){

					if(elem.checked){ //do this if they checked the box

						for (var n = 1; n < (checked); n++){

							var hiddentables = $$('.hidden-table'+n);

							if (hiddentables[0].getStyle("display") == "none"){

								hiddentables.each(

									function(el){

										el.style.display = '';

								});

							}

						}

					}else{ // do this if they unchecked the box

						var hiddentables = $$('.hidden-table'+checked);

						hiddentables.each(

							function(el){

								el.style.display = 'none';

							});

						checkboxes.each(

							function(el){

								el.disabled = false;

						});

					}

					switch(checked)

					{

						case 1:

							element.style.width = "515px";

							centerComparePopUp();

							break;

						case 2:

							element.style.width = "680px";

							centerComparePopUp();

							break;

						case 3:

							element.style.width = "845px";

							centerComparePopUp();

							break;

						case 4:

							element.style.width = "1020px";

							centerComparePopUp();

							break;



					}



				}else{

					elem.checked = false;

					alert("You may only select up to 4 options");

				}

				});

			});



			if(element.hasClassName('open')){

				//uncheck all but first box

				for (var n=0; n < checkboxes.length; n++){

					checkboxes[n].disabled = false;

					if(n != 0){

						checkboxes[n].checked = false;

					}

				}

				element.style.width = "515px";

				element.toggleClassName('open');

				element.fade({ duration: 0.3, from: 1, to: 0 });

			} else {

				element.appear({ duration: 0.3, from: 0, to: 1 });

				element.toggleClassName('open');



				centerComparePopUp = function(){

					var thePopup = $(element);

					var scr = document.viewport.getScrollOffsets();

					var dim = document.viewport.getDimensions();



			 		thePopup.style.top = (dim.height / 2 - thePopup.getHeight() / 2) + scr.top + 'px';

			 		thePopup.style.left = (dim.width / 2 - thePopup.getWidth() / 2) + scr.left + 'px';

			 		if(!thePopup.hasClassName('shadow')){

			 			GMX.popups.addDropShadow(thePopup);

			 			thePopup.addClassName('shadow');

			 		}

				}



				centerComparePopUp();

				// keep popup in center while scrolling

				Event.observe(window, 'resize', centerComparePopUp);

				Event.observe(window, 'scroll', centerComparePopUp);



			}

		},

        /*
         *Special launchPopUp
         **/

		/* POPUP SCRIPT

		------------------------------------------------------------- */

        launchPopUpSpecial: function(element) {
            this.idWrapperPopup = element;

            //------------------------------------------------------------//
            /* if any other popup is open , let's close it */
            $$('div.open').each(function(item){
                if(element != item.readAttribute('id') && item.hasClassName('open')){
                    item.removeClassName('open');
                    item.hide();
                    this.idWrapperPopup = null;
                }
            });
            //------------------------------------------------------------//

            element = $(element);
            if(element.hasClassName('open')){
                // if its open then close it
                element.removeClassName('open');
                element.fade({
                    duration: 0.3,
                    from: 1,
                    to: 0
                });
                this.idWrapperPopup = null;
            } else {
                //open popup
                this.idWrapperPopup = element.readAttribute('id');
                element.appear({
                    duration: 0.3,
                    from: 0,
                    to: 1
                });
                $('allover').style.display = "block";
                var allOverHeight = 0;
                try{
                    allOverHeight = document.body.scrollHeight;
                    allOverWidth = document.body.scrollWidth;
                }catch(exp){
                    try{
                        allOverHeight = ($('header')).scrollHeight +  ($('container')).scrollHeight + ($('footer')).scrollHeight;
                    }catch(exp){
                        allOverHeight = 1000;
                        allOverWidth = 2000;
                    }
                }
                $('allover').style.height = allOverHeight + 'px';
                $('allover').style.width = allOverWidth + 'px';
                element.addClassName('open');

                // function to center the popup on screen

                centerPopUp = function(){
                    var thePopup = $(element);
                    var scr = document.viewport.getScrollOffsets();
                    var dim = document.viewport.getDimensions();
                    // set it in middle

                    if(thePopup.getHeight() >= dim.height){
                        thePopup.style.top = scr.top + 10 + 'px';
                        thePopup.style.left = (dim.width / 2 - thePopup.getWidth() / 2) + scr.left + 'px';
                    } else {
                        thePopup.style.top = (dim.height / 2 - thePopup.getHeight() / 2) + scr.top + 'px';
                        thePopup.style.left = (dim.width / 2 - thePopup.getWidth() / 2) + scr.left + 'px';
                    }

                    // Add the dropshadow to the element
                    if(!thePopup.hasClassName('shadow')){
                        GMX.popups.addDropShadow(thePopup);
                        thePopup.addClassName('shadow');
                    }
                }
                // center
                centerPopUp();
                // keep popup in center while scrolling
                //Event.observe(window, 'resize', centerPopUp);
            //Event.observe(window, 'scroll', centerPopUp);
            }
            this.closeSetup();
        },



        /*End Special launchPopUp*/



		/* POPUP SCRIPT

		------------------------------------------------------------- */

        launchPopUp: function(element) {
            this.idWrapperPopup = element;
            var popupDivId=element;

            //------------------------------------------------------------//
            /* if any other popup is open , let's close it */
            $$('div.open').each(function(item){
                if(element != item.readAttribute('id') && item.hasClassName('open')){
                    item.removeClassName('open');
                    item.hide();
                    this.idWrapperPopup = null;
                }
            });
            //------------------------------------------------------------//

            element = $(element);
            if(element.hasClassName('open')){
                // if its open then close it
                element.removeClassName('open');
                element.fade({
                    duration: 0.3,
                    from: 1,
                    to: 0
                });
                this.idWrapperPopup = null;
            } else {
               //open popup
                this.idWrapperPopup = element.readAttribute('id');
                element.appear({
                    duration: 0.3,
                    from: 0,
                    to: 1
                });

                try {
                    $('allover-spinner').style.display = "none";
                } catch (exp) {}

                $('allover').style.display = "block";
                var allOverHeight = 0;
                try{
                    allOverHeight = document.body.scrollHeight;
                    allOverWidth = document.body.scrollWidth;
                }catch(exp){
                    try{
                        allOverHeight = ($('header')).scrollHeight +  ($('container')).scrollHeight + ($('footer')).scrollHeight;
                    }catch(exp){
                        allOverHeight = 1000;
                        allOverWidth = 2000;
                    }
                }
                $('allover').style.height = allOverHeight + 'px';
                $('allover').style.width = allOverWidth + 'px';
                element.addClassName('open');
                // function to center the popup on screen
                centerPopUp = function(){
                    var thePopup = $(element);
                    var scr = document.viewport.getScrollOffsets();
                    var dim = document.viewport.getDimensions();
                    // set it in middle
                    if($(element).id=='picker-popup'){
                        scroll(0,0);
                        thePopup.style.top = '80px';
                        thePopup.style.left = '280px';
                        Effect.ScrollTo('picker-popup', {offset: '80px'});
                    }else{
                        if(thePopup.getHeight() >= dim.height){
                            thePopup.style.top = scr.top + 10 + 'px';
                            thePopup.style.left = (dim.width / 2 - thePopup.getWidth() / 2) + scr.left + 'px';
                        } else {
                            thePopup.style.top = (dim.height / 2 - thePopup.getHeight() / 2) + scr.top + 'px';
                            //alert('thePopup.style.top=' + thePopup.style.top);
                            thePopup.style.left = (dim.width / 2 - thePopup.getWidth() / 2) + scr.left + 'px';
                            //alert('thePopup.style.left='+thePopup.style.left);
                        }
                    }

                    // Add the dropshadow to the element
                    if(!thePopup.hasClassName('shadow')){
                        GMX.popups.addDropShadow(thePopup);
                        thePopup.addClassName('shadow');
                    }
                }

                // center
                centerPopUp();
                // keep popup in center while scrolling
                Event.observe(window, 'resize', centerPopUp);
                //Event.observe(window, 'scroll', centerPopUp);
            }

            this.closeSetup();

            // GMX-993

            if(popupDivId != 'option-contact-popup' && popupDivId !='option-add-to-deals-popup' && popupDivId !='option-add-to-popup' && popupDivId !='location-popup') {
                setupTabIndexForPopup(popupDivId);
            }

           // GMX:-3122
	      GMX.utility.ie.btnfix();

            //SUBMIT POPUP
            //$$('div.buttons .submit-btn').each(function(item){
            //    item.observe('click', function(){
            //        this.stopObserving('click');
            //        this.up(1).hide();
            //        $$('#'+GMX.popups.idWrapperPopup+' div.confirm').first().show();
            //        centerPopUp();
            //        setTimeout(function() {
            //            $(GMX.popups.idWrapperPopup).fade({
            //                duration: 1 ,
            //                afterFinish: function(){
            //                    $(GMX.popups.idWrapperPopup).removeClassName('open');
            //                    GMX.popups.idWrapperPopup = null;
            //                }
            //            });
            //        }, 3000);
            //    });
            //});
        },

        closeSetup: function(){

            try{

                // CHECK TO SEE IF POP CLOSE BUTTON IS CLICKED

                $$('a.close-popup-btn2').each(function(el){

                    Event.stopObserving(el, 'click');
                    el.observe('click',function(){

                        if(GMX.popups.idWrapperPopup != null){

                            $(GMX.popups.idWrapperPopup).fade({

                                duration: 0.3,

                                from: 1,

                                to: 0,

                                afterFinish: function(){

                                    try{

                                        $('allover').style.display = "none";

                                        $(GMX.popups.idWrapperPopup).removeClassName('open');

                                        GMX.popups.idWrapperPopup = null;

                                    }catch(exp){}

                                }

                            });



                        }

                        else{

                            this.up(4).fade({

                                duration: 0.3,

                                from: 1,

                                to: 0

                            });

                            $('allover').style.display = "none";

                            this.up(4).removeClassName('open');

                        }

                    });

                });

                //CANCEL POPUP - step 1 only!!!

                $$('a.button-cancel').each(function(item){

                    Event.stopObserving(item, 'click');

                    item.observe('click', function(){

                        if(GMX.popups.idWrapperPopup != null){

                            $(GMX.popups.idWrapperPopup).fade({

                                duration: 0.3,

                                from: 1,

                                to: 0 ,

                                afterFinish: function(){

                                    if($('allover')) $('allover').style.display = "none";

                                    if($(GMX.popups.idWrapperPopup)) $(GMX.popups.idWrapperPopup).removeClassName('open');

                                    GMX.popups.idWrapperPopup = null;

                                }

                            });



                        }

                    });

                });

            }catch(exp){}

        },

        setup: function(){



        }

 },

 characters_count:{
  //element - the id of the textarea for which we will count the characters
  //limit - the number of characters maximum allowed
  //countCh - the id of the element which will show how many characters we still have to use
  countCh:function(element,limit,countCh){
    var element = $(element);
    if(!element) return;
    var elemSize = limit - element.value.length;
    var countCh = $(countCh);
    if(countCh) countCh.innerHTML = elemSize;
    $(element).observe('keyup',function(){
        if(limit - this.value.length >0){
            if(countCh) countCh.innerHTML = limit - this.value.length;
        }else{
        if(countCh) countCh.innerHTML = 0;
            this.value = this.value.substr(0,limit);
        }
    });
    element.observe('keydown',function(){
        if(limit - this.value.length >0){
            if(countCh) countCh.innerHTML = limit - this.value.length;
        }else{
            if(countCh) countCh.innerHTML = 0;
            this.value = this.value.substr(0,limit);
        }
    });
  },

  setup: function(){
  }
 },


selectManyCheckbox:{
   setup: function(){
       $$('table.select-many-chkbox tr input').each(function(inputChk){
            inputChk.stopObserving('click');
            inputChk.observe('click',function(){
                this.parentNode.addClassName('fakeClass');
            });
        });
        $$('table.select-many-chkbox tr label').each(function(inputLabel){
            inputLabel.stopObserving('mousedown');
            inputLabel.observe('mousedown',function(){
                this.parentNode.addClassName('fakeClass');
            });
        });
        $$('table.select-many-chkbox td').each(function(parentTd){
            parentTd.style.width= '100%';
            parentTd.stopObserving('mouseover');
            parentTd.observe('mouseover',function(){
                this.style.backgroundColor='#CCC';
            });
            parentTd.stopObserving('mouseout');
            parentTd.observe('mouseout',function(){
                this.style.backgroundColor='#FFF';
            });
            parentTd.stopObserving('click');
            parentTd.observe('click',function(){
                var chk = this.down(0);
                if(this.hasClassName('fakeClass')){
                    this.removeClassName('fakeClass');
                }else{
                    if(chk && !chk.disabled && chk.checked){
                        chk.checked=false;
                    }else if(chk && !chk.disabled && !chk.checked){
                        chk.checked=true;
                    }
                }
            });
        });
    }
  }
};


function getScrollOffsetX(){

	var x=0;

	if (self.pageXOffset) {// all except Explorer

		x = self.pageXOffset;

	}else if (document.documentElement && document.documentElement.scrollLeft)	{

		x = document.documentElement.scrollLeft;

	}else if (document.body){ // all other Explorers

		x = document.body.clientWidth;

	}

    return x;



}



function getScrollOffsetY(){

	var y=0;

	if (self.pageYOffset){ // all except Explorer

		y = self.pageYOffset;

	}else if (document.documentElement && document.documentElement.scrollTop){

		y = document.documentElement.scrollTop;

	}else if (document.body){ // all other Explorers

		y = document.body.clientHeight;

	}

    return y;

}



    function posX() {

        return (document.body) ? document.body.scrollLeft : window.pageXOffset;

    }

    function posY() {

        return (document.body) ? document.body.scrollTop : window.pageYOffset;

    }

// NOTE: DO NOT PUT ANYTHING WHICH IS VERY CPU INTENSIVE, AS THAT WILL AFFECT ENTIRE PAGE LOAD PROCESS AND WILL MAKE BROWSER SLOWER TOO !!!
// Following block loads when the broswer's DOM is ready, but still browser is pending with loading other stuff.
// This event occurs even before the window load event. Only put something here which needs to load for all the pages.
var alreadyrunflag=0;
if (document.addEventListener){
    document.addEventListener("DOMContentLoaded", function(){
        alreadyrunflag=1; DOMReadyInitialization()
        }, false)
}else if (document.all && !window.opera){
    document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>')
    var contentloadtag=document.getElementById("contentloadtag")
    contentloadtag.onreadystatechange=function(){
        if (this.readyState=="complete"){
            alreadyrunflag=1
            DOMReadyInitialization();
        }
    }
}


// FOLLOWING SCRIPT PERFOMS CERTAIN TASKS IN PARALLEL, DO NOT MODIFY SEQUENCE WITHOUT PROPER PERFOMANCE TESTING.
// ALL TASKS WILL BE PERFOMED AS SOON AS BROWSER IS DOM READY, AND STILL WINDOWN LOAD EVENT IS GOING TO OCCUR.
var DOMReadyInitialization=function(){
    //alert('DOM Ready started...');

    // Skin Dropdowns
    if(typeof replaceSelectBoxesLocal !== 'undefined' && replaceSelectBoxesLocal){
        replaceSelectBoxesLocal();
    }
    GMX.select.setup();
    // Skin Search dropdown.

    // GMX Menu
    GMX.gmx_menu.setup();

    // Navigation bar
    GMX.navigation.setup();

   //Rest of common initialization
    var handle = setTimeout(fixBrowserButtons,200);

    var searchButton=$('search-go-button');
    if( searchButton)  {
        searchButton.style.visibility='visible';
    }
};

var fixBrowserButtons=function(){
    if(Prototype.Browser.IE){
        // IE Buttons fix
        GMX.utility.ie.btnfix();
        //IE PNG Fix
        GMX.utility.ie.pngfix();
        try {
            document.execCommand("BackgroundImageCache", false, true);
        } catch(err){}
    }

    // GMX-1648 Fix
    browserButtonFix();

    //GMX-2516 Fix
    disableAllHeaderFooterRegionLinks();
}

var orgA4jProcessResponse;
function A4JSessionTimeoutHandler(){
	if(typeof A4J !== 'undefined'){
    if(!(typeof orgA4jProcessResponse !== 'undefined' && orgA4jProcessResponse)){
        orgA4jProcessResponse=A4J.AJAX.processResponse;
    }
    A4J.AJAX.processResponse=function dummyProcessResponse(req){
        //alert('A4JSessionTimeoutHandler Started...');
        var ajaxResponse = req._request.responseText;
        //alert('Res Text:' + ajaxResponse);
        if(ajaxResponse.indexOf('homePage()', 0) > 0 ){
            //alert('Your session has expired...');
            location.href=requestContext;
            return;
        }
        orgA4jProcessResponse(req);
    //alert('A4JSessionTimeoutHandler Ended...');
    }
	}
}

// ------ Code migrated from global-am.js ---------------------------- //
//This function is not referred anywhere
function createObject(objId) {
    if (document.getElementById) return document.getElementById(objId);
    else if (document.layers) return eval("document." + objId);
    else if (document.all) return eval("document.all." + objId);
    else return eval("document." + objId);
}

function limitTextarea(limitField, showCount, limitNum, eve) {
    limitField = $(limitField);
    if(limitField != null ){
        var unicode=eve.charCode? eve.charCode : eve.keyCode ;
        showCount = document.getElementById(showCount);
        var countChar = limitNum - limitField.value.length;

        if(eve.ctrlKey && (eve.charCode == 97 || eve.charCode == 99 ||  eve.charCode == 120 || eve.charCode == 65 || eve.charCode == 67 ||eve.charCode == 88  )){
            //console.debug('eve.charCode : '+ eve.charCode );
            return true;
        }else if(eve.ctrlKey && (eve.charCode == 86 || eve.charCode == 118)){

            if(countChar == 0){
                //console.debug('Paste not allowed');
                return false;
            }else{
                if (limitField.value.length > limitNum) {
                    limitField.value = limitField.value.substring(0, limitNum);
                    return;
                }
            }
        }

        if(countChar >= limitNum) {
            showCount.innerHTML =  countChar+" characters maximum";
        } else {
            showCount.innerHTML =  countChar+" characters remaining";
        }

        if (limitField.value.length > limitNum) {
            limitField.value = limitField.value.substring(0, limitNum);
        }
        else if (limitField.value.length == limitNum) {
            if (unicode!=8 && unicode!=46 && (unicode <37 || unicode>40)){
                return false;
            }
        }
    }
}

function showLoadingIndicator(spinnerDivElement, replacementDivElement) {
    spinnerDivElement.style.display = "block";
    replacementDivElement.style.display = "none";
}

function hideLoadingIndicator(spinnerDivElement, replacementDivElement) {
    spinnerDivElement.style.display = "none";
    replacementDivElement.style.display = "block";
}

function clearTextArea(area, counter, maxCount){
    var areaObj = $(area);
    var counterObj = $(counter);
    if(areaObj){
        areaObj.value = '';
    }
    if(counterObj){
        counterObj.innerHTML = maxCount;
    }
}


function tipsetup(orgContainer, dummyContainer){

    var appearFunc = function(){
        //dummyContainer.style.opacity = '0.1';
        try{
            var tmp = dummyContainer.firstChild.nextSibling.nextSibling.nextSibling.firstChild.nextSibling.nextSibling.nextSibling;
            if(tmp){
                tmp.style.opacity='0.1';
            }
        }catch(err){ }
        orgContainer.innerHTML = dummyContainer.innerHTML;


        $('tips-data-div').appear({
            duration: 0.5,
            from: 0.1,
            to: 1
        });
    }
    $('tips-data-div').fade({
        duration: 0.5,
        from: 1,
        to: 0.1,
        afterFinish: appearFunc
    });
}
//This function is not refered anywhere
function sleepMillis(millis)
{
    var date = new Date();function clearTextArea(area, counter, maxCount){
        var areaObj = $(area);
        var counterObj = $(counter);
        if(areaObj){
            areaObj.value = '';
        }
        if(counterObj){
            counterObj.innerHTML = maxCount;
        }
    }
    var curDate = null;

    do {
        curDate = new Date();
    }
    while(curDate-date < millis);
}

var nextLinkOnClick = function(){

    var reqUrl = requestContext + '/content/components/support_center/try_this.jsf';

    var dummyContainer = document.createElement('div');
    new Ajax.Updater(dummyContainer, reqUrl,
    {
        method: "get",
        onComplete: function(req){
            if(req.responseText != null &&  req.responseText != ''){
                var responseText =  req.responseText;
                if(responseText.indexOf('homePage()', 0) > 0 ){
                    //alert('Your session expired...');
                    location.href=requestContext;
                    return;
                }else{
                    tipsetup($('tips-portlet-div'),dummyContainer);
                }
            }
        },
        onFailure: function(){
            alert('Something gone wrong...');
        }
    });

    return false;
}

var setTitleVal = function(id,val){
    if(!val){
        val = $(id).value;
    }
    if($(id)){
        ($(id)).setAttribute('title',val);
    }
}

function showWaitCursor(){
    document.body.style.cursor='wait';
}

function showDefaultCursor(){
    document.body.style.cursor='default';
}

function filterNonNumbericKeys(e) {
    var evt;
    if(window.event) {
        evt = window.event;
        if( (evt.keyCode > 47) && (evt.keyCode < 58)) {
            return document.defaultAction;
        }
    } else {
        evt = e;
        if( (evt.charCode > 47) && (evt.charCode < 58) ||  evt.keyCode == 8 || evt.keyCode == 13 || evt.keyCode == 9 || evt.keyCode == 46 || evt.keyCode == 37 || evt.keyCode == 39) {
            return document.defaultAction;
        }
    }
    return false;
}

// Values with "." allowed
function filterNonDecimalKeys(e) {
    var evt;
    if(window.event) {
        evt = window.event;
        if( (evt.keyCode > 47) && (evt.keyCode < 58) ||  evt.keyCode == 46) {
            return document.defaultAction;
        }
    } else {
        evt = e;
        if( (evt.charCode > 47) && (evt.charCode < 58) ||  evt.keyCode == 8 || evt.keyCode == 13 || evt.keyCode == 9 || evt.keyCode == 46 || evt.keyCode == 37 || evt.keyCode == 39 || evt.charCode == 46) {
            return document.defaultAction;
        }
    }
    return false;
}

// Values with "." NOT allowed
function filterNonCurrencyKeys(e) {
    var evt;
    if($('revenue-share-currency')){
        currencyType = $('revenue-share-currency').value;
    }
    else{
        currencyType ="USD";
    }
    if(currencyType == "EURO") {
        if(window.event) {
            evt = window.event;
            if( (evt.keyCode > 47) && (evt.keyCode < 58) ||  evt.keyCode == 44) {
                return document.defaultAction;
            }
            } else {
                evt = e;
                if( (evt.charCode > 47) && (evt.charCode < 58) ||  evt.keyCode == 8 || evt.keyCode == 13 || evt.keyCode == 9 || evt.keyCode == 46 || evt.keyCode == 37 || evt.keyCode == 39 || evt.charCode == 44) {
                    return document.defaultAction;
            }
        }
    }
    else
    {
        if(window.event) {
            evt = window.event;
            if( (evt.keyCode > 47) && (evt.keyCode < 58) ||  evt.keyCode == 46) {
                return document.defaultAction;
            }
            } else {
            evt = e;
            if( (evt.charCode > 47) && (evt.charCode < 58) ||  evt.keyCode == 8 || evt.keyCode == 13 || evt.keyCode == 9 || evt.keyCode == 46 || evt.keyCode == 37 || evt.keyCode == 39 || evt.charCode == 46) {
                return document.defaultAction;
            }
            }
    }
    return false;
}

function formatForUSD(num) {
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
        num = "0";

    var hasCent = false;
    var dotPosition = num.lastIndexOf('.');
    if(dotPosition != "" && dotPosition != -1) {
        hasCent=true;
    }
    sign = (num == (num = Math.abs(num)));

    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
        cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
        num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));

     var finalNum = ((sign)?'':'-') + num; //+ '.' + cents);
     if(hasCent){
         finalNum = (((sign)?'':'-') +  num + '.' + cents);
     }
    return finalNum;
}

function formatForUSD_OLD(strValue){
    strValue = strValue.toString().replace(/\$|\,/g,'');
    dotPosition = strValue.lastIndexOf('.');

    if(dotPosition != "" && dotPosition != -1) {
	appendCharacter = ".";      //strValue.substring(dotPosition,strValue.length);
        appendText  = strValue.substring(dotPosition+1,strValue.length);
    }
    else {
        appendCharacter = "";
        appendText = "";
    }

    dblValue = parseFloat(strValue);

    dblValue = Math.floor(dblValue*100+0.50000000001);
    intCents = dblValue%100;

    if(appendText.length == 1)
        strCents = appendText;
    else if(intCents !=0)
        strCents = intCents.toString();
    else
        strCents ="";

    dblValue = Math.floor(dblValue/100).toString();

    if(intCents<10 && intCents != 0)
        strCents = "0" + strCents;

    for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
        dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
        dblValue.substring(dblValue.length-(4*i+3));

   if(strCents != "")
        strValue =   dblValue + appendCharacter +strCents;
   else if(dblValue != 0 && strCents == "")
        strValue =   dblValue + appendCharacter + appendText;
   else
        strValue = "0.00";

 return strValue;
}

function formatForEURO(strValue){
    strValue=formatForUSD(strValue);
    if(strValue && strValue != "" ){
        strValue = strValue.toString().replace(/\$|\./g,'#');
        strValue = strValue.toString().replace(/\$|\,/g,'.');
        strValue = strValue.toString().replace(/\$|\#/g,',');
    }
    /*
    strValue = strValue.toString().replace(/\$|\./g,'');
    dotPosition = strValue.lastIndexOf(',');

    if(dotPosition != "" && dotPosition != -1) {
	appendCharacter = ",";      //strValue.substring(dotPosition,strValue.length);
        appendText  = strValue.substring(dotPosition+1,strValue.length);
    }
    else {
	appendCharacter = "";
	appendText = "";
    }

    strValue = strValue.replace(',','.');

    dblValue = parseFloat(strValue);

    dblValue = Math.floor(dblValue*100+0.50000000001);
    intCents = dblValue%100;

    if(appendText.length == 1)
        strCents = appendText;
    else if(intCents !=0)
        strCents = intCents.toString();
    else
        strCents ="";

    dblValue = Math.floor(dblValue/100).toString();

    if(intCents<10 && intCents != 0)
        strCents = "0" + strCents;

    for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
        dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+'.'+
        dblValue.substring(dblValue.length-(4*i+3));

   if(strCents != "")
        strValue =   dblValue + appendCharacter +strCents;
   else if(dblValue != 0 && strCents == "")
        strValue =   dblValue + appendCharacter + appendText;
   else
        strValue = "0,00";
*/
   return strValue;
}


function formatCurrency(objNum,decimalAllowed){
    if(objNum.value == '')
        strValue=""
    else
        strValue=objNum.value;

    if($('revenue-share-currency')){
        currencyType = $('revenue-share-currency').value;
    }
    else{
        currencyType ="USD";
    }
    if(strValue != ""){
        if(!decimalAllowed){
            strValue=removeCommaDot(strValue);
        }
        if(currencyType == "EURO"){
            objNum.value=formatForEURO(strValue);
        }else{
            objNum.value=formatForUSD(strValue);
        }
    }
}

function extractNumber(element)
{
	var temp = element.value;
	var decimalPlaces = 2;

	if($('revenue-share-currency')){
		currencyType = $('revenue-share-currency').value;
	}
	else{
		currencyType ="USD";
	}

	if (decimalPlaces != 0) {
		if(currencyType == "EURO"){
			var reg3 = /\,/g;
		}else{
			var reg3 = /\./g;
		}
		var reg3Array = reg3.exec(temp);
		if (reg3Array != null) {
			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);

			if(reg3Right == "")
				reg3Right = "00";
			else if(reg3Right.length == 1)
			 	reg3Right = reg3Right+"0";

			if(currencyType == "EURO"){
				temp = temp.substring(0,reg3Array.index) + ',' + reg3Right;
			}else {
				temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
			}
		}
	}

	element.value = temp;
}

function roundingDecimalNumber(element)
{
	var temp = element.value;
	var decimalPlaces = 2;

	if (decimalPlaces != 0) {
		var reg3 = /\./g;
		var reg3Array = reg3.exec(temp);
		if (reg3Array != null) {
			// keep only first occurrence of .
			//  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
			reg3Right = reg3Right.replace(reg3, '');
			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
		}
	}

	element.value = temp;
}

function checkNumericValue(textfield){
    var anum=/(^\d+$)/
    if(anum.test(textfield.value)){
        return true;
    }else{
        alert("The value in the textfield must be numeric.");
        textfield.value = "";
    }
}

//Dynamically changes the height of the element by adding the amount of pixels specified.
function setHeightFromFirstElement(firstElement, secondElement){
    var panelHeight = firstElement.getHeight();
    secondElement.style.height = panelHeight+'px';
}

var busyfetch = false;
function fetchLaunchPopup(page, popupDivId, initFunc, destDivId, scheme, server, port, contextPath, pagePath,updateId,popUpMessage){
    if(busyfetch) return;
    busyfetch = true;

    if ($('allover-spinner') != null) {
        try {
            $('allover-spinner').style.display = "block";
            var allOverHeight = 0;
            var allOverWidth = 0;
            try{
                allOverHeight = document.body.scrollHeight;
                allOverWidth = document.body.scrollWidth;
            }catch(exp){
                try{
                    allOverHeight = ($('header')).scrollHeight +  ($('container')).scrollHeight + ($('footer')).scrollHeight;
                }catch(exp){
                    allOverHeight = 1000;
                    allOverWidth = 2000;
                }
            }
            $('allover-spinner').style.height = allOverHeight + 'px';
            $('allover-spinner').style.width = allOverWidth + 'px';
        } catch (exp) {}

        try {
            var scr = document.viewport.getScrollOffsets();
            var dim = document.viewport.getDimensions();
            // set it in middle
            if($('allover-spinner-img').getHeight() >= dim.height){
                $('allover-spinner-img').style.top = scr.top + 10 + 'px';
                $('allover-spinner-img').style.left = (dim.width / 2 - 60 / 2) + scr.left + 'px';
            } else {
                $('allover-spinner-img').style.top = (dim.height / 2 - 60 / 2) + scr.top + 'px';
                $('allover-spinner-img').style.left = (dim.width / 2 - 60 / 2) + scr.left + 'px';
            }
        } catch (exp) {}
    }

    try{
        var pageUrl = contextPath + pagePath + page;
        //alert(pageUrl);
        new Ajax.Updater(destDivId, pageUrl,
        {
            method: "get",
            onComplete: function(req){
                if(req.responseText != null &&  req.responseText != ''){
                    var responseText =  req.responseText;
                    if(responseText.indexOf('homePage()', 0) > 0 ){
                        //alert('Your session expired...');
                        location.href=requestContext;
                        return;
                    }
                }
                try{//alert('onComplete');
                    GMX.popups.launchPopUp(popupDivId);
                } catch(exp){}
                try{
                    if(updateId!=null && popUpMessage!=null){
                        var renderId=document.getElementById(updateId);
                        if(renderId!=null){
                            renderId.innerHTML=popUpMessage;
                        }
                    }
                    if(initFunc != null) initFunc();
                } catch(exp){}
                busyfetch = false;
            },
            onFailure: function(){
                busyfetch = false;
                //alert('Cant Get ' + pageUrl);
                location.href=requestContext+'/logout.jsp';
            }
        });
    }catch(exp){
        alert(exp);
        busyfetch = false;
    }
}

function submitLink(event,linkId)
{
       if(event==null)
          event =  window.event;

        var key=event.keyCode;

        if(key == '13')
        {
            var submitLink = document.getElementById(linkId);
            if(submitLink){
                submitLink.click();
            }
        }
}

//This function is not refered anywhere
var keyPressTestConfirmationModalDialog = function(idVal,genericYesFuncToCallAction){
    if($(idVal)){
        Event.observe(document,'keypress', function(e){
            if(!e)var e = window.event;
            if(e.keyCode=='13'){
                genericYesFuncToCallAction();
            }
        });
    }
}

// Added for GMX-1648
function browserButtonFix(){
    if(Prototype.Browser.WebKit) {
        $$('button').each(function(el) {
            el.addClassName('s-blue-btn');
            el.addClassName('blue-btn span');
        } );
    }
    if(Prototype.Browser.IE8) {
        $$('button').each(function(el) {
            el.addClassName('s-blue-btn');
            el.addClassName('m-blue-btn span');
        });
    }
    if(Prototype.Browser.IE7) {
        $$('button').each(function(el) {
            el.addClassName('i-blue-btn');
            el.addClassName('i-blue-btn span');
        } );
    }
    if(Prototype.Browser.Mozilla) {
        $$('button').each(function(el) {
                el.addClassName('blue-btn');
                el.addClassName('blue-btn span');
        } );
    }
}
//End

function selectwholeText(boxId){
    if($(boxId)){
         $(boxId).select();
    }
}

//Used for informational modal dialog.
var checkOkClick = function(popupId){
    $(popupId).fade({
        duration: 0.3,
        from: 1,
        to: 0,
        afterFinish: function(){
            try{
                if($('allover')){
                    $('allover').style.display = "none";
                }
                $(popupId).removeClassName('open');
                if(GMX.popups.idWrapperPopup){
                    GMX.popups.idWrapperPopup = null;
                }
            }catch(exp){}
        }
    });
}



/**
 *  Disable all the Header and Footer links so that user can't naviagete through Header and Footer links
 *  Fix for GMX-2516
 */

function disableAllHeaderFooterRegionLinks(){
    try {
        var disableLinks = $('disableLinks');
        if ( disableLinks ) {
            var idName = document.getElementById("inbox_count_id");
            if ( idName )  {
                    idName.style.color="#D5D8D8";
                    idName.style.cursor="text";
                    idName.onclick='javascript:void(0);';
                    idName.href='javascript:void(0);';
                    idName.style.textDecoration="none";
                }
             var buttonId = document.getElementById("search-go-button");
            if( buttonId ) {
                    buttonId.style.color="#D5D8D8";
                    buttonId.style.cursor="text";
                    buttonId.click='javascript:void(0);';
                    buttonId.href='javascript:void(0);';
                    buttonId.disabled='true';
                    buttonId.style.textDecoration="none";
                }
                $$('a.headerClass').each(function(item){
                    item.style.color="#D5D8D8";
                    item.style.cursor="text";
                    item.onclick='javascript:void(0);';
                    item.href='javascript:void(0);';
                    item.style.textDecoration="none";
                });

            $$('a.footerClass').each(function(item){
                    item.style.color="white";
                    item.style.cursor="text";
                    item.onclick='javascript:void(0);';
                    item.href='javascript:void(0);';
                    item.style.textDecoration="none";
                });

               $$('a.subMenuClass').each(function(item){
                    item.style.color="#D5D8D8";
                    item.style.cursor="text";
                    item.onclick='javascript:void(0);';
                    item.href='javascript:void(0);';
                    item.style.textDecoration="none";
                });
        }
    } catch (ex) {}
}



function setupTabIndexForPopup(popupDivId){
    $(popupDivId).style.display = 'block';

    var firstElement = Form.getElements($(popupDivId)).find(function(element) {
        return element.type != 'hidden' && !element.disabled &&
        ['input', 'select', 'textarea','checkbox','select-one','select-multiple'].include(element.tagName.toLowerCase());
    });

    if(firstElement != null && firstElement.type != 'select-one' &&  firstElement.type != 'select-multiple'){
	if(!$(firstElement).tabIndex)
		$(firstElement).tabIndex="0";
	setTimeout(function() {
	    try{
	          $(firstElement).focus();
	    } catch (e) {}
	}, 100)
    }

    var cancelElement = document.getElementById(popupDivId).getElementsByClassName('button-cancel');
    if(cancelElement != null && cancelElement[0] != null){
        var lastElementId = cancelElement[0];
        Event.observe($(lastElementId),'keyup', function(e){
            if (e.keyCode == Event.KEY_TAB)
                $(firstElement).focus();
        });
    }

    var childNodes = document.getElementById(popupDivId).getElementsByTagName('*');
    if(childNodes != null) {
            for(var i = 0, maxI = childNodes.length; i < maxI; i++) {
                var element = childNodes[i];
                switch(element.type) {
                    case "text":
                    case "textarea":
                    case "button":
                    case "reset":
                    case "submit":
                    case "file":
                    case "image":
                    case "radio":
                    case "checkbox":
                    case "select-one":
                    case "select-multiple":{
			if(!$(element).tabIndex)
				$(element).tabIndex ="0";
			}
                }
            }
    }
    if(lastElementId != null && !$(lastElementId).tabIndex  )
        $(lastElementId).tabIndex = "0";

}



// Function to load images specifically need for Safari bugs.
// e.g. GMX-2429, GMX-2638
function loadTitleImages(){
    $$('span.title-image-url').each(function (el){
        var imgURL=el.innerHTML.strip().unescapeHTML();
        var newImage = new Element('img', {
            'src': imgURL,
            'class':'title',
            'style':'float:left;padding-right:10px;'
        });
        Element.insert(el, { after: newImage });
    });
}

//Utility function to get element by names and ext with Prototype
function $N(elName){
    if(typeof elName== 'string'){
        var el=document.getElementsByName(elName);
        if(el && el.length>0){
            for(i=0; i <el.length; i++){
                try{
                    el[i]=Element.extend(el[i]);
                }catch(err){}
            }
            return el;
        }
    }
    return null;
}

function captureEnter(event){
    var evt;
    if(window.event) {
        evt = window.event;
        if(evt.keyCode == 13)
            return false;
        else
            return document.defaultAction;
    }
    return document.defaultAction;
}


function hideShowPastEvents(){
    var sideElement = $("side");
    var downElement = $("down");
    var pastEventsPanel = $("past_events_panel");
	if(sideElement.style.display == "block") {
	    sideElement.style.display = "none";
	    downElement.style.display = "block";
	    pastEventsPanel.style.display = "block";

	} else {
	    sideElement.style.display = "block";
	    downElement.style.display = "none";
	    pastEventsPanel.style.display = "none";
	}
}