// PUBLIC WEB SERVICE PROXY - used by public API

var publicWebServiceKmlUrl = 'http://www.netescape-secure.co.uk/busmappingservice/kml';
var publicWebServiceUrl = 'http://www.netescape-secure.co.uk/busmappingservice/BusesPublic.asmx';

function locationmap_getRoutePolylineJS(routeId, _onSuccessDelegate, _onFailureDelegate)
{
        new Ajax.Request(publicWebServiceUrl + '/getRoutePolyLineJs',
                {   postBody:"{routeid:'" + routeId + "'}",
                    method: 'post', contentType:'application/json; charset=utf-8',
                    onSuccess: _onSuccessDelegate,
                    onFailure: _onFailureDelegate});    
}

function locationmap_getRoutePolyline(routeId, _onSuccessDelegate, _onFailureDelegate)
{
        new Ajax.Request(publicWebServiceUrl + '/getRoutePolyLineStandard',
                {   postBody:"{routeid:'" + routeId + "'}",
                    method: 'post', contentType:'application/json; charset=utf-8',
                    onSuccess: _onSuccessDelegate,
                    onFailure: _onFailureDelegate});
}

function locationmap_getRoutePolyline(routeId, weight, _onSuccessDelegate, _onFailureDelegate)
{
        new Ajax.Request(publicWebServiceUrl + '/getRoutePolyLine',
                {   postBody:"{routeid:'" + routeId + "',weight:'" + weight + "'}",
                    method: 'post', contentType:'application/json; charset=utf-8',
                    onSuccess: _onSuccessDelegate,
                    onFailure: _onFailureDelegate
                });
            }

function locationmap_getRouteMapPolyline(routeId, routeMapId, weight, _onSuccessDelegate, _onFailureDelegate) {
    new Ajax.Request(publicWebServiceUrl + '/getRouteMapPolyLine',
    { postBody: "{routeid:'" + routeId + "',routemapid:'" + routeMapId + "',weight:'" + weight + "'}",
        method: 'post', contentType: 'application/json; charset=utf-8',
        onSuccess: _onSuccessDelegate,
        onFailure: _onFailureDelegate
    });
}



function locationmap_getRouteStops(routeId, _onSuccessDelegate, _onFailureDelegate)
{
        new Ajax.Request(publicWebServiceUrl + '/getRouteStops',
                {   postBody:"{routeid:'" + routeId + "'}",
                    method: 'post', contentType:'application/json; charset=utf-8',
                    onSuccess: _onSuccessDelegate,
                    onFailure: _onFailureDelegate});    
}

function locationmap_getRouteTimetableStops(routeId, _onSuccessDelegate, _onFailureDelegate)
{
        new Ajax.Request(publicWebServiceUrl + '/getRouteTimetableStops',
                {   postBody:"{routeid:'" + routeId + "'}",
                    method: 'post', contentType:'application/json; charset=utf-8',
                    onSuccess: _onSuccessDelegate,
                    onFailure: _onFailureDelegate});    
}

function servicemap_getServiceInfo(serviceid, _onSuccessDelegate, _onFailureDelegate)
{
        new Ajax.Request(publicWebServiceUrl + '/getServiceInfo',
                {   postBody:"{serviceid:'" + serviceid + "'}",
                    method: 'post', contentType:'application/json; charset=utf-8',
                    onSuccess: _onSuccessDelegate,
                    onFailure: _onFailureDelegate});    
}


function route_getRealtimeData(stopid, serviceid, routeid, url, relativeXslPath, _onSuccessDelegate, _onFailureDelegate)
{
    new Ajax.Request(publicWebServiceUrl + '/getDepartureData',
	{ postBody: "{stopid:'" + stopid + "',serviceid:'" + serviceid + "',routeid:'" + routeid + "',url:'" + url + "',relativeXslPath:'" + relativeXslPath + "'}",
	    method: 'post', contentType:'application/json; charset=utf-8',
	    onSuccess: _onSuccessDelegate,
	    onFailure: _onFailureDelegate});
}       
  
function stop_getServicesByStop(stopid, _onSuccessDelegate, _onFailureDelegate)
{
	new Ajax.Request(publicWebServiceUrl+'/getServicesByStop',
	{   postBody:"{stopid:'" + stopid + "'}",
	    method: 'post', contentType:'application/json; charset=utf-8',
	    onSuccess: _onSuccessDelegate,
	    onFailure: _onFailureDelegate});
}       
    


function ws_getRoutePOIs(routeId, _onSuccessDelegate, _onFailureDelegate)
{
        new Ajax.Request(publicWebServiceUrl+'/getRoutePOIs',
                {   postBody:"{routeid:'" + routeId + "'}",
                    method: 'post', contentType:'application/json; charset=utf-8',
                    onSuccess: _onSuccessDelegate,
                    onFailure: _onFailureDelegate});
}  

function ws_getRoutePOILiness(routeId, _onSuccessDelegate, _onFailureDelegate)
{
        new Ajax.Request(publicWebServiceUrl+'/getRoutePOILines',
                {   postBody:"{routeid:'" + routeId + "'}",
                    method: 'post', contentType:'application/json; charset=utf-8',
                    onSuccess: _onSuccessDelegate,
                    onFailure: _onFailureDelegate});
} 



function cleanResponse(_unclean)
{
		var val = _unclean;
		val = val.substring(5);
		val = val.substring(0, val.length-2);
		val = val.replace(/\\\"/g, "'");
		val = val.replace(/\"/g, ' ');
		val = val.replace("\"", "");
		return val;
}

function cleanResponse2(_unclean)
{
		var val = _unclean;
		val = val.substring(5);
		val = val.substring(0, val.length-2);
		val = val.substring(1, val.length-1);
		val = val.replace(/\\\"/g, '"');
		return val;
}

function ajaxError(error)
{
        var val = error.responseText;
        //alert("An AJAX error occured");
        //alert(val);

}