var IFrameObj;
var DDC_TESTING = false;
function ApiCall() {
    //this.url =
    this.url = (DDC_TESTING) ? "http://localhost:7070/services/":"http://apis.dealer.com/services/";
    this.reseller = "";
    this.accountId = "";
    this.service = "";
    this.operation = "";
    this.version = "v1";
    this.output = "json";
    this.callback = "";
    this.params = new Array();
    this.params.index = new Array();

    this.param = function(key, value) {
        var addKey = true;
        for (var i = 0; i < this.params.index.length; i++){
            if( this.params.index[i] == key )
                addKey = false;
        }
        if( addKey )
            this.params.index.push(key);

        this.params[key] = value;
    };

    this.execute = function() {
        // construct url
        var head= document.getElementsByTagName('head')[0];
        var script= document.createElement('script');
        script.type= 'text/javascript';
        script.src=this.toUrl();
        head.appendChild(script);

    };

    this.inline = function() {
        var req = this.toUrl();
        document.write("<scr"+"ipt type='text/javascript' src='" + req + "'><script>");
    }

    this.toUrl = function() {
        var request = this.url +
                      this.service + "/" +
                      this.version + "/" +
                      this.operation + "?" +
                      "reseller=" + this.reseller + "&" +
                      "accountId=" + this.accountId;

        if (this.callback != "")
            request += "&callback=" + this.callback;

        if (this.output != "json")
            request += "&output=" + this.output;

        for (var i = 0; i < this.params.index.length; i++)
            request += "&" + this.params.index[i] + "=" + this.params[ this.params.index[i] ];

        return request;
    }

}


var USED_INVENTORY = 1;
var NEW_INVENTORY = 2;
