/*
 * JAVASCRIPT FUNCTIONS FOR SWWWEET
 * By Javier Usobiaga - www.swwweet.com
 * Requires jQuery Library - www.jquery.com
 */


/*
 * =======================
 * Functions: declaration
 * =======================
 */

/*complete form validation*/
function validaForm(targetForm){
	$(targetForm).submit(
		function(){
			var validacion = true;
			var feedbackMessage = "<ul>";
			$(targetForm+" input[type=text],"+targetForm+" input[type=email],"+targetForm+" textarea").each(
				function(){
					if($(this).attr("value")=="" && $(this).hasClass("required")){
						if($(this).hasClass("name")){
							feedbackMessage+="<li>We need to know your name. You know ours, so it feels just fair!</li>";
						}
						else if($(this).hasClass("email")){
							feedbackMessage+="<li>We need your email. Telepathy won't be supported until HTML6 :-(</li>";
						}
						else if($(this).hasClass("message")){
							feedbackMessage+="<li>There's something you want to tell us, we can feel it. Come on, write a message!</li>";
						}
					validacion = false;
					}
				}
			);
			
			if(validacion ==false){
				feedbackMessage+="</ul>";
				$(targetForm+" .feedback").html(feedbackMessage);
				$(targetForm+" .feedback").fadeIn(500);
			};
			return validacion;
		}
	)
}


/*simple form validation, all fields required*/
function simpleValidaForm(targetForm){
	$(targetForm).submit(
		function(){
			var validacion = true;
			$(targetForm+" input[type=text],"+targetForm+" input[type=email],"+targetForm+" textarea").each(
				function(){
					if($(this).attr("value")==""){
					validacion = false;
					}
				}
			);
			
			if(validacion ==false){
				$(targetForm+" .feedback").html("Please, you need to fill all the form fields.");
				$(targetForm+" .feedback").fadeIn(500);
			};
			return validacion;
		}
	)
}




/*
 * =======================
 * Functions: call
 * =======================
 */

$(document).ready(function(){

	 $(function(){ 
			validaForm("#main-contact form");
			$('input, textarea').placeholder();
		});
	 

});


