// JavaScript Document
$(document).ready(function(){
			$('.shadom p').textShadow();
		
		
		 var options = { 
			//target:        '#output1',   // target element(s) to be updated with server response 
			beforeSubmit:  validate,  // pre-submit callback 
			success:       showResponse,  // post-submit callback 
	 
			// other available options: 
			//url:       url         // override for form's 'action' attribute 
			//type:      type        // 'get' or 'post', override for form's 'method' attribute 
			//dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
			//clearForm: true        // clear all form fields after successful submit 
			resetForm: true        // reset the form after successful submit 
	 
			// $.ajax options can be used here too, for example: 
			//timeout:   3000 
		}; 
		
		var optionsLance = { 
			//target:        '#output1',   // target element(s) to be updated with server response 
			beforeSubmit:  validateLance,  // pre-submit callback 
			success:       showResponseLance,  // post-submit callback 
	 
			// other available options: 
			//url:       url         // override for form's 'action' attribute 
			//type:      type        // 'get' or 'post', override for form's 'method' attribute 
			//dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
			//clearForm: true        // clear all form fields after successful submit 
			resetForm: true        // reset the form after successful submit 
	 
			// $.ajax options can be used here too, for example: 
			//timeout:   3000 
		}; 
		
		$('#myForm').ajaxForm(options);
		$('#myFormLance').ajaxForm(optionsLance);
				
		
		
		function validateLance(formData, jqForm, optionsLance) { 
			// fieldValue is a Form Plugin method that can be invoked to find the 
			// current value of a field 
			// 
			// To validate, we can capture the values of both the username and password 
			// fields and return true only if both evaluate to true 
		 
			var usernameValue = $('input[name=nomeLance]').fieldValue(); 
			var emailValue = $('input[name=emailLance]').fieldValue();
		 
			// usernameValue and passwordValue are arrays but we can do simple 
			// "not" tests to see if the arrays are empty 
			if (!usernameValue[0]  || usernameValue == 'Escreva aqui o seu nome' || usernameValue == 'Write your name' || usernameValue == 'Escriba su nombre') { 
				//alert('Por favor insira o seu nome!'); 
				$('#nomeLance').fadeIn('slow');
				return false; 
			} else { $('#nomeLance').fadeOut('slow'); }
			
			if (!emailValue[0] || emailValue == 'Escreva aqui o seu e-mail' || emailValue == 'Write your email' || emailValue == 'Escriba su e-mail') { 
				//alert('Por favor insira o seu e-mail!');
				$('#emailLance').fadeIn('slow');
				return false; 
			} else { $('#emailLance').fadeOut('slow'); }
		}
		
		function validate(formData, jqForm, options) { 
			// fieldValue is a Form Plugin method that can be invoked to find the 
			// current value of a field 
			// 
			// To validate, we can capture the values of both the username and password 
			// fields and return true only if both evaluate to true 
		 
			var usernameValue = $('input[name=nome]').fieldValue(); 
			var emailValue = $('input[name=email]').fieldValue();
		 
			// usernameValue and passwordValue are arrays but we can do simple 
			// "not" tests to see if the arrays are empty 
			if (!usernameValue[0]  || usernameValue == 'Escreva aqui o seu nome' || usernameValue == 'Write your name' || usernameValue == 'Escriba su nombre') { 
				//alert('Por favor insira o seu nome!'); 
				$('#nome').fadeIn('slow');
				return false; 
			} else { $('#nome').fadeOut('slow'); }
			
			if (!emailValue[0] || emailValue == 'Escreva aqui o seu e-mail' || emailValue == 'Write your email' || emailValue == 'Escriba su e-mail') { 
				//alert('Por favor insira o seu e-mail!');
				$('#email').fadeIn('slow');
				return false; 
			} else { $('#email').fadeOut('slow'); }
		} 
		 
		// post-submit callback 
		function showResponseLance(responseText, statusText, xhr, $form)  {
			$('#nomeLance').fadeOut('slow');
		    $('#emailLance').fadeOut('slow');
			$('#principalLance').fadeOut('slow', function () {
				$('#respostaLance').fadeIn('slow');
          	});
		 
			//alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
				//'\n\nThe output div should have already been updated with the responseText.'); 
		}
		
		// post-submit callback 
		function showResponse(responseText, statusText, xhr, $form)  {
			$('#nome').fadeOut('slow');
		    $('#email').fadeOut('slow');
			$('#principal').fadeOut('slow', function () {
				$('#resposta').fadeIn('slow');
          	});
		 
			//alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
				//'\n\nThe output div should have already been updated with the responseText.'); 
		}
});
