function htmleditor(){
    
    $('.tipo_htmleditor2').each(function(){
          var name = $(this).attr('id');
          eval("oEdit_" + name + " = new InnovaEditor(\"oEdit_\" + name);");
          eval("oEdit_" + name).width="200px";
          eval("oEdit_" + name).height="100px";
          eval("oEdit_" + name).css="/fotos/htmlarea.css";
          eval("oEdit_" + name).useBR=false;
          eval("oEdit_" + name).useDIV=false;
          eval("oEdit_" + name).mode = "HTML";
          eval("oEdit_" + name).arrCustomButtons=[
          ["SpellChecker","openSpellChecker('" + name + "')","Corrector Ortogr&aacute;fico","btnSpellCheck.gif"]
          ];
          eval("oEdit_" + name).features=[
            "Bold",
            "Italic",
            "Underline",
            "Strikethrough",
            "|",
            "JustifyLeft",
            "JustifyCenter",
            "JustifyRight",
            "JustifyFull",
            "|",
            "Cut",
            "Copy",
            "Paste",
            "PasteWord",
            "PasteText",
            "SpellChecker",
            "|",
            "Undo",
            "Redo",
            "|",
            "ForeColor",
            "BackColor",
            "|",
            "Hyperlink",
            "InternalLink",
            "|",
            "Numbering",
            "Bullets",
            "|",
            "Indent",
            "Outdent"
            ];
          eval("oEdit_" + name).REPLACE(name);
    }); 
}

function update_facebox(data){
  if($('#facebox').is(':visible')){
      $('#facebox .content').html(data);
  }
  else{
    $.facebox(data);
  }
}

function popup_functions()
{
	  $('a[rel=facebox]').live('click',function(){
		  update_facebox('<div class="loading_ajax"><img src="/img/ajax-loader.gif" alt="Loading..."/></div>');
		  $.get($(this).attr('href'), function(data) {            
              if(data!=''){
			   	update_facebox(data);
			  }
              loadForm();
          });
          return false;
      });
	  loadForm();    
}

function loadForm(){

	$(".popup_form").submit(function(){         		 
	 var result=$(this).serialize();
	 var action=$(this).attr('action');
     var method=$(this).attr('method');
	 $.ajax({
               type:method,
               url:action,
               data:result,
               beforeSend:function(){                                
                    update_facebox('<div class="loading_ajax"><img src="/img/ajax-loader.gif" alt="Loading..."/></div>');
               }, 
               success:function(res){
                    if(res!=''){
				   	update_facebox(res);
				  }
				  loadForm(); 
               }
       });
       return false;
    });
}
