			$(function(){

				// Tabs
				$('#tabs').tabs({
					disabled: [1, 2, 3, 4, 5]
				});
			
				// Progressbar
				$("#progressbar").progressbar({
					value: 0 
				});
				
				$("#wait").dialog({
					modal: true,
					autoOpen: false,
					draggable: false,
					closeOnEscape: false,
					resizable: false,
					closeText: 'hide',
					show: 'puff',
					width: 400,
					height:60,
					open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); }
				});

				
				$('#next1, #next2, #next3, #next4, #next5').click(function(){
					nexttab();
					return false;
				});
				
				var options = { 
			        target:        '#wmsg', 
			        beforeSubmit:  showRequest,
			        success:       showResponse,
        			url: 'process.php',
		 	       	resetForm: true
 			    }; 
				$('#sondajfrm').ajaxForm(options); 
				function showRequest() {
					$('#wait').dialog("open");
				}
				function showResponse() {
					$('#trimite').hide();
					$('#progresss').html("Progres: 100%");
					$("#progressbar").progressbar({value: 100});
					$('#wait').dialog("option", "height", 150);
				}
				$('#trimite').click(function(){
					var sex = $("#tabs-6 input[@name=sex]:checked").val();
					var varsta = $("#tabs-6 input[@name=varsta]:checked").val();
					if(sex==undefined || varsta==undefined) {
							$('#output6').html("Va rugam selectati un raspuns!");
					} else {
						$('#output6').html(" ");
						$('#sondajfrm').submit();
					}
       		 	});
				
				$('#next1, #next2, #next3, #next4, #next5, #trimite').hover(
					function() { $(this).addClass('ui-state-hover'); }, 
					function() { $(this).removeClass('ui-state-hover'); }
				);	
				
				function nexttab() {
					var $tabs = $('#tabs').tabs();
					var selected = $tabs.tabs('option', 'selected');
					if (selected==0) {
						var q1c = $("#tabs-1 input[@name=q1]:checked").val();
						if(q1c==undefined) {
							$('#output1').html("Va rugam selectati un raspuns!");
						} else if(q1c=='c') {
							$('#output1').html(" ");
							$('#tabs').tabs("enable", 5);
							$('#tabs').tabs("disable", 1);
							$('#tabs').tabs("disable", 2);
							$('#tabs').tabs("disable", 3);
							$('#tabs').tabs("disable", 4);
							$('#tabs').tabs("select", 5);
							$('#progresss').html("Progres: 80%");
							$("#progressbar").progressbar({value: 80});
							$('#g1, #graph1').addClass('showw');
						    $('#g1, #graph1').removeClass('hidee');
						} else {
							$('#output1').html(" ");
							$('#tabs').tabs("enable", selected+1);
							$('#tabs').tabs("select", selected+1);
							var prc = (selected+1)*16;
							$('#progresss').html("Progres: "+prc+"%");
							$("#progressbar").progressbar({value: prc});
							$('#g1, #graph1').addClass('showw');
						    $('#g1, #graph1').removeClass('hidee');
						}
					}
					if (selected==1) {
						var q2c = $("#tabs-2 input[@name=q2]:checked").val();
						if(q2c==undefined) {
							$('#output2').html("Va rugam selectati un raspuns!");
						} else {
							$('#output2').html(" ");
							$('#tabs').tabs("enable", selected+1);
							$('#tabs').tabs("select", selected+1);
							var prc = (selected+1)*16;
							$('#progresss').html("Progres: "+prc+"%");
							$("#progressbar").progressbar({value: prc});
							$('#g1, #graph1').addClass('hidee');
						    $('#g1, #graph1').removeClass('showw');
							$('#g2, #graph2').addClass('showw');
						    $('#g2, #graph2').removeClass('hidee');
						}
					}
					if (selected==2) {
						var q3c = $("#tabs-3 input[@name=q3]:checked").val();
						if(q3c==undefined) {
							$('#output3').html("Va rugam selectati un raspuns!");
						} else {
							$('#output3').html(" ");
							$('#tabs').tabs("enable", selected+1);
							$('#tabs').tabs("select", selected+1);
							var prc = (selected+1)*16;
							$('#progresss').html("Progres: "+prc+"%");
							$("#progressbar").progressbar({value: prc});
							$('#g2, #graph2').addClass('hidee');
						    $('#g2, #graph2').removeClass('showw');
							$('#g3, #graph3').addClass('showw');
						    $('#g3, #graph3').removeClass('hidee');
						}
					}
					if (selected==3) {
						var q4c = $("#tabs-4 input[@name=q4]:checked").val();
						if(q4c==undefined) {
							$('#output4').html("Va rugam selectati un raspuns!");
						} else if(q4c=='a') {
							var q4e1c = $("#q4e1 input[@name=q4e1]:checked").val();
							if(q4e1c==undefined) {
								$('#output4').html("Va rugam selectati un raspuns!");
							} else {
								$('#output4').html(" ");
								$('#tabs').tabs("enable", selected+1);
								$('#tabs').tabs("select", selected+1);
								var prc = (selected+1)*16;
								$('#progresss').html("Progres: "+prc+"%");
								$("#progressbar").progressbar({value: prc});
								$('#g3, #graph3').addClass('hidee');
							    $('#g3, #graph3').removeClass('showw');
								$('#g4, #graph4').addClass('showw');
							    $('#g4, #graph4').removeClass('hidee');
							}
						} else if(q4c=='b') {
							var q4e2c = $("#q4e2 input[@name=q4e2]:checked").val();
							if(q4e2c==undefined) {
								$('#output4').html("Va rugam selectati un raspuns!");
							} else {
								$('#output4').html(" ");
								$('#tabs').tabs("enable", selected+1);
								$('#tabs').tabs("select", selected+1);
								var prc = (selected+1)*16;
								$('#progresss').html("Progres: "+prc+"%");
								$("#progressbar").progressbar({value: prc});
								$('#g3, #graph3').addClass('hidee');
							    $('#g3, #graph3').removeClass('showw');
								$('#g4, #graph4').addClass('showw');
							    $('#g4, #graph4').removeClass('hidee');
							}
						} else if(q4c=='c') {
							var q4e3c = $("#q4e3 input").val();
							if(q4e3c==undefined || q4e3c=='' || q4e3c ==' ') {
								$('#output4').html("Va rugam selectati un raspuns!");
							} else {
								$('#output4').html(" ");
								$('#tabs').tabs("enable", selected+1);
								$('#tabs').tabs("select", selected+1);
								var prc = (selected+1)*16;
								$('#progresss').html("Progres: "+prc+"%");
								$("#progressbar").progressbar({value: prc});
								$('#g3, #graph3').addClass('hidee');
							    $('#g3, #graph3').removeClass('showw');
								$('#g4, #graph4').addClass('showw');
							    $('#g4, #graph4').removeClass('hidee');
							}
						}
					}
					if (selected==4) {
						var q5c = $("#tabs-5 input[@name=q5]:checked").val();
						if(q5c==undefined) {
							$('#output5').html("Va rugam selectati un raspuns!");
						} else {
							$('#output5').html(" ");
							$('#tabs').tabs("enable", selected+1);
							$('#tabs').tabs("select", selected+1);
							var prc = (selected+1)*16;
							$('#progresss').html("Progres: "+prc+"%");
							$("#progressbar").progressbar({value: prc});
							$('#g4, #graph4').addClass('hidee');
						    $('#g4, #graph4').removeClass('showw');
							$('#g5, #graph5').addClass('showw');
						    $('#g5, #graph5').removeClass('hidee');
						}
					}
				}
				
				$('#q4a').click(function() {
					 $('#q4e1').addClass('showw');
					 $('#q4e1').removeClass('hidee');
					 
					 $('#q4e2').addClass('hidee');
					 $('#q4e2').removeClass('showw');
					 
					 $('#q4e3').addClass('hidee');
					 $('#q4e3').removeClass('showw');
				});
				$('#q4b').click(function() {
					 $('#q4e2').addClass('showw');
					 $('#q4e2').removeClass('hidee');
					 
					 $('#q4e1').addClass('hidee');
					 $('#q4e1').removeClass('showw');
					 
					 $('#q4e3').addClass('hidee');
					 $('#q4e3').removeClass('showw');
				});
				$('#q4c').click(function() {
					 $('#q4e3').addClass('showw');
					 $('#q4e3').removeClass('hidee');
					 
					 $('#q4e2').addClass('hidee');
					 $('#q4e2').removeClass('showw');
					 
					 $('#q4e1').addClass('hidee');
					 $('#q4e1').removeClass('showw');
				});	
			});
