$(document).ready(function(){
	
	$( "#loggaIN" ).click(function() {
//		$("#loggaIN").append("<div style='display:none' id='dialog-form' title='Logga in'>" +
//				"<form action='/names.nsf?login' method='post' id='login-form' onsubmit='return DEXT.Session.Authenticate(this);'>" +
//				"<input type='hidden' value='/orsymobil.nsf/start' name='RedirectTo' />" +
//				"<label for='form_email'>Anv\u00E4ndarnamn</label><br/>" +
//				"<input style='width:200px' type='text' name='username' value='tr@compose.se' id='form_email' class='text ui-widget-content ui-corner-all'/><br/>" +
//				"<label for='form_password'>L\u00F6senord</label><br/>" +
//				"<input style='width:100px' type='password' name='password' value='martinsson' id='form_password' class='text ui-widget-content ui-corner-all'/><br/>" +
//				"<input type='submit' value='Logga in'></form></div>");
		$( "#dialog-form" ).dialog( "open" );
	});
	
	$( "#dialog-form" ).dialog({
			autoOpen: false,
			height: 200,
			width: 350,
			modal: true
	});

	$('#car').change(function(){
		var qs = '&action=ajax&unid=' + $('#unid').val();
		var key = '&key=' + $(this).val();
		$.ajax({
			  url: 'shop?openagent'+ qs + key,
			  success: function(data) {
			   	$("#model").html(data); 
			}
		});
	});
	

  	$('#model').change(function(){
  		var qs = '&action=ajax&unid=' + $('#unid').val();
  		var str = "";
   		$("select option:selected").each(function () {
   			str += "&key="+$(this).text();
   		}); 
   		$.ajax({
			url: 'product?openagent&action=getCarPic'+ str,
			success: function(data) {
   				$("#Bild").html(data);
   				$.ajax({
   					url: 'product?openagent'+ str + qs,
   					success: function(data) {
   						$("#result").html(data);
   					}
   				});
			}
		});
	});
  	$('#filter').change(function(){
  		var qs = '&action=ajax&unid=' + $('#unid').val();
  		var str = "";
   		$("select option:selected").each(function () {
   			str += "&key="+$(this).text();
   		}); 
   		$.ajax({
			url: 'product?openagent&action=getCarPic'+ str,
			success: function(data) {
   				$("#Bild").html(data);
   				$.ajax({
   					url: 'product?openagent'+ str + qs,
   					success: function(data) {
   						$("#result").html(data);
   					}
   				});
			}
		});
	});
  	
	$('a.shop').click(function(){
 		var unid = $(this).attr("ref");
		var id = $(this).attr("id");
		if(unid==""){
			$(this).attr("href","start?openagent&action=additem");
			$(this).attr("target","_top");
		}
		$.ajax({
			  url: 'start?openagent&action=additem&id='+id+'&unid='+ unid,
			  success: function(data) {
			   	$("#varukorg").html(data);
			  }
		});
	});
	

	
	$('.discount').click(function(){
		var id = $(this).attr("ref");
		var discount =  $("#"+id).val();
		var unid = $("#unid").val();
		//alert("hello" + discount + unid);
		$.ajax({
			  url: 'start?openagent&action=discount&unid=' +unid+ '&discount='+discount+'&id='+id, 
			  success: function(data) {
			location.reload();
			}
		});
		
		//alert("hello" + discount);
	});

	
});
