﻿// JScript File

    var tempX = 0;
    var tempY = 0;
    var firefox=document.getElementById&&!document.all;
        
    
    function getTranslationString(key)
    {
        var item = ge("translation-" + key);
        
        if(item)
        {
            return item.value;
        }
        
        return "";
    }
    
    function ge()
    {
      var ea;
      for( var i = 0; i < arguments.length; i++ ) {
        var e = arguments[i];
        if( typeof e == 'string' )
          e = document.getElementById(e);
        if( arguments.length == 1 )
          return e;
        if( !ea )
          ea = new Array();
        ea[ea.length] = e;
      }
      return ea;
    }
    
    function show()
    {
      for( var i = 0; i < arguments.length; i++ ) 
      {
        var element = ge(arguments[i]);        
        if (element && element.style) element.style.display = '';
      }
      return false;
    }

    function hide()
    {
      for( var i = 0; i < arguments.length; i++ ) {
        var element = ge(arguments[i]);
        if (element && element.style) element.style.display = 'none';
      }
      return false;
    }
    
    function remove_node(node) 
    {
      if (node.removeNode)
        node.removeNode(true);
      else {
        for (var i=node.childNodes.length-1; i>=0; i--)
          remove_node(node.childNodes[i]);
        node.parentNode.removeChild(node);
      }
      return null;
    }
    
// === Event Info Access ===

var KEYS = { BACKSPACE: 8,
             TAB:       9,
             RETURN:   13,
             ESC:      27,             
             LEFT:     37,
             UP:       38,             
             RIGHT:    39,             
             DOWN:     40,
             DELETE:   46 };

function mouseX(event)
{
  return event.pageX || (event.clientX +
    (document.documentElement.scrollLeft || document.body.scrollLeft));
}

function mouseY(event)
{
  return event.pageY || (event.clientY +
    (document.documentElement.scrollTop || document.body.scrollTop));
}

function pageScrollX()
{
  return document.body.scrollLeft || document.documentElement.scrollLeft;
}

function pageScrollY()
{
  return document.body.scrollTop || document.documentElement.scrollTop;
}

function elementX(obj)
{
  var curleft = 0;
  if (obj.offsetParent) {
    while (obj.offsetParent) {
      curleft += obj.offsetLeft;
      obj = obj.offsetParent;
    }
  }
  else if (obj.x)
    curleft += obj.x;
  return curleft;
}

function elementY(obj)
{
  var curtop = 0;
  if(obj.offsetParent) {
    while (obj.offsetParent) {
      curtop += obj.offsetTop;
      obj = obj.offsetParent;
    }
  }
  else if (obj.y)
    curtop += obj.y;
  return curtop;
}

// === Onload Registry ===

function onloadRegister(handler) {
  if (window.onload) {
    var old=window.onload;
    window.onload=function() { old(); handler(); };
  }
  else {
    window.onload=handler;
  }
}

// === Event Attaching ===
// (see: http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html)

function addEvent(obj, type, fn, name_hash)
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
                obj["e"+type+fn+name_hash] = fn;
		obj[type+fn+name_hash] = function() { obj["e"+type+fn+name_hash]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn+name_hash] );
          
	}
}


// why name_hash? So you can use the same function and pass different name_hashes and ie won't get confused
function removeEvent(obj, type, fn, name_hash)
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn+name_hash] );
		obj[type+fn+name_hash] = null;
		obj["e"+type+fn+name_hash] = null;
	}
}    
    


    function OpenDialog(dialogContent)
    {       
        /*     
        switch(dialogContent)
        {
            case 'realMoney':
            {

                HideAllPopupContentsButThis(document.getElementById('rmContent'));
                break;
            }
        } */
        
        popupXOffset = 15;
        popupYOffset = -340;        
        
        currentMovingPopup = document.getElementById(dialogContent);
        
        document.onmousemove = getMouseXY;

    }
    
    function HideAllPopupContentsButThis(c)
    {        
               
        document.getElementById('rmContent').style.display = 'none';        
        
        c.style.display = 'block';
    }
            


    function createCookie(name,value,days) 
    {
        //eraseCookie(name);
        
	    if (days) 
	    {
		    var date = new Date();
		    date.setTime(date.getTime()+(days*24*60*60*1000));
		    var expires = "; expires="+date.toGMTString();
	    }
	    else var expires = "";
	    document.cookie = name+"="+value+expires+"; path=/";
    }

    function readCookie(name) 
    {
	    var nameEQ = name + "=";
	    var ca = document.cookie.split(';');
	    for(var i=0;i < ca.length;i++) 
	    {
		    var c = ca[i];
		    while (c.charAt(0)==' ') c = c.substring(1,c.length);
		    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	    }
	    return null;
    }

    function eraseCookie(name) 
    {
	    createCookie(name,"",-1);
    }
    
    
// === String Utilities ===

function htmlspecialchars(text) {
  return text ? text.toString().replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#039;').replace(/</g, '&lt;').replace(/>/g, '&gt;') : '';
}

function escape_js_quotes(text) {
  if (!text) {
    return;
  }

  return text.replace(/\\/g, '\\\\').replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/"/g, '\\x22').replace(/'/g, '\\\'').replace(/</g, '\\x3c').replace(/>/g, '\\x3e').replace(/&/g, '\\x26');
}

function trim(str) {
  var delim = arguments.length > 1 ? arguments[1] : ' ';
  for (var i=0, c=str.length-delim.length; i<=c; i+=delim.length) {
    if (str.substring(i, i + delim.length) != delim) {
      break;
    }
  }

  for (var j=str.length, c=Math.max(i, delim.length - 1); j>c; j-=delim.length) {
    if (str.substring(j - delim.length, j) != delim) {
      break;
    }
  }

  return str.substring(i, j);
}

// === URI Handling ===

function escapeURI(u)
{
    if(encodeURIComponent) {
        return encodeURIComponent(u);
    }
    if(escape) {
        return escape(u);
    }
}

function goURI(href) {
  window.location.href = href;
}

function is_email(email) {
  return /^[\w!.%+]+@[\w]+(?:\.[\w]+)+$/.test(email);
}    

// === Dropdown Menus ===

/* functionality for an optional drop down menu (example: drop downs in the 
nav.) It consists of a link, an arrow, and a menu which appears when the
arrow is clicked. Pass this function an arrow, link, and menu element 
 
arrow_class and arrow_old_class is optional
*/
function optional_drop_down_menu(arrow, link, menu, event, arrow_class, arrow_old_class)
{

   

  if (menu.style.display=='none') {
    menu.style.display='block';
    var old_arrow_classname = arrow_old_class ? arrow_old_class : arrow.className;

    // Lock In Button Pressed State   
    if (link) {
      //link.className = 'active';          
    }

    //arrow.className = arrow_class ? arrow_class : 'global_menu_arrow_active';   

    var justChanged = true;

    // prevent selects from showing through menu in ie6
    var shim = ge(menu.id + '_iframe');
    if (shim) {
      shim.style.top = menu.style.top;
      shim.style.right = menu.style.right;
      shim.style.display = 'block';
      shim.style.width = (menu.offsetWidth +2) + 'px';
      shim.style.height = (menu.offsetHeight +2) + 'px';
    }
    
    
    
    menu.offclick = function(e) {
    
      //  debugger;
    
      if (!justChanged) {
        // Hide dropdown                                                                       
        hide(this);
      
        // Restore Normal link and hover class                                           
        if (link) {
          link.className = '';
        }
        arrow.className = old_arrow_classname;
      
        var shim = ge(menu.id + '_iframe');
        if (shim) {
          shim.style.display = 'none';
          shim.style.width = menu.offsetWidth + 'px';
          shim.style.height = menu.offsetHeight + 'px';
        }

        removeEventBase(document, 'click', this.offclick, menu.id);
      } else {
        justChanged = false;
      }
      
      
    }.bind(menu);
    

    addEventBase(document, 'click', menu.offclick, menu.id);
    
  }
  return false;
}


/* special case for the app_switcher mneu, we need to set its position since it's right-aligned */
function position_app_switcher() {
  var switcher = ge('app_switcher');
  var menu = ge('app_switcher_menu');
  menu.style.top = (switcher.offsetHeight - 1) + 'px';
  menu.style.right = '0px';
}

// === Event Attaching ===
// (see: http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html)

function addEventBase(obj, type, fn, name_hash)
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
                obj["e"+type+fn+name_hash] = fn;
		obj[type+fn+name_hash] = function() { obj["e"+type+fn+name_hash]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn+name_hash] );
          
	}
}


// why name_hash? So you can use the same function and pass different name_hashes and ie won't get confused
function removeEventBase(obj, type, fn, name_hash)
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn+name_hash] );
		obj[type+fn+name_hash] = null;
		obj["e"+type+fn+name_hash] = null;
	}
}

//
// OOP implementation
function __super_class(obj) {
  this.__super=obj;
  this.__parent=obj.prototype.parent;
}
__super_class.prototype.__super_method=function(method, pointer) {
  var __pointer=pointer;
  this[method]=function() {
    var __parent=this.__context.parent;
    this.__context.__parents.push(__parent);
    this.__context.parent=__parent ? __parent.__parent : null;
    var __ret=__pointer.apply(this.__context, arguments);
    this.__context.parent=__parent;
    this.__context.__parents.pop();
    __parent=null;
    return __ret;
  };
}
__super_class.prototype.__overridden_method=function(method, pointer) {
  var __pointer=pointer;
  return function() {
    if ((typeof this.__parents=='undefined') || !this.__parents.length) {
      return __pointer.apply(this, arguments);
    }
    else {
      var __parent=this.parent;
      this.parent=this.__parents[0];
      var __ret=__pointer.apply(this, arguments);
      this.parent=__parent;
      __parent=null;
      return __ret;
    }
  }
}
__super_class.prototype.construct=function(context) {
  this.__context=context;
  this.__context.__parents=[];
  if (typeof this.__context.__prototype.__overridden=='undefined') {
    this.__context.__prototype.__overridden=true;
    for (var i in this.__context.__prototype) {
      if ((typeof this.__context.__prototype[i]=='function') && this.__context.__prototype[i]!=this.__super.prototype[i]) {
        this.__context.__prototype[i]=this.__overridden_method(i, this.__context.__prototype[i]);
      }
    }
  }
  var a=new Array();
  for (var i=1; i<arguments.length; i++) {
    a.push(arguments[i]);
  }
  this.__context.parent=this.__parent;
  var __ret=this.__super.apply(context, a);
  this.__context.parent=this;
  return __ret;
}
Function.prototype.bind=function(context) {
  var __method=this;
  return function() {
    return __method.apply(context, arguments);
  }
}
Function.prototype.extend=function(obj) {
  this.prototype.parent=new __super_class(obj);
  this.prototype.__prototype=this.prototype;
  for (var i in obj.prototype) {
    if (typeof obj.prototype[i]=='function') {
      this.prototype[i]=obj.prototype[i];
      this.prototype.parent.__super_method(i, obj.prototype[i]);
    }
    else if (i!='parent') {
      this.prototype[i]=obj.prototype[i];
    }
  }
}
