$(document).ready(function()
{
	$("#destacados").scrollable({ circular: true }).autoscroll(8000).navigator({ navi:'#navegador-destacado' });
	
	
	$("ul.tabs").tabs("div.pane > div.contenedor-pane", {effect: 'ajax'});
	
$("#select_provincias").bind("change", cargarDistribuidor);
$("#listadoModelos").bind("change", obtenerPrecioModelo);
$("#envio-soporte").bind("click", soporte);
$("#envio-review").bind("click", review);
	
	$("a.fancybox").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	400, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		'titlePosition'	:	'over'
	});
	
});
	
function cargarDistribuidor()
{
	id = $(this).val();
	$.ajax({
		type: "POST",
		url: '/distribucion/carga_distribuidores.php?provincia='+id,
		success: function(data)
		{
			$("#todos_distribuidores").html(data);
		}
	});
}

function cargarDistribuidorMapa(id)
{
	
	$.ajax({
		type: "POST",
		url: '/distribucion/carga_distribuidores.php?provincia='+id,
		success: function(data)
		{
			$("#todos_distribuidores").html(data);
		}
	});
}

function cargarTodosDistribuidor()
{
	
	$.ajax({
		type: "POST",
		url: '/distribucion/carga_distribuidores',
		success: function(data)
		{
			$("#todos_distribuidores").html(data);
		}
	});
}	

function obtenerPrecioModelo()
{
	id = $(this).val();
	$.ajax({
		type: "POST",
		url: '/scriptsTienda/getPrecioModelo.php?idModelo='+id,
		success: function(data)
		{
			$("#precio").html(data);
		}
	});
}

function soporte()
{	
	var nombre = $("input[id=nombre]").val();
	var nombre_oculto = $("#nombre_oculto").val();
	var email = $("input[id=email]").val();
	var email_oculto = $("#email_oculto").val();
	var comentario = $("#comentario").val();
	var comentario_oculto = $("#comentario_oculto").val();
	var error_general = $("#error_general").val();
	var error_vacio = $("#error_vacio").val();
	var error_email = $("#error_email").val();	
	var mensaje_enviado = $("#mensaje_enviado").val();
	var texto_mensaje_enviado = $("#texto_mensaje_enviado").val();
	var error = 0;
	var error_vacio_1 = 0;	
	var error_email_1 = 0;	
	
	
	$("#notificacion").html('');	
	$("#notificacion-vacio").html('');	
	$("#notificacion-email").html('');		
if ((nombre == nombre_oculto) || (nombre == ""))
	{					
		document.getElementById("nombre").style.borderColor = "#FF0000";	
		document.getElementById("nombre").style.MozBorderRadius = "5px";
		document.getElementById("nombre").style.WebkitBorderRadius = "5px";		
		document.getElementById("nombre").style.borderRadius = "5px";			
		error_vacio_1=1;
		error=1;
	}
	else
	{
		document.getElementById("nombre").style.borderColor = "#CCC";	
		document.getElementById("nombre").style.MozBorderRadius = "5px";
		document.getElementById("nombre").style.WebkitBorderRadius = "5px";		
		document.getElementById("nombre").style.borderRadius = "5px";	
		
		
	}		
	if ((email == email_oculto) || (email == ""))
	{
		document.getElementById("email").style.borderColor = "#FF0000";
		document.getElementById("email").style.MozBorderRadius = "5px";
		document.getElementById("email").style.WebkitBorderRadius = "5px";		
		document.getElementById("email").style.borderRadius = "5px";				
		error_vacio_1=1;
		error=1;
	}
	else
	{		
		if ((validarEmail(email)) == false)
		{
			document.getElementById("email").style.borderColor = "#FF0000";	
			document.getElementById("email").style.MozBorderRadius = "5px";
			document.getElementById("email").style.WebkitBorderRadius = "5px";		
			document.getElementById("email").style.borderRadius = "5px";	
			error=1;
			error_email_1=1;
		}
		else
		{
			document.getElementById("email").style.borderColor = "#CCC";
			document.getElementById("email").style.MozBorderRadius = "5px";
			document.getElementById("email").style.WebkitBorderRadius = "5px";		
			document.getElementById("email").style.borderRadius = "5px";				
			
		}
	}
	if ((comentario == comentario_oculto) || (comentario == ""))
	{
		document.getElementById("comentario").style.borderColor = "#FF0000";	
		document.getElementById("comentario").style.MozBorderRadius = "5px";
		document.getElementById("comentario").style.WebkitBorderRadius = "5px";		
		document.getElementById("comentario").style.borderRadius = "5px";		
		error_vacio_1=1;
		error=1;
	}
	else
	{
		document.getElementById("comentario").style.borderColor = "#CCC";		
		document.getElementById("comentario").style.MozBorderRadius = "5px";
		document.getElementById("comentario").style.WebkitBorderRadius = "5px";		
		document.getElementById("comentario").style.borderRadius = "5px";		
	}	
	
	
	if (error_vacio_1 == 1)
	{
		$("#notificacion-vacio").html('<div class="titulo-verde3" style="clear:both; width:400px;">'+error_vacio+'</div>');		
		
	}
	if (error_email_1 == 1)
	{
		$("#notificacion-email").html('<div class="titulo-verde3" style="clear:both; width:400px;">'+error_email+'</div>');	
		
	}
	if ((error == 0) && (error_vacio_1 == 0) && (error_email_1 == 0))
	{
		$("#notificacion").html('');	
		$.ajax({
				type: 'GET',
				url: '/scripts/contacto/enviar.php?isAjax=1&nombre='+nombre+'&email='+email+'&comentario='+comentario,
				success: function (msg)				
				{
						$("#items-agregados > .informacion-envio").html('<div class="titulo-lightbox">'+mensaje_enviado+'</div>');
					$("#items-agregados > .informacion-envio2").html('<div class="titulo-subLightbox">'+texto_mensaje_enviado+'</div>');
					
					$("#envio-soporte").overlay({
						top: "15%",
						mask:
						{
							color: '#fff',
							loadspeed: 200,
							opacity: 0.7
						},
						closeOnClick: false,
						load: true,
						target: '#items-agregados'
					});
					
					
				}
				});
	}
	
}

function cambiarImagen(imagen)
{
		document.getElementById('principal').src = imagen;
	
}

function review()
{	

	var ruta = $("input[id=ruta]").val();
	var pais= $("#ddlNames").val();
	var mensaje_enviado = $("#mensaje_enviado").val();
	var texto_review_enviado = $("#texto_review_enviado").val();
	
	var error_vacio = $("#error_vacio").val();
	var error_vacio_1 = 0;	
	var error_email_1 = 0;	
	
	
	$("#notificacion").html('');	
	$("#notificacion-vacio").html('');	
	$("#notificacion-email").html('');		
	
	if (ruta == "")
	{					
		document.getElementById("ruta").style.borderColor = "#FF0000";	
		document.getElementById("ruta").style.MozBorderRadius = "5px";
		document.getElementById("ruta").style.WebkitBorderRadius = "5px";		
		document.getElementById("ruta").style.borderRadius = "5px";			
		error_vacio_1=1;
		error=1;
	}
	else
	{
		document.getElementById("ruta").style.borderColor = "#CCC";	
		document.getElementById("ruta").style.MozBorderRadius = "5px";
		document.getElementById("ruta").style.WebkitBorderRadius = "5px";		
		document.getElementById("ruta").style.borderRadius = "5px";	
		
		
	}		
	
		if (error_vacio_1 == 1)
	{
		$("#notificacion-vacio").html('<div class="titulo-verde3" style="clear:both; width:400px;">'+error_vacio+'</div>');		
		
	}
	if (error_vacio_1 == 0)
	{
		$.ajax({
				type: 'GET',
				url: '/scripts/review/enviar.php?isAjax=1&ruta='+ruta+'&pais='+pais,
				success: function (msg)				
				{
					$("#items-agregados2 > .informacion-envio").html('<div class="titulo-lightbox">'+mensaje_enviado+'</div>');
					$("#items-agregados2 > .informacion-envio2").html('<div class="titulo-subLightbox">'+texto_review_enviado+'</div>');
					
					$("#envio-review").overlay({
						top: "15%",
						mask:
						{
							color: '#fff',
							loadspeed: 200,
							opacity: 0.7
						},
						closeOnClick: false,
						load: true,
						target: '#items-agregados2'
					});
					
					
				}
				});
	}

	
}
