//this file depends on YUI, it could be served directly from de YAHOO servers



function Trace(msg) {
  $('trace').innerHTML += msg + "<br />";
}


String.prototype.endsWith = function(t, i) { if (i==false) { return (t == this.substring(this.length - t.length)); } else { return (t.toLowerCase() == this.substring(this.length - t.length).toLowerCase()); } }

String.replaceAll = function(str, replacements)
{
  for (i = 0; i < replacements.length; i++) 
  {
    var idx = str.indexOf(replacements[i][0]);
    
    while (idx > -1) 
    {
      str = str.replace(replacements[i][0], replacements[i][1]);
      idx = str.indexOf(replacements[i][0]);
    }
  }
  
  return str;
};

String.format = function(s)
{
  for (var i = 1; i < arguments.length; i++) 
  {
    //s = s.replace("{" + (i -1) + "}", arguments[i]);
    s = String.replaceAll(s, [["{" + (i - 1) + "}", arguments[i]]]);
  }
  
  return s;
};


/*
 Created By Roy Riojas Montenegro
 */
var $YUD = null; //YAHOO.util.Dom
var $YUE = null; //YAHOO.util.Event
//Shortcuts for the YAHOO namespaces
if (YAHOO) 
{
  $YUD = YAHOO.util.Dom;
  $YUE = YAHOO.util.Event;
}

/**
 *  wrapper for the get function of the YAHOO Object
 */
function $(str_id)
{
  if (str_id == window) return window;
  return $YUD.get(str_id);
}

/**
 * Wrapper for the getElementsByClassName function of the YAHOO object
 * @param {Object} aFunction
 */
function $ByClass(str_className, str_parentId, str_tag)
{
  if (!str_tag) 
    str_tag = null;
  
  return $YUD.getElementsByClassName(str_className, str_tag, $(str_parentId));
}

/**
 * Wrapper for the onDOMReady function of the YAHOO object
 * @param {Object} aFunction
 */
function $ready(aFunction)
{
 
  if (!$YUE.DOMReady) 
    $YUE.onDOMReady(aFunction);  
  else {
    aFunction();
  } 
  if (typeof (Sys) != 'undefined') {   
    $__AddFunctionToPageLoadEvent(aFunction);
  }
}

function $__AddFunctionToPageLoadEvent(aFunction) {
  var pLoadEvent = function (sender, args) {
    var updatedPanels = args.get_panelsUpdated();    
    if (updatedPanels && updatedPanels.length > 0) {
      
      aFunction();
    }
  }  
  Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pLoadEvent);
}

/*MOZILLA OUTER_HTML*/


if (typeof(HTMLElement) != 'undefined') 
{
  var _emptyTags = 
  {
    "IMG": true,
    "BR": true,
    "INPUT": true,
    "META": true,
    "LINK": true,
    "PARAM": true,
    "HR": true
  };
  
  HTMLElement.prototype.__defineGetter__("outerHTML", function()
  {
    var attrs = this.attributes;
    var str = "<" + this.tagName;
    for (var i = 0; i < attrs.length; i++) 
      str += " " + attrs[i].name + "=\"" + attrs[i].value + "\"";
    
    if (_emptyTags[this.tagName]) 
      return str + ">";
    
    return str + ">" + this.innerHTML + "</" + this.tagName + ">";
  });
  
  HTMLElement.prototype.__defineSetter__("outerHTML", function(sHTML)
  {
    var r = this.ownerDocument.createRange();
    r.setStartBefore(this);
    var df = r.createContextualFragment(sHTML);
    this.parentNode.replaceChild(df, this);
  });
  
}

function xStopEvent(evt)
{
  try 
  {
    $YUE.stopEvent(evt);
  } 
  catch (e) 
  {
  
  }
}

/**
 *
 * @param {Object} e
 * @param {Object} eT
 * @param {Object} eL
 * @param {Object} cap
 */
function $ale(e, eT, eL, cap)
{
  if (!(e = $(e))) 
    return;
  
  eT = eT.toLowerCase();
  
  var eh = 'e.on' + eT + '=eL';
  
  if (e.addEventListener) 
    e.addEventListener(eT, eL, cap);
  else 
    if (e.attachEvent) 
      e.attachEvent('on' + eT, eL);
    else 
      eval(eh);
}

function $rle(e, eT, eL, cap)
{
  if (!(e = $(e))) 
    return;
  
  eT = eT.toLowerCase();
  
  if (e == window) 
  {
    if (eT == 'resize' && e.xREL) 
    {
      e.xREL = null;
      return;
    }
    
    if (eT == 'scroll' && e.xSEL) 
    {
      e.xSEL = null;
      return;
    }
  }
  
  if (e.removeEventListener) 
    e.removeEventListener(eT, eL, cap || false);
  else 
    if (e.detachEvent) 
      e.detachEvent('on' + eT, eL);
    else 
      e['on' + eT] = null;
}


function AvoidInstantCache()
{
  var today = new Date();
  var month = today.getMonth() + 1;
  var day = today.getDate();
  var year = today.getFullYear();
  
  var semilla = month + day + year + today.getHours() + today.getMinutes() + today.getSeconds();
  
  return semilla;
};
function GetNoCacheUrl(str_url)
{
  var token = (str_url.indexOf("?") > -1) ? "&" : "?";
  
  str_url += String.format("{0}xnocache={1}", token, AvoidInstantCache()); //token + 'xnocache=' + this.AvoidInstantCache();    
  return str_url;
};

function $LoadScript(file, is_relative_, pfn_callback)
{
  if (is_relative_) 
    file = YAHOO.Global.Config.PathToScript + file;
  //Check if the Script is already Loaded
  var doc_scripts = document.getElementsByTagName('script');
  if (doc_scripts && doc_scripts.length > 0) 
  {
    for (var xi = 0; xi < doc_scripts.length; xi++) 
    {
      if (doc_scripts[xi].src) 
      {
        if (doc_scripts[xi].src.indexOf(file) > -1) 
        {
          if (typeof(pfn_callback) == 'function') 
          {
            pfn_callback();
          }
          return;
        }
      }
    }
  }
  
  var Scripts = "";
  
  // Create script DOM element
  var script = document.createElement('script');
  script.type = 'text/javascript';
  script.src = file;
  
  
  
  // Alert when the script is loaded
  if (typeof(script.onreadystatechange) == 'undefined') // W3C
    script.onload = function()
    {
      this.onload = null;
      
      if (typeof(pfn_callback) == 'function') 
      {
        pfn_callback();
      }
    }
  else // IE
     script.onreadystatechange = function()
    {
      if (this.readyState != 'loaded' && this.readyState != 'complete') 
        return;
      
      this.onreadystatechange = null;
      
      if (typeof(pfn_callback) == 'function') 
      {
        pfn_callback();
      }
    }; // Unset onreadystatechange, leaks mem in IE
  // Add script DOM element to document tree
  document.getElementsByTagName('head')[0].appendChild(script);
}

function $LoadCSS(url_, is_relative_, media_)
{

  if (is_relative_) 
    url_ = YAHOO.Global.Config.PathToScript + url_;
  // We are preventing loading a file already loaded
  var _links = document.getElementsByTagName("link");
  if (_links && _links.length > 0) 
  {
    for (var xi = 0; xi < _links.length; xi++) 
    {
      if (_links[xi].href) 
      {
        if (_links[xi].href.indexOf(url_) > -1) 
        {
          return;
        }
      }
    }
  }
  
  // Optional parameters check
  var _media = media_ === undefined || media_ === null ? "all" : media_;
  
  var _elstyle = document.createElement("link");
  _elstyle.setAttribute("rel", "stylesheet");
  _elstyle.setAttribute("type", "text/css");
  _elstyle.setAttribute("media", _media);
  _elstyle.setAttribute("href", url_);
  
  var _head = document.getElementsByTagName("head")[0];
  _head.appendChild(_elstyle);
}

YAHOO.namespace("Global.Config");

YAHOO.Global.Config = 
{
  PathToScript: "./script_objs/"
};



function $Display(str_ele, b_visible)
{
  str_ele = $(str_ele);
  str_ele.style.display = b_visible ? "" : "none";
}

/*xEvent Init*/
function xIsNull(aVar, aDefaultValue)
{
  return (!xDef(aVar)) ? aDefaultValue : aVar;
}

// xEvent r9, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xDef()
{
  for (var i = 0; i < arguments.length; ++i) 
  {
    if (typeof(arguments[i]) == 'undefined' || arguments[i] == null) 
      return false;
  }
  return true;
}

function xNum()
{
  for (var i = 0; i < arguments.length; ++i) 
  {
    if (isNaN(arguments[i]) || typeof(arguments[i]) != 'number') 
      return false;
  }
  return true;
}


function xClientWidth()
{
  return YAHOO.util.Dom.getClientWidth();
}

function xClientHeight()
{
  return YAHOO.util.Dom.getClientHeight();
}

function xScrollLeft(e, bWin)
{
  var offset = 0;
  if (!xDef(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') 
  {
    var w = window;
    if (bWin && e) 
      w = e;
    if (w.document.documentElement && w.document.documentElement.scrollLeft) 
      offset = w.document.documentElement.scrollLeft;
    else 
      if (w.document.body && xDef(w.document.body.scrollLeft)) 
        offset = w.document.body.scrollLeft;
  }
  else 
  {
    e = $(e);
    if (e && xNum(e.scrollLeft)) 
      offset = e.scrollLeft;
  }
  return offset;
}

function xScrollTop(e, bWin)
{
  var offset = 0;
  if (!xDef(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') 
  {
    var w = window;
    if (bWin && e) 
      w = e;
    if (w.document.documentElement && w.document.documentElement.scrollTop) 
      offset = w.document.documentElement.scrollTop;
    else 
      if (w.document.body && xDef(w.document.body.scrollTop)) 
        offset = w.document.body.scrollTop;
  }
  else 
  {
    e = $(e);
    if (e && xNum(e.scrollTop)) 
      offset = e.scrollTop;
  }
  return offset;
}

function xPageX(e)
{
  var x = 0;
  e = $(e);
  while (e) 
  {
    if (xDef(e.offsetLeft)) 
      x += e.offsetLeft;
    e = xDef(e.offsetParent) ? e.offsetParent : null;
  }
  return x;
}

function xPageY(e)
{
  var y = 0;
  e = $(e);
  while (e) 
  {
    if (xDef(e.offsetTop)) 
      y += e.offsetTop;
    e = xDef(e.offsetParent) ? e.offsetParent : null;
  }
  return y;
}

function xEvent(evt) // object prototype
{
  var e = evt || window.event;
  
  if (!e) 
    return;
  
  if (e.type) 
    this.type = e.type;
  
  if (e.target) 
    this.target = e.target;
  else 
    if (e.srcElement) 
      this.target = e.srcElement;
  
  // Section B
  if (e.relatedTarget) 
    this.relatedTarget = e.relatedTarget;
  else 
    if (e.type == 'mouseover' && e.fromElement) 
      this.relatedTarget = e.fromElement;
    else 
      if (e.type == 'mouseout') 
        this.relatedTarget = e.toElement;
  
  // End Section B
  if (xDef(e.pageX, e.pageY)) 
  {
    this.pageX = e.pageX;
    this.pageY = e.pageY;
  }
  else 
    if (xDef(e.clientX, e.clientY)) 
    {
      this.pageX = e.clientX + xScrollLeft();
      this.pageY = e.clientY + xScrollTop();
    }
  
  // Section A
  if (xDef(e.offsetX, e.offsetY)) 
  {
    this.offsetX = e.offsetX;
    this.offsetY = e.offsetY;
  }
  else 
    if (xDef(e.layerX, e.layerY)) 
    {
      this.offsetX = e.layerX;
      this.offsetY = e.layerY;
    }
    else 
    {
      this.offsetX = this.pageX - xPageX(this.target);
      this.offsetY = this.pageY - xPageY(this.target);
    }
  
  // End Section A
  this.keyCode = e.keyCode || e.which || 0;
  this.shiftKey = e.shiftKey;
  this.ctrlKey = e.ctrlKey;
  this.altKey = e.altKey;
  // rev8
  this.button = null; // 0=left, 1=middle, 2=right, null=none-mouse event
  if (e.type.indexOf('click') != -1) 
    this.button = 0;
  else 
    if (e.type.indexOf('mouse') != -1) 
    {
      var ie = 0, v = navigator.vendor;
      /*@cc_on ie = 1; @*/
      // I hate this sniff, but I don't know of any other way to support Safari here.
      if (ie || (v && v.indexOf('Apple') != -1)) 
      { // IE or Safari
        if (e.button & 1) 
          this.button = 0;
        else 
          if (e.button & 2) 
            this.button = 2;
          else 
            if (e.button & 4) 
              this.button = 1;
      }
      else 
        this.button = e.button;
    }
};

function $GetElements(ClassName, SecId, OnItem)
{
  var rdn_ctrs = $ByClass(ClassName);
  if (rdn_ctrs != null && rdn_ctrs.length > 0) 
  {
    for (var xi = 0; xi < rdn_ctrs.length; xi++) 
    {
      if (SecId) 
      {
        if (rdn_ctrs[xi].id == "") 
          rdn_ctrs[xi].id = SecId + xi;
      }
      if (typeof(OnItem == "function")) 
        OnItem(rdn_ctrs[xi]);
    }
  }
  
}


function $ByTag(str_tag, str_parentEleId)
{
  tag = str_tag || '*';
  var nodes = [];
  var root = null;
  
  if (str_parentEleId) 
  {
    root = $(str_parentEleId);
    
    if (!root) 
    { // if no root node, then no children
      return nodes;
    }
  }
  else 
  {
    root = document;
  }
  
  var nodes = root.getElementsByTagName(tag);
  
  if (!nodes.length && (tag == '*' && root.all)) 
  {
    nodes = root.all; // IE < 6
  }
  
  return nodes;
}

function xGetAttribute(ele, sAtt)
{
  try 
  {
    var a = ele.getAttribute(sAtt);
    
    if (!a) 
    {
      a = ele[sAtt];
    }
    
    return a;
  } 
  catch (e) 
  {
    return '';
  }
}

function xSetAttribute(ele, attribute, value)
{
  ele.setAttribute(attribute, value);
  var a = ele.getAttribute(attribute);
  
  if (!a || a != value) 
    a = ele[attribute] = value;
  
  return a;
}

/**
 *
 * @param {Object} str_ele
 * @param {Object} str_attr
 * @param {Object} str_val
 */
function xAttr(str_ele, str_attr, str_val)
{
  var ele = $(str_ele);
  
  if (ele != null) 
  {
    if (str_val) 
    {
      //ele.setAttribute(str_attr,str_val);
      xSetAttribute(ele, str_attr, str_val);
    }
    
    return xGetAttribute(ele, str_attr);
  }
  
  return null;
}

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();
