$(function(){
	//Dialog
	
	$("#dialog-question").dialog({
		autoOpen: false,
		bgiframe: true,
		resizable: false,
		height:260,
		width:520,
		modal: true,
		overlay: {
			backgroundColor: '#000',
			opacity: 0.5
		},
		buttons: {
			'Enviar Pregunta!': function() {
				$.ajax({
					type: "POST",
					url: "ajax.php",
					data: "productoId=" + $("#productoId").val() + "&question=" + $("#question").val() + "&accion=17",
					success: function(datos){
						eval(datos);						
					},
					error: function(objeto, quepaso, otroobj){
						alert("Ha ocurrido un error intentelo nuevamente");
					}
				});
				$(this).dialog('close');
			},
			'Cancelar': function() {
				$(this).dialog('close');
			}
		},
		close: function() {
			$("#titulo-comentario").val('');
			$("#nuevo-comentario").val('');
		}
	});	
	
	$("#dialog-comment").dialog({
		autoOpen: false,
		bgiframe: true,
		resizable: false,
		height:380,
		width:520,
		modal: true,
		overlay: {
			backgroundColor: '#000',
			opacity: 0.5
		},
		buttons: {
			'Guardar Comentario!': function() {
				$.ajax({
					type: "POST",
					url: "ajax.php",
					data: "titulo=" + $("#titulo-comentario").val() + "&comentario=" + $("#nuevo-comentario").val() + "&cual=" + $("#cual").val() + "&id=" + $("#id_cual").val() + "&accion=13",
					success: function(datos){
						eval(datos);
						
					},
					error: function(objeto, quepaso, otroobj){
						alert("Ha ocurrido un error intentelo nuevamente");
					}
				});
				$(this).dialog('close');
			},
			'Cancelar': function() {
				$(this).dialog('close');
			}
		},
		close: function() {
			$("#titulo-comentario").val('');
			$("#nuevo-comentario").val('');
		}
	});	
	
	$("#dialog-report").dialog({
		autoOpen: false,
		bgiframe: true,
		resizable: false,
		height:150,
		width:300,
		modal: true,
		overlay: {
			backgroundColor: '#000',
			opacity: 0.5
		},
		buttons: {
			'Reportar!': function() {
				agregarReporte(comentario)
				$(this).dialog('close');
			},
			'Cancelar': function() {
				$(this).dialog('close');
			}
		}
	});	
	
	$("#dialog-add").dialog({
		autoOpen: false,
		bgiframe: true,
		resizable: false,
		height:380,
		width:300,
		modal: true,
		overlay: {
			backgroundColor: '#000',
			opacity: 0.5
		},
		buttons: {
			'Agregar!': function() {
				if($("input[@name='cual']:checked").val()==undefined){
					alert("Por favor elija una lista a la cual agregar este producto");
				}else{
					agregarLista($("input[@name='cual']:checked").val(), producto)
					$(this).dialog('close');
				}
			},
			'Cancelar': function() {
				$(this).dialog('close');
			}
		}
	});	


	$("#dialog-user").dialog({
		autoOpen: false,
		resizable: false,
		bgiframe: true,
		modal: true,
		buttons: {
			Ok: function() {
				$(this).dialog('close');
			}
		}
	});
	
	$("#dialog-cart-add").dialog({
		autoOpen: false,
		resizable: false,
		bgiframe: true,
		modal: true,
		width:300,
		buttons: {
			Ok: function() {
				$(this).dialog('close');
			}
		}
	});
	
	$("#dialog-cart-mod").dialog({
		autoOpen: false,
		resizable: false,
		bgiframe: true,
		modal: true,
		width:300,
		buttons: {
			Ok: function() {
				$(this).dialog('close');
			}
		}
	});
	
	$("#dialog-preorder-list").dialog({
		autoOpen: false,
		resizable: false,
		bgiframe: true,
		modal: true,
		width:400,
		buttons: {
			Ok: function() {
				//alert(producto);
				$.ajax({
					type: "POST",
					url: "ajax.php",
					data: "producto="+producto+"&accion=12",
					success: function(datos){
						alert(datos);
					},
					error: function(objeto, quepaso, otroobj){
						alert("Ha ocurrido un error intentelo nuevamente");
					}
				});
				$(this).dialog('close');
			},
			Cancelar: function(){
				$(this).dialog('close');
			}
		}
	});
});

function agregarLista(lista, idProducto){
	$.ajax({
		type: "POST",
		url: "ajax.php",
		data: "parametro1="+idProducto+"&parametro2="+lista+"&accion=3",
		success: function(datos){
			alert(datos);
		},
		error: function(objeto, quepaso, otroobj){
			alert("Ha ocurrido un error intentelo nuevamente");
		}
	});	
	return true;
}

function verDetalle(id){
	window.location = 'detalles-productos.php?productoId=' + id;
}
