// JavaScript Document
var m = 0;
var idioma;

var heightClose = 54;
var heightOpen = "82%";
var direction = "";
var flashOpen="364px";
var flashClose="49px"; 
var referenceDivIds = new Array();
//referenceDivIds.push('change');
//referenceDivIds.push('modmed');
var background="0";
var divIds = new Array();
//divIds.push('change');
var abajopx = "252px";
var explorer="nada";

var standard =545;
var menuOpen =34;
var menuClose ="6%";



//////////////////////NUEVOOO
var height;
var width;
var j = 0;
var move = true;
var tam;
var direction = 0;
var myWindowWidth;
var myWindowHeight;
var WindowHeight;
var PrincipalHeight;
var page;
var navigatorName = navigator.appName;
var i;
var imagenes = new Array("../images/logo-cabecera.jpg","../images/fondo-cabecera.jpg","../images/fondo_home.jpg");
var lista_imagenes = new Array();

function leerCookie(nombre) {
   a = document.cookie.substring(document.cookie.indexOf(nombre + '=') + nombre.length + 1,document.cookie.length);
   if(a.indexOf(';') != -1)a = a.substring(0,a.indexOf(';'))
   return a; 
}
function scroll()
{    
	unifyDivSizes();
 	 pages = leerCookie("page");
	 
	 var etiquetaScript=document.createElement("script");
               document.getElementsByTagName("head")[0].appendChild(etiquetaScript);
    
     if (navigatorName == "Netscape")
		         {  
		         	tamSol = "90%";
		         	tamNos = "75%";
		         	tamP = "90%";
		         }
		         else
		         {
		         	tamn = ((WindowHeight*50)/100);
		         	tams = ((WindowHeight*34)/100);
		         	
		         	tamSol = tams+"px";
		         	tamNos = tamn+"px";
		         	tam = ((WindowHeight*41)/100);
		         	tamP = tam+"px";
		         }
     if(pages == "nosotros")
   		 etiquetaScript.text="CSBfleXcroll('lista','"+tamNos+"','4');";
	   		else if(pages == "soluciones")
		           	 etiquetaScript.text="CSBfleXcroll('lista','"+tamSol+"','3');";
	           else if(pages == "noticias")
	           		etiquetaScript.text="CSBfleXcroll('lista','"+tamP+"','2');";
	           		else if(pages == "productos")
	           			etiquetaScript.text="CSBfleXcroll('lista','"+tamP+"','1');";
	    
}
function cargarimagenes()
{
	for(i in imagenes)
	{
		lista_imagenes[i] = new Image();
		lista_imagenes[i].src = imagenes[i];
	}
}




function resizeFlash(datoX,datoY) {
	if(document.all && !document.getElementById) {
 		if(datoX!=null) document.all['arriba'].style.pixelWidth = datoX;
 		if(datoY!=null) document.all['arriba'].style.pixelHeight = datoY;
	}else{
		if(datoX!=null) document.getElementById('arriba').style.width = datoX;
		if(datoY!=null) document.getElementById('arriba').style.height = datoY;
	}
}
function appearContent(app,desapp)
{

			document.all[app].style.display="block";
			document.all[desapp].style.display="none";

}
function closeMenu(percent)
{
	document.all['contenido'].style.display="none";
	document.all['change'].style.height=percent;
	
}
function apearDiv(i,percent,modAp,modDis)
{  
	if(i == "3")			//	
	{	
		
		m = 1;
			
			document.all["change"].style.display="block";
			document.all["arriba"].style.display="none";
			document.all['contenido'].style.display="block";
			
		    document.all["abajo"].style.height=menuOpen+"%";  
		  
		    document.all["change"].style.height=heightClose+"%"; //65%
		    
	}
	else if(i == "1")
	{	
		
		m = 1;
		document.all['contenido'].style.display="none";
		document.all["change"].style.display="block";
		document.all["arriba"].style.display="none";
		
		document.all["change"].style.height=heightOpen; //65%
		document.all["abajo"].style.height=menuOpen+"%"; 

	}
	else if(i == "0")		//Contacto
	{
		m = 0;
		
	
		document.all["contenido"].style.display="none";
		document.all["arriba"].style.height=heightOpen;//"92%";
		document.all["abajo"].style.height=menuClose;
	
		document.all["contenido"].style.display="none";
		document.all["change"].style.display="none";
		
		
		document.all["arriba"].style.display="block"
	

  
	}
	else if (i == "5")		//Productos; Noticias; Tecnoligia; Mercadeo; CReatividad
	{
		m = 1;
		
			document.all["change"].style.display="none";
			document.all["arriba"].style.display="block";
			document.all['contenido'].style.display="block";
		    document.all["abajo"].style.height=menuOpen+"%";//heightClose+6+"%";  
			document.all["arriba"].style.height=heightClose+"%"; //65%
		
	}
	else if (i == "6")
	{
		m = 1;
		
			document.all["change"].style.display="block";
			document.all["arriba"].style.display="none";
			document.all["change"].style.height=heightClose+"%"; //65%
		
	}
	else		//Nosotros; Proyectos; Mapa
	{ 
		m = 0;
		
		document.all["contenido"].style.display="none";
		document.all["arriba"].style.display="none";
		document.all["change"].style.display="block";
		document.all["change"].style.height=heightOpen;
		document.all["abajo"].style.height=menuClose;  
		
	}
	
}

function getHeightWindow()
{
	 var myWindowHeight = window.innerHeight;
	 return myWindowHeight;

}

function getWidthWindow()
{
	var myWindowWidth = window.innerWidth;
	 return myWindowWidth;
}


function calledFlash(actions,params,dir)
{
	loadInformation1(actions,params,dir);
}
function loadHome(actions,id,link,title)  //para cargar el home y contactos
{ 					
  	url = urlserver+actions+"?id="+id+"&idiom="+idioma;
	 
	if(window.XMLHttpRequest)
	{// NO IExplorer
		req = new XMLHttpRequest();
			req.onreadystatechange = loadHomeAction;     //el request tiene varios status: 1 sin inicializar, 2 inicializado, 3 cargando, 4 hecho/ejecutado
			try
			{
				req.open("GET",url,true);//true significa asincrono
			}
			catch(e)
			{
				alert(e);
			}
			req.send(null);
	}else
		{
			if(window.ActiveXObject)
				{//IExplorer
					req = new ActiveXObject("Microsoft.XMLHTTP");
					if(req)
					{
						req.onreadystatechange=loadHomeAction;
						req.open("GET",url,true);
						req.send();
					}
				}
		}

 //tracking de google
 //urchinTracker('/'+link+'/');
 link.href="#";
 document.title = title;
}

function loadInformation1(actions,params,dir,back,link,title) //para cargar soluciones y nosotros
{ 

	direction = dir;
	actions='us';
	url = urlserver+actions;
	background = back;
//	alert('actions: '+actions+' params: '+params+' dir: '+dir+' back: '+back+' link: '+link+' title: '+title);

	if (params != "")  
    	url = url	//+"?id="+params+"&idiom="+idioma;
	
//		alert('url: '+url)
	
	 
	if(window.XMLHttpRequest)
	{// NO IExplorer
		req = new XMLHttpRequest();
			req.onreadystatechange = loadinformation1Action;     //el request tiene varios status: 1 sin inicializar, 2 inicializado, 3 cargando, 4 hecho/ejecutado
			try
			{
				req.open("GET",url,true);//true significa asincrono
			}
			catch(e)
			{
				alert(e);
			}
			req.send(null);
	}else
		{
			if(window.ActiveXObject)
				{//IExplorer
					req = new ActiveXObject("Microsoft.XMLHTTP");
					if(req)
					{
						req.onreadystatechange=loadinformation1Action;
						req.open("GET",url,true);
						req.send();
					}
				}
		}

 //tracking de google
/*urchinTracker('/'+link+'/');
 link.href="#";*/
 document.title = title;

 }
 
 
function loadMenu(actions,params,dir,back,link,title)  //para cargar noticias y productos
{   
	
	j=0; 
	direction = params;
    document.all['txt'+(j+1)] = null;
    page = params;
	url = urlserver+actions;
	appearContent('arriba','change');  //colocar el flash inicial en la parte superior
	 background = back;
	 
    
    
       if (params != "")  url = url+"?id="+params+"&idiom="+idioma;
	 
	if(window.XMLHttpRequest)
	{// NO IExplorer
		req = new XMLHttpRequest();
			req.onreadystatechange =loadMenuAction;     //el request tiene varios status: 1 sin inicializar, 2 inicializado, 3 cargando, 4 hecho/ejecutado
			try
			{
//				alert(url);
				req.open("GET",url,true);//true significa asincrono
			}
			catch(e)
			{
				alert(e);
			}
			//req.send(null);
			req.send('');
	}else
		{
			if(window.ActiveXObject)
				{//IExplorer
					req = new ActiveXObject("Microsoft.XMLHTTP");
					if(req)
					{
						req.onreadystatechange=loadMenuAction;
						req.open("GET",url,true);
						req.send();
					}
				}
		}

 //tracking de google
//urchinTracker('/'+link+'/');
 link.href="#";
document.title = title;

}

function loadContent(actions,params,table,link,title)  //carga contenido de noticias y productos
{    
	
	url = urlserver+actions;
        if (params != "")  url = url+"?id="+params+"&idiom="+idioma+"&table="+table;
	if(window.XMLHttpRequest)
	{// NO IExplorer
		req = new XMLHttpRequest();
			req.onreadystatechange = loadContentAction;     //el request tiene varios status: 1 sin inicializar, 2 inicializado, 3 cargando, 4 hecho/ejecutado
			try
			{
				req.open("GET",url,true);//true significa asincrono
			}
			catch(e)
			{
				alert(e);
			}
			req.send(null);
	}else
		{
			if(window.ActiveXObject)
				{//IExplorer
					req = new ActiveXObject("Microsoft.XMLHTTP");
					if(req)
					{
						req.onreadystatechange=loadContentAction;
						req.open("GET",url,true);
						req.send();
					}
				}
		}
//urchinTracker('/'+link+'/');
 link.href="#";
document.title = title;
}
function changeIdiom(actions,params,dir,back,link,title)
{    
    if(idioma == "en")
    {
    	idioma = "es";
    }
    else
    {
    	idioma = "en";
    }
    
    direction = dir;
	url = urlserver+actions;
	
      background = back;
        if (params != "")  url = url+"?idiom="+idioma;
	 
	if(window.XMLHttpRequest)
	{// NO IExplorer
		req = new XMLHttpRequest();
			req.onreadystatechange = idiomAction;     //el request tiene varios status: 1 sin inicializar, 2 inicializado, 3 cargando, 4 hecho/ejecutado
			try
			{
				req.open("GET",url,true);//true significa asincrono
			}
			catch(e)
			{
				alert(e);
			}
			req.send(null);
	}else
		{
			if(window.ActiveXObject)
				{//IExplorer
					req = new ActiveXObject("Microsoft.XMLHTTP");
					if(req)
					{
						req.onreadystatechange=idiomAction;
						req.open("GET",url,true);
						req.send();
					}
				}
		}

 //tracking de google
 //urchinTracker('/'+link+'/');
 link.href="#";
 document.title = title;
}

function loadinformation1Action()                     // Funcion que llama a movercapa1 para mover el div para la izq y coloca el texto traido por AJAX en el doc
{
	WindowHeight = windowHeight();
	if(req.readyState == 4)
	{//4= ejecutado
		if(req.status == 200)
		{//HTTP OK
           newContent = req.responseText;
          
           document.all['change'].innerHTML= newContent;                           // abrir el menu
           apearDiv(direction,heightOpen,"change","arriba");
           	 if(direction == "4")
           	 	document.cookie="page"+"="+"nosotros";
           	 else
           	 	document.cookie="page"+"="+"soluciones";
				var tamNos;
           	  var tamSol;
           	  var etiquetaScript=document.createElement("script");
               document.getElementsByTagName("head")[0].appendChild(etiquetaScript);
		        
		         if (navigatorName == "Netscape")
		         {  
		         	tamSol = "90%";
		         	tamNos = "75%";
		         	
		         }
		         else
		         {
		         	
		         	tamn = ((WindowHeight*50)/100);
		         	tams = ((WindowHeight*34)/100);
		         	
		         	tamSol = tams+"px";
		         	tamNos = tamn+"px";
		         }
	           	 if (navigatorName == "Netscape")
	           	 {
			         if(direction == "4") 
			            	etiquetaScript.text="CSBfleXcroll('lista','"+tamNos+"','4');";    /// nosotros
			            	
			            else
			            	etiquetaScript.text="CSBfleXcroll('lista','"+tamSol+"','3');";    //soluciones
			            	
		      	 }  
      		  	 else 
	           	 {
			         if(direction == "4") 
			            	etiquetaScript.text="CSBfleXcroll('lista','"+tamNos+"','4');";    /// nosotros
			            	
			            else
			            	etiquetaScript.text="CSBfleXcroll('lista','"+tamSol+"','3');";    //soluciones
			            	
		      	 }  
			}
		}	
	}
	
	
function loadHomeAction()                     // Funcion que llama a movercapa1 para mover el div para la izq y coloca el texto traido por AJAX en el doc
{
	if(req.readyState == 4)
	{//4= ejecutado
		if(req.status == 200)
		{//HTTP OK
           newContent = req.responseText;
            
             document.all['arriba'].innerHTML= newContent;                           // abrir el menu
            
           		 apearDiv(0,'81%','arriba','change');
           	// unifyDivHeights();
			}
		}	
}
function loadMenuAction()                     // Funcion que llama a movercapa1 para mover el div para la izq y coloca el texto traido por AJAX en el doc
{
	if(req.readyState == 4)
	{//4= ejecutado
		if(req.status == 200)
		{//HTTP OK
          
					
			newContent = req.responseText;
            
            document.all['cambio'].innerHTML= newContent;              // abrir el menu
      		apearDiv(5,"65%","contenido","change");
            if((page == "news") || (page == "product"))
           		document.all['scroller'].start();
  				
			}
		}	
	}
	

function idiomAction()                     // Funcion que llama a movercapa1 para mover el div para la izq y coloca el texto traido por AJAX en el doc
{
	if(req.readyState == 4)
	{//4= ejecutado
		if(req.status == 200)
		{//HTTP OK
            newContent = req.responseText;
           // document.all['completo'].innerHTML= newContent;             
  				
			}
		}	
}


function loadContentAction()                     // Funcion para cambiar el contenido dentro del menu de la noticia o el producto seleccionado
{
    WindowHeight = windowHeight();
	style = "1";
	if(req.readyState == 4)
	{//4= ejecutado
		if(req.status == 200)
		{//HTTP OK
           newContent = req.responseText;
           if(direction == "news")
           	 	document.cookie="page"+"="+"noticias";
           	 else
           	 	document.cookie="page"+"="+"productos";
           	 	
             document.all['change'].innerHTML= newContent;             
    			apearDiv(6,"65%","contenido","change");
    			   var etiquetaScript=document.createElement("script");
                        document.getElementsByTagName("head")[0].appendChild(etiquetaScript);
          if(direction == "news")
          	 style = "2";
	 		 if (navigatorName == "Netscape")
		         {  
		         	tamP = "90%";
		         
		         }
		         else
		         {
		         	tam = ((WindowHeight*41)/100);
		         	tamP = tam+"px";
		         }
			 	if (navigatorName == "Netscape")
	           	 {
			         
			            	etiquetaScript.text="CSBfleXcroll('lista','"+tamP+"',"+style+");";   
			            	
		      	 }  
      		  	 else 
	           	 {
	           	 	etiquetaScript.text="CSBfleXcroll('lista','"+tamP+"',"+style+");";    
			            	
		      	 }  
      		
    			//se agrega la funcionalidad de la marquesina
    		
			}
		}	
	}

 
function unifyDivHeights()
 {
	  var myWindowHeight = windowHeight();
	 
	  var minHeight = PrincipalHeight;
	
	
	  if(myWindowHeight>minHeight) minHeight = myWindowHeight;
	
	  for(var i=0; i<divIds.length; i++)
	  {
	   //document.getElementById(divIds[i]).style.height = 'auto';
	 	}
	  var divHeights = new Array();
	  for(var i=0; i<divIds.length; i++) 
	  {
			divHeights[i] = document.getElementById(divIds[i]).offsetHeight;
	 
		}
	
	  var referenceDivHeights = new Array();
	  for(var i=0; i<referenceDivIds.length; i++) referenceDivHeights[i] = document.getElementById(referenceDivIds[i]).offsetHeight;
	
	  var maxDivHeight = 0;
	  for(var i=1; i<divIds.length; i++)
	  { 
	  	if(divHeights[i]>maxDivHeight)
	  	{
	  		 maxDivHeight = divHeights[i];
	  	}
	  }
	  for(var i=1; i<referenceDivIds.length; i++)
	  { 
	  	if(referenceDivHeights[i]>maxDivHeight)
	  	{
	  	 	maxDivHeight = referenceDivHeights[i];
	  	}
	 }
	  var newHeight = minHeight;
	
	  if(maxDivHeight>newHeight)
	  {  
	        newHeight = maxDivHeight;
	        
	  }
	  for(var i=0; i<divIds.length; i++)
	  {
	  		document.getElementById(divIds[i]).style.height = (newHeight) + "px";
	  }
	  
	
	  if(newHeight>minHeight)
	  {  
	  	  newHeight = minHeight;
	  
	  }
	 WindowHeight = newHeight;
	  document.body.style.height = newHeight + "px"; 
     
 }

///////////////////////////////777





function ChangeTitle(title)
{
  document.title = title;
}




function windowWidth(){
	var ancho= 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		ancho= window.innerWidth;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		ancho= document.documentElement.clientWidth;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		ancho= document.body.clientWidth;
	}
	return ancho;
}

function unifyDivSizes()
 {

//  unifyDivWidths();
//  
//  unifyDivHeights()
//  
// 
//  unifyDivWidths();
  
 }

 
 function windowHeight(){
	var alto= 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		alto= window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		alto= document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		alto= document.body.clientHeight;
	}

	return alto;
}


 
 
 
 