var capa_activa=1;
var repeticiones=9;
var capa_desplegada=1;


function activar(capa){

	if(capa!=capa_desplegada){
	
		if(capa==capa_activa){
		
			if(capa>capa_desplegada){	
		
				if(repeticiones<9){
					for(i=capa_desplegada;i<capa_activa;i++){		
						obj = document.getElementById("block"+i);
						pos = obj.style.top.split("p");				
						obj.style.top = (parseInt(pos[0])-10)+"px";				
					}		
				}	
						
			}else{	

				if(repeticiones<9){
					for(i=capa_activa;i<capa_desplegada;i++){		
						obj = document.getElementById("block"+i);
						pos = obj.style.top.split("p");				
						obj.style.top = (parseInt(pos[0])+10)+"px";	
					}
				}				
			}
			repeticiones++;	
			
			if(repeticiones==9){
				capa_desplegada=capa_activa;
			}
			setTimeout("activar("+capa_activa+")",20);

		}else{

			if(repeticiones==9){
				capa_activa=capa;
				repeticiones=0;
				activar(capa);
			}		
		}	
	}
}


function imagenON_ESP(capa){

	obj=document.getElementById("block"+capa);		
	obj.style.backgroundImage="url(imagenes/b"+capa+"on-esp.png)";
	console.log(obj.style.backgroundImage);
	
	if(capa==1){
		obj=document.getElementById("block"+capa+"_top");
		obj.style.backgroundImage="url(imagenes/b"+capa+"on-top.png)";		
	}
}


function imagenON_ENG(capa)
{
	obj=document.getElementById("block"+capa);		
	obj.style.backgroundImage="url(imagenes/b"+capa+"on-eng.png)";

	if(capa==1){
		obj=document.getElementById("block"+capa+"_top");
		obj.style.backgroundImage="url(imagenes/b"+capa+"on-top.png)";		
	}
}


function imagenOFF_ESP(capa)
{
	obj=document.getElementById("block"+capa);
	obj.style.backgroundImage="url(imagenes/b"+capa+"off-esp.png)";
	
	if(capa==1){
		obj=document.getElementById("block"+capa+"_top");
		obj.style.backgroundImage="url(imagenes/b"+capa+"off-top.png)";		
	}
}


function imagenOFF_ENG(capa)
{
	obj=document.getElementById("block"+capa);
	obj.style.backgroundImage="url(imagenes/b"+capa+"off-eng.png)";
	
	if(capa==1){
		obj=document.getElementById("block"+capa+"_top");
		obj.style.backgroundImage="url(imagenes/b"+capa+"off-top.png)";		
	}
}


function precargar(){

	//alert('hola')
	directory = 'http://www.mialarmavenezuela.com/';

	img1 = new Image();
	img1.src = directory+'imagenes/b1on-top.png';
	
	img2 = new Image();
	img2.src = directory+'imagenes/b1on-esp.png';

	img3 = new Image();
	img3.src = directory+'imagenes/b2on-esp.png';

	img4 = new Image();
	img4.src = directory+'imagenes/b3on-esp.png';

	img5 = new Image();
	img5.src = directory+'imagenes/b4on-esp.png';

	img6 = new Image();
	img6.src = directory+'imagenes/b5on-esp.png';

	img7 = new Image();
	img7.src = directory+'imagenes/b6on-esp.png';
	
	img8 = new Image();
	img8.src = directory+'imagenes/b1on-eng.png';

	img9 = new Image();
	img9.src = directory+'imagenes/b2on-eng.png';

	img10 = new Image();
	img10.src = directory+'imagenes/b3on-eng.png';

	img11 = new Image();
	img11.src = directory+'imagenes/b4on-eng.png';

	img12 = new Image();
	img12.src = directory+'imagenes/b5on-eng.png';

	img13 = new Image();
	img13.src = directory+'imagenes/b6on-eng.png';	
}


function changeURL(key,strUserValue)
{	
	var strQuery = location.search.substring(1);
	var arrOrigPairs = strQuery.split('&');
	var arrNewPairs = [];
	var found = false;
	
	for(var i=0; i<arrOrigPairs.length; i++)
	{
		var intPos = arrOrigPairs[i].indexOf('=');
		var strOrigName = arrOrigPairs[i].substring(0,intPos);
		var strOrigValue = arrOrigPairs[i].substring(intPos+1);
		
		if(strOrigName == key)
		{
			found = true;		
			arrNewPairs.push(strOrigName+'='+strUserValue);
		}
		else
		{				
			arrNewPairs.push(strOrigName+'='+strOrigValue);
		}		
	}
	
	if(!found)
	{
		arrNewPairs.push(key+'='+strUserValue);
	}
	
	var intPos = location.href.indexOf('?');
	var strDir = location.href.substr(0,intPos);
	strDir += '?'+arrNewPairs.join('&');
	location.href = strDir;
}


function GetXmlHttpObject() {
	var xmlhttp = null;
	if (window.ActiveXObject){	//Check if we are using IE.
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");	
	} else {					//Check if we are using non-IE.
		xmlhttp = new XMLHttpRequest();	
	}
	return xmlhttp;
}


function sendPaymentForm(){

	/*--- Se almacena formulario en variables ---*/
	/*productos=0;*/
	nombre = document.formulario.nombre.value;
	cuenta_cliente = document.formulario.cuenta_cliente.value;
	numero_deposito = document.formulario.numero_deposito.value;
	cuenta_banco = document.formulario.cuenta_banco.value;
	fecha = document.formulario.fecha.value;
	monto = document.formulario.monto.value;
	pais = document.formulario.pais.value;
		
	cadena = "nombre="+nombre+"&cuenta_cliente="+cuenta_cliente+"&numero_deposito="+numero_deposito+"&cuenta_banco="+cuenta_banco+"&fecha="+fecha+"&monto="+monto+"&pais="+pais;

	if(nombre=="" || numero_deposito=="" || cuenta_banco=="" || fecha=="" || monto==""){
		alert("Por favor rellene todos los campos o su solicitud no será enviada");}
		
	else{
		xmlhttp = GetXmlHttpObject();
		xmlhttp.open("POST","email_reporte_pago.php",true);
		
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState==4) {
				alert('Gracias por reporta su pago.\nLe responderemos a la mayor brevedad');
			}
		}
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlhttp.send(cadena);
	}
}


function sendContactForm(){

	/*--- Se almacena formulario en variables ---*/
	productos=0;
	nombre = document.formulario.nombre.value;
	correo = document.formulario.correo.value;
	telefono = document.formulario.telefono.value;
	comentario = document.formulario.comentario.value;
	pais = document.formulario.pais.value;

	for(i=0;i<document.formulario.producto.length;i++){
		if(document.formulario.producto[i].checked){
			productos = document.formulario.producto[i].value;	
		}
	}		
	
	cadena = "nombre="+nombre+"&correo="+correo+"&telefono="+telefono+"&comentario="+comentario+"&producto="+productos+"&pais="+pais;

	if(nombre=="" || correo=="" || telefono=="" || comentario=="" || productos==0){
		alert("Por favor rellene todos los campos o su solicitud no será enviada");}
		
	else{
		xmlhttp = GetXmlHttpObject();
		xmlhttp.open("POST","email_formulario.php",true);
		
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState==4){		
				//alert(xmlhttp.responseText);
				alert('Gracias por ponerse en contacto con nostros\nLe responderemos a la mayor brevedad');
			}
		}
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlhttp.send(cadena);
	}
}


function getURLQueryString(){
	return location.search;
}
