
// -----------------------------------------  FUNCIONES GENERICAS


function OpenCentered (psUrl, psName, piWidth, piHeight, psFlags)
{
	var iX=(screen.width-piWidth-20)/2;
	var iY=(screen.height-piHeight-30)/2;
			
	open(psUrl, psName, 'width=' + piWidth + ',height=' + piHeight + ',scrollbars=1,left=' + iX + ',top=' + iY +  ',screenX=' + iX + ',screenY=' + iY + psFlags);
}

var xmlhttp;

	function activaImagen(imagenId, img, param)
	{
		imagen1 = new Image;
		imagen2 = new Image;
		imagen1.src = "../images/" + param + "_0.jpg";
		imagen2.src = "../images/" + param + "_1.jpg";
		document.images[imagenId].src = eval(img + ".src");
	}
	
		
	function devuelveRadio(grupo) {
		var logintudRadio = grupo.length;
		if(logintudRadio == undefined)
			if(grupo.checked)
				return grupo.value;
			else
				return "";
		for(var i = 0; i < logintudRadio; i++) {
			if(grupo[i].checked) {
				return grupo[i].value;
			}
		}
		return "";
	}
	

	function GetXmlHttpObject()
	{
		if (window.XMLHttpRequest)
		{
		return new XMLHttpRequest();
		}
		
		if (window.ActiveXObject)
		{
		return new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		return null;
	}
	


	function cambiaSeccionAnt(uri) { 
	
			var fadeIn = new Fx.Morph($('configurador'),{ 
				duration: 500 
				}); 		
			
			var makeRequest = function() { 
					var req = new Request.HTML({url:"seccion" + uri + ".php", 
		
						onSuccess: function(html) {
							$('configurador').set('text', '');
							$('configurador').adopt(html);
							fadeIn.start({ 
							opacity : 1 
							}) 
						}
	
					}); 
						
					req.send();
				}; 
	
			 
			var fadeOut = new Fx.Morph($('configurador'),{ 
				duration: 500
			}); 
			
			fadeOut.start({ 
				opacity : 0
				}); 
				
			fadeOut.addEvent("complete", function() {
				makeRequest();
			});	
			
					
		};	
		
		
		
		
		function cambiaSeccionAltura(uri) { 
	
			var fadeIn = new Fx.Morph($('configurador'),{ 
				duration: 500 
				}); 		
			
			var makeRequest = function() { 
					var req = new Request.HTML({url:"seccion" + uri + ".php", 
		
						onSuccess: function(html) {
							$('configurador').set('text', '');
							$('configurador').adopt(html);
							fadeIn.start({ 
							opacity : 1 
							}) 
						}
	
					}); 
						
					req.send();
				}; 
	
			 
			var fadeOut = new Fx.Morph($('configurador'),{ 
				duration: 500
			}); 
			
			fadeOut.start({ 
				opacity : 0
				}); 
				
			fadeOut.addEvent("complete", function() {
				makeRequest();
			});	
			
			fadeIn.addEvent("start", function() {
				cambiaAltura(document.seccion1.combo_altura.value);
			});			
			
					
		};			
	
	
// -----------------------------------------  SALTO A SELECCIÓN DE TIPO DE PRODUCTO
	
	function inicioConfigurador(uri) { 
		var fadeIn = new Fx.Morph($('configurador'),{ 
			duration: 500 
			}); 		
		
		var makeRequest = function() { 
				var req = new Request.HTML({url:"seccion" + uri + ".php", 
	
					onSuccess: function(html) {
						$('configurador').set('text', '');
						$('configurador').adopt(html);
						fadeIn.start({ 
						opacity : 1 
						}) 
					}
				}); 
				req.send();
			}; 
		 
		var fadeOut = new Fx.Morph($('configurador'),{ 
			duration: 500
        }); 
		
		fadeOut.start({ 
			opacity : 0
			}); 
			
		fadeOut.addEvent("complete", function() {
		  	makeRequest();
		});	

	}; 



function activaRadio(param)
{
	document.seccion0.modelo[param].checked = 1;
}


// -----------------------------------------  SALTO A SELECCIÓN DE COLUMNA


	function cambiaSeccionColumna(uri) { 
		modelo = devuelveRadio(document.seccion0.modelo);
		var fadeIn = new Fx.Morph($('configurador'),{ 
			duration: 500 
			}); 		
		
		var makeRequest = function() { 
				
				var req = new Request.HTML({url:"seccion" + uri + ".php" + "?m=" + modelo, 
	
					onSuccess: function(html) {
						$('configurador').set('text', '');
						$('configurador').adopt(html);
						fadeIn.start({ 
						opacity : 1 
						}) 
					}

				}); 
					
				req.send();
			}; 

		var fadeOut = new Fx.Morph($('configurador'),{ 
			duration: 500
        }); 
		
		fadeOut.start({ 
			opacity : 0
			}); 
			
		fadeOut.addEvent("complete", function() {
		  	makeRequest();
		});	
				
		
	};



	function cambiaAltura(str)
	{
		var arradios = document.seccion1.nudos;	
		for(var l = 0; l < arradios.length; l++) {
			arradios[l].checked = 0;
			}
					
		xmlhttpAlt=GetXmlHttpObject();
		if (xmlhttpAlt==null)
		{
		return;
		}
		
		var url="seccion1_cambiaaltura.php";
		url = url + "?a=" + str;
		url = url + "&sid=" + Math.random();
		
		xmlhttpAlt.onreadystatechange = stateChanged;
		xmlhttpAlt.open("GET",url,true);
		xmlhttpAlt.send(null);
	}



	function activaRadios(param)
	{
		document.seccion1.nudos[param].checked = 1;
	}
	
	
	function stateChanged()
		{
			if (xmlhttpAlt.readyState == 4)
			{
			
				var nodos = xmlhttpAlt.responseText;
				if(nodos.length>0) nodos = nodos.split("|");
	
				document.getElementById('bloqueDERNudo0').setStyle("display", "none");
				document.getElementById('bloqueDERNudo1').setStyle("display", "none");
				document.getElementById('bloqueDERNudo2').setStyle("display", "none");
				
				var fadeIn0 = new Fx.Morph($('bloqueDERNudo0'),{ 
					duration: 500
				}); 
				
				var fadeIn1 = new Fx.Morph($('bloqueDERNudo1'),{ 
					duration: 500
				}); 
				
				var fadeIn2 = new Fx.Morph($('bloqueDERNudo2'),{ 
					duration: 500
				}); 						
	
	
				for( n = 0; n < nodos.length - 1; n++)
				{
					if(nodos[n] == 0) 
					{ 
					document.getElementById('bloqueDERNudo0').setStyle("display", "block");
					document.getElementById('bloqueDERNudo0').setStyle("opacity", "0");
					fadeIn0.start({ 
						opacity : 1
						});					 
					}
					if(nodos[n] == 1) 
					{ 
					document.getElementById('bloqueDERNudo1').setStyle("display", "block");
					document.getElementById('bloqueDERNudo1').setStyle("opacity", "0");
					fadeIn1.start({ 
						opacity : 1
						});					 
					}
					if(nodos[n] == 2) 
					{ 
					document.getElementById('bloqueDERNudo2').setStyle("display", "block");
					document.getElementById('bloqueDERNudo2').setStyle("opacity", "0");
					fadeIn2.start({ 
						opacity : 1
						});
					}								
								
				}
				
				
			}
		}	
	
	
	
// -----------------------------------------  SALTO A SELECCIÓN DE BRAZOS
	

	
	function cambiaSeccionBrazos(uri) { 
	
		altura = document.seccion1.combo_altura.value;
		tipo = devuelveRadio(document.seccion1.nudos);

		var fadeIn = new Fx.Morph($('configurador'),{ 
			duration: 500 
			}); 
			
			
		fadeIn.addEvent("complete", function() {

			if(tipo > 0){

				var fadeBrazos_sup = new Fx.Morph($('lista_sup'),{ 
					duration: 500 
				}); 
					
				fadeBrazos_sup.start({ 
					opacity : 1 
				})			
		
				var elem_sup = document.getElementById('cajaBrazoArrowI');
				var list_sup = document.getElementById('ulista_sup');	
				elem_sup.activo = false;
				var myFx_sup = new Fx.Slide(list_sup).hide();	
				
				
				elem_sup.addEvents({
					'click' : function(){ 
						if(this.activo){
							myFx_sup.hide();
						}else{
							myFx_sup.show();
						}
						this.activo = !this.activo;
						
						
					}						
				});
				
				document.getElementById('ulista_sup').getElements('li').each( function( lista_supItems ){
					lista_supItems.addEvents({

					'click' : function(e){ 
						myFx_sup.hide();
						elem_sup.activo = !elem_sup.activo;
						document.getElementById('cajaBrazoInitS').innerHTML = this.innerHTML;
						document.getElementById('brazoSup').value = (this.id).substr(2);						
						}						
					});																			   
				});
				
				
			}
			
		

			if(tipo > 1){	
			
				var fadeBrazos_inf = new Fx.Morph($('lista_inf'),{ 
					duration: 500 
				}); 
					
				fadeBrazos_inf.start({ 
					opacity : 1 
				})			
		
				var elem_inf = document.getElementById('cajaBrazoArrowD');
				var list_inf = document.getElementById('ulista_inf');	
				elem_inf.activo = false;
				var myFx_inf = new Fx.Slide(list_inf).hide();
				
				
				elem_inf.addEvents({
					'click' : function(){
						if(this.activo){
							myFx_inf.hide();
						}else{
							myFx_inf.show();
						}
						this.activo = !this.activo;
					}						
				});
				
				document.getElementById('ulista_inf').getElements('li').each( function( lista_infItems ){
					lista_infItems.addEvents({
					'click' : function(){ 
						myFx_inf.hide();
						elem_inf.activo = !elem_inf.activo;
						document.getElementById('cajaBrazoInitI').innerHTML = this.innerHTML;
						document.getElementById('brazoInf').value = (this.id).substr(2);
						}						
					});																			   
				});	
				
			}						

		});						
		
		
		var makeRequest = function() {
				var req = new Request.HTML({url:"seccion" + uri + ".php?a=" + altura + "&t=" + tipo, 
	
					onSuccess: function(html) {
						$('configurador').set('text', '');
						$('configurador').adopt(html);
						if( tipo > 0) 
						{						
							document.getElementById('lista_sup').setStyle("opacity", "0");
						}
						if( tipo > 1) 
						{
							document.getElementById('lista_inf').setStyle("opacity", "0"); 
						}
						
						fadeIn.start({ 
						opacity : 1 
						}) 
					}

				}); 
					
				req.send();
			}; 

		 
		var fadeOut = new Fx.Morph($('configurador'),{ 
			duration: 500
		}); 
		
		fadeOut.start({ 
			opacity : 0
			}); 
			
		fadeOut.addEvent("complete", function() {
			makeRequest();
		});	
			
					
		}; 	
		
		
		
// -----------------------------------------  VUELTA A LA SELECCIÓN DE BRAZOS
	

	
	function vuelveSeccionBrazos(uri, altura, tipo) {
		var fadeIn = new Fx.Morph($('configurador'),{ 
			duration: 500 
			}); 
			
			
		fadeIn.addEvent("complete", function() {
										 

			if(tipo > 0){
				
			bs = "id" + document.getElementById('brazoSup').value;
			document.getElementById('cajaBrazoInitS').innerHTML = document.getElementById(bs).innerHTML;

				var fadeBrazos_sup = new Fx.Morph($('lista_sup'),{ 
					duration: 500 
				}); 
					
				fadeBrazos_sup.start({ 
					opacity : 1 
				})			
		
				var elem_sup = document.getElementById('cajaBrazoArrowI');
				var list_sup = document.getElementById('ulista_sup');	
				elem_sup.activo = false;
				var myFx_sup = new Fx.Slide(list_sup).hide();
				
			
				
				elem_sup.addEvents({
					'click' : function(){ 
						if(this.activo){
							myFx_sup.hide();
						}else{
							myFx_sup.show();
						}
						this.activo = !this.activo;
						
						
					}						
				});
				
				document.getElementById('ulista_sup').getElements('li').each( function( lista_supItems ){
					lista_supItems.addEvents({

					'click' : function(e){ 
						myFx_sup.hide();
						elem_sup.activo = !elem_sup.activo;
						document.getElementById('cajaBrazoInitS').innerHTML = this.innerHTML;
						document.getElementById('brazoSup').value = (this.id).substr(2);						
						}						
					});																			   
				});
				
				
			}
			
		

			if(tipo > 1){	
			
				bi = "id" + document.getElementById('brazoInf').value;
				document.getElementById('cajaBrazoInitI').innerHTML = document.getElementById(bi).innerHTML;			
			
				var fadeBrazos_inf = new Fx.Morph($('lista_inf'),{ 
					duration: 500 
				}); 
					
				fadeBrazos_inf.start({ 
					opacity : 1 
				})			
		
				var elem_inf = document.getElementById('cajaBrazoArrowD');
				var list_inf = document.getElementById('ulista_inf');	
				elem_inf.activo = false;
				var myFx_inf = new Fx.Slide(list_inf).hide();
				
				
				elem_inf.addEvents({
					'click' : function(){
						if(this.activo){
							myFx_inf.hide();
						}else{
							myFx_inf.show();
						}
						this.activo = !this.activo;
					}						
				});
				
				document.getElementById('ulista_inf').getElements('li').each( function( lista_infItems ){
					lista_infItems.addEvents({
					'click' : function(){ 
						myFx_inf.hide();
						elem_inf.activo = !elem_inf.activo;
						document.getElementById('cajaBrazoInitI').innerHTML = this.innerHTML;
						document.getElementById('brazoInf').value = (this.id).substr(2);
						}						
					});																			   
				});	
				
			}						

		});						
		
		
		var makeRequest = function() {
				var req = new Request.HTML({url:"seccion" + uri + ".php?a=" + altura + "&t=" + tipo, 
	
					onSuccess: function(html) {
						$('configurador').set('text', '');
						$('configurador').adopt(html);
						if( tipo > 0) 
						{						
							document.getElementById('lista_sup').setStyle("opacity", "0");
						}
						if( tipo > 1) 
						{
							document.getElementById('lista_inf').setStyle("opacity", "0"); 
						}
						
						fadeIn.start({ 
						opacity : 1 
						}) 
					}

				}); 
					
				req.send();
			}; 

		 
		var fadeOut = new Fx.Morph($('configurador'),{ 
			duration: 500
		}); 
		
		fadeOut.start({ 
			opacity : 0
			}); 
			
		fadeOut.addEvent("complete", function() {
			makeRequest();
		});	
			
					
		}; 			
		



// -----------------------------------------  SALTO A SELECCIÓN DE ACCESORIOS


	function cambiaSeccionAccesorios(s, i,param) { 

		if(param == 1 && document.getElementById('brazoSup').value.length < 1)
		{
			alert("Debe seleccionar los brazos del nudo superior.");
			return;
		}
		
		if(param > 1 && document.getElementById('brazoInf').value.length < 1)
		{
			alert("Debe seleccionar los brazos del nudo superior e inferior.");
			return;
		}		

		var fadeIn = new Fx.Morph($('configurador'),{ 
			duration: 500 
			}); 		
		
		var makeRequest = function() { 
				s = document.getElementById('brazoSup').value;
				uri = "seccion3.php?s=" + s;
				
				if(param > 1)
				{
					i = document.getElementById('brazoInf').value;
					uri += "&i=" + i;
				}
				
				var req = new Request.HTML({url:uri, 
	
					onSuccess: function(html) {
						$('configurador').set('text', '');
						$('configurador').adopt(html);
						fadeIn.start({ 
						opacity : 1 
						}) 
					}

				}); 
					
				req.send();
			}; 

		var fadeOut = new Fx.Morph($('configurador'),{ 
			duration: 500
        }); 
		
		fadeOut.start({ 
			opacity : 0
			}); 
			
		fadeOut.addEvent("complete", function() {
		  	makeRequest();
		});	
	
	};
	
	


// -----------------------------------------  SALTO A FICHA DE COLUMNA DE MONTAJE COMPLETO
	
function validar(formulario) 
{
	var accesos = "";
	with(document.accesorios) 
	{
		for(var i = 0; i < accesorio.length; i++)
		{
			if(accesorio[i].checked)
			{
				accesos += accesorio[i].value + "|";
			}
		}
	}
	accesos = accesos.substr(0,accesos.length - 1);
	misAccesorios = accesos.split("|");
	
	if(misAccesorios.length > 0)
	{
		misParams = "?";
		for(var n = 0; n < misAccesorios.length; n++)
		{		
			misParams = misParams + "param" + n + "=" + misAccesorios[n] + "&";
		}
		
		misParams = misParams.substr(0,misParams.length - 1);
	}
	return misParams;
}




	function cargaFicha(formu) { 
		var fadeIn = new Fx.Morph($('configurador'),{ 
			duration: 500 
			}); 		
		
		var loadFicha = function() { 
				var req = new Request.HTML({url:"seccion4.php" + validar(formu),
	
					onSuccess: function(html) {
						$('configurador').set('text', '');
						$('configurador').adopt(html);
						fadeIn.start({ 
						opacity : 1 
						}) 
					}
				}); 
				req.send();
			}; 
		 
		var fadeOut = new Fx.Morph($('configurador'),{ 
			duration: 500
        }); 
		
		fadeOut.start({ 
			opacity : 0
			}); 
			
		fadeOut.addEvent("complete", function() {
		  	loadFicha(formu);
		});	
		
		fadeIn.addEvent("complete", function() {
		  	Show_MFC_Docs(document.docs.dradis.value);
		});			

	};

		
		
// -----------------------------------------  SALTO A FICHA DE COLUMNA MONTAJE EN PUNTA
	
	
	
	
	
	function cambiaSeccionPunta(uri) { 
		var fadeIn = new Fx.Morph($('configurador'),{ 
			duration: 500 
			}); 		
		
		var makeSalto = function() { 
				var req = new Request.HTML({url:"seccion" + uri + ".php", 
	
					onSuccess: function(html) {
						$('configurador').set('text', '');
						$('configurador').adopt(html);
						fadeIn.start({ 
						opacity : 1 
						}) 
					}
				}); 
				req.send();
			}; 
		 
		var fadeOut = new Fx.Morph($('configurador'),{ 
			duration: 500
        }); 
		
		fadeOut.start({ 
			opacity : 0
			}); 
			
		fadeOut.addEvent("complete", function() {
		  	makeSalto();
		});	

	};
	
	
	
	
	
	
function cargaFichaPunta(formu) { 
		var fadeIn = new Fx.Morph($('configurador'),{ 
			duration: 500 
			}); 		
		
		var loadFicha = function() { 
				var req = new Request.HTML({url:"seccion7.php" + validar(formu),
	
					onSuccess: function(html) {
						$('configurador').set('text', '');
						$('configurador').adopt(html);
						fadeIn.start({ 
						opacity : 1 
						}) 
					}
				}); 
				req.send();
			}; 
		 
		var fadeOut = new Fx.Morph($('configurador'),{ 
			duration: 500
        }); 
		
		fadeOut.start({ 
			opacity : 0
			}); 
			
		fadeOut.addEvent("complete", function() {
		  	loadFicha(formu);
		});
		
		fadeIn.addEvent("complete", function() {
		  	Show_MFC_Docs(document.docs.dradis.value);
		});		

	};	
	
	function vuelveSeccionAccesorios() { 

		var fadeIn = new Fx.Morph($('configurador'),{ 
			duration: 500 
			}); 		
		
		var makeRequest = function() { 
				uri = "seccion6.php";

				
				var req = new Request.HTML({url:uri, 
	
					onSuccess: function(html) {
						$('configurador').set('text', '');
						$('configurador').adopt(html);
						fadeIn.start({ 
						opacity : 1 
						}) 
					}

				}); 
					
				req.send();
			}; 

		var fadeOut = new Fx.Morph($('configurador'),{ 
			duration: 500
        }); 
		
		fadeOut.start({ 
			opacity : 0
			}); 
			
		fadeOut.addEvent("complete", function() {
		  	makeRequest();
		});	
	
	};	
	
	
	
	
// -----------------------------------------  SALTO A LA FICHA FINAL DE BRAZO PARED
	
	
	
	
	
	function fichaFinalBrazoPared(uri) { 
	
		var fadeIn = new Fx.Morph($('configurador'),{ 
			duration: 500 
			}); 		
		
		var makeSalto = function() { 
				var req = new Request.HTML({url:"seccion8.php", 
	
					onSuccess: function(html) {
						$('configurador').set('text', '');
						$('configurador').adopt(html);
						fadeIn.start({ 
						opacity : 1 
						}) 
					}
				}); 
				req.send();
			}; 
		 
		var fadeOut = new Fx.Morph($('configurador'),{ 
			duration: 500
        }); 
		
		fadeOut.start({ 
			opacity : 0
			}); 
			
		fadeOut.addEvent("complete", function() {
		  	makeSalto();
		});
		
		fadeIn.addEvent("complete", function() {
		  	Show_MFC_Docs(document.docs.dradis.value);
		});			

	};	
	