// ESTOS SON LOS CALLBACKS DEL PLAYER
/* jQuery(function(){
// $('input.star').rating();
})*/

var fromPlaylist = 1;
var get_file="";

function isFromBuscador() {
	/* Si venim del buscador, cridem a aquesta funció per especificar que SI que hem de mostrar els relacionats. Ho cridem des de la secció PLAYER a la HOME */
	fromPlaylist = 0;
}

function rate(){
		$("input.star").rating();
}

function desactiv_estrellas(){
	$("#estrellas_votos div[class!=cancel]").unbind(); 
	$("div.star_hover a, div.star_live a").css({"background-position":"0px 0px","cursor":"auto"});
}

function fromFlash(video){
	var file=video.substring(14,video.length);
	var idwimob=jQuery("#WimobId").html();
	jQuery("#CurrentVideo").html("wmbp://t|20|"+idwimob+"|http%3A//"+file+"|NewWimob||");
	var url = video.split("/");
	var id = url[url.length - 1].split(".");
	var folder = url[url.length - 2];
	var idperfil = '';
	if (folder == 'FLVHigh') idperfil = 1;
	else if (folder == 'FLVHD') idperfil = 5;

	jQuery.post("/Detalles.GetDetalles",{idvideo:id[0],idperfil:idperfil},function(detalles){
		var res = eval("(" + detalles + ")");             
		document.title="Emprendedores TV - " + res.nombre;
		$("#detalle_canal").removeClass().addClass("texto_" + res.idcanal);

		if (res.programa == '') {
			$("#detalle_canal").html(res.canal);
		} else {
			$("#detalle_canal").html(res.canal + " /<span style='color:#555555;'> " + res.programa+'</span>');
		}
		$("#detalle_nombre").html(res.nombre);
		$("#detalle_titular").html(res.titular);
		$("#detalle_autor").html(res.autor);
		$("#detalle_desc").html(res.resumen);
		$("#detalle_idvideo").html(res.idvideo);
		$("#detalle_img").attr("src",res.imagen);
		$("#info_visto").html(res.visitas);
		$("#info_fecha").html(res.fecha);
		$("#link").val(res.permalink);
                //cambiarRuta(res.permalink);
		diligencia_embed(res.idvideo,res.idioma);
		videos_relacionados( res.idvideo );
		// $("#estrellas_votos div, #estrellas_votos a").unbind();
		$("#infovoto").remove();
		$("#estrellas_votos").empty().html(res.votos);
		var txtvaloracio = res.txtvaloracio;
		jQuery.rating.groups = {};
		$("#estrellas_votos input").rating({
		  callback:function(value,link){
		    if(value != ''){ /* si se vota */
		        desactiv_estrellas();
			$.post("/Detalles.gravavotos",{idvideo:id[0],nota:value,action:'gravar'}, function(response){
			  var res = eval("(" + response + ")");
			  /* -- Grabar votacion en el cookie -- */
			  var cook = readCookie('emprendv2');
			  if(cook == null){var cook = ''} else {cook = cook + "|";}
			  cooktxt = cook + id[0] + "," + value;
			  createCookie('emprendv2',cooktxt,3650);
			  $("#infovoto").remove();
			  $("#estrellas_votos").after("<div id='infovoto' style='clear:both;padding:4px 11px;font-size:10px;'>" + res.resp + "<span>" + value +"</span></div>");
			  fromFlash(video);
		    })
		    }
		    else{
			/* -- Se puede cancelar si ya se ha votado -- */
			var cook = readCookie('emprendv2');
			if(cook != null){
				var newcook='';
				var tbcook = cook.split("|");
				var yavotado ='n';
				for(i=0; i < tbcook.length; i++){
			  		var idvid = tbcook[i].split(",")[0];
			  		var nota = tbcook[i].split(",")[1];
			  		if(idvid == id[0]){
					  var yavotado ='s';
			    		}
					else{
					  if(newcook == ''){var newcook = newcook + tbcook[i];} else{var newcook = newcook + "|" + tbcook[i];}
					}
				}
			eraseCookie('emprendv2');
			createCookie('emprendv2',newcook,3650);				
			}
			if(yavotado == 's'){
				$.post("/Detalles.gravavotos",{idvideo:id[0],nota:nota,action:'cancel'}, function(response){
				  $("#infovoto").remove();
				  fromFlash(video); 
				})
			}
		    }
		  }
		});
		/* --- Ver si ya se ha votado para este video --- */
		var cook = readCookie('emprendv2');
		if(cook != null){
			var tbcook = cook.split("|");
			for(i=0; i < tbcook.length; i++){
			  var idvid = tbcook[i].split(",")[0];
			  var nota = tbcook[i].split(",")[1];
			  if(idvid == id[0]){
			    $("#infovoto").remove();
			    $("#estrellas_votos").after("<div id='infovoto' style='clear:both;padding:4px 11px;font-size:10px;'>" + txtvaloracio + "<span>" + nota + "</span></div>");
			    desactiv_estrellas();break;}
			}
		}
	})

	if (fromPlaylist == 1) {
		jQuery.get("/Stats.save_stats", {idvideo:id[0],auto:'true'}, function(text) {  });
	} else {
		jQuery.get("/Stats.save_stats", {idvideo:id[0],auto:'false'}, function(text) {  });
	}

}

function muestraOcultaDiv(divtext,idVideo){
	var div1 = document.getElementById(divtext);
	var flecha = document.getElementById('flecha'+idVideo);
	var cruz = document.getElementById('cruz'+idVideo);
	var text = document.getElementById('masinfo'+idVideo);
	if(div1.style.display == "none") {
		div1.style.display = "block";
		flecha.style.display = "none";
		cruz.style.display = "inline";
		text.innerHTML="";
	} else {
		div1.style.display = "none";
		flecha.style.display = "inline";
		text.innerHTML="+ info";
		cruz.style.display = "none";
	}
}
function hideAllDetails() {
	var divs = document.getElementById('ajax_section_player').getElementsByTagName('div');
	for (var d = 0; d < divs.length; d++) { 
		if (divs[d].id.substr(0,12) == 'detalleVideo') divs[d].style.display='none';
	}
}

function alertFlash(msg) {
	//alert("ALERTFLASH: " + msg);
}

function callbackPlayer(html){
	var obj=document.getElementById("ajax_section_player");
	obj.innerHTML=html;
}

function call_player(url){
	eBDSection.show(url, callbackPlayer);
}

function play(idvideo, idperfil, host, idioma) {
	var s1 = new SWFObject("http://" + host + "/imgfiles/flash/banesto-player-video.swf","playlist","900","447","7");
	s1.addParam("wmode","transparent");
	s1.addParam("base","http://" + host + "/imgfiles/flash/");
	s1.addParam("allowFullScreen","true");
//	s1.addVariable("fluURL","http://" + host + "/banesto.m3u?idvideo=" + idvideo + "-" + idperfil);
	s1.addVariable("host","http://" + host);
	s1.addVariable("idvideo",idvideo);
	s1.addVariable("idperfil",idperfil);
	s1.addVariable("idioma",idioma);
	s1.write("player");
	jQuery(document).scrollTop(0);
	fromPlaylist = 0;
}

$(function(){

	// DETALLE DEL VIDEO

	$("#embed,#link").click(function(){
		this.select();
	});
  	$("#detalle_mas_info").click(function(){
		if($("#detalle_que_es").html() == 'X') {
			$("#detalle_quees").slideToggle("slow",function(){
				$("#detalle_que_es.detalle_flecha,#detalle_que_es.detalle_cruz").toggleClass("detalle_flecha").toggleClass("detalle_cruz");
				$("#detalle_que_es.detalle_flecha_esade,#detalle_que_es.detalle_cruz_esade").toggleClass("detalle_flecha_esade").toggleClass("detalle_cruz_esade");
				$("#detalle_que_es.detalle_flecha_turismo,#detalle_que_es.detalle_cruz_turismo").toggleClass("detalle_flecha_turismo").toggleClass("detalle_cruz_turismo");
				$("#detalle_que_es.detalle_flecha_telefonica,#detalle_que_es.detalle_cruz_telefonica").toggleClass("detalle_flecha_telefonica").toggleClass("detalle_cruz_telefonica");
				if($("#detalle_que_es.detalle_flecha_esade").length > 0) {
					$("#detalle_que_es").html("¿Qué es ESADE Alumni?");
				} else {
					$("#detalle_que_es").html("¿Qué es Turismo Solidario?");
				}
			});
		}
		$("#detalle_desc").slideToggle("slow",function(){
			$("#detalle_mas_info.detalle_flecha,#detalle_mas_info.detalle_cruz").toggleClass("detalle_flecha").toggleClass("detalle_cruz");
			$("#detalle_mas_info.detalle_flecha_esade,#detalle_mas_info.detalle_cruz_esade").toggleClass("detalle_flecha_esade").toggleClass("detalle_cruz_esade");
			$("#detalle_mas_info.detalle_flecha_turismo,#detalle_mas_info.detalle_cruz_turismo").toggleClass("detalle_flecha_turismo").toggleClass("detalle_cruz_turismo");
			if($("#detalle_mas_info").html() == 'X') {
				$("#detalle_mas_info").html("Más Información");
			} else {
				$("#detalle_mas_info").html("X");
			}
		});
	})
  	$("#detalle_que_es").click(function(){
		if($("#detalle_mas_info").html() == 'X') {
			$("#detalle_desc").slideToggle("slow",function(){
				$("#detalle_mas_info.detalle_flecha,#detalle_mas_info.detalle_cruz").toggleClass("detalle_flecha").toggleClass("detalle_cruz");
				$("#detalle_mas_info.detalle_flecha_esade,#detalle_mas_info.detalle_cruz_esade").toggleClass("detalle_flecha_esade").toggleClass("detalle_cruz_esade");
				$("#detalle_mas_info.detalle_flecha_turismo,#detalle_mas_info.detalle_cruz_turismo").toggleClass("detalle_flecha_turismo").toggleClass("detalle_cruz_turismo");
				$("#detalle_mas_info").html("Más Información");
			});
		}
		$("#detalle_quees").slideToggle("slow",function(){
			$("#detalle_que_es.detalle_flecha,#detalle_que_es.detalle_cruz").toggleClass("detalle_flecha").toggleClass("detalle_cruz");
			$("#detalle_que_es.detalle_flecha_esade,#detalle_que_es.detalle_cruz_esade").toggleClass("detalle_flecha_esade").toggleClass("detalle_cruz_esade");
			$("#detalle_que_es.detalle_flecha_turismo,#detalle_que_es.detalle_cruz_turismo").toggleClass("detalle_flecha_turismo").toggleClass("detalle_cruz_turismo");
			if($("#detalle_que_es").html() == 'X') {
				if($("#detalle_que_es.detalle_flecha_esade").length > 0) {
					$("#detalle_que_es").html("¿Qué es ESADE Alumni?");
				} else {
					$("#detalle_que_es").html("¿Qué es Turismo Solidario?");
				}
			} else {
				$("#detalle_que_es").html("X");
			}
		});
	})

	/********WiMob********/

	var file=jQuery("#CurrentVideo").html();
	var wimob_text=jQuery("#WiMobText").html();
	jQuery(".conxBluetooh").prepend("<div style='float:left;'><img style='font:11px Arial;color:#D48603;font-weight:bold;text-decoration:underline;cursor:pointer;' src='http://www.wimob.com/icons/wimob-1-07.gif' onclick='javascript:var file=document.getElementById(\"CurrentVideo\").innerHTML;javascript:sniffWimob(file);'/></div><div style='padding:5px;float:left;'><span style='font:11px Arial;color:#D48603;font-weight:bold;text-decoration:underline;cursor:pointer;' onclick='javascript:var file=document.getElementById(\"CurrentVideo\").innerHTML;javascript:sniffWimob(file);'>"+wimob_text+"</span></div>");
	var idwimob=jQuery("#WimobId").html();
	jQuery("#wmb"+idwimob).remove();

})

function diligencia_embed ( idvideo , idioma ){
	$("#embed").val('<embed height="447" width="900" flashvars="host=http://' + document.domain + '&amp;idvideo=' + idvideo + '&amp;idperfil=1&amp;idioma='+idioma+'" allowfullscreen="true" base="http://' + document.domain + '/imgfiles/flash/" wmode="transparent" quality="high" name="playlist" id="playlist" style="" src="http://' + document.domain + '/imgfiles/flash/banesto-player-video.swf" type="application/x-shockwave-flash"/>');
}

function videos_relacionados( idvideo ){
	if (fromPlaylist == 0) {
		jQuery.post("/videosRelacionados.getUrl",{idVideo: idvideo},function(json){
			var element = eval("(" + json + ")");
			var url = element.url;
			if (url != '') {
				eBDSection.show(url, reemplazar_videos_relacionados );
			} else {
				$("#relacionados").css("display", "none");
			}
		});
	}
}

function reemplazar_videos_relacionados( html ){
	$("#relacionados").html( html ).css("display", "block");
}

/* galeria canal evento --> programas videos */

function changeimg(idlk){
	var sentido = idlk.split("_")[0];
	var idprog = idlk.split("_")[1];
	var numimg = (jQuery("#celda_" + idprog + " input[type=hidden]").length) / 6;

	if(sentido == 'prec') var increm = -1; else var increm = 1;
	var idimgactual = jQuery("#celda_" + idprog + " img").attr("id");
	var counterimg = idimgactual.split("_")[2];
	/* definir imagen que pintar */
	var nextcounter = parseInt(counterimg) + increm;
	if(nextcounter == 0) var newcounter = numimg;
	else if(nextcounter > numimg) var newcounter = 1;
	else var newcounter = nextcounter;
	/* pintar los datos nuevos */
	jQuery("#contimgprg_" + idprog + " div").fadeOut("fast", function(){
		jQuery("#contimgprg_" + idprog).empty();
		var newtxt=jQuery("#txtprg_" + idprog + "_" + newcounter).val();
		var newimg=jQuery("#imgprg_" + idprog + "_" + newcounter).val();
		var newhd = jQuery("#hd_" + idprog + "_" + newcounter).val();
		
		jQuery("#contimgprg_" + idprog).html("<div class='cont_img'>" + newhd + "<img id='img_" + idprog + "_" + newcounter + "' src='" + newimg + "' alt='" + newtxt + "' title='" + newtxt + "'></div><div class='leyendaimg' id='txt_" + idprog + "_" + newcounter + "'>" + newtxt + "</div>")
		jQuery("#counter_" + idprog).text(newcounter + " / " + numimg);
		jQuery("#contimgprg_" + idprog + " div").fadeIn();

		jQuery(".cont_img").click(function(){
			var idvideo = jQuery("#idvideo_" + idprog + "_" + newcounter).val();
			var idperfil = jQuery("#idperfil_" + idprog + "_" + newcounter).val();
			var host = jQuery("#host_" + idprog + "_" + newcounter).val();
			hide_elempest();
			play(idvideo, idperfil, host);
		});
	});
}

/* --- Comportamiento del menu --- */
jQuery(function(){  
	var points = new Array();
	var elem1 = jQuery("#showcanales").offset();
	var elem2 = jQuery("#capa_menu").offset();
	points["x1"]=elem1.left;
	points["y1"]=elem1.top;
	points["x2"]=elem1.left + jQuery("#showcanales").outerWidth();
	points["y2"]=elem2.top;
	points["x3"] = elem2.left + jQuery("#capa_menu").outerWidth();
	points["y3"]=points["y2"] + jQuery("#capa_menu").outerHeight();
	//console.dir(points);
	jQuery("#capa_menu").css({"display":"none","visibility":"visible"});
	jQuery("#showcanales").hover(function(e){
		jQuery("#capa_menu").show();
		jQuery("#showcanales").removeClass("pleg").addClass("despleg");
	  }, function(e){
		if(e.pageX <= points["x1"] || e.pageY <= points["y1"] || (e.pageX > points["x2"] && e.pageY < points["y2"])){
			jQuery("#capa_menu").hide(); 
			jQuery("#showcanales").removeClass("despleg").addClass("pleg");
	  }
	})

	jQuery("#capa_menu").hover(function(e){
		jQuery("#capa_menu").show();
	  }, function(e){
		if(e.pageX <= points["x1"] || e.pageX >= points["x3"] || e.pageY>= points["y3"] || (e.pageX >= points["x2"] && e.pageY<= points["y2"])){
			jQuery("#capa_menu").hide();
			jQuery("#showcanales").removeClass("despleg").addClass("pleg");
		}
	  }
	)

})

/* -- test -- */
jQuery(function(){
	jQuery("#logo_telefonica").click(function(){
		jQuery("#showcanales").removeClass("pleg").addClass("despleg");
		alert(jQuery("#showcanales").attr("class"));
		return false;
	})

	/* --- Buscador amigable --- */
	jQuery("#globalsearch").submit(function(){
		var keyword = jQuery("#palabraClave").val()
		if(keyword.length == 0) keyword = 'all';
		keyword = keyword.toLowerCase();
		keyword = keyword.replace(/\s+/g,"_");
		keyword = keyword.replace(/\/\/+/g,"");
		keyword = keyword.replace(/\\+/g,"");
		keyword = keyword.replace(/[àáâãäå]/g,"a");
		keyword = keyword.replace(/[èéêë]/g,"e");
		keyword = keyword.replace(/[ìíîï]/g,"i");
		keyword = keyword.replace(/[òóôõö]/g,"o");
		keyword = keyword.replace(/[ùúûü]/g,"u");
		keyword = keyword.replace(/[ýÿ]/g,"u");
		keyword = keyword.replace(/ñ+/g,"n");
		keyword = keyword.replace(/ç+/g,"c");
		keyword = keyword.replace(/&+/g,"");
		keyword = keyword.replace(/'+/g,"");
		keyword = keyword.replace(/"+/g,"");
		keyword = keyword.replace(/\.+/g,"_");
		jQuery(this).attr('action', jQuery(this).attr('action') + keyword);
		return true;
	})

})


/*----cosas pára telefonica------*/




function chane(idlk){
var idprog = idlk.split("_")[1];
var counter=jQuery("#cspan_"+idprog).attr('title');
var total=counter.split("/")[1];
var count=counter.split("/")[0];
count=parseInt(count)-3;
var aux=parseInt(count)-3;
if(count<total){
//jQuery("#imglinkr_"+idprog).attr('style','display:block;');
jQuery("#imglinkr_"+idprog).show();
//jQuery("#imgsolar_"+idprog).attr('style','display:none;');
jQuery("#imgsolar_"+idprog).hide();

}
if(aux==0){
//jQuery("#imglinkl_"+idprog).attr('style','display:none;');
jQuery("#imglinkl_"+idprog).hide();
//jQuery("#imgsolal_"+idprog).attr('style','display:block;');
jQuery("#imgsolal_"+idprog).show();
//jQuery("#imgsolal_"+idprog+" span").attr('style','display:block;margin-top:80px;');
jQuery("#imgsolal_"+idprog+" span").show();
}

var newv=count+"/"+total;
jQuery("#cspan_"+idprog).attr('title',newv);
var value=jQuery("#nexttel_"+idprog).val();
var clss=value;
var after=parseInt(clss)-100;
jQuery("."+clss).hide();//attr('style','display:none;');
jQuery("."+after).fadeIn("fast");
jQuery("#nexttel_"+idprog).attr('value',after);
jQuery("#prevtel_"+idprog).attr('value',clss);
jQuery("#cspan_" + idprog).text(newv);


}
function changeimgtel(idlk){
	var idprog = idlk.split("_")[1];
	var counter=jQuery("#cspan_"+idprog).attr('title');
	var total=counter.split("/")[1];
	var count=counter.split("/")[0];
	count=parseInt(count)+3;
	var aux=parseInt(count)-3;
	if(count>=total){
		//jQuery("#imglinkr_"+idprog).attr('style','display:none;');
		jQuery("#imglinkr_"+idprog).hide();
		//jQuery("#imgsolar_"+idprog).attr('style','display:block;');
		jQuery("#imgsolar_"+idprog).show();
	}
	if(aux!=0){
		//jQuery("#imglinkl_"+idprog).attr('style','display:block;');
		jQuery("#imglinkl_"+idprog).show();
		//jQuery("#imgsolal_"+idprog).attr('style','display:none;');
		jQuery("#imgsolal_"+idprog).hide();
	}
	var newv=count+"/"+total;
	jQuery("#cspan_"+idprog).attr('title',newv);

	var value=jQuery("#nexttel_"+idprog).val();
	var clss=value;
	var after=parseInt(clss)+100;
	jQuery("."+clss).hide();//attr('style','display:none;');
	jQuery("."+after).fadeIn("fast");
	jQuery("#nexttel_"+idprog).attr('value',after);
	jQuery("#prevtel_"+idprog).attr('value',clss);

	if(count>total){
		newv=total+"/"+total;
	}
	jQuery("#cspan_" + idprog).text(newv);

}



/*----------------------------------------------*/




/* --- Pintar contenidos estaticos en una capa --- */
function verestatic(idcont, ididioma){
	jQuery.post("/estaticos.contents",{idcontenido:idcont, ididioma:ididioma}, function(json){
		var res = eval("(" + json + ")");

		jQuery("body").prepend("<div id='pop_estatic'><div class='close_pop'></div><div class='barita'>" + res.titulo + "</div><div class='cont_estatic'>" + res.texto + "</div></div>");
		jQuery("#capa").height(jQuery(document).height());
		jQuery("#capa").width(jQuery(document).width());
		jQuery("#capa").show();
		jQuery("#capa").click(function(){jQuery("#capa").hide();jQuery("#pop_estatic").remove();});

		var popw = jQuery('#pop_estatic').outerWidth();
		var poph = jQuery('#pop_estatic').outerHeight();
		var docw = jQuery(window).width();
		var doch = jQuery(window).height();
		var posx = (docw - popw)/2;
		var posy = (doch - poph)/3;

		if (jQuery.browser.msie==true && parseInt(jQuery.browser.version)<7) {	var scroll=jQuery(window).scrollTop();posy=posy+scroll;}

		jQuery("#pop_estatic").css({"left":posx, "top":posy}).show();
		jQuery(".cont_estatic").css({"height":"400px"});
		jQuery("#pop_estatic div[class=close_pop]").click(function(){jQuery("#pop_estatic").remove(); jQuery("#capa").hide();})
	})
}
/* --- esconder bloque de datos de las pestanyas en canales --- */
function hide_elempest(){
	jQuery("#box_videospest").hide();
	jQuery("div[class=p_on]").attr("class","p_off");
}


/**       Formulario contactar   **/

function contactar(){
	var url=jQuery("#contact_form_reload").val();
	jQuery.post("/_ajax/Section.show"+url,{},function(data){
		var res = data.getElementsByTagName("body")[0].firstChild.nodeValue;		

		jQuery("body").prepend("<div id='pop_estatic'><div class='close_pop'></div><div class='barita'>Formulario de contacto</div><div class='cont_estatic'><p class='login_titulo' style='padding:5px 15px;'>Para ponerse en contacto con nosotros rellene el siguiente formulario con sus datos. Tenga en cuenta que le enviaremos la respuesta al email que nos indique:<br></p>"+res+"</div></div>");
		jQuery("#capa").height(jQuery(document).height());
		jQuery("#capa").width(jQuery(document).width());
		jQuery("#capa").show();
		jQuery("#capa").click(function(){jQuery("#capa").hide();jQuery("#pop_estatic").remove();});

		var popw = jQuery('#pop_estatic').outerWidth();
		var poph = jQuery('#pop_estatic').outerHeight();
		var docw = jQuery(window).width();
		var doch = jQuery(window).height();
		var posx = (docw - popw)/2;
		var posy = ((doch - poph)/3)-50;

		if (jQuery.browser.msie==true && parseInt(jQuery.browser.version)<7) {	var scroll=jQuery(window).scrollTop();posy=posy+scroll;}

		jQuery("#pop_estatic").css({"left":posx+"px", "top":posy}).show();
		jQuery("#pop_estatic div.cont_estatic").css({"height":"auto"});
		jQuery("#pop_estatic div[class=close_pop]").click(function(){jQuery("#pop_estatic").remove();jQuery("#capa").hide();})
		contact_validate();
	})
}

function contact_validate()
{
	jQuery.validator.addMethod('validCaptcha', function(value, element){
		var illegalChars = /\W/; 
		var ret=false;

		if (illegalChars.test(value))
		{
			ret=false;
		}
		else{
			var capcha=jQuery('#capcha').val();
			jQuery.ajax({
				type: 'POST',
				url: '/v2/contact.captcha',
				async: false,
				data: 'captcha='+capcha,
				success: function(json){
					var resp=eval('('+json+')');
					if (resp.res == 'KO'){  ret=false; }
					else { ret=true; }
				}
			});
		}
		return ret;
	}, '<br><span style="color:red">El código es incorrecto</span>');

	jQuery("#contact_form").validate(
	{
		rules: {
			nombre: 'required',
			email:  {
				required:true,
				email : true
			},
			titulo: 'required',
			contact_detalle:'required',
			capcha: {
				required:true,
				validCaptcha : true				
			}
		},
		messages: {
			nombre: '<br><span style="color:red">No puede estar vacío</span>',
			titulo: '<br><span style="color:red">No puede estar vacío</span>',
			contact_detalle: '<br><span style="color:red">No puede estar vacío</span>',
			email:  
			{	
				required : '<br><span style="color:red">No puede estar vacío</span>',
				email : '<br><span style="color:red">Introduce un email válido</span>'
			},
			capcha:
			{
				required : '<br><span style="color:red">No puede estar vacío</span>',
				validCaptcha : '<br><span style="color:red">El código es incorrecto</span>'
			}
		},
		submitHandler: function(form) {
			// do other stuff for a valid form
			save_contact();
		}
	})
}
function save_contact(){
	var capcha=jQuery('#capcha').val();
	var nombre=jQuery("#nombre").val();
	var titulo=jQuery("#titulo").val();
	var email=jQuery("#email").val();
	var contact_detalle=jQuery("#contact_detalle").val();

	jQuery.ajax({
		type: 'POST',
		url: '/v2/contact.save',
		async: false,
		data: 'nombre='+nombre+'&titulo='+titulo+'&contact_detalle='+contact_detalle+'&email='+email,
		success: function(json){
			var resp=eval('('+json+')');
			jQuery("#pop_estatic div.cont_estatic").html("<p class='login_titulo' style='text-align:center;'>"+resp.res+"</p>");
		}
	})
}
