/* $Rev: 3634 $ */
if (jQuery) (function($) {
	
	$.jajax = function(c, p) {
		if ('string' != typeof c) {
			alert('JAJAX url not set');
			return false;
		}
		if ('undefined' == typeof p) {
			p = {};
		}
		if ('undefined' == typeof p.fun) {
			p.fun = null;
		}
		if ('undefined' == typeof p.error) {
			p.error = null;
		}
		if ('undefined' == typeof p.datatype) {
			p.datatype = 'json';
		}
		if ('undefined' == typeof p.post) {
			p.post = '';
		}
		if ('undefined' == typeof p.async) {
			p.async = true;
		}
		if ('undefined' != typeof p.formid) {
			var a = $('#' + p.formid).serialize();
			if (('' != a) && ('' != p.post)) {
				a += '&';
			}
			if (('boolean' == typeof p.clearform) && (p.clearform)) {
				$('#' + p.formid).each(function() {
					this.reset();
				});
			}
			p.post = a + p.post;
		}
		$.ajax({
			type:'POST',
			url:c,
			data:p.post,
			cache:false,
			async:p.async,
			dataType:p.datatype,
			processData:false,
			scriptCharset:'UTF-8',
			beforeSend:function(xmlHttpRequest) {
				xmlHttpRequest.setRequestHeader('X-JAJAX-Version', '0.2');			
			},
			success:function(response) {
				if (null != p.fun) {
					p.fun(response);
				}
			},
			error:function(response) {
				if (null != p.error) {
					p.error(response);
				}
			}
		});
	};

	$.jajaxparse = function(r) {
		if (null == r) {
			return false;
		}
		if ('undefined' != typeof r.innerhtml) {
			for (var i in r.innerhtml) {
				$('#' + r.innerhtml[i].id).html(r.innerhtml[i].html);
			}
		}
		if ('undefined' != typeof r.appendhtml) {
			for (var i in r.appendhtml) {
				$('#' + r.appendhtml[i].id).append(r.appendhtml[i].html);
			}
		}
		if ('undefined' != typeof r.prependhtml) {
			for (var i in r.prependhtml) {
				$('#' + r.prependhtml[i].id).prepend(r.prependhtml[i].html);
			}
		}
		if ('undefined' != typeof r.eval) {
			for (var i in r.eval) {
				eval(r.eval[i]);
			}
		}
		if ('undefined' != typeof r.addclass) {
			for (var i in r.addclass) {
				$('#' + r.addclass[i].id).addClass(r.addclass[i].classes);
			}
		}
		if ('undefined' != typeof r.removeclass) {
			for (var i in r.removeclass) {
				$('#' + r.removeclass[i].id).removeClass(r.removeclass[i].classes);
			}
		}
		if ('undefined' != typeof r.loadjs) {
			for (var i in r.loadjs) {
				$('head:first').prepend('<script type="text/javascript" src="' + r.loadjs[i] + '"></script>');
			}
		}
		if ('undefined' != typeof r.loadcss) {
			for (var i in r.loadcss) {
				$('head:first').prepend('<link rel="stylesheet" type="text/css" href="' + r.loadcss[i] + '"/>');
			}
		}
	};
	
})(jQuery);

