
$(document).ready(function() { 
    // bind form using ajaxForm 
    $("form[class!=normal]").livequery(  
	    function (){
	    	
	    $(this).submit(function() 
	    { 	
    		try{ tinyMCE.triggerSave(); }catch(err){}
    		try{ tinyMCE.activeEditor.save(); }catch(err){}	
    		try{ tinyMCE.triggerSave(); }catch(err){}
    		try{ tinyMCE.activeEditor.save(); }catch(err){}	    		

	    	$(this).ajaxSubmit({ 
		        // target identifies the element(s) to update with the server response 
		        //target: '#htmlExampleTarget', 
		        // success identifies the function to invoke when the server response 
		        // has been received; here we apply a fade-in effect to the new content 
		    	//beforeSubmit:  saveEditors,
		        success: checkResponse
		    });
	    	return false;
	    });
    });
 
    $("textarea[class*=editor]").livequery(  
    		function (){ 
    			tinyMCE.execCommand('mceAddControl', false,  $(this).attr('id') ); 
    		}
    );
    
});

    

   
    
    
    
    
    
/*
$('#myForm2').submit(function() { 
    // inside event callbacks 'this' is the DOM element so we first 
    // wrap it in a jQuery object and then invoke ajaxSubmit 
    $(this).ajaxSubmit(options); 

    // !!! Important !!! 
    // always return false to prevent standard browser submit and page navigation 
    return false; 
});
*/


function checkResponse(responseText, statusText)  { 

/*
	newUrl--x--'newUrl' -x-x-
	nextPageMensaje--x--'mensaje'-x-x-
	alert--x--'mensaje' -x-x-
	newValue--x--nameCampo--x--'valor' -x-x-
	newContetn--x--jquerySelector--x--'valor' -x-x-
*/	

	String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };

	var comandos=responseText.split('-x-x-'); 
	for (var i in comandos)
	{
		//alert(comandos[i]); 
		var comando = comandos[i].split('--x--');
		//alert(comando[0]);

		if(comando[0].trim()=="alert"){ alert(comando[1].trim()); }
		else if(comando[0].trim()=="newUrl"){
			if(comando.length==3)
			{ 
				if(comando[2].indexOf('?')){
					var temp = '&mensaje='+comando[2].trim();
				}else{
					var temp = '?mensaje='+comando[2].trim();
				}
			}
			window.location = comando[1].trim() + temp; 
		}
		else if(comando[0].trim()=="newValue"){ $(comando[1].trim()).attr('value',comando[2].trim()); }
		else if(comando[0].trim()=="newContent"){ $(comando[1].trim()).html( comando[2].trim() ); }
		else if(comando[0].trim()=="addContent"){ $(comando[1].trim()).after( comando[2].trim() ); }
		else if(comando[0].trim()=="reemplaza"){ reemplaza(comando[1].trim(),comando[2].trim() ); }
		else if(comando[0].trim()=="function")
		{ 
			//alert(comando[1]); 
			comando.shift();
			
			cadena=comando.shift().trim()+'(\'';
				 cadena+=comando.join('\',\'');
			cadena+='\')';
			//alert(cadena);
			eval(cadena);
		}
	}

}


function sumitform(formname){
	
	if(window.tinyMCE !== undefined){
		tinyMCE.triggerSave();	
	}
	
	$("[name="+formname+"]").submit();
	//if(editorHTMLactivo==1){a='aaa';}
	//tinyMCE.triggerSave();
/*
	$("[name="+formname+"]").ajaxSubmit({ 
        // target identifies the element(s) to update with the server response 
        //target: '#htmlExampleTarget', 
        // success identifies the function to invoke when the server response 
        // has been received; here we apply a fade-in effect to the new content 
    	//beforeSubmit:  saveEditors,
        success: checkResponse
    });
*/
	//return false;
}




