/**
 * Innovectra extention to Mapquest API.
 * 
 * $Id: mapquestExt.js,v 1.1.4.4 2008/07/26 06:24:19 kyevenko Exp $
 */

InnoPoi = Class.create();
InnoPoi.prototype = {
    initialize: function(pid, street, city, state, zip, latitude, longitude, title, subtitle) {
        this.pid = pid;
        this.street = street;
        this.city = city;
        this.state = state;
        this.zip = zip;
        this.latitude = latitude;
        this.longitude = longitude;
        this.title = title;
        this.subtitle = subtitle;
        this.options = {};
    },
    
    toMQ: function() {
        var address = new MQGeoAddress();
        address.setStreet(this.street);
        address.setCity(this.city);
        address.setState(this.state);
        address.setPostalCode(this.zip);
        address.setMQLatLng(new MQLatLng(this.latitude, this.longitude));
        
        return address;
    }
}

/* This is workaround for bug in Mapquest libraries (5.0 - 5.2) */
function Image(){
    return document.createElement('img');
};

/* This is fix for prototype's Ajax.Request broken by mapquest library */
Object.extend(Ajax.Request.prototype, {
  setRequestHeaders: function() {
    var headers = {
      'X-Requested-With': 'XMLHttpRequest',
      'X-Prototype-Version': Prototype.Version,
      'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'
    };

    if (this.method == 'post') {
      headers['Content-type'] = this.options.contentType +
        (this.options.encoding ? '; charset=' + this.options.encoding : '');

      /* Force "Connection: close" for older Mozilla browsers to work
       * around a bug where XMLHttpRequest sends an incorrect
       * Content-length header. See Mozilla Bugzilla #246651.
       */
      if (this.transport.overrideMimeType &&
          (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005)
            headers['Connection'] = 'close';
    }

    // user-defined headers
    if (typeof this.options.requestHeaders == 'object') {
      var extras = this.options.requestHeaders;

      if (typeof extras.push == 'function')
        for (var i = 0, length = extras.length; i < length; i += 2)
          headers[extras[i]] = extras[i+1];
      else {
        $H(extras).each(function(pair) { headers[pair.key] = pair.value });
      }
    }

    for (var name in headers) {
        /* KY: this fix skip non-string properties created by other dumb libraries in Object */
        if (typeof headers[name] == 'string')
            this.transport.setRequestHeader(name, headers[name]);
    }
  }
});