var myhost = 'http://www.bangpo-hospital.com/th';
function preloadimage(path,w,h) {
    if (document.images) {
      preload_image = new Image(w,h); 
      preload_image.src = path; 
    }
}
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,'');
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,'');
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,'');
}

jQuery.fn.center = function () {
	this.css('position', 'absolute');
	this.css('top', ($(window).height() - this.height()) / 2 + $(window).scrollTop() + 'px');
	this.css('left', ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + 'px');
	return this;
}

jQuery.fn.divcenter = function (mainbox, type) {
	this.css('position', 'relative');
	if (type=='h') {
		if ($('#' + mainbox).height() > this.height()) {
			this.css('top', ($('#' + mainbox).height() - this.height()) / 2 + 'px');
		}
	} else if (type=='w') {
		if ($('#' + mainbox).width() > this.width()) {
			this.css('left', ($('#' + mainbox).width() - this.width()) / 2 + 'px');
		}
	} else {
		if ($('#' + mainbox).height() > this.height()) {
			this.css('top', ($('#' + mainbox).height() - this.height()) / 2 + 'px');
		}
		if ($('#' + mainbox).width() > this.width()) {
			this.css('left', ($('#' + mainbox).width() - this.width()) / 2 + 'px');
		}
	}
	return this;
}

/*--- AJAX Function Library ---*/
function AjaxFunction(destpath, QString, DestArea, CallNext, ParamString) {
	callback = function (data) {
		if (CallNext == '') {
			$('#' + DestArea).html(data);
		} else {
			eval(CallNext+'(data, DestArea, ParamString)');
		}
	}
	$.get(destpath + '?ranno=' + Math.random() + QString, callback);
}

function AjaxFunctionWithPreload(destpath, QString, DestArea, InnerDisplay, InnerDisplayArea, CallNext, ParamString) {
	$('#' + InnerDisplayArea).html(InnerDisplay);
	callback = function (data) {
		if (CallNext == '') {
			$('#' + InnerDisplayArea).html('');
			$('#' + DestArea).html(data);
		} else {
			eval(CallNext+'(data, DestArea, InnerDisplayArea, ParamString)');
		}
	}
	$.get(destpath + '?ranno=' + Math.random() + QString, callback);
}

function AjaxPostFunction(destpath, dataset, DestArea, CallNext, ParamString) {
//var dataset = { name: 55555 };
//var dataset = $('#mainform').serialize();
	callback = function (data) {
		if (CallNext == '') {
			$('#' + DestArea).html(data);
		} else {
			eval(CallNext+'(data, DestArea, ParamString)');
		}
	}
	$.post(destpath + '?ranno=' + Math.random(), dataset, callback);
}

function AjaxPostFunctionWithPreload(destpath, dataset, DestArea, InnerDisplay, InnerDisplayArea, CallNext, ParamString) {
//var dataset = { name: 55555 };
//var dataset = $('#mainform').serialize();
	$('#' + InnerDisplayArea).html(InnerDisplay);
	callback = function (data) {
		if (CallNext == '') {
			$('#' + InnerDisplayArea).html('');
			$('#' + DestArea).html(data);
		} else {
			eval(CallNext+'(data, DestArea, InnerDisplayArea, ParamString)');
		}
	}
	$.post(destpath + '?ranno=' + Math.random(), dataset, callback);
}

function RedirectHome() {
	window.location = 'http://' + myhost + '/index.php';
}
