function enviaLogin(){
	user = document.getElementById('user').value;
	pwd = document.getElementById('pwd').value;
	if((user=="")||(pwd =="")) $('#campos_obligatorios').fadeIn("slow");
	else document.getElementById('formlogin').submit();
	
}
function enviaLoginPrensa(){
	pwd = document.getElementById('pwd').value;
	if(pwd !=""){
		document.getElementById('formlogin').submit();
	}
	
}
function loading(capa){
	document.getElementById(capa).innerHTML = '<img class="loadimg" src="imgs/loading.gif" alt="loading &hellip;" />';
}
function oculta_mensajes(){
	$('#msg').fadeOut('slow');
	$('#campos_obligatorios').fadeOut('slow');
	
}
function cargaSeccion(seccion){

	loading('parte_inferior');
	$.ajax({
			   type: "POST",
			   url: "secciones/clientes/clientes.php",
			   data: "ajax=1&OP_1="+seccion,			   
			   success: function(msg){
			   	document.getElementById('parte_inferior').innerHTML = msg;
			   	$.scrollTo(600);
			    }
			 });
	
}
function subscribete(){
	email 	= document.getElementById("subscribe_mail").value;
	var email	=		email.htmlEntities();	
	
	mail_valido = isValidEmail(email);
	if((email!="")&&(mail_valido)){
			
			
			$.ajax({
			   type: "POST",
			   url: "secciones/comunes/insertanewsletter.php",
			   data: "ajax=1&OP_1=submit"+
			   "&email="+email,
			   
			   
			   success: function(msg){
					//alert(msg); 
					tmp = msg.split("__");

					switch(tmp[0]){
						case "error1":
							$('#subscribe').fadeOut("slow");
							document.getElementById("mensaje_newsletter").innerHTML = tmp[1];
							$('#mensaje_newsletter').fadeIn("slow");
						break;
						default:
							$('#subscribe').hide();
							document.getElementById("mensaje_newsletter").innerHTML = tmp[0];
							$('#mensaje_newsletter').fadeIn("slow");
							
							document.getElementById("news_form").reset();
							var t=setTimeout("muestraEnvioNewsletter()",3000);
						break;
					} 
					
			   	//cargaDadesCapa(msg,'container_general');
			   }
			 });
		}else{
			
			if(!mail_valido){
					$('#subscribe').hide();
					
					$('#mensaje_newsletter').fadeIn("slow");
					
					document.getElementById("news_form").reset();
					var t=setTimeout("muestraEnvioNewsletter()",3000);
			}
		}
}
function muestraEnvioNewsletter(){

	$('#subscribe').fadeIn("slow");
	document.getElementById("mensaje_newsletter").innerHTML = mensaje_por_defecto_newsletter;
	$('#mensaje_newsletter').hide();
	
}




function recomienda(){
	email 	= document.getElementById("recomienda_mail").value;
	var email	=		email.htmlEntities();	
	
	mail_valido = isValidEmail(email);
	if((email!="")&&(mail_valido)){
			
			
			$.ajax({
			   type: "POST",
			   url: "secciones/comunes/recomienda.php",
			   data: "ajax=1&OP_1=submit"+
			   "&email="+email,
			   
			   
			   success: function(msg){
					//alert(msg); 
					tmp = msg.split("__");

					switch(tmp[0]){
						case "error1":
							$('#recomienda').fadeOut("slow");
							document.getElementById("mensaje_recomienda").innerHTML = tmp[1];
							$('#mensaje_recomienda').fadeIn("slow");
						break;
						default:
							$('#recomienda').hide();
							document.getElementById("mensaje_recomienda").innerHTML = tmp[0];
							document.getElementById("reco_form").reset();
							$('#mensaje_recomienda').fadeIn("slow");
							var t2=setTimeout("muestraRecomienda()",3000);
						break;
					} 
					
			   	//cargaDadesCapa(msg,'container_general');
			   }
			 });
		}else{
			if(!mail_valido){
			
					$('#recomienda').hide();
					
					$('#mensaje_recomienda').fadeIn("slow");
					
					document.getElementById("reco_form").reset();
					var t=setTimeout("muestraRecomienda()",3000);
			}
		}
}
function muestraRecomienda(){
	$('#recomienda').fadeIn("slow");
	document.getElementById("mensaje_recomienda").innerHTML = mensaje_por_defecto_recomienda;
	$('#mensaje_recomienda').hide();
}
function enviaUsuarioTiendas(){

		nombre 		= document.getElementById("nombre").value;
		pais 			= document.getElementById("pais").value;
		provincia 			= document.getElementById("provincia").value;		
		poblacion 	= document.getElementById("poblacion").value;		
		email 	= document.getElementById("email").value;
		
		
		var nombre		=		nombre.htmlEntities();
		
		var email	=		email.htmlEntities();
		/*var pais		=		pais.htmlEntities();
		var provincia	=		provincia.htmlEntities();
		var poblacion		=		poblacion.htmlEntities();*/
		
		
		
		mail_valido = isValidEmail(email);
		if((nombre!="")&&(poblacion!="")&&(poblacion!=0)&&(provincia!="")&&(provincia!=0)&&(email!="")&&(pais!="")&&(pais!=0)&&(mail_valido)){
			$('#localizador').hide();
			document.getElementById("mensaje_localizador").innerHTML = enviando_datos;
			$('#mensaje_localizador').fadeIn("slow");
			$.ajax({
			   type: "POST",
			   url: "secciones/tiendas/inserta_usuarios.php",
			   data: "ajax=1&OP_1=submit"+
			   "&nombre="+nombre+
			   "&pais="+pais+
			   "&poblacion="+poblacion+
			 
			   "&provincia="+provincia+
			
			   "&email="+email,
			 
			   
			   success: function(msg){
					//alert(msg); 
					tmp = msg.split("__");

					switch(tmp[0]){
						case "error1":
							$('#localizador').hide();
							document.getElementById("mensaje_localizador").innerHTML = tmp[1];
							$('#mensaje_localizador').fadeIn("slow");
							var t3=setTimeout("muestraLocalizador()",3000);
						break;
						default:
							$('#localizador').hide();
							document.getElementById("mensaje_localizador").innerHTML = tmp[0];
							document.getElementById("tiendas_form").reset();
							$('#mensaje_localizador').fadeIn("slow");
							var t3=setTimeout("muestraLocalizador()",3000);
						break;
					} 
					$('#msg').fadeIn("slow");
			   	//cargaDadesCapa(msg,'container_general');
			   }
			 });
		}else{
			if((email!="")&&(!mail_valido)){
			
					$('#localizador').hide();
					document.getElementById("mensaje_localizador").innerHTML = mensaje_por_defecto_recomienda;
					$('#mensaje_localizador').fadeIn("slow");
					var t3=setTimeout("muestraLocalizador()",3000);
			}else{
				$('#localizador').hide();
					
				
					$('#mensaje_localizador').fadeIn("slow");
					var t3=setTimeout("muestraLocalizador()",3000);
			}
		}
		
		

}
function muestraLocalizador(){
	$('#localizador').fadeIn("slow");
	document.getElementById("mensaje_localizador").innerHTML = mensaje_por_defecto_datos_obligatorios;
	$('#mensaje_localizador').hide();
}
function isValidEmail(str) {
   return (str.indexOf(".") >= 1) && (str.indexOf("@") > 0);
}

//	prototipo htmlentity en javascript
String.prototype.htmlEntities = function () {
   return this.replace(/&/g,'_AMP_').replace('>','_GRAN_').replace('<','_PETIT_').replace(/[+]/g,'_PLUS_').replace(/#/g,'_ALMO_');
};

function cargaProvincia(pais){

	$.ajax({
			   type: "POST",
			   url: "secciones/tiendas/cargacombo.php",
			   data: "ajax=1&pais="+pais,
			  
			 
			   
			   success: function(msg){
			   	document.getElementById("combo_provincia").innerHTML =	msg;
			   	cargaLocalidad('');
			   }
	});
}

function cargaLocalidad(provincia){
	$.ajax({
			   type: "POST",
			   url: "secciones/tiendas/cargacombo.php",
			   data: "ajax=1&provincia="+provincia,
			  
			 
			   
			   success: function(msg){
			   	document.getElementById("combo_poblacion").innerHTML =	msg;
			   
			   }
	});
}
