function jQueryGetElem(elm) {
	return $("*").get($("*").index($("#" + elm)[0]));
}

function oGetjQueryDatePickerTH() {
	var d = new Date();
	var toDay = d.getDate() + '/' + (d.getMonth() + 1) + '/' + (d.getFullYear() + 543);
	jQueryDatePickerTH = 
	{ 
		changeMonth: true,
		changeYear: true,
		dateFormat: 'dd/mm/yy',
		isBuddhist: true,
		defaultDate: toDay,dayNames: ['อาทิตย์','จันทร์','อังคาร','พุธ','พฤหัสบดี','ศุกร์','เสาร์'],
		dayNamesMin: ['อา.','จ.','อ.','พ.','พฤ.','ศ.','ส.'],
		monthNames: ['มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม'],
		monthNamesShort: ['ม.ค.','ก.พ.','มี.ค.','เม.ย.','พ.ค.','มิ.ย.','ก.ค.','ส.ค.','ก.ย.','ต.ค.','พ.ย.','ธ.ค.']
	};
	return jQueryDatePickerTH;
}

function openPopup(url, width, height) {
	var mywindow = window.open(url, "mywindow","toolbar=no,location=0,status=0,scrollbars=1,width=" + width + ",height=" + height + "");
	mywindow.moveTo(screen.availWidth / 2 - (width / 2), screen.availHeight / 2 - (height / 2));
	return false;
}

function goLocation(url) {
	window.location = url;
}

function getCallbackYes() {
	var callback = function() {
		$('#dialog').dialog('close');
	};
	return callback;
}

function getCallbackNo() {
	var callback = function() {
		$('#dialog').dialog('close');
	};
	return callback;
}

function openDialogConfirm(yes, no) {
	$('#dialog').dialog({
		autoOpen : false, 
		buttons : 	{ "ลบรายการ" : yes, 
						   "ยกเลิก" : no
						}, 
		draggable : false, 
		modal : true
	});
	$('#dialog').dialog('open');
}

function openDialog(title, message) {
	$('#dialog').html(message);
	$('#dialog').dialog({
		modal : true, 
		title : title
	});
	$('#dialog').dialog('open');
}

function getCallbackDeleteItem(id, url) {
	var callback = function() {
		goLocation(url);
		jQuery('#dialog').dialog('close');
	};
	return callback;
}

function openPopup(url, width, height) {
	var mywindow = window.open(url, "mywindow","toolbar=no,location=0,status=0,scrollbars=1,width=" + width + ",height=" + height + "");
	mywindow.moveTo(screen.availWidth / 2 - (width / 2), screen.availHeight / 2 - (height / 2));
	return false;
}

function openPopups(url, width, height, obj) {
	var mywindow = window.open(url, obj,"toolbar=no,location=0,status=0,scrollbars=1,width=" + width + ",height=" + height + "");
	mywindow.moveTo(screen.availWidth / 2 - (width / 2), screen.availHeight / 2 - (height / 2));
	return false;
}
 
function removeFormField(id) {
	$(id).remove();
}

/*
* AJAX by classic javascript
*/

function Inint_AJAX() {
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} 
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
   try { return new XMLHttpRequest(); } catch(e) {}
   alert("XMLHttpRequest not supported");
   return null;
};

/*
* AJAX by JQuery
*/

var ajaxSendElementItems;

function ajaxSend() {
	$("#" + ajaxSendElementItems).html('');
	var loading = '<img src="images/animation/ajaxLoading.gif" align="absmiddle">';
	$("#" + ajaxSendElementItems).append(loading);
}
