// ASB, 2008/12/01
function ajaxIndicator( status, indicator_id ) {
if( undefined == indicator_id ) indicator_id = 'indicator';
jQuery('#'+indicator_id).css( { visibility: ( status == 0 ? "hidden" : "visible" ) } );
}
function ajaxRequest( element_id, url, data, onload_func ) {
ajaxIndicator(1);
jQuery('#'+element_id).load( url, data, onload_func );
ajaxIndicator(0);
}
function ajaxJs( url, data, onload_func ) {
ajaxIndicator(1);
jQuery.post( url, data, function(obj) {
eval(obj);
if( typeof(onload_func) == 'function' ) onload_func();
ajaxIndicator(0);
});
}
function ajaxLink( element_id, anchor, onload_func ) {
ajaxRequest( element_id, anchor.href, {}, onload_func );
return false;
}
function ajaxLinkJs( anchor, onload_func ) {
ajaxJs( anchor.href, onload_func );
return false;
}
function ajaxForm( element_id, form, onload_func ) {
ajaxRequestSubForm( element_id, form.action, form, '', onload_func );
return false;
}
function ajaxRequestSubForm( element_id, action, form, name_pefix, onload_func ) {
data = {};
var max = form.length;
for( var i = 0; i < max; i++ ) {
obj = form.elements[i];
if( obj.name.indexOf(name_pefix) == 0 ) {
if( 'checkbox' == obj.type ) {
data[obj.name] = obj.checked;
} else if( 'radio' == obj.type ) {
if(obj.checked) data[obj.name] = obj.value;
} else if( 'select-multiple' == obj.type ) {
re = /\[\]$/;
base_name = obj.name.replace(re, '');
opt_list = obj.options;
k = 0;
for( j = 0; j < opt_list.length; j++ ) {
opt_name = base_name + '[' + k + ']';
if( true == opt_list[j].selected ) {
data[opt_name] = opt_list[j].value;
k++;
}
}
} else {
data[obj.name] = obj.value;
}
}
}
ajaxRequest( element_id, action, data, onload_func );
return false;
}
function ajaxFormJs( form, onload_func ) {
ajaxJs( form.action, form.elements, onload_func );
return false;
}
function ajaxFormUpload( element_id, form, onload_func )
{
res = AIM.submit( form, {
'onStart' : function() {
ajaxIndicator(1);
return true;
},
'onComplete' : function(response) {
ajaxIndicator(0);
jQuery('#'+element_id).empty();
jQuery('#'+element_id).html(response);
var scripts = jQuery( [] );
scripts = scripts.add( jQuery( "script", response ) );
scripts.each( eval );
if( typeof(onload_func) == 'function' ) {
onload_func();
}
}
});
return res;
}
function ajaxImage( element_id, url, attr_list ) {
if( undefined == attr_list ) attr_list = '';
html = '<img src="' + url + '"' + attr_list + '/>';
jQuery('#'+element_id).html( html );
ajaxIndicator(0);
}
function ajaxHere( url, data, onload_func ) {
var element_id = 'here' + Math.floor( Math.random() * 99999 ) + '' + Math.floor( Math.random() * 99999 );
document.write('<span id="' + element_id + '"></span>');
ajaxRequest( element_id, url, data, onload_func );
}

