function winOnUnload()
{

}

function winOnLoad()
{
	//var c = new xFenster('xf1', 100, 100);
  xAddEventListener(window, 'resize', winOnResize, false);
  xAddEventListener(window, 'scroll', winOnScroll, false);
  xAddEventListener(document, 'mousemove', documentOnMousemove, false);
  if (window.menuOnLoad) window.menuOnLoad();
}

function winOnResize() {
  centrar("contenedorxfenser1");
  winOnScroll(); // initial slide
}
function winOnScroll() {
  centrar("contenedorxfenser1");
  //xTop('ventana_log',xScrollTop())
}

function documentOnMousemove(e) {
	//alert(e);
	e = new xEvent(e);
	//window.status = e.target.id.lastIndexOf("popup");
	if (e.target.id.lastIndexOf("popup") > -1) popupOnMousemove(e);
}


// Cuadro de Log
function mostrar_log(){
vent = xGetElementById('ventana_log');
//posx = xLeft(vent);
if (xLeft(vent) < 0) x = 0; else x = 15-xWidth(vent);
xSlideTo('ventana_log',x,xTop(vent),250);
}


//  Ventana
function mostrar_ventana(posx,posy,w,h,ele,con) {

	if (!xGetElementById(con)) {
		ventana = new xFenster(ele, posx, posy);
	} else {
		xMoveTo(xGetElementById(con), posx, posy);
	}
	xShow(con);
	xShow(ele);
      for (var i = 0; i < xFenster.instances.length; ++i) {
	if (xFenster.instances[i].conID == con) {
		xFenster.instances[i].paint(w-xWidth(con),h-xHeight(con));
		xFenster.instances[i].focus();
	}
      }
	centrar(con);

}

function posicion(e) {
        var posx = 0;
        var posy = 0;
        if (!e) var e = window.event;
        if (e.pageX || e.pageY){posx = e.pageX;posy = e.pageY;}
        else if (e.clientX || e.clientY)        {
                posx = e.clientX + document.body.scrollLeft
                        + document.documentElement.scrollLeft;
                posy = e.clientY + document.body.scrollTop
                        + document.documentElement.scrollTop;
        }
	//var pos = array();
	pos = Array();
	pos[0] = posx;
	pos[1] = posy;
	return pos;
}

function mostrar_ventanaI(e,w,h,url) {
	pos = posicion(e);
	mostrar_ventana(pos[0],pos[1],w,h,'ventanaIframe','contenedorxfenserI');
	ifr = xGetElementById('ventanaIframe');
	var url_ac = ifr.src;
	if (url_ac.charAt(url_ac.length-1) == '/' ) { url_ac = url_ac.substring(0,url_ac.length-1); }
	if (url_ac != url) { ifr.src=url;}
}

function mostrar_ventanaD(e,w,h,txt) {
	pos = posicion(e);
	mostrar_ventana(pos[0],pos[1],w,h,'ventanaDiv','contenedorxfenserD');
	div = xGetElementById('ventanaDiv');
	xInnerHtml(div,txt)
}

function centrar(id_ele) {
	//alert('en centrar'+id_ele)
  var w = xWidth(id_ele), h = xHeight(id_ele), sl_time = 1000;
  var cw = xClientWidth(), ch = xClientHeight();
  //var ele = document.getElementById(id_ele);
	//window.status = id_ele+", "+(cw-w)/2+" "+(ch-h)/2+" "+sl_time;
  xSlideTo(id_ele, ((cw-w)/2)+xScrollLeft(), ((ch-h)/2)+xScrollTop(), sl_time);

}


//  Popup
function popupOnMousemove(e)
{
  //alert(popup+" "+p);
  var p,w,h,x,y,popup='poopupdiv',esiframe=0;
  offsetH = 20; // offsetH = horizontal distance between mouse and edge of preview
  offsetV = 20; // offsetV = vertical distance between mouse and edge of preview
  if (e.target.textopopup) if (e.target.textopopup.substring(0,7) == 'http://') var popup = 'poopupifr',esiframe=1;
  p = xGetElementById(popup);

  if (p && e.target.textopopup) {
    var textopopup = e.target.textopopup;
    p.style.display = 'block';
    e.target.onmouseout = popupOnMouseout;
    //window.status = e.target.texto;
	//alert(esiframe);
    if (esiframe) {
	var url_ac = p.src, url = e.target.textopopup;
	//alert(p);
	if (url_ac.charAt(url_ac.length-1) == '/' ) { url_ac = url_ac.substring(0,url_ac.length-1); }
	if (url_ac != url) { p.src=url;}
    } else { xInnerHtml(p,e.target.textopopup);}
    x = e.pageX;
    y = e.pageY + offsetV;
    w = xWidth(p);
    //offsetH = 0 - w/2;
    if (x - w - offsetH - xScrollLeft() < 0) {x += offsetH;}
    else {x -= w + offsetH;}
    h = xHeight(p);
    if (y + h  > xScrollTop() + xClientHeight()) {y -= h + (offsetV * 2);} 
    //else {y -= h - offsetV;}

    xMoveTo(p, x, y);
  }
}
function popupOnMouseout()
{
  var p = xGetElementById('poopupdiv');
  if (p) p.style.display = 'none';
  var p = xGetElementById('poopupifr');
  if (p) p.style.display = 'none';
}



function subeValor(oObj)

{
if(oObj.value =='')
 oObj.value=1;
 else
 oObj.value++;
 }

