/* --- Login part --- */
function showLogin()
{
	$('#loginslide').css("display","")
	.animate({"top": 0 + "px"}, 1250);		
}

function hideLogin()
{
	$('#loginslide').animate({"top": -320 + "px"}, 1250);
	
	document.getElementById("strUser").value="";
	document.getElementById("strSword").value="";
}

// JavaScript Document
function checkEnter(e)
{ //e is event object passed from function invocation
//	var characterCode literal character code will be stored in this variable
	if(e && e.which)
	{ //if which property of event object is supported (NN4)
		e=e;
		characterCode = e.which //character code is contained in NN4's which property
	}
	else
	{
		characterCode = event.keyCode //character code is contained in IE's keyCode property
	}
	
	if(characterCode == 13)
	{ //if generated character code is equal to ascii 13 (if enter key)
		if(navigator.appName=="Microsoft Internet Explorer")
		{
			checkPartnerLoginIE();
		}
		else
		{
			checkPartnerLogin();
		}
		return false;
	}
	else
	{
		return true;
	}
}

function checkPartnerLoginIE()
{
	var param="";
	var un=document.getElementById("strUser").value;
	var pwd=document.getElementById("strSword").value;
	
	var newun="";
	var newpwd="";
		
	if(checkDataEntry(un)==0)
	{
		alert('Please enter your username');
		return false;
	}
	else
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<un.length; i++)
		{
			mycode = un.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=un.substr(i,1);
			}
			newun=newun+myChar;
		}
		param="?un="+newun;
	}
	
	if(checkDataEntry(pwd)==0)
	{
		alert('Please enter your password');
		return false;
	}
	else
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<pwd.length; i++)
		{
			mycode = pwd.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=pwd.substr(i,1);
			}
			newpwd=newpwd+myChar;
		}
		param=param+"&pwd="+newpwd;
	}
	
	// AJAX stuff	
	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	doc.open("GET","process_partner_login.php"+param, true);
	doc.send(null);
		
	function handleStateChange()
	{        
		if (doc.readyState == 4)
		{
			if(doc.responseText=="error")
			{
				alert('Sorry - unable to verify your details, please try again');
			}
			else
			{
				hideLogin();
				document.location.href="dashboard.php"
			}
		}
	}	
}

function notYet()
{
	jAlert("Sorry this item is not available yet",'BKK Town Message');
}

function clearGenBrowseFileBox(obj)
{
	document.getElementById(obj).value="";
}

function changeImageBorderColour(obj,clsname)
{
	obj.className=clsname;
}

function hideArea(nm)
{
	document.getElementById(nm).style.display="none";
}

function ignoreIt(obj)
{
	obj.blur();
}

function mypopup(num)
{
	var thewidth=screen.availWidth/2;
	var screenwidth=1000;
	
	var screenheight=screen.availHeight;
	
	mywindow = window.open("displaybox.php?num="+num+"&win_height="+(screenheight-200),"mywindow","locationbar=0,status=0,scrollbars=1,titlebar=0,width=" + screenwidth + ",height=" + screenheight + ",left=" + (thewidth-500));
}

function closeIt()
{
	window.parent.close();
}

function printIt(oTgt)
{
	oTgt.focus();
	oTgt.print();
}

function numericOnly(obj,msg)
{
	var iNext=0;
	var iChar="";
	var iFirstDot="";
	var newStr="";
	var iDot=0;
	if(isNaN(obj.value))
	  {
		alert("The "+msg+" can only be numbers");
		
		while(iNext<=obj.value.length)
		{
			iChar=obj.value.substr(iNext,1)
			if((iDot==1) && (iChar=="."))
			{
				iFirstDot=iChar;
				iChar="";
			}
			else
			{
				if(isNaN(iChar))
				{
					if(iChar!=".")
					{
						iChar="";
					}
				}
			}
			newStr=newStr+iChar;
			iNext=iNext+1;
			
			if(iDot==0)
			{
				if(iChar==".")
				{
					iDot=1;
				}
			}
		}
		obj.value=newStr;
		obj.focus();
	  }
}

function setZero(opt)
{
	if(opt.value=="")
	{
		opt.value=0;
	}
}

function setBlank(opt)
{
	if(opt.value=="0")
	{
		opt.value="";
	}
}

function checkDataEntry(obj)
{
	var mycode
	var count=0;
	if(obj.length!=0)
	{
		for(i=0; i<obj.length; i++)
		{
			mycode = obj.charCodeAt(i);
			if((mycode>47 && mycode<58) || (mycode>64 && mycode<91) || (mycode>96 && mycode<123) || (mycode>3584 && mycode<3631) || (mycode>3647 && mycode<3653))
			{
				count=count+1;
			}
		}
	}
	return count;
}

function checkEmailValid(emailStr,msg)
{
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var errMsg="";   
	var matchArray=emailStr.match(emailPat)

	if (matchArray==null) 
	{
	   errMsg=errMsg+msg+" email address seems incorrect";
	   return errMsg;
	}
	else
	{
	  var user=matchArray[1]
	  var domain=matchArray[2]
	  if (user.match(userPat)==null) 
	  {


		errMsg=errMsg+msg+" email address seems incorrect";
		return errMsg;       
	  }
	  var IPArray=domain.match(ipDomainPat)
	  if (IPArray!=null) 
	  {
		  for (var i=1;i<=4;i++) 
			  {
			if (IPArray[i]>255) 
				{
				errMsg=errMsg+msg+" email address seems incorrect";
				return errMsg;
				}//IF
			  }//for
	   }//IP Array
	   var domainArray=domain.match(domainPat)
	   if (domainArray==null) 
	   {
		 errMsg=errMsg+msg+" email address seems incorrect";
		 return errMsg;
	   }
	   var atomPat=new RegExp(atom,"g")
	   var domArr=domain.match(atomPat)
	   var len=domArr.length
	   if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>4) 
	   {
		 errMsg=errMsg+msg+" email address seems incorrect";
		 return errMsg;	
	   } 
	   if (len<2) 
	   {
		 errMsg=errMsg+msg+" email address seems incorrect";
		 return errMsg;	 
	   } 
	 }//End  Match
	return "0";
}

function checkPartnerLogin()
{
	var param="";
	var un=document.getElementById("strUser").value;
	var pwd=document.getElementById("strSword").value;
	
	var newun="";
	var newpwd="";
		
	if(checkDataEntry(un)==0)
	{
		jAlert('Please enter your username','BKK Town Message');
		return false;
	}
	else
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<un.length; i++)
		{
			mycode = un.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=un.substr(i,1);
			}
			newun=newun+myChar;
		}
		param="?un="+newun;
	}
	
	if(checkDataEntry(pwd)==0)
	{
		jAlert('Please enter your password', 'BKK Town Message');
		return false;
	}
	else
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<pwd.length; i++)
		{
			mycode = pwd.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=pwd.substr(i,1);
			}
			newpwd=newpwd+myChar;
		}
		param=param+"&pwd="+newpwd;
	}
	
	// AJAX stuff	
	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	doc.open("GET","process_partner_login.php"+param, true);
	doc.send(null);
		
	function handleStateChange()
	{        
		if (doc.readyState == 4)
		{
			if(doc.responseText=="error")
			{
				jAlert('Sorry - unable to verify your details, please try again', 'BKK Town Message');
			}
			else
			{
				hideLogin();
				document.location.href="dashboard.php"
			}
		}
	}	
}

function fetchEstablishmentList(obj)
{
	document.getElementById("fulllistcontainer").innerHTML="<br /><img src='images/lightgrayindicator24.gif' width='24' height='24' style='margin-right:5px;' /><span class='graytext'><i>loading</i></span>";

	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "fetch_business_full_list.php?sby="+obj.value, true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			var pos=doc.responseText.indexOf("signin.php");
			if(pos==-1)
			{
				document.getElementById("fulllistcontainer").innerHTML=doc.responseText;
			}
			else
			{
				//do this if system times out
				jAlert("The system has timed out",'BKK Town Message');
				document.location.href="signin.php";
			}
		}
	}
}

function checkFeedback()
{
	var param="";
	var cn=document.getElementById("strContactName").value;
	var e=document.getElementById("strEmail").value;
	var cm=document.getElementById("strComment").value;
	
	var newcn="";
	var newe="";
	var newcm="";
		
	if(checkDataEntry(cn)==0)
	{
		jAlert('Please enter your name','BKK Town Message');
		return false;
	}
	else
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<cn.length; i++)
		{
			mycode = cn.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=cn.substr(i,1);
			}
			newcn=newcn+myChar;
		}
		param="?cn="+newcn;
	}
	
	if(checkDataEntry(e)==0)
	{
		jAlert('Please enter your email address', 'BKK Town Message');
		return false;
	}
	else
	{
		if(checkEmailValid(e)!="0") 
		{
			jAlert(checkEmailValid(e,'Your'), 'BKK Town Message');
			return false;
		}
		else
		{
			var i=0;
			var mycode=0;
			var myChar;
	
			for(i=0; i<e.length; i++)
			{
				mycode = e.charCodeAt(i);
				if(mycode==38)
				{
					myChar="(amp)";
				}
				else if(mycode==35)
				{
					myChar="(hash)";
				}
				else if(mycode==37)
				{
					myChar="(percentage)";
				}
				else if(mycode==43)
				{
					myChar="(plus)";
				}
				else
				{
					myChar=e.substr(i,1);
				}
				newe=newe+myChar;
			}
			param=param+"&e="+newe;
		}
	}

	if(checkDataEntry(cm)==0)
	{
		jAlert("Please enter your comment",'BKK Town Message');
		return false;
	}
	else
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<cm.length; i++)
		{
			mycode = cm.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else if(mycode==13)
			{
				myChar="";
			}
			else if(mycode==10)
			{
				myChar="<br />";
			}
			else
			{
				myChar=cm.substr(i,1);
			}
			newcm=newcm+myChar;
		}
		param=param+"&cm="+newcm;
	}

	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "process_feedback.php"+param, true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			jAlert("Thank you for your feedback","BKK Town Message",function(ans)
			{
				parent.tb_remove();
			});
		}
	}
}

function fetchSubCategory(obj)
{
	document.getElementById("subcategorybox").innerHTML="<span style='margin-left:20px;font-size:10px;color:#fff8dc;'><i>loading...</i></span>";
	
	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "fetch_sub_category.php?cid="+obj.value, true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			document.getElementById("subcategorybox").innerHTML=doc.responseText;
		}
	}
}

function fetchCityArea(obj)
{
	document.getElementById("cityareabox").innerHTML="<span style='margin-left:20px;font-size:10px;color:#fff8dc;'><i>loading...</i></span>";
	
	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "fetch_city_area.php?cid="+obj.value, true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			document.getElementById("cityareabox").innerHTML=doc.responseText;
		}
	}
}

function checkRecommendation()
{
	var param="";
	var cn=document.getElementById("strContactName").value;
	var e=document.getElementById("strEmail").value;
	var pn=document.getElementById("strPhone").value;
	var cid=document.getElementById("lngCategoryId").value;
	var sid=document.getElementById("lngSubCatId").value;
	var en=document.getElementById("strEstablishmentName").value;
	var ad=document.getElementById("strAddress").value;
	var ctid=document.getElementById("lngCityId").value;
	var aid=document.getElementById("lngAreaId").value;
	var zc=document.getElementById("strZipCode").value;
	var ws=document.getElementById("strWebsite").value;
	var ee=document.getElementById("strEstEmail").value;
	var epn=document.getElementById("strEstPhone").value;
	var cm=document.getElementById("strComment").value;
	
	var newcn="";
	var newe="";
	var newpn="";
	var newen="";
	var newad="";
	var newzc="";
	var newws="";
	var newee="";
	var newepn="";
	var newcm="";
		
	if(checkDataEntry(cn)==0)
	{
		jAlert('Please enter your name','BKK Town Message');
		return false;
	}
	else
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<cn.length; i++)
		{
			mycode = cn.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=cn.substr(i,1);
			}
			newcn=newcn+myChar;
		}
		param="?cn="+newcn;
	}

	if(checkDataEntry(e)==0)
	{
		jAlert('Please enter your email address', 'BKK Town Message');
		return false;
	}
	else
	{
		if(checkEmailValid(e)!="0") 
		{
			jAlert(checkEmailValid(e,'Your'), 'BKK Town Message');
			return false;
		}
		else
		{
			var i=0;
			var mycode=0;
			var myChar;
	
			for(i=0; i<e.length; i++)
			{
				mycode = e.charCodeAt(i);
				if(mycode==38)
				{
					myChar="(amp)";
				}
				else if(mycode==35)
				{
					myChar="(hash)";
				}
				else if(mycode==37)
				{
					myChar="(percentage)";
				}
				else if(mycode==43)
				{
					myChar="(plus)";
				}
				else
				{
					myChar=e.substr(i,1);
				}
				newe=newe+myChar;
			}
			param=param+"&e="+newe;
		}
	}
	
	if(checkDataEntry(pn)!=0)
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<pn.length; i++)
		{
			mycode = pn.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=pn.substr(i,1);
			}
			newpn=newpn+myChar;
		}
		param=param+"&pn="+newpn;
	}
	
	if(checkDataEntry(en)==0)
	{
		jAlert('Please enter the establishment name','BKK Town Message');
		return false;
	}
	else
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<en.length; i++)
		{
			mycode = en.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=en.substr(i,1);
			}
			newen=newen+myChar;
		}
		param=param+"&en="+newen;
	}

	param=param+"&sid="+sid;
	
	if(checkDataEntry(ad)!=0)
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<ad.length; i++)
		{
			mycode = ad.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else if(mycode==13)
			{
				myChar="";
			}
			else if(mycode==10)
			{
				myChar="<br />";
			}
			else
			{
				myChar=ad.substr(i,1);
			}
			newad=newad+myChar;
		}
		param=param+"&ad="+newad;
	}
	
	if(ctid>0)
	{
		if(aid==0)
		{
			jAlert("Please select a city area",'BKK Town Message');
			return false;
		}
		else
		{
			param=param+"&aid="+aid;
		}
	}

	if(checkDataEntry(zc)!=0)
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<zc.length; i++)
		{
			mycode = zc.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=zc.substr(i,1);
			}
			newzc=newzc+myChar;
		}
		param=param+"&zc="+newzc;
	}
	
	if(checkDataEntry(ws)!=0)
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<ws.length; i++)
		{
			mycode = ws.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=ws.substr(i,1);
			}
			newws=newws+myChar;
		}
		param=param+"&ws="+newws;
	}
	
	if(checkDataEntry(ee)!=0)
	{
		if(checkEmailValid(ee)!="0") 
		{
			jAlert(checkEmailValid(ee,'The establishment'), 'BKK Town Message');
			return false;
		}
		else
		{
			var i=0;
			var mycode=0;
			var myChar;
	
			for(i=0; i<ee.length; i++)
			{
				mycode = ee.charCodeAt(i);
				if(mycode==38)
				{
					myChar="(amp)";
				}
				else if(mycode==35)
				{
					myChar="(hash)";
				}
				else if(mycode==37)
				{
					myChar="(percentage)";
				}
				else if(mycode==43)
				{
					myChar="(plus)";
				}
				else
				{
					myChar=ee.substr(i,1);
				}
				newee=newee+myChar;
			}
			param=param+"&ee="+newee;
		}
	}
	
	if(checkDataEntry(epn)!=0)
	{
		var mycode=0;
		var myChar;

		for(i=0; i<epn.length; i++)
		{
			mycode = epn.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=epn.substr(i,1);
			}
			newepn=newepn+myChar;
		}
		param=param+"&epn="+newepn;
	}
	
	if(checkDataEntry(cm)==0)
	{
		jAlert("Please enter your comment",'BKK Town Message');
		return false;
	}
	else
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<cm.length; i++)
		{
			mycode = cm.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else if(mycode==13)
			{
				myChar="";
			}
			else if(mycode==10)
			{
				myChar="<br />";
			}
			else
			{
				myChar=cm.substr(i,1);
			}
			newcm=newcm+myChar;
		}
		param=param+"&cm="+newcm;
	}

	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "process_recommend_business.php"+param, true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			jAlert("Thank you for recommending a new business","BKK Town Message",function(ans)
			{
				parent.tb_remove();
			});
		}
	}
}

function checkBusinessReview(eid)
{
	var param="";
	var cn=document.getElementById("strContactName").value;
	var e=document.getElementById("strEmail").value;
	var hd=document.getElementById("strHeading").value;
	var rvw=document.getElementById("strReview").value;
	
	var newcn="";
	var newe="";
	var newhd="";
	var newrvw="";
		
	if(checkDataEntry(cn)==0)
	{
		jAlert('Please enter your name','BKK Town Message');
		return false;
	}
	else
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<cn.length; i++)
		{
			mycode = cn.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=cn.substr(i,1);
			}
			newcn=newcn+myChar;
		}
		param="&cn="+newcn;
	}
	
	if(checkDataEntry(e)==0)
	{
		jAlert('Please enter your email address', 'BKK Town Message');
		return false;
	}
	else
	{
		if(checkEmailValid(e)!="0") 
		{
			jAlert(checkEmailValid(e,'Your'), 'BKK Town Message');
			return false;
		}
		else
		{
			var i=0;
			var mycode=0;
			var myChar;
	
			for(i=0; i<e.length; i++)
			{
				mycode = e.charCodeAt(i);
				if(mycode==38)
				{
					myChar="(amp)";
				}
				else if(mycode==35)
				{
					myChar="(hash)";
				}
				else if(mycode==37)
				{
					myChar="(percentage)";
				}
				else if(mycode==43)
				{
					myChar="(plus)";
				}
				else
				{
					myChar=e.substr(i,1);
				}
				newe=newe+myChar;
			}
			param=param+"&e="+newe;
		}
	}
		
	if(checkDataEntry(hd)==0)
	{
		jAlert('Please enter your review title','BKK Town Message');
		return false;
	}
	else
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<hd.length; i++)
		{
			mycode = hd.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=hd.substr(i,1);
			}
			newhd=newhd+myChar;
		}
		param=param+"&hd="+newhd;
	}

	if(checkDataEntry(rvw)==0)
	{
		jAlert("Please enter your review text",'BKK Town Message');
		return false;
	}
	else
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<rvw.length; i++)
		{
			mycode = rvw.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else if(mycode==13)
			{
				myChar="";
			}
			else if(mycode==10)
			{
				myChar="<br />";
			}
			else
			{
				myChar=rvw.substr(i,1);
			}
			newrvw=newrvw+myChar;
		}
		param=param+"&rvw="+newrvw;
	}

	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "process_business_review.php?eid="+eid+param, true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			jAlert("Thank you for your review","BKK Town Message",function(ans)
			{
				parent.tb_remove();
			});
		}
	}
}

function checkContactUs()
{
	var param="";
	var cn=document.getElementById("strContactName").value;
	var e=document.getElementById("strEmail").value;
	var msg=document.getElementById("strMessage").value;
	
	var newcn="";
	var newe="";
	var newmsg="";
		
	if(checkDataEntry(cn)==0)
	{
		jAlert('Please enter your name','BKK Town Message');
		return false;
	}
	else
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<cn.length; i++)
		{
			mycode = cn.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=cn.substr(i,1);
			}
			newcn=newcn+myChar;
		}
		param="?cn="+newcn;
	}
	
	if(checkDataEntry(e)==0)
	{
		jAlert('Please enter your email address', 'BKK Town Message');
		return false;
	}
	else
	{
		if(checkEmailValid(e)!="0") 
		{
			jAlert(checkEmailValid(e,'Your'), 'BKK Town Message');
			return false;
		}
		else
		{
			var i=0;
			var mycode=0;
			var myChar;
	
			for(i=0; i<e.length; i++)
			{
				mycode = e.charCodeAt(i);
				if(mycode==38)
				{
					myChar="(amp)";
				}
				else if(mycode==35)
				{
					myChar="(hash)";
				}
				else if(mycode==37)
				{
					myChar="(percentage)";
				}
				else if(mycode==43)
				{
					myChar="(plus)";
				}
				else
				{
					myChar=e.substr(i,1);
				}
				newe=newe+myChar;
			}
			param=param+"&e="+newe;
		}
	}

	if(checkDataEntry(msg)==0)
	{
		jAlert("Please enter your message",'BKK Town Message');
		return false;
	}
	else
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<msg.length; i++)
		{
			mycode = msg.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else if(mycode==13)
			{
				myChar="";
			}
			else if(mycode==10)
			{
				myChar="<br />";
			}
			else
			{
				myChar=msg.substr(i,1);
			}
			newmsg=newmsg+myChar;
		}
		param=param+"&msg="+newmsg;
	}

	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "process_contact_us.php"+param, true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			jAlert("Thank you for contacting us","BKK Town Message",function(ans)
			{
				parent.tb_remove();
			});
		}
	}
}

function setSelectCity(obj)
{
	var cn=obj.options[obj.selectedIndex].text;
	
	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "set_select_city.php?id="+obj.value+"&cn="+cn, true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			document.location.href="city.php";
		}
	}
}

function fetchCalendar(sd)
{
	document.getElementById("eventlist").innerHTML="";
	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "cal.php?sd="+sd, true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			document.getElementById("calendar").innerHTML=doc.responseText;
			fetchEvents("");
		}
	}
}

function fetchEvents(nd)
{
	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "getevents.php?nd="+nd, true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			document.getElementById("eventlist").innerHTML=doc.responseText;
		}
	}
}

function hideShowEventInfo(dvname)
{
	if(document.getElementById(dvname).style.display=="none")
	{
		document.getElementById(dvname).style.display="";
	}
	else
	{
		document.getElementById(dvname).style.display="none";
	}
}

function changePageClass(obj,selclass)
{
	obj.className=selclass;
}

function fetchCityCategory(cs,dvname,pagenum)
{
	var ids="";
	switch(cs)
	{
		case "loyaltycard":
		{
			ids=document.getElementById("strLoyaltyIdList").value;
			break;
		}
		case "featured":
		{
			ids=document.getElementById("strFeaturedIdList").value;
			break;
		}
		case "other":
		{
			ids=document.getElementById("strOtherIdList").value;
			break;
		}
	}

	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "fetch_city_category.php?cs="+cs+"&dvname="+dvname+"&ids="+ids+"&pagenum="+pagenum, true);
	doc.send();
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			document.getElementById(dvname).innerHTML=doc.responseText;
		}
	}
}

function fetchCityAreaCategory(cs,dvname,pagenum)
{
	var ids="";
	switch(cs)
	{
		case "loyaltycard":
		{
			ids=document.getElementById("strLoyaltyIdList").value;
			break;
		}
		case "featured":
		{
			ids=document.getElementById("strFeaturedIdList").value;
			break;
		}
		case "other":
		{
			ids=document.getElementById("strOtherIdList").value;
			break;
		}
	}

	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "fetch_city_area_category.php?cs="+cs+"&dvname="+dvname+"&ids="+ids+"&pagenum="+pagenum, true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			document.getElementById(dvname).innerHTML=doc.responseText;
		}
	}
}

function storeSelEstablishmentName(ename)
{
	document.getElementById('strEstablishment').value=ename;
}

function printDiv()
{
	var ename=document.getElementById('strEstablishment').value;
	var divToPrint=document.getElementById('cluetipcontainer'); 
	
	var newWin=window.open("","PrintWindow","width=350,height=320"); 
	newWin.document.open();
	newWin.document.write('<html><head><title>Printing...</title></head><body onload="window.print()">'+"<div style='text-align:center;'><strong>"+ename.toUpperCase(ename)+"</strong></div>"+divToPrint.innerHTML+'</body></html>'); 
	newWin.document.close();

	if(navigator.appName!="Microsoft Internet Explorer")
	{
		setTimeout(function(){newWin.close();},10);
	}
}

function searchButton()
{
	var stxt=document.getElementById("strSearch").value;
		
	if(checkDataEntry(stxt)==0)
	{
		jAlert('Please enter your search criteria','BKK Town Message');
		return false;
	}
	document.globFrmData.submit();
}

function fetchEstablishmentHours()
{
	document.getElementById("tab3").innerHTML="<img src='images/lightgrayindicator24.gif' width='24' height='24' style='margin-right:5px;' /><span class='graytext'><i>saving</i></span>";

	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "fetch_establishment_hours.php", true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			document.getElementById("tab3").innerHTML=doc.responseText;
		}
	}
}

function showHideTimeBoxes(obj,dvnm)
{
	if(dvnm=="opnhrtimecontainer0")
	{
		var cnt=document.getElementById("intOpeningHourCount").value;
		var i=0;
		if(obj.checked==true)
		{
			document.getElementById(dvnm).style.display="";
	
			for(i=1; i<=cnt; i++)
			{
				document.getElementById("opnhrtimecontainer"+i).style.display="none";
				document.getElementById("chkOpeningHour"+i).checked=false;
				document.getElementById("opnhr"+i).style.display="none";
			}
		}
		else
		{
			document.getElementById(dvnm).style.display="none";
	
			for(i=1; i<=cnt; i++)
			{
				document.getElementById("opnhr"+i).style.display="";
			}
		}
	}
	else if(dvnm=="hphrtimecontainer0")
	{
		var cnt=document.getElementById("intHappyHourCount").value;
		var i=0;
		if(obj.checked==true)
		{
			document.getElementById(dvnm).style.display="";
	
			for(i=1; i<=cnt; i++)
			{
				document.getElementById("hphrtimecontainer"+i).style.display="none";
				document.getElementById("chkHappyHour"+i).checked=false;
				document.getElementById("hphr"+i).style.display="none";
			}
		}
		else
		{
			document.getElementById(dvnm).style.display="none";
	
			for(i=1; i<=cnt; i++)
			{
				document.getElementById("hphr"+i).style.display="";
			}
		}
	}
	else
	{
		if(obj.checked==true)
		{
			document.getElementById(dvnm).style.display="";
		}
		else
		{
			document.getElementById(dvnm).style.display="none";
		}
	}
}

function checkEstablishmentHours()
{
	var param="";
	
	//save opening hours here
	var chksame=document.getElementById("chkSameOpeningHour");

	if(chksame.checked==true)
	{
		//for opening hour session 1
		var sh=document.getElementById("intOpnHr1StartHour").value;
		var sm=document.getElementById("intOpnHr1StartMinute").value;
		var eh=document.getElementById("intOpnHr1EndHour").value;
		var em=document.getElementById("intOpnHr1EndMinute").value;
		var opnhrdesc=document.getElementById("strOpnHr1Desc").value;
		var newopnhrdesc="";

		if(sh==99) 
		{
			jAlert("The opening hours start time of session 1 is invalid",'BKK Town Message');
			return false;
		}
		else if(sm==99) 
		{
			jAlert("The opening hours start time of session 1 is invalid",'BKK Town Message');
			return false;
		}
		else if(eh==99) 
		{
			jAlert("The opening hours end time of session 1 is invalid",'BKK Town Message');
			return false;
		}
		else if(em==99) 
		{
			jAlert("The opening hours end time of session 1 is invalid",'BKK Town Message');
			return false;
		}
		else
		{
			param="?opnhr1=0,"+sh+","+sm+","+eh+","+em;
		}
		
		if(checkDataEntry(opnhrdesc)!=0)
		{
			var i=0;
			var mycode=0;
			var myChar;
	
			for(i=0; i<opnhrdesc.length; i++)
			{
				mycode = opnhrdesc.charCodeAt(i);
				if(mycode==38)
				{
					myChar="(amp)";
				}
				else if(mycode==35)
				{
					myChar="(hash)";
				}
				else if(mycode==37)
				{
					myChar="(percentage)";
				}
				else if(mycode==43)
				{
					myChar="(plus)";
				}
				else if(mycode==13)
				{
					myChar="";
				}
				else if(mycode==10)
				{
					myChar="<br />";
				}
				else
				{
					myChar=opnhrdesc.substr(i,1);
				}
				newopnhrdesc=newopnhrdesc+myChar;
			}
			param=param+","+newopnhrdesc;
		}
		
		//for opening hour session 2
		var sh=document.getElementById("intOpnHr2StartHour").value;
		var sm=document.getElementById("intOpnHr2StartMinute").value;
		var eh=document.getElementById("intOpnHr2EndHour").value;
		var em=document.getElementById("intOpnHr2EndMinute").value;
		var opnhrdesc=document.getElementById("strOpnHr2Desc").value;
		var newopnhrdesc="";

		if((sh!=99) && (sm!=99) && (eh!=99) && (em!=99))
		{
			if(param.length==0)
			{
				param="?opnhr2=0,"+sh+","+sm+","+eh+","+em;
			}
			else
			{
				param=param+"&opnhr2=0,"+sh+","+sm+","+eh+","+em;
			}
		}
		else
		{
			if((sh!=99) || (sm!=99) || (eh!=99) || (em!=99))
			{
				jAlert("The opening hours time of session 2 is invalid",'BKK Town Message');
				return false;
			}
		}
		
		if(checkDataEntry(opnhrdesc)!=0)
		{
			if((sh==99) || (sm==99) || (eh==99) || (em==99))
			{
				jAlert("The opening hours time of session 2 is invalid",'BKK Town Message');
				return false;
			}

			var i=0;
			var mycode=0;
			var myChar;
	
			for(i=0; i<opnhrdesc.length; i++)
			{
				mycode = opnhrdesc.charCodeAt(i);
				if(mycode==38)
				{
					myChar="(amp)";
				}
				else if(mycode==35)
				{
					myChar="(hash)";
				}
				else if(mycode==37)
				{
					myChar="(percentage)";
				}
				else if(mycode==43)
				{
					myChar="(plus)";
				}
				else if(mycode==13)
				{
					myChar="";
				}
				else if(mycode==10)
				{
					myChar="<br />";
				}
				else
				{
					myChar=opnhrdesc.substr(i,1);
				}
				newopnhrdesc=newopnhrdesc+myChar;
			}
			param=param+","+newopnhrdesc;
		}
	}
	else
	{
		var opnhr="";
		var cnt=document.getElementById("intOpeningHourCount").value;
		var i=0;

		//opening hour session 1 here
		for(i=1; i<=cnt; i++)
		{
			var obj=document.getElementById("chkOpeningHour"+i)
			var sh=document.getElementById("intOpnHr1StartHour"+i).value;
			var sm=document.getElementById("intOpnHr1StartMinute"+i).value;
			var eh=document.getElementById("intOpnHr1EndHour"+i).value;
			var em=document.getElementById("intOpnHr1EndMinute"+i).value;
			var opnhrdesc=document.getElementById("strOpnHr1Desc"+i).value;
			var newopnhrdesc="";
			
			if(obj.checked==true)
			{
				if(sh==99) 
				{
					jAlert("The opening hours start time of session 1 for "+obj.name+" is invalid",'BKK Town Message');
					return false;
				}
				else if(sm==99) 
				{
					jAlert("The opening hours start time of session 1 for "+obj.name+" is invalid",'BKK Town Message');
					return false;
				}
				else if(eh==99) 
				{
					jAlert("The opening hours end time of session 1 for "+obj.name+" is invalid",'BKK Town Message');
					return false;
				}
				else if(em==99) 
				{
					jAlert("The opening hours end time of session 1 for "+obj.name+" is invalid",'BKK Town Message');
					return false;
				}
				else
				{
					if(checkDataEntry(opnhrdesc)!=0)
					{
						var j=0;
						var mycode=0;
						var myChar;
				
						for(j=0; j<opnhrdesc.length; j++)
						{
							mycode = opnhrdesc.charCodeAt(j);
							if(mycode==38)
							{
								myChar="(amp)";
							}
							else if(mycode==35)
							{
								myChar="(hash)";
							}
							else if(mycode==37)
							{
								myChar="(percentage)";
							}
							else if(mycode==43)
							{
								myChar="(plus)";
							}
							else if(mycode==13)
							{
								myChar="";
							}
							else if(mycode==10)
							{
								myChar="<br />";
							}
							else
							{
								myChar=opnhrdesc.substr(j,1);
							}
							newopnhrdesc=newopnhrdesc+myChar;
						}
					}
				}

				if(opnhr.length==0)
				{
					opnhr=obj.value+","+sh+","+sm+","+eh+","+em;
				}
				else
				{
					opnhr=opnhr+"|"+obj.value+","+sh+","+sm+","+eh+","+em;
				}
				
				if(newopnhrdesc.length>0)
				{
					opnhr=opnhr+","+newopnhrdesc;
				}
			}
		}
		
		if(param.length==0)
		{
			param="?opnhr1="+opnhr;
		}
		else
		{
			param=param+"&opnhr1="+opnhr;
		}

		//opening hour session 2 here
		var i=0;
		var opnhr="";
		for(i=1; i<=cnt; i++)
		{
			var obj=document.getElementById("chkOpeningHour"+i)
			var sh=document.getElementById("intOpnHr2StartHour"+i).value;
			var sm=document.getElementById("intOpnHr2StartMinute"+i).value;
			var eh=document.getElementById("intOpnHr2EndHour"+i).value;
			var em=document.getElementById("intOpnHr2EndMinute"+i).value;
			var opnhrdesc=document.getElementById("strOpnHr2Desc"+i).value;
			var newopnhrdesc="";

			if(obj.checked==true)
			{
				if((sh!=99) && (sm!=99) && (eh!=99) && (em!=99))
				{
					if(opnhr.length==0)
					{
						opnhr=obj.value+","+sh+","+sm+","+eh+","+em;
					}
					else
					{
						opnhr=opnhr+"|"+obj.value+","+sh+","+sm+","+eh+","+em;
					}
				}
				else
				{
					if((sh!=99) || (sm!=99) || (eh!=99) || (em!=99))
					{
						jAlert("The opening hours time of session 2 for "+obj.name+" is invalid",'BKK Town Message');
						return false;
					}
				}
				
				if(checkDataEntry(opnhrdesc)!=0)
				{
					if((sh==99) || (sm==99) || (eh==99) || (em==99))
					{
						jAlert("The opening hours time of session 2 for "+obj.name+" is invalid",'BKK Town Message');
						return false;
					}
					
					var j=0;
					var mycode=0;
					var myChar;
			
					for(j=0; j<opnhrdesc.length; j++)
					{
						mycode = opnhrdesc.charCodeAt(j);
						if(mycode==38)
						{
							myChar="(amp)";
						}
						else if(mycode==35)
						{
							myChar="(hash)";
						}
						else if(mycode==37)
						{
							myChar="(percentage)";
						}
						else if(mycode==43)
						{
							myChar="(plus)";
						}
						else if(mycode==13)
						{
							myChar="";
						}
						else if(mycode==10)
						{
							myChar="<br />";
						}
						else
						{
							myChar=opnhrdesc.substr(j,1);
						}
						newopnhrdesc=newopnhrdesc+myChar;
					}
					
					if(newopnhrdesc.length>0)
					{
						opnhr=opnhr+","+newopnhrdesc;
					}
				}
			}
		}
				
		if(opnhr.length>0)
		{
			if(param.length==0)
			{
				param="?opnhr2="+opnhr;
			}
			else
			{
				param=param+"&opnhr2="+opnhr;
			}
		}
	}

	//save happy hours here
	var chksame=document.getElementById("chkSameHappyHour");

	if(chksame.checked==true)
	{
		//for happy hour session 1
		var sh=document.getElementById("intHpHr1StartHour").value;
		var sm=document.getElementById("intHpHr1StartMinute").value;
		var eh=document.getElementById("intHpHr1EndHour").value;
		var em=document.getElementById("intHpHr1EndMinute").value;
		var hphrdesc=document.getElementById("strHpHr1Desc").value;
		var newhphrdesc="";

		if(sh==99) 
		{
			jAlert("The happy hours start time of session 1 is invalid",'BKK Town Message');
			return false;
		}
		else if(sm==99) 
		{
			jAlert("The happy hours start time of session 1 is invalid",'BKK Town Message');
			return false;
		}
		else if(eh==99) 
		{
			jAlert("The happy hours end time of session 1 is invalid",'BKK Town Message');
			return false;
		}
		else if(em==99) 
		{
			jAlert("The happy hours end time of session 1 is invalid",'BKK Town Message');
			return false;
		}
		else
		{
			if(param.length==0)
			{
				param="?hphr1=0,"+sh+","+sm+","+eh+","+em;
			}
			else
			{
				param=param+"&hphr1=0,"+sh+","+sm+","+eh+","+em;
			}
		}
		
		if(checkDataEntry(hphrdesc)!=0)
		{
			var i=0;
			var mycode=0;
			var myChar;
	
			for(i=0; i<hphrdesc.length; i++)
			{
				mycode = hphrdesc.charCodeAt(i);
				if(mycode==38)
				{
					myChar="(amp)";
				}
				else if(mycode==35)
				{
					myChar="(hash)";
				}
				else if(mycode==37)
				{
					myChar="(percentage)";
				}
				else if(mycode==43)
				{
					myChar="(plus)";
				}
				else if(mycode==13)
				{
					myChar="";
				}
				else if(mycode==10)
				{
					myChar="<br />";
				}
				else
				{
					myChar=hphrdesc.substr(i,1);
				}
				newhphrdesc=newhphrdesc+myChar;
			}
			param=param+","+newhphrdesc;
		}
		
		//for happy hour session 2
		var sh=document.getElementById("intHpHr2StartHour").value;
		var sm=document.getElementById("intHpHr2StartMinute").value;
		var eh=document.getElementById("intHpHr2EndHour").value;
		var em=document.getElementById("intHpHr2EndMinute").value;
		var hphrdesc=document.getElementById("strHpHr2Desc").value;
		var newhphrdesc="";

		if((sh!=99) && (sm!=99) && (eh!=99) && (em!=99))
		{
			if(param.length==0)
			{
				param="?hphr2=0,"+sh+","+sm+","+eh+","+em;
			}
			else
			{
				param=param+"&hphr2=0,"+sh+","+sm+","+eh+","+em;
			}
		}
		else
		{
			if((sh!=99) || (sm!=99) || (eh!=99) || (em!=99))
			{
				jAlert("The happy hours time of session 2 is invalid",'BKK Town Message');
				return false;
			}
		}
		
		if(checkDataEntry(hphrdesc)!=0)
		{
			if((sh==99) || (sm==99) || (eh==99) || (em==99))
			{
				jAlert("The happy hours time of session 2 is invalid",'BKK Town Message');
				return false;
			}

			var i=0;
			var mycode=0;
			var myChar;
	
			for(i=0; i<hphrdesc.length; i++)
			{
				mycode = hphrdesc.charCodeAt(i);
				if(mycode==38)
				{
					myChar="(amp)";
				}
				else if(mycode==35)
				{
					myChar="(hash)";
				}
				else if(mycode==37)
				{
					myChar="(percentage)";
				}
				else if(mycode==43)
				{
					myChar="(plus)";
				}
				else if(mycode==13)
				{
					myChar="";
				}
				else if(mycode==10)
				{
					myChar="<br />";
				}
				else
				{
					myChar=hphrdesc.substr(i,1);
				}
				newhphrdesc=newhphrdesc+myChar;
			}
			param=param+","+newhphrdesc;
		}
	}
	else
	{
		var hphr="";
		var cnt=document.getElementById("intHappyHourCount").value;
		var i=0;

		//happy hour session 1 here
		for(i=1; i<=cnt; i++)
		{
			var obj=document.getElementById("chkHappyHour"+i)
			var sh=document.getElementById("intHpHr1StartHour"+i).value;
			var sm=document.getElementById("intHpHr1StartMinute"+i).value;
			var eh=document.getElementById("intHpHr1EndHour"+i).value;
			var em=document.getElementById("intHpHr1EndMinute"+i).value;
			var hphrdesc=document.getElementById("strHpHr1Desc"+i).value;
			var newhphrdesc="";
			
			if(obj.checked==true)
			{
				if(sh==99) 
				{
					jAlert("The happy hours start time of session 1 for "+obj.name+" is invalid",'BKK Town Message');
					return false;
				}
				else if(sm==99) 
				{
					jAlert("The happy hours start time of session 1 for "+obj.name+" is invalid",'BKK Town Message');
					return false;
				}
				else if(eh==99) 
				{
					jAlert("The happy hours end time of session 1 for "+obj.name+" is invalid",'BKK Town Message');
					return false;
				}
				else if(em==99) 
				{
					jAlert("The happy hours end time of session 1 for "+obj.name+" is invalid",'BKK Town Message');
					return false;
				}
				else
				{
					if(checkDataEntry(hphrdesc)!=0)
					{
						var j=0;
						var mycode=0;
						var myChar;
				
						for(j=0; j<hphrdesc.length; j++)
						{
							mycode = hphrdesc.charCodeAt(j);
							if(mycode==38)
							{
								myChar="(amp)";
							}
							else if(mycode==35)
							{
								myChar="(hash)";
							}
							else if(mycode==37)
							{
								myChar="(percentage)";
							}
							else if(mycode==43)
							{
								myChar="(plus)";
							}
							else if(mycode==13)
							{
								myChar="";
							}
							else if(mycode==10)
							{
								myChar="<br />";
							}
							else
							{
								myChar=hphrdesc.substr(j,1);
							}
							newhphrdesc=newhphrdesc+myChar;
						}
					}
				}

				if(hphr.length==0)
				{
					hphr=obj.value+","+sh+","+sm+","+eh+","+em;
				}
				else
				{
					hphr=hphr+"|"+obj.value+","+sh+","+sm+","+eh+","+em;
				}
				
				if(newhphrdesc.length>0)
				{
					hphr=hphr+","+newhphrdesc;
				}
			}
		}
		
		if(param.length==0)
		{
			param="?hphr1="+hphr;
		}
		else
		{
			param=param+"&hphr1="+hphr;
		}

		//happy hour session 2 here
		var i=0;
		var hphr="";
		for(i=1; i<=cnt; i++)
		{
			var obj=document.getElementById("chkHappyHour"+i)
			var sh=document.getElementById("intHpHr2StartHour"+i).value;
			var sm=document.getElementById("intHpHr2StartMinute"+i).value;
			var eh=document.getElementById("intHpHr2EndHour"+i).value;
			var em=document.getElementById("intHpHr2EndMinute"+i).value;
			var hphrdesc=document.getElementById("strHpHr2Desc"+i).value;
			var newhphrdesc="";

			if(obj.checked==true)
			{
				if((sh!=99) && (sm!=99) && (eh!=99) && (em!=99))
				{
					if(hphr.length==0)
					{
						hphr=obj.value+","+sh+","+sm+","+eh+","+em;
					}
					else
					{
						hphr=hphr+"|"+obj.value+","+sh+","+sm+","+eh+","+em;
					}
				}
				else
				{
					if((sh!=99) || (sm!=99) || (eh!=99) || (em!=99))
					{
						jAlert("The happy hours time of session 2 for "+obj.name+" is invalid",'BKK Town Message');
						return false;
					}
				}
				
				if(checkDataEntry(hphrdesc)!=0)
				{
					if((sh==99) || (sm==99) || (eh==99) || (em==99))
					{
						jAlert("The happy hours time of session 2 for "+obj.name+" is invalid",'BKK Town Message');
						return false;
					}
					
					var j=0;
					var mycode=0;
					var myChar;
			
					for(j=0; j<hphrdesc.length; j++)
					{
						mycode = hphrdesc.charCodeAt(j);
						if(mycode==38)
						{
							myChar="(amp)";
						}
						else if(mycode==35)
						{
							myChar="(hash)";
						}
						else if(mycode==37)
						{
							myChar="(percentage)";
						}
						else if(mycode==43)
						{
							myChar="(plus)";
						}
						else if(mycode==13)
						{
							myChar="";
						}
						else if(mycode==10)
						{
							myChar="<br />";
						}
						else
						{
							myChar=hphrdesc.substr(j,1);
						}
						newhphrdesc=newhphrdesc+myChar;
					}
					
					if(newhphrdesc.length>0)
					{
						hphr=hphr+","+newhphrdesc;
					}
				}
			}
		}
				
		if(hphr.length>0)
		{
			if(param.length==0)
			{
				param="?hphr2="+hphr;
			}
			else
			{
				param=param+"&hphr2="+hphr;
			}
		}
	}

	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "process_establishment_hours.php"+param, true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			fetchEstablishmentHours();
		}
	}
}

function getCityArea(obj)
{
	document.getElementById("cityarealistbox").innerHTML="<i><span class='graytext'>loading...</span></i>";

	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "fetch_city_area.php?cid="+obj.value, true);	//*** this file was also used by Recommended a Business section ***
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			document.getElementById("cityarealistbox").innerHTML=doc.responseText;
		}
	}
}

function checkEstablishmentAddress()
{
	var param="";
	var ad=document.getElementById("strAddress").value;
	var aid=document.getElementById("lngAreaId").value;
	var zc=document.getElementById("strZipCode").value;
	var ws=document.getElementById("strWebsite").value;
	var e=document.getElementById("strEmail").value;
	var pn=document.getElementById("strPhone").value;

	var newad="";
	var newzc="";
	var newws="";
	var newe="";
	var newpn="";

	if(checkDataEntry(ad)!=0)
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<ad.length; i++)
		{
			mycode = ad.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else if(mycode==13)
			{
				myChar="";
			}
			else if(mycode==10)
			{
				myChar="<br />";
			}
			else
			{
				myChar=ad.substr(i,1);
			}
			newad=newad+myChar;
		}
		param="?ad="+newad;
	}

	if(aid!=0)
	{
		if(param.length==0)
		{
			param="?aid="+aid;
		}
		else
		{
			param=param+"&aid="+aid;
		}
	}
	
	if(checkDataEntry(zc)!=0)
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<zc.length; i++)
		{
			mycode = zc.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=zc.substr(i,1);
			}
			newzc=newzc+myChar;
		}

		if(param.length==0)
		{
			param="?zc="+newzc;
		}
		else
		{
			param=param+"&zc="+newzc;
		}
	}
	
	if(checkDataEntry(pn)!=0)
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<pn.length; i++)
		{
			mycode = pn.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=pn.substr(i,1);
			}
			newpn=newpn+myChar;
		}

		if(param.length==0)
		{
			param="?pn="+newpn;
		}
		else
		{
			param=param+"&pn="+newpn;
		}
	}

	if(checkDataEntry(e)!=0)
	{
		if (checkEmailValid(e)!="0") 
		{
			jAlert(checkEmailValid(e,'The'), 'BKK Town Message');
			return false;
		}
		else
		{
			var i=0;
			var mycode=0;
			var myChar;
	
			for(i=0; i<e.length; i++)
			{
				mycode = e.charCodeAt(i);
				if(mycode==38)
				{
					myChar="(amp)";
				}
				else if(mycode==35)
				{
					myChar="(hash)";
				}
				else if(mycode==37)
				{
					myChar="(percentage)";
				}
				else if(mycode==43)
				{
					myChar="(plus)";
				}
				else
				{
					myChar=e.substr(i,1);
				}
				newe=newe+myChar;
			}

			if(param.length==0)
			{
				param="?e="+newe;
			}
			else
			{
				param=param+"&e="+newe;
			}
		}
	}

	if(checkDataEntry(ws)!=0)
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<ws.length; i++)
		{
			mycode = ws.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=ws.substr(i,1);
			}
			newws=newws+myChar;
		}

		if(param.length==0)
		{
			param="?ws="+newws;
		}
		else
		{
			param=param+"&ws="+newws;
		}
	}

	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "process_establishment_address.php"+param, true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			fetchEstablishmentAddress();
		}
	}
}

function fetchEstablishmentAddress()
{
	document.getElementById("tab2").innerHTML="<img src='images/lightgrayindicator24.gif' width='24' height='24' style='margin-right:5px;' /><span class='graytext'><i>saving</i></span>";

	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "fetch_establishment_address.php", true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			document.getElementById("tab2").innerHTML=doc.responseText;
		}
	}
}

function removeEstablishmentLogo(id)
{
	jConfirm("Are you sure you want to remove the logo?",'BKK Town Message',function(ans)
	{
		if(ans==false)
		{
			return false;
		}

		var doc = null; 
	 
		// Make a new XMLHttp object
		 if (typeof window.ActiveXObject != 'undefined' ) 
		{ 
		   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		else 
		{ 
		   doc = new XMLHttpRequest(); 
		//doc.setRequestHeader 'Content-Type', 'text/xml';
		} 
		doc.onreadystatechange = handleStateChange;  
		  
		// Load the result from the response page
		// Note the response page can be any page that returns the right result. 
		// I used ASP. PHP, PERL... etc could acheive the same result
		 
		// ** As far a I know firefox will only load a document on the SAME domain!!
		//doc.setRequestHeader "Content-Type", "text/xml"
		doc.open("GET", "process_establishment_overview.php?cs=delpic&id="+id, true);
		doc.send(null);
		//destination.innerHTML = doc.responseText;
		
		function handleStateChange()
		{        
			if (doc.readyState==4)
			{
				var dblQuote=String.fromCharCode(34);
				var txt="";

				txt="<label for='strLogo'>Company Logo:</label>";
				txt=txt+"<input id='strLogo' name='strLogo' type='file' size='33'>";
				txt=txt+"<br /><label>&nbsp;</label>";
				txt=txt+"<i>";
				txt=txt+"<a href='JavaScript:void(0);' onClick='clearGenBrowseFileBox("+dblQuote+"strLogo"+dblQuote+")' class='loyaltycard' title=' click to clear your browsed file '>clear</a>";
				txt=txt+"</i>";

				document.getElementById("logocontainer").innerHTML=txt;
			}
		}
	});
}

function checkEstablishmentOverview()
{
	var param="";
	var en=document.getElementById("strEstablishmentName").value;
	var ctn=document.getElementById("strContactName").value;
	var cn=document.getElementById("strCompanyName").value;
	var dc=document.getElementById("strEstDescription").value;
	var un=document.getElementById("strUsername").value;
	var pwd=document.getElementById("strPassword").value;
	var cpwd=document.getElementById("strConfPassword").value;

	var newen="";
	var newcn="";
	var newdc="";
	var newctn="";
	var newbf="";
	var newun="";
	var newpwd="";

	if(checkDataEntry(en)==0)
	{
		jAlert("Please enter your establishment name",'BKK Town Message');
		return false;
	}
	else
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<en.length; i++)
		{
			mycode = en.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=en.substr(i,1);
			}
			newen=newen+myChar;
		}
		param="&en="+newen;
	}

	if(checkDataEntry(ctn)!=0)
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<ctn.length; i++)
		{
			mycode = ctn.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=ctn.substr(i,1);
			}
			newctn=newctn+myChar;
		}
		param=param+"&ctn="+newctn;
	}

	if(checkDataEntry(cn)!=0)
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<cn.length; i++)
		{
			mycode = cn.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=cn.substr(i,1);
			}
			newcn=newcn+myChar;
		}
		param=param+"&cn="+newcn;
	}
	
	var loc=document.getElementById("strLogo");
	if(checkDataEntry(loc.value)!=0)
	{
		var str=new String(loc.value.toUpperCase());
		var n=str.length;
		var i=n-1;
		var ext="";
		var h="";
		while((h!=".")&&(i>=0)&&(n!=0))
		{
			h = str.substr(i,1);
			i--;
		}
		ext=str.substr(i+2,3);
		ext2=str.substr(i+2,4);
		if((n!=0)&&(ext!="PNG")&&(ext!="JPG")&&(ext!="GIF")&&(ext2!="JPEG"))
		{
			alert("Only jpg, gif and png formats are allowed for the logo file");
			return false;
		}
	}

	if(checkDataEntry(dc)!=0)
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<dc.length; i++)
		{
			mycode = dc.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else if(mycode==13)
			{
				myChar="";
			}
			else if(mycode==10)
			{
				myChar="<br />";
			}
			else
			{
				myChar=dc.substr(i,1);
			}
			newdc=newdc+myChar;
		}
		//this is for a special case as found out that if there is the word "from" more than once
		//then the software would not save for example "Lyon French Cuisine", "Coran Boutique Spa" (establishment)
		newdc=newdc.replace(/ from /g," 5rom ");
		
		param=param+"&dc="+newdc;
	}
	
	if(document.getElementById("strBenefit")!=null)
	{
		var bf=document.getElementById("strBenefit").value;
		
		if(checkDataEntry(bf)!=0)
		{
			var i=0;
			var mycode=0;
			var myChar;
	
			for(i=0; i<bf.length; i++)
			{
				mycode = bf.charCodeAt(i);
				if(mycode==38)
				{
					myChar="(amp)";
				}
				else if(mycode==35)
				{
					myChar="(hash)";
				}
				else if(mycode==37)
				{
					myChar="(percentage)";
				}
				else if(mycode==43)
				{
					myChar="(plus)";
				}
				else if(mycode==13)
				{
					myChar="";
				}
				else if(mycode==10)
				{
					myChar="<br />";
				}
				else
				{
					myChar=bf.substr(i,1);
				}
				newbf=newbf+myChar;
			}
			param=param+"&bf="+newbf;
		}
	}
	
	if(checkDataEntry(un)==0)
	{
		jAlert("Please enter the username",'BKK Town Message');
		return false;
	}
	else
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<un.length; i++)
		{
			mycode = un.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=un.substr(i,1);
			}
			newun=newun+myChar;
		}
		param=param+"&un="+newun;
	}

	if(checkDataEntry(pwd)==0)
	{
		jAlert("Please enter the password",'BKK Town Message');
		return false;
	}
	else
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<pwd.length; i++)
		{
			mycode = pwd.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=pwd.substr(i,1);
			}
			newpwd=newpwd+myChar;
		}
		param=param+"&pwd="+newpwd;
	}

	if(checkDataEntry(cpwd)==0)
	{
		jAlert("Please enter the confirm password",'BKK Town Message');
		return false;
	}

	if(pwd!=cpwd)
	{
		jAlert("Your password and confirm password do not match, please amend",'BKK Town Message');
		return false;
	}

	$("#loading")
	.ajaxStart(function(){
		$(this).show();
	})
	.ajaxComplete(function(){
		$(this).hide();
	});

	$.ajaxFileUpload
	(
		{
			url:'process_establishment_overview.php?cs=upd'+param,
			secureuri:false,
			fileElementId:'strLogo',
			dataType: 'json',
			success: function (data, status)
			{
				if(data.responseText=="userdup")
				{
					jAlert("Sorry, your selected username already exists",'BKK Town Message');
					return false;
				}
				else if(data.responseText=="exists")
				{
					jAlert("Sorry, the entered establishment name already exists",'BKK Town Message');
					return false;
				}
				else
				{
					fetchEstablishmentOverview();
				}
			},
			error: function (data, status, e)
			{
				alert(e);
			}
		}
	)
}

function fetchEstablishmentOverview()
{
	document.getElementById("tab1").innerHTML="<img src='images/lightgrayindicator24.gif' width='24' height='24' style='margin-right:5px;' /><span class='graytext'><i>saving</i></span>";

	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "fetch_establishment_overview.php", true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			document.getElementById("tab1").innerHTML=doc.responseText;
		}
	}
}

function doNewEstablishmentImage()
{
	document.getElementById("uploadimagecontainer").style.display="";
	document.getElementById("uploadimagecontainer").innerHTML="<img src='images/lightgrayindicator24.gif' width='24' height='24' style='margin-right:5px;' /><span class='graytext'><i>loading</i></span>";
	
	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "new_establishment_image.php", true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			document.getElementById("uploadimagecontainer").innerHTML=doc.responseText;
		}
	}
}

function doEditEstablishmentImage(id)
{
	document.getElementById("uploadimagecontainer").style.display="";
	document.getElementById("uploadimagecontainer").innerHTML="<img src='images/lightgrayindicator24.gif' width='24' height='24' style='margin-right:5px;' /><span class='graytext'><i>loading</i></span>";
	
	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "edit_establishment_image.php?id="+id, true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			document.getElementById("uploadimagecontainer").innerHTML=doc.responseText;
		}
	}
}

function checkEstablishmentImage(cs,id)
{
	var param="";
	var orgloc=document.getElementById("strOrgPhoto").value;
	var cap=document.getElementById("strCaption").value;

	var newcap="";

	param="&id="+id;
	
	var loc=document.getElementById("strPhoto");
	if(orgloc.length==0)
	{
		if(checkDataEntry(loc.value)==0)
		{
			jAlert('Please specify the image','BKK Town Message');
			return false;
		}
		else
		{
			var str=new String(loc.value.toUpperCase());
			var n=str.length;
			var i=n-1;
			var ext="";
			var h="";
			while((h!=".")&&(i>=0)&&(n!=0))
			{
				h = str.substr(i,1);
				i--;
			}
			ext=str.substr(i+2,3);
			ext2=str.substr(i+2,4);
			if((n!=0)&&(ext!="PNG")&&(ext!="JPG")&&(ext!="GIF")&&(ext2!="JPEG"))
			{
				alert("Only jpg, gif and png formats are allowed for the image file");
				return false;
			}
		}
	}
	
	if(checkDataEntry(cap)!=0)
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<cap.length; i++)
		{
			mycode = cap.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=cap.substr(i,1);
			}
			newcap=newcap+myChar;
		}
		param=param+"&cap="+newcap;
	}

	$("#loading")
	.ajaxStart(function(){
		$(this).show();
	})
	.ajaxComplete(function(){
		$(this).hide();
	});

	$.ajaxFileUpload
	(
		{
			url:'process_establishment_gallery.php?cs='+cs+param,
			secureuri:false,
			fileElementId:'strPhoto',
			dataType: 'json',
			success: function (data, status)
			{
				document.getElementById("uploadimagecontainer").style.display="none";
				fetchEstablishmentGallery('uploading');
			},
			error: function (data, status, e)
			{
				alert(e);
			}
		}
	)
}

function fetchEstablishmentGallery(act)
{
	document.getElementById("gallerytab").innerHTML="<br /><img src='images/lightgrayindicator24.gif' width='24' height='24' style='margin-right:5px;' /><span class='graytext'><i>"+act+"</i></span>";

	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "fetch_establishment_gallery.php", true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			document.getElementById("gallerytab").innerHTML=doc.responseText;
		}
	}
}

function doDeleteEstablishmentImage(id)
{
	jConfirm("Are you sure you want to delete this image?","BKK Town Message",function(ans)
	{
		//cancel the delete
		if(ans==false)
		{
			return false;
		}
		
		var doc = null; 
	
		// Make a new XMLHttp object
		 if (typeof window.ActiveXObject != 'undefined' ) 
		{ 
		   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		else 
		{ 
		   doc = new XMLHttpRequest(); 
		//doc.setRequestHeader 'Content-Type', 'text/xml';
		} 
		doc.onreadystatechange = handleStateChange;  
		  
		// Load the result from the response page
		// Note the response page can be any page that returns the right result. 
		// I used ASP. PHP, PERL... etc could acheive the same result
		 
		// ** As far a I know firefox will only load a document on the SAME domain!!
		//doc.setRequestHeader "Content-Type", "text/xml"
		doc.open("GET", "process_establishment_gallery.php?cs=del&id="+id, true);
		doc.send(null);
		//destination.innerHTML = doc.responseText;
		
		function handleStateChange()
		{        
			if (doc.readyState==4)
			{
				fetchEstablishmentGallery('loading');
			}
		}
	});
}

function srchsubmit()
{
	var stxt=document.getElementById("strSearch").value;
		
	if(checkDataEntry(stxt)==0)
	{
		jAlert('Please enter your search criteria','BKK Town Message');
		return false;
	}
	document.srchbox.submit();
}

function doNewEstablishmentEvent()
{
	document.getElementById("eventmaintcontainer").style.display="";
	document.getElementById("eventmaintcontainer").innerHTML="<img src='images/lightgrayindicator24.gif' width='24' height='24' style='margin-right:5px;' /><span class='graytext'><i>loading</i></span>";
	
	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "new_establishment_event.php", true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			document.getElementById("eventmaintcontainer").innerHTML=doc.responseText;
		}
	}
}

function doEditEstablishmentEvent(pagenum,id,scode)
{
	if(scode>0)
	{
		jAlert("This event is part of a series of events. Any changes will ony take effect in this event.",'BKK Town Message',function(ans)
		{
			if(ans==false)
			{
				return false;
			}
			displayEditEventScreen(pagenum,id);
		});
	}
	else
	{
		displayEditEventScreen(pagenum,id)
	}
}

function displayEditEventScreen(pagenum,id)
{
	//when press ok then do this
	document.getElementById("eventmaintcontainer").style.display="";
	document.getElementById("eventmaintcontainer").innerHTML="<img src='images/lightgrayindicator24.gif' width='24' height='24' style='margin-right:5px;' /><span class='graytext'><i>loading</i></span>";
	
	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "edit_establishment_event.php?id="+id+"&pagenum="+pagenum, true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			document.getElementById("eventmaintcontainer").innerHTML=doc.responseText;
		}
	}
}

function resetEventTimeBoxes(obj)
{
	if(obj.checked==true)
	{
		document.getElementById("intStartHour").className="graytext";
		document.getElementById("intStartHour").disabled="disabled";

		document.getElementById("intStartMinute").className="graytext";
		document.getElementById("intStartMinute").disabled="disabled";

		document.getElementById("intEndHour").className="graytext";
		document.getElementById("intEndHour").disabled="disabled";

		document.getElementById("intEndMinute").className="graytext";
		document.getElementById("intEndMinute").disabled="disabled";
}
	else
	{
		document.getElementById("intStartHour").className="";
		document.getElementById("intStartHour").disabled="";

		document.getElementById("intStartMinute").className="";
		document.getElementById("intStartMinute").disabled="";

		document.getElementById("intEndHour").className="";
		document.getElementById("intEndHour").disabled="";

		document.getElementById("intEndMinute").className="";
		document.getElementById("intEndMinute").disabled="";
	}
}

function resetRecurNumberBox(obj)
{
	if(obj.value=="norepeat")
	{
		document.getElementById("intRepeatEvery").className="graytext";
		document.getElementById("intRepeatEvery").disabled="disabled";
	}
	else
	{
		document.getElementById("intRepeatEvery").className="";
		document.getElementById("intRepeatEvery").disabled="";
	}
}

function checkEstablishmentEvent(cs,pagenum,id)
{
	var tt=document.getElementById("strTitle").value;
	var tid=document.getElementById("lngTypeId").value;
	var dt=document.getElementById("strDateBox").value;
	var ctrlad=document.getElementById("chkAllDay");
	var sh=document.getElementById("intStartHour").value;
	var sm=document.getElementById("intStartMinute").value;
	var eh=document.getElementById("intEndHour").value;
	var em=document.getElementById("intEndMinute").value;
	var desc=document.getElementById("strDescription").value;
	var lc=document.getElementById("strLocation").value;
	var url=document.getElementById("strUrl").value;
	var prc=document.getElementById("strPrice").value;
	var nt=document.getElementById("strNote").value;
	var chkcl=document.getElementById("chkClosed");

	var newtt="";
	var newdesc="";
	var newlc="";
	var newurl="";
	var newnt="";
	
	var param="&id="+id;
	
	if(checkDataEntry(tt)==0)
	{
		jAlert("Please enter the title",'BKK Town Message');
		return false;
	}
	else
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<tt.length; i++)
		{
			mycode = tt.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=tt.substr(i,1);
			}
			newtt=newtt+myChar;
		}
		param=param+"&tt="+newtt;
	}

	if(tid==0)
	{
		jAlert("Please select an event type",'BKK Town Message');
		return false;
	}
	else
	{
		param=param+"&tid="+tid;
	}

	if(dt=="Click icon to select =>")
	{
		jAlert("Please select an event date",'BKK Town Message');
		return false;
	}
	else
	{
		param=param+"&dt="+dt;
	}
	
	if((document.getElementById("lngTypeId").text=="Public Holiday") || (document.getElementById("lngTypeId").text=="Religous Holiday") || (document.getElementById("lngTypeId").text=="Festival"))
	{
		ctrlad.checked=true;
	}

	if((ctrlad.checked==false) && (sh==99) && (sm==99) && (eh==99) && (em==99))
	{
		jAlert("If this is not an all day event please select start time and end time",'BKK Town Message');
		return false;
	}
	else
	{
		if(ctrlad.checked==true)
		{
			param=param+"&aldy=1";
		}
		else
		{
			if(sh==99) 
			{
				jAlert("The start time is invalid",'BKK Town Message');
				return false;
			}
			else if(sm==99) 
			{
				jAlert("The start time is invalid",'BKK Town Message');
				return false;
			}
			else if(eh==99) 
			{
				jAlert("The end time is invalid",'BKK Town Message');
				return false;
			}
			else if(em==99) 
			{
				jAlert("The end time is invalid",'BKK Town Message');
				return false;
			}
			else
			{
				param=param+"&aldy=0&sh="+sh+"&sm="+sm+"&eh="+eh+"&em="+em;
			}
		}
	}
	
	if(cs=="add")
	{
		var optyly=document.getElementById("optYearly");
		var optmly=document.getElementById("optMonthly");
		var optwly=document.getElementById("optWeekly");
		if(optyly.checked==true)
		{
			param=param+"&rpt="+optyly.value;
		}
		else if(optmly.checked==true)
		{
			param=param+"&rpt="+optmly.value;
		}
		else if(optwly.checked==true)
		{
			param=param+"&rpt="+optwly.value;
		}
		param=param+"&rptnum="+document.getElementById("intRepeatEvery").value;
	}
	
	if(checkDataEntry(desc)!=0)
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<desc.length; i++)
		{
			mycode = desc.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else if(mycode==13)
			{
				myChar="";
			}
			else if(mycode==10)
			{
				myChar="<br />";
			}
			else
			{
				myChar=desc.substr(i,1);
			}
			newdesc=newdesc+myChar;
		}
		param=param+"&desc="+newdesc;
	}
	
	if(checkDataEntry(lc)!=0)
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<lc.length; i++)
		{
			mycode = lc.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=lc.substr(i,1);
			}
			newlc=newlc+myChar;
		}
		param=param+"&lc="+newlc;
	}
	
	if(checkDataEntry(url)!=0)
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<url.length; i++)
		{
			mycode = url.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=url.substr(i,1);
			}
			newurl=newurl+myChar;
		}
		param=param+"&url="+newurl;
	}

	param=param+"&prc="+prc;
	
	if(checkDataEntry(nt)!=0)
	{
		var i=0;
		var mycode=0;
		var myChar;

		for(i=0; i<nt.length; i++)
		{
			mycode = nt.charCodeAt(i);
			if(mycode==38)
			{
				myChar="(amp)";
			}
			else if(mycode==35)
			{
				myChar="(hash)";
			}
			else if(mycode==37)
			{
				myChar="(percentage)";
			}
			else if(mycode==43)
			{
				myChar="(plus)";
			}
			else
			{
				myChar=nt.substr(i,1);
			}
			newnt=newnt+myChar;
		}
		param=param+"&nt="+newnt;
	}
	
	var loc=document.getElementById("strImage");
	if(checkDataEntry(loc.value)!=0)
	{
		var str=new String(loc.value.toUpperCase());
		var n=str.length;
		var i=n-1;
		var ext="";
		var h="";
		while((h!=".")&&(i>=0)&&(n!=0))
		{
			h = str.substr(i,1);
			i--;
		}
		ext=str.substr(i+2,3);
		ext2=str.substr(i+2,4);
		if((n!=0)&&(ext!="PNG")&&(ext!="JPG")&&(ext!="GIF")&&(ext2!="JPEG"))
		{
			alert("Only jpg, gif and png formats are allowed for the front picture file");
			return false;
		}
	}
	
	if(chkcl.checked==true)
	{
		param=param+"&chkcl=1";
	}
	else
	{
		param=param+"&chkcl=0";
	}

	$("#loading")
	.ajaxStart(function(){
		$(this).show();
	})
	.ajaxComplete(function(){
		$(this).hide();
	});

	$.ajaxFileUpload
	(
		{
			url:'process_establishment_event.php?cs='+cs+param,
			secureuri:false,
			fileElementId:'strImage',
			dataType: 'json',
			success: function (data, status)
			{
				if(data.responseText=="exists")
				{
					jAlert("Sorry, the entered event already exists",'BKK Town Message');
					return false;
				}
				else
				{
					fetchEstablishmentEvent('saving',pagenum)
				}
			},
			error: function (data, status, e)
			{
				alert(e);
			}
		}
	)
}

function fetchEstablishmentEvent(act,pagenum)
{
	document.getElementById("eventtab").innerHTML="<img src='images/lightgrayindicator24.gif' width='24' height='24' style='margin-right:5px;' /><span class='graytext'><i>"+act+"</i></span>";

	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "fetch_establishment_event.php?pagenum="+pagenum, true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			document.getElementById("eventtab").innerHTML=doc.responseText;
		}
	}
}

function removeEstablishmentEventImage(id)
{
	jConfirm("Are you sure you want to remove the image?",'BKK Town Message',function(ans)
	{
		if(ans==false)
		{
			return false;
		}

		var doc = null; 
	 
		// Make a new XMLHttp object
		 if (typeof window.ActiveXObject != 'undefined' ) 
		{ 
		   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		else 
		{ 
		   doc = new XMLHttpRequest(); 
		//doc.setRequestHeader 'Content-Type', 'text/xml';
		} 
		doc.onreadystatechange = handleStateChange;  
		  
		// Load the result from the response page
		// Note the response page can be any page that returns the right result. 
		// I used ASP. PHP, PERL... etc could acheive the same result
		 
		// ** As far a I know firefox will only load a document on the SAME domain!!
		//doc.setRequestHeader "Content-Type", "text/xml"
		doc.open("GET", "process_establishment_event.php?cs=delpic&id="+id, true);
		doc.send(null);
		//destination.innerHTML = doc.responseText;
		
		function handleStateChange()
		{        
			if (doc.readyState==4)
			{
				var dblQuote=String.fromCharCode(34);
				var txt="";

				txt="<br />";
				txt=txt+"<label for='strImage'>";
				txt=txt+"Image:</label>";
				txt=txt+"<input id='strImage' name='strImage' type='file' size='33'>";
				txt=txt+"<br />";
				txt=txt+"<label>&nbsp;</label>";
				txt=txt+"<i>";
				txt=txt+"<a href='JavaScript:void(0);' onClick='clearGenBrowseFileBox("+dblQuote+"strImage"+dblQuote+")' class='smalllink' title=' click to clear your browsed file '>clear</a>";
				txt=txt+"</i>";

				document.getElementById("eventpiccontainer").innerHTML=txt;
			}
		}
	});
}

function doDeleteEstablishmentEvent(pagenum,id,scode)
{
	var del_msg="";
	if(scode==0)
	{
		del_msg="Are you sure you want to delete this event?";
		document.getElementById("strDelCase").value="one";
	}
	else
	{
		del_msg="Do you want to delete all occurences of this recurring event or just this one?";
		document.getElementById("strDelCase").value="series";
	}
	
	jConfirm(del_msg,"BKK Town Message",function(ans)
	{
		//cancel the delete
		if(ans==false)
		{
			return false;
		}
		else
		{
			if(scode==0)
			{
				ans="one";
			}
		}
		
		var doc = null; 
	
		// Make a new XMLHttp object
		 if (typeof window.ActiveXObject != 'undefined' ) 
		{ 
		   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		else 
		{ 
		   doc = new XMLHttpRequest(); 
		//doc.setRequestHeader 'Content-Type', 'text/xml';
		} 
		doc.onreadystatechange = handleStateChange;  
		  
		// Load the result from the response page
		// Note the response page can be any page that returns the right result. 
		// I used ASP. PHP, PERL... etc could acheive the same result
		 
		// ** As far a I know firefox will only load a document on the SAME domain!!
		//doc.setRequestHeader "Content-Type", "text/xml"
		doc.open("GET", "process_establishment_event.php?pagenum="+pagenum+"&cs=del&id="+id+"&delcase="+ans+"&scode="+scode, true);
		doc.send(null);
		//destination.innerHTML = doc.responseText;
		
		function handleStateChange()
		{        
			if (doc.readyState==4)
			{
				fetchEstablishmentEvent('loading',pagenum);
			}
		}
	});
}

function fetchEstablishmentStats()
{
	document.getElementById("tab6").innerHTML="<img src='images/lightgrayindicator24.gif' width='24' height='24' style='margin-right:5px;' /><span class='graytext'><i>loading</i></span>";

	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "fetch_establishment_stats.php", true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			document.getElementById("tab6").innerHTML=doc.responseText;
		}
	}
}

function expColDirSubCategory(id)
{
	if(document.getElementById("dirsubcatcontainer"+id).style.display=="none")
	{
		document.getElementById("dirsubcatcontainer"+id).style.display="";
	}
	else
	{
		document.getElementById("dirsubcatcontainer"+id).style.display="none";
	}
}

function expColDirEstablishment(id)
{
	if(document.getElementById("dircatestcontainer"+id).style.display=="none")
	{
		document.getElementById("dircatestcontainer"+id).style.display="";
	}
	else
	{
		document.getElementById("dircatestcontainer"+id).style.display="none";
	}
}

function expColDirectory(dvname)
{
	if(document.getElementById(dvname).style.display=="none")
	{
		document.getElementById(dvname).style.display="";
	}
	else
	{
		document.getElementById(dvname).style.display="none";
	}
}

function addUpBottomHomeAdClick(id)
{
	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "add_up_bottom_home_ad_click.php?id="+id, true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			//do nothing
		}
	}
}

function addUpSideHomeAdClick(id)
{
	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "add_up_side_home_ad_click.php?id="+id, true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			//do nothing
		}
	}
}

function addUpBottomCatHomeAdClick(id)
{
	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "add_up_bottom_category_ad_click.php?id="+id, true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			//do nothing
		}
	}
}

function addUpSideCatHomeAdClick(id)
{
	var doc = null; 
 
	// Make a new XMLHttp object
	 if (typeof window.ActiveXObject != 'undefined' ) 
	{ 
	   doc = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	else 
	{ 
	   doc = new XMLHttpRequest(); 
	//doc.setRequestHeader 'Content-Type', 'text/xml';
	} 
	doc.onreadystatechange = handleStateChange;  
	  
	// Load the result from the response page
	// Note the response page can be any page that returns the right result. 
	// I used ASP. PHP, PERL... etc could acheive the same result
	 
	// ** As far a I know firefox will only load a document on the SAME domain!!
	//doc.setRequestHeader "Content-Type", "text/xml"
	doc.open("GET", "add_up_side_category_ad_click.php?id="+id, true);
	doc.send(null);
	//destination.innerHTML = doc.responseText;
	
	function handleStateChange()
	{        
		if (doc.readyState==4)
		{
			//do nothing
		}
	}
}

function setOnOffCluetip(cs)
{
	if(cs=="off")
	{
		document.getElementById("strIgnoreCluetip").value="yes";
	}
	else
	{
		document.getElementById("strIgnoreCluetip").value="no";
	}
}
