// JavaScript Document
function objetoAjax(){
	  var xmlhttp=false;
	  try {
		  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	  } catch (e) {
		  try {
			 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		  } catch (E) {
			  xmlhttp = false;
		  }
	  }
	  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		  xmlhttp = new XMLHttpRequest();
	  }
	  return xmlhttp;
  }
function idioma(cual){
   ajax=objetoAjax();
   ajax.open("POST", "idioma.php");
   ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
   var loc=window.location;
   ajax.send("idiom="+cual+"&lugar="+escape(loc));
   ajax.onreadystatechange=function() {
	  if (ajax.readyState==4) {
		  var idiomas=ajax.responseText;
		  document.location.reload();	
	  }
   } }
function kilataje(idK,idP,numero){

   $.ajax({
   				type: "POST",
   				url: "medidas.php",
   				data: "idProducto="+idP+"&kilataje="+idK,
   				success: function(msg){
					$("#medidas").html(msg);
					document.getElementById('agregando').setAttribute("onclick","javascript:agregarProducto('"+idP+"','"+idK+"','"+numero+"');return false;");
				}
				
		   });
   
    
	}
function agregarFav(idP,idioma){
	$.ajax({
   				type: "POST",
   				url: "agregarFav.php",
   				data: "idProducto="+idP+"&idioma="+idioma,
   				success: function(msg){
					$("#mensajes").hide();
					$("#mensajes").html(msg);
    				$("#mensajes").slideDown("slow");
					var inter=window.setTimeout(function(){up()}, 7000);
				}
				
		   });
	
	}
function up(){
	$("#mensajes").slideUp("slow");
	$("#mensajes").empty();
	}
function share(idP,idioma){
	var envi="";
	if(idioma=="es"){envi="enviar.jpg";}else{envi="enviarEng.jpg";}
			
						if(idioma=="es"){
						$("#mensajes").html("<div style='width:100%;float:left;margin-bottom:15px;margin-top:15px;font-size:14px;'><div style='width:120px; float:left;text-align:right;margin-right:10px;'>Nombre:</div><div style='width:120px; float:left;'><input type='text' name='nombre' id='nombre' style='font-family:normal;'></div><div style='clear:both;height:10px;'></div><div style='width:120px; float:left;text-align:right;margin-right:10px;'>Correo:</div><div style='width:120px; float:left;'><input type='text' name='correo' id='correo' style='font-family:normal;'></div><div style='clear:both;height:10px;'></div><div style='width:120px; float:left;text-align:right;margin-right:10px;'>Correo destino:</div><div style='width:120px; float:left;'><input type='text' name='correod' id='correod' style='font-family:normal;'></div><div style='clear:both;height:10px;'></div><div style='width:120px; float:left;text-align:right;margin-right:10px;'>Mensaje:</div><div style='width:120px; float:left;'><textarea cols='19' rows='4' name='msg' id='msg' style='font-family:normal;'></textarea></div><div style='clear:both;height:10px;'></div><div style='width:120px; float:left;text-align:right;margin-left:130px;'><div class='transparenteMaestro'><a href='#' onclick=\"javascript:envioShare('"+idioma+"','"+idP+"');return false;\"><img src='img/"+envi+"'/></a></div></div><div style='width:120px; float:left;'></div><div style='clear:both;height:10px;'></div></div><div style='clear:both;'></div>");
						}else{
							$("#mensajes").html("<div style='width:100%;float:left;margin-bottom:15px;margin-top:15px;font-size:14px;'><div style='width:120px; float:left;text-align:right;margin-right:10px;'>Name:</div><div style='width:120px; float:left;'><input type='text' name='nombre' id='nombre' style='font-family:normal;'></div><div style='clear:both;height:10px;'></div><div style='width:120px; float:left;text-align:right;margin-right:10px;'>Email:</div><div style='width:120px; float:left;'><input type='text' name='correo' id='correo' style='font-family:normal;'></div><div style='clear:both;height:10px;'></div><div style='width:120px; float:left;text-align:right;margin-right:10px;'>Dest. Email:</div><div style='width:120px; float:left;'><input type='text' name='correod' id='correod' style='font-family:normal;'></div><div style='clear:both;height:10px;'></div><div style='width:120px; float:left;text-align:right;margin-right:10px;'>Message:</div><div style='width:120px; float:left;'><textarea cols='19' rows='4' name='msg' id='msg' style='font-family:normal;'></textarea></div><div style='clear:both;height:10px;'></div><div style='width:120px; float:left;text-align:right;margin-left:130px;'><div class='transparenteMaestro'><a href='#' onclick=\"javascript:envioShare('"+idioma+"','"+idP+"');return false;\"><img src='img/"+envi+"'/></a></div></div><div style='width:120px; float:left;'></div><div style='clear:both;height:10px;'></div></div><div style='clear:both;'></div>");
							}
             			$("#mensajes").slideToggle("slow");
                   
	} 
function valEmail(valor){
    re=/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/
    if(!re.exec(valor))    {
        return false;
    }else{
        return true;
    }}
function envioShare(idioma,idProducto){
	var nombre=$("#nombre").val();
	var correo=$("#correo").val();
	var correod=$("#correod").val();
	var msg=$("#msg").val();
	if(nombre=="" || correo=="" || correod=="" || valEmail(correo)==false || valEmail(correod)==false){
		alert("Alguno de los datos esta incompleto o es incorrecto, intente de nuevo");
		$("#nombre").val("");
		$("#correo").val("");
		$("#correod").val("");
		$("#msg").val("");
		}else{
		up();
		$.ajax({
   				type: "POST",
   				url: "shareProduct.php",
   				data: "nombre="+nombre+"&idioma="+idioma+"&correo="+correo+"&destino="+correod+"&msg="+msg+"&idProducto="+idProducto,
   				success: function(msg){
					$("#mensajes").hide();
					$("#mensajes").html(msg);
    				$("#mensajes").slideDown("slow");
					var inter=window.setTimeout(function(){up()}, 7000);
				}
				
		   });
		}
	}
function agregarProducto(idP,idK,num,idioma){
	var idKs=new Array();
	var cans=new Array();
	for(var i=1;i<=num;i++){
		var nua=$("#cant"+i).val();
		if(nua>0){
			var asd=$("#numK"+i).val();
			idKs.push(asd);
			cans.push(nua);
			}
			$("#cant"+i).val("0");
		}
	var idsK=idKs.join(";");
	var cans2=cans.join(";");
	if(idKs.length>0){
		$.ajax({
   				type: "POST",
   				url: "agregarCarrito.php",
   				data: "idsK="+idsK+"&cans="+cans2,
   				success: function(msg){
					$("#mensajes").hide();
					$("#mensajes").html(msg);
    				$("#mensajes").slideDown("slow");
					var inter=window.setTimeout(function(){up()}, 7000);
				}
				
		   });
	}else{
			$("#mensajes").hide();
			if(idioma=="es"){
			$("#mensajes").html("<div style='width:100%;float:left;margin-bottom:15px;margin-top:15px;font-size:14px;'>Debes seleccionar la cantidad de productos a agregar</div>");
			}else{
			$("#mensajes").html("<div style='width:100%;float:left;margin-bottom:15px;margin-top:15px;font-size:14px;'>Please select the quantity of products you want to add</div>");	
				}
    		$("#mensajes").slideDown("slow");
			var inter=window.setTimeout(function(){up()}, 7000);
		}
		
}	
function grabado(idioma){
	$("#informacion2").slideUp("slow");
	if(idioma=="es"){
							$("#informacion").html("<div style='width:100%;float:left;margin-bottom:15px;margin-top:15px;font-size:14px;height:196px;'><img src='img/grabado.jpg' /></div>");
						}else{
							$("#informacion").html("<div style='width:100%;float:left;margin-bottom:15px;margin-top:15px;font-size:14px;height:196px;'><img src='img/grabadoEng.jpg' /></div>");
						}
             	
                        $("#informacion").slideToggle("slow");
						
	
	
	}
function envio(idioma){
	  $("#informacion").slideUp("slow");
						if(idioma=="es"){
							$("#informacion2").html("<div style='width:100%;float:left;margin-bottom:15px;margin-top:15px;font-size:14px;'>Opciones y condiciones de envio</div>");
						}else{
							$("#informacion2").html("<div style='width:100%;float:left;margin-bottom:15px;margin-top:15px;font-size:14px;'>Options and conditions of shipment</div>");
						}
             	
                        $("#informacion2").slideToggle("slow");
						
					
	
	
	}
