////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

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_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_findObj(n, d) { //v3.0
  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_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 MWbuscapos(id, vEst, base) {
var busca = '';

	for(var i=1; i<vEst.length; i++) {
		vaux = vEst[i][0].split(',');
		if(vaux[0]==id) return(base + ((base=='') ? '' : '-') + i);
	}

	for(var i=1; i<vEst.length; i++) {
		busca = MWbuscapos(id, vEst[i], '')
		if(busca!='') return(base + ((base=='') ? '' : '-') + i + '-' + busca); 
	}

	return('');
}




////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

var id_n1;
var id_n2;
var id_n3;

var pos, vpos;
var pos_n1;
var pos_n2;
var pos_n3;

var plant_noticias;


function genera_entorno() {
	
	id_n1 = parseInt(vp[0].split(',')[0],10);
	id_n2 = (vp.length>1) ? parseInt(vp[1].split(',')[0],10) : -1;
	id_n3 = (vp.length>2) ? parseInt(vp[2].split(',')[0],10) : -1;

	pos = MWbuscapos(id_pagina, vm, '');

	vpos = (pos=='') ? new Array : pos.split('-');
	pos_n1 = (vpos.length==0) ? 1 : parseInt(vpos[0],10);
	pos_n2 = (vpos.length>1) ? parseInt(vpos[1],10) : -1;
	pos_n3 = (vpos.length>2) ? parseInt(vpos[2],10) : -1;
	
	

	//Enlaces a las 6 familias
		genera_enlaces_principales();



	if(id_pagina!=1) {
		
		plant_noticias = (document.getElementById('div_menun3')) ? false : true;

		//Título de nivel 1
			var vec = vm[pos_n1][0].split(',');
			document.getElementById('div_titulon1').innerHTML = unescape(vec[1]).toUpperCase();

		//Menú izquierdo
			genera_menun2();

		//Menú nivel 3 - En plantilla noticias no
			if(!plant_noticias) genera_menun3();

		//Título del contenido
			genera_titulo();

		//Imagen de área resaltada
			if(pos_n1<=6) document.getElementById('Image'+pos_n1).src = 'imgs/' + pos_n1 + 'on' + cadIdioma + '.gif';
		
		//Botones de navegación entre noticias
			if(plant_noticias) genera_botones_nav();

	}
}



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function genera_enlaces_principales() {
	var vec = vm;
	for(var i=1; i<=6; i++) {
		var vaux1 = vm[i][0].split(',');
		if(vm[i].length>1) {
			var vaux = vm[i][1][0].split(',');
			document.getElementById('enl' + i).href = 'default.asp?id=' + vaux[0];
            /*
			if(document.getElementById('enl' + i + '_2')) {
				document.getElementById('enl' + i + '_2').href = 'default.asp?id=' + vaux[0];
				document.getElementById('enl' + i + '_2').innerText = unescape(vaux1[1]).toUpperCase();
			}
            */
		} else {
			var vaux = vm[i][0].split(',');
			document.getElementById('enl' + i).href = 'default.asp?id=' + vaux[0];
			/*
            if(document.getElementById('enl' + i + '_2')) {
				document.getElementById('enl' + i + '_2').href = 'default.asp?id=' + vaux[0];
				document.getElementById('enl' + i + '_2').innerText = unescape(vaux1[1]).toUpperCase();
			}
            */
		}
	}
}



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function genera_menun2() {
	var vaux = vm[pos_n1];
	for(var i=1, cad = ''; i<vaux.length; i++) {
		var vec = vaux[i][0].split(',');
		if(vec[2]=='1') cad += '<tr><td><A href="default.asp?id=' + vec[0] + '" class=menu>:: ' + unescape(vec[1]).toUpperCase() + '</A></td></tr>';
	}
	if(cad!='') {
		cad = '<table width="140" border=0 cellspacing="0" cellpadding="3">' + cad + '</table>';
		document.getElementById('div_menun2').innerHTML = cad;
	}
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function genera_menun3() {
	if(pos_n2>-1) {
		var vaux = vm[pos_n1][pos_n2];
		for(var i=1, cad = ''; i<vaux.length; i++) {
			var vec = vaux[i][0].split(',');
			if(vec[2]=='1') cad += ((cad=='') ? '' : ' | ') + '<A href="default.asp?id=' + vec[0] + '" class=seccs>' + unescape(vec[1]) + '</A>';
		}
		if(cad!='') document.getElementById('div_menun3').innerHTML = cad;
	}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function genera_titulo() {
	var titulo_n2 = '';
	
	if(plant_noticias) {
		if(pos_n3>-1) {
			var vec = vm[pos_n1][pos_n2][pos_n3][0].split(',');
			titulo_n2 = unescape(vec[1]).toUpperCase();
		} else {
			var vec = vm[pos_n1][pos_n2][0].split(',');
			var cadtit = (idioma==1) ? 'TITULARES' : 'NEWS';
			var caddia = (idioma==1) ? 'MI DIARIO' : 'MY DIARY';
			titulo_n2 = ((id_n1==2) ? cadtit : caddia) + ' :: ' + unescape(vec[1]).toUpperCase();
			//titulo_n2 = unescape(vec[1]).toUpperCase();
		}
	} else {
		if(pos_n2>-1) {
			var vec = vm[pos_n1][pos_n2][0].split(',');
			titulo_n2 = unescape(vec[1]).toUpperCase();
		}
	}

	document.getElementById('div_titulon2').innerHTML = titulo_n2;
}




////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function genera_botones_nav() {
	
	//Botones de navegación anterior y siguiente
		if(pos_n3>-1) {
			var vaux = vm[pos_n1][pos_n2];
			if(pos_n3>1) {
				var pos_ant = pos_n3-1;
				var vec = vaux[pos_ant][0].split(',');				
				for( ; pos_ant>0 && vec[2]=='2'; pos_ant--) {
					pos_ant--;
					if(pos_ant > 0) vec = vaux[pos_ant][0].split(',');
				}
				if(vec[2]!='2') {
					document.getElementById('div_ant').style.visibility = 'visible';
					document.getElementById('a_ant').href = 'default.asp?id=' + vec[0];
					document.getElementById('img_ant').href = 'default.asp?id=' + vec[0];
				}
			}
			if(pos_n3<vaux.length-1) {
				var pos_sig = pos_n3+1;
				var vec = vaux[pos_sig][0].split(',');
				for( ; pos_sig<vaux.length && vec[2]=='2'; ) {
					pos_sig++;
					if(pos_sig<vaux.length) {
						vec = vaux[pos_sig][0].split(',');
					}
				}
				if(vec[2]!='2') {
					document.getElementById('div_sig').style.visibility = 'visible';
					document.getElementById('a_sig').href = 'default.asp?id=' + vec[0];
					document.getElementById('img_sig').href = 'default.asp?id=' + vec[0];
				}
			}
		}
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function abrirGaleria(path) {
	window.open('galeria.asp?carpeta='+path, null, 'menubar=no, dependent=no, height=540, width=940, resizable=no, location=no, status=no');
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

