aki=new Object();
aki.getid=function(xid){return document.getElementById(xid);}
aki.href=function(xurl){return document.location=xurl;};
aki.popup=function() {newwindow=window.open('livechat.php','livechat','height=535,width=518');}

function clickAjax(xid)
{
		var xmlhttp;
		if(window.XMLHttpRequest)
		{xmlhttp=new XMLHttpRequest();}
		else
		{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}

		xmlhttp.onreadystatechange=function()
		{
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
					if(xmlhttp.responseText=="double")
					{alert('คุณเป็นผู้ประมูลล่าสุด ในขณะนี้');}
					if(xmlhttp.responseText=="nobids")
					{alert('คุณมี bids ไม่พอ ค่ะ');}
				}
		}
xmlhttp.open("GET","clickbids.php?id="+xid+"&rand="+Math.random(),true);
xmlhttp.send();
}

function clickJoin(xid)
{
		var xmlhttp;
		if(window.XMLHttpRequest)
		{xmlhttp=new XMLHttpRequest();}
		else
		{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}

		xmlhttp.onreadystatechange=function()
		{
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
					if(xmlhttp.responseText=="no join")
					{alert('คุณยังไม่ได้เข้าร่วมการประมูล!');}
					if(xmlhttp.responseText=="double")
					{alert('คุณเป็นผู้ประมูลล่าสุด ในขณะนี้');}
					if(xmlhttp.responseText=="no click")
					{alert('คุณมี click ไม่พอ ค่ะ');}
				}
		}
xmlhttp.open("GET","clickbids_join.php?id="+xid+"&rand="+Math.random(),true);
xmlhttp.send();
}

function timer(time)
{
		if(time>0) 
		{
				day=Math.floor(time/((60*60)*24));
				hrs=Math.floor((time/(60*60))-(day*24));
				min=Math.floor(((time/(60*60)-hrs)-(day*24))*60);
				sec=Math.round(((((time/(60*60)-hrs)-(day*24))*60)-min)*60);

				if(sec==60) 
				{sec=0;}
				if(hrs.toString().length==1)
				{hrs="0"+hrs;}
				if(min.toString().length==1)
				{min="0"+min;}
				if(sec.toString().length==1)
				{sec="0"+sec;}
		}
		else
		{
				day="00";
				hrs="00";
				min="00";
				sec="00";
		 }
		if(day>0)
		{days=day+"DAYS";}
		else
		{days="";}

		if((day+":"+hrs+":"+min+":"+sec)!="00:00:00:00")
		{
				if(time>20)
				{display=days+" "+hrs+":"+min+":"+sec;}
				else
				{display="<font color='#FF0000'>"+days+" "+hrs+":"+min+":"+sec+"</font>";}
		}
		else
		{display="สินค้าปิดประมูล!";}
		return display;
}

function loadAjax(xid)
{
		var xmlhttp;
		if(window.XMLHttpRequest)
		{xmlhttp=new XMLHttpRequest();}
		else
		{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}

		xmlhttp.onreadystatechange=function()
		{
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
						arr=xmlhttp.responseText.split("|");
						for(i=0;i<arr.length-1;i++)
						{
								ex=arr[i].split(",");
								if(aki.getid("timer_"+ex[0]))
								{
										aki.getid("timer_"+ex[0]).innerHTML=timer(ex[1]);
										aki.getid("cost_"+ex[0]).innerHTML="฿"+ex[2];
											if(!ex[3])
											{ex[3]="ยังไม่มีผู้ประมูล";}
											aki.getid("user_"+ex[0]).innerHTML=ex[3];
											aki.getid("bid").innerHTML=ex[5];
												//########## join auction ######//
												if(!ex[7])
												{aki.getid("mclick_"+ex[0]).innerHTML=ex[6];}
												//#########################//

													// ############ for view page########//
													if(ex[7])
													{
														aki.getid("cost2_"+ex[0]).innerHTML="฿ "+ex[2];

														if(ex[4]<0){ex[4]=0;}	
														aki.getid("total_"+ex[0]).innerHTML="฿ "+ex[4];

																if(ex[0]==ex[7])
																{
																		if(!aki.getid("xcount").innerHTML)
																		{aki.getid("xcount").innerHTML=ex[2];}

																		if(ex[2]!=aki.getid("xcount").innerHTML)
																		{	aki.getid("show_update_"+ex[0]).style.color="#FF0000";
																			aki.getid("xcount").innerHTML=ex[2];}
																		else
																		{	aki.getid("show_update_"+ex[0]).style.color="#FFFFFF";}

																		if(ex[9])
																		{
																				aki.getid("usebids_"+ex[0]).innerHTML=ex[9];
																		}
																}
																	if(!ex[8])
																	{ex[8]=0;}
																	aki.getid("bids_"+ex[0]).innerHTML="คุณใช้สิทธิ์ประมูลทั้งสิ้น : "+ex[8];
																	aki.getid("money_"+ex[0]).innerHTML="฿ "+(ex[8]*6.5);
																	if(ex[10])
																	{aki.getid("jclick_"+ex[0]).innerHTML=ex[10];}
													}
													// ############ for view page########//
								}
						}
				}
		}
xmlhttp.open("GET","process.php?id="+xid+"&rand="+Math.random(),true);
xmlhttp.send();
}

function refresh_capcha()
{
		var xmlhttp;
		if(window.XMLHttpRequest)
		{xmlhttp=new XMLHttpRequest();}
		else
		{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}

		xmlhttp.onreadystatechange=function()
		{
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
						aki.getid("capcha").innerHTML=xmlhttp.responseText;
				}
		}
xmlhttp.open("GET","capcha_page.php?rand="+Math.random(),true);
xmlhttp.send();
}

function bidslist(xid)
{
		var xmlhttp;
		if(window.XMLHttpRequest)
		{xmlhttp=new XMLHttpRequest();}
		else
		{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}

		xmlhttp.onreadystatechange=function()
		{
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
						aki.getid("bidslist").innerHTML=xmlhttp.responseText;
				}
		}
xmlhttp.open("GET","v_bidslist.php?id="+xid+"&rand="+Math.random(),true);
xmlhttp.send();
}

function shoutbox(txt)
{
		var xmlhttp;
		if(window.XMLHttpRequest)
		{xmlhttp=new XMLHttpRequest();}
		else
		{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}

		xmlhttp.onreadystatechange=function()
		{
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
						aki.getid("shoutbox").innerHTML=xmlhttp.responseText;
				}
		}
		xmlhttp.open("GET","v_shoutbox.php?rand="+Math.random(),true);	
xmlhttp.send();
}

function shoutboxSend(txt)
{
	if(!txt)
	{alert('กรุณากรอกข้อมูลก่อนส่ง');}
	else
	{
		var xmlhttp;
		if(window.XMLHttpRequest)
		{xmlhttp=new XMLHttpRequest();}
		else
		{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}

		xmlhttp.onreadystatechange=function()
		{
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
						aki.getid("shoutbox").innerHTML=xmlhttp.responseText;
				}
		}
		xmlhttp.open("GET","s_shoutbox.php?text="+encodeURIComponent(txt)+"&rand="+Math.random(),true);
	xmlhttp.send();
	}
}
