var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);

function dropmenu(mostrar,item){
	var sub_lista=item.getElementsByTagName("ul");
	if(sub_lista[0]){
		if(mostrar==0){
			sub_lista[0].style.display="none";
			//for (var i=1; i<sub_lista.length; i++){
			//	sub_lista[i].style.display="none"
			item.className="";
			//}
		}else{
			sub_lista[0].style.display="block";
			sub_lista[0].className="ulhover";
			item.className="lihover";
		}
	}
}

var activo;

function menuclose(){
	if(activo!=null){
		activo.className="nav-desplegable";
		var item_act=activo.parentNode;
		var sub_lista_act=item_act.getElementsByTagName("ul");
		var as_act=item_act.getElementsByTagName("a");
		if(as_act[0]){
			for (var i=0; i<as_act.length; i++){
				if(as_act[i].className=="nav-cerrable"){
					as_act[i].className="nav-desplegable";
				}
			}
		}
		if(sub_lista_act[0]){
			for (var i=0; i<sub_lista_act.length; i++){
				Effect.BlindUp(sub_lista_act[i],{duration:0.3, queue: 'end'});
			}
		}
		activo=null;
	}
}


function submenu(a,lev1){
	if(lev1==1){
		if(activo!=a){
			if(activo!=null){
				activo.className="nav-desplegable";
				var item_act=activo.parentNode;
				var sub_lista_act=item_act.getElementsByTagName("ul");
				var as_act=item_act.getElementsByTagName("a");
				if(as_act[0]){
					for (var i=0; i<as_act.length; i++){
						if(as_act[i].className=="nav-cerrable"){
							as_act[i].className="nav-desplegable";
						}
					}
				}
				if(sub_lista_act[0]){
					for (var i=0; i<sub_lista_act.length; i++){
						Effect.BlindUp(sub_lista_act[i],{duration:0.3, queue: 'end'});
					}
				}
			}
			activo=a;
		}
	}
	var item=a.parentNode;
	var sub_lista=item.getElementsByTagName("ul");
	var as=item.getElementsByTagName("a");
	
	if(sub_lista[0]){
			if(sub_lista[0].style.display=="none"){
				a.className="nav-cerrable";

				Effect.BlindDown(sub_lista[0],{duration:0.3});
			}else{
				for (var i=0; i<sub_lista.length; i++){
					Effect.BlindUp(sub_lista[i],{duration:0.3, queue: 'end'});
				}
				if(as[0]){
					for (var i=0; i<as.length; i++){
						if(as[i].className=="nav-cerrable"){
							as[i].className="nav-desplegable";
						}
					}
				}
				
			}
	}
}

function boxbuscar(){
	var boxbuscar=document.getElementById("boxbuscar");
	if(boxbuscar.style.display=="none"){
		Effect.BlindDown(boxbuscar,{duration:0.5, queue: 'end'});
	}else{
		Effect.BlindUp(boxbuscar,{duration:0.5, queue: 'end'});
	}

}

function boxasociados(){
	var boxasociados=document.getElementById("boxasociados");
	if(boxasociados.style.display=="none"){
		Effect.BlindDown(boxasociados,{duration:0.5, queue: 'end'});
	}else{
		Effect.BlindUp(boxasociados,{duration:0.5, queue: 'end'});
	}

}



/* Funciones para slideshow del home */


function start_slideshow() {
	var span_botones=document.getElementById("slideshow_titulos")
	for(var i=0;i<=end_frame;i++){
		span_botones.innerHTML=span_botones.innerHTML+"<a href='#' id='slideshow-titulo-"+i+"' class='slideshow-titulo' onclick='slideshow_goto("+i+"); return false;'>"+swfs_titulos[i]+"</a>";
	}
	
	insert_swf();
}


var start_frame=0;
var frame=0;
var t;


function insert_swf_code(){
var file=swfs[frame];
	for(var i=0;i<=end_frame;i++){
		document.getElementById("slideshow-titulo-"+i+"").className="slideshow-titulo";
	}
	document.getElementById("slideshow-titulo-"+frame+"").className="slideshow-titulo-activo";
return "<object type='application/x-shockwave-flash' width='460' height='320' data='media/flash/"+file+".swf' id='flash-slideshow' name='flash-slideshow'><param name='bgcolor' value='#ffffff' /><param name='movie' value='media/flash/"+file+".swf' /><param name='quality' value='high' /><param name='wmode' value='transparent' /></object>";
}


function insert_swf(){
	var delay=swfs_delays[frame];
	document.getElementById("home_swf").innerHTML=insert_swf_code();
	t=setTimeout(switch_slides(), delay+1000);
}
 
function switch_slides() {
	frame=frame;
	return (function() {
	Effect.Fade('flash-slideshow');
	if (frame == end_frame) { frame = start_frame; } else { frame = frame + 1; }
		t=setTimeout("insert_swf("+frame+");", 1000);
	})
}

function slideshow_pause(){
	document.getElementById("slideshow_pause").style.display="none";
	document.getElementById("slideshow_play").style.display="block";
	clearTimeout(t);
}
function slideshow_play(){
	document.getElementById("slideshow_pause").style.display="block";
	document.getElementById("slideshow_play").style.display="none";
	if (frame == end_frame) { frame = start_frame; } else { frame = frame + 1; }
	insert_swf();
}
function slideshow_goto(goto){
	frame = goto;
	clearTimeout(t);
	insert_swf();
}
function slideshow_next(){
/*	
	document.getElementById("slideshow_pause").style.display="none";
	document.getElementById("slideshow_play").style.display="inline";
	clearTimeout(t);
*/
	clearTimeout(t);
	if (frame == end_frame) { frame = start_frame; } else { frame = frame + 1; }
	document.getElementById("home_swf").innerHTML=insert_swf_code();
}
function slideshow_prev(){
/*
	document.getElementById("slideshow_pause").style.display="none";
	document.getElementById("slideshow_play").style.display="inline";
	clearTimeout(t);
*/
	clearTimeout(t);
	if (frame == start_frame) { frame =end_frame; } else { frame = frame - 1; }
	document.getElementById("home_swf").innerHTML=insert_swf_code();
}


//  ********************   funciones de uso general  ************************************

function fauxpopup(ancho,alto){
	if(document.getElementById("capa").style.display=="block"){
		document.getElementById("capa").style.display="none";
		document.getElementById("fauxpp").style.display="none";
		document.getElementById("fauxpp").innerHTML="";
	}else{
		var arr_pagesize=getPageSize();
		var arr_pagescroll=getPageScroll();
		var top=arr_pagescroll[1]+150;
		var left=(arr_pagesize[0]-ancho)/2;
		document.getElementById("fauxpp").style.top=top+"px";
		document.getElementById("fauxpp").style.left=left+"px";
		document.getElementById("fauxpp").style.width=ancho+"px";
		document.getElementById("fauxpp").style.height=alto+"px";
		document.getElementById("capa").style.height=arr_pagesize[1]+"px";
		
		document.getElementById("capa").style.display="block";
		document.getElementById("fauxpp").style.display="block";
		
	}
}


var divid="";
function ajax_load(caja,url) {
	divid=caja;
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	  alert ("Su navegador no soporta AJAX!");
	  return;
	 } 
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
	
function GetXmlHttpObject() {
  var xmlHttp=null;
  try{// Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
   }
  catch (e){ // Internet Explorer
    try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
    catch (e){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
   }
  return xmlHttp;
}

function stateChanged() {
/*
	if (xmlHttp.readyState==1){//request seteado
		document.getElementById(divid).innerHTML="<p>seteando</p>";
	}
	if (xmlHttp.readyState==2){//request enviado
		document.getElementById(divid).innerHTML="<p>enviado</p>";
	}
	if (xmlHttp.readyState==3){//requesten proceso
		document.getElementById(divid).innerHTML="<p>en proceso</p>";
	}
*/
	if (xmlHttp.readyState==4){//request completo
		document.getElementById(divid).innerHTML=xmlHttp.responseText;
	}
}

function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
