function ClearValue(x)
{ 
	document.getElementById(x).value="";
}
function keypress(e)
{
	var Ucode=e.keyCode? e.keyCode : e.charCode
    if (Ucode == 13)
    {
     //write the code for submit
		ajax_request();
    }
}

function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
    {
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
}  

/**Ajax Request (Submits the form below through AJAX
 *               and then calls the ajax_response function)
 */
function ajax_request() {
	toggleBox('placediv',0); //turn off
	toggleBox('place1',0); // turn off
	toggleBox('place2',0); // turn off
	toggleBox('place3',0); // turn off
	toggleBox('place4',0); // turn off
  var place = document.getElementById('placename');	
  var submitTo = 'Places.php?place='+ place.value;
  //location.href = submitTo; //uncomment if you need for debugging
  http('GET', submitTo, ajax_response);
}

/**Ajax Response (Called when ajax data has been retrieved)
 *
 * @param   object  data   Javascript (JSON) data object received
 *                         through ajax call
 */
function ajax_response(data) {
  var a = new Array();
  var thePlace;
  var placeid = "place";
  var i;
  var id;
  var j = 1;
  eval("a = data;");
	var thePlaceName = document.getElementById('placename');
	thePlaceName.value = a[0];
	var hrefs = a.length -1;
	if (hrefs >0)
	{
		toggleBox('placediv',1);
		for (i = 1; i < hrefs;i = i +2 )
		{
			id = placeid + j++;
			thePlace = document.getElementById(id);
			thePlace.setAttribute('href','../' +a[i]);
			thePlace.childNodes[0].nodeValue = a[i+1];
			toggleBox(id,1);
		}
	}
	// window.alert( 'The value of the text node is:\n' + thePlace.childNodes[0].nodeValue );

  }
