<!--

function InitializeGlobalData()
{
	if ('undefined' != typeof(strRtl))
		strIsRtl = strRtl;

	var divs = document.body.getElementsByTagName("DIV");
	var spans = document.body.getElementsByTagName("SPAN");

	var countDiv = 0;
	var countSpan = 0;
	if (typeof(divs) != "undefined" && null != divs)
		countDiv = divs.length;

	if (typeof(spans) != "undefined" && null != spans)
		countSpan = spans.length;

	allDivsInPage = new Array();
	for (i=0; i < countDiv; i++)
		if (typeof(divs[i].id) != "undefined" &&
			null != divs[i].id &&
			divs[i].id.length > 0)
			allDivsInPage[divs[i].id] = divs[i];

	for (i=0; i < countSpan; i++)
		if (typeof(spans[i].id) != "undefined" &&
			null != spans[i].id &&
			spans[i].id.length > 0)
			allDivsInPage[spans[i].id] = spans[i];

}

function ExpandDiv(theDivName)
{
	InitializeGlobalData(); 

	if (null == theDivName || typeof(theDivName) == "undefined") return; var theDiv = allDivsInPage[theDivName]; if (null == theDiv || typeof(theDiv) == "undefined") return;
	theDiv.style.display = "block";

}

function CollapseDiv(theDivName)
{
	InitializeGlobalData();

	if (null == theDivName || typeof(theDivName) == "undefined") return; var theDiv = allDivsInPage[theDivName]; if (null == theDiv || typeof(theDiv) == "undefined") return;
	theDiv.style.display = "none";

}

function ToggleDiv(theDivName)
{
	InitializeGlobalData();

	if (null == theDivName || typeof(theDivName) == "undefined") return; 
	var theDiv = allDivsInPage[theDivName]; 
	if (null == theDiv || typeof(theDiv) == "undefined") return;

	if (theDiv.style.display.toUpperCase() != "BLOCK")
		ExpandDiv(theDivName);
	else
		CollapseDiv(theDivName);
}

function SwapDiv(selected) {
	for (var i = 1; i < arguments.length ; i++ ) {
		theDiv = document.getElementById(arguments[i])
		if (arguments[i] == selected) {
			theDiv.style.display = "block"
		} else {
			theDiv.style.display = "none"
		}
	}
}

function showBalloon(BalloonID,x,y){
	document.getElementById(BalloonID).style.visibility = "visible";
	document.getElementById(BalloonID).style.left = x;
	document.getElementById(BalloonID).style.top = y;
}

function hideBalloon(BalloonID){
	document.getElementById(BalloonID).style.visibility = "hidden";
}

function PopWindow(ObjName, URL,W,H) {
	var Winsize = "alwaysRaised=yes, scrollbars=yes, status=yes, resizable=yes, width=" + W + ", height=" + H
	window.open(URL, ObjName, Winsize)
}

function PopSmallWindow(URL) {
	var Winsize = "alwaysRaised=yes, scrollbars=no, status=yes, resizable=yes, width=480, height=360"
	window.open(URL, '_blank', Winsize)
}

function TrimString(sInString) {
	sInString = sInString.replace( /^\s+/g, "" );// strip leading
	return sInString.replace( /\s+$/g, "" );// strip trailing
}


/*----- for new board only ------*/
	var isSelected = false;
	function storeCaret(textEl) {
		if (textEl.createTextRange) {
			textEl.caretPos = document.selection.createRange().duplicate();
			isSelected = true;
		}
	}

	function icon(myCode) {
		var txtObj = document.myForm.myEntry;
		if (txtObj.createTextRange && txtObj.caretPos) {
			var caretPos = txtObj.caretPos;
			if (caretPos.text.charAt(caretPos.text.length - 1) == ' ') {
				caretPos.text = myCode + ' ';
			} else {
				caretPos.text = myCode;
			}
			if (txtObj.caretPos.text=='') {
				txtObj.focus();
			}
		} else {
			txtObj.value += myCode;
			txtObj.focus();
		}
	}
	function insertMyCode (mysymbol) {
		var caretPos = document.myForm.myEntry.caretPos;
		switch (mysymbol) {
			case 'url' :
				var thisURL = prompt("ป้อน URL ตรงนี้", "http://");
				if (!thisURL | thisURL == "http://"){return;}
				if (isSelected && !caretPos.text == '') {
					myText = ' ' + "[:URL=" + thisURL + ":]" + caretPos.text + "[:/URL:]" + ' ';
					isSelected = false;
				} else if (document.myForm.myEntry.selectionEnd && (document.myForm.myEntry.selectionStart | document.myForm.myEntry.selectionStart == 0)) {
					mozInsert(document.myForm.myEntry, "[:URL=" + thisURL + ":]", "[:/URL:]");
					return;
				} else {
					var thisTitle = prompt("ทีนี้ก็ป้อนชื่อลิงค์ลงไป", thisURL);
					if (!thisTitle){return;}
					myText = ' ' + "[:URL=" + thisURL + ":]" + thisTitle + "[:/URL:]" + ' ';
				}
				doInsert(myText);
				break;
			case 'bold' :
				if (isSelected && !caretPos.text == '') {
					isSelected = false;
					myText = "[:b:]" + caretPos.text + "[:/b:]";
				} else if (document.myForm.myEntry.selectionEnd && (document.myForm.myEntry.selectionStart | document.myForm.myEntry.selectionStart == 0)) {
					mozInsert(document.myForm.myEntry, "[:b:]", "[:/b:]");
					return;
				} else {
					var thisBold = prompt("ป้อนข้อความที่ต้องการให้เป็นตัวหนา", "ตัวหนา");
					if(!thisBold) {return;}
					myText = "[:b:]" + thisBold + "[:/b:]";
				}
				doInsert(myText);
				break;
			default : 
				if (isSelected && !caretPos.text == '') {
					myText = ' ' + mysymbol + ' ' + caretPos.text;
					isSelected = false;
				} else {
					myText = ' ' + mysymbol + ' ';
				}
				doInsert(myText);
		}
	}
	function mozInsert(txtarea, openTag, closeTag) {
		if (txtarea.selectionEnd > txtarea.value.length) { txtarea.selectionEnd = txtarea.value.length; }

		var startPos = txtarea.selectionStart;
		var endPos = txtarea.selectionEnd+openTag.length;

		txtarea.value=txtarea.value.slice(0,startPos)+openTag+txtarea.value.slice(startPos);
		txtarea.value=txtarea.value.slice(0,endPos)+closeTag+txtarea.value.slice(endPos);

		txtarea.selectionStart = startPos+openTag.length;
		txtarea.selectionEnd = endPos;
		txtarea.focus();
	}
	function doInsert(myCode) {
		var txtObj = document.myForm.myEntry;
		if (txtObj.createTextRange && txtObj.caretPos) {
			var caretPos = txtObj.caretPos;
			if (caretPos.text.charAt(caretPos.text.length - 1) == ' ') {
				caretPos.text = myCode + ' ';
			} else {
				caretPos.text = myCode;
			}
			if (txtObj.caretPos.text=='') {
				isSelected = false;
				txtObj.focus();
			}
		} else if (txtObj.selectionEnd && (txtObj.selectionStart | txtObj.selectionStart == 0)) {
			mozInsert(txtObj, myCode, "");
			return;
		} else {
			txtObj.value += myCode;
			txtObj.focus();
		}
	}


	function checkInput() {
		if(document.myForm.myEntry.value=="") {
			alert("ข้อความ ?")
			document.myForm.myEntry.focus()
			return false
		}
		if(document.myForm.whom.value=="") {
			alert("ชื่อผู้เขียน ?")
			document.myForm.whom.focus()
			return false
		}
		if(document.myForm.pic_chk[1].checked && document.myForm.msg_pic.value=="") {
			alert("กรุณาเลือกไฟล์รูปภาพ ?")
			document.myForm.msg_pic.select()
			return false
		}
		if(document.myForm.chkCopy.value=="") {
			if(!confirm("เพื่อป้องกันข้อความหายไป กรณีโพสไม่สำเร็จ หรือเนตหลุด\nควรจะทำสำเนาข้อความไว้ก่อนนะครับ\n\nคลิก OK หากต้องการโพสเดี๋ยวนี้\nหรือ คลิก Cancel เพื่อกลับไปทำสำเนา")) {
				document.myForm.chkCopy.value='OK'
				return false
			}
		}
	}
	
/*----- for new board only ------*/

// -->
