/**
 * @author marcg
 */
// cookie functions http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}
// /cookie functions
 
 
  // carga del arbol DOM completa
  $(document).ready(function(){
	 $("#left_bar ul").find(" li ul").css({"display":"none"})
	 $("#left_bar ul").Accordion();
	 // vinculamos el evento de redimensionar a la funcion redim
  	 $(window).bind("resize",redim);
	 $(window).load(redim);
	 // y la llamamos
  });
  // funcion redim
  var redim = function(){
	var ofH = document.getElementById("page").clientHeight - ( $("#footer").height() + $("#header").height() ); // Asi mide la altura
	$("#left_bar #menu").height( ofH );
	return true; // stop propagation
  };
  
$(document).ready(function(){
 $('#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("formError"); // marcamos el campo como no valido
	    }else{
	      $(el).removeClass("formError");
	    };
	  }else if($(el).attr("id") == "telefon" ){
             if( !$(el).val().match(/^\d+$/i) ){
              noErr = false;
	      $(el).addClass("formError"); // marcamos el campo como no valido
	     }else{
	      $(el).removeClass("formError");
	     };
	  }else{
	    $(el).removeClass("formError"); // marcamos el campo como no valido
	  };
        }else{ // si no es mayor de 0
	  $(el).addClass("formError"); // marcamos el campo como no valido
	  noErr = false;
        };
    })
    if( !noErr ){ alert(errCode); };
    return noErr
  })
  var sf = '<object type="application/x-shockwave-flash" data="img/animac.swf" width="464" height="313">';
  sf += '<param name="movie" value="img/animac.swf" />';
  sf += '</object>';
  $("#flash_intro").html(sf)
})
