
$.fn.load_tol = function (url,callback) {
		var self = this;
		// Request the remote document
		jQuery.ajax({
			url: url,
			type: "GET",
			dataType: "html",
			data: {},
			complete: function( res, status ) {
				// If successful, inject the HTML into all the matched elements
				if ( status === "success" || status === "notmodified" ) {
					// See if a selector was specified
					self.html( 
						res.responseText );
				}

				if ( callback ) {
					self.each( callback, [res.responseText, status, res] );
				}
			}
		});

}

function includeHelp(target, to){
    var t = '#'+target;
    $(t).load('/include/help.do?to='+to+'&id='+target);
    $(t).hide();
    $(t).show('slow');
}

function hideHelp(target) {
	var t = '#'+target;
	$(t).hide('slow');
}

function includeOntologia(target, cc, section, docid){
    var t = '#'+target;
    $(t).load('/document/jquery/ontologia.do?cc='+cc+'&mode=0&section='+section+'&docid='+docid);
    $(t).fadeIn('slow');
} 

function attachResult(target, docid) {
    var t = '#'+target;
    $(t).load('/attach/jquery/attachDocument.do?docid='+docid);
    $(t).hide();
    $(t).show('slow');
}
/*
function attachDocument(target, catid, ind, sec) {
    var t = '#'+target;
    $(t).load('/attach/jquery/attachDocument.do?catid=' + catid + '&ind=' + ind + '&sec=' + sec);
    $(t).hide();
    $(t).show('slow');
}
*/
function attachDocument(target, catid) {
    var t = '#'+target;
    $(t).load('/attach/jquery/attachDocument.do?ind='+catid);
    $(t).hide();
    $(t).show('slow');
}

function attachSearch(target, op, sp, as, visited, media) {
    var t = '#'+target;
    $(t).load_tol('/attach/jquery/attachDocument.do?search=0&op='+op+'&sp='+escape(sp)+'&as='+as+'&visited='+visited+'&media='+media);
    $(t).hide();
    $(t).show('slow');
}




function tolSerializeForm($form) {
	var serializado = $form.serializeArray();
	var serializadoIe = "";
	for (var i=0;i<serializado.length;i++){
    	var e = serializado[i];
    	var v = e.value;
    	var vs = v.replace(/\s+/g,encodeURIComponent(" "));
		serializadoIe += (e.name+"="+vs) +"&";
    }	
	return serializadoIe;
}

if (typeof(Ajax)=='undefined') {
	var Ajax = {
		Updater: function(sel,url) {
			$('#'+sel).load(url);
		}
	};
}


