
/** FUNCIONES GENERICAS DE JS PARA SERVEIS ACTIUS **/
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

function imgFullScreen(imgSrc){
	Lightview.show({ href: imgSrc });
}

	function changeImg(imgId,newImg){	
		(function ($) {
		$('#'+imgId).fadeOut(400).attr('src',newImg).delay(200).fadeIn(400);
		})(jQuery);
	
	}
	function changeSrc(imgId,newImg){
		(function ($) {
		$('#'+imgId).attr('src',newImg);
		$('#'+imgId).fadeIn(400);
		})(jQuery);
	}

function makepage(src)
{
  // We break the closing script tag in half to prevent
  // the HTML parser from seeing it as a part of
  // the *main* page.

  return "<html>\n" +
    "<head>\n" +
    "<title>Temporary Printing Window</title>\n" +
    "<script>\n" +
    "function step1() {\n" +
    "  setTimeout('step2()', 10);\n" +
    "}\n" +
    "function step2() {\n" +
    "  window.print();\n" +
    "  window.close();\n" +
    "}\n" +
    "</scr" + "ipt>\n" +
    "</head>\n" +
    "<body onLoad='step1()'>\n" +
    "<img src='" + src + "'/>\n" +
    "</body>\n" +
    "</html>\n";
}

function contactarOnline(){
	(function ($) {
		$.colorbox({inline:true, href:"#hiddenform"});
	})(jQuery);
}
function printme(imgSrc)
{
  link = "about:blank";
  var pw = window.open(link, "_new");
  pw.document.open();
  pw.document.write(makepage(imgSrc));
  pw.document.close();
}
/** Contactar cliente **/
function enviaMailAlCliente(form,submit_button, ok_box, error_box, msg_hide_id){
  (function ($) {
    $(submit_button).attr('disabled', 'true');
    $(submit_button).attr('value', "Enviant correu ...");

    $.post($(form).attr("action"), $(form).serialize(), function(data){
		if(data.match(/^OK/) != null) {
		  $(ok_box).html('El seu missatge s\'han enviat correctament');
		  $(error_box).html('');
		  $(form).each (function(){ this.reset();});
		  $(form).hide();
		  setTimeout("enviaMailAlClienteCerrando(3,'"+msg_hide_id+"','"+form+"')",1000);	
		  $(msg_hide_id).css('display', 'block');
		  $.colorbox.resize();
		} else {
		  $(error_box).html(data); 
		}
		$(submit_button).attr('value','Enviar');
		$(submit_button).attr('disabled', '');
	
	
      	});
      	
    })(jQuery);
    return false;
  }
function enviaMailAlClienteCerrando(i,msg_id, form){
	(function ($) {
	if(i>0){
		$(msg_id).html($(msg_id).html()+'.');
		setTimeout("enviaMailAlClienteCerrando("+(i-1)+",'"+msg_id+"','"+form+"')",1000);
	}else{
		$.colorbox.close();
		$(msg_id).css('display', 'none');
		$("ok_box").css('display', 'none');
		$(form).show();
	}
	})(jQuery);
}
;

