function test()
{
	alert("TEST");
}

function goto1(url,param,div)
{
	postDataReturnTextNoLoad(url, param+ "&r=" + new Date().getTime(), 
	function (text)
	{
		$(div).innerHTML=text;
	});    
}

function goto2(url,param,div1,div2)
{
	postDataReturnTextPic(url, param+ "&r=" + new Date().getTime(),div1,path+"images/repeat.gif",
	function (text)
	{
		$(div2).innerHTML=text;
	});
}

function gotoURL(url,param,div)
{
	postDataReturnText(url, param+ "&r=" + new Date().getTime(),div, 
	function (text)
	{
		$(div).innerHTML=text;
	});    
}

function gotoURL2(url,param,div)
{
	postDataReturnTextPic(url, param+ "&r=" + new Date().getTime(),div,path+"images/loading2.gif",
	function (text)
	{
		$(div).innerHTML=text;
	});
}

function gotoURL3(url,param,div)
{
	postDataReturnTextPic(url, param+ "&r=" + new Date().getTime(),div,path+"images/loading3.gif",
	function (text)
	{
		$(div).innerHTML=text;
	});
}


function wait(msecs)
{
	var start = new Date().getTime();
	var cur = start
	while(cur - start < msecs)
	{
		cur = new Date().getTime();
	}	
}


//-------------------- USER LOGIN -----------------------------
function login()
{
	if($("user").value=='Username')
	{
		alert("กรุณาใส่ Username");
		$("user").focus();
		return false;
	}
	else if($("pass").value=='Password')
	{
		alert("กรุณาใส่ Password");
		$("pass").focus();
		return false;
	}
	else
	{
		var url=path+"chkLogin.php";
		var param="user="+$("user").value;
		param+="&pass="+$("pass").value;
		param+="&longTime="+$("longTime").value;
	
		postDataReturnTextNoLoad(url, param+ "&r=" + new Date().getTime(),
		function (text)
		{
			if(text=='error')
			{
				//gotoURL("loginForm.php","","login");
				alert("Username หรือ Password ของคุณไม่ถูกต้อง");
				return false;
			}
			else if(text=='ok')
			{
//				window.opener.location.reload();
				location.reload();
				//window.close();
				//gotoURL("showLoginBox.php","","login");
			}
			else if(text=='ban')
				alert("Username ของคุณถูกระงับการให้บริการ");
		});
	}
}
function logout()
{
	if(confirm("คุณแน่ใจหรือไม่ว่าจะต้องการออกจากระบบ"))
	{
		var url=path+"logout.php";
		var param="code=4hagas9g8sasdf";
		postDataReturnTextNoLoad(url, param+ "&r=" + new Date().getTime(),
		function (text)
		{
			if(text=='ok')
			{
				window.location.reload();
			}
		});
	}
}
function getQuestionForgotPass()
{
	if($("user").value=='Username')
		alert("กรุณาใส่ Username");
	else
	{
		var url=path+"forgotPass.php";
		var param="action=question";
		param+="&user="+$("user").value;

		postDataReturnTextNoLoad(url, param+ "&r=" + new Date().getTime(),
		function (text)
		{
			if(text.substring(0,5)=='error')
				alert(text.substring(5));
			else
				$("question").innerHTML=text;
		});
	}
}
function sendAnsForgotPass()
{
	if($("ans").value=='')
		alert("กรุณาใส่คำตอบ");
	else
	{
		var url=path+"forgotPass.php";
		var param="action=answer";
		param+="&user="+$("username").value;
		param+="&ans="+$("ans").value;

		postDataReturnTextNoLoad(url, param+ "&r=" + new Date().getTime(),
		function (text)
		{
			if(text.length<1500)
				$("question").innerHTML=text;
			else
			{
				$("question").innerHTML=text;
				alert("คำตอบไม่ถูกต้อง");
			}
		});
	}
}

function saveNewPass()
{
	if($("newpass").value.length<6)
	{
		alert("กรุณาใส่รหัสผ่านอย่างน้อย 6 ตัวอักษร");
		$("newpass").focus();
	}
	else if($("newpass").value.length==0)
	{
		alert("กรุณาใส่รหัสผ่าน");
		$("newpass").focus();
	}
	else if($("newpass").value!=$("renewpass").value)
	{
		alert("กรุณาใส่รหัสผ่านให้ตรงกัน");
		$("renewpass").focus();
	}
	else if($("newpass").value.length>=6)
	{
		var url=path+"saveNewPass.php";
		var param="user="+$("username").value;
		param+="&pass="+$("newpass").value;
		param+="&ans="+$("ans").value;

		postDataReturnTextNoLoad(url, param+ "&r=" + new Date().getTime(),
		function (text)
		{
			if(text=='ok')
			{
				window.location=path+"formLogin.php";
				alert("รหัสผ่านได้ถูกบันทึกเรียบร้อยแล้ว");
			}
			else
				alert("ERROR");
		});
	}
}

//-------------------- GENERAL -----------------------------
function divToBigH(div,height,step,time)
{
	var h=$(div).style.height;
	h=h.substring(0,h.length-2);

	if(h<height)
	{
		$(div).style.height=parseInt(h)+step+'px';
		setTimeout("divToBigH('"+div+"',"+height+","+step+","+time+")",time);
	}
}

function divToSmallH(div,height,step,time)
{
	var h=$(div).style.height;
	h=h.substring(0,h.length-2);
	if(h>height)
	{
		$(div).style.height=parseInt(h)-step+'px';
		setTimeout("divToSmallH('"+div+"',"+height+","+step+","+time+")",time);
	}
}

function changeSpam()
{
	var url=path+"include/blockSpam.php";
	var param="r="+new Date().getTime();
		
	postDataReturnTextPic(url, param,"imgSpam",path+"images/loading2.gif",
	function (text)
	{
		$("imgSpam").innerHTML=text;
		chkSpam("spam");
	});
}

function chkSpam(x)
{
	var url=path+"include/chkCodeSpam.php";
	var param="spam="+$("spam").value;
	param+="&codeSpam="+$("codeSpam").value;

	if($(x).value.length>0)
		toUpper(x);

	if($(x).value.length<6)
		$("spamBox").innerHTML="<img src="+path+"images/f.gif width=15>";
	else if($(x).value!='')
	{
		postDataReturnTextPic(url, param+"&r="+new Date().getTime(),"spamBox",path+"images/loading3.gif",
		function (text)
		{
			if(text=='ok')
				$("spamBox").innerHTML="<img src="+path+"images/t.gif width=15>";
			else
				$("spamBox").innerHTML="<img src="+path+"images/f.gif width=15>";
		});
	}
}
//======================  GENERAL FUNCTION  ===================================

function cvForPostData(x)
{
	x=x.replace(/\+/,";;plus;;	");
	x=x.replace(/&/g,";;amp;;");
	return x;
}
//====================  END GENERAL FUNCTION  =================================

