
	function openInANewWindow(img,newTitle){
	  url = "fullimage.php?img="+img+"&title="+newTitle;
	  window.open(url,"_blank","left=100,top=50,height=150,width=150,scrollbars=yes,resizable=yes,toolbar=no,menubar=no,location=no");
	}
	
	function openVidInANewWindow(id,lng,title,sec){
	  url = "video.php?id="+id+"&lng="+lng+"&t="+title+"&sec="+sec;
	  window.open(url,"_blank","left=100,top=50,height=150,width=150,scrollbars=yes,resizable=yes,toolbar=no,menubar=no,location=no");
	}
	
	function swapSport(value){
		document.location.href='tienda-deportes.php?generoh&generom&generou&temporadai&temporadav&mtemporada&s='+value;
	}
	
	function browseByProductType(value){
		document.location.href='tienda.php?generoh&generom&generou&temporadai&temporadav&mtemporada&cat='+value;
	}
	
	function swapImage(id,img){
		$("#images_list a.active").removeClass("active");
		$("#"+id).addClass("active");
		$("#bigImg").attr("src",img);
	}
	
	function clearCart(){
		var vars = "opc=clearCart";
		$.ajax({
		   async: false,
		   type: "POST",
		   url: "_ajax.php",
		   data: vars,
		   success: function(data){
				
		   }
		});
	}
	
	function sendCartToAdmin(){
		var vars = "opc=sendCartToAdmin";
		$.ajax({
		   async: true,
		   type: "POST",
		   url: "_ajax.php",
		   data: vars,
		   success: function(data){
				//alert(data);
		   }
		});
	}
	
	function saveCart(fp,fe,m){
		//alert("saveCart ejecutada!");
		var vars = "opc=saveCart&fp="+fp+"&fe="+fe;
		var ret = false;
		$.ajax({
		   async: true,
		   type: "POST",
		   url: "_ajax.php",
		   data: vars,
		   success: function(data){
				//alert(data);
				if(data != '0'){
					$('#paypal_form_custom').val(data);
				}else{
					alert(getTranslateEntry("CARRITO_NO_GUARDADO"));
				}
		   }
		});
		if(m == 1){
			sendCartToAdmin();
		}
	}
	
	function updatePurchase(m){
		saveCart($('#select_pago').val(),$('#formaDeEnvio').val(),m);
		$("#add_loader").html('<img src="images/admin/ajax-loader.gif" />');
		var message = "";
		var vars = "opc=updatePurchase";
		$.ajax({
		   async: true,
		   type: "POST",
		   url: "_ajax.php",
		   data: vars,
		   success: function(data){
				if(data != 1){
					alert(data);
				}
				if(m == '1'){
					$('#paypal_form').trigger("submit");
					
				}else if(m == '2'){
					vars = "opc=pm2";
					$.ajax({
					   async: false,
					   type: "POST",
					   url: "_ajax.php",
					   data: vars,
					   success: function(data){
							$("#add_loader").remove();
							message = data;
					   }
					});
					var html ='<div id="alert_msg" style="width:690px;background-color:#FFFFFF;border: 1px solid #999999; cursor:default;float:left">';
					html+='<div style="float:left"><div id="message_div" style="color:#000;font-size:12px;padding:10px;">'+message+'</div></div>';
					html+='</div>';
					MySimpleLightBox.border='1px solid #999999';
					MySimpleLightBox.loadHTML(html);
					
					clearCart();
					
				}else if(m == '3'){
					//alert("Third payment method.");
					vars = "opc=pm3";
					$.ajax({
					   async: false,
					   type: "POST",
					   url: "_ajax.php",
					   data: vars,
					   success: function(data){
							$("#add_loader").remove();
							message = data;
					   }
					});
					var html ='<div id="alert_msg" style="width:690px;background-color:#FFFFFF;border: 1px solid #999999; cursor:default;float:left">';
					html+='<div style="float:left"><div id="message_div" style="color:#000;font-size:12px;padding:10px;">'+message+'</div></div>';
					html+='</div>';
					
					MySimpleLightBox.border='1px solid #999999';
					MySimpleLightBox.loadHTML(html);
					
					clearCart();
				}
		   }
		});
	}
	
	function showLightbox(which,id){
		var img_icon="";
		var vars = 'opc='+which;
		var message = "";
		var close_on_click = close_on_click == '' || close_on_click == undefined  ? false: close_on_click;
		if(typeof(DIR_PREFIX) == "undefined"){
			window.DIR_PREFIX = '';
		}
		if(which == 'fichaTecnica'){ // Muestra la ficha técnica
			vars += '&id='+id;
			$.ajax({
			   async: false,
			   type: "POST",
			   url: "_ajax.php",
			   data: vars,
			   success: function(data){
					message = data;
			   }
			});
		}else if(which == 'recover_pass'){ // En caso de que sea desde recuperación de clave
			$.ajax({
			   async: false,
			   type: "POST",
			   url: "_ajax.php",
			   data: vars,
			   success: function(data){
					message = data;
			   }
			});
		}else if(which == 'costo_envio'){ // En caso de que sea desde resumen de compra ( ? )
			$.ajax({
			   async: false,
			   type: "POST",
			   url: "_ajax.php",
			   data: vars,
			   success: function(data){
					message = data;
			   }
			});
		}else{ // El resto de los casos (no debería suceder)
			$.ajax({
			   async: false,
			   type: "POST",
			   url: "_ajax.php",
			   data: vars,
			   success: function(data){
					message = data;
			   }
			});
		}
		if(id != 'noclick'){
			onclick_close = 'onclick="MySimpleLightBox.close();"';
			cursor = "pointer";
		}else{
			onclick_close = '';
			cursor = 'default';
		}
		var html ='<div id="alert_msg" style="width:600px;background-color:#FFFFFF;border: 1px solid #999999; cursor:'+cursor+';float:left" '+onclick_close+'>';
		html+='<div style="float:left"><div id="message_div" style="color:#000;font-size:12px;padding:10px;">'+message+'</div></div>';
		html+='</div>';
		
		MySimpleLightBox.border='1px solid #999999';
		MySimpleLightBox.loadHTML(html);
		if(id != 'noclick'){
			$("#lbox").bind("click",function(){
				if(close_on_click){
					MySimpleLightBox.close();
				}	
			});
		}
	}
	
	function enviarClave(preg,resp){
		var vars = "opc=recoverPassword&ps="+$("#"+preg).val()+"&rs="+$("#"+resp).val();
		//alert($("#"+preg).val()+" "+$("#"+resp).val());
		$("#message_div").html('<img src="images/admin/ajax-loader.gif"');
		$.ajax({
		   async: true,
		   type: "POST",
		   url: "_ajax.php",
		   data: vars,
		   success: function(data){
				$("#message_div").html(data);
		   }
		});
	}
	
	function selectProduct(id,g){
		$("#showSelector").remove();
		$("#desc").show();
		showAvailableSizes(id,g);
	}
	
	function checkQuantityPerProduct(elements){
		var res = true;
		/*
		for(i = 0; i < elements.length; i++){
			if($('#'+elements[i]).length != 0){
				
				if( parseInt($('#q_'+elements[i]).val())  < parseInt($('#'+elements[i]).val()) ){
					$('#'+elements[i]).css("background-color","red");
					res = false;
				}else{
					$('#'+elements[i]).css("background-color","white");
				}
				
			}
		}
		*/
		return res;
	}
	
	function logIn(m,p,rtn,url){
		var vars = "opc=logIn&m="+m+"&p="+p;
		$.ajax({
		   async: true,
		   type: "POST",
		   url: "_ajax.php",
		   data: vars,
		   success: function(data){
				if(!data){
					$('#'+rtn).html(getTranslateEntry("LOGIN_ERROR"));
				}else{
					window.location.href = url;
				}
		   }
		});
	}
	
	function checkAvailable(){
		var vars = "opc=checkAvailable";
		$.ajax({
		   async: true,
		   type: "POST",
		   url: "_ajax.php",
		   data: vars,
		   success: function(data){
				if(data == 0){
					window.location.href = "mi-compra.php";
				}
		   }
		});
	}
	
	function guardarPedido(){
		var vars = "opc=guardarPedido";
		$.ajax({
		   async: true,
		   type: "POST",
		   url: "_ajax.php",
		   data: vars,
		   success: function(data){
				if(data){
					$('#guardado').html(getTranslateEntry("GUARDADO"));
				}else{
					$('#guardado').html(getTranslateEntry("ERROR_AL_GUARDAR"));
				}
		   }
		});
	}
	
	function updateTotalPrice(){
		var vars = "opc=getTotalPrice";
		$.ajax({
		   async: true,
		   type: "POST",
		   url: "_ajax.php",
		   data: vars,
		   success: function(data){
				$('#totalCost').html(data);
		   }
		});
	}
	
	function removeItemFromCart(idx,idtr){
		var vars = "opc=removeFromCart&idx="+idx;
		$.ajax({
		   async: true,
		   type: "POST",
		   url: "_ajax.php",
		   data: vars,
		   success: function(data){
				if(data){
					$('#'+idtr).remove();
					$('#mi_compra').html(data);
				}
				//updateTotalPrice();
		   }
		});
	}
	
	function updateTotal(){
		var vars = "opc=getTotalPrice";
		$.ajax({
		   async: true,
		   type: "POST",
		   url: "_ajax.php",
		   data: vars,
		   success: function(data){
				$('#totalCost').html(data);
		   }
		});
	}
	
	function recuperarCarrito(){
		if(confirm(getTranslateEntry("SE_PERDERAN_LOS_DATOS"))){
			var vars = "opc=recuperarCarrito";
			$.ajax({
			   async: true,
			   type: "POST",
			   url: "_ajax.php",
			   data: vars,
			   success: function(data){
					window.location.href="mi-compra.php";
			   }
			});
		}
	}
	
	function showAvailableSizes(idp,gender){
		$("#desc_talle").remove();
		$("#desc_color").remove();
		$("#wrap_price").remove();
		var vars = "opc=showAvailableSizes&idp="+idp+"&gender="+gender;
		$.ajax({
		   async: true,
		   type: "POST",
		   url: "_ajax.php",
		   data: vars,
		   success: function(data){
		     $('#desc').append(data);
		   }
		});
	}
	
	function subscribeToNewsletter(name,email){
		//alert("Name: "+name+"\nemail: "+email);
		var vars = "opc=registerForNewsletter&name="+name+"&email="+email;
		$.ajax({
		   async: true,
		   type: "POST",
		   url: "_ajax.php",
		   data: vars,
		   success: function(data){
		     $('#rta').html(data);
		   }
		});
	}
	
	function checkQuantity(quantity){
		// Devuelve TRUE si cantidad solicitada es mayor a 0
		if(quantity > 0){
			return true;
		}else{
			return false;
		}
	}
	
	function showAvailableColors(idp,gender,size){
		$("#desc_color").remove();
		$("#wrap_price").remove();
		var vars = "opc=showAvailableColors&idp="+idp+"&gender="+gender+"&size="+size;
		$.ajax({
		   async: true,
		   type: "POST",
		   url: "_ajax.php",
		   data: vars,
		   success: function(data){
		     $('#desc').append(data);
		   }
		});
	}
	
	function showPrice(idp,gender,size,color){
		$("#wrap_price").remove();
		var vars = "opc=showPrice&idp="+idp+"&gender="+gender+"&size="+size+"&color="+color;
		$.ajax({
		   async: true,
		   type: "POST",
		   url: "_ajax.php",
		   data: vars,
		   success: function(data){
		     $('#desc').append(data);
		   }
		});
	}
	
	$.fn.clearForm = function() {
	  return this.each(function() {
	    var type = this.type, tag = this.tagName.toLowerCase();
	    if (tag == 'form')
	      return $(':input',this).clearForm();
	    if (type == 'text' || type == 'password' || tag == 'textarea')
	      this.value = '';
	    else if (type == 'checkbox' || type == 'radio')
	      this.checked = false;
	    else if (tag == 'select')
	      this.selectedIndex = -1;
	  });
	};
	$.fn.image = function(src, f){ 
		   return this.each(function(){ 
		     var i = new Image(); 
		     i.src = src; 
		     i.onload = f; 
		     this.appendChild(i);
		   }); 
	 }; 
	
	
	function sendForm(array_fields,rta_field,to,subject,opc){
		var sendingMsg = getTranslateEntry("sending");
		var h=$('#'+rta_field).outerHeight();
	
		var vars='opc='+(opc!=''?opc:'sendForm')+'&to='+to+'&subject='+subject;
		for(var i=0; i<array_fields.length;i++){
			vars+= "&"+array_fields[i]+"_desc="+$('#'+array_fields[i]).attr('title');
			vars+= "&"+array_fields[i]+"="+$('#'+array_fields[i]).val();
		}
		$('#'+rta_field).html("<h3>"+sendingMsg+"...</h3>");
		$('#'+rta_field).css("display","block");
		
		$.ajax({
		   async: true,
		   type: "POST",
		   url: "_ajax.php",
		   data: vars,
		   success: function(data){
		     $('#'+rta_field).html(data).fadeOut(10000,function(){$('#'+rta_field).css("display","none");});
		   }
		 });
	}
	
	function getTranslateEntry(word){
		var translation="";
		$.ajax({
		   async: false,
		   type: "GET",
		   url: "_ajax.php",
		   data: "opc=translate&word="+word,
		   success: function(data){
		    translation = data;
		   }
		 });
		return translation;
	}
	
	function registerUser(){
		
		var translation="opc=registerUser&name=";
		$.ajax({
		   async: false,
		   type: "POST",
		   url: "_ajax.php",
		   data: "opc=translate&word="+word,
		   success: function(data){
		    translation = data;
		   }
		 });
		return translation;
	}
	
	function emailCheck (emailStr) {
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		return reg.test(emailStr) == false?false:true;
	}
	
	function checkDate(y,m,d){
		y=document.getElementById(y);
		m=document.getElementById(m);
		d=document.getElementById(d);
		if(m.value==2){
			if(y.value % 4==0){
				if(d.value>29){
					d.value=29;
				}
			}
			else{
				if(d.value>28){
					d.value=28;
				}
			}
	   }
	   else{
		   if(m.value==4||m.vlaue==6||m.value==9||m.value==11){
			   if(d.value>30){
				   d.value=30;
			   }
		   }
	   }	 
	}	
	
	function restrictInputLength(form_id){
		var inputs=null;
		if(form_id!='' && form_id!=undefined){
			inputs = $("#"+form_id+" input[type='text'],input[type='password'], textarea");
		}
		else{
			inputs = $("input[type='text'],input[type='password'], textarea");
			
		}
		inputs.each(function(){
			var maxlength = 0;
			
			var class_name = $(this).attr("class").split(" ");
		 	for(var i=0; i<class_name.length;i++){
				if(jQuery.trim(class_name[i]).indexOf("maxlength_")!=-1){
					maxlength = parseInt(jQuery.trim(class_name[i]).replace("maxlength_",""));
				}
			}
			
		 	if(maxlength > 0){
				$(this).keypress(function(evt){
					textCounter(this,maxlength,evt);
				});
				$(this).change(function(evt){
					textCounter(this,maxlength,evt);
				});
				
				if(document.all){
					this.onpaste = function(){
						maxLengthPaste(this,maxlength);
					};
				}
				else{
					$(this).attr("oninput",'textCounter(this,'+maxlength+',event)');
				}	
				
			}
		 	
		});	
	}
	
	function maxLengthPaste(field,maxChars){
	    event.returnValue=false;
	    if((field.value.length + window.clipboardData.getData("Text").length) > maxChars){
	       return false;
	    }
	    event.returnValue=true;
	} 
	function textCounter(field,maxlimit,evento) {
		
		var ex=new Array('8','46','37','38','39','40','116');
		if(in_array(ex,evento.keyCode)){
			return;	
		}
		if (field.value.length >= maxlimit){ // if too long...trim it!
				cancelEvent(evento);
				field.value = field.value.substring(0, maxlimit);
		}
	}		
	
	function checkTextLength(l){
		aux=new String();
		aux=event.srcElement.value;
		if(aux.length>=l){
			event.returnValue=false;
		}
	}
	
	function isCaptchaCodeCorrect(code){
		var bool =true;
		$.ajax({
			   async: false,
			   type: "GET",
			   url:  "_ajax.php",
			   data:  "opc=getCaptcha&captcha="+code,
			   success: function(data){
					if(data==0){
						 bool=false;
					}
			   }
			});
		 return bool;
	}
	
	function updateCaptcha(layer){
		
		$.ajax({
		   async: false,
		   type: "GET",
		   url:  "_ajax.php",
		   data:  "opc=updateCaptcha",
		   success: function(data){
				$(layer).replaceWith(data);
		   }
		});
	}
	
	function checkFormFields(frm,animate,animate_msg,field_font_color,field_background_color){ //(formulario, array de campos a validar,idioma,animar(1|0)?,mostrar alerta(1|0)?)
		var msg="";
		var verify = true;
		var show_alert  = false;
		$("#"+frm+" input,#"+frm+" select,#"+frm+" textarea,#"+frm+" div").each(function(){
			
			if($(this).hasClass("required")){
				
				if($(this).attr('id').indexOf('captcha')!=-1){
					verify = isCaptchaCodeCorrect($(this).val());
				}
				if( (jQuery.trim($(this).val())=='' || ($(this).attr('id').toLowerCase().indexOf('email')!=-1 && !emailCheck($(this).val())) || ($(this).attr('type')=='checkbox' && !$(this).attr('checked')) ||  ($(this).attr('id').lastIndexOf("_confirmation")!=-1 && $(this).val()!= $("#"+$(this).attr('id').replace("_confirmation","")).val()) || verify==false) && ( $(this).parents(".no_display").length==0 ) ){
					show_alert = true;
					msg=msg+"\n"+$(this).attr('title');
					if($(this).attr('type')!='checkbox' && $(this).attr('type')!='radio'){
						if(animate==1){
							if(animate_msg!=1){   
								$(this).effect("highlight", {color:"#FF0000"},1000,function(){});
							}
							else{
								$(this).css("backgroundColor","#FF0000");
								$(this).css("color","#FFFFFF");
							}
						}
					}
					if(($(this).attr('type')=='checkbox' || $(this).attr('type')=='radio') && $(this).attr('checked')!=true){
						var type = $(this).attr('type');
						/*
						var w=$(this).outerWidth();
						var	h=$(this).outerHeight();
						*/
						var w=15;
						var	h=15;
						
						var style = $(this).attr("style");
						var className = $(this).attr("class");
						var title = $(this).attr("title");
						var chk_id = "chk_"+getMicrotime();
						var div = '<div onclick="$(this).replaceWith(\'<input title=&quot;'+$(this).attr('title')+'&quot; id=&quot;'+$(this).attr('id')+'&quot;  checked=&quot;checked&quot; class=&quot;'+className+'&quot; type=&quot;'+type+'&quot;/>\');" class="'+className+'" title="'+title+'" style="background-color:#FF0000;height:'+h+'px;width:'+w+'px"></div>';
						var div = '<div id="'+chk_id+'" class="'+className+'" title="'+title+'" style="background-color:#FF0000;height:'+h+'px;width:'+w+'px"></div>';
						$(this).replaceWith(div);
						$("#"+chk_id).click(function(){
							var chk = '<input checked="checked" type="'+type+'" class="'+className+'" style="'+style+'" title="'+title+'"/>';
							$(this).replaceWith(chk);
						});
					}
					$(this).one("click", function(){
						$(this).css("backgroundColor",field_background_color);
				   		$(this).css("color",field_font_color);
				   		//$(this).val("");
					});
					$(this).one("focus", function(){
						$(this).css("backgroundColor",field_background_color);
				   		$(this).css("color",field_font_color);
				   		//$(this).val("");
					});
					$(this).one("keypress", function(){
				   		$(this).css("backgroundColor",field_background_color);
					   	$(this).css("color",field_font_color);
					   	//$(this).val("");
				   		
					});
				}	
			}
		});
	  
	   if(show_alert){
			if(animate!=1){
				msg = getTranslateEntry("complete_following_fields")+": "+msg;
		   		alert(msg);
		   	}
			else{
				if(animate_msg==1){
					showAlertMessage(getTranslateEntry("complete_required_fields"),"error",1);
				}
			}
			return false;
	   }
	   else{
			return true;
	   }	
	}
	
	function focusIn(frm,field){
		//if($("#"+frm+"#"+field).val == ''){
	}
	
	function focusOut(frm,field){
		
	}
	
	function showAlertMessage(message,icon,close_on_click){
		/* ICONS:ajax,info,alert,error */
		var img_icon="";
		close_on_click = close_on_click == '' || close_on_click == undefined  ? false: close_on_click; 
		if(icon=='ajax'){img_icon="images/admin/ajax-loader.gif";}
		else if (icon=='info'){img_icon="images/admin/icon-dialog-info.png";}
		else if (icon=='error'){img_icon="images/admin/icon-dialog-error.png";}
		else if (icon=='password'){img_icon="images/admin/icon-dialog-password.png";}
		else if (icon=='warning'){img_icon="images/admin/icon-dialog-warning.png";}
		else{img_icon="images/admin/icon-dialog-warning.png";}
		
		var html ='<div id="alert_msg" style="width:600px;background-color:#FFFFFF;border: 1px solid #999999; cursor:pointer;float:left" onclick="MySimpleLightBox.close();">';
		html+='<div style="float:left"><img style="margin:10px" src="'+img_icon+'"></div>';
		html+='<div style="float:left"><div style="color:#000;font-size:12px;padding-top:30px;">'+message+'</div></div>';
		html+='</div>';
		
		MySimpleLightBox.border='1px solid #000';
		MySimpleLightBox.loadHTML(html);
		MySimpleLightBox.bgColor="#FFFFFF";
		$("#alert_msg").corners("5px");
		$("#lbox").bind("click",function(){
			if(close_on_click){
				MySimpleLightBox.close();
			}	
		});
		
	}
	
	function in_array(mat,field){
			var i;
			for(i=0;i<mat.length;i++){
				if(mat[i].toLowerCase()==new String(field).toLowerCase()){
					return true;
				}	
			}
			return false;	
	}
	
	function onlyIntegerInputAllowed(e){
		var keynum;
		var keychar;
		var numcheck;
		if(window.event){ // IE
			keynum = e.keyCode;
		}
		else if(e.which){ // Netscape/Firefox/Opera
			keynum = e.which;
		} 
		keychar = String.fromCharCode(keynum);
		numcheck = /\d/;
		
		if(numcheck.test(keychar)==false && keynum!=8 && keynum!=undefined){
			cancelEvent(e);
		}
	} 


	function eventTrigger (e) {
	    	if (! e) e = event;
		    return e.target || e.srcElement;
	}
		
	function cancelEvent(e){
			if(navigator.userAgent.indexOf("MSIE")!=-1){
				e.returnValue=0;	
			}
			if(navigator.userAgent.indexOf("Gecko")!=-1){
				e.preventDefault();	
			}
	}
	
	function validateExtensions(file,ext,evt){
		var auxext=new String(file);
		var extPosibles;
		for (var i=0;i<ext.length;i++){
			if(i==0){
				extPosibles=ext[i];
			}
			else{
				extPosibles += ","+ext[i];
			}
		}
		auxext=auxext.substring(auxext.lastIndexOf('.')+1);
		if(!in_array(ext,auxext)){
			cancelEvent(evt);	
		}
		else{
			return true;	
		}
	
	}
	
	function getMicrotime(){
		var micro = "";
		$.ajax({
		   async: false,
		   type: "GET",
		   url: "_ajax.php",
		   data: "opc=getMicrotime",
		   success: function(data){
		     micro = data;
		   }
		 });
		return micro;
	}
	
	function getCleanFileName(filename){
		$.ajax({
		   async: false,
		   type: "POST",
		   url: "_ajax.php",
		   data: "opc=getCleanFilename&filename="+filename,
		   success: function(data){
	   			filename=data;
		   }
		 });
		 return filename;
	}