jQuery(function(){
	jQuery("#send_comment").live("click",function(){
                  var error=0;
		var content=jQuery("#comment_content").val();
		var idvideo=jQuery("#id_video").val();
		if (content=='')
		{	
			jQuery("#content_empty").fadeIn("slow").fadeTo(4000, 1).fadeOut("slow");
                            error++;
			/*return false;*/
		}

                  if(jQuery("#captcha").val()==''){
                           jQuery("#captcha_empty").fadeIn("slow").fadeTo(4000, 1).fadeOut("slow");
                           error++;
                           /*return false;*/
                  }

                  var code = jQuery("#captcha").val().toUpperCase();

                  jQuery.ajax({
                     type: "POST",
                     async: false,
                     url: "/front_xal/Comments.Captcha",
                     cache: false,
                     data: {code:code},
                     success: function(response){
                       response=eval("("+response+")");
                       if(response.valid == "true"){
                       }else{
                         jQuery("#captcha_error").fadeIn("slow").fadeTo(4000, 1).fadeOut("slow");
                         jQuery("#captcha").focus();
                         error++;
                       }
                     }
                  });
         if(error>0){
          return false;
         }else{
		jQuery.post(
			'/front_xal/Comments.add',
			{idvideo:idvideo,content:content},
			function(json){
				resp=eval("("+json+")");
				if(resp.saved=='OK')
				{
					jQuery("#tabs-content").css({"opacity":"0.6"});
					//var url=jQuery("#reload_comments").val();
					var url = jQuery("#pestcomment a").attr("href");
					var idpatter = jQuery("div[id[^=content_section]]:eq(0)","#content").attr("id").split("_")[2];
					jQuery.post(
					'/_ajax/Section.show'+url,
					{},
					function(xml){
						var html=xml.getElementsByTagName("body")[0].firstChild.nodeValue;
						jQuery("#content_section_" + idpatter).html(html);
						jQuery("#tabs-content").css({"opacity":"1"});
						jQuery("#comment_content").attr('value','');
						jQuery("#captcha").attr('value','');
						changeCaptcha('#captcha_container');
					})

				}
				
			})
          }
    })
})

function changeCaptcha(container){
   jQuery(container).html('<iframe class="frameCaptcha" src="/front_xal/captcha" scrolling="no"></iframe>');
}

