
StickyRollover = Behavior.create({

    initialize: function(options){
    
        this.imageUrl = options.imageUrl;
        this.hoverImageUrl = options.hoverImageUrl;
        this.onClickCallback = options.onClickCallback;
        this.sticky = options.sticky;
        
        new Image().src = this.imageUrl;
        new Image().src = this.hoverImageUrl;
        
        if (this.sticky.call()) 
            this.element.src = this.hoverImageUrl;
    },
    
    onmouseover: function(){
        this.element.src = this.hoverImageUrl;
    },
    
    onmouseout: function(){
        if (!(this.sticky.call())) 
            this.element.src = this.imageUrl;
    },
    
    onclick: function(evt){
        this.onClickCallback.call();
        evt.stop();
    }
});


TipIndicator = Behavior.create({

    initialize: function(tipId){
        this.tip = $(tipId);
    },
    
    onmouseover: function(){
        this.tip.show();
    },
    
    onmouseout: function(){
        this.tip.hide();
    },
    
    onclick: function(evt){
        evt.stop();
    }
});

ShowOnMouseOver = Behavior.create({

    initialize: function(showDivId, hideDivId, hideDivId1){        
        this.showDiv = $(showDivId);
        this.hideDiv = $(hideDivId);
        if (hideDivId1) {
            this.hideDiv1 = $(hideDivId1);
        }
    },
    
    onmouseover: function(){
        if (showingPanels == false) {
          this.showDiv.show();
          this.hideDiv.hide();         
          
          if (this.hideDiv1) {
              this.hideDiv1.hide();
          }
          showingPanels = true;
        }
    }   
});


HideOnMouseOut = Behavior.create({

    initialize: function(callback){
        this.callback = callback;
    },
    
    onmouseout: function() {
        this.element.hide();
        this.callback.call();
        showingPanels = false;
    }   
});

ToggleMapStats = Behavior.create({

    initialize: function(showDivId, timeDivId, time){
        this.showDiv = $(showDivId);
        this.time = time;
        this.timeDivId = timeDivId;
        new Image().src = '/web_images/members/world_wide_members.gif';
    },
    
    onmouseover: function(){
    
        // convert time (which is in GMT) to local time 
        var now = new Date();
        var gmtOffset = now.getTimezoneOffset();
        var date = new Date(2000, 0, 1);
        date.setHours(this.time.substring(0, 2));
        date.setMinutes(this.time.substring(3, 5));
        date.setTime(date.getTime() - (gmtOffset * 60000));
        var ap = "AM";
        var hour = date.getHours();
        if (hour > 11) {
            ap = "PM";
        }
        if (hour > 12) {
            hour = hour - 12;
        }
        if (hour == 0) {
            hour = 12;
        }
        $(this.timeDivId).innerHTML = hour + ':' + date.getMinutes() + ' ' + ap + ' ';
        
        $('member_gif_anim').hide();
        $('world_banner_img').src = '/web_images/members/world_wide_members.gif';
        this.showDiv.show();
    },
    
    onmouseout: function(){
        this.showDiv.hide();
        $('world_banner_img').src = '/web_images/members/world_wide.gif';
        $('member_gif_anim').show();
    }
});

ClearOnClick = Behavior.create({

    initialize: function(){
        this.alreadyClicked = false;
    },
    
    onclick: function(){
        if (!this.alreadyClicked) {
            this.element.innerHTML = '';
            this.alreadyClicked = true;
        }
    }
});

ShowHide = Behavior.create({

    initialize: function(eId){
        this.shown = false;
        this.e = $(eId);
    },
    
    onclick: function(){
        if (!this.shown) {
            this.e.show();
            this.shown = true;
        }
        else {
            this.e.hide();
            this.shown = false;
        }
    }
});

ToggleOnClick = Behavior.create({

    initialize: function(inputFieldId){
				this.inputField = $(inputFieldId);
				new ShowOnBlur(inputFieldId,this.element.id);
    },
    
    onfocus: function(){
			  this.element.hide();
        this.inputField.show();
				this.inputField.focus();
    }
});

ShowOnBlur = Behavior.create({
    initialize: function(placeHolderId){
        this.placeHolder = $(placeHolderId);
    },
    
    onblur: function() {
        if (this.element.value == '') {
          this.element.hide();         
          this.placeHolder.show();
        }
    }
});



SwapOnClick = Behavior.create({

    initialize: function(onUrl, offUrl){
        this.shown = false;
        this.onUrl = onUrl;
        this.offUrl = offUrl;
        
        new Image().src = this.onUrl;
        new Image().src = this.offUrl;
    },
    
    onclick: function(){
        if (!this.shown) {
            this.element.src = this.onUrl;
            this.shown = true;
        }
        else {
            this.element.src = this.offUrl;
            this.shown = false;
        }
    }
});

function registerLables(){
    argumentsAry = $A(arguments);
    Event.observe($('form'), 'submit', function(evt){
        clearIfEqual(argumentsAry);
    });
    var i = 0;
    var element = '';
    var lable = '';
    argumentsAry.each(function(argument){
        if (i % 2 == 0) {
            element = argument;
        }
        else {
            lable = argument;
            new InputLable(element, lable);
        }
        i = i + 1;
    });
}

InputLable = Behavior.create({

    initialize: function(lable){
        this.lable = lable;
        if (this.element.value == '') {
            this.element.value = this.lable;
        }
    },
    
    onclick: function() {
        clearElementIfEqual(this.element, this.lable);
    },
		
		onblur: function() {
        if (this.element.value == '') {
            this.element.value = this.lable;
        }
		}
});

function clearElementIfEqual(element, lable){
    if ($(element).value == lable) {
        $(element).value = '';
    }
}

function clearIfEqual(argumentsAry){
    var i = 0;
    var element = '';
    var lable = '';
    argumentsAry.each(function(argument){
        if (i % 2 == 0) {
            element = argument;
        }
        else {
            lable = argument;
            if ($(element).value == lable) {
                $(element).value = '';
            }
        }
        i = i + 1;
    });
}


MaxLength = Behavior.create({

    initialize: function(length){
        this.length = length;
    },
    
    onchange: function() {
        restrictToMaxLength(this.element.id,this.length);
    },
    
    onkeyup: function() {
        restrictToMaxLength(this.element.id,this.length);
    }
});

ShowHideOnHover = Behavior.create({

    initialize: function(showHideDiv){
        this.showHideDiv = showHideDiv;
    },
    
    onmouseover: function() {
        this.showHideDiv.show();
    },
    
    onmouseout: function() {
        this.showHideDiv.hide();
    }
});

function restrictToMaxLength(compId, maxchars){
  if($(compId).value.length > maxchars) $(compId).value = $(compId).value.substring(0, maxchars);
}

function getPageCount(recPerPage,total){
  if(total%recPerPage == 0){
    return (total/recPerPage);
  }else{
    return (total/recPerPage)+1;
  }
}

PagedLinks = Class.create({
    initialize: function(containerId, recordsPerPage, panelIdentifyingClassname, initiallyVisiblePanelIndexes, totalRecords, blockNo){
        if (totalRecords > recordsPerPage) {
          this.panels = $$('#' + containerId + ' .' + panelIdentifyingClassname);
          this.recordsPerPage = recordsPerPage;
          this.displayInitiallyVisiblePanels(initiallyVisiblePanelIndexes, this.panels);
          this.current = 0;
          this.blockNo = blockNo;
         // new PaginationLinks('group_nav_pages', '12','pagelinkcont', $R(0,11),getPageCount(12,totalRecords),blockNo);
          if (totalRecords % recordsPerPage > 0) 
            this.pageTotal = (Math.floor(totalRecords / recordsPerPage)) + 1;
          else 
            this.pageTotal = Math.floor(totalRecords / recordsPerPage);
                      
          for (j = 1; j <= blockNo; j++) {
            new PagedLinks.next($('next_' + j.toString()), j, this);
            new PagedLinks.back($('back_' + j.toString()), j, this);
            new PagedLinks.first($('first_' + j.toString()), j, this);
            new PagedLinks.last($('last_' + j.toString()), j, this);
            this.showButtons(0, this.pageTotal, j);
            for (i = 1; i <= this.pageTotal; i++) {
              new PagedLinks.pageLink($(i.toString() + '_' + j.toString()), i, this.pageTotal, j, this);
            }
          }
					//this.highlightCurrentPage(1);
        }
    },
    
    visiblePanelRange: function(){
        var firstVisible, lastVisible;
        this.panels.each(function(panel, index){
            if (panel.visible()) {
                if (firstVisible != null) 
                    lastVisible = index;
                else 
                    firstVisible = index;
            }
        });
        return $A($R(firstVisible, lastVisible));
    },
    
    showPanelAtIndex: function(index){
        this.panels[index].show();
    },
    
    hidePanelAtIndex: function(index){
        this.panels[index].hide();
    },
        
    firstPanelIsVisible: function(){        
        return this.panels.first().visible();
    },
    
    lastPanelIsVisible: function(){        
        return this.panels.last().visible();
    },
    displayInitiallyVisiblePanels: function(initiallyVisiblePanelIndexes){       
        this.panels.each(function(panel, index){
        
            if (initiallyVisiblePanelIndexes.include(index)) 
                panel.show();
            else 
                panel.hide();
        });
    },
    panelExists: function(index){
        if (0 > index) {
            return false;
        }
        else {
            return this.panels.length > index;
        }
    },
    panelsCount: function(){
        return this.panels.length - 1;
    },
    recordsCount: function(){
        return this.recordsPerPage;
    },
    hidePanelRange: function(start, end){
        while (end >= start) {
            this.hidePanelAtIndex(end);
            end--;
        }
    },
    showPanelRange: function(start, end){
        while (end >= start) {
            this.showPanelAtIndex(end);
            end--;
        }
    },
    getCurrentPage: function(){
      return this.current;
    },
     highlightCurrentPage: function(pageNo){      
       for (j = 1; j <= this.blockNo; j++) {            
           $((pageNo+1)+'_'+j).style.display = "none";  
           $((pageNo+1)+'_'+j+'h').style.display = "inline";    
           $((this.current+1)+'_'+j).style.display = "inline";  
           $((this.current+1)+'_'+j+'h').style.display = "none";
           this.showButtons(pageNo,this.pageTotal,j);          
      }      
      this.current = pageNo;      
    },
    totalPages: function(){
      return this.pageTotal;
    },
    showButtons: function(pageNo, totalPages, blockNo){
   
        if (pageNo == 0 && totalPages == 1) {
            $('next_buttons_' + blockNo).style.display = 'none';
            $('previous_buttons_' + blockNo).style.display = 'none';
        }
        else 
            if (pageNo == 0) {
                $('next_buttons_' + blockNo).style.display = '';
                $('previous_buttons_' + blockNo).style.display = 'none';
            }
        else 
            if (pageNo == (totalPages - 1)) {
                $('next_buttons_' + blockNo).style.display = 'none';
                $('previous_buttons_' + blockNo).style.display = '';
            }
        else {
            $('next_buttons_' + blockNo).style.display = '';
            $('previous_buttons_' + blockNo).style.display = '';
        }    
  }
})

PagedLinks.next = Behavior.create({
    initialize: function(blockNo, container){
        this.container = container;
        this.blockNo = blockNo;
    },
    onclick: function(){      
      if(this.container.lastPanelIsVisible()) return;
    
      var pageNo = this.container.getCurrentPage();
      var totalPages = this.container.totalPages();
      var recordsPerPage = this.container.recordsCount();
      
      if(pageNo < totalPages-1) this.container.highlightCurrentPage(++pageNo);
      else this.container.highlightCurrentPage(totalPages-1);
      
      if (pageNo == 0) {
          this.container.hidePanelRange((pageNo + 1) * recordsPerPage, this.container.panelsCount());
          this.container.showPanelRange(pageNo * recordsPerPage, ((pageNo + 1) * recordsPerPage) - 1);
      }else if (pageNo == (totalPages - 1)) {         
          this.container.hidePanelRange(0, pageNo*recordsPerPage-1);
          this.container.showPanelRange(pageNo*recordsPerPage, this.container.panelsCount());
      } else {
          this.container.hidePanelRange(0, (pageNo * recordsPerPage) - 1);
          this.container.showPanelRange(pageNo * recordsPerPage, ((pageNo + 1) * recordsPerPage) - 1);
          this.container.hidePanelRange((pageNo + 1) * recordsPerPage, this.container.panelsCount());
      }
     // setDisplayButtons(pageNo,totalPages,this.blockNo);
    }
    
});

PagedLinks.back = Behavior.create({
    initialize: function(blockNo, container){
        this.container = container;
        this.blockNo = blockNo;
    },
    onclick: function(){     
      if(this.container.firstPanelIsVisible()) return;
    
      var pageNo = this.container.getCurrentPage();
      var totalPages = this.container.totalPages();
      var recordsPerPage = this.container.recordsCount();
      if(pageNo > 0) this.container.highlightCurrentPage(--pageNo);
      else this.container.highlightCurrentPage(0);
      
      if (pageNo == 0) {
          this.container.hidePanelRange((pageNo + 1) * recordsPerPage, this.container.panelsCount());
          this.container.showPanelRange(pageNo * recordsPerPage, ((pageNo + 1) * recordsPerPage) - 1);
      }else if (pageNo == (totalPages - 1)) {         
          this.container.hidePanelRange(0, pageNo*recordsPerPage-1);
          this.container.showPanelRange(pageNo*recordsPerPage, this.container.panelsCount());
      } else {
          this.container.hidePanelRange(0, (pageNo * recordsPerPage) - 1);
          this.container.showPanelRange(pageNo * recordsPerPage, ((pageNo + 1) * recordsPerPage) - 1);
          this.container.hidePanelRange((pageNo + 1) * recordsPerPage, this.container.panelsCount());
      }
    //   setDisplayButtons(pageNo,totalPages,this.blockNo); 
    }
});

PagedLinks.first = Behavior.create({
    initialize: function(blockNo, container){
        this.container = container;
        this.blockNo = blockNo;
    },
    onclick: function(){
      if(this.container.firstPanelIsVisible()) return;
      
      var pageNo = 0;      
      var recordsPerPage = this.container.recordsCount();
      
      this.container.highlightCurrentPage(pageNo);          
      this.container.hidePanelRange((pageNo + 1) * recordsPerPage, this.container.panelsCount());
      this.container.showPanelRange(pageNo * recordsPerPage, ((pageNo + 1) * recordsPerPage) - 1);
     // setDisplayButtons(pageNo,this.container.totalPages(),this.blockNo);
    }
    
});

PagedLinks.last = Behavior.create({
    initialize: function(blockNo, container){
        this.container = container;
        this.blockNo = blockNo;
    },
    onclick: function(){
          if(this.container.lastPanelIsVisible()) return;
          
          var pageNo = this.container.totalPages() - 1;      
          var recordsPerPage = this.container.recordsCount();
          
          this.container.highlightCurrentPage(pageNo);   
          this.container.hidePanelRange(0, pageNo*recordsPerPage-1);
          this.container.showPanelRange(pageNo*recordsPerPage, this.container.panelsCount());   
       //   setDisplayButtons(pageNo,this.container.totalPages(),this.blockNo);       
    }
});

PagedLinks.pageLink = Behavior.create({
    initialize: function(currentPage, totalPages, blockNo, container){
        this.pageNo = currentPage - 1;
        this.totalPages = totalPages;
        this.container = container;
        this.blockNo = blockNo;
    },
    onclick: function(){
        var recordsPerPage = this.container.recordsCount();
        this.container.highlightCurrentPage(this.pageNo);
        
        if (this.pageNo == 0) {          
            this.container.hidePanelRange((this.pageNo + 1) * recordsPerPage, this.container.panelsCount());
            this.container.showPanelRange(this.pageNo * recordsPerPage, ((this.pageNo + 1) * recordsPerPage) - 1);
        }else if (this.pageNo == (this.totalPages - 1)) {                     
            this.container.hidePanelRange(0, this.pageNo*recordsPerPage-1);
            this.container.showPanelRange(this.pageNo*recordsPerPage, this.container.panelsCount());
        } else {
            this.container.hidePanelRange(0, (this.pageNo * recordsPerPage) - 1);
            this.container.showPanelRange(this.pageNo * recordsPerPage, ((this.pageNo + 1) * recordsPerPage) - 1);
            this.container.hidePanelRange((this.pageNo + 1) * recordsPerPage, this.container.panelsCount());
        }  
       // setDisplayButtons(this.pageNo,this.totalPages,this.blockNo);
    }
});

function setDisplayButtons(pageNo, totalPages, blockNo){
    for (j = 1; j <= blockNo; j++) {
        if (pageNo == 0 && totalPages == 1) {
            $('next_buttons_' + j).style.display = 'none';
            $('previous_buttons_' + j).style.display = 'none';
        }
        else 
            if (pageNo == 0) {
                $('next_buttons_' + j).style.display = '';
                $('previous_buttons_' + j).style.display = 'none';
            }
        else 
            if (pageNo == (totalPages - 1)) {
                $('next_buttons_' + j).style.display = 'none';
                $('previous_buttons_' + j).style.display = '';
            }
        else {
            $('next_buttons_' + j).style.display = '';
            $('previous_buttons_' + j).style.display = '';
        }
    }
}


PaginationLinks = Class.create({

    initialize: function(containerId, recordsPerPage, panelIdentifyingClassname, initiallyVisiblePanelCount, totalRecords, blockNo){
      if (totalRecords > recordsPerPage) {
        this.panels = $$('#' + containerId + ' .' + panelIdentifyingClassname);
        
        this.current = 1;
        this.blockNo = blockNo;
        var panelsArray = $A(initiallyVisiblePanelCount); 
        
        if (totalRecords % recordsPerPage > 0) 
          this.pageTotal = (Math.floor(totalRecords / recordsPerPage)) + 1;
        else 
          this.pageTotal = Math.floor(totalRecords / recordsPerPage);
          
        this.recordsPerPage = panelsArray.length; 
				
				if (this.pageTotal > this.recordsPerPage) 
				  this.minInitVisiblePanels = this.recordsPerPage;
				else
          this.minInitVisiblePanels = this.pageTotal;
					
        this.firstVisiblePage = 1;
        this.lastVisiblePage = parseInt(panelsArray.length,10);
        for (j = 1; j <= this.blockNo; j++) {
          new PaginationLinks.Left($('back_' + j.toString()), this);
          new PaginationLinks.Right($('next_' + j.toString()), this);
          new PaginationLinks.first($('first_' + j.toString()), this);
          new PaginationLinks.last($('last_' + j.toString()), this);
          for (i = 1; i <= this.pageTotal; i++) {
            new PaginationLinks.pageLink($(i.toString() + '_' + j.toString()), i, this);
          }
          this.displayInitiallyVisiblePanels(this.minInitVisiblePanels,j);
        }
      }    
    },
      visiblePanelRange: function(){
        var firstVisible, lastVisible;
        this.panels.each(function(panel, index){
            if (panel.visible()) {
                if (firstVisible != null) 
                    lastVisible = index;
                else 
                    firstVisible = index;
            }
        });
        return $A($R(firstVisible, lastVisible));
    },
    
    showPanelAtIndex: function(index){
        for (j = 1; j <= this.blockNo; j++) {
          $('link_' + index + '_' + j).style.display = 'inline';
        }
    },
    
    hidePanelAtIndex: function(index){
        for (j = 1; j <= this.blockNo; j++) {
          $('link_' + index + '_' + j).style.display = 'none';
        }
    },
        
    firstPanelIsVisible: function(){
        return this.panels.first().visible();
    },
    
    lastPanelIsVisible: function(){
        return this.panels.last().visible();
    },
		
    displayInitiallyVisiblePanels: function(pageTotal,blockNo) {
        for(index=1; index <= pageTotal; index++){         
          $('link_' + index + '_' + blockNo).style.display = '';
        }   
    },
		
    panelExists: function(index){
        if (0 > index) {
            return false;
        }
        else {
            return this.panels.length > index;
        }
    },
    panelsCount: function(){
        return this.panels.length - 1;
    },
    recordsCount: function(){
        return parseInt(this.recordsPerPage,10);
    },
    hidePanelRange: function(start, end){ 
           while (end >= start) {
            this.hidePanelAtIndex(end);         
            end--;
          }   
    },
    showPanelRange: function(start, end){    
          while (end >= start) {
           this.showPanelAtIndex(end); 
            end--;
          }    
    },
    setCurrentPage: function(pageNo){
      this.current = pageNo;      
    },
    getCurrentPage: function(){
      return parseInt(this.current,10);
    }, 
    setFirstVisiblePage: function(pageNo){
      this.firstVisiblePage = pageNo;      
    },
    getFirstVisiblePage: function(){
      return parseInt(this.firstVisiblePage,10);
    },  
    setLastVisiblePage: function(pageNo){
      this.lastVisiblePage = pageNo;      
    },
    getLastVisiblePage: function(){
      return parseInt(this.lastVisiblePage,10);
    },     
    totalPages: function(){
      return this.pageTotal;
    }
    
});

PaginationLinks.first = Behavior.create({
    initialize: function(container){
        this.container = container;
    },
    onclick: function(){
      if(this.container.firstPanelIsVisible()) return;      
      var pageNo = 1;      
      var recordsPerPage = this.container.recordsCount();
      this.container.setCurrentPage(pageNo);
      this.container.setFirstVisiblePage(pageNo);
      this.container.setLastVisiblePage(recordsPerPage);         
      
      this.container.showPanelRange(1, this.container.recordsCount());
      this.container.hidePanelRange((this.container.recordsCount()+1), this.container.totalPages());
    }
});

PaginationLinks.last = Behavior.create({
    initialize: function(container){
        this.container = container;
    },
    onclick: function(){
         // if(this.container.lastPanelIsVisible()) return;          
          var pageNo = this.container.totalPages();  
          var recordsPerPage = this.container.recordsCount();   
          this.container.setCurrentPage(pageNo); 
          this.container.setFirstVisiblePage((pageNo-recordsPerPage)+1);
          this.container.setLastVisiblePage(pageNo);
             
          this.container.hidePanelRange(1, (pageNo - recordsPerPage));
          this.container.showPanelRange((pageNo - recordsPerPage)+1, pageNo);          
    }
});
PaginationLinks.Left = Behavior.create({
    initialize: function(container){
        this.container = container;
    },
    onclick: function(){
        var pageNo = this.container.getCurrentPage();
        if(pageNo == 1) return;
        var totalPages = this.container.totalPages();        
        var firstVisiblePage = this.container.getFirstVisiblePage();
        var lastVisiblePage = this.container.getLastVisiblePage();
        pageNo= parseInt(pageNo,10)-1;
        this.container.setCurrentPage(pageNo);
        
        if (firstVisiblePage <= pageNo) {
          return false;
        }
        else {
          firstVisiblePage = parseInt(firstVisiblePage)-1;
          lastVisiblePage = parseInt(lastVisiblePage)-1;
          this.container.setFirstVisiblePage(firstVisiblePage);
          this.container.setLastVisiblePage(lastVisiblePage);
          
          this.container.hidePanelRange(1, firstVisiblePage - 1);
          this.container.showPanelRange(firstVisiblePage, lastVisiblePage);
          this.container.hidePanelRange(lastVisiblePage + 1, totalPages);
        }      
    }
});

PaginationLinks.Right = Behavior.create({
    initialize: function(container){
        this.container = container;
    },
    onclick: function(){
        var pageNo = this.container.getCurrentPage();        
        var totalPages = this.container.totalPages();
        
        if(pageNo == totalPages) return;
        
        pageNo= parseInt(pageNo,10)+1;
        this.container.setCurrentPage(pageNo);
        var firstVisiblePage = this.container.getFirstVisiblePage();
        var lastVisiblePage = this.container.getLastVisiblePage();
      //  window.alert('current '+pageNo +' '+' firstVisiblePage '+ firstVisiblePage +' lastVisiblePage '+lastVisiblePage);
       
        if (pageNo <= lastVisiblePage) {
          return false;
        }
        else {        
          firstVisiblePage = parseInt(firstVisiblePage)+1;
          lastVisiblePage = parseInt(lastVisiblePage)+1;
          this.container.setFirstVisiblePage(firstVisiblePage);
          this.container.setLastVisiblePage(lastVisiblePage);
          
          this.container.hidePanelRange(1, firstVisiblePage - 1);
          this.container.showPanelRange(firstVisiblePage, lastVisiblePage);
          this.container.hidePanelRange(lastVisiblePage + 1, totalPages);
        }  
    }
});

PaginationLinks.pageLink = Behavior.create({
    initialize: function(currentPage, container){
        this.pageNo = currentPage;       
        this.container = container;       
    },
    onclick: function(){        
        this.container.setCurrentPage(this.pageNo);       
    }
});

PagedPanels = Class.create({

    initialize: function(containerId, panelIdentifyingClassname, initiallyVisiblePanelIndexes, pageLeftElementId, pageRightElementId){
        this.panels = $$('#' + containerId + ' .' + panelIdentifyingClassname);
        this.displayInitiallyVisiblePanels(initiallyVisiblePanelIndexes, this.panels);
        new PagedPanels.Left($(pageLeftElementId), this);
        new PagedPanels.Right($(pageRightElementId), this);
    },
    
    visiblePanelRange: function(){
        var firstVisible, lastVisible;
        this.panels.each(function(panel, index){
            if (panel.visible()) {
                if (firstVisible != null) 
                    lastVisible = index;
                else 
                    firstVisible = index;
            }
        });
        return $A($R(firstVisible, lastVisible));
    },
    
    showPanelAtIndex: function(index){
        this.panels[index].show();
    },
    
    hidePanelAtIndex: function(index){
        this.panels[index].hide();
    },
    
    firstPanelIsVisible: function(){
        return this.panels.first().visible();
    },
    
    lastPanelIsVisible: function(){
        return this.panels.last().visible();
    },
    
    displayInitiallyVisiblePanels: function(initiallyVisiblePanelIndexes){
        this.panels.each(function(panel, index){
            if (initiallyVisiblePanelIndexes.include(index)) 
                panel.show();
            else 
                panel.hide();
        });
    }
});

PagedPanels.Left = Behavior.create({
    initialize: function(container){
        this.container = container;
    },
    onclick: function(){
			for (i=1;i<=4;i++) {
        if (this.container.firstPanelIsVisible()) 
            return;
        var visibleRange = this.container.visiblePanelRange();
        this.container.showPanelAtIndex(visibleRange.first() - 1);
        this.container.hidePanelAtIndex(visibleRange.last());
			}
    }
});

PagedPanels.Right = Behavior.create({
    initialize: function(container){
        this.container = container;
    },
    onclick: function(){
      for (i=1;i<=4;i++) {
        if (this.container.lastPanelIsVisible()) 
            return;
        var visibleRange = this.container.visiblePanelRange();
        this.container.hidePanelAtIndex(visibleRange.first());
        this.container.showPanelAtIndex(visibleRange.last() + 1);
      }
    }
});

function hideMinutesOnClock(){
    $('minutes_bucket').hide();
    $('clock_mins_secs').hide();
    $('clock_secs').show();
    $('countDownClockSpan').removeClassName('time');
    $('countDownClockSpan').addClassName('time_sec');
    $('pageHeader_table').removeClassName('pageHeader_gen_bk');
    $('pageHeader_table').addClassName('pageHeader_rate_bk');
    $('pageHeader_table_cell1').removeClassName('pageHeader_table_cell1_gen');
    $('pageHeader_table_cell1').addClassName('pageHeader_table_cell1_rate');
    $('pageHeader_table_cell2').removeClassName('pageHeader_table_cell2_gen');
    $('pageHeader_table_cell2').addClassName('pageHeader_table_cell2_rate');
}

function showMinutesOnClock(){
    $('minutes_bucket').show();
    $('clock_mins_secs').show();
    $('clock_secs').hide();
    $('countDownClockSpan').removeClassName('time_sec');
    $('countDownClockSpan').addClassName('time');
    $('pageHeader_table').removeClassName('pageHeader_rate_bk');
    $('pageHeader_table').addClassName('pageHeader_gen_bk');
    $('pageHeader_table_cell1').removeClassName('pageHeader_table_cell1_rate');
    $('pageHeader_table_cell1').addClassName('pageHeader_table_cell1_gen');
    $('pageHeader_table_cell2').removeClassName('pageHeader_table_cell2_rate');
    $('pageHeader_table_cell2').addClassName('pageHeader_table_cell2_gen');
}

function hideClock(){
    $('countDownClockSpan').hide();
    $('pageHeader_table').removeClassName('pageHeader_gen_bk');
    $('pageHeader_table').removeClassName('pageHeader_rate_bk');
    $('pageHeader_table').addClassName('pageHeader_review_bk');
    $('pageHeader_table_cell2').removeClassName('pageHeader_table_cell2_rate');
    $('pageHeader_table_cell2').addClassName('pageHeader_table_cell2_review');
}

function removeClassNames(e){
    e.classNames().each(function(item){
        e.removeClassName(item);
    });
}

function showClock(){
    $('countDownClockSpan').show();
    $('pageHeader_table').removeClassName('pageHeader_review_bk');
    $('pageHeader_table').removeClassName('pageHeader_rate_bk');
    $('pageHeader_table').addClassName('pageHeader_gen_bk');
}

function changeHeaderImage(src, alt, width, height){
    $('pageHeaderImage').src = src;
    $('pageHeaderImage').alt = alt;
    $('pageHeaderImage').width = width;
    $('pageHeaderImage').height = height;
    $('pageHeaderText').update('');
}

function changeHeaderImageAndText(src, alt, width, height, text, oldClass, newClass){
    $('pageHeaderImage').src = src;
    $('pageHeaderImage').alt = alt;
    $('pageHeaderImage').width = width;
    $('pageHeaderImage').height = height;
    if (oldClass != null) 
        $('pageHeaderText').removeClassName(oldClass)
    $('pageHeaderText').addClassName(newClass).update(text);
}

function hideMenu() {
  $('info_menu').hide();
	$('report_error').show();
}

function updateCheckInstatus(){
    if (siteClock.seconds > 240) {
        $('checkInStatus').src = '/web_images/members/buttons/check_in_open.gif';
    }
    else 
        if (siteClock.seconds > 120) {
            $('checkInStatus').src = '/web_images/members/buttons/check_in_last_call.gif';
        }
        else 
            if (siteClock.seconds > 0) {
                $('checkInStatus').src = '/web_images/members/buttons/check_in_closing.gif';
            }
}

function openPopupWindow(strURL, strType, strHeight, strWidth, strTop, strLeft){
    var positionStr = ',';
    if (strTop != null && strLeft != null) 
        positionStr += 'left=' + strLeft + ',top=' + strTop;
    else 
        positionStr += 'left=150,top=120';
    
    var strOptions = "";
    
    if (strType == "console") 
        strOptions = "scrollbars,height=" + strHeight + ",width=" + strWidth;
    
    if (strType == "fixed") 
        strOptions = "status,height=" + strHeight + ",width=" + strWidth;
    
    if (strType == "elastic") 
        strOptions = "scrollbars,resizable,height=" + strHeight + ",width=" + strWidth;
    
    strOptions = strOptions + positionStr;
    popUpWindow = window.open(strURL, 'popUpWindow', strOptions);
    popUpWindow.focus();
}

function openFullWindow(aURL, aWinName){
    var wOpen;
    var sOptions;
    
    sOptions = 'status=yes,menubar=yes,scrollbars=yes,toolbar=yes,location=yes,resizable=yes,toolbar=yes';
    sOptions = sOptions + ',width=' + (screen.availWidth).toString();
    sOptions = sOptions + ',height=' + (screen.availHeight).toString();
    sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';
    wOpen = window.open(aURL, aWinName, sOptions);
		wOpen.focus();
}

function updateParentWindow(url) {
	if (window.opener != null) {
	 window.opener.document.location = url;
   window.opener.focus();
	 return false;
	}
	else
	  return true; 
}

/**
 * Returns the value of the selected radio button in the radio group, null if
 * none are selected, and false if the button group doesn't exist
 *
 * @param {radio Object} or {radio id} el
 * OR
 * @param {form Object} or {form id} el
 * @param {radio group name} radioGroup
 */
function $RF(el, radioGroup){
    if ($(el).type && $(el).type.toLowerCase() == 'radio') {
        var radioGroup = $(el).name;
        var el = $(el).form;
    }
    else 
        if ($(el).tagName.toLowerCase() != 'form') {
            return false;
        }
    
    var checked = $(el).getInputs('radio', radioGroup).find(function(re){
        return re.checked;
    });
    return (checked) ? $F(checked) : null;
}

function checkUnCheckAll(c, cb){
    if (c.checked == true) {
        cb.each(function(item){
            item.checked = true;
        });
    }
    else {
        cb.each(function(item){
            item.checked = false;
        });
    }
}

function showDeleteDate(){
    $('blockDate').hide();
    $('deleteDate').show();
}

function toggleBox(divId, show){
    if (show) 
        $(divId).show();
    else 
        $(divId).hide();
}

function setAsInnerHtml(sourceDivId, destDivId, show){
  $(destDivId).innerHTML = $(sourceDivId).innerHTML;
  toggleBox(destDivId, show);
}

function clearText(thefield){
    if (thefield.defaultValue == thefield.value) 
        thefield.value = ""
    
}

//Mouse Over Image Swap effect 
function MM_swapImgRestore(){ //v3.0
    var i, x, a = document.MM_sr;
    for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) 
        x.src = x.oSrc;
}

function MM_preloadImages(){ //v3.0
    var d = document;
    if (d.images) {
        if (!d.MM_p) 
            d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
        for (i = 0; i < a.length; i++) 
            if (a[i].indexOf("#") != 0) {
                d.MM_p[j] = new Image;
                d.MM_p[j++].src = a[i];
            }
    }
}

function MM_findObj(n, d){ //v4.01
    var p, i, x;
    if (!d) 
        d = document;
    if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document;
        n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) 
        x = d.all[n];
    for (i = 0; !x && i < d.forms.length; i++) 
        x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) 
        x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) 
        x = d.getElementById(n);
    return x;
}

function MM_swapImage(){ //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments;
    document.MM_sr = new Array;
    for (i = 0; i < (a.length - 2); i += 3) 
        if ((x = MM_findObj(a[i])) != null) {
            document.MM_sr[j++] = x;
            if (!x.oSrc) 
                x.oSrc = x.src;
            x.src = a[i + 2];
        }
}

function validateNickname(nickname) {
	var patt = new RegExp("[^\\w.]");
  if (nickname == 'Must contain from 6 to 14 characters') 
	  return false;
	if (nickname.length > 14 || nickname.length < 6) {
	  return false;  
	}
	if (patt.test(nickname)) {
		return false;
	}
  else 
	  return true;
}

function showNicknameAvailability(available,nickname) {
	if (available == 1) {
		$('nickname_taken').hide();
		$('nickname_avialable').show();
	}
	else {
    $('nickname_avialable').hide();
    $('nickname_taken').show();
	}
}

function log(msg) {
   var log = $('log');
   if(log) {
     log.innerHTML = log.innerHTML + '<br/>' + msg;   
  }
}

function disableForm(controlId) {
    $(controlId).disabled = true;     
    $('form').submit();
}
  
function disablelinks(){
    var linkArray = new Array();
    var objLink = document.links;
    for(var i=0;i < objLink.length;i++) {
        linkArray[i] = objLink[i].href.toString();
        if (objLink[i].id=='logout_link') {
        }
        else {
            objLink[i].disabled=true;
            objLink[i].href='#';
            objLink[i].onclick = new Function("return false;");
        }
    }
}

function disablelink(linkId){
    var linkArray = new Array();
    var objLink = document.links;
    for(var i=0;i < objLink.length;i++) {
        linkArray[i] = objLink[i].href.toString();
        if (objLink[i].id==linkId) {
            objLink[i].disabled=true;
            objLink[i].href='#';
            objLink[i].onclick = new Function("return false;");
        }
    }
}

function gmtToLocal(gmt) {
  var currentTime = new Date();
  var currentTimezone = currentTime.getTimezoneOffset();
  var now = gmt - currentTimezone;
  if (now < 0) 
    now = 1440 + now;
  else if ( now > 1440)  
    now = now - 1440;
	return now;
}

function convertGMTDateToLocal(_gmt) {
  var local = new Date(_gmt);
	return local.format('h.MMtt dddd mmmm d yyyy');
}

function convertGMTToLocal(gmt,elementId) {
  var currentTime = new Date();
  var currentTimezone = currentTime.getTimezoneOffset();
  var now = gmt - currentTimezone;
  if (now < 0) 
    now = 1440 + now;
	else if ( now > 1440)  
		now = now - 1440;
	$(elementId).innerHTML = formatMins(now);
}

function formatMins(min) {
	var period = 'am';
  var hrs = Math.floor(min / 60);
  min = min % 60;
	if (hrs >= 12) {
	  period = 'pm' 
	  if (hrs > 12)
		  hrs = hrs - 12;	
	}
	if (min < 10)
	  min = '0'+min;
		
  return hrs+':'+min+''+period;
}

function registerRegoLables() {
  registerLables('username','Create a new Skyecandy Nickname','skypename','We need your correct Skype name!','password_placeholder','Must contain at least 6 characters','emailAddress','Must be a real email address','emailAddressCon','Retype Email');
}

function registerSkypenameErrorLables() {
  registerLables('skypename','Find this in Skype menu  > Account');
}	

function markFieldsAsError(fields) {
  fields.each(function(item) {
    $(item).addClassName('t-error');
  });	
} 

function updateStats(stats) {
	$('inm').innerHTML = stats.inm;
	$('inf').innerHTML = stats.inf;
	//$('onm').innerHTML = stats.onm;
	//$('onf').innerHTML = stats.onf;
	$('inmage').innerHTML = stats.inmage;
	$('infage').innerHTML = stats.infage;
	//$('onmage').innerHTML = stats.onmage;
	//$('onfage').innerHTML = stats.onfage;
}

function isOnlyDigits(field) {
	return /^\d+$/.test(field);
}

function setCookie(name,value) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+90);
	document.cookie=name+ "=" +escape(value)+";expires="+exdate.toGMTString();
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function showHideYouTubeVideo(){
	$('you_tube_img').hide();
	$('you_tube_video').show();
}

HideOnClick = Behavior.create({
    initialize: function(ele) {
        this.ele = $(ele);
    },
    
    onclick: function(evt) {
      this.ele.hide();
    }
});
