function redirect(url){window.location.assign(url);}
function __selectMain(){window.location.replace('webboard_main.php');}
function __alertComment(data){alert(data);}

//--------------------------------
function addBBquote(data){
	var input = window.document.post.txtMessage;
	input.focus();

		if(typeof document.selection != 'undefined'){
			var range = document.selection.createRange();
			var insText = range.text;
			range.text = '[reply]'+ data + '[/reply]';
			range.move('character', +0);
			range.select();
		}		
		else if(typeof input.selectionStart != 'undefined')	{

			var start = input.selectionStart;
			var end = input.selectionEnd;
			var insText = input.value.substring(start, end);
			input.value = input.value.substr(0, start) + '[reply]'+ data + '[/reply]' + input.value.substr(end);
			var pos;
			if (insText.length == 0){
					pos = start + bbdebut.length;
					range.move('character', -bbfin.length);
				}
				else{
					pos = start + bbdebut.length + insText.length + bbfin.length;
				}
				input.selectionStart = pos;
				input.selectionEnd = pos;
		}
}
function bbcode2(bbdebut, bbfin){

	alert(bbdebut+" : "+bbfin);
}

function bbcode(bbdebut, bbfin){
			var input = window.document.post.txtMessage;
			input.focus();
			if(bbdebut=="[COLOR=0]"){return false;}
			if(bbdebut=="[SIZE=0]"){return false;}
			if(bbdebut=="[QUOTE=0]"){return false;}
			
		 if(typeof document.selection != 'undefined'){
				var range = document.selection.createRange();
				var insText = range.text;
				range.text = bbdebut + insText + bbfin;
				range = document.selection.createRange();
				if (insText.length == 0){
						range.move('character', -bbfin.length);
				}
				else{
						range.moveStart('character', bbdebut.length + insText.length + bbfin.length);
				}
				range.select();
		}
		else if(typeof input.selectionStart != 'undefined')	{
							var start = input.selectionStart;
							var end = input.selectionEnd;
							var insText = input.value.substring(start, end);
							input.value = input.value.substr(0, start) + bbdebut + insText + bbfin + input.value.substr(end);
							var pos;
							if (insText.length == 0){
									pos = start + bbdebut.length;
									range.move('character', -bbfin.length);
							}
							else{
								pos = start + bbdebut.length + insText.length + bbfin.length;
							}
							input.selectionStart = pos;
							input.selectionEnd = pos;
		}
	}
function bbcode_url(){

		var input = window.document.post.txtMessage;
		input.focus();
		
		url = prompt('Insert your URL','http://');
		if((url == "http://") || (url == null)){
			return false;	
		}
		
		title = prompt('Enter your Webpage Title','');
		if((title == "http://") || (title == null)){
			return false;	
		}
		
		bbdebut="[URL=" + url +"]";
		bbfin= title + "[/URL]";
		 
		 if(typeof document.selection != 'undefined'){
				var range = document.selection.createRange();
				var insText = range.text;
				range.text = bbdebut + insText + bbfin;
				range = document.selection.createRange();
				if (insText.length == 0){
						range.move('character', -bbfin.length);
				}
				else{
						range.moveStart('character', bbdebut.length + insText.length + bbfin.length);
				}
				range.select();
		}
		else if(typeof input.selectionStart != 'undefined')	{
							var start = input.selectionStart;
							var end = input.selectionEnd;
							var insText = input.value.substring(start, end);
							input.value = input.value.substr(0, start) + bbdebut + insText + bbfin + input.value.substr(end);
							var pos;
							if (insText.length == 0){
								pos = start + bbdebut.length;
							}
							else{
								pos = start + bbdebut.length + insText.length + bbfin.length;
							}
							input.selectionStart = pos;
							input.selectionEnd = pos;
		}

	}
//-----------------------------------------
function showPreview1(){
	var postname= document.getElementById('txtPostname').value;
	var message= document.getElementById('txtMessage').value;
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	var fnWhenDone = function (oXML) { 
		document.getElementById('scf_post_name_preview').innerHTML=postname;
		document.getElementById('post_message_preview').innerHTML=oXML.responseText;
		showPreview2();
	}
	DataToSend = "cmd=check&";
	DataToSend += "dataMessage="+message;
	myConn.connect("show_preview.php", "POST", DataToSend, fnWhenDone);
	return false;
	}

//-----------------------------------
function editStatusPost(id){
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
		var fnWhenDone = function (oXML) { 
		alert('ระบบได้ทำการบันทึกการแจ้งลบของท่านแล้ว ขอบคุณค่ะ');
	}
	DataToSend = "cmd=alert&";
	DataToSend += "idPost="+id;
	myConn.connect("alert_remove.php", "POST", DataToSend, fnWhenDone1);
	return false;
}
//---------------------------------------

function editPostMessage2(idPost){
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	var fnWhenDone = function (oXML) { 
		post.txtMessage.value=oXML.responseText;
		window.location = "#aaa";
		document.getElementById('txtMessage').focus();
	}
	DataToSend = "cmd=editPost&";
	DataToSend += "POST_ID="+idPost;
	myConn.connect("show_preview.php", "POST", DataToSend, fnWhenDone);
	return false;
	}
//-----------------------------------
function deletePostMessage2(idPost,tpid,rmid){
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	var fnWhenDone = function (oXML) { 
		document.getElementById('tr_'+idPost).style.display='none';
	}
	DataToSend = "cmd=deletePost&";
	DataToSend += "POST_ID="+idPost+"&TOPIC_ID="+tpid+"&BOARD_ID="+rmid;
	myConn.connect("show_preview.php", "POST", DataToSend, fnWhenDone);
	return false;
	}
//-----------------------------------
function deleteTopicMessage2(tpid,rmid){
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	var fnWhenDone = function (oXML) { 
			window.location = "webboard_topic.php";
	}
	DataToSend = "cmd=deleteTopic&";
	DataToSend += "TOPIC_ID="+tpid+"&BOARD_ID="+rmid;
	myConn.connect("show_preview.php", "POST", DataToSend, fnWhenDone);
	return false;

	}
//-----------------------------------
function updateTopic2(tpid,data){
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	var fnWhenDone = function (oXML) { 
			//window.location.reload();
			window.location = "webboard_post.php";
	}
	DataToSend = "cmd=updateTopic&";
	DataToSend += "TOPIC_ID="+tpid+"&data="+data;
	myConn.connect("show_preview.php", "POST", DataToSend, fnWhenDone);
	return false;
	}
//-----------------------------------
//-----------------------------------
function updateTopicType2(tpid,data,rmid){
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	var fnWhenDone = function (oXML) { 
			window.location = "webboard_topic.php?rmid="+rmid;
	}
	DataToSend = "cmd=updateTopicType&";
	DataToSend += "TOPIC_ID="+tpid+"&data="+data;
	myConn.connect("show_preview.php", "POST", DataToSend, fnWhenDone);
	return false;
	}
//-----------------------------------
function __cSearch(){
	var s1 = document.getElementById('boxSearch').style.display;
	if(s1=='' || s1==null){
	document.getElementById('boxSearch').style.display='none';
	}else{
	document.getElementById('boxSearch').style.display='';
	}
}
//---------------------------------------------------
function checksearch(){
	var form5 = document.forms["form5"];
var cLength = form5.cLength.value;
dataA = form5.keySearch.value;
if(dataA==''){
	alert('please insert key search');
	form5.keySearch.focus();
	return false;
	}
else if(dataA.length < cLength){
	alert('please insert key search over '+cLength+' character');
	form5.keySearch.focus();
	return false;
}
else
{
			var box_change = document.getElementById('Search_box');
			box_change.style.display='none';
			var waiting_show = document.getElementById('waiting');
			waiting_show.style.display='';
			return false;
form5.submit();
}
}
//---------------------------------------------

function openPopupForgot(URL){
	var newWind = window.open(URL, "forgot", "status=no,menubar=no,height=358,width=450");
}



