
  function ClearAllControls() 
        {
              for (i=0; i<document.forms[0].length; i++)
              {
                    doc = document.forms[0].elements[i];
                    switch (doc.type) 
                    {
                        case "text" :
                                doc.value = "";
                                break;
                          case "checkbox" :
                                doc.checked = false;
                                break;    
                          case "radio" :
                                doc.checked = false;
                                break;                
                          case "select-one" :
                                doc.options[doc.selectedIndex].selected = false;
                                break;                      
                          case "select-multiple" :
                                while (doc.selectedIndex != -1) 
                                {
                                      indx = doc.selectedIndex;
                                      doc.options[indx].selected = false;
                                }
                                doc.selected = false;
                                break;
                                    
                          default :
                                break;
                    }
              }
        }


$(document).ready(function(){

	ClearAllControls();


	$(function () {  
		 $('.error').hide();  
		 
		 $("input.button").click(function() {  
			var False = 0;	   
		    $('.error').hide();  
		   
	  
			 var soglasje = $("input[name=soglasje]:checked").val();
			   if (soglasje != "on") {  
				 $("label#soglasje_error").show();  
				 $("input#soglasje").focus();  	 
				 False = 1;				 
				}

			var email = $("input#email").val();  
			   if (email == "") {  
				 $("label#email_error").show();  
				 $("input#email").focus();  	 
				 False = 1;				 
				}
				if (email != "") {
					var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
					if(filter.test(email)){ }
					else {  
					$("label#email_error2").show();  
				 	$("input#email").focus();  	
					False = 1; 
					}
				}


			var city = $("input#city").val();  
			   if(city == "") {  
				 $("label#city_error").show();  
				 $("input#city").focus();  
				 False = 1;				 
				}
				else if(city.length < 4) {  
				 $("label#city_error2").show();  
				 $("input#city").focus();  
				 False = 1;				 
				}

			var postNo = $("input#postNo").val();  
			   if(postNo == "") {  
				 $("label#postNo_error").show();  
				 $("input#postNo").focus();  
				 False = 1;		   	
				}
			   else if(postNo.length < 4) {  
				 $("label#postNo_error2").show();  
				 $("input#postNo").focus();  
				 False = 1;
				}  

			var addressNo = $("input#addressNo").val();  
			   if(addressNo == "") {  
				 $("label#addressNo_error").show();  
				 $("input#addressNo").focus();  
				 False = 1;		   	
				}
			   else if(addressNo.length < 1) {  
				 $("label#addressNo_error2").show();  
				 $("input#addressNo").focus();  
				 False = 1;
				}  

			var address = $("input#address").val();  
			   if(address == "") {  
				 $("label#address_error").show();  
				 $("input#address").focus();  
				 False = 1;		   	
				}
			   else if(address.length < 5) {  
				 $("label#address_error2").show();  
				 $("input#address").focus();  
				 False = 1;
				}  

			var lastname = $("input#lastname").val();  
			   if(lastname == "") {  
			   	 $("label#lastname_error").show();  
				 $("input#lastname").focus();  
				 False = 1;
				}			 
			   else if(lastname.length< 3) {  
				 $("label#lastname_error2").show();  
				 $("input#lastname").focus();  
				 False = 1;
				}  

			 var name = $("input#name").val();  
			   if(name == "") {
				 $("label#name_error").show();  
				 $("input#name").focus();  
				 False = 1;				 
				 }
			   else if(name.length< 3) {  
				 $("label#name_error2").show();  
				 $("input#name").focus();  
				 False = 1;
				}
								
			var telefon = $("input#telefon").val();  
			   if(telefon == "") {  
				 $("label#telefon_error").show();  
				 $("input#telefon").focus();  
				 False = 1;		   	
				}
			   else if(telefon.length < 7) {  
				 $("label#telefon_error2").show();  
				 $("input#telefon").focus();  
				 False = 1;
				}  				

			

			if (False == 1) { return false; }
			else {
				

	var dataString = 'lastname=' + lastname + '&name='+ name + '&address='+ address +  '&addressNo='+ addressNo +  '&postNo='+ postNo +'&city='+ city + '&telefon=' + telefon  + '&email=' + email;  
	 $.ajax({  
	   type: "POST",  
	   url: "process.php",  
	   data: dataString,  
	   success: function() { 
		 $('#div_form').html('<h3>Prijava za sodelovanje v nagradni igri je bila uspe&#X161;na!</h3><br />'); 
	   }  
	});  
	return false;  

			}
				
		});  
	});  


});
