/**
 * @author marcg
 */



$(document).ready(function(){
 /*function showError(str){
   var mH = $("body").height();
   $(".fade").css({"width":"100%","height":mH,"opacity":0}).animate({opacity:0.6},800,function(){
   $('.jqmWindow').slideToggle().find(".msg").html(str);
   })
 }
 $('.jqmWindow .close').click(function(){
   $('.jqmWindow').slideToggle(function(){
     $(".fade").css({"width":"1px","height":"1px"}).animate({opacity:0},800)
   })
 });*/
 
 if($.browser.msie){ 
   var cont = $("#swfGallery").html();
   $("#swfGallery").html("").html(cont);
 };
 
 $('#contacto').submit(
   function(){
    var noErr = true;
    var errCode = "No s'ha pogut enviar degut a que els camps en vermell no eren valids";
    $(this).find(".required").each(function(i,el){
	if( $(el).val().length > 0 ){ // si el valor es mayor de 0
	  if( $(el).attr("id") == "email" ){
	    if( !$(el).val().match(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i) ){
	      noErr = false;
	      $(el).addClass("error"); // marcamos el campo como no valido
	    }else{
	      $(el).removeClass("error");
	    };
	  }else if($(el).attr("id") == "telefon" || $(el).attr("id") == "mobil" ){
             if( !$(el).val().match(/^\d+$/i) ){
              noErr = false;
	      $(el).addClass("error"); // marcamos el campo como no valido
	     }else{
	      $(el).removeClass("error");
	     };
	  }else{
	    $(el).removeClass("error"); // marcamos el campo como no valido
	  };
        }else{ // si no es mayor de 0
	  $(el).addClass("error"); // marcamos el campo como no valido
	  noErr = false;
        };
    })
    
    if( !noErr ){ /*showError(errCode);*/ 
      $.ajax({
	 type: "GET",
	 url: "lib/js/error.js",
	 dataType: "script",
	 success:function(){
	    alert(errors[$("#locale").val()])
	 }
      });
    };
    return noErr
  })
})

