
function processaddcityarea(action)
{
  // only continue if xmlHttp isn't void
	// initialize the request query string to empty string 
	params = "";
	
	// create var content map to the postURL's value
	//cid = document.getElementById('cid').value;
	
    // escape the values to be safely sent to the server 
    //content = encodeURIComponent(content);

	// send different parameters depending on action

	if (action == "addcityarea") // 刪除 publish 附加檔案
	{
		city = document.getElementById("city").value;
		area = document.getElementById("area").value;
		jage = document.getElementById("jage").value;
		params = "?action=addcityarea&city=" + city + "&area=" + area + "&jage=" + jage;
		//alert(params);
	}
	
    if (params)
	{
		var rand = Math.floor(Math.random()*5);
		params = params + "&rand=" + rand.toString
		cache.push(params);
	}

    // try to connect to the server
    try
    {
		if (action == "addcityarea") 
		{

			  //alert(params);
			  if ((xmlHttp2.readyState == 4 || xmlHttp2.readyState == 0) && cache.length>0)
			  {
					var cacheEntry = cache.shift();
					xmlHttp2.open("GET", "/process_ajax.php" + params + cacheEntry, true);
					xmlHttp2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					xmlHttp2.onreadystatechange = addcityarea;
					xmlHttp2.send(null);
			  }
			  else
			  {
					setTimeout("process();", 1000);  
			  }
		}
		
    }
    // display the error in case of failure
    catch (e)
    {
	  displayError(e.toString());
    }
}

function processcontainer(action,self,npage)
{
	//alert(action);
	
	params = "";

	if (action == "container")
	{
		params = "?npage=" + npage;	
		
	}
	
    if (params)
	{
		var rand = Math.floor(Math.random()*5);
		params = params + "&rand=" + rand.toString
		cache.push(params);
	}

    // try to connect to the server
    try
    {
		if (action == "container") 
		{
			  //alert(params);
			  if ((xmlHttp1.readyState == 4 || xmlHttp1.readyState == 0) && cache.length>0)
			  {
					//alert(params);
					var cacheEntry = cache.shift();
					xmlHttp1.open("GET", self + params + cacheEntry, true);
					xmlHttp1.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					xmlHttp1.onreadystatechange = container;
					xmlHttp1.send(null);
			  }
			  else
			  {
					setTimeout("process();", 1000);  
			  }
		}
		
    }
    // display the error in case of failure
    catch (e)
    {
	  displayError(e.toString());
    }
}




/* handles keydown to detect when enter is pressed */
function handleKey(e) 
{
  // get the event
  e = (!e) ? window.event : e;
  // get the code of the character that has been pressed        
  code = (e.charCode) ? e.charCode :
         ((e.keyCode) ? e.keyCode :
         ((e.which) ? e.which : 0));
  // handle the keydown event       
  if (e.type == "keydown") 
  {
    // if enter (code 13) is pressed
    if(code == 13)
    {
      // send the current message  
      process("postURL", "doPostURL");
    }
  }
}