var doc = window.document;

function $parent(v) { doc = v; }
function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function $E(v) { return(doc.getElementById(v)); }
function $S(v) { return($E(v).style); }
function $T(v, text) { if(agent('msie')) $E(v).innerText = text; else $E(v).textContent = text; }
function $HTML(v, html) { $E(v).innerHTML = html; }
function $nodisplay(v) { $S(v).display = 'none'; }
function $display(v) { $S(v).display = 'block'; }
function isset(v) { return((typeof(v)=='undefined' || v.length==0)?false:true); }

function $translucent(v) { $S(v).filter = 'alpha(opacity=30)'; }
function $C(text) { alert(text); }
function $SetFocus(v) { doc.getElementById(v).focus(); }
function $SetValue(v,str) { doc.getElementById(v).value = str; }

function ajax(u,change) {
	var r=[function(){ return new XMLHttpRequest(); },function(){ return new ActiveXObject("Msxml2.XMLHTTP"); },function(){ return new ActiveXObject("Microsoft.XMLHTTP"); }];
	for(var i in r) { try { var v=r[i],q=v(); } catch(e) { continue; } }
	if(change) q.onreadystatechange=function(){
			if(q.readyState==4) {
				if (q.status==200) change(q.responseText);
				else alert("Error: " + q.status);
			}
		};
	q.open('GET',u);
	q.send(null);
}

function parse(text) {
	element = new my_element();
	if (text.length > 5) {
		array = text.split('&');
		for (i=0; i<array.length; i++) {
			element_value = array[i].split('=');
			element.add(element_value[0], element_value[1]);
		}
	}
	return element;
}

function findtext(str, obj) {
	i = 0;
	while (obj.options[i]) {
		strtext = obj.options[i].text;
		if (strtext.indexOf(str) == 0) {
			obj.selectedIndex = i;
			break;
		}
		i++;
	}
}

function saveok(textdisplay) {
	if (textdisplay.length > 0) {
		$S('saveok').backgroundColor = "#FFFF55";
		$HTML('saveok', '** บันทึก <b>"' + textdisplay + '"</b> เรียบร้อย');
		window.setTimeout("$nodisplay('saveok')", 5000);
	}
}

function Reload() {
	window.location.reload();
}

function mOvr(src,clrOver) {
	if (!src.contains(event.fromElement)) {
		src.style.cursor = 'default';
		src.bgColor = clrOver;
	}
	src = event.toElement;
}

function mOut(src,clrOut) {
	if (!src.contains(event.toElement)) {
		src.style.cursor = 'default';
		src.bgColor = clrOut;
	}
	src=event.fromElement;
}

function PopupNotify(type,id) {
	window.open('/get/notify.php?type='+type+'&id='+id,'notify','width=210,height=230,status=0,resizable=0,toolbar=0');
}