// JavaScript Document
$(document).ready(function() {
 
	// email field focus
	//$('#name').focus();
	
   
	// anchor trigger submit
   	$(function() {
  		$("#ahrefsubmit").click(function() {
    		$("form").submit();
    	return false;
  	});
	
	// use this to reset several forms at once
	$("#ahrefreset").click(function() {
		$("form").each(function() {
			this.reset();
		});
	})
}); 

	// prepare the form when the DOM is ready 
	var options = { 
		  beforeSubmit:   validate, 
		  success:       showResponse  
	}; 
 
    // bind to the form's submit event 
    $("#form2").submit(function() { 
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        $(this).ajaxSubmit(options); 
		
        // always return false to prevent standard browser submit and page navigation 	
        return false; 
    }); 	
	
	 $("#form2").ajaxSuccess(function(evt, request, settings){	
	 });
	
});

//pre post validate form values
function validate(formData, jqForm, options) { 
    // jqForm is a jQuery object which wraps the form DOM element 
	 var form = jqForm[0]; 
	 var msgErrorText = "";
	/*
	if validation is NOT OK
	*/
		if (!form.ime.value) { 
		msgErrorText += "Unesite vaše ime<br />";
    } 
  		if (!form.name.value) { 
		msgErrorText += "Unesite vaše prezime <br />";
    } 
		if (!form.naselje.value) { 
		msgErrorText += "Unesite naselje <br />";
    } 
		if (!form.mesto.value) { 
		msgErrorText += "Unesite mesto <br />";
    } 
		 if (!form.rodjen.value) { 
	 	msgErrorText += "Unesite vaš datum rodjenja<br />";
    } 
		 if (!form.tel.value) { 
	 	msgErrorText += "Unesite vaš telefon<br />";
    } 
		if (!form.mob.value) { 
	 	msgErrorText += "Unesite vaš mob. telefon<br />";
    } 
		if (!form.zanimanje.value) { 
		msgErrorText += "Unesite vaše zanimanje <br />";
    }
		if (!form.brlk.value) { 
		msgErrorText += "Unesite broj LK <br />";
    } 
		if (!form.rodnos.value) { 
		msgErrorText += "Unesite status radnog odnosa <br />";
    } 
		if (!form.biro.value) { 
		msgErrorText += "Unesite status na birou <br />";
    } 
		if (!form.vozilo.value) { 
		msgErrorText += "Unesite imate li vozilo <br />";
    } 
		if (!form.marka.value) { 
		msgErrorText += "Unesite marku vozila<br />";
    } 
		if (!form.rbroj.value) { 
		msgErrorText += "Unesite registarski broj <br />";
    } 
		if (!form.boja.value) { 
		msgErrorText += "Unesite boju <br />";
    } 
		if (!form.radiobih.value) { 
		msgErrorText += "Unesite sa kime bi radili <br />";
    } 


	//uploadfile is not *
	
	//print error msg
	if(msgErrorText.length!=0){ 
		//FBug debuger:: 
		//console.log(msgErrorText)
		alert_lightbox("<b>Molimo Vas unesite sledeće podatke:</b><br />" + msgErrorText);
		return false;
	}
	/*
	if validation is OK
	-----------------------------------------------------
	 if visior choosed to upload file for mail attachment 
	 1 - we need to upload it first on server
	 2 - & then send mail with file attachment
	 
	*/
/*	 if (form.uploadfile.value) { 
	 	//FBug debuger:: 
		console.log(form.uploadfile.value)
	 } */
	
	//alert("validation is OK..");
	return true; 
}
 
// post-submit callback 
function showResponse(responseText, statusText)  { 
	 //alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
       // '\n\nThe output div should have already been updated with the responseText.'); 
	 $('#form2').resetForm();
	 alert_lightbox("Hvala na Vašem e-mail-u. Odgovorićemo ubrzo. ");
}

//prompt Fn
function alert_lightbox(msg){
	$.prompt(msg,
	{
		buttons:{'OK':true}, 
		show:'fadeIn',
		opacity: 0.4
	});
}


        
