// JavaScript Document

var EsAJaxhttp = false;
function EsAJax(url) {
	  var today=new Date();
	  var getdate=today.getTime();
	  url=String(url)+String(String(url).indexOf('?')>0 ? "&" : "?")+'ranid='+ String(Math.ceil(Math.random()*getdate));
	  var result;
	  if (!EsAJaxhttp) {
		  if (window.XMLHttpRequest) 
		      EsAJaxhttp = new XMLHttpRequest();
		 else if (window.ActiveXObject)
		     EsAJaxhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  EsAJaxhttp.open("GET", url, false);
	  EsAJaxhttp.send(null);
	  while (EsAJaxhttp.readyState != 4);
	  result = EsAJaxhttp.responseText;
	  return(result);
}

function AjaxHTTP(){
		try{return new ActiveXObject( "Msxml2.XMLHTTP" );}
		catch ( e ){};
		try{return new ActiveXObject( "Microsoft.XMLHTTP" );}
		catch ( e ){};
		try{return new XMLHttpRequest();}
		catch ( e ){};
		alert( "XMLHttpRequest not supported" );
		return null;
	}

	function AjaxRequest(method,url,ByID){
		var Req = AjaxHTTP();
		Req.onreadystatechange = function() {
			if(Req.readyState == 4){
				var Obj = document.getElementById(ByID);
				Obj.innerHTML = Req.responseText;
			}else{
				var Obj =	 document.getElementById(ByID);
				Obj.innerHTML = '<div style="text-align:center;"><img src="../images/loading.gif"></div>';
			}
		}		
		Str =	 Math.random();
		Req.open(""+method, url, true);
		Req.send(null);	
	}
	
	
	function ltrim(str)
	{
	   var whitespace = new String(" \t\n\r");
	   var s = new String(str);
	   if (whitespace.indexOf(s.charAt(0)) != -1) {
		  var j=0, i = s.length;
		  while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
			 j++;
		  s = s.substring(j, i);
	   }
	   return s;
	   
	}
	
	//RTrim(string) : Returns a copy of a string without trailing spaces.
	function rtrim(str)
	{
	   var whitespace = new String(" \t\n\r");
	   var s = new String(str);
	   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
		  var i = s.length - 1;       // Get length of string
		  while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
			 i--;
		  s = s.substring(0, i+1);
	   }
	   return s;
	}
	
	// Trim(string) : Returns a copy of a string without leading or trailing spaces
	function trim(str) {
	   return rtrim(ltrim(str));
	}
	
	function CheckformatMail(e) {
			ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
			for(i=0; i < e.length ;i++){
					if(ok.indexOf(e.charAt(i))<0){
							return (false);
					}
			}
			if (document.images) {
					re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
					re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
					if (!e.match(re) && e.match(re_two)) {
							return (-1);
					}
			}
	}
	
	function addCommas(nStr)
	{
		nStr += '';
		x = nStr.split('.');
		x1 = x[0];
		x2 = x.length > 1 ? '.' + x[1] : '';
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(x1)) {
			x1 = x1.replace(rgx, '$1' + ',' + '$2');
		}
		return x1 + x2;
	}
	//addCommas(1000)1,000


	function addSeparatorsNF(nStr, inD, outD, sep)
	{
		nStr += '';
		var dpos = nStr.indexOf(inD);
		var nStrEnd = '';
		if (dpos != -1) {
			nStrEnd = outD + nStr.substring(dpos + 1, nStr.length);
			nStr = nStr.substring(0, dpos);
		}
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(nStr)) {
			nStr = nStr.replace(rgx, '$1' + sep + '$2');
		}
		return nStr + nStrEnd;
	}
	//addSeparatorsNF(43211234.56, '.', '.', ',')43,211,234.56


	function ChkNumber() {
		e_k=event.keyCode;
		if ((e_k < 48) || (e_k > 57)){
			event.returnValue = false;
			return false;
		}
	} 
	
	function Chk_Char() {
		e_k=event.keyCode;
		if (e_k < 65){
			event.returnValue = false;
			return false;
		}else{
			if(e_k > 90 && e_k < 98){
				event.returnValue = false;
				return false;			
			}else if(e_k > 122){
				if(e_k < 3585 || e_k > 3660){
					event.returnValue = false;
					return false;
				}
			}
		}
	} 
	
	var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	function autoTab(input,len, e) {
		var keyCode = (isNN) ? e.which : e.keyCode; 
		var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
		if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}
	function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length)
		if(arr[index] == ele)
		found = true;
		else
		index++;
		return found;
	}
	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
		if (input.form[i] == input)index = i;
		else i++;
		return index;
		}
		return true;
	}
	function DialogModeless(url,Width,Height){
		return showModelessDialog(url,window,"status:false;dialogWidth:"+Width+"px;dialogHeight:"+Height+"px");
	}
	function DialogModel(url,Width,Height){
		return showModalDialog(url,window,"status:false;dialogWidth:"+Width+"px;dialogHeight:"+Height+"px");
	}
	
	// Check Pinid
	function ChkPinId(id){
		if(id.length != 13) return false;
		for(i=0, sum=0; i < 12; i++)
			sum += parseFloat(id.charAt(i))*(13-i);
		if((11-sum%11)%10!=parseFloat(id.charAt(12))) return false;
		return true;
	}
	
	function MouseOverLan(element,obj)
	{ 
			element.style.backgroundColor = '#09F';//F2F9FF 6c8c63
			//document.getElementById(obj).className = 'Dov';
			document.getElementById(obj).style.zIndex = 1000000;
			document.getElementById(obj).border=2;
			document.getElementById(obj).style.borderColor = '#fff'
			document.getElementById('QM_'+obj).style.color = '#fff';
			if(obj=='member'){
				document.getElementById('m_ber').style.zIndex = 1000000;
				document.getElementById('m_ber').border=2;
				document.getElementById('m_ber').style.borderColor = '#fff'
			}
	}
	function MouseOutLan(element,obj)
	{
			element.style.backgroundColor = '';
			//document.getElementById(obj).className = 'Dot';
			document.getElementById(obj).style.zIndex = 1000;
			document.getElementById(obj).border=0;
			document.getElementById('QM_'+obj).style.color = '#409dbc';
			if(obj=='member'){
				document.getElementById('m_ber').style.zIndex = 1000;
				document.getElementById('m_ber').border=0;
			}
	}
	function MouseOverLan2(element,obj)
	{ 
			element.style.backgroundColor = '#09F';//F2F9FF 6c8c63
			document.getElementById('QM_'+obj).style.color = '#fff';
	}
	function MouseOutLan2(element,obj)
	{
			element.style.backgroundColor = '';
			document.getElementById('QM_'+obj).style.color = '#409dbc';
	}
function PlaySound()
{
	document.all.sound.src = '../media/Jungle_B-popovich-2628_hifi.mp3';
	document.getElementById('pays').innerHTML = '<label onClick="StopSound()">Sound Off</label>';
}
function StopSound()
{
	document.all.sound.src = '';
	document.getElementById('pays').innerHTML = '<label onClick="PlaySound()">Sound On</label>';
}


function login(){
	user = trim(document.getElementById('userlogin').value);
	pass = trim(document.getElementById('passlogin').value);
	if(user==''){
		document.getElementById('userlogin').focus();
		return false;
	}
	if(pass==''){
		document.getElementById('passlogin').focus();
		return false;
	}
	var urllogin = 'checklogin.php?userlogin='+user+'&pass='+pass;
	result = EsAJax(urllogin);
	if(result!=0){
		window.location = 'member.php?member_id='+result;
	}else{
		alert('กรุณา login ใหม่อีกครั้ง เนื่องจากไม่พบผู้ใช้ชื่อนี้');	
	}
	return false;
}
function login2(){
	user = trim(document.getElementById('userlogin').value);
	pass = trim(document.getElementById('passlogin').value);
	if(user==''){
		document.getElementById('userlogin').focus();
		return false;
	}
	if(pass==''){
		document.getElementById('passlogin').focus();
		return false;
	}
	var urllogin = 'member/checklogin.php?userlogin='+user+'&pass='+pass;
	result = EsAJax(urllogin);
	if(result!=0){
		window.location = 'index.php';
	}else{
		alert('กรุณา login ใหม่อีกครั้ง เนื่องจากไม่พบผู้ใช้ชื่อนี้');	
	}
	return false;
}
function login3(){
	user = trim(document.getElementById('userlogin').value);
	pass = trim(document.getElementById('passlogin').value);
	if(user==''){
		document.getElementById('userlogin').focus();
		return false;
	}
	if(pass==''){
		document.getElementById('passlogin').focus();
		return false;
	}
	var urllogin = 'checklogin.php?userlogin='+user+'&pass='+pass;
	result = EsAJax(urllogin);
	if(result!=0){
		window.location.reload(true);
	}else{
		alert('กรุณา login ใหม่อีกครั้ง เนื่องจากไม่พบผู้ใช้ชื่อนี้');	
	}
	return false;
}

function Updatetimelogin(){
	var page = '../js/updatetimelogin.php';
	result = EsAJax(page);
	if(result!=0){
		setTimeout("Updatetimelogin()",600000);
	}
}

Updatetimelogin();







