function ajaxTakeAnAction(source, result, method, loadingBar, checkScripts, finalScripts) {
	source = $(source);
	result = $(result);
		
	if (checkScripts != null) {
		var x = eval(checkScripts);
		if (!x) {
			return false;
		}
	}
	if (loadingBar != null) {
		loadingBar = $(loadingBar);
		loadingBar.style.display = 'inline';
	}
	
	var uri = "index.php";
	
	new Ajax(uri, {
		method: method,
		update: result,
		evalScripts: true,
		data: source,
		onComplete: function() {
			if (finalScripts != null) {
				var y = eval(finalScripts);
			}
			if (loadingBar != null) {
				loadingBar.style.display = 'none';
			}
		}
	}).request();
}

function ajaxMakeGetRequest(path, result, loadingBar) {
	result=$(result);
	
	if (loadingBar!=null) {
		loadingBar=$(loadingBar);
		loadingBar.style.display='inline';
	}
	
	var uri='index.php?'+path;
	
	new Ajax(uri, {
		method: 'get',
		update: result,
		evalScripts: true,
		onComplete: function() {
			if (loadingBar!=null) {
				loadingBar.style.display='none';
			}
		}
	}).request();
}

function do_ajax_request(progress, res, params) {
	var res=$(res);
	res.empty();
	if (progress!=null) {
		var progress=$(progress);
		progress.addClass('ajax-loading');
		//progress.style.display = 'block';
	}
	var uri='index.php' + params;
	new Ajax(uri, {
		method: 'get',
		update: res,
		evalScripts: true,
		onComplete: function() {
			if (progress != null) {
				//progress.style.display = 'none';
				progress.removeClass('ajax-loading');
			}
		}
	}).request();
}

function do_ajax_request_wo_flashing_screen(params, res) {
	var res=$(res);

	var uri='index.php' + params;
	new Ajax(uri, {
		method: 'get',
		update: res,
		evalScripts: true
	}).request();
}

function ajax_submit(src, res, method, act, progress, progress_h, validator) {
	src.addEvent(act, function(e) {
		e=new Event(e).stop();
		if (validator!=null) {
			var x=eval(validator);
			if (!x) {
				return false;
			}
		}
		res.style.display='none';
		res.empty().addClass('ajax-loading');
		var url="index.php";
		if (progress!=null) {
			if (progress_h!=null) {
				progress.style.height=progress_h;
			} else {
				progress.style.height='30px';
			}
			progress.addClass('ajax-loading');
		}
		new Ajax(url, {
			method: method,
			update: res,
			evalScripts: true,
			data: src,
			onComplete: function() {
				res.removeClass('ajax-loading');
				res.style.display='block';
				if (progress!=null) {
					progress.style.height='0px';
					progress.removeClass('ajax-loading');
				}
			}
		}).request();
	});
}

function ajax_submit_wo_flashing_screen(src, res, method, act, validator) {
	src.addEvent(act, function(e) {
		e=new Event(e).stop();
		if (validator!=null) {
			var x=eval(validator);
			if (!x) {
				return false;
			}
		}
		var uri="index.php";
		new Ajax(uri, {
			method: method,
			update: res,
			evalScripts: true,
			data: src
		}).request();
	});
}

function ajax_click(data, res, act, progress, progress_h, validator) {
	res.style.display='none';
	res.empty().addClass('ajax-loading');
	var url="index.php";
	if (progress!=null) {
		if (progress_h!=null) {
			progress.style.height=progress_h;
		} else {
			progress.style.height='30px';
		}
		progress.addClass('ajax-loading');
	}
	new Ajax(url, {
		method: 'post',
		update: res,
		evalScripts: true,
		data: data,
		onComplete: function() {
			res.removeClass('ajax-loading');
			res.style.display='block';
			if (progress!=null) {
				progress.style.height='0px';
				progress.removeClass('ajax-loading');
			}
		}
	}).request();
}

function ajax_click_wo_flashing_screen(data, res, method, act, validator) {
	var uri="index.php";

	new Ajax(uri, {
		method: method,
		update: res,
		evalScripts: true,
		data: data
	}).request();
}

function ajax_reload(src, res, seconds, progress) {
	var periodical, dummy;
	var res=$(res);
	var progress=$(progress);

	var ajax=new Ajax(src, {
		method: 'get',
		update: res,
		evalScripts: true,
		onComplete: function() {
			res.removeClass('ajax-loading');
			res.style.display='block';
			if (progress!=null) {
				progress.style.height='0px';
				progress.removeClass('ajax-loading');
			}
		}
	});
	var refresh=(function() {
		dummy=$time() + $random(3, 333);
	//	res.style.display='none';
	//	res.empty().addClass('ajax-loading');
		if (progress!=null) {
			progress.style.height='30px';
			progress.addClass('ajax-loading');
		}
		ajax.request(dummy); 
	});

	$clear(periodical);
	periodical=refresh.periodical(seconds*1000);
	ajax.request($time());
}



function msg_inbox() {
	ajax_click($('frmBoxIn'), $('box_in_res'), 'click');
}

function msg_inbox_answered() {
	ajax_click($('frmBoxInAns'), $('box_in_answered_res'), 'click');
}

function msg_outbox() {
	ajax_click($('frmBoxOut'), $('box_out_res'), 'click');
}

function mrc_stats() {
	ajax_submit($('frm_mrc_stats'), $('frm_mrc_trnxs'), 'post', 'submit', $('progress'), '30px', 'checkForm2()');
}



function soi_draw_admin_task_list() {
	ajax_click($('frmAdminIndividualenPlan'), $('task_list'), 'load');
}

function soi_draw_admin_soi_panel() {
	ajax_click($('frmAdminIndividualenPlan'), $('soi_panel'), 'change');
}



function trnxs_in_pos_profile() {
	ajax_submit_wo_flashing_screen($('trnx_for_POS'), $('trnxs_in_pos_profile'), 'get', 'submit', null);
}

function doHeaderSearch(sid, pg_id) {
	var txt = $('txtHeaderSearch').value;
	uri = encodeURI('index.php?sid=' + sid + '&pg_id=' + pg_id + '&fld_txt=' + txt);
	result=$('divHeaderSrchRes');
	
	new Ajax(uri, {
		method: 'get',
		update: result,
		evalScripts: true
	}).request();
}
