// 3 de julio de 2007 [cs]


var today = new Date();
var the_date = new Date("December 31, 2023");
var the_cookie_date = the_date.toGMTString();
var the_cookie = "users_resolution="+ screen.width +"x"+ screen.height;
var the_cookie = the_cookie + ";expires=" + the_cookie_date;
document.cookie=the_cookie; 

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = refreshMouseXY;

var tempX = 0;
var tempY = 0;

function refreshMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft;
tempY = event.clientY + document.body.scrollTop;
}
else {  // grab the x-y pos.s if browser is NS
tempX = e.pageX;
tempY = e.pageY;
}  
//document.getElementById("divMostrar").innerHTML = "[" + tempX + "][" + tempY + "]";

if (tempX < 0){tempX = 0;}
if (tempY < 0){tempY = 0;}  

return true;
}

function maxlength(element, maxvalue)
     {
     var q = eval("document.formNuevo."+element+".value.length");
     var r = q - maxvalue;
     var msg = "The limit for the message field is "+
       maxvalue+" characters. Please remove "+ r +
       " --/-- Disculpa, acabas de capturar "+q+" caracteres; el limite es de "+
       maxvalue+". Debes remover "+r+".  Gracias.";
     if (q > maxvalue) alert(msg);
     }

function checkform()
{
   if(document.formNuevo.msg.value.length > 255)
      return false;
   return true;
}

//////////////////////////////////////////////////////////////////////////    
//  by Marcus Andersson   marcan at home.se 
//////////////////////////////////////////////////////////////////////////    

    var ElementUtil = new Object();
    ElementUtil.getElementPosition = function(elt){
      var position = new Object();    
      if(elt.style.position == "absolute") {
        position.left = parseInt(elt.style.left);
        position.top = parseInt(elt.style.top);
      }
      else {
        position.left = ElementUtil.calcPosition(elt, "Left");      
        position.top = ElementUtil.calcPosition(elt, "Top");      
      }  
      return position;
    }
    
    ElementUtil.calcPosition = function(elt, dir){
        var tmpElt = elt;
        var pos = parseInt(tmpElt["offset" + dir]);
        while(tmpElt.tagName != "BODY") {
            tmpElt = tmpElt.offsetParent;
            pos += parseInt(tmpElt["offset" + dir]);
        }
        return pos;
    }
    
    ElementUtil.getElementDimension = function(elt) {
      var dim = new Object();
      dim.width = elt.offsetWidth;
      dim.height = elt.offsetHeight;
      return dim;
    }    
    
    ElementUtil.addEventListener = function(o, type, handler) {
      if(ie) {
        o.attachEvent("on" + type, handler);
      }
      else if(moz) {
        o.addEventListener(type, handler, false);
      }
    }

    ElementUtil.removeEventListener = function(o, type, handler) {
      if(ie) {
        o.detachEvent("on" + type, handler);
      }
      else if(moz) {
        o.removeEventListener(type, handler, false);
      }
    }
    
//////////////////////////////////////////////////////////////////////////    

function handleFavIconError(e) { e.style.display='none'; }

function mostrar_portada(e, cual) {
  
  var espacio = document.body.clientHeight - document.getElementById(cual).height;
  var yRaton = e.clientY  + document.body.scrollTop;
  
  if(document.body.clientTop)
     yRaton -= document.body.clientTop;

  var percPos = (yRaton - ElementUtil.getElementPosition(document.getElementById(cual + "_mini")).top) / document.getElementById(cual + "_mini").height;
  
  if (!e) var e = window.event;
  
  if (document.getElementById) {
     if ( espacio >= 0 ) 
        document.getElementById(cual).style.top = document.body.scrollTop + (espacio/2);    
     else 
        document.getElementById(cual).style.top = (percPos * document.body.clientHeight) + document.body.scrollTop - (percPos * document.getElementById(cual).height);

     if(document.body.clientTop && document.getElementById(cual).style.top >= document.body.clientTop)
        document.getElementById(cual).style.top = document.getElementById(cual).style.top - document.body.clientTop;

     document.getElementById(cual).style.display = "block";
  }
}

//      document.getElementById(cual).style.top = e.clientY  + document.body.scrollTop - 100;

function ocultar_portada(cual) {
  if (document.getElementById)
    document.getElementById(cual).style.display = "none";
}

function mostrar_img(e, oImg, newsrc) {

ocultaMedios();

  var cual = "divParaImg";
  if (typeof newsrc == "undefined") {
	  newsrc = new String(oImg.src);
	  newsrc=newsrc.replace("thumb_", "");
  }
//  newsrc=newsrc.replace("_m.jpg", "_o.jpg");

  if(document.getElementById("imgParaImg").src != newsrc) {
     document.getElementById("imgParaImg").src = "http://delotrolado.net/img/cargaimg.jpg";
//     document.getElementById("imgParaImg").style.clip='rect(auto 222px auto 0px)';
     document.getElementById("imgParaImg").src = newsrc;
  }
  
  document.getElementById(cual).style.left = 0;

  if(document.getElementById("imgParaImg").height == oImg.height)
     return;

  var xRaton = e.clientX  + document.body.scrollLeft;
  var yRaton = e.clientY  + document.body.scrollTop;
  
  if(document.body.clientLeft)
    xRaton -= document.body.clientLeft;
  if(document.body.clientTop)
    yRaton -= document.body.clientTop;

  var percPosX = (xRaton - ElementUtil.getElementPosition(oImg).left) / oImg.width;  
  var percPos = (yRaton - ElementUtil.getElementPosition(oImg).top) / oImg.height;  

  var espacioVer = document.body.clientHeight - document.getElementById("imgParaImg").height;
  var espacioHorIzq = ElementUtil.getElementPosition(oImg).left;
  var espacioHorDer = document.body.clientWidth - ElementUtil.getElementPosition(oImg).left - oImg.width;
  
  if(espacioHorDer > espacioHorIzq) {
     document.getElementById(cual).style.left =  ElementUtil.getElementPosition(oImg).left + oImg.width + 10;

     if(document.getElementById("imgParaImg").width > espacioHorDer) {

        xDiff = document.getElementById("imgParaImg").width - espacioHorDer + 50;
        x1 = xDiff * percPosX;
        x2 = document.getElementById("imgParaImg").width - (xDiff - x1);

        document.getElementById("imgParaImg").style.clip='rect(auto ' + x2 + 'px auto ' + x1 + 'px)';
        document.getElementById(cual).style.width = espacioHorDer- 30;
        document.getElementById("imgParaImg").style.left = 10 - x1;
     } else {
        document.getElementById("imgParaImg").style.left = 15;
        document.getElementById(cual).style.width = document.getElementById("imgParaImg").width + 25;
        document.getElementById("imgParaImg").style.clip='rect(auto auto auto auto)';

     }

   } else {
     document.getElementById(cual).style.left =  espacioHorIzq - document.getElementById("imgParaImg").width - 50;

     if(document.getElementById("imgParaImg").width > espacioHorIzq) {

        xDiff = document.getElementById("imgParaImg").width - espacioHorIzq + 50;
//alert(percPosX);
//alert(xDiff);
        x1 = xDiff * percPosX;
        x2 = document.getElementById("imgParaImg").width - (xDiff - x1);

        document.getElementById(cual).style.left = 5;
        document.getElementById("imgParaImg").style.clip='rect(auto ' + x2 + 'px auto ' + x1 + 'px)';
        document.getElementById(cual).style.width = espacioHorIzq - 30;
        document.getElementById("imgParaImg").style.left = 10 - x1;

     } else {
        document.getElementById("imgParaImg").style.left = 15;
        document.getElementById(cual).style.width = document.getElementById("imgParaImg").width + 25;
        document.getElementById("imgParaImg").style.clip='rect(auto auto auto auto)';
     }
   }

  document.getElementById(cual).style.height = document.getElementById("imgParaImg").height + 25;
  document.getElementById("imgParaImg").style.top = "12px";
 
  if (!e) var e = window.event;

  if (document.getElementById) {
     if ( espacioVer >= 0 ) {
         document.getElementById(cual).style.top = document.body.scrollTop + (espacioVer/2);    
      }
     else {
      document.getElementById(cual).style.top = (percPos * document.body.clientHeight) + document.body.scrollTop - (percPos * document.getElementById("imgParaImg").height);
      }
      if(document.body.clientTop && document.getElementById(cual).style.top >= document.body.clientTop)
         document.getElementById(cual).style.top = document.getElementById(cual).style.top - document.body.clientTop;
    document.getElementById(cual).style.display = "block";
  }
}

/*
function mostrar_img_ant(e, oImg) {

  var newsrc = new String(oImg.src);

  newsrc=newsrc.replace("thumb_", "");

window.status=newsrc;

//  newsrc=newsrc.replace(/thumb_$/, "");

  //alert(newsrc);

  if(document.getElementById("imgParaImg").src != newsrc) {
     document.getElementById("imgParaImg").src = "http://delotrolado.net/img/cargaimg.jpg";
     document.getElementById("imgParaImg").src = newsrc;
  }

  if(document.getElementById("imgParaImg").height == oImg.height)
     return;

  var cual = "divParaImg";
  var espacioVer = document.body.clientHeight - document.getElementById("imgParaImg").height;
  var espacioHorIzq = ElementUtil.getElementPosition(oImg).left;
  var espacioHorDer = document.body.clientWidth - ElementUtil.getElementPosition(oImg).left - oImg.width;
  
  if(espacioHorDer > espacioHorIzq || document.getElementById(cual).width > espacioHorIzq) {
     document.getElementById(cual).style.left =  ElementUtil.getElementPosition(oImg).left + oImg.width + 10;
   } else {
     document.getElementById(cual).style.left =  espacioHorIzq - document.getElementById("imgParaImg").width - 30;
   }

  var yRaton = e.clientY  + document.body.scrollTop;
  
  if(document.body.clientTop)
    yRaton -= document.body.clientTop;

  var percPos = (yRaton - ElementUtil.getElementPosition(oImg).top) / oImg.height;  
 
  if (!e) var e = window.event;

  if (document.getElementById) {

     if ( espacioVer >= 0 ) {
         document.getElementById(cual).style.top = document.body.scrollTop + (espacioVer/2);    
      }
     else {
      document.getElementById(cual).style.top = (percPos * document.body.clientHeight) + document.body.scrollTop - (percPos * document.getElementById("imgParaImg").height);
      }

      if(document.body.clientTop && document.getElementById(cual).style.top >= document.body.clientTop)
         document.getElementById(cual).style.top = document.getElementById(cual).style.top - document.body.clientTop;

    document.getElementById(cual).style.display = "block";
  }
}
*/

function ocultar_img() {
 var cual = "divParaImg";

muestraMedios();
//document.getElementById("divMostrar").innerHTML = "antes de";

 if (document.getElementById) {
   
//   document.getElementById("divMostrar").innerHTML = "[" + document.getElementById(cual).style.left + "][" + document.getElementById("imgParaImg").width + "][" + (parseInt(document.getElementById(cual).style.left) + parseInt(document.getElementById("imgParaImg").width) + 50) + "][" + tempX + "]";
   if(parseInt(document.getElementById(cual).style.left) <= tempX && (parseInt(document.getElementById(cual).style.left) + parseInt(document.getElementById("imgParaImg").width) + 50) > tempX) {
       document.getElementById(cual).style.left = tempX - document.getElementById("imgParaImg").width - 50;
       //return;
   }

   document.getElementById("imgParaImg").src = "http://delotrolado.net/img/cargaimg.jpg";
   document.getElementById("divParaImg").style.display = "none";
 }
}


/*
function adjustImgSize(o) { 
  if(o.width > $imgMaxW || o.height > $imgMaxH) { 
    if(o.height-$imgH > o.width-$imgW) {
       o.height=$imgH;
    } else {
       o.width=$imgW;
    } 
  } 
} 
*/

function adjustImgSize2(o, w, h) { 
  if(o.width > w || o.height > h) { 
    if(o.height-h > o.width-w){
      o.height=h;
    } else {
      o.width=w;
    } 
  } 
}

function scrollToObj(what) {
  
document.scrollTop = ElementUtil.getElementPosition(document.getElementById(what)).top;

document.scrollLeft = ElementUtil.getElementPosition(document.getElementById(what)).left;

//document.scrollTo(ElementUtil.getElementPosition(document.getElementById(what)).top, ElementUtil.getElementPosition(document.getElementById(what)).left);

//  document.getElementById(what).scrollTop = document.Form1.scrollPos.value;
}

 function CreateBookmarkLink() {

 title = document.title; 
 url = location.href;

   if (window.sidebar) { // Mozilla Firefox Bookmark
      window.sidebar.addPanel(title, url,"");
   } else if( window.external ) { // IE Favorite
      window.external.AddFavorite(url, title); }
   else if(window.opera && window.print) { // Opera Hotlist
      return true; }
 }


var favsLiga = "-";

 if (window.external) {
  favsLiga = '<a href="javascript:CreateBookmarkLink()");"><span style="font-size:9pt;font-weight:bold;color:LightSteelBlue;">+Favs</span></a>'; 
  } 
 if (window.sidebar) {
  favsLiga = '<a href="javascript:CreateBookmarkLink()");"><span style="font-size:9pt;font-weight:bold;color:LightSteelBlue;">+Favs</span></a>'; 
 } 
 if (window.opera && window.print) {   
  favsLiga = '<a href="javascript:CreateBookmarkLink()");"><span style="font-size:9pt;font-weight:bold;color:LightSteelBlue;">+Favs</span></a>'; 
 } 

//////////////////////////////////////////////////
//    MULTIMEDIOS
//////////////////////////////////////////////////

var mostrando_multi = false;

//window.onscroll = multi_ajusta;
//window.onresize = multi_ajusta;
//parent.ient.location="about:blank";

window.onload = terminaCarga;
var cargando = true;

function multi_ajusta() {
  if(!mostrando_multi)
    return;
  centra_caja();
}

function oculta_multi(){
  muestraMedios();
  document.getElementById('divMultiCaja').style.display = 'none';
  document.getElementById('divFondoMulti').style.display = 'none';
  mostrando_multi = false;
}

function getPageSizeWithScroll(){
   if (window.innerHeight && window.scrollMaxY) {// Firefox
      yWithScroll = window.innerHeight + window.scrollMaxY;
      xWithScroll = window.innerWidth + window.scrollMaxX;
   } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
      yWithScroll = document.body.scrollHeight;
      xWithScroll = document.body.scrollWidth;
   } else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
      yWithScroll = document.body.offsetHeight;
      xWithScroll = document.body.offsetWidth;
   }
   arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
   //alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
   return arrayPageSizeWithScroll;
}

function terminaCarga() {
   cargando = false;
}

function getInnerClient(){
var x,y;
if (self.innerHeight) // all except Explorer
{
   x = self.innerWidth;
   y = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight)
   // Explorer 6 Strict Mode
{
   x = document.documentElement.clientWidth;
   y = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{
   x = document.body.clientWidth;
   y = document.body.clientHeight;
}
arrayXY = new Array(x,y);
// alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
   return arrayXY;
}

function centra_caja(cajaNombre, divNombre) {

  var ocaja = document.getElementById(cajaNombre);
  var omedios = document.getElementById(divNombre);
// alert(cajaNombre + "--> " + ocaja + "--> " + ocaja.offsetHeight);
  var vespacio = getInnerClient()[1] - ocaja.offsetHeight;
  var hespacio = document.body.clientWidth - ocaja.offsetWidth;

  ocaja.style.top = Math.max(document.body.scrollTop + (vespacio/2), document.body.scrollTop + 5);  
  ocaja.style.left = document.body.scrollLeft + (hespacio/2);  

//show.value += "\n" + document.body.scrollTop + "|" + vespacio + "|" + ocaja.style.top;

  omedios.style.left = ((ocaja.offsetWidth - omedios.offsetWidth - 20)/2);
  
  var ofondo = document.getElementById('divFondoMulti');
  ofondo.style.width = getPageSizeWithScroll()[0];
  ofondo.style.height = getPageSizeWithScroll()[1];
  ofondo.style.display = '';
    
}

function muestra_multi(smedio, tipo, obj){
  var omedios = document.getElementById('divMultiMedios');
  var ocaja = document.getElementById('divMultiCaja');
  
  ocultaMedios();

//  show.value = tipo + "[" + smedio + "]:";
  
  switch(tipo)
  {
  case "YOU TUBE":
//    show.value = show.value + " " + '<object width="425" height="350"><param name="movie" value="'+ smedio +'"></param><param name="wmode" value="transparent"></param><embed alt="CARGANDO VIDEO" src="'+ smedio +'" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>';
    omedios.innerHTML = '<embed alt="CARGANDO VIDEO" src="'+ smedio +'" bgcolor="#d9e5ee" quality="best" type="application/x-shockwave-flash" width="425" height="350" AUTOSTART=TRUE >';
    //  wmode="transparent"
    omedios.style.width = "425";
    break 
  case "VIDEO Google":
    omedios.innerHTML = '<embed alt="CARGANDO VIDEO" style="width: 425px; height: 350px;" type="application/x-shockwave-flash" src="'+ smedio +'" id="VideoPlayback" quality="best" bgcolor="#d9e5ee" AUTOSTART=TRUE >';
    //salign="TL"  align="middle" scale="noScale"  flashvars="playerMode=embedded"
    omedios.style.width = "425";
    break 
  default:
    omedios.innerHTML = smedio;
  }
//  alert(omedios.innerHTML);
//  show.value = show.value + " " + omedios.innerHTML;
  
  document.getElementById('divMultiControles').innerHTML = obj.parentNode.parentNode.parentNode.innerHTML;
  ocaja.style.display = '';
  centra_caja('divMultiCaja', 'divMultiMedios');   
  mostrando_multi = true;
}
//document.getElementById('".$divVideo."').style.display = 'block';scrollToObj('".$divVideo."');

var cargaReal = false;

function abreEntrada($entradaNo) {
//  if(cargando && document.getElementById('divPiecito')) {
//     cargando = false;
//     window.stop();
//     document.execCommand("Stop");
//  }

ocultaMedios();

  cargaReal = true;
  parent.ient.location="/2/inc/server/f/dameEntrada.php?entradaNo=" + $entradaNo;
  document.getElementById('divVerEntrada').innerHTML = "<h2><font color='Thistle'>Cargando...</font></h2>";
  document.getElementById('divVerEntradaCaja').style.display = '';   
  centra_caja('divVerEntradaCaja', 'divVerEntrada');
}

function muestraEntrada() {

//show.value += window.frames['ient'].location + "\n";

   var idoc=window.frames['ient'].document;
   var root = idoc.documentElement || idoc.body;
   var HTML = root.innerHTML;

//show.value = "[" + parent.ient.location + "][" + HTML + "]";

if(!cargaReal || parent.ient.location == "" || parent.ient.location == "about:blank" || HTML == "" || HTML == "<head><title></title></head><body></body>" || HTML == "<HEAD></HEAD>\n<BODY></BODY>")
  return;   
   
   document.getElementById('divVerEntrada').innerHTML=HTML;
   document.getElementById('divVerEntradaCaja').style.display = '';   
   centra_caja('divVerEntradaCaja', 'divVerEntrada');
}

function ocultaEntrada(){
  muestraMedios();
  document.getElementById('divVerEntradaCaja').style.display = 'none';
  document.getElementById('divFondoMulti').style.display = 'none';
  mostrando_multi = false;
}

function changeEntradaBG() {
  var oBG = document.getElementById('divBGEntrada');

  document.getElementById('divVerEntrada').style.backgroundColor = oBG.style.backgroundColor;

//show.value = "\n" + oBG.style.backgroundColor.toLowerCase();
  
   switch(oBG.style.backgroundColor.toLowerCase())
   {
   case "whitesmoke":
     oBG.style.backgroundColor = "Lavender";
     break;
   case "lavender":
     oBG.style.backgroundColor = "LightSteelBlue";
     break;
   case "lightsteelblue":
     oBG.style.backgroundColor = "LightSlateGray";
     break;
   case "lightslategray":
     oBG.style.backgroundColor = "CadetBlue";
     break;
   case "cadetblue":
     oBG.style.backgroundColor = "DarkSlateGray";
     break;
   case "darkslategray":
     oBG.style.backgroundColor = "Black";
     break;
   case "black":
     oBG.style.backgroundColor = "White";
     break;
   case "white":
     oBG.style.backgroundColor = "WhiteSmoke";
     break;
   default:
//      show.value += "\nD: " + oBG.style.backgroundColor.toLowerCase();
     oBG.style.backgroundColor = "Black";
   }  
}



/*
function SymError()
{
  return true;
}

window.onerror = SymError;
*/

//////////////////////////////////////////////////////////////////////////    
//////////////////////////////////////////////////////////////////////////    
//////////////////////////////////////////////////////////////////////////    

function ocultaMedios(){
  var vids = document.getElementsByTagName("DIV"); 
  for(i=0; i<vids.length; i++){
  	  if(vids[i].id.indexOf("divMedioEmbeded_")>=0){
  	  	  vids[i].style.display = 'none';
  	  }
  }	
}

function  muestraMedios() {
  var vids = document.getElementsByTagName("DIV"); 
  for(i=0; i<vids.length; i++){
  	  if(vids[i].id.indexOf("divMedioEmbeded_")>=0){
  	  	  vids[i].style.display = '';
  	  }
  }  
}