/*
 EnginyWorks Technologies SL
 Javascript Document
*/

$(document).ready(resizepantalla);
$(window).resize(resizepantalla);

function resizepantalla() {
	roda_sense_fi(); roda_sense_fi_2();
	/*if($(window).height()<778){ $('#container_exterior').css("top",40); $('#container_exterior').css("margin-top",0); }
	else{$('#container_exterior').css("top",'50%'); $('#container_exterior').css("margin-top",-350);}
	*/
};

function roda_sense_fi(){
	var angle = 0;
	setInterval(function(){
	      angle+=1;
	     $("#logo_img").rotate(angle);
	},50);
}

function roda_sense_fi_2(){
	var angle = 0;
	setInterval(function(){
	      angle-=1;
	     $("#logo_img_2").rotate(angle);
	},50);
}


//$('#logo').live('mouseenter',function(event){roda_sense_fi();});

//$('#img_psd2html').live('click',function(event){$('#psd2html').slideToggle('slow');});
//$('#img_psd2cms').live('click',function(event){$('#psd2cms').slideToggle('slow');});

var contentForm;
$(function() {
	contentForm=$('#formContacte').html();
	$('.error').hide();
	 /* $('input.text-input').css({backgroundColor:"#FFFFFF"});
	  $('input.text-input').focus(function(){
	    $(this).css({backgroundColor:"#FFDDAA"});
	  });
	  $('input.text-input').blur(function(){
	    $(this).css({backgroundColor:"#FFFFFF"});
	  });*/

	  $("#boto").click(function() {
			// validate and process form
			// first hide any error messages
	    $('.error').hide();
			
		  var nom = $("input#nom").val();
			if (isWhitespace(nom)) {
	      $("label#nom_error").show();
	      $("input#nom").focus();
	      return false;
	    }
			var email = $("input#email").val();
			if (!isEmail(email)) {
	      $("label#email_error").show();
	      $("input#email").focus();
	      return false;
	    }
			var comentaris = $("textarea#comentaris").val();
			if (isWhitespace(comentaris)) {
	      $("label#comentaris_error").show();
	      $("textarea#comentaris").focus();
	      return false;
	    }
			
			var dataString = 'nom='+ nom + '&email=' + email + '&telf=' +  $("input#telf").val() + '&comentaris=' + comentaris;
			//alert (dataString);return false;
			
			$.ajax({
	      type: "POST",
	      url: "contactesendmail.php",
	      data: dataString,
		  beforeSend: function( ) {
			  $("#formContacte").hide();
			  $("#formContacte").html("<div class='fade'><img src='loading.gif' style='margin:200px 0 0 205px'/></div>");
			  $("#formContacte").fadeIn();
		  },	      
	      success: function(data) {
	    	  $('#formContacte').html("<div id='message'></div>");
	    	  if (data=="OK") {
	  	        $('#message').html("Hem rebut els teus comentaris correctament!")
		        .append("<p>En breu ens posarem en contacte amb tu.</p>")
		        .hide()
		        .fadeIn(1500, function() {
		          $('#message').append("<img id='checkmark' src='check.png' />");
		        });	    		  
	    	  }
	    	  else {
	  	        $('#message').html("No s'han enviat els comentaris")
		        .append("<p>Torna-ho a intentar més tard. Disculpa les molèsties.</p>")
		        .hide()
		        .fadeIn(1500, function() {
		          $('#message').append("<img id='checkmark' src='cancel.png' />");
		        });

	    	  }
	      }
	     });
	    return false;
		});
	});
	runOnLoad(function(){
	 // $("input#nom").select().focus();
	});
$('#boto').live('click',function(event){SubmitForm();});
$('#message').live('click',function(event){
	$("#formContacte").hide();
	$("#formContacte").html(contentForm); 
	$("#formContacte").fadeIn();
    $('.error').hide();
});
