// JavaScript Document
xCore=true;

var xBrowser= new Object();
xBrowser.v = navigator.userAgent.toLowerCase();
xBrowser.isIe = (xBrowser.v.indexOf("msie 6") > -1 )?true:false;
xBrowser.cssCompat = (document.compatMode == "CSS1Compat")?true:false;
xBrowser.isMoz = (xBrowser.v.indexOf("rv:1.") > -1 )?true:false;

function newXML(){
	var obj=null;
    if(window.ActiveXObject){
		obj = new ActiveXObject("microsoft.XMLDOM");
	}else if(window.DOMParser){
		obj = new DOMParser();
	}
    return obj;
}
// convierto xmldom a una string
function serializeToString(xmldom){
    if (typeof xmldom.xml!='undefined')
        return xmldom.xml;
    else
        return (new XMLSerializer()).serializeToString(xmldom);
}
function xGetURLArguments()
{
  var idx = location.href.indexOf('?');
  var params = new Array();
  if (idx != -1) {
    var pairs = location.href.substring(idx+1, location.href.length).split('&');
    for (var i=0; i<pairs.length; i++) {
      nameVal = pairs[i].split('=');
      params[i] = nameVal[1];
      params[nameVal[0]] = nameVal[1];
    }
  }
  return params;
}

function getHTTP() {
    var obj;
    try{ //to get the mozilla httprequest object
        obj = new XMLHttpRequest();
    }catch(e){
        try{ //to get MS HTTP request object
            obj=new ActiveXObject("Msxml2.XMLHTTP.4.0");
        }catch(e){
            try{ //to get MS HTTP request object
                obj=new ActiveXObject("Msxml2.XMLHTTP");
            }catch(e){
                try{// to get the old MS HTTP request object
                    obj = new ActiveXObject("microsoft.XMLHTTP");
                }catch(e){
                    throw "Unable to get an HTTP request object.";
                }
            }
        }
    }
    return obj;
}

function antiCache(tempUrl) {
    if (tempUrl.indexOf('?')>=0) {
    	return "&anticachecontrol=" +  Math.random();
    } else {
    	return "?anticachecontrol=" + Math.random();
    }
}
/**
 *  Normalizes whitespace between mozilla and IE
 *    - removes blank text nodes (where "blank" is defined as "containing no non-space characters")
 *  @param  domObj    the root of the DOM object to normalize
 */
function normalizeWhitespace  (domObj) {
    // with thanks to the kind folks in this thread: http://www.codingforums.com/archive/index.php/t-7028
    if (document.createTreeWalker) {
        var filter = {
            acceptNode: function(node) {
                if (/\S/.test(node.nodeValue)) {
                    return NodeFilter.FILTER_SKIP;
                }
                return NodeFilter.FILTER_ACCEPT;
            }
        }
        var treeWalker = document.createTreeWalker(domObj, NodeFilter.SHOW_TEXT, filter, true);
        while (treeWalker.nextNode()) {
            treeWalker.currentNode.parentNode.removeChild(treeWalker.currentNode);
            treeWalker.currentNode = domObj;
        }
        return domObj;
    } else {
        return domObj;
    }
}
/**
 * Retorna un xml cargado desde la url
 * To do: parametro assync
 */
function openXML(url,async,callBackFunction) {
	if (!xDef(async))
	async=false;
	if (!xDef(callBackFunction))
	callBackFunction=new Function();

	var xmlhttp= getHTTP();

    if (async){
    	 xmlhttp.onreadystatechange=function(){
    	 	if (xmlhttp.readyState == 4) {
    	        if (xmlhttp.status == 200) {
                   callBackFunction(normalizeWhitespace(xmlhttp.responseXML));
    	        }
    	        else{
				   e=new Error(xmlhttp.status, xmlhttp.statusText);
                   throw e;
    	        }
    	    }
    	 }
    }

    xmlhttp.open("GET", url+antiCache(url), async);
	xmlhttp.setRequestHeader("Content-type", "text/xml");
    xmlhttp.send("");

    if (!async){
	    if(xmlhttp.status == 200 || xmlhttp.status == 0){
	        return normalizeWhitespace(xmlhttp.responseXML);
	    }
		else{
	        e=new Error(xmlhttp.status, xmlhttp.statusText);
	        throw e;
	    }
    }
}
/**
    Retrieves a file given its URL.
    @param url             The url to load.
    @param headers=[]  The headers to use.
    @return                 The content of the file.
*/
function getFile(url, headers) {
    //if callback is defined then the operation is done async
    headers = (headers != null) ? headers : [];
    //setup the request
    try{
        var xmlhttp= getHTTP();
        xmlhttp.open("GET", url+antiCache(url), false);
        for(var i=0;i< headers.length;i++){
            xmlhttp.setRequestHeader(headers[i][0], headers[i][1]);
        }
        xmlhttp.send("");
    }catch(e){
        throw e;
    }
    if(xmlhttp.status == 200 || xmlhttp.status == 0){
        return xmlhttp.responseText;
    }else{
        e=new Error(xmlhttp.status, xmlhttp.statusText);
        throw e;
    }
}
function xLoadCSS(url)
{
  if (xBrowser.isIe){
      return document.createStyleSheet(url);
  }
  else{
      if (document.createElement && document.getElementsByTagName) {
        var s = document.createElement('link');
        var h = document.getElementsByTagName('head');
        if (s && h.length) {
          h[0].appendChild(s);
    	  s.rel = 'stylesheet';
    	  s.type = "text/css";
          s.href = url;
    	  return s;
        }
      }
      return false;
  }
}
function xInclude(url)
{
  if (xBrowser.isIe){
      try{
      var code=getFile(url);
      }
      catch(e){
        alert(e.description)
      }
     // var h=document.getElementsByTagName('head');
      var s ='<script>'+code+'</script>';
      document.write(s);
      return;
  }
  else{
      if (document.createElement && document.getElementsByTagName) {
        var s = document.createElement('script');
        var h = document.getElementsByTagName('head');
        if (s && h.length) {
          s.src = url;
          h[0].appendChild(s);
    	  return s;
        }
      }
      return false;
  }
}

/*

misc

*/

// xSlideCornerTo, Copyright 2002-2005 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
/*
function xSlideCornerTo(e, corner, targetX, targetY, totalTime)
{
  if (!(e=xGetElementById(e))) return;
  if (!e.timeout) e.timeout = 25;
  e.xT = targetX;
  e.yT = targetY;
  e.slideTime = totalTime;
  e.corner = corner.toLowerCase();
  e.stop = false;
  switch(e.corner) {
    case 'nw': e.xA = e.xT - xLeft(e); e.yA = e.yT - xTop(e); e.xD = xLeft(e); e.yD = xTop(e); break;
    case 'sw': e.xA = e.xT - xLeft(e); e.yA = e.yT - (xTop(e) + xHeight(e)); e.xD = xLeft(e); e.yD = xTop(e) + xHeight(e); break;
    case 'ne': e.xA = e.xT - (xLeft(e) + xWidth(e)); e.yA = e.yT - xTop(e); e.xD = xLeft(e) + xWidth(e); e.yD = xTop(e); break;
    case 'se': e.xA = e.xT - (xLeft(e) + xWidth(e)); e.yA = e.yT - (xTop(e) + xHeight(e)); e.xD = xLeft(e) + xWidth(e); e.yD = xTop(e) + xHeight(e); break;
    default: alert('&quot;xSlideCornerTo: Invalid corner&quot;'); return;
  }
  e.B = Math.PI / ( 2 * e.slideTime );
  var d = new Date();
  e.C = d.getTime();
  if (!e.moving) _xSlideCornerTo(e);
}

function _xSlideCornerTo(e)
{
  if (!(e=xGetElementById(e))) return;
  var now, seX, seY;
  now = new Date();
  t = now.getTime() - e.C;
  if (e.stop) { e.moving = false; e.stop = false; return; }
  else if (t &lt; e.slideTime) {
    setTimeout(&quot;_xSlideCornerTo('&quot;+e.id+&quot;')&quot;, e.timeout);
    s = Math.sin( e.B * t );
    newX = Math.round(e.xA * s + e.xD);
    newY = Math.round(e.yA * s + e.yD);
  }
  else { newX = e.xT; newY = e.yT; }
  seX = xLeft(e) + xWidth(e);
  seY = xTop(e) + xHeight(e);
  switch(e.corner) {
    case 'nw': xMoveTo(e, newX, newY); xResizeTo(e, seX - xLeft(e), seY - xTop(e)); break;
    case 'sw': if (e.xT != xLeft(e)) { xLeft(e, newX); xWidth(e, seX - xLeft(e)); } xHeight(e, newY - xTop(e)); break;
    case 'ne': xWidth(e, newX - xLeft(e)); if (e.yT != xTop(e)) { xTop(e, newY); xHeight(e, seY - xTop(e)); } break;
    case 'se': xWidth(e, newX - xLeft(e)); xHeight(e, newY - xTop(e)); break;
    default: e.stop = true;
  }
  //window.status = ('Target: ' + e.xT + ', ' + e.yT);//////debug///////
  //  xClip(e, 'auto'); // ?????is this needed? it was used in the original CBE method?????
  e.moving = true;
  if (t &gt;= e.slideTime) {
    e.moving = false;
  }
}
*/
/*

dom section

*/


function xParent(el, pTagName) {
    if (el == null) return null;
    else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase()) return el;
    else{
        return xParent(el.parentNode, pTagName);
    }
}

function xGetInnerText(el) {
    var str = "";
    for (var i=0; i<el.childNodes.length; i++) {
        switch (el.childNodes.item(i).nodeType) {
            case 1: //ELEMENT_NODE
                str += getInnerText(el.childNodes.item(i));
                break;
            case 3:    //TEXT_NODE
                str += el.childNodes.item(i).nodeValue;
                break;
        }
    }
    return str;
}

function xDef() {
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}
function xStr() {
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])!='string') return false;}
  return true;
}
function xNum() {
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])!='number') return false;}
  return true;
}
// posicion del objeto desde afuera del margen
function xLeft(e,iL){
	if (iL!=undefined){
		e.style.left=iL+'px';
	}
	return parseInt(e.style.left);
}

function xTop(e,iT){
	if (iT!=undefined){
		e.style.top=iT+'px';
	}
	return parseInt(e.style.top);
}
// retorna el tamaņo unusable de un elemento desde su borde hacia adentro
function xUnusableEdgeHeight(e){
	if (document.defaultView){
		pt=parseInt(document.defaultView.getComputedStyle(e,'').getPropertyValue('padding-top'));
		pb=parseInt(document.defaultView.getComputedStyle(e,'').getPropertyValue('padding-bottom'));
		bt=parseInt(document.defaultView.getComputedStyle(e,'').getPropertyValue('border-top-width'));
		bb=parseInt(document.defaultView.getComputedStyle(e,'').getPropertyValue('border-bottom-width'));
	}
	else if((e.currentStyle) && (xBrowser.cssCompat==true)){
		pt=parseInt(e.currentStyle.paddingTop);
		pb=parseInt(e.currentStyle.paddingBottom);
		bt=parseInt(e.currentStyle.borderTopWidth);
		bb=parseInt(e.currentStyle.borderBottomWidth);
	}
	if(isNaN(pt)) pt=0; if(isNaN(pb)) pb=0; if(isNaN(bt)) bt=0; if(isNaN(bb)) bb=0;
	return pt+pb+bt+bb;
}
function xUnusableEdgeWidth(e){
	if (document.defaultView){
	pt=parseInt(document.defaultView.getComputedStyle(e,'').getPropertyValue('padding-left'));
	pb=parseInt(document.defaultView.getComputedStyle(e,'').getPropertyValue('padding-right'));
	bt=parseInt(document.defaultView.getComputedStyle(e,'').getPropertyValue('border-left-width'));
	bb=parseInt(document.defaultView.getComputedStyle(e,'').getPropertyValue('border-right-width'));
	}
	else if((e.currentStyle) && (xBrowser.cssCompat==true)){
	pt=parseInt(e.currentStyle.paddingLeft);
	pb=parseInt(e.currentStyle.paddingRight);
	bt=parseInt(e.currentStyle.borderLeftWidth);
	bb=parseInt(e.currentStyle.borderRightWidth);
	}
	if(isNaN(pt)) pt=0; if(isNaN(pb)) pb=0; if(isNaN(bt)) bt=0; if(isNaN(bb)) bb=0;
	return (pt+pb+bt+bb);
}
// tamaņo usable dentro de un elemento
function xInnerWidth(e,iW){
	if (xNum(iW)){
		e.style.width=iW+'px';
	}
	var pt=0;
	var pb=0;
	if (xBrowser.cssCompat==true && e.currentStyle){
		pt=parseInt(e.currentStyle.paddingLeft);
		pb=parseInt(e.currentStyle.paddingRight);
	}
	if (document.defaultView){
		pt=parseInt(document.defaultView.getComputedStyle(e,'').getPropertyValue('padding-left'));
		pb=parseInt(document.defaultView.getComputedStyle(e,'').getPropertyValue('padding-right'));
	}
	if(isNaN(pt)) pt=0; if(isNaN(pb)) pb=0;

	return e.clientWidth-(pt+pb);
}
function xInnerHeight(e,iW){
	if (xNum(iW)){
		e.style.height=iW+'px';
	}
	var pt=0;
	var pb=0;
	if (xBrowser.cssCompat==true && e.currentStyle){
		pt=parseInt(e.currentStyle.paddingTop);
		pb=parseInt(e.currentStyle.paddingBottom);
	}
	if (document.defaultView){
		pt=parseInt(document.defaultView.getComputedStyle(e,'').getPropertyValue('padding-top'));
		pb=parseInt(document.defaultView.getComputedStyle(e,'').getPropertyValue('padding-bottom'));
	}
	if(isNaN(pt)) pt=0; if(isNaN(pb)) pb=0;

	return e.clientHeight-(pt+pb);
}

// posicion sin incluir margen
function xOffsetLeft(e,iL){
	if (iL!=undefined){
		if (xBrowser.cssCompat==true && e.currentStyle){
			ml=parseInt(e.currentStyle.marginLeft);
		}
		if (document.defaultView){
			ml=parseInt(document.defaultView.getComputedStyle(e,'').getPropertyValue('margin-left'));
		}

		if(isNaN(ml)) ml=0;
		cssL=iL-(ml);
		e.style.left=cssL+'px';
	}
	return parseInt(e.offsetLeft);
}
function xOffsetTop(e,iL){
	if (iL!=undefined){
		if (xBrowser.cssCompat==true && e.currentStyle){
			ml=parseInt(e.currentStyle.marginTop);
		}
		if (document.defaultView){
			ml=parseInt(document.defaultView.getComputedStyle(e,'').getPropertyValue('margin-top'));
		}

		if(isNaN(ml)) ml=0;
		cssL=iL-(ml);
		e.style.top=cssL+'px';
	}
	return parseInt(e.offsetTop);
}

// setea y retorna el tamano del objeto incluyendo borde y padding
function xOffsetHeight(e,iH){
	if (xNum(iH)){
	  if (document.defaultView){
		pt=parseInt(document.defaultView.getComputedStyle(e,'').getPropertyValue('padding-top'));
		pb=parseInt(document.defaultView.getComputedStyle(e,'').getPropertyValue('padding-bottom'));
		bt=parseInt(document.defaultView.getComputedStyle(e,'').getPropertyValue('border-top-width'));
		bb=parseInt(document.defaultView.getComputedStyle(e,'').getPropertyValue('border-bottom-width'));
	  }
	  else if((e.currentStyle) && (xBrowser.cssCompat==true)){
		pt=parseInt(e.currentStyle.paddingTop);
		pb=parseInt(e.currentStyle.paddingBottom);
		bt=parseInt(e.currentStyle.borderTopWidth);
		bb=parseInt(e.currentStyle.borderBottomWidth);
	  }


      if(isNaN(pt)) pt=0; if(isNaN(pb)) pb=0; if(isNaN(bt)) bt=0; if(isNaN(bb)) bb=0;
      cssH=iH-(pt+pb+bt+bb);
	  e.style.height=cssH+'px';
	}
	return parseInt(e.offsetHeight);
}
function xOffsetWidth(e,iW){
	if (xNum(iW)){

	  if (document.defaultView){
		pt=parseInt(document.defaultView.getComputedStyle(e,'').getPropertyValue('padding-left'));
		pb=parseInt(document.defaultView.getComputedStyle(e,'').getPropertyValue('padding-right'));
		bt=parseInt(document.defaultView.getComputedStyle(e,'').getPropertyValue('border-left-width'));
		bb=parseInt(document.defaultView.getComputedStyle(e,'').getPropertyValue('border-right-width'));
	  }
	  else if((e.currentStyle) && (xBrowser.cssCompat==true)){
		pt=parseInt(e.currentStyle.paddingLeft);
		pb=parseInt(e.currentStyle.paddingRight);
		bt=parseInt(e.currentStyle.borderLeftWidth);
		bb=parseInt(e.currentStyle.borderRightWidth);
	  }


      if(isNaN(pt)) pt=0; if(isNaN(pb)) pb=0; if(isNaN(bt)) bt=0; if(isNaN(bb)) bb=0;
      cssH=iW-(pt+pb+bt+bb);

	  e.style.width=cssH+'px';
	}
	return parseInt(e.offsetWidth);
}
function xClientWidth() {
  var w=0;
  if(document.documentElement && document.documentElement.clientWidth)
    w=document.documentElement.clientWidth;
  else if(document.body && document.body.clientWidth)
    w=document.body.clientWidth;
  else if(xDef(window.innerWidth,window.innerHeight,document.height)) {
    w=window.innerWidth;
    if(document.height>window.innerHeight) w-=16;
  }
  return w;
}
function xClientHeight() {
  var h=0;
  if(document.documentElement && document.documentElement.clientHeight)
    h=document.documentElement.clientHeight;
  else if(document.body && document.body.clientHeight)
    h=document.body.clientHeight;
  else if(xDef(window.innerWidth,window.innerHeight,document.width)) {
    h=window.innerHeight;
    if(document.width>window.innerWidth) h-=16;
  }
  return h;
}
function xGetPageX(e) {
  var x = 0;
  while (e) {
    if (e.offsetLeft) x += e.offsetLeft;
    e = (e.offsetParent) ? e.offsetParent : null;
  }
  return x;
}
function xGetPageY(e) {
  var y = 0;
  while (e) {
    if (e.offsetTop) y += e.offsetTop;
    e = (e.offsetParent) ? e.offsetParent : null;
  }
  return y;
}
function xHasPoint(ele, iLeft, iTop, iClpT, iClpR, iClpB, iClpL) {
  if (iClpT==undefined)iClpT=0;
  if (iClpR==undefined)iClpR=0;
  if (iClpB==undefined)iClpB=0;
  if (iClpL==undefined)iClpL=0;
  var thisX = xGetPageX(ele), thisY = xGetPageY(ele);
  return (iLeft >= thisX + iClpL && iLeft <= thisX + xOffsetWidth(ele) - iClpR &&
          iTop >=thisY + iClpT && iTop <= thisY + xOffsetHeight(ele) - iClpB );
}
function xClip(e,iTop,iRight,iBottom,iLeft) {
    if (iLeft!=undefined)
		e.style.clip='rect('+iTop+'px '+iRight+'px '+iBottom+'px '+iLeft+'px)';
    else
		e.style.clip='rect(0 '+parseInt(e.style.width)+'px '+parseInt(e.style.height)+'px 0)';
}

function xSetOpacity(e,opac) {
	if (xBrowser.isIe) e.style.filter = "Alpha(opacity=" + (opac*100) + ")";
	if (xBrowser.isMoz) e.style.MozOpacity = opac;
}

function xContains(e,oElement) {
	var tmp = oElement;
	while (tmp != null) {
		if (tmp == e) return true;
		tmp = tmp.parentNode;
	}
	return false;
};
// dom
function xIntersection(e1, e2, o)
{
  var ix1, iy2, iw, ih, intersect = true;
  var e1x1 = xGetPageX(e1);
  var e1x2 = e1x1 + xOffsetWidth(e1);
  var e1y1 = xGetPageY(e1);
  var e1y2 = e1y1 + xOffsetHeight(e1);
  var e2x1 = xGetPageX(e2);
  var e2x2 = e2x1 + xOffsetWidth(e2);
  var e2y1 = xGetPageY(e2);
  var e2y2 = e2y1 + xOffsetHeight(e2);
  // horizontal
  if (e1x1 <= e2x1) {
    ix1 = e2x1;
    if (e1x2 < e2x1) intersect = false;
    else iw = Math.min(e1x2, e2x2) - e2x1;
  }
  else {
    ix1 = e1x1;
    if (e2x2 < e1x1) intersect = false;
    else iw = Math.min(e1x2, e2x2) - e1x1;
  }
  // vertical
  if (e1y2 >= e2y2) {
    iy2 = e2y2;
    if (e1y1 > e2y2) intersect = false;
    else ih = e2y2 - Math.max(e1y1, e2y1);
  }
  else {
    iy2 = e1y2;
    if (e2y1 > e1y2) intersect = false;
    else ih = e1y2 - Math.max(e1y1, e2y1);
  }
  // intersected rectangle
  if (intersect && typeof(o)=='object') {
    o.x = ix1;
    o.y = iy2 - ih;
    o.w = iw;
    o.h = ih;
  }
  return intersect;
}

// from here down, added in v3.15.3

function xGetURLArguments()
{
  var idx = location.href.indexOf('?');
  var params = new Array();
  if (idx != -1) {
    var pairs = location.href.substring(idx+1, location.href.length).split('&');
    for (var i=0; i<pairs.length; i++) {
      nameVal = pairs[i].split('=');
      params[i] = nameVal[1];
      params[nameVal[0]] = nameVal[1];
    }
  }
  return params;
}
