//inicializa las variables de navegador y S.O.
function SetBrowserVars(){
     NS4 = (document.layers);
     IE4 = (document.all);
    ver4 = (NS4 || IE4);
     IE5 = (IE4 && navigator.appVersion.indexOf("5.")!=-1);
     NS6 = (document.getElementById && !document.all) ? true : false;
   isMac = (navigator.appVersion.indexOf("Mac") != -1);
  isMenu = (NS4 || (IE4 && !isMac) || (IE5 && isMac));
  if (!ver4) event=null;
  isNav = (NS4 || NS6);
   isIE = (IE4 || IE5);
  if (NS4) {
		coll="";
		styleObj="";
  } else if (NS6) {	
		coll="getElementById('";
		styleObj="').style";
  } else {
		coll="all.";
		styleObj=".style";
  }
}

//Selecciona estilos de acuerdo al navegador y S.O.
function SetStyleSheets(){
   if (isNav){
            document.write('<LINK REL="stylesheet" TYPE="TEXT/CSS" HREF="../css/estilosns.css">')
   }
   else{
   		if (isMac){
            document.write('<LINK REL="stylesheet" TYPE="TEXT/CSS" HREF="../css/estilosiem.css">') 
		}
		else {
            document.write('<LINK REL="stylesheet" TYPE="TEXT/CSS" HREF="../css/estilosiew.css">') 
		}	
   }
}
function ShowMenuImage(idnumber){
  MM_swapImage('foto'+idnumber+'-menu','','img/bt-'+idnumber+'-off-over.gif',1);
  MM_swapImage('texto'+idnumber+'-menu','','img/bt-tx-'+idnumber+'-on.gif',1);
}

  function HideMenuImage(idnumber){
  MM_swapImage('foto'+idnumber+'-menu','','img/bt-'+idnumber+'-off.gif',1);
  MM_swapImage('texto'+idnumber+'-menu','','img/bt-tx-'+idnumber+'-off.gif',1);
}
// Mueve la barra del menu superior

//enciende fondo de menues izq
function changeBackon(ids){
var change
var idname
var idname = ids
if (NS4){
// si es nav mueve los fondos que no quedan bien posicionados
    document.fondonoticias.moveTo(6,261)
    document.fondoenlaces.moveTo(6,299)
    document.alterini.moveTo(650,230)    
	var change = eval("document."+idname)
	change.visibility="visible"}
	else {
	var change = eval("document.all."+idname+".style")
	change.visibility="visible"
	}
}

//apagado de fondos
function changeBackoff(ids){
var change
var idname
var idname = ids
if (NS4){
var change = eval("document."+idname)
change.visibility="hidden"}
else {
var change = eval("document.all."+idname+".style")
change.visibility="hidden"

}

}
//comentar***************************
function upmenuoff(){
var Change	
for (var i=0; i<= 2; i++){
     changeBackoff(MenuId[0])
	 }
}

// Devuelve la altura (height) del contenido de un objeto en pixels
function getObjHeight(obj) {
	if (isNav) {
		return obj.clip.height
	} else {
		return obj.offsetHeight
	}
}

// Devuelve el ancho (width) del contenido de un objeto en pixels
function getObjWidth(obj) {
	if (isNav) {
		return obj.clip.width
	} else {
		return obj.offsetWidth
	}
}

// Pone el z-order de un objeto
function setZIndex(obj, zOrder) {
	var theObj = getObject(obj)
	theObj.zIndex = zOrder
}

// Pone el color de background de un object
function setBGColor(obj, color) {
	var theObj = getObject(obj)
	if (isNav4) {
		theObj.bgColor = color
	} else {
		theObj.backgroundColor = color
	}
}

// Hace visible un objeto
function show(obj) {
	var theObj = getObject(obj)
	theObj.visibility = "visible"
}

// Oculta un objeto
function hide(obj) {
	var theObj = getObject(obj)
	theObj.visibility = "hidden"
}

// Devuelve la coordenada x de un objeto posicionable
function getObjectLeft(obj)  {
	var theObj = getObject(obj)
	if (isNav4) {
		return theObj.left
	} else {
		return theObj.pixelLeft
	}
}

// Devuelve la coordenada y de un objeto posicionable
function getObjectTop(obj)  {
	var theObj = getObject(obj)
	if (isNav4) {
		return theObj.top
	} else {
		return theObj.pixelTop
	}
}
// Devuelve la altura (height) del área cliente de la ventana del browser en pixels
function getInsideWindowHeight() {
	if (isNav) {
		return window.innerHeight
	} else {
		return document.body.clientHeight
	}
}

// Devuelve el ancho (width) del área cliente de la ventana del browser en pixels
function getInsideWindowWidth() {
	if (isNav) {
		return window.innerWidth
	} else {
		return document.body.clientWidth
	}
}

// Función para posicionar un elemento en una posición específica x,y
function shiftTo(obj, x, y) {
	if (isNav) {
		obj.moveTo(x,y)
	} else {
		obj.pixelLeft = x
		obj.pixelTop = y
	}
}

// Funcion para desplazar un objeto xy pixels
function shiftBy(obj, deltaX, deltaY) {
	if (isNav) {
		obj.moveBy(deltaX, deltaY)
	} else {
		obj.pixelLeft += deltaX
		obj.pixelTop += deltaY
	}
}

// Función para re-posicionar horizontalmente un elemento de acuerdo
// a las dimensiones del área cliente con relación a la de diseño
function AdjustLeft(l,designresw,minx) {
	var w = getInsideWindowWidth();
	if (l > w) {
		return l;
	} else {
		var delta = Math.round((w - designresw) / 2);
	    if (w <= designresw) {
			if (delta < -minx) {
				delta = -minx
			}
		}
		l = l + delta;
		return l
	}
}

// Función para re-posicionar verticalmente un elemento de acuerdo
// a las dimensiones del área cliente con relación a la de diseño
function AdjustTop(t,designresh,miny) {
	var h = getInsideWindowHeight();
	if (t > h) {
		return t;
	} else {
		var delta = Math.round((h - designresh) / 2);
	    if (h <= designresh) {
			if (delta < -miny) {
				delta = -miny
			}
		}
		t = t + delta;
		return t;
	}
}

function CenterLeft(wd) {
	var w = getInsideWindowWidth();
	if (wd >= w) {
		return 0;
	} else {
		return Math.round((w - wd) / 2);
	}
}

function CenterTop(ht) {
	var h = getInsideWindowHeight();
	if (ht >= h) {
		return 0;
	} else {
		return Math.round((h - ht) / 2);
	}
}

// Función para centrar un objeto posicionable, cuyo nombre se pasa
// como parámetro, en la ventana/frame actual y lo hace visible
function centerObject(layerName) {
	// 'obj' es el objeto posicionable
	var obj = eval("document." + coll + layerName + styleObj);
	// 'contentObj' es el contenedor
	var contentObj;
	if (isNav) {
		// elemento posicionable para NN
		contentObj = document.layers[layerName];
	}
	else {
		// necesario para obtener la dimensión de contenedores encadenados para fijar dimensión
		// del DIV contenido para IE
		contentObj = document.all[layerName].children[0];
		// Para IE, redimensionar div para dimensionar el contenedor para mostrar el color de background
		obj.pixelWidth = contentObj.offsetWidth;
		obj.pixelHeight = contentObj.offsetHeight;
	}
	var x = Math.round((getInsideWindowWidth()/2) - (getObjWidth(contentObj)/2));
	var y = Math.round((getInsideWindowHeight()/2) - (getObjHeight(contentObj)/2));
	shiftTo(obj, x, y);
	obj.visibility = "visible";
}

function CenterLayer(name,w,h) {
		var obj = eval("document." + coll + name + styleObj);
		obj.left = CenterLeft(w);
		obj.top = CenterTop(h);
}	

// Función para corregir el bug de CSS-P redraw en Navigator 4
function handleNS4Resize() {
	if (NS4) {
		location.reload()	
	}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_findObj30(n, d) { //v3.0
	if (NS6) {
		return document.getElementById(n);
	} else {
	  	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	  	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
	}  
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() {
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) { 
	 obj=MM_findObj(args[i]);
     if (obj != null) {
	     v=args[i+2];
    	 if (obj.style) { obj = obj.style; v = (v=='show')?'visible':(v='hide')?'hidden':v; }
	     obj.visibility=v;
     }
  }	 
}

function fecha(){
                mes = new Array();
                mes[0] = "ENE";
                mes[1] = "FEB";
                mes[2] = "MAR";
                mes[3] = "ABR";
                mes[4] = "MAY";
                mes[5] = "JUN";
                mes[6] = "JUL";
                mes[7] = "AGO";
                mes[8] = "SEP";
                mes[9] = "OCT";
                mes[10] = "NOV";
                mes[11] = "DIC";
                x = new Date();
                d = x.getDate();
                m = x.getMonth();
                a = x.getFullYear();
                document.write(d + " " + mes[m] + " " + a);
}

var upH = 11; // Height of up-arrow
var upW = 11; // Width of up-arrow
var downH = 11; // Height of down-arrow
var downW = 11; // Width of down-arrow
var dragH = 7; // Height of scrollbar
var dragW = 17; // Width of scrollbar
var scrollH = 100; // Height of scrollbar
var speed = 4; // Scroll speed

// And now... go to the bottom of the page...
var mouseY; // Mouse Y position onclick
var mouseX; // Mouse X position onclick

var clickUp = false; // If click on up-arrow
var clickDown = false; // If click on down-arrow
var clickDrag = false; // If click on scrollbar
var clickAbove = false; // If click above scrollbar
var clickBelow = false; // If click below scrollbar

var timer = setTimeout("",500); // Repeat variable
var upL; // Up-arrow X
var upT; // Up-arrow Y
var downL; // Down-arrow X
var downT; // Down-arrow Y
var dragL; // Scrollbar X
var dragT; // Scrollbar Y
var rulerL; // Ruler X
var rulerT; // Ruler Y
var contentT; // Content layer Y;
var contentH; // Content height
var contentClipH; // Content clip height
var scrollLength; // Number of pixels scrollbar should move
var startY; // Keeps track of offset between mouse and span

// Mousedown
function down(e){
	if((document.layers && e.which!=1) || (document.all && event.button!=1)) return true; // Enables the right mousebutton		
	getMouse(e);
	startY = (mouseY - dragT);
	
	// If click on up-arrow
	if(mouseX >= upL && (mouseX <= (upL + upW)) && mouseY >= upT && (mouseY <= (upT + upH))){
		clickUp = true;
		return scrollUp();
	}	
	// Else if click on down-arrow
	else if(mouseX >= downL && (mouseX <= (downL + downW)) && mouseY >= downT && (mouseY <= (downT + downH))){
		clickDown = true;
		return scrollDown();
	}
	// Else if click on scrollbar
	else if(mouseX >= dragL && (mouseX <= (dragL + dragW)) && mouseY >= dragT && (mouseY <= (dragT + dragH))){
		clickDrag = true;
		return false;
	}
	else if(mouseX >= dragL && (mouseX <= (dragL + dragW)) && mouseY >= rulerT && (mouseY <= (rulerT + scrollH))){
		// If click above drag
		if(mouseY < dragT){
			clickAbove = true;
			clickUp = true;
			return scrollUp();
		}
		// Else click below drag
		else{
			clickBelow = true;
			clickDown = true;
			return scrollDown();
		}
	}
	// If no scrolling is to take place
	else{
		return true;
	}
}

// Drag function
function move(e){
	if(clickDrag){
		getMouse(e);
		dragT = (mouseY - startY);
		
		if(dragT < (rulerT))
			dragT = rulerT;		
		if(dragT > (rulerT + scrollH - dragH))
			dragT = (rulerT + scrollH - dragH);
		
		contentT = ((dragT - rulerT)*(1/scrollLength));
		contentT = eval('-' + contentT);

		moveTo();
		
		// So ie-pc doesn't select gifs
		if(IE4)
			return false;		
	}
}


function up(){
	clearTimeout(timer);
	// Resetting variables
	clickUp = false;
	clickDown = false;
	clickDrag = false;
	clickAbove = false;
	clickBelow = false;
	return true;
}

// Reads content layer top
function getT(){
	if(IE4)
		contentT = document.all.content.style.pixelTop;
	else if(NS4)
		contentT = document.contentClip.document.content.top;
	else if(NS6)
		contentT = parseInt(document.getElementById("content").style.top);
}

// Reads mouse X and Y coordinates
function getMouse(e){
	if(IE4){
		mouseY = event.clientY;
		mouseX = event.clientX;
	}
	else if(NS4 || NS6){
		mouseY = e.pageY;
		mouseX = e.pageX;
	}
}

// Moves the layer
function moveTo(){
	if(IE4){
		document.all.content.style.top = contentT;
		document.all.ruler.style.top = dragT;
		document.all.drag.style.top = dragT;
	}
	else if(NS4){
		document.contentClip.document.content.top = contentT;
		document.ruler.top = dragT;
		document.drag.top = dragT;
	}
	else if(NS6){
		document.getElementById("content").style.top = contentT + "px";
		document.getElementById("drag").style.top = dragT + "px";
		document.getElementById("ruler").style.top = dragT + "px";
	}
}

// Scrolls up
function scrollUp(){
	getT();
	
	if(clickAbove){
		if(dragT <= (mouseY-(dragH/2)))
			return up();
	}
	
	if(clickUp){
		if(contentT < 0){		
			dragT = dragT - (speed*scrollLength);
			
			if(dragT < (rulerT))
				dragT = rulerT;
				
			contentT = contentT + speed;
			if(contentT > 0)
				contentT = 0;
			
			moveTo();
			timer = setTimeout("scrollUp()",25);
		}
	}
	return false;
}

// Scrolls down
function scrollDown(){
	getT();
	
	if(clickBelow){
		if(dragT >= (mouseY-(dragH/2)))
			return up();
	}

	if(clickDown){
		if(contentT > -(contentH - contentClipH)){			
			dragT = dragT + (speed*scrollLength);
			if(dragT > (rulerT + scrollH - dragH))
				dragT = (rulerT + scrollH - dragH);
			
			contentT = contentT - speed;
			if(contentT < -(contentH - contentClipH))
				contentT = -(contentH - contentClipH);
			
			moveTo();
			timer = setTimeout("scrollDown()",25);
		}
	}
	return false;
}

// reloads page to position the layers again
function reloadPage(){
	location.reload();
}

// Preload
function eventLoader(){
	if(IE4){
		// Up-arrow X and Y variables
		upL = document.all.up.style.pixelLeft + MainDiv.style.pixelLeft;
		upT = document.all.up.style.pixelTop + MainDiv.style.pixelTop;
		// Down-arrow X and Y variables
		downL = document.all.down.style.pixelLeft + MainDiv.style.pixelLeft;
		downT = document.all.down.style.pixelTop + MainDiv.style.pixelTop;
		// Scrollbar X and Y variables
		dragL = document.all.drag.style.pixelLeft + MainDiv.style.pixelLeft;
		dragT = document.all.drag.style.pixelTop + MainDiv.style.pixelTop;
		// Ruler Y variable
		rulerT = document.all.ruler.style.pixelTop + MainDiv.style.pixelTop;		
		// Height of content layer and clip layer
		contentH = document.all.content.offsetHeight;
		contentClipH = document.all.contentClip.offsetHeight;
	}
	else if(NS4){
		// Up-arrow X and Y variables
//		upL = document.up.left + document.MainDiv.left;
//		upT = document.up.top + document.MainDiv.top;
		upL = document.up.left;
		upT = document.up.top;
		// Down-arrow X and Y variables
//		downL = document.down.left + document.MainDiv.left;
//		downT = document.down.top + document.MainDiv.top;
		downL = document.down.left;
		downT = document.down.top;
		// Scrollbar X and Y variables
//		dragL = document.drag.left + document.MainDiv.left;
//		dragT = document.drag.top + document.MainDiv.top;
		dragL = document.drag.left;
		dragT = document.drag.top;
		// Ruler Y variable
//		rulerT = document.ruler.top + document.MainDiv.top;
		// Height of content layer and clip layer
		contentH = document.contentClip.document.content.clip.bottom;
		contentClipH = document.contentClip.clip.bottom;
	}
	else if(NS6){
		// Up-arrow X and Y variables
		upL = parseInt(document.getElementById("up").style.left) + parseInt(document.getElementById("MainDiv").style.left);
		upT = parseInt(document.getElementById("up").style.top) + parseInt(document.getElementById("MainDiv").style.top);
		// Down-arrow X and Y variables
		downL = parseInt(document.getElementById("down").style.left) + parseInt(document.getElementById("MainDiv").style.left);
		downT = parseInt(document.getElementById("down").style.top) + parseInt(document.getElementById("MainDiv").style.top);
		// Scrollbar X and Y variables
		dragL = parseInt(document.getElementById("drag").style.left) + parseInt(document.getElementById("MainDiv").style.left);
		dragT = parseInt(document.getElementById("drag").style.top) + parseInt(document.getElementById("MainDiv").style.top);
		// Ruler Y variable
		rulerT = parseInt(document.getElementById("ruler").style.top) + parseInt(document.getElementById("MainDiv").style.top);
		// Height of content layer and clip layer
		contentH = document.getElementById("content").offsetHeight;
		contentClipH = document.getElementById("contentClip").offsetHeight;
		document.getElementById("content").style.top = 0 + "px";
	}
	// Number of pixels scrollbar should move
	scrollLength = ((scrollH-dragH)/(contentH-contentClipH));
	// Initializes event capturing
	if(NS4){
		document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP)
		window.onresize = reloadPage;
	}
	document.onmousedown = down;
	document.onmousemove = move;
	document.onmouseup = up;
}

