$(function(){
  
	$('a.email').each(function(){
		e = this.rel.split('#');
		link = e[0]+"@"+e[1]+"."+e[2];
		this.href = 'mailto:' + link;
		$(this).text(link);
	});

	$('img[@src$=.png], .png, .mi_foto').ifixpng();	//png transparentes en IE.

	$('#logotipo').click(function(){
		self.location = base_url;
	});
 
	$("#select_clientes").change(function(){				  
		self.location = $(this).val();
	});

	$('#enviar_contacto').click(function(){
		error = "";
		if ($('#nombre').val().length<3){error += $('#nombre').attr('alt')+"\n";}
		if ( $('#email').val().length<3 || !validar_mail($('#email')) ){ error += $('#email').attr('alt')+"\n"; }
		if ($('#comentarios').val().length<10){error += $('#comentarios').attr('title')+"\n";}
		if ($('#field_codigo').val().length != 5){error += $('#field_codigo').attr('alt')+"\n";}
		if (error != ""){
			alert(error); return;
		} else {
			$('#form_contacto').submit();
		}
	});
	
	$('#enviar_carta').click(function(){
		$('#send_carta').submit();							  
	});

	if ($("#news").length>0){
		$("#news").newsTicker(8000);
	}

	if ($(".lightbox").length>0){
		$(".lightbox").lightbox();
	}
	
	if ($('.captify').length){
		$('.captify').each(function(){
			$objeto = $(this).attr('alt');
			$(this).attr('rel', $objeto);
		});
		$('img.captify').captify({
			speedOver: 150,
			speedOut: 200,
			hideDelay: 100,
			animation: 'fade',	  	
			prefix: '',	
			className: 'caption'
		});
	}

	if ($('.editor').length){
		$('.editor').wysiwyg({
			controls : {
				separator04 : { visible : true },
				insertOrderedList : { visible : true },
				insertUnorderedList : { visible : true },
				separator01 : { visible : true },
				indent  : { visible : true },
				outdent : { visible : true },
				separator02 : { visible : true },
				subscript   : { visible : true },
				superscript : { visible : true },
				separator00 : { visible : true },
				justifyLeft   : { visible : true },
				justifyCenter : { visible : true },
				justifyRight  : { visible : true },
				justifyFull   : { visible : true },
				separator06 : { separator : false },
				insertImage : { visible : false },
				h1mozilla : { visible : false },
				h2mozilla : { visible : false },
				h3mozilla : { visible : false },
				h1 : { visible : false },
				h2 : { visible : false },
				h3 : { visible : false },
				separator08 : { visible : false },
				increaseFontSize : { visible : false },
				decreaseFontSize : { visible : false }
			}
		});
	}
	
});
function validar_mail(objeto){
	reg=/(\S+\@\S+(\.\S+)+)|(^[ \t]*$)/;
	if (! reg.exec(objeto.val())){ return false; }
	return true;
}

function FlashTransparente(DivID,ObjectID,WIDTH,HEIGHT,MOVIE){
	document.getElementById(DivID).innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" id="' + ObjectID + '" width="' + WIDTH + '" height="' + HEIGHT +'"><param name="movie" value="' + MOVIE +'"><param name="quality" value="high"><PARAM NAME="wmode" VALUE="transparent"><embed src="' + MOVIE +'" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' + WIDTH + '" height="' + HEIGHT +'"></embed></object>';
}

