$(document).ready(function() {

// TOOLTIP
$("#msg_lavoro").easytooltip("pos_ap", {backgroundcolor: "transparent", border: "0px"});

	
// AJAX UPLOADER
	
new AjaxUpload('#upload_button', {
  // Location of the server-side upload script
  // NOTE: You are not allowed to upload files to another domain
  action: 'Admin/uploadCurriculum.php',
  // File upload name
  name: 'curri',
  // Additional data to send
  data: {
    example_key1 : 'example_value'
  },
  // Submit file after selection
  autoSubmit: true,
  // The type of data that you're expecting back from the server.
  // HTML (text) and XML are detected automatically.
  // Useful when you are using JSON data as a response, set to "json" in that case.
  // Also set server response type to text/html, otherwise it will not work in IE6
  responseType: false,
  // Fired after the file is selected
  // Useful when autoSubmit is disabled
  // You can return false to cancel upload
  // @param file basename of uploaded file
  // @param extension of that file
  onChange: function(file, extension){
	
  },
  // Fired before the file is uploaded
  // You can return false to cancel upload
  // @param file basename of uploaded file
  // @param extension of that file
  onSubmit: function(file, ext) {
                if (!(ext && /^(doc|docx|txt|pdf)$/.test(ext))){
                     // extension is not allowed
					 $('#msg').css('color','#c60000');
                     $('#msg').text("Il file deve essere un doc, docx, txt o pdf!");
                     // cancel upload
                     return false;
           		}

				// If you want to allow uploading only 1 file at time,
				// you can disable upload button
				this.disable();
				$('#msg').css('color','#0ad100');
				$('#msg').text('Caricando... ' + file);
				
  },
  // Fired when file upload is completed
  // WARNING! DO NOT USE "FALSE" STRING AS A RESPONSE!
  // @param file basename of uploaded file
  // @param response server response
  onComplete: function(file, response) {

		// enable upload button
		this.enable();
		$('#curriculum_name').val(''+file);
		// display file
		$('#msg').css('color','#0ad100');
		$('#msg').text("Curriculum caricato: " + file);
 	}
});

// FORM SENDER LAVORA CON NOI
$("#lavoraconnoiForm").validate({
		rules: {
			nome: "required",
			cognome: "required",
			email: {
				required: true,
				email: true
			},
			messaggio: "required",
			privacy: "required"
		},
		messages: {
			nome: " Inserisci il tuo nome",
			cognome: " Inserisci il tuo cognome",
			email: " Inserisci una email valida",
			messaggio: " Inserisci un messaggio",
			privacy: " Obbligatorio..   "
		},
		errorElement: 'errorDiv',
		errorPlacement: function(error, element) {
		      error.insertBefore(element);
		},
		submitHandler: function(form) {
			jQuery(form).ajaxSubmit({
				target: "#result"
			});
			$("#lavoraconnoiForm").resetForm()
		}
		
	});



});