var array_menus = ['menu_oro','menu_app','menu_sof'];
var array_descrip = ['P&aacute;ginas sobre Oropesa', 'Secciones de la web','P&aacute;ginas sobre programaci&oacute;n' ];

var esExplorer = (document.all && navigator.userAgent.indexOf('MSIE')!=-1 && navigator.userAgent.indexOf('Opera')==-1);

var esOpera = (navigator.userAgent.indexOf('Opera')!=-1);
var submenuAlr = [
		['../paginas_oropesa/alr_alcanizo.htm','Alca&ntilde;izo','alr'],
		['../paginas_oropesa/alr_alcolea.htm','Alcolea','alr'],
		['../paginas_oropesa/alr_azutan.htm','Azut&aacute;n','alr'],
		['../paginas_oropesa/alr_caleruela.htm','Caleruela','alr'],
		['../paginas_oropesa/alr_calzada.htm','Calzada','alr'],
		['../paginas_oropesa/alr_corchuela.htm','Corchuela','alr'],
		['../paginas_oropesa/alr_herreruela.htm','Herreruela','alr'],
		['../paginas_oropesa/alr_lagartera.htm','Lagartera','alr'],
		['../paginas_oropesa/alr_puente.htm','Puente','alr'],
		['../paginas_oropesa/alr_rosarito.htm','Rosarito','alr'],
		['../paginas_oropesa/alr_tietar.htm','Ti&eacute;tar','alr'],
		['../paginas_oropesa/alr_torralba.htm','Torralba','alr'],
		['../paginas_oropesa/alr_torrico.htm','Torrico','alr'],
		['../paginas_oropesa/alr_valdeverdeja.htm','Valdeverdeja','alr'],
		['../paginas_oropesa/alr_ventas.htm','Ventas de San Juli&aacute;n','alr']];

var submenuMon = [
		['../paginas_oropesa/mon_igleasun.htm','Iglesia de la Asunci&oacute;n','mon'],
		['../paginas_oropesa/mon_palacast.htm','Palacio y Castillos','mon'],
		['../paginas_oropesa/mon_csanbern.htm','Capilla de S. Bernardo','mon'],
		['../paginas_oropesa/mon_convmise.htm','Conv. Misericordias','mon'],
		['../paginas_oropesa/mon_plaznava.htm','Plaza del Navarro','mon'],
		['../paginas_oropesa/mon_otroslug.htm','Otros','monotr']];
var submenuMonOtr = [
		['../paginas_oropesa/otros_ayunviej.htm','Ayuntamiento Viejo','monotr'],
		['../paginas_oropesa/otros_colejesu.htm','Colegio de Jesu&iacute;tas','monotr'],
		['../paginas_oropesa/otros_ermipeni.htm','Ermita de Pe&ntilde;itas','monotr'],
		['../paginas_oropesa/otros_hospviej.htm','Hospital Viejo','monotr'],
		['../paginas_oropesa/otros_museplat.htm','Museo Plat&oacute;n P&aacute;ramo','monotr'],
		['../paginas_oropesa/otros_arqupopu.htm','Arquitectura popular','monotr'],
		['../paginas_oropesa/otros_monteagu.htm','Molino de Monteagudo','monotr'],
		['../paginas_oropesa/otros_puenroma.htm','Puente romano','monotr']];

var mouse_pos_x;
var mouse_pos_y;
var width_browser;
var height_browser;

document.onmousemove = moveHandler;
//document.onclick = moveHandler;
function moveHandler(evt) {
     if (!evt) {
        evt = window.event;
     }
     mouse_pos_x = evt.clientX;
	 mouse_pos_y = evt.clientY;
}


/*
if (typeof document.oncontextmenu == "object") {
     if (document.all) {
        document.onmousedown = captureMousedown;
     }
     else {
        document.oncontextmenu = captureMousedown;
     }
}
else {
     window.oncontextmenu = captureMousedown;
}

function captureMousedown(evt) {
     var mouseClick = (evt) ? evt.which : window.event.button;

     if (mouseClick==1 || mouseClick==2 || mouseClick==3) {
        alert("menu contextual. Se puede poner un div");
        return false;
     }
}

*/



function setActiveStyleSheet(title) {
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
     if(a.getAttribute("rel").indexOf("style") != -1
        && a.getAttribute("title")) {
       a.disabled = true;
       if(a.getAttribute("title") == title) a.disabled = false;
     }
   }
}






function do_onload() {
	width_browser = getViewportSize().x;
	height_browser = getViewportSize().y;
	for (var i=0;i<array_menus.length;i++) {
		document.getElementById(array_menus[i]).style.display='none';
	}
	// Colocamos posicion de footer como absolute para exploter
	//if (document.all && navigator.userAgent.indexOf('MSIE')!=-1 && navigator.userAgent.indexOf('Opera')==-1) { // IE only
	if (esExplorer) { // IE only
		document.all.footer.style.position = "absolute";
		document.all.footer.style.top = (height_browser - 62)+'px';
		setActiveStyleSheet('cssex');
		document.getElementById('let_oro').src='let_oro.png'; //'letrero_oropesa2.png';
		document.getElementById('let_sit').src='let_sec.png'; //'letrero_sitios2.png';
		document.getElementById('let_sof').src='let_sof.png'; //'letrero_software2.png';
		document.getElementById('closebt_1').src='cerrar_vent_exp.png'; //'letrero_oropesa2.png';
		document.getElementById('closebt_2').src='cerrar_vent_exp.png'; //'letrero_sitios2.png';
		document.getElementById('closebt_3').src='cerrar_vent_exp.png'; //'letrero_software2.png';
		document.all.let_oro.style.border='1px #000 solid';
		document.all.let_sit.style.border='1px #000 solid';
		document.all.let_sof.style.border='1px #000 solid';
		document.all.header_left.style.backgroundImage="url('./cabecera_left_explorer.png')";
	}
	else {
		setActiveStyleSheet('css');
	}
	// Recolocamos frame para mostrar elementos
	resize_frame();
}



function open_rollover (menu) {
	var menustyle = document.getElementById(menu).style;
	var widthmenu = 200;
	if (menustyle.display != "block") { menustyle.display = "block";	}
	for (var i=0;i<array_menus.length;i++) { if (array_menus[i]!=menu) document.getElementById(array_menus[i]).style.display='none'; }
	if ( (mouse_pos_x+widthmenu+10) > width_browser) {
		menustyle.left = (width_browser-widthmenu-10)+'px';
	}
	else {
		menustyle.left = mouse_pos_x+'px';
	}
	menustyle.top = mouse_pos_y+'px';
	return true;
}
function close_rollover (zap) {
  var abra = document.getElementById(zap).style;
  if (abra.display == "block") { abra.display = "none";  }
  return true;
}



function pon_descripcion (tit) {
	if (!esExplorer) {
		var width_descripcion = 250;
		var div_descripcion = document.getElementById('descripcion_titulo');
		for (var i=0;i<array_menus.length;i++) { if (array_menus[i]==tit) div_descripcion.innerHTML=array_descrip[i]; }
		div_descripcion.style.display='block';
		if ( (mouse_pos_x+width_descripcion+10) > width_browser) {
			div_descripcion.style.left = (width_browser-width_descripcion-10)+'px';
		}
		else {
			div_descripcion.style.left = (mouse_pos_x+10)+'px';
		}
		div_descripcion.style.top = (mouse_pos_y+10)+'px';
	}
}
function quita_descripcion (tit) {
	if (!esExplorer) {
		var div_descripcion = document.getElementById('descripcion_titulo');
		for (var i=0;i<array_menus.length;i++) { div_descripcion.innerHTML=''; }
		div_descripcion.style.display='none';
	}
}

















function getViewportWidth() { 
	var helper; 
	if (null == (helper = document.getElementById('styleSwapHelper'))) { 
		var helper = document.createElement('div'); 
		helper.style.position = 'absolute'; 
		helper.style.margin = '0'; 
		helper.style.padding = '0'; 
		helper.style.right = '0'; 
		helper.style.width = '10px'; 
		document.getElementsByTagName('body')[0].appendChild(helper); 
	} 
	return helper.offsetLeft + 10; 
} 

function getViewportSize() { 
	var x, y; 
	if (self.innerHeight) { // MOS 
		y = self.innerHeight; 
		x = self.innerWidth; 
	} else if (document.documentElement && document.documentElement.clientWidth) { // IE6 Strict 
		x = document.documentElement.clientWidth; 
		y = document.documentElement.clientHeight; 
	} else if (document.body.clientHeight) { // IE quirks 
		y = document.body.clientHeight; 
		x = document.body.clientWidth; 
	} 
	return {x: x, y: y}; 
} 


function resize_frame() {
	width_browser = getViewportSize().x;
	height_browser = getViewportSize().y;
	// Obtenemos anchos para posicionar algunos elementos
	var marco_frame = document.getElementById('pagina_marco');
	var div_lateral = document.getElementById('lateral');
	var div_home = document.getElementById('texto_home');
	var i_frame = document.getElementById('frame');
	var ancho_frame = (width_browser - (120+15)); // left del frame + margen derecho
	var ancho_frame = (width_browser - (120+100)); // left del frame + margen derecho
	var alto_frame  = (height_browser - (90+80));  // top del frame + margen inferior
	// var ancho_frame = (getViewportSize().x - (120+15)); // left del frame + margen derecho
	// var ancho_frame = (getViewportSize().x - (120+100)); // left del frame + margen derecho
	// var alto_frame  = (getViewportSize().y - (90+80));  // top del frame + margen inferior

	div_lateral.style.height = alto_frame+'px';
	div_home.style.width =  ancho_frame+'px';
	div_home.style.height = alto_frame+'px';
	marco_frame.style.width =  ancho_frame+'px';
	marco_frame.style.height = alto_frame+'px';
	i_frame.style.top = '20px';
	i_frame.style.width =  (ancho_frame-5)+'px';
	i_frame.style.height = (alto_frame-22)+'px';
	//alert ('iframe de ('+i_frame.style.width+','+i_frame.style.height+')\nmarco de ('+marco_frame.style.width+','+marco_frame.style.height+')' );
	if (esExplorer) i_frame.style.top = '0px';
}





function muestra_pagina (fichero,subm) {
	// Recolocamos frame para mostrar elementos
	resize_frame();
	/* var contenido = '<html><head><style>p {color:#F00;}</style></head><body><p>hola mundo</p><br/></body></html>'; */
	// var fichero = 'pagina_incluida.html';
	var texto_home = document.getElementById('texto_home');
	var pagina = document.getElementById('pagina_marco');
	var frame = document.getElementById('frame');
	frame.innerHTML = '';
	
	
	//* -- comentado para ponel llamada ajax 
	var miFrame = document.createElement('iframe');
	miFrame.frameBorder = '0';
	miFrame.style.top='0px';
	//miFrame.height='542px';miFrame.width='590px';
	miFrame.height='100%';miFrame.width='100%';
	miFrame.src = fichero;
	frame.appendChild(miFrame);
	if (subm!='') {
		poner_submenu(subm);
	}
	else {
		quitar_submenu();
	}
	/* -- */
	
	/*  LLamada tipo ajax (no va)
	doRequest(fichero,'GET','',poner_pagina,'text');
	/*  */
	
    //	pagina.innerHTML = '<iframe src="'+fichero+'">< /iframe>';
	//cerramos los menus
	for (var i=0;i<array_menus.length;i++) { document.getElementById(array_menus[i]).style.display='none'; }
	pagina.style.display='block';
	texto_home.style.display='none';
	return true;
}

function oculta_pagina () {
	var texto_home = document.getElementById('texto_home');
	var pagina = document.getElementById('pagina_marco');
	var frame = document.getElementById('frame');
	for (var i=0;i<array_menus.length;i++) { document.getElementById(array_menus[i]).style.display='none'; }
	frame.innerHTML = '';
	pagina.style.display='none';
	texto_home.style.display='block';
	quitar_submenu();
	return true;
}


function poner_submenu (subm) {
	var espacio = document.getElementById('submenu');
	var inner = '';
	if (subm=='alr') {
		for (var i=0;i<submenuAlr.length;i++) {
			inner+='<li>'+'<a href="javascript:void%200" onclick="muestra_pagina(\''+submenuAlr[i][0]+'\',\''+submenuAlr[i][2]+'\');return false;">'+submenuAlr[i][1]+'</a></li>';
		}
		inner = '<p>Alrededores</p><ul>'+inner+'</ul>';
	}
	else if (subm=='mon') {
		for (var i=0;i<submenuMon.length;i++) {
			inner+='<li>'+'<a href="javascript:void%200" onclick="muestra_pagina(\''+submenuMon[i][0]+'\',\''+submenuMon[i][2]+'\');return false;">'+submenuMon[i][1]+'</a></li>';
		}
		inner = '<p>Monumentos</p><ul>'+inner+'</ul>';
	}
	else if (subm=='monotr') {
		for (var i=0;i<submenuMonOtr.length;i++) {
			inner+='<li>'+'<a href="javascript:void%200" onclick="muestra_pagina(\''+submenuMonOtr[i][0]+'\',\''+submenuMonOtr[i][2]+'\');return false;">'+submenuMonOtr[i][1]+'</a></li>';
		}
		inner = '<p>Otros lugares de interes</p><ul>'+inner+'</ul>';
	}
	espacio.style.display='block';
	espacio.innerHTML=inner;
}


function quitar_submenu () {
	var espacio = document.getElementById('submenu');
	espacio.innerHTML='';
	espacio.style.display='none';
}













function poner_pagina() {
	var texto = request.responseText;
	var frame = document.getElementById('frame');
	alert ('entra en ponerpagina');
	frame.innerHTML = texto;
}




function doRequest(url,method,queryString,callback,responsetype) {
	alert ('url='+url);
	var myRequest=null;
    if(window.XMLHttpRequest){             // Mozilla-based browsers
        myRequest = new XMLHttpRequest(  );
    } else if (window.ActiveXObject){     // Exploter
	    var aVersions = ["Msxml2.XMLHttp.5.0","Msxml2.XMLHttp.4.0","Msxml2.XMLHttp.3.0","Msxml2.XMLHttp","Microsoft.XMLHttp"];
	    for (var i = 0; i < aVersions.length; i++) {
	        try { myRequest=new ActiveXObject(aVersions[i]);
	        } catch (oError) { } //Do nothing
	    }
	    if (!myRequest) alert ("MSXML is not installed.");
    }
    //initialization succeeded
    if(myRequest){
		try {
			// Ponemos funcion que manejara la respuesta
			//myRequest.onreadystatechange=manejadorRespuesta;
			myRequest.onreadystatechange=function () {
				if (myRequest.readyState == 4) {	
					alert ('myRequest.readyState='+myRequest.readyState)
				    if(myRequest.status == 200){
						if (responsetype=='xml') {
							a= eval (callback+'(myRequest)');
						} else {
							//alert ('llamamos a '+callback);
							alert (callback+'(myRequest)');
							eval (callback+'(myRequest)');
						}
					} else {
						alert ('El status para readyState='+myRequest.readyState+
						       ' es :'+myRequest.status+'('+myRequest.statusText+')'+
							   '\nProblema: comunicacion entre XMLHttpRequest y '+url+' en el server.');
					}
				}
			};
			if (method.toUpperCase()=='POST') {
				myRequest.open("POST",url,true); //asynch=true
			    // Set the Content-Type header for a POST request 
			    myRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
			    myRequest.send(queryString);
			}
			else {
				myRequest.open("GET",url,true); //asincrono=false
			    myRequest.send(null);
			}
		} catch (errv) {
			alert("EXCEPTION en initReq:\n"+"Error:"+errv.message+"\nNo continuara el codigo");
		}
    } else {
        alert("El browser no puede iniciar el XMLHttpRequest. Pasate a Firefox");
    }
	
}








