// requires jquery v1.2.6

function createNamespace(n){var p=n.split('.'),b=window,s;while(s=p.shift())b=!b[s]?b[s]={}:b[s];}
createNamespace('planeteye.map.services');
createNamespace('planeteye.map.services.state');

if (!planeteye.map.services.state.basePath) {
    planeteye.map.services.state.basePath = '';
}


// make sure this is in a namespace
// planeteye.services.get

// make generic ajax call

// public methods and members

// TODO - get markers
/**
 * Get a full set of points, for the categories passed in.  These are not summarized into
 * dots, rather individual points are returned.
 *
 * Example usage:
 * planeteye.map.services.pointsGetForSet('map.5664,map.5633', 123, 234, 90, 89, -1, successFn, errorFn, args);
 * 
 * function successFn(points, args, datasetNames) { 
 *   points[i]["@lat"]
 *   points[i]["@long"]
 *   points[i]["@pointid"] // 'place.<placeid>' or 'photo.<mediaid>'
 *   points[i]["@type"] = 'photo|place'
 * }
 * function errorFn(errorMsg) { }
 */
planeteye.map.services.pointsGetForSet = function(datasetNames, latNorth, latSouth, lonWest, lonEast, zoom, customerId, successHandler, errorHandler, args) 
{
    // return a list of dots
    // return a list of categories
    return $.ajax({
        type: "POST",
        url: planeteye.map.services.state.basePath + "/webservice/flashservice.asmx/GetPointsJSON",
        data: "{'LatitudeNorth':'" + latNorth.toString() + "',"
              +"'LatitudeSouth':'" + latSouth.toString() + "',"
              +"'LongitudeWest':'" + lonWest.toString() + "',"
              +"'LongitudeEast':'" + lonEast.toString() + "',"
              +"'Zoom':'" + zoom.toString() + "',"
              +"'CustomerID':'" + customerId.toString()+ "',"
              +"'Sets':'" + datasetNames + "'}",
        contentType: "application/json; charset=utf-8", 
        dataType: "json",

        success: function(xhr, status) {
        
                //this is on purpose .net webservices
                //return strings of json as a json string
                //hence eval twice. dont ask....
//                xhr = xhr.replace("\\\"","\"");
                var obj = eval("(" + xhr + ")");
                
                if (obj != null && obj.points != null) {
                    var pointArray;
                    if (obj.points.point instanceof Array) {
                        pointArray = obj.points.point;
                    } else {
                        pointArray = new Array();
                        if (obj.points.point) {
                            pointArray[0] = obj.points.point;
                        }
                    }
                    successHandler(pointArray, args, datasetNames);
                } else {
                    //errorHandler("no points");
                }
        },

        error: function(xhr, status, error) {
            //var err = JSON.parse(xhr.responseText);
            errorHandler(status, args);
        }
    });

}

	

/**
 * Add a particular point to a set (currently only works for maps).
 */	
planeteye.map.services.pointAddToSet = function(datasetNames, pointId, customerId, successHandler, errorHandler, args) {

    // return a list of dots
    // return a list of categories
    return $.ajax({
        type: "POST",
        url: planeteye.map.services.state.basePath + "/webservice/flashservice.asmx/AddPointsToMapJSON",
        data: "{'Sets':'" + datasetNames + "',"
              +"'PointID':'" + pointId + "',"
              +"'CustomerID':'" + customerId.toString() + "'}",
        contentType: "application/json; charset=utf-8", 
        dataType: "json",

        success: function(xhr, status) {
                var obj = eval("(" + xhr + ")");
               
                if (obj != null && obj > 0) {
                    successHandler(args);
                } else {
                    errorHandler(args);
                }
        },

        error: function(xhr, status, error) {
            //var err = JSON.parse(xhr.responseText);
            errorHandler(status, args);
        }
    });

}


/**
 * Remove a particular point to a set (currently only works for maps).
 */	
planeteye.map.services.pointRemoveFromSet = function(datasetNames, pointId, customerId, successHandler, errorHandler, args) {

    // return a list of dots
    // return a list of categories
    return $.ajax({
        type: "POST",
        url: planeteye.map.services.state.basePath + "/webservice/flashservice.asmx/RemovePointsFromMapJSON",
        data: "{'Sets':'" + datasetNames + "',"
              +"'PointID':'" + pointId + "',"
              +"'CustomerID':'" + customerId.toString() + "'}",
        contentType: "application/json; charset=utf-8", 
        dataType: "json",

        success: function(xhr, status) {
                var obj = eval("(" + xhr + ")");
               
                if (obj != null && obj > 0) {
                    successHandler(xhr,args);
                } else {
                    successHandler(xhr,args);
                    //errorHandler(args);
                }
        },

        error: function(xhr, status, error) {
            //var err = JSON.parse(xhr.responseText);
            errorHandler(status, args);
        }
    });

}


/**
 * Update the details for a single travelpack place item (place in a travel pack)
 */
planeteye.map.services.updateTPKPlaceItem = function(tpkid, placeItemId, title, description, successHandler, errorHandler, args) {
    // return a list of dots
    // return a list of categories
    return $.ajax({
        type: "POST",
        url: planeteye.map.services.state.basePath + "/webservice/flashservice.asmx/UpdateTPKPlaceItemJSON",
        data: "{'travelPackId':'" + tpkid.toString() + "',"
              +"'travelPackPlaceItemId':'" + placeItemId.toString() + "',"
              +"'title':'" + title+ "',"
              +"'description':'" + description + "'}",
        contentType: "application/json; charset=utf-8", 
        dataType: "json",

        success: function(xhr, status) {
        
                successHandler(xhr,args);
                
                
        },

        error: function(xhr, status, error) {
            //var err = JSON.parse(xhr.responseText);
            errorHandler(status, args);
        }
    });
}


/**
 * Update the details for a single travelpack place item (place in a travel pack)
 */
planeteye.map.services.travelPackUpdateTitleDescription = function(datasetName, title, description, tabConfig, mapParams, successHandler, errorHandler, args) {

    return $.ajax({
        type: "POST",
        url: planeteye.map.services.state.basePath + "/webservice/flashservice.asmx/TravelPacksUpdateTitleDescription",
        data: "{'set':'" + datasetName + "',"
              +"'title':'" + escapeSingleQuotes(title) + "',"
              +"'description':'" + escapeSingleQuotes(description) + "',"
              +"'mapParams':'" + escapeSingleQuotes(mapParams) + "',"
              +"'tabConfig':'" + escapeSingleQuotes(tabConfig) + "'}",
        contentType: "application/json; charset=utf-8", 
        dataType: "json",

        success: function(xhr, status) {
            successHandler(xhr, args);
        },

        error: function(xhr, status, error) {
            errorHandler(status, args);
        }
    });
}

/**
 * Get the place and/or media within a point.  This will only ever return a single place/photo.
 *
 * Example usage:
 * planeteye.map.services.pointsGetContents('map.109', 'place.123', 9, -1, successFn, errorFn);
 * 
 * function successFn(point) { 
 *   point.photo['@id']
 *   point.photo['@lat']
 *   point.photo['@lng']
 *   point.photo.pathMedium['@path']
 *   point.photo.planeteyeUrl
 *   point.place['@id']
 *   point.place['@lat']
 *   point.place['@lng']
 *   point.place.title
 *   point.place.description['#cdata-section']
 *   point.place.address
 *   point.place.phone
 *   point.place.rating
 *   point.place.planeteyeUrl
 *   point.place.categories.category[j]['@name']
 *   point.place.categories.category[j]['@code']
 * }
 * function errorFn(point) { 
 */
planeteye.map.services.pointGetContents = function(pointId, customerId, sets, successHandler, errorHandler, args) 
{
    // return a list of dots
    // return a list of categories
    return $.ajax({
        type: "POST",
        url: planeteye.map.services.state.basePath + "/webservice/flashservice.asmx/GetPointContentsJSON",
        data: "{'PointID':'" + pointId.toString() + "',"
              +"'CustomerID':'" + customerId.toString()+ "',"
              +"'Sets':'" + sets + "'}",
        contentType: "application/json; charset=utf-8", 
        dataType: "json",

        success: function(xhr, status) {
        
                //this is on purpose .net webservices
                //return strings of json as a json string
                //hence eval twice. dont ask....
//                xhr = xhr.replace("\\\"","\"");
                var obj = eval("(" + xhr + ")");
                
                if (obj != null && obj.point) {
                    var point = {};
                    point['@isowner'] = obj.point['@isowner'];
                    
                    if (obj.point.place) {
                        point.place = obj.point.place;
                    } else if (obj.point.photo) {
                        point.photo = obj.point.photo;
                    }
                    successHandler(point, args);
                } else {
                    errorHandler("no results", args);
                }
        },

        error: function(xhr, status, error) {
            //var err = JSON.parse(xhr.responseText);
            errorHandler(status, args);
        }
    });
}


/**
 * Get a full set of dots, for the categories passed in.
 *
 * Example usage:
 * planeteye.map.services.dotsGetForSet('photos,lodging', 123, 234, 90, 89, -1, successFn, errorFn, args);
 *
 * function successFn(dots, args, datasetNames) { 
 *   dots[i]["@dotid"]
 *   dots[i]["@lat"]
 *   dots[i]["@long"]
 *   dots[i].BoundingBox.East
 *   dots[i].BoundingBox.West
 *   dots[i].BoundingBox.North
 *   dots[i].BoundingBox.South
 *   dots[i].media["@count"]
 *   dots[i].places.place[j]["@categoryID"]
 *   dots[i].places.place[j]["@count"]
 * }
 * function errorFn(errorMsg) { }
 */
planeteye.map.services.dotsGetForSet = function(datasetNames, latNorth, latSouth, lonWest, lonEast, zoom, customerId, successHandler, errorHandler, args) 
{
    // return a list of dots
    // return a list of categories
    return $.ajax({
        type: "POST",
        url: planeteye.map.services.state.basePath + "/webservice/flashservice.asmx/GetDotsJSON",
        data: "{'LatitudeNorth':'" + latNorth.toString() + "',"
              +"'LatitudeSouth':'" + latSouth.toString() + "',"
              +"'LongitudeWest':'" + lonWest.toString() + "',"
              +"'LongitudeEast':'" + lonEast.toString() + "',"
              +"'Zoom':'" + zoom.toString() + "',"
              +"'CustomerID':'" + customerId.toString()+ "',"
              +"'Sets':'" + datasetNames + "'}",
        contentType: "application/json; charset=utf-8", 
        dataType: "json",

        success: function(xhr, status) {
        
                //this is on purpose .net webservices
                //return strings of json as a json string
                //hence eval twice. dont ask....
//                xhr = xhr.replace("\\\"","\"");
                var obj = eval("(" + xhr + ")");
                
                if (obj != null && obj.grid_data != null) {
                    var dotArray;
                    if (obj.grid_data.dot instanceof Array) {
                        dotArray = obj.grid_data.dot;
                    } else {
                        dotArray = new Array();
                        dotArray[0] = obj.grid_data.dot;
                    }
                    successHandler(dotArray, args, datasetNames);
                } else {
                    // no results
                    //errorHandler("no results");
                }
        },

        error: function(xhr, status, error) {
            //var err = JSON.parse(xhr.responseText);
            errorHandler(status, args);
        }
    });
}


// FUTURE METHOD: text searches
planeteye.map.services.dotsGetForSearch = function(searchText) { }



/**
 * Get all places and/or media within a dot.
 *
 * Example usage:
 * planeteye.map.services.dotsGetContents('photos,lodging', 123, -1, 89, -1, successFn, errorFn);
 *
 * function successFn(dots) { 
 *   dot["@dotid"]
 *   dot["@defaultIndex"]
 *   dot.photos[i]['@id']
 *   dot.photos[i]['@lat']
 *   dot.photos[i]['@lng']
 *   dot.photos[i].pathMedium['@path']
 *   dot.photos[i].planeteyeUrl
 *   dot.places[i]['@id']
 *   dot.places[i]['@lat']
 *   dot.places[i]['@lng']
 *   dot.places[i].title
 *   dot.places[i].description['#cdata-section']
 *   dot.places[i].address
 *   dot.places[i].phone
 *   dot.places[i].rating
 *   dot.places[i].planeteyeUrl
 *   dot.places[i].categories.category[j]['@name']
 *   dot.places[i].categories.category[j]['@code']
 * }
 * function errorFn(errorMsg) { }
 */
planeteye.map.services.dotsGetContents = function(datasetNames, dotId, defaultItemId, zoom, customerId, page, perPage, successHandler, errorHandler, args)
{
    // return a list of dots
    // return a list of categories
    return $.ajax({
        type: "POST",
        url: planeteye.map.services.state.basePath + "/webservice/flashservice.asmx/GetDotContentsJSON",
        data: "{'DotID':'" + dotId.toString() + "',"
              +"'DefaultItemID':'" + defaultItemId + "',"
              +"'Zoom':'" + zoom.toString() + "',"
              +"'CustomerID':'" + customerId.toString()+ "',"
              +"'Page':'" + page.toString() + "',"
              +"'PerPage':'" + perPage.toString()+ "',"
              +"'Sets':'" + datasetNames + "',"
              +"'Extended':'false'}",
        contentType: "application/json; charset=utf-8", 
        dataType: "json",

        success: function(xhr, status) {
        
            //this is on purpose .net webservices
            //return strings of json as a json string
            //hence eval twice. dont ask....
//            xhr = xhr.replace(/\\\"/g,'"'); // replace all
//            xhr = xhr.replace("\\\"","\"");
            var obj = eval("(" + xhr + ")");
            
            if (obj != null && obj.dot != null) {
                var pdot = {};
                
                //pdot = new Array();
                //pdot = obj.dot;
                pdot = new Array();
                pdot["@dotid"] = obj.dot["@dotid"];
                pdot["@isowner"] = obj.dot["@isowner"];
                
                // deal with the places
                if (obj.dot.places.place && obj.dot.places.place instanceof Array) {
                    pdot.places = obj.dot.places.place;
                    pdot.places["@defaultIndex"] = obj.dot.places["@defaultIndex"];
                    pdot.places["@page"] = obj.dot.places["@page"];
                    pdot.places["@perPage"] = obj.dot.places["@perPage"];
                } else {
                    pdot.places = new Array();
                    if (obj.dot.places.place) {
                        pdot.places[0] = obj.dot.places.place;
                        pdot.places["@defaultIndex"] = "0";
                        pdot.places["@page"] = "1";
                        pdot.places["@perPage"] = "1";
                    }
                }
               
                // deal with the media 
                if (obj.dot.photos.photo && obj.dot.photos.photo instanceof Array) {
                    pdot.photos = obj.dot.photos.photo;
                    pdot.photos["@defaultIndex"] = obj.dot.photos["@defaultIndex"];
                    pdot.photos["@page"] = obj.dot.photos["@page"];
                    pdot.photos["@perPage"] = obj.dot.photos["@perPage"];
                } else {
                    pdot.photos = new Array();
                    if (obj.dot.photos.photo) {
                        pdot.photos[0] = obj.dot.photos.photo;
                        pdot.photos["@defaultIndex"] = "0";
                        pdot.photos["@page"] = "1";
                        pdot.photos["@perPage"] = "1";
                    }
                }
                
                successHandler(pdot,args);
            } else {
                errorHandler("no results");
            }
        },

        error: function(xhr, status, error) {
            //var err = JSON.parse(xhr.responseText);
            errorHandler(xhr, status, error);
        }
    });
}



/**
 * Gets a full set of points and dots for the categories passed in.
 *
 * Example usage:
 * planeteye.map.services.overlaysGetForSet('map.5664,map.5633,attractions', 123, 234, 90, 89, -1, successFn, errorFn, args);
 * 
 * function successFn(points, dots, args, datasetNames) { 
 *   points[i]["@lat"]
 *   points[i]["@long"]
 *   points[i]["@pointid"] // 'place.<placeid>' or 'photo.<mediaid>'
 *   points[i]["@type"] = 'photo|place'
 * }
 * function errorFn(errorMsg, args) { }
 */
planeteye.map.services.overlaysGetForSet = function(datasetNames, latNorth, latSouth, lonWest, lonEast, zoom, customerId, successHandler, errorHandler, args) 
{
    // return a list of dots
    // return a list of categories
    return $.ajax({
        type: "POST",
        url: planeteye.map.services.state.basePath + "/webservice/flashservice.asmx/GetOverlaysJSON",
        data: "{'LatitudeNorth':'" + latNorth.toString() + "',"
              +"'LatitudeSouth':'" + latSouth.toString() + "',"
              +"'LongitudeWest':'" + lonWest.toString() + "',"
              +"'LongitudeEast':'" + lonEast.toString() + "',"
              +"'Zoom':'" + zoom.toString() + "',"
              +"'CustomerID':'" + customerId.toString()+ "',"
              +"'Sets':'" + datasetNames + "'}",
        contentType: "application/json; charset=utf-8", 
        dataType: "json",

        success: function(xhr, status) {
        
            //this is on purpose .net webservices
            //return strings of json as a json string
            //hence eval twice. dont ask....
//            xhr = xhr.replace("\\\"","\"");
            var obj = eval("(" + xhr + ")");
            
            if (obj != null && obj.overlays != null) {
                var pointArray;
             
                if (obj.overlays.points != null) {
                    // handle the points 
                    if (obj.overlays.points.point instanceof Array) {
                        pointArray = obj.overlays.points.point;
                    } else {
                        pointArray = new Array();
                        if (obj.overlays.points.point) {
                            pointArray[0] = obj.overlays.points.point;
                        }
                    }
                 
                    // is the current user the owner of this dataset?
                    if (obj.overlays.points['@isowner'] && obj.overlays.points['@isowner'] == 'true') {
                        pointArray['@isowner'] = true;
                    } else {
                        pointArray['@isowner'] = false;
                    }
                } 
                
                var dotArray;
                
                if (obj.overlays.grid_data != null) {
                    if (obj.overlays.grid_data.dot instanceof Array) {
                        dotArray = obj.overlays.grid_data.dot;
                    } else {
                        dotArray = new Array();
                        dotArray[0] = obj.overlays.grid_data.dot;
                    }
                }
               
                // successHandler must deal with both sets of data..
                successHandler(pointArray, dotArray, args, datasetNames);
            } else {
                //errorHandler("no points");
            }
        },

        error: function(xhr, status, error) {
            //var err = JSON.parse(xhr.responseText);
            errorHandler(status, args);
        }
    });

}

/**
 * Get a full set of categories, and category codes.
 *
 * Example usage:
 * planeteye.map.services.categoriesGet(successFn, errorFn);
 *
 * function successFn(categories) { 
 *   var categoryId = categories[0].["@CategoryID"]
 *   var categoryName = categories[0].["@Name"]
 *   var categoryCode = categories[0].["@Code"]
 *   var categoryColor = categories[0].["@Color"]
 *   var categoryBorderColor = categories[0].["@BorderColor"]
 * }
 * function errorFn(errorMsg) { }
 */
planeteye.map.services.categoriesGet = function(successHandler, errorHandler) {
    // return a list of categories
    return $.ajax({
        type: "POST",
        url: planeteye.map.services.state.basePath + "/webservice/flashservice.asmx/GetCategoriesJSON",
        data: "{ }",
        contentType: "application/json; charset=utf-8", 
        dataType: "json",

        success: function(xhr, status) {
        
                //this is on purpose .net webservices
                //return strings of json as a json string
                //hence eval twice. dont ask....
//                xhr = xhr.replace("\\\"","\"");
                var obj = eval("(" + xhr + ")");
                if (obj != null && obj.Categories != null) {
                    categoryArray = obj.Categories.Category;
                    successHandler(categoryArray);
                }
        },

        error: function(xhr, status, error) {
            //var err = JSON.parse(xhr.responseText);
            errorHandler(status);
        }
    });
}

/**
 * Gets the list of places to display in the sidebar based on the category passed in and the bounding box.
 */
planeteye.map.services.getSidebarPlaces  = function(north,south,east,west,zoom, pageNum,customerId,categoryId,successHandler,failureHandler,args,requestQueue){
    requestQueue.push($.ajax({

    type: "POST",

    //url: planeteye.map.services.state.basePath + "/DestinationMap.aspx/getSidebarPlaces",
    url: planeteye.map.services.state.basePath + "/webservice/flashservice.asmx/getSidebarPlaces",

    data: "{'north':'"+north.toString()+"',"
          +"'south':'"+south.toString()+"',"
          +"'east':'"+east.toString()+"',"
          +"'west':'"+west.toString()+"',"
          +"'zoom':'"+zoom.toString()+"',"
           +"'pageNum':'"+pageNum.toString()+"',"
           +"'customerId':'"+customerId.toString()+"',"
          +"'categoryId':'"+categoryId.toString()+"'}",  
                  
       
    contentType: "application/json; charset=utf-8", 

    dataType: "json",

    success: function(xhr, status) {
           
            successHandler(xhr,args);
       
    },

    error: function(xhr, status, error) {

        errorHandler(xhr,args);

    }

    }));
}

/**
 * Gets the list of photos to display in the sidebar based on the category passed in and the bounding box.
 */
planeteye.map.services.getSidebarPhotos  = function(north,south,east,west,zoom, pageNum,customerId,successHandler,failureHandler,args,requestQueue){
    requestQueue.push(
            $.ajax({

            type: "POST",

            url: planeteye.map.services.state.basePath + "/webservice/flashservice.asmx/getSidebarMedia",

            data: "{'north':'"+north.toString()+"',"
                  +"'south':'"+south.toString()+"',"
                  +"'east':'"+east.toString()+"',"
                  +"'west':'"+west.toString()+"',"
                  +"'pageNum':'"+pageNum.toString()+"',"
                  +"'customerId':'"+customerId.toString()+"',"
                   +"'zoom':'"+zoom.toString()+"'}", 
                    

            contentType: "application/json; charset=utf-8", 

            dataType: "json",

            success: function(xhr, status) {
                    
                 successHandler(xhr,args);   
            },

            error: function(xhr, status, error) {

                errorHandler(xhr,args);
            }

            }));

}
/**
 * Gets the list of travelpack items to display in the sidebar in the locations section based on the category passed in and the bounding box.
 */
planeteye.map.services.getTravelPackItems = function(north,south,east,west,zoom,travelPackId,pageNum,pageSize,successHandler,failureHandler,args,requestQueue){
    
    
    requestQueue.push($.ajax({

    type: "POST",

    url: planeteye.map.services.state.basePath + "/ContentManagement/TravelPackMapView.aspx/getTravelPackItems",

    data: "{'north':'"+north.toString()+"',"
          +"'south':'"+south.toString()+"',"
          +"'east':'"+east.toString()+"',"
          +"'west':'"+west.toString()+"',"
          +"'zoom':'"+zoom.toString()+"',"
           +"'pageNum':'"+pageNum.toString()+"',"
          +"'travelPackId':'"+travelPackId.toString()+"'}",
           
                  
       
    contentType: "application/json; charset=utf-8", 

    dataType: "json",

    success: function(xhr, status) {

          successHandler(xhr,args);
            
       
    },

    error: function(xhr, status, error) {

        errorHandler(xhr,args);

    }

    }));
}


/**
	 * Gets the travelpack Items for the whole map area that is visible, not just for a single clicked on dot
	 */	
	planeteye.map.services.getTravelPackItemsForArea =  function (north,south,east,west,zoom, maxToReturn,  pageNum,  ownerId, travelPackId, customerId, successHandler,errorHandler,args,requestQueue){
	
	    
        
        requestQueue.push(
        $.ajax({

        type: "POST",

        url: planeteye.map.services.state.basePath + "/webservice/flashservice.asmx/getTravelPackItemsForAreaCustomerJSON",

        data: "{'north':'"+north.toString()+"',"
              +"'south':'"+south.toString()+"',"
              +"'east':'"+east.toString()+"',"
              +"'west':'"+west.toString()+"',"
              +"'maxToReturn':'"+maxToReturn.toString()+"',"
              +"'pageNum':'1',"
              +"'ownerID':'"+ownerId.toString()+"',"
              +"'travelPackId':'"+travelPackId.toString()+"',"
              +"'customerId':'"+customerId.toString()+"',"
              +"'zoom':'"+zoom.toString()+"'}", 
                

        contentType: "application/json; charset=utf-8", 

        dataType: "json",

        success: function(xhr, status) {
                
                var sb = "";
                //this is on purpose .net webservices
                //return strings of json as a json string
                //hence eval twice. dont ask....
//                xhr = xhr.replace("\\\"","\"");
                
                var obj = eval("(" + xhr + ")");
           
                 successHandler(obj,args);
                //place the dots on the map 
                 
                
        },

        error: function(xhr, status, error) {

        var err = JSON.parse(xhr.responseText);

        $("#error").html("Error –> " + err.Message);

        }

        }));
	

	}
/*planeteye.map.services.getTravelPackItemsForArea =  function(placeId,successHandler,failureHandler,args){	
	$.ajax({
                        type: "GET",
                                url: "/services/APIWordpressPluginJSONHandler.ashx",
                                data: "{ placeId: '" + placeId + "' } ",
                                dataType: "jsonp",
                                success: function(xhr, status) {
                                           successHandler(xhr,args);     
                                },

                        error: function(xhr, status, error) {
                                failureHandler(error,args);
                        },

                        complete: function(xhr, status) {
                                // do nothing..
                        }
                });
}*/
planeteye.map.services.getPlaceForGooglePlace = function(name, lat, lng,address,addressLine,postalCode,city,country,editName,editDescription,travelPackId,addToTpk,successHandler,failureHandler,args){
var add = addToTpk ? "True":"False"
$.ajax({
                        type: "POST",
                                url: planeteye.map.services.state.basePath + "/services/AddSearchToTravelPackJSONHandler.ashx",
                                data: "{ title: '" + escapeSingleQuotes(name) + "',"
                                        +"editTitle: '" + escapeSingleQuotes(editName) + "',"
                                        +"description: '" + escapeSingleQuotes(editDescription) + "',"
                                        +"lat: '" + escapeSingleQuotes(lat) + "',"
                                        +"lng: '" + escapeSingleQuotes(lng) + "',"
                                        +"normalizedAddress: '" + escapeSingleQuotes(address) + "',"
                                        +"addressLine: '" + escapeSingleQuotes(addressLine) + "',"
                                        +"postalCode: '" + escapeSingleQuotes(postalCode) + "',"
                                        +"city: '" + escapeSingleQuotes(city) + "',"
                                        +"travelPackId: '" + escapeSingleQuotes(travelPackId) + "',"
                                        +"addToTpk: '" + add  + "',"  
                                        +"country: '" + escapeSingleQuotes(country) + "' } ",
                                dataType: "jsonp",
                                success: function(xhr, status) {
                                                successHandler(xhr,args);
                                },

                        error: function(xhr, status, error) {
                                failureHandler(xhr,error);
                        },

                        complete: function(xhr, status) {
                                // do nothing..
                        }
                });
}

planeteye.map.services.addPlaceToTPK = function(tpkId,placeId,successHandler,failureHandler,args){
$.ajax({
                        type: "POST",
                                url: planeteye.map.services.state.basePath + "/WebService/FlashService.asmx/TravelPacksAddPlaceJSON",
                                data: "{ placeid: '" + placeId + "', travelpackid: '" + tpkId + "' } ",
                                dataType: "json",
                                success: function(xhr, status) {
                                                successHandler(xhr,args);
                                },

                        error: function(xhr, status, error) {
                                failureHandler(xhr,error);
                        },

                        complete: function(xhr, status) {
                                // do nothing..
                        }
                });
}

function escapeSingleQuotes(value) {
        if (value != null && value != '') {
                value = value.replace(/'/g,"\\'");
        }
        return value;
}


