                 
var tempSavingClassName = new Array();
function disableInputField(fieldname){
  var object = document.getElementById(fieldname);
  if(object)
  {
    if(object.className != '') tempSavingClassName[fieldname] = object.className;
    object.className = "disabled";
    object.disabled = true;
  }
}

function enableInputField(fieldname){
  var object = document.getElementById(fieldname);
  var tmpClassName = tempSavingClassName[fieldname];
  if(object)   
  {
    if(tmpClassName){
      object.className = tmpClassName;
    }else{
      object.className = '';
    }    
    object.disabled = false;  
  }
}

function rowOverEffect(object) {
  if (object.className == 'moduleRow') object.className = 'moduleRowOver';
}

function rowOutEffect(object) {
  if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}

function selectRow(object){
  if (object.className != 'moduleRowSelected') object.className = 'moduleRowSelected';
  else if (object.className == 'moduleRowSelected') object.className = 'moduleRow';
}

function checkBox(object) {
  document.account_newsletter.elements[object].checked = !document.account_newsletter.elements[object].checked;
}

function ahref(link){
  window.location.href = link;
}

function resize(x) {
  var i;
  i=x;
  if (navigator.appName == 'Netscape') i=40;
  if (document.images[0]) window.resizeTo(document.images[0].width +30, document.images[0].height+140-i);
  self.focus();
}

function popupWindow(url, width , height) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width='+width+',height='+height+',screenX=150,screenY=150,top=150,left=150');
}

function popupScrolWindow(url, width , height) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width='+width+',height='+height+',screenX=150,screenY=150,top=150,left=150');
}

var submitter = null;
function submitFunction() {
  submitter = 1;
}

//MS3 Compatibility
function pageLinkPrompt(url,val,current,max)
{
  if (page = parseInt(prompt("Enter a page number between 1 and "+max,val)))
    if ( page == current)
      return false;
    else if (page > max)
      return formSubmit('',url+'&page='+max);
    else if (page < 1)
      return formSubmit('',url+'&page=1');
    else
      return formSubmit('',url+'&page='+page);
  else
    return false;
}

function formSubmit(form,action,target)
{
  //alert('form.name = '+form.name+' form.action = '+action+' form.target = '+target);
  if (action != null && action != '')
    form.action = action;
  if (target != null && target != '') {
    form.target = target;
    popup(form.action,form.target);
  }
  
  if ((form == null || form == '' || form == 'undefined') && action != null & action != '')
    document.location.href = action;
  else
    form.submit();
  return false;
}

popups = new Array();

function popup(url,name,args)
{
  if (url == null || url == '')
    exit;
  if (name == null || name == '')
    name = '_popup';
  if (args == null || args == '') {
    var height = 400;
    var width  = 600;
    var top    = (screen.height) ? (screen.height-height)/2 : 0;
    var left   = (screen.width) ? (screen.width-width)/2 : 0;
    var args = 'toolbar=0,status,location=0,scrollbars,resizable,width='+width+',height='+height+',top='+top+',left='+left;
  }
  
  if ( typeof( popups[name] ) != "object" ) {
    popups[name] = window.open(url,name,args);
    if (!popups[name].opener)
      popups[name].opener = self;
  } else {
    if (!popups[name].closed) {
      popups[name].location.href = url;
    } else {
      popups[name] = window.open(url, name,args);
      if (!popups[name].opener)
        popups[name].opener = self;
    }
  }

  if (window.focus)
    popups[name].focus();
  return false;
}


function hoverIE(menu) {
  var MENU = document.getElementById(menu); 
  
  if(LI = getFirstElementWithTagname(MENU,'UL')){
    LI = LI.firstChild;
    do {
      LI.onmouseover=displayMenuDropDown; LI.onmouseout=hideMenuDropDown;
      LI = LI.nextSibling;
    }    
    while(LI);
  }
}

function getFirstElementWithTagname(OBJ, TAG) {  
  ELEMENTS = OBJ.getElementsByTagName(TAG);
  if(ELEMENTS[0]) return ELEMENTS[0];
  else return false;
}

function displayMenuDropDown() {            
 if(A = getFirstElementWithTagname(this, 'A')){
  A.className = 'active'; 
 }
  if(UL = getFirstElementWithTagname(this, 'UL')){
    UL.style.display = "block";
  }
}
function hideMenuDropDown() {
 if(A = getFirstElementWithTagname(this, 'A')){
  A.className = null; 
 }
  if(UL = getFirstElementWithTagname(this, 'UL')){
    UL.style.display = "none";
  }
}
  
function toggleAuto(target ) {
  if(typeof(target) == 'string')
    target = document.getElementById(target);   
                
  if (target.style.display == "none"){
    if(arguments[1]) display = arguments[1];
    else display = "block";      
   
    target.style.display = display;
  } else {
    target.style.display = "none";
  }
}

/* Pattern fot template placeholder %=varname% */
function removeCDATA(text){
  return text.substring(9,text.length - 3);
}
    
var ToolTip = Class.create({
    /*
    * target, string: Prototype selector
    * class, string: Stylesheet class for the tooltip
    * hideOn, [mouseout, click]: Open when...
    * showOn, [mouseover, mousemove, click]: Open when...
    * valign, [top,bottom]: Vertical align
    * halign, [left,center,right]: Horizontal align
    * content, string: Assign default content
    */
    initialize: function() {
      this.timeout = false;
      
      this.options = $H({target: false, 'class': 'tooltip', hideOn: 'mouseout', showOn: 'mouseover', valign: 'bottom', halign: 'right', content: false, title: false, yoffset: 20, xoffset:20, delay:0.1});
      if(arguments[0] && Object.isHash(arguments[0])){
        this.options.update(arguments[0]);
      }      
      this.setup = false;
      if(this.options.get('target') != false){
        Event.observe(window, 'load', this.observeSelector.bindAsEventListener(this)); 
      }
    },
    dosetup: function(){
           if(!Object.isElement($('fileTooltipCSS'))){
        $$('head')[0].appendChild(new Element('link', {'id': 'fileTooltipCSS','rel': 'stylesheet', 'type': 'text/css', 'href': 'resource/css?t=default&s=tooltip&m=screen;'}));
      }

      //create tooltip container
      this.tooltip = new Element('div', {'class': this.options.get('class'),'style': 'position:absolute;'}).hide();

      this.top = new Element('div', {'class': 'top'});
      if(this.options.get('hideOn') == 'click'){
        this.closeButton = new Element('div',{'class': 'closeButton'});
        this.closeButton.observe('click', this.hide.bindAsEventListener(this,this.closeButton));
        this.top.appendChild(this.closeButton);
      }
      if(this.options.get('title') != false){
        this.title = new Element('h6').update(this.options.get('title'));
        this.top.appendChild(this.title);
      }
      this.tooltip.appendChild(this.top);
      
      this.content = new Element('div', {'class': 'inner'});
      if(this.options.get('content') != false)
        this.content.update(this.options.get('content'));
      this.tooltip.appendChild(this.content);
      
      this.bottom = new Element('div', {'class': 'bottom'});
      this.tooltip.appendChild(this.bottom);
      $$('body')[0].appendChild(this.tooltip);      

      this.setup = true;
    },
    observeSelector: function(){
      if(Object.isElement(this.options.get('target')))
        var target = this.options.get('target');
      else
        var target = $$(this.options.get('target'));
        
      if(this.options.get('showOn') != false)
        target.each(function(Element){this.observe(Element)}.bind(this));            
    },
    update: function(content){
      this.content.update(content);
    },
    show: function(event, element) {
      if(!this.setup) this.dosetup();
      else if(this.tooltip.visible()) return false;
      
      //remove attibute title and alt
      if(element.readAttribute('title')){
        element.ttip = unescape(element.readAttribute('title'));
        element.removeAttribute('title'); 
        element.select('img').each(function(child){
          child.removeAttribute("alt");
          child.removeAttribute("title");
        });    
      }
      //remove lin8k when sticky
      if(this.options.get('showOn') == 'click' && element.readAttribute('href')){
        element.removeAttribute("href"); 
        element.style.cursor = "pointer";
      }
      
      if(this.myUpdate){
        this.myUpdate();
      }else if(element.ttip){
        this.update(element.ttip);
      }

      //update tooltip content 
      position = element.cumulativeOffset(); 
      this.locate(position.left, position.top);
      
      //this.tooltip.show(); 
      this.tooltip.show();  
    },
    hide: function(){
      /*if(this.timeout) window.clearTimeout(this.timeout);*/
      this.tooltip.hide();      
    },
    mousefollow: function(event) {
      this.locate(Event.pointerX(event), Event.pointerY(event));
    },
    locate: function(x, y) {
      var width = this.tooltip.getWidth();
      var height = this.tooltip.getHeight();
      var xx = x+this.options.get('xoffset');
      var yy = y+this.options.get('yoffset');
      if(this.options.get('halign') == 'center' && (x > width/2)){
        xx = x-(width/2);
      }

      this.tooltip.style.left = xx+'px';
      this.tooltip.style.top = yy+'px';
    },
    observe: function(element){
      if(this.options.get('showOn') == 'mouseover' || this.options.get('showOn') == 'mousemove') element.observe( 'mouseover', this.show.bindAsEventListener(this,element));
      
      if(this.options.get('showOn') == 'mousemove')  element.observe( 'mousemove', this.locate.bindAsEventListener(this,element));
      
      if(this.options.get('showOn') == 'click')  element.observe( 'click', this.show.bindAsEventListener(this,element));
      else if(this.options.get('hideOn') == 'mouseout') element.observe('mouseout', this.hide.bindAsEventListener(this,element));
      
    }
  });

var TTip = new ToolTip($H({target: '.ttip'}));

var CheckFormQuickfind = Class.create({
  initialize: function() {
    Event.observe(window, 'load', this.setup.bindAsEventListener(this));
  },
  setup: function(){
    this.fldKeywords = $('frmQuickfindKeywords');
    this.form = $('frmQuickfind');
    
    if(Object.isElement(this.form)){      
      this.fldKeywords.value = this.fldKeywords.title;
      this.title = this.fldKeywords.title;
      this.fldKeywords.title = '';      

      $('frmQuickfindKeywords').onfocus = function(Event){
        if(this.fldKeywords.value == this.title) this.fldKeywords.value = '';                              
      }.bind(this);
    
      $('frmQuickfind').onsubmit = function(Event){
        if(this.fldKeywords.value == this.title || this.fldKeywords.value == ''){
          ahref(this.form.action);
          return false;
        }                  
      }.bind(this);    
    }
  }
});
new CheckFormQuickfind();

