function TS_Ajax()
{
try
{
return new ActiveXObject( "Msxml2.XMLHTTP" );
}
catch (e)
{
}
try
{
return new ActiveXObject( "Microsoft.XMLHTTP" );
}
catch (e)
{
}
try
{
return new XMLHttpRequest();
}
catch (e)
{
}
alert("request not supported");
return null;
}

var Req=TS_Ajax();
var Category="";
var Allow="";
var HexChars="0123456789ABCDEF";

function TS_Dec2Hex(Value)
{
var A_Value=Value % 16;
var B_Value=(Value - A_Value)/16;
hex="" + HexChars.charAt(B_Value) + HexChars.charAt(A_Value);
return hex;
}

function TS_ThaiHex(Value)
{
s2='';
for(var i=0;i<Value.length;i++)
{
if(Value.charCodeAt(i)>3423)
{
n=Value.charCodeAt(i)-3424;
s2+='%'+TS_Dec2Hex(n);
}
else s2+=Value.charAt(i);
}
return s2
} 

function TS_GetAjax(Page, Num, Output)
{
TS_Sound.src=Sound_Click;
Req.open("GET", Page+"?id="+Num, true);
Req.onreadystatechange=function()
{
if (Req.readyState==4)
{
if (Req.status==200)
{
document.getElementById(Output).innerHTML=Req.responseText;
}
}
}
Req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
Req.send(null);
}

function TS_ConEdit(Input, Output, Control, Value)
{
Req.open("GET", "ajax_txtbox.php?input="+Input+"&output="+Output+"&control="+Control+"&value="+Value, true);
Req.onreadystatechange=function()
{
if (Req.readyState==4)
{
if (Req.status==200)
{
document.getElementById(Output).innerHTML=Req.responseText;
}
}
}
Req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
Req.send(null);
}

function TS_Control(Input, Output, Control)
{
var Value=document.getElementById(Input).value;
Req.open("GET", "ajax_control.php?input="+Input+"&output="+Output+"&control="+Control+"&value="+Value, true);
Req.onreadystatechange=function()
{
if (Req.readyState==4)
{
if (Req.status==200)
{
document.getElementById(Output).innerHTML=Req.responseText;
}
}
};
Req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
Req.send(null);
}

function TS_Category()
{
TS_Sound.src=Sound_Click;
var Output=document.getElementById('output').value;
var Cat=document.getElementById('select').value;
var Page="1";
Req.open("GET", Output+"?cat="+Cat+"&page="+Page, true);
Req.onreadystatechange=function()
{
if (Req.readyState==4)
{
if (Req.status==200)
{
document.getElementById("Output_Main").innerHTML=Req.responseText;
document.getElementById("cat").value=Cat;
document.getElementById("page").value=Page;
document.getElementById("Output_Page").value=Page;
}
}
};
Req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
Req.send(null);
}

function TS_Page(Status)
{
TS_Sound.src=Sound_Click;
var Output=document.getElementById('output').value;
var Cat=document.getElementById('cat').value;
var Num=document.getElementById('num').value;
var Page=document.getElementById('page').value;
if(Num!="0")
{
if(Status=="first")
{
var Page=1;
}
if(Status=="previous")
{
if(Page=="1")
{
var Page=1;
}
else
{
var Page=parseInt(Page) - 1;
}
}
if(Status=="next")
{
if(Page==Num)
{
var Page=parseInt(Num);
}
else
{
var Page=parseInt(Page) + 1;
}
}
if(Status=="last")
{
var Page=parseInt(Num);
}
}
else
{
var Page=1;
}
Req.open("GET", Output+"?cat="+Cat+"&page="+Page, true);
Req.onreadystatechange=function()
{
if (Req.readyState==4)
{
if (Req.status==200)
{
document.getElementById("Output_Main").innerHTML=Req.responseText;
document.getElementById("cat").value=Cat;
document.getElementById("page").value=Page;
document.getElementById("Output_ShowPage").innerHTML="<input type='text' name='Output_Page' value='"+Page+"' readonly class='TS_Input_Status' onmouseover=\"TS_ShowPage('true');\">";
TS_GoTop();
}
}
};
Req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
Req.send(null);
}

function TS_ShowPage(Status)
{
TS_Sound.src=Sound_Click;
var Output=document.getElementById('output').value;
var Num=document.getElementById('num').value;
var Page=document.getElementById('page').value;
Req.open("GET", "ajax_pagenum.php?num="+Num+"&page="+Page+"&status="+Status, true);
Req.onreadystatechange=function()
{
if (Req.readyState==4)
{
if (Req.status==200)
{
document.getElementById("Output_ShowPage").innerHTML=Req.responseText;
}
}
};
Req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
Req.send(null);
}

function TS_SelectPage()
{
TS_Sound.src=Sound_Click;
var Output=document.getElementById('output').value;
var Cat=document.getElementById('cat').value;
var Page=document.getElementById('Select_Page').value;
Req.open("GET", Output+"?cat="+Cat+"&page="+Page, true);
Req.onreadystatechange=function()
{
if (Req.readyState==4)
{
if (Req.status==200)
{
document.getElementById("Output_Main").innerHTML=Req.responseText;
document.getElementById("cat").value=Cat;
document.getElementById("page").value=Page;
document.getElementById("Output_ShowPage").innerHTML="<input type='text' name='Output_Page' value='"+Page+"' readonly class='TS_Input_Status' onmouseover=\"TS_ShowPage('true');\">";
TS_GoTop();
}
}
};
Req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
Req.send(null);
}

function TS_GetCmd(Output, Value)
{
TS_Sound.src=Sound_Click;
var Cat=document.getElementById('cat').value;
var Page=document.getElementById('page').value;
var strURL=Output+"?cat="+Cat+"&page="+Page+"&id="+Value;
window.location=strURL;
}

function TS_GetReport(Output, Value)
{
var PopUp=0;
var strURL=Output+"?id="+Value;
TS_Sound.src=Sound_Click;
if(PopUp)
{
if(!PopUp.closed) PopUp.close();
}
PopUp=window.open(strURL);
PopUp.focus();
}

function TS_ListMain()
{
TS_Sound.src=Sound_Click;
var Output="list_main.php";
window.location=Output;
}

function TS_ListCancel(Page, Value)
{
TS_Sound.src=Sound_Click;
var Output=Page+"?"+Value;
window.location=Output;
}

function TS_ListStatus(Page, Value)
{
TS_Sound.src=Sound_Click;
var Output=Page+"?"+Value;
window.location=Output;
}

function TS_ListShow(Page, Value, Show)
{
TS_Sound.src=Sound_Click;
var Output="ajax_"+Page+"?status=show"+Value+"&show="+Show;
Req.open("GET", Output, true);
Req.onreadystatechange=function()
{
if (Req.readyState==4)
{
if (Req.status==200)
{
document.getElementById("Output_Main").innerHTML=Req.responseText;
}
}
}
Req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
Req.send(null);
}

function TS_ListTarget(Page, Value, Target)
{
TS_Sound.src=Sound_Click;
var Output="ajax_"+Page+"?status=target"+Value+"&target="+Target;
Req.open("GET", Output, true);
Req.onreadystatechange=function()
{
if (Req.readyState==4)
{
if (Req.status==200)
{
document.getElementById("Output_Main").innerHTML=Req.responseText;
}
}
}
Req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
Req.send(null);
}

function TS_ListDelO(Page, Value, Create, Update)
{
TS_Sound.src=Sound_Click;
var ChkConfirm=confirm('ลบข้อมูลที่ทำรายการ');
if (ChkConfirm==0)
{
return false
}
else
{
//Start Check User
if (Create==Update)
{
//Start Process
var Output="ajax_"+Page+"?status=delete_one"+Value;
Req.open("GET", Output, true);
Req.onreadystatechange=function()
{
if (Req.readyState==4)
{
if (Req.status==200)
{
document.getElementById("Output_Main").innerHTML=Req.responseText;
}
}
}
Req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
Req.send(null);
//End Process
}
else
{
alert("ไม่สามารถลบได้ เนื่องจากคุณไม่ใช้ผู้สร้างรายการนี้");
return false
}
//End Chk User
}
}

function TS_ListDelA(Page, Value, Status)
{
TS_Sound.src=Sound_Click;
var TS_chkValue=0;
var TS_strValue="";
var TS_ChkBox=document.forms['List_Main'].elements['select_all[]'];
var TS_Counts=TS_ChkBox.length;
for(var i=0;i<TS_Counts;i++)
{
if (TS_ChkBox[i].checked!=false)
{
TS_chkValue+=1;
}
}
//Start Chk Status
if (Status=="admin")
{
//Start Chk Check
if(TS_chkValue==0)
{
alert("กรุณาลือกรายการที่ต้องการลบด้วย");
return false
}
else
{
for(var i=0;i<TS_Counts;i++)
{
if (TS_ChkBox[i].checked!=false)
{
TS_strValue+=TS_ChkBox[i].value+',';
}
}
//Start Process
var Output="ajax_"+Page+"?status=delete_all"+Value+"&del="+TS_strValue;
Req.open("GET", Output, true);
Req.onreadystatechange=function()
{
if (Req.readyState==4)
{
if (Req.status==200)
{
document.getElementById("Output_Main").innerHTML=Req.responseText;
}
}
}
Req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
Req.send(null);
//End Process
}
//End Chk Check
}
else
{
alert("จำกัดสิทธิ์ในการลบทั้งหมดเฉพาะ Administrator");
return false
}
//End Chk Status
}

function TS_ChkUpload(Input, Status)
{
var Pics_Value=document.getElementById(Input).value;
var TS_ChkCount="No";
switch (Status)
{
case "A" : var TS_ExtArr=new Array("bmp","gif","jpg","png"); break;
case "B" : var TS_ExtArr=new Array("bmp","gif","jpg","png","swf"); break;
case "C" : var TS_ExtArr=new Array("doc","flv","jpg","mp3","mp4","pdf","ppt","rar","swf","wmv","xls","zip"); break;
default : var TS_ExtArr=new Array("bmp","gif","jpg","png");
}
var Pics_Ext=Pics_Value.substring(Pics_Value.lastIndexOf('.')+1);
//Start Ckeck Browse
if (Pics_Ext!="")
{
var Pics_Lower=Pics_Ext.toLowerCase();
for (var i=0;i<TS_ExtArr.length;i++)
{
if (Pics_Lower==TS_ExtArr[i])
{
TS_ChkCount="Yes";
break;
}
}
//Start Process
if(TS_ChkCount!="No")
{
return true;
}
else
{
alert("ไฟล์ที่เลือกต้องเป็นนามสกุล "+TS_ExtArr+" เท่านั้น");
document.getElementById("Files_Output").innerHTML="<input type='file' id='pic_post' name='pic_post' class='ts_input_4' onchange=\"TS_ChkUpload('pic_post','"+Status+"');\">";
return false;
}
//End Process
}
else
{
alert('กรุณาเลือกไฟล์ที่ต้องการด้วย');
document.getElementById("Files_Output").innerHTML="<input type='file' id='pic_post' name='pic_post' class='ts_input_4' onchange=\"TS_ChkUpload('pic_post','"+Status+"');\">";
return false;
}
//End Ckeck Browse
}

function TS_ChkBefore(Input, Status)
{
var Pics_Value=document.getElementById(Input).value;
var TS_ChkCount="No";
switch (Status)
{
case "A" : var TS_ExtArr=new Array("bmp","jpeg","jpg"); break;
default : var TS_ExtArr=new Array("bmp","gif","jpg","png");
}
var Pics_Ext=Pics_Value.substring(Pics_Value.lastIndexOf('.')+1);
//Start Ckeck Browse
if (Pics_Ext!="")
{
var Pics_Lower=Pics_Ext.toLowerCase();
for (var i=0;i<TS_ExtArr.length;i++)
{
if (Pics_Lower==TS_ExtArr[i])
{
TS_ChkCount="Yes";
break;
}
}
//Start Process
if(TS_ChkCount!="No")
{
return true;
}
else
{
alert("ไฟล์ที่เลือกต้องเป็นนามสกุล "+TS_ExtArr+" เท่านั้น");
document.getElementById("BeforeOutput").innerHTML="<input type='file' id='pics_before' name='pics_before' class='ts_input_3' onchange=\"TS_ChkBefore('pics_before','"+Status+"');\">";
return false;
}
//End Process
}
else
{
alert('กรุณาเลือกไฟล์ที่ต้องการด้วย');
document.getElementById("BeforeOutput").innerHTML="<input type='file' id='pics_before' name='pics_before' class='ts_input_3' onchange=\"TS_ChkBefore('pics_before','"+Status+"');\">";
return false;
}
//End Ckeck Browse
}

function TS_ChkAfter(Input, Status)
{
var Pics_Value=document.getElementById(Input).value;
var TS_ChkCount="No";
switch (Status)
{
case "A" : var TS_ExtArr=new Array("bmp","jpeg","jpg"); break;
default : var TS_ExtArr=new Array("bmp","gif","jpg","png");
}
var Pics_Ext=Pics_Value.substring(Pics_Value.lastIndexOf('.')+1);
//Start Ckeck Browse
if (Pics_Ext!="")
{
var Pics_Lower=Pics_Ext.toLowerCase();
for (var i=0;i<TS_ExtArr.length;i++)
{
if (Pics_Lower==TS_ExtArr[i])
{
TS_ChkCount="Yes";
break;
}
}
//Start Process
if(TS_ChkCount!="No")
{
return true;
}
else
{
alert("ไฟล์ที่เลือกต้องเป็นนามสกุล "+TS_ExtArr+" เท่านั้น");
document.getElementById("AfterOutput").innerHTML="<input type='file' id='pics_after' name='pics_after' class='ts_input_3' onchange=\"TS_ChkAfter('pics_after','"+Status+"');\">";
return false;
}
//End Process
}
else
{
alert('กรุณาเลือกไฟล์ที่ต้องการด้วย');
document.getElementById("AfterOutput").innerHTML="<input type='file' id='pics_after' name='pics_after' class='ts_input_3' onchange=\"TS_ChkAfter('pics_after','"+Status+"');\">";
return false;
}
//End Ckeck Browse
}

function TS_ChkStyle(Input, Status)
{
var Pics_Value=document.getElementById(Input).value;
var TS_ChkCount="No";
switch (Status)
{
case "A" : var TS_ExtArr=new Array("bmp","jpeg","jpg"); break;
default : var TS_ExtArr=new Array("bmp","gif","jpg","png");
}
var Pics_Ext=Pics_Value.substring(Pics_Value.lastIndexOf('.')+1);
//Start Ckeck Browse
if (Pics_Ext!="")
{
var Pics_Lower=Pics_Ext.toLowerCase();
for (var i=0;i<TS_ExtArr.length;i++)
{
if (Pics_Lower==TS_ExtArr[i])
{
TS_ChkCount="Yes";
break;
}
}
//Start Process
if(TS_ChkCount!="No")
{
return true;
}
else
{
alert("ไฟล์ที่เลือกต้องเป็นนามสกุล "+TS_ExtArr+" เท่านั้น");
document.getElementById("StyleOutput").innerHTML="<input type='file' id='pics_style' name='pics_style' class='ts_input_3' onchange=\"TS_ChkStyle('pics_style','"+Status+"');\">";
return false;
}
//End Process
}
else
{
alert('กรุณาเลือกไฟล์ที่ต้องการด้วย');
document.getElementById("StyleOutput").innerHTML="<input type='file' id='pics_style' name='pics_style' class='ts_input_3' onchange=\"TS_ChkStyle('pics_style','"+Status+"');\">";
return false;
}
//End Ckeck Browse
}

function TS_ShowImg(obj,msg)
{
TS_Sound.src=Sound_Click;
if(TS_ImgBox.style.display!="block")
{
TS_ImgBox.style.top=obj.offsetTop;
TS_ImgBox.style.left=obj.offsetLeft+obj.offsetWidth+5;
TS_Content.innerHTML="<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td align='center'><img src='"+msg+"' width='100' border='1' bordercolor='#000000' alt='"+msg+"'></td></tr></table>";
TS_ImgBox.style.display="block";
}
else
{
TS_ImgBox.style.display="none";
}
}

function TS_GetPlayer()
{
var Check_Play=document.getElementById("Player_Value").value;
if (Check_Play=="1")
{
Category="0";
}
else
{
Category="1";
}
Req.open("GET", "ajax_player.php?status="+Category, true);
Req.onreadystatechange=Response_Player;
Req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
Req.send(null);
}

function Response_Player()
{
if (Req.readyState==4)
{
if (Req.status==200)
{
document.getElementById("Music_Output").innerHTML=Req.responseText;
if (Category=="0")
{
document.getElementById("TS_Play").src="images/icon_play_y.gif";
document.getElementById("TS_Play").alt="Click to Play";
document.getElementById("Player_Value").value="0";
document.getElementById("TS_Player").stop();
}
if (Category=="1")
{
document.getElementById("TS_Play").src="images/icon_play_n.gif";
document.getElementById("TS_Play").alt="Click to Stop";
document.getElementById("Player_Value").value="1";
document.getElementById("TS_Player").play();
}
}
}
}

function TS_SelectAll(Value)
{
if(!document.forms['List_Main'])
{
return;
}
var TS_ChkBox=document.forms['List_Main'].elements['select_all[]'];
if(!TS_ChkBox)
{
return;
}
var TS_Counts=TS_ChkBox.length;
if(!TS_Counts)
{
TS_ChkBox.checked=Value;
}
else
{
for(var i=0;i<TS_Counts;i++)
{
TS_ChkBox[i].checked=Value;
}
}
}

function TS_BannerOver(Value)
{
TS_Sound.src=Sound_Over;
document.getElementById(Value).className='ts_shine';
TS_Highlighting=setInterval("TS_GradFade("+Value+")",50)
}

function TS_BannerOut(Value)
{
document.getElementById(Value).className='ts_img';
}

function TS_GradFade(Value)
{
Value.filters.alpha.opacity+=5;
}