
$(document).ready(function(){
	$('#enterprise').slider({	max:200,
								min:10,
								step:5,
								value:10,
								slide:function(){
									var locations = "#enterprise";
									var locationsval = "#enterpriseval";
									var delay = function() { update_slider(locations,locationsval); };
									setTimeout(delay, 10);
								}
	});
	
	$('#locations').slider({	max:10,
								min:1,
								step:1,
								value:1,
								slide:function(){
									var locations = "#locations";
									var locationsval = "#locationsval";
									var delay = function() { update_slider(locations,locationsval); };
									setTimeout(delay, 10);
								}
	});
	$('#network').slider({	max:35,
							min:1,
							step:1,
							value:1,
							slide:function(){
									var locations = "#network";
									var locationsval = "#networkval";
									var delay = function() { update_slider(locations,locationsval); };
									setTimeout(delay, 10);
							}
	});
	$('#workstation').slider({	min:0,
								max:200,
								step:5,
								value:0,
								slide:function(){
									var locations = "#workstation";
									var locationsval = "#workstationval";
									var delay = function() { update_slider(locations,locationsval); };
									setTimeout(delay, 10);
								}
	});
	$('#laptop').slider({	min:0,
							max:200,
							step:1,
							value:0,
							slide:function(){
									var locations = "#laptop";
									var locationsval = "#laptopval";
									var delay = function() { update_slider(locations,locationsval); };
									setTimeout(delay, 10);
							}
	});
	
	function update_slider(name,div){
		    var offset = $('.ui-slider-handle').offset();
		    var value = $(name).slider('option', 'value');

		    $(div).text(+value);
		}
	
	$("#calculate").click(function(){
//		var name = $("input[name='username']").val();
//		var email = $("input[name='email']").val();
//		var company = $("input[name='company']").val();
//		if(name.length == 0){
//			alert("Name is required!");
//			return false;
//		}
//		if(email.length == 0){
//			alert("Email is required!");
//			return false;
//		}else{
//			var patterns = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
//			if(!patterns.exec(email)){
//				alert("Type a correct Email please!");
//				return false;
//			}
//		}
//		if(company.length == 0){
//			alert("Company Name is required!");
//			return false;
//		}
		var out = "";
		$("input:checked").each(function(){
			out = out + $(this).val()+", ";
		});
		
		var other = $("input[name='other']").val();
		
		$.ajax({
		   type: "POST",
		   url: "calculate.php",
		   data: "enterprise="+$("#enterpriseval").text()+"&location="+$("#locationsval").text()+"&network="+$("#networkval").text()+"&workstation="+$("#workstationval").text()+"&laptop="+$("#laptopval").text()+"&application="+out+"Other="+other,
		   success: function(msg){
		   		var out = msg.search("!");
				if(out > 0){
					alert( msg );
				}else{
					window.location.href="index.php?action=result&"+msg;
				}
		   }
		});
	});
});
