

/************************************************************************************
Versión  
************************************************************************************/



function externalLinks() 
{
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
anchor.target = "_blank";

}
}


function escribe_boton(idioma, title, alt)
{
document.write("<a href='javascript:history.back(1);' title='"+title+"' lang='"+idioma+"'><img src='/comunes/img/wai/final_flecha1.gif' width='16px' height='14px' alt='"+alt+"' /></a>");
}


// escribe los estilos de las capas interiores con 'display:none', en su hoja de estilo
// ya están pero sin 'display'. Si se desactiva javascript aparecerán las capas desplegadas.
//document.write("<style type='text/css'><!--.Sub1{position:relative;background-color:#E7E6D3;width:9.6em;float:left;clear:both;z-index:10;background-image: url(/comunes/img_desarrollo/menu_wai/nivel2.gif);background-repeat: no-repeat;background-position:left top;display:none;}.Sub1_mas{position:relative;background-color:#E7E6D3;width:9.6em;float:left;clear:both;z-index:10;background-image: url(/comunes/img_desarrollo/menu_wai/nivel2_mas.gif);background-repeat: no-repeat;background-position: left top;display:none;}.Sub2{position:relative;background-color:#DBDFD1;width:9.6em;float:left;clear:both;z-index:15;background-image: url(/comunes/img_desarrollo/menu_wai/nivel3.gif);background-repeat: no-repeat;background-position: left top;display:none;}--></style>");


function lib_bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=this.agent.indexOf("Opera")>-1
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}

var bw=new lib_bwcheck()


/************************************************************************************
Cookies
************************************************************************************/
var expDays = 30;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));


function getCookieVal (offset) {  
var endstr = document.cookie.indexOf (";", offset);  
if (endstr == -1)    
endstr = document.cookie.length;  
return unescape(document.cookie.substring(offset, endstr));
}


function GetCookie (name) {  
var arg = name + "=";  
var alen = arg.length;  
var clen = document.cookie.length;  
var i = 0;  
while (i < clen) {    
var j = i + alen;    
if (document.cookie.substring(i, j) == arg)      
return getCookieVal (j);    
i = document.cookie.indexOf(" ", i) + 1;    
if (i == 0) break;   
}  
return null;
}


function SetCookie (name, value) { 

//alert(value); 
var argv = SetCookie.arguments;  
var argc = SetCookie.arguments.length;  
var expires = (argc > 2) ? argv[2] : null;  
var path = (argc > 3) ? argv[3] : null;  
var domain = (argc > 4) ? argv[4] : null;  
var secure = (argc > 5) ? argv[5] : false;  
document.cookie = name + "=" + escape (value) + 
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
((path == null) ? "" : ("; path=" + path )) +  
((domain == null) ? "" : ("; domain=" + domain)) +    
((secure == true) ? "; secure" : "");
}


function DeleteCookie (name) {  
var exp = new Date();  
exp.setTime (exp.getTime() - 1);  
var cval = GetCookie (name);  
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}



function makeMenuObj(obj,nest){
	
	nest=(!nest) ? "":'document.'+nest+'.'										
   	this.css=bw.dom? document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+"document.layers." +obj):0;		
	this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0;	

	this.ref=bw.dom || bw.ie4? document:bw.ns4?eval(nest+"document.layers." +obj+".document"):0;		
	this.x=(bw.ns4 || bw.ns5)? this.css.left:this.css.offsetLeft;
	this.y=(bw.ns4 || bw.ns5)? this.css.top:this.css.offsetTop;


	this.ancho=b_ancho;
	this.b_estoy_pr_sin= b_estoy_pr_sin;
	this.estoy_pr=b_estoy_pr; this.estoy=b_estoy; this.noestoy=b_noestoy;this.status_display=0;		
	this.hideIt=b_hideIt; this.showIt=b_showIt; this.movey=b_movey;
	this.moveIt=b_moveIt; this.moveBy=b_moveBy; this.status=0; 
	this.bgImg=b_bgImg;this.obj = obj + "Object"; eval(this.obj + "=this"); 
	this.clipTo=b_clipTo;
	this.seccion;
	return this
}


function b_ancho(an){this.css.width=an;}
function b_estoy_pr(color){this.css.display="inline"; this.css.borderStyle="solid"; this.css.borderWidth="1px";this.css.borderColor=color; this.status_display=1;this.css.left="-1px"; }
function b_estoy_pr_sin(){this.css.display="inline"; this.css.borderStyle="none"; this.css.borderWidth="1px"; this.status_display=1}
function b_estoy(){this.css.display="inline";this.status_display=1;}
function b_noestoy(){this.css.display="none"; this.status_display=0;}
function b_showIt(){this.css.visibility="visible"; this.status=1}
function b_hideIt(){this.css.visibility="hidden"; this.status=0}
function b_movey(y){this.y=y; this.css.top=this.y}	
function b_moveIt(x,y){this.x=x; this.y=y; this.css.left=this.x;this.css.top=this.y}
function b_moveBy(x,y){this.x=this.x+x; this.y=this.y+y; this.css.left=this.x;this.css.top=this.y}
function b_bgImg(img){if(bw.ie||bw.dom)this.css.backgroundImage="url('"+img+"')"
else this.css.background.src=img
}
function b_clipTo(t,r,b,l,w){if(bw.ns4){this.css.clip.top=t;this.css.clip.right=r
this.css.clip.bottom=b;this.css.clip.left=l
}else{this.css.clip="rect("+t+","+r+","+b+","+l+")"; if(w){this.css.width=r; this.css.height=b}}}




function limpia(texto){
	var a 
	if(texto.substring(0,1)=="0")
	{a=texto.substring(1,2);}
	else
	{a=texto.substring(0,2);}
	return(a)

}


var primera=-1;
var segunda=-1;


function abre(pr,se,seccion){


	//Escribe Cookies
	SetCookie ('sitio',pr ,exp ,"/" ,null,null) 
	SetCookie ('sitio1',se ,exp ,"/" ,null,null) 

//alert(pr);
//alert(se);



	if (primera>-1)
		{
		if(primera!= pr)
		{oSlide[parseInt(primera)].b_estoy_pr_sin();
		for(i=0;i<oSlide[parseInt(primera)].subs;i++)
			{
			oSlide[parseInt(primera)].sub[i].noestoy();
			
			}
		}

		if (segunda>-1)
			{
			for(i=0;i<oSlide[parseInt(primera)].sub[parseInt(segunda)].subs;i++)
			{oSlide[parseInt(primera)].sub[parseInt(segunda)].sub1[i].noestoy();}
			}
		}



	if(pr>-1)
	{
	for(i=0;i<oSlide[parseInt(pr)].subs;i++)
	{oSlide[parseInt(pr)].sub[i].estoy();}
	}


	if(pr>-1 && se >-1)
	{
	oSlide[pr].sub[se].estoy();
	for(i=0;i<oSlide[parseInt(pr)].sub[parseInt(se)].subs;i++)
	{oSlide[parseInt(pr)].sub[parseInt(se)].sub1[i].estoy();}
	}

	primera=pr;
	segunda=se;

	var color;
    	switch(this.seccion)
       	{    	case 'Agricultura': color ="#a9af94";break;
		case 'Ministerio': color ="#a9af94";break;
		case 'Ganaderia': color="#dfb976";break;
		case 'Desarrollo': color="#97a7a7";break;
		case 'Pesca': color="#9aa8b7";break;
		case 'Sig': color="#cfb367";break;
		case 'Estadistica': color="#af9073";break;
		case 'Alimentacion': color="#e7a17a";break;
            default:
             { 
		color="#afafaf";
             }
       	}

	oSlide[parseInt(pr)].estoy_pr(color);




}






function prueba(ruta,color1,color2) 
{
document.write("<style type='text/css'>.Sub1{position:relative;background-color:"+color1+";width:9.6em;float:left;clear:both;z-index:10;background-image: url("+ruta+"nivel2.gif);background-repeat: no-repeat;background-position:left top;display:none;}.Sub1_mas{position:relative;background-color:"+color1+";width:9.6em;float:left;clear:both;z-index:10;background-image:url("+ruta+"nivel2_mas.gif);background-repeat:no-repeat;background-position:left top;display:none;}.Sub2{position:relative;background-color:"+color2+";width:9.6em;float:left;clear:both;z-index:15;background-image:url("+ruta+"nivel3.gif);background-repeat: no-repeat;background-position: left top;display:none;}</style>");
}

function escribe_estilo(ruta,color1,color2,seccion) 
{
this.seccion=seccion;
document.write("<style type='text/css'>.Sub1{position:relative;background-color:"+color1+";width:9.6em;float:left;clear:both;z-index:10;background-image: url("+ruta+"nivel2.gif);background-repeat: no-repeat;background-position:left top;display:none;}.Sub1_mas{position:relative;background-color:"+color1+";width:9.6em;float:left;clear:both;z-index:10;background-image:url("+ruta+"nivel2_mas.gif);background-repeat:no-repeat;background-position:left top;display:none;}.Sub2{position:relative;background-color:"+color2+";width:9.6em;float:left;clear:both;z-index:15;background-image:url("+ruta+"nivel3.gif);background-repeat: no-repeat;background-position: left top;display:none;}</style>");
}


function ajusta() {

    	var ie = (document.all) ? true:false
    	var n6 = (document.getElementById) ? true:false
  	var dd=0;
	var ancho=0;

    if(ie)
      {	
	dd=window.document.body.offsetWidth; 
	ancho=(dd-780-25)/2
	if (ancho<1) {ancho=0}
	}

    else if(n6)
      {
	dd=window.innerWidth;
	ancho=(dd-780-15)/2
	if (ancho<1) {ancho=0}
	}

document.write("<style type='text/css'>#contenedor{position:absolute;width: 48.73em;left:"+ancho+"px;margin-right:0px;margin-top:0px;top:0px;}</style>");
}

function refresca() {

    	var ie = (document.all) ? true:false
    	var n6 = (document.getElementById) ? true:false
  	var dd=0;
	var ancho=0;



    if(ie)
      {	
	dd=window.document.body.offsetWidth; 
	ancho=(dd-780-25)/2
	if (ancho<1) {ancho=0}
	document.all['contenedor'].style.left=ancho;
	}

    else if(n6)
      {
	dd=window.innerWidth;
	ancho=(dd-780-15)/2
	if (ancho<1) {ancho=0}
	document.getElementById("contenedor").style.left=String(ancho)+ 'px';
	}

}



function inicio(){



if(bw.dom!=1){return(false);}


var capas,i,e,a;
var str;
capas=document.getElementsByTagName('li');



var pr, se, te;
var control_sub = -1;
var control_sub1 = -1;
var u =0;

oSlide=new Array();

for(i=0;i<capas.length;i++)
	{


	str=capas[i].id;

	if (str.substring(0,3)=="TJR") 
		{


	pr=limpia(str.substring(3,5));
	se=limpia(str.substring(5,7));
	te=limpia(str.substring(7,9));

	if (se=="XX" && te=="XX")
		{

		oSlide[parseInt(pr)]=new makeMenuObj(capas[i].id);
		oSlide[parseInt(pr)].subs=-1;
		}


	if (pr!="XX" && se!="XX" && te=="XX")
		{
		if (control_sub!=parseInt(pr))
			{
			oSlide[parseInt(pr)].sub=new Array();
			}
		oSlide[parseInt(pr)].sub[parseInt(se)]=new makeMenuObj(capas[i].id);
		control_sub = parseInt(pr);
		oSlide[parseInt(pr)].subs=-1;
		oSlide[parseInt(pr)].subs=oSlide[parseInt(pr)].sub.length;

		}

	if (pr!="XX" && se!="XX" && te!="XX")
		{

		
		if (control_sub1!=parseInt(se) || control_subx!=parseInt(pr) )
			{
			oSlide[parseInt(pr)].sub[parseInt(se)].sub1=new Array();
			}

		oSlide[parseInt(pr)].sub[parseInt(se)].sub1[parseInt(te)]=new makeMenuObj(capas[i].id);
		control_sub1 = parseInt(se);
		control_subx = parseInt(pr);
		oSlide[parseInt(pr)].sub[parseInt(se)].subs=-1;
		oSlide[parseInt(pr)].sub[parseInt(se)].subs=oSlide[parseInt(pr)].sub[parseInt(se)].sub1.length;
		}



	}
	}





var anterior = null
var anterior1 = null

anterior = parseInt(GetCookie ('sitio'));


if (anterior1>=0)
	{anterior1 = parseInt(GetCookie ('sitio1'))}
else
	{anterior1 = -1}



if (anterior!= null) 
	{

	if (parseInt(anterior) <= oSlide.length && parseInt(anterior) >= 0 )
		{


		if (parseInt(anterior1) <= parseInt(oSlide[anterior].subs))
			{
			abre(anterior,anterior1);
			}


		}
	}


externalLinks();



}






