
// Set the delimiter to something other than | when defining condition values
var http_request = false;

function pointinfo(val) {
	//make the call

	http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
	    http_request = new XMLHttpRequest();
	    if (http_request.overrideMimeType) {
		http_request.overrideMimeType('text/xml');
		// See note below about this line
	    }
	} else if (window.ActiveXObject) { // IE
	    try {
		http_request = new ActiveXObject("Msxml2.XMLHTTP");
	    } catch (e) {
		try {
		    http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	    }
	}

	if (!http_request) {
	    alert('Giving up :( Cannot create an XMLHTTP instance');
	    return false;
	}

	//get the selected category
	var box = val;
	var pointsel = box.options[box.selectedIndex].value;
	http_request.onreadystatechange = alertContents;
	http_request.open('POST', "pointinformation.action", true);
	http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	http_request.send("endpointid=" + pointsel);
		

}
	   

function alertContents() {
	
	    if (http_request.readyState == 4) {
	            if (http_request.status == 200) {

			
			var xmldoc = http_request.responseXML;

			//root tag
			var roottag = xmldoc.getElementsByTagName('root')[0];
			//point name
			var pointname_node = roottag.getElementsByTagName('name')[0];				
			var point = pointname_node.childNodes[0].nodeValue; 

			/*var cat_node = xmldoc.getElementsByTagName('category')[0];
			var cat_node_desc = cat_node.getElementsByTagName('descriptionen')[0];
			var cat = cat_node_desc.childNodes[0].nodeValue;
			*/			

			var address_node = roottag.getElementsByTagName('street')[0];
			var street = "";

			var addresschild = address_node.childNodes[0];

			if(addresschild != null){
				street = addresschild.nodeValue;
			}


			var streetno_desc = roottag.getElementsByTagName('streetno')[0];
			var streetno = "";
			var streetnochild = streetno_desc.childNodes[0];
			if( streetnochild != null){
				streetno = streetnochild.nodeValue;
			}

			if(streetno=="null"){
				streetno="";
			}

			var loc_node = roottag.getElementsByTagName('postcode')[0];
			var postcode = loc_node.childNodes[0].nodeValue;
			var area_desc = roottag.getElementsByTagName('area')[0];
			var area = "";
			var areachild = area_desc.childNodes[0];
			if(areachild != null){
				area = areachild.nodeValue;
			}

			if(area=="null"){
				area="";
			}

			//telephone
			//var tel_desc = roottag.getElementsByTagName('tel')[0];
			var tel = "";
			//var telchild = tel_desc.childNodes[0];
			//if(telchild != null){
			//	tel = telchild.nodeValue;
			//}

			//if(tel=="null"){
			//	tel="";
			//}

			//telephone
			//var email_desc = roottag.getElementsByTagName('email')[0];
			var email = "";
			//var emailchild = email_desc.childNodes[0];
			//if(emailchild != null){
			//	email = emailchild.nodeValue;
			//}

			//if(email=="null"){
			//	email="";
			//}

			//nearto
			var nearto = "";
			var nearto_desc = roottag.getElementsByTagName('nearto')[0];
			var neartochild = nearto_desc.childNodes[0];
			if(neartochild != null){
				nearto = neartochild.nodeValue;
			}

			if(nearto=="null"){
				nearto="";
			}

			//homepage
			//var homepage_desc = roottag.getElementsByTagName('homepage')[0];
			var homepage = "";
			//var homepagechild = homepage_desc.childNodes[0];
			//if(homepagechild != null){
			//	homepage = homepagechild.nodeValue;
			//}

			//if(homepage=="null"){
			//	homepage="";
			//}

			point+="<br>" + streetno + "&nbsp;" + street + "<br>postcode " + postcode + "&nbsp;" + area;

			if (tel!=""){
				point+="<br>" + tel;
			}
			if (email!=""){
				point+="<br>" + email;
			}
			if (nearto!=""){
				point+="<br>" + nearto;
			}
			if (homepage!=""){
				point+="<br>" + homepage;
			}
			document.getElementById("pointnfodiv").innerHTML=point;
			document.getElementById("pointinfodesc").innerHTML=infdesc;			
			
			
		}  else {
                //alert('There was a problem with the request.');
            }
	
    }
    
}


