function changeRating(value){
	document.getElementById("show"+value).style.display="";
	document.getElementById("r"+value).className="rating_on";
	for(var i=1;i<=3;i++){
		if(value != i){
			document.getElementById("show"+i).style.display="none";
			document.getElementById("r"+i).className="rating_off";
		}
	}
}

function changeBoard(value){
	  document.getElementById("board"+value).style.display="";
	  document.getElementById("c"+value).className="board_on";
	  for(var i=1;i<=3;i++){
			 if(value != i){
				document.getElementById("board"+i).style.display="none";
				document.getElementById("c"+i).className="board_off";
			 }
	  }
}

function changeAlbum(value){
	document.getElementById("showalbum"+value).style.display="";
	document.getElementById("a"+value).className="rating_on";
	for(var i=1;i<=2;i++){
		if(value != i){
			document.getElementById("showalbum"+i).style.display="none";
			document.getElementById("a"+i).className="rating_off";
		}
	}
}

function rand(index){ 
	today=new Date();
	jran=today.getTime();
	var MaxNumber = index;
	ia=9301;
	ic=49297;
	im=233280;
	jran = (jran*ia+ic) % im;
	rand = Math.ceil( (jran/(im*1.0)) *MaxNumber);  
	changeRating(rand);
	changeBoard(rand);
} 

function checkSearch(){
	if(document.search_form.nick.value==""){
		alert('กรุณาใส่ชื่อที่ต้องการค้นหา');
	}else{
		document.search_form.submit();
	}
}
					  
function checkBrowse(){
	if(navigator.appName == "Microsoft Internet Explorer") return true;
	else  return false;
}
		 
   function openAppShow(val){
		 if(val==0){
			 document.getElementById("form_app_chat").style.display='';
			 document.getElementById("form_app").style.display='none';
		 }else{
			 document.getElementById("form_app_chat").style.display='none';
			 document.getElementById("form_app").style.display='';
		 }
   }

	function GetXmlHttpObject(handler){ 

				var objXmlHttp=null;
				if(navigator.userAgent.indexOf("Opera")>=0){
							alert("This example doesn't work in Opera") ;
							return 
				}
				if (navigator.userAgent.indexOf("MSIE")>=0){ 
							var strName="Msxml2.XMLHTTP";
							if(navigator.appVersion.indexOf("MSIE 5.5")>=0){
										strName="Microsoft.XMLHTTP";
							}
							try{ 
										objXmlHttp=new ActiveXObject(strName);
										objXmlHttp.onreadystatechange=handler ;
										return objXmlHttp;
							}catch(e){ 
										alert("Error. Scripting for ActiveX might be disabled") ;
										return ;
							} 
			  } 
			 if (navigator.userAgent.indexOf("Mozilla")>=0){
						objXmlHttp=new XMLHttpRequest();
						objXmlHttp.onload=handler;
						objXmlHttp.onerror=handler ;
						return objXmlHttp;
			 }
	} 

   function stateChanged(){ 
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
				var response=xmlHttp.responseText ;
				alert('บันทึกเรียบร้อยแล้ว');
				 var detail=document.getElementById("chat_detail");
				 var msg=document.getElementById("msg_app");
				 msg.value='';
				  var butt=document.getElementById("butt_app");
				  butt.disabled=false;
				  butt.value='บันทึก';
				  detail.innerHTML=response;
				  openAppShow(0);
			} 
	} 

	function addApp(){
		  var msg=document.getElementById("msg_app");
		  var minute=document.getElementsByName("Time_Minute");
		  var hour=document.getElementsByName("Time_Hour");

		  if(msg.value==""){
			 alert('กรอกข้อความให้ครบถ้วน');
			 return false;
		  }
		  var butt=document.getElementById("butt_app");
		  butt.disabled=true;
		  butt.value='....';
		 
		  var url="/board/add_app.php?sid="+ Math.random()+"&msg="+msg.value+"&minute="+minute[0].value+"&hour="+hour[0].value;
		  xmlHttp=GetXmlHttpObject(stateChanged);
		  xmlHttp.open("GET", url , true);
		  xmlHttp.send(null);	   
   }



function refreshTalk(){
		 
		  document.getElementById("talk_id").style.width='150px';
		  document.getElementById("talk_load").style.display='';
		  var url="home/refresh_talk.php?sid="+ Math.random();
		  xmlHttp=GetXmlHttpObject(stateChangedTalk);
		  xmlHttp.open("GET", url , true);
		  xmlHttp.send(null);	   
}

function stateChangedTalk(){ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
			var response=xmlHttp.responseText ;
			document.getElementById('talk_rep').innerHTML = response;      
			document.getElementById("talk_id").style.width='170px';
			document.getElementById("talk_load").style.display='none';
			document.getElementById("talk_id").value='';
		} 
} 



  var http_request = false;
   function makePOSTRequest(url, parameters) {
	  http_request = false;
	  if (window.XMLHttpRequest) { 
		 http_request = new XMLHttpRequest();
		 if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/html');
		 }
	  } else if (window.ActiveXObject) { // IE
		 try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		 } catch (e) {
			try {
			   http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		 }
	  }
	  if (!http_request) {
		 alert('Cannot create XMLHTTP instance');
		 return false;
	  }
	  
	  http_request.onreadystatechange = alertContents;
	  http_request.open('POST', url, true);
	  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	  http_request.setRequestHeader("Content-length", parameters.length);
	  http_request.setRequestHeader("Connection", "close");
	  http_request.send(parameters);
   }

   function alertContents() {
	  if (http_request.readyState == 4) {
		 if (http_request.status == 200) {
			result = http_request.responseText;
			document.getElementById('talk_rep').innerHTML = result;      
			document.getElementById("talk_id").style.width='170px';
			document.getElementById("talk_load").style.display='none';
			document.getElementById("talk_id").value='';
		 } else {
			alert('There was a problem with the request.');
		 }
	  }
   }
   
   function get(obj){	
	  if(document.getElementById("talk_id").value==""){
          alert('กรอกข้อความด้วย');
		  return false;
	  }
	  document.getElementById("talk_id").style.width='150px';
	  document.getElementById("talk_load").style.display='';
	  var poststr = "mode=index&talk=" + encodeURI(document.getElementById("talk_id").value);
	  makePOSTRequest('/home/save_talk.php', poststr);
   }


 /*msn*/

   function openMsnShow(val){
		 if(val==0){
			 document.getElementById("form_msn_more").style.display='';
			 document.getElementById("form_msn").style.display='none';
		 }else{
			 document.getElementById("form_msn_more").style.display='none';
			 document.getElementById("form_msn").style.display='';
		 }
	}


  var http_request = false;
   function makePOSTMsn(url, parameters) {
	  http_request = false;
	  if (window.XMLHttpRequest) { 
		 http_request = new XMLHttpRequest();
		 if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/html');
		 }
	  } else if (window.ActiveXObject) { // IE
		 try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		 } catch (e) {
			try {
			   http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		 }
	  }
	  if (!http_request) {
		 alert('Cannot create XMLHTTP instance');
		 return false;
	  }
	  
	  http_request.onreadystatechange = alertMsn;
	  http_request.open('POST', url, true);
	  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	  http_request.setRequestHeader("Content-length", parameters.length);
	  http_request.setRequestHeader("Connection", "close");
	  http_request.send(parameters);
   }

   function alertMsn() {
	  if (http_request.readyState == 4) {
		 if (http_request.status == 200) {
			result = http_request.responseText;
			document.getElementById('msn_rep').innerHTML = result;      
			document.getElementById("msn_load").style.display='none';
			document.getElementById("msn_id").value='';
			document.getElementById("msn_msg").value='';
			document.getElementById("msn_id").style.width='70px';
			 openMsnShow(0);
		 } else {
			alert('There was a problem with the request.');
		 }
	  }
   }


function addMsn(){
		  var msn=document.getElementById("msn_id");
		  var msn_detail=document.getElementById("msn_msg");

		  if(msn.value.indexOf("@")==-1){
			   alert('กรอก email ให้ถูกต้องด้วยครับ');
				msg.focus();
			   return false;
		  }else if(msn.value.indexOf(".")==-1){
			   alert('กรอก email  ให้ถูกต้องด้วยครับ');
			   msn.focus();
			   return false;
		  }else if(msn_detail.value==""){
			   alert('กรอก ข้อความ แนะนำตัวด้วย');
			   msn_detail.focus();
			   return false;
		  }

		  var poststr = "msn_id=" + encodeURI(msn.value)+"&msn_msg=" + encodeURI(msn_detail.value);
		  document.getElementById("msn_id").style.width='50px';
		  document.getElementById("msn_load").style.display='';
		  makePOSTMsn('/save_msn.php',poststr);
   }



	function newFriend2008(){ 
					  var url="cron_fri3nd.php?refresh=1&name=refresh_newFriend2008&sid="+ Math.random();
					  xmlHttp=GetXmlHttpObject(refresh_newFriend2008);
					  xmlHttp.open("GET", url , true);
					  xmlHttp.send(null);	
	}function refresh_newFriend2008(){ 
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
				var response=xmlHttp.responseText ;
				document.getElementById('refresh_newFriend2008').innerHTML = response;   
				 profileUpdate2008();
			} 
	} 


	/**/
	function profileUpdate2008(){ 
					  var url="cron_fri3nd.php?refresh=1&name=refresh_profileUpdate2008&sid="+ Math.random();
					  xmlHttp=GetXmlHttpObject(refresh_profileUpdate2008);
					  xmlHttp.open("GET", url , true);
					  xmlHttp.send(null);	
	}function refresh_profileUpdate2008(){ 
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
				var response=xmlHttp.responseText ;
				document.getElementById('refresh_profileUpdate2008').innerHTML = response;   
				 updateAlbumFristpage2008();

			} 
	} 



	/**/
	function updateAlbumFristpage2008(){ 
					  var url="cron_fri3nd.php?refresh=1&name=refresh_updateAlbumFristpage2008&sid="+ Math.random();
					  xmlHttp=GetXmlHttpObject(refresh_updateAlbumFristpage2008);
					  xmlHttp.open("GET", url , true);
					  xmlHttp.send(null);	
	}function refresh_updateAlbumFristpage2008(){ 
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
				var response=xmlHttp.responseText ;
				document.getElementById('refresh_updateAlbumFristpage2008').innerHTML = response;   
				 updateAlbumClubFristpage2008();
			} 
	} 


	/**/
	function updateAlbumClubFristpage2008(){ 
					  var url="cron_fri3nd.php?refresh=1&name=refresh_updateAlbumClubFristpage2008&sid="+ Math.random();
					  xmlHttp=GetXmlHttpObject(refresh_updateAlbumClubFristpage2008);
					  xmlHttp.open("GET", url , true);
					  xmlHttp.send(null);	
	}function refresh_updateAlbumClubFristpage2008(){ 
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
				var response=xmlHttp.responseText ;
				document.getElementById('refresh_updateAlbumClubFristpage2008').innerHTML = response;   
				updateBlogFristpageNew2008();
			} 
	} 


	/**/
	function updateBlogFristpageNew2008(){ 
					  var url="cron_fri3nd.php?refresh=1&name=refresh_updateBlogFristpageNew2008&sid="+ Math.random();
					  xmlHttp=GetXmlHttpObject(refresh_updateBlogFristpageNew2008);
					  xmlHttp.open("GET", url , true);
					  xmlHttp.send(null);	
	}
	function refresh_updateBlogFristpageNew2008(){ 
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
				var response=xmlHttp.responseText ;
				document.getElementById('refresh_updateBlogFristpageNew2008').innerHTML = response;  
				 refreshTalk();
			} 
	} 

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='rss.php?url="+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// ++++++++  AJAX สำหรับ ข้อมูล ส่วน MSN List ++++++++ \\
function actionMSN(action, page, msn, comment, name) 
{ 
	new Ajax.Updater('showMSN', '../../home/msn/showmsn.php?action='+action+'&msn='+msn+'&comment='+comment+'&name='+name+'&page='+page, 
			{
				onComplete: function() { document.getElementById('msn-loading').innerHTML="";  if($('showMSN').style.display=="none") { $('showDiary').style.display='block';} }
			} ); 
}
// ++++++++++++++++++++++++++++++++++++++++++ \\

// +++++++++++  AJAX สำหรับ ข้อมูล ส่วน Diary  ++++++++ \\
function actionDiary(page) 
{ 
	new Ajax.Updater('showDiary', '../../home/showdiary/showdiary.php?page='+page, 
			{
				onComplete: function() { document.getElementById('diary-loading').innerHTML=""; if($('showDiary').style.display=="none") { $('showDiary').style.display='block';}  }
			} ); 
}
// ++++++++++++++++++++++++++++++++++++++++++ \\

// ++++++++  AJAX สำหรับ ข้อมูล ส่วน Comment ฝากข้อความ ++++++++ \\
function actionShoutbox(pagesize) 
{ 
	
	new Ajax.Updater('showShoutbox', '../../home/comment/showcomment.php?pagesize='+pagesize, 
			{
				onComplete: function() { if($('showShoutbox').style.display=="none") { $('showShoutbox').style.display='block';}  }
			} ); 
}

// ฟังก์ชั่น ส่งค่าจาก FCKeditorAPI ไปยังตัวแปร
function includeMsgComment(data) 
{ 
	var oEditor1 = FCKeditorAPI.GetInstance(data);
	var temp_str = oEditor1.GetXHTML(true);

	var spcRemove	= "";
	var myOldString	= "";
	var myNewString	= "";
	
	// เปลี่ยน tag &nbsp; ในข้อความใหม่
	spcRemove = " ";
	myOldString = temp_str;
	myNewString = myOldString.replace(/&nbsp;/g, spcRemove);

	// เปลี่ยน tag <br> ในข้อความใหม่
	spcRemove = "<br>";
	myOldString = myNewString;
	myNewString = myOldString.replace(/<br \/>/g, spcRemove);

	return myNewString;
}

// ฟังก์ชั่นการ โพสข้อความและบันทึก
function addShoutbox(action) 
{ 
	if(action=='add') {	// เพิ่มข้อความ
		new Ajax.Updater('showShoutbox', '../../home/comment/form_new.php?action='+action); 
	} else if(action=='addnew') {	// เพิ่มข้อความใหม่

		var temp_str = encodeURI(includeMsgComment('idetailX'));	// เข้ารหัสข้อความ URI

		var var_temp = 'action='+action+'&idetailX='+ temp_str +'&inameX='+$('inameX').value+'&txtConfirmSubmit='+$('txtConfirmSubmit').value;
		new Ajax.Updater('showShoutbox', '../../home/comment/form_new.php?action='+action ,
			{
				method: 'post' , 
				postBody: var_temp ,
				onSuccess: function() { setTimeout("actionShoutbox(30)", 2000); }
			} );

	}		
}

// ฟังก์ชั่นสำหรับการ ลบ/แบน/ยกเลิกการแบน ข้อความ
function delShoutbox(action , id) 
{ 
		new Ajax.Updater('showShoutbox', '../../home/comment/form_new.php?action='+action+'&id='+id ,
			{
				onSuccess: function() { actionShoutbox(30); }
			} ); 	
}

// ฟังก์ชั่นการเปลี่ยน ภาพรหัสลับ สำหรับการโพส
function changeSecurity()
{
		document.getElementById('imageSecurity').innerHTML='<img src=../../home/comment/img.php align=absbottom onclick="changeSecurity();" style="cursor:pointer;">';
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++ \\
function changeRSS(url) { new Ajax.Updater('showRSS', 'rss.php?url='+url); }


function actionNews(page) 
{ 
	var fileName = '../../home/news/shownews.php';
	new Ajax.Updater('showNews', fileName+'?page='+page, 
			{
				onComplete: function() { document.getElementById('news-loading').innerHTML=""; if($('showNews').style.display=="none") { $('showNews').style.display='block';}  }
			} ); 
}

function showloading(id , size)
{
	document.getElementById(''+id).innerHTML="<br><br><center><img src='../../img/loading-"+size+".gif'></center><br>";
}

function showLoadingProgress(id)
{
	document.getElementById(''+id).innerHTML="<img src='../../img/loading-big.gif'>"; 
}
function hideLoadingProgress(id)
{
	document.getElementById(''+id).style.display="none"; 
}

function check_postcomment()
{
		var v1 = document.getElementById('inameX');
		var v3 = document.getElementById('txtConfirmSubmit');
		
		if(v1.value.length < 1)
		{
				alert("กรุณาระบุชื่อของคุณ !!");
				v1.focus();
				return false;
		}
		//else if(v3.value.length < 5)
		//{
		//		alert("กรุณาระบุ รหัสยืนยันการโพสก่อน นะจ๊ะ");
		//		v3.focus();
		//		return false;
		//>
		else 	return true;
}

function checkMSN()
{
	var v1= document.frmMSN.hid_msn.value=document.frmMSN.txt_msn.value;
	var v2=document.frmMSN.hid_comm.value=document.frmMSN.txt_comm.value;
	var v3=document.frmMSN.hid_nickname.value=document.frmMSN.txt_nickname.value;
	
	if(v1.length < 14)
	{
		alert("กรุณา ระบุ MSN ของคุณก่อน");
		document.frmMSN.txt_msn.focus();
		return false;
	}
	else	if(v2.length < 5)
	{
		alert("กรุณา แนะนำตัวซักนิดนะคะ");
		document.frmMSN.txt_comm.focus();
		return false;
	}
	else 	if(v3.length < 2 )
	{
		alert("กรุณา ระบุ  ชื่อเล่น หรือชื่อเรียกขาน ของคุณก่อน");
		document.frmMSN.txt_nickname.focus();
		return false;
	}
	else
	{
		document.frmMSN.txt_msn.value='';
		document.frmMSN.txt_comm.value='';
		document.frmMSN.txt_nickname.value='';		
		return true;
	}
			
}

function openSendboxMSN()
{
	if($('sendMSN').style.display=='block')
		$('sendMSN').style.display='none';
	else
		$('sendMSN').style.display='block';
}