// JavaScript Document


var popAct = "";


function showPopUp(wich)
{
		clearTimeout(timer);
		
		if((popAct != "")&&(popAct != wich))
		{
			hidePopUp(popAct);
		}
		
		$('#'+wich).animate({
				width: '480',
				height: '290'
			}, 400 );
		
		
		popAct = wich;
	
}

function hidePopUp(wich)
{

	panelToHide = document.getElementById(wich);
	
	if(panelToHide.style.width != '0px')
	{
		$('#'+wich).animate(
			{
				width: '0',
				height: '0'
			},
			300
		)
	}
		
}

var timer = null;

function hidePopUpTimer(wich)
{

	timer = setTimeout("hidePopUp('"+wich+"')",300);
}

function startTimer()
{
	timer = setTimeout("hidePopUp('"+popAct+"')",300);
}

function stopTimer()
{
	clearTimeout(timer);
}

function changeIMG(img,stado)
{
	if(stado)
	{
		document.images[img].src = "images/header_"+img+"_"+stado+".png";
	}else{
		document.images[img].src = "images/header_"+img+".png";
	}
}



//	----------------	HOME	----------------	//
function cambiaStyleNew(ide,stado)
{
	if(stado)
	{
		
		//BG
		document.getElementById('new'+ide).className = "itNoticiaOver";
		
		//Title
		document.getElementById('titnew'+ide).className = "titleOver";
			
	}else{
		//BG
		document.getElementById('new'+ide).className = "itNoticia";
		
		//Title
		document.getElementById('titnew'+ide).className = "title";
	}
}

function cambiaStyleDestacado(ide,stado)
{
	if(stado)
	{
		document.getElementById('titdest'+ide).className = "titDestOver";
		
	}else{
		document.getElementById('titdest'+ide).className = "titDest";
		
	}
}

function changeInfo(ide,stado,ruta)
{
	rutaIMG = "";
	
	if(ruta)
	{
		rutaIMG = ruta;
	}
	
	if(stado)
	{
		document.images['masinfo'+ide].src = rutaIMG+"images/masinfoover.jpg";
		
	}else{
		document.images['masinfo'+ide].src = rutaIMG+"images/masinfo.jpg";
		
	}
}


//	----------------	CONCESIONARIOS	----------------	//

var slideIni = 0;

function showComunidad(valor)
{
	panelToHide = document.getElementById("com"+valor);
	
	
	for(i=0;i<comunidadesArr.length;i++)
	{
		if((comunidadesArr[i] == valor)||(valor==0))
		{
			if( $('#com'+comunidadesArr[i]).css("display")=="none" )
			{
					 $('#com'+comunidadesArr[i]).slideDown("slow");
			}
		}
	}
	
	if(valor!=0)
	{
	
	if(slideIni == 1)
	{
		setTimeout("hideComunidades("+valor+")",500);
	}else{
		slideIni = 1;
		hideComunidades(valor);
	}
	
	}
	
}

function hideComunidades(valor)
{
	for(i=0;i<comunidadesArr.length;i++)
	{
		if(comunidadesArr[i] != valor)
		{
			$('#com'+comunidadesArr[i]).slideUp();
		}
	}
	
}


//	----------------	NOTICIAS	----------------	//
function getXMLHttpRequest(){
   var Versiones = [ "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp","Microsoft.XMLHttp"];
	 var aVersions = [ "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp","Microsoft.XMLHttp"]; 
   if (window.XMLHttpRequest){
      return new XMLHttpRequest();
   }
   else if(window.ActiveXObject){
      for(var i = 0; i < aVersions.length; i++){
         try{
            var oXmlHttp = new ActiveXObject(aVersions[i]);
            return oXmlHttp;
         }
         catch(error){
      
         }
      }
   }
}

function getHistoricoNews(pagAct)
{
	var xmlhttp = getXMLHttpRequest();
		
	xmlhttp.onreadystatechange = function() 
	{
		if (xmlhttp.readyState == 4) 
		{
			document.getElementById("HistoricoNews").innerHTML = xmlhttp.responseText;
		}
	}

	xmlhttp.open("POST", "getHistorico.php", true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	xmlhttp.send("pagAct="+pagAct);
}


function getNoticiasPanel(idNews)
{
	var xmlhttp = getXMLHttpRequest();
		
	xmlhttp.onreadystatechange = function() 
	{
		if (xmlhttp.readyState == 4) 
		{
			document.getElementById("noticiasPanel").innerHTML = xmlhttp.responseText;
		}
	}

	xmlhttp.open("POST", "getNoticiasPanel.php", true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	xmlhttp.send("idNoticia="+idNews);
}