function openMenuDiv(){
    document.all["change"].style.height=heightClose+"%"; //65%
    document.all["abajo"].style.height=menuOpen+"%";  
	document.all["contenido"].style.display="block";
    //document.getElementById('contenido').style.display="block";
}

function closeMenuDiv(){
	document.all["change"].style.height=heightOpen;
	document.all["abajo"].style.height=menuClose;  
	document.all["contenido"].style.display="none";
}


function requestArribaDiv(divId, url){
	sendAjaxRequest(url, updateArribaDiv, 'updateArribaDiv');
}
function requestContentDiv(divId, url){
	sendAjaxRequest(url, updateContentDiv, 'updateContentDiv');
}
function requestDetailDiv(divId, url){
	sendAjaxRequest(url, updateDetailDiv, 'updateDetailDiv');
}


function updateArribaDiv(){
	var myReq = req['updateArribaDiv'];
	if((myReq != null) && (myReq.readyState == 4) && (myReq.status == 200)){
        document.getElementById('change').innerHTML = myReq.responseText;
        
		document.all["change"].style.display="block";
		document.all["arriba"].style.display="none";

		if(doCloseMenu) closeMenuDiv();
	}
}

function updateContentDiv(){
	var myReq = req['updateContentDiv'];
	if((myReq != null) && (myReq.readyState == 4) && (myReq.status == 200)){
        document.getElementById('contenido').innerHTML = myReq.responseText;
        
		document.all["change"].style.display="block";
		document.all["arriba"].style.display="none";

		openMenuDiv();
	}
}

function updateDetailDiv(){
	var myReq = req['updateDetailDiv'];
	if((myReq != null) && (myReq.readyState == 4) && (myReq.status == 200)){
        document.getElementById('change').innerHTML = myReq.responseText;
	}
}


req = new Array();

function sendAjaxRequest(url, callBackFunction, reqName){

	req[reqName] = null;
	
	if(window.XMLHttpRequest){
		req[reqName] = new XMLHttpRequest();
		if(req[reqName]){
			req[reqName].onreadystatechange = callBackFunction;
			try{
				req[reqName].open("GET",url,true);
				req[reqName].send(null);
			}
			catch(e){
				alert(e);
			}
		}
	}
	
	else if(window.ActiveXObject){
		req[reqName] = new ActiveXObject("Microsoft.XMLHTTP");
		if(req[reqName]){
			req[reqName].onreadystatechange = callBackFunction;
			try{
				req[reqName].open("GET",url,true);
				req[reqName].send();
			}
			catch(e){
				alert(e);
			}
		}
	}
}

function showSection(sectionId){
	for(var i=0; i<3; i++){
		if(i==sectionId){
			showdiv("section_" + i);
			hidediv("sectiontab_inact_" + i);
			showdiv("sectiontab_act_" + i);
		}
			
		else{
			hidediv("section_" + i);
			hidediv("sectiontab_act_" + i);
			showdiv("sectiontab_inact_" + i);
		}
	}
}




function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    } else {
        return document[movieName];
    }
}
 

function loadAnimatedSectionByName(name){
	var homeMovie = thisMovie('swf-Inicio');
	if(homeMovie != null && homeMovie.playAnimationByName!=null){
	    try{
    		homeMovie.playAnimationByName(name);
    	   }
    	   catch(e){
		alert(e);
    	   }
	}
	else{
		loadSectionByName(name);
	}
}

function loadSectionByName(name){
	if(name=='Inicio'){
		var homeMovie = thisMovie('swf-Inicio');
		if(homeMovie != null && homeMovie.playAnimationByName!=null){
			return;
		}
	}
	
	//FIXME ESTO DEBE SER DINÁMICO
	switch(name){	
		case 'Productos':
			doCloseMenu = false;
			requestArribaDiv('arriba', '/index.php/sections/sectionInfo/' + name);
			requestContentDiv('contenido', '/index.php/products/menu');
		break;

		case 'Noticias':
			doCloseMenu = false;
			requestArribaDiv('arriba', '/index.php/sections/sectionInfo/' + name);
			requestContentDiv('contenido', '/index.php/news/menu');
		break;

		default:
			doCloseMenu = true;
			requestArribaDiv('arriba', '/index.php/sections/sectionInfo/' + name);
	}
}
	
function loadSolutionCategory(categoryId){
	doCloseMenu = false;
	requestArribaDiv('arriba', '/index.php/categorys/categoryInfo/' + categoryId);
	requestContentDiv('contenido', '/index.php/solutions/menu/0/' + categoryId);
}

function loadSolutionCategoryByName(name){
	doCloseMenu = false;
	requestArribaDiv('arriba', '/index.php/categorys/categoryInfoByName/' + name);
	requestContentDiv('contenido', '/index.php/solutions/menuByName/' + name);	
}

function loadSolution(solutionId, categoryId){

	doCloseMenu = false;
	requestArribaDiv('arriba', '/index.php/solutions/detail/' + solutionId);
	requestContentDiv('contenido', '/index.php/solutions/menu/0/' + categoryId);	
}

function loadProduct(productId){
	doCloseMenu = false;
	requestArribaDiv('arriba', '/index.php/products/detail/' + productId);
	requestContentDiv('contenido', '/index.php/products/menu/');	
}

function loadMap(){
	doCloseMenu = true;
	requestArribaDiv('arriba', '/index.php/welcome/map');
}


function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'inline';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}
