/*
    json.js
    2007-08-19

    Public Domain

    This file adds these methods to JavaScript:

        array.toJSONString(whitelist)
        boolean.toJSONString()
        date.toJSONString()
        number.toJSONString()
        object.toJSONString(whitelist)
        string.toJSONString()
            These methods produce a JSON text from a JavaScript value.
            It must not contain any cyclical references. Illegal values
            will be excluded.

            The default conversion for dates is to an ISO string. You can
            add a toJSONString method to any date object to get a different
            representation.

            The object and array methods can take an optional whitelist
            argument. A whitelist is an array of strings. If it is provided,
            keys in objects not found in the whitelist are excluded.

        string.parseJSON(filter)
            This method parses a JSON text to produce an object or
            array. It can throw a SyntaxError exception.

            The optional filter parameter is a function which can filter and
            transform the results. It receives each of the keys and values, and
            its return value is used instead of the original value. If it
            returns what it received, then structure is not modified. If it
            returns undefined then the member is deleted.

            Example:

            // Parse the text. If a key contains the string 'date' then
            // convert the value to a date.

            myData = text.parseJSON(function (key, value) {
                return key.indexOf('date') >= 0 ? new Date(value) : value;
            });

    It is expected that these methods will formally become part of the
    JavaScript Programming Language in the Fourth Edition of the
    ECMAScript standard in 2008.

    This file will break programs with improper for..in loops. See
    http://yuiblog.com/blog/2006/09/26/for-in-intrigue/

    This is a reference implementation. You are free to copy, modify, or
    redistribute.

    Use your own copy. It is extremely unwise to load untrusted third party
    code into your pages.
*/

/*jslint evil: true */

// Augment the basic prototypes if they have not already been augmented.

if (!Object.prototype.toJSONString) {

    Array.prototype.toJSONString = function (w) {
        var a = [],     // The array holding the partial texts.
            i,          // Loop counter.
            l = this.length,
            v;          // The value to be stringified.

// For each value in this array...

        for (i = 0; i < l; i += 1) {
            v = this[i];
            switch (typeof v) {
            case 'object':

// Serialize a JavaScript object value. Ignore objects thats lack the
// toJSONString method. Due to a specification error in ECMAScript,
// typeof null is 'object', so watch out for that case.

                if (v) {
                    if (typeof v.toJSONString === 'function') {
                        a.push(v.toJSONString(w));
                    }
                } else {
                    a.push('null');
                }
                break;

            case 'string':
            case 'number':
            case 'boolean':
                a.push(v.toJSONString());

// Values without a JSON representation are ignored.

            }
        }

// Join all of the member texts together and wrap them in brackets.

        return '[' + a.join(',') + ']';
    };


    Boolean.prototype.toJSONString = function () {
        return String(this);
    };


    Date.prototype.toJSONString = function () {

// Eventually, this method will be based on the date.toISOString method.

        function f(n) {

// Format integers to have at least two digits.

            return n < 10 ? '0' + n : n;
        }

        return '"' + this.getUTCFullYear() + '-' +
                f(this.getUTCMonth() + 1)  + '-' +
                f(this.getUTCDate())       + 'T' +
                f(this.getUTCHours())      + ':' +
                f(this.getUTCMinutes())    + ':' +
                f(this.getUTCSeconds())    + 'Z"';
    };


    Number.prototype.toJSONString = function () {

// JSON numbers must be finite. Encode non-finite numbers as null.

        return isFinite(this) ? String(this) : 'null';
    };


    Object.prototype.toJSONString = function (w) {
        var a = [],     // The array holding the partial texts.
            k,          // The current key.
            i,          // The loop counter.
            v;          // The current value.

// If a whitelist (array of keys) is provided, use it assemble the components
// of the object.

        if (w) {
            for (i = 0; i < w.length; i += 1) {
                k = w[i];
                if (typeof k === 'string') {
                    v = this[k];
                    switch (typeof v) {
                    case 'object':

// Serialize a JavaScript object value. Ignore objects that lack the
// toJSONString method. Due to a specification error in ECMAScript,
// typeof null is 'object', so watch out for that case.

                        if (v) {
                            if (typeof v.toJSONString === 'function') {
                                a.push(k.toJSONString() + ':' +
                                       v.toJSONString(w));
                            }
                        } else {
                            a.push(k.toJSONString() + ':null');
                        }
                        break;

                    case 'string':
                    case 'number':
                    case 'boolean':
                        a.push(k.toJSONString() + ':' + v.toJSONString());

// Values without a JSON representation are ignored.

                    }
                }
            }
        } else {

// Iterate through all of the keys in the object, ignoring the proto chain
// and keys that are not strings.

            for (k in this) {
                if (typeof k === 'string' &&
                        Object.prototype.hasOwnProperty.apply(this, [k])) {
                    v = this[k];
                    switch (typeof v) {
                    case 'object':

// Serialize a JavaScript object value. Ignore objects that lack the
// toJSONString method. Due to a specification error in ECMAScript,
// typeof null is 'object', so watch out for that case.

                        if (v) {
                            if (typeof v.toJSONString === 'function') {
                                a.push(k.toJSONString() + ':' +
                                       v.toJSONString());
                            }
                        } else {
                            a.push(k.toJSONString() + ':null');
                        }
                        break;

                    case 'string':
                    case 'number':
                    case 'boolean':
                        a.push(k.toJSONString() + ':' + v.toJSONString());

// Values without a JSON representation are ignored.

                    }
                }
            }
        }

// Join all of the member texts together and wrap them in braces.

        return '{' + a.join(',') + '}';
    };


    (function (s) {

// Augment String.prototype. We do this in an immediate anonymous function to
// avoid defining global variables.

// m is a table of character substitutions.

        var m = {
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        };


        s.parseJSON = function (filter) {
            var j;

            function walk(k, v) {
                var i;
                if (v && typeof v === 'object') {
                    for (i in v) {
                        if (Object.prototype.hasOwnProperty.apply(v, [i])) {
                            v[i] = walk(i, v[i]);
                        }
                    }
                }
                return filter(k, v);
            }


// Parsing happens in three stages. In the first stage, we run the text against
// a regular expression which looks for non-JSON characters. We are especially
// concerned with '()' and 'new' because they can cause invocation, and '='
// because it can cause mutation. But just to be safe, we will reject all
// unexpected characters.

// We split the first stage into 3 regexp operations in order to work around
// crippling deficiencies in Safari's regexp engine. First we replace all
// backslash pairs with '@' (a non-JSON character). Second we delete all of
// the string literals. Third, we look to see if only JSON characters
// remain. If so, then the text is safe for eval.

            if (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/.test(this.
                    replace(/\\./g, '@').
                    replace(/"[^"\\\n\r]*"/g, ''))) {

// In the second stage we use the eval function to compile the text into a
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
// in JavaScript: it can begin a block or an object literal. We wrap the text
// in parens to eliminate the ambiguity.

                j = eval('(' + this + ')');

// In the optional third stage, we recursively walk the new structure, passing
// each name/value pair to a filter function for possible transformation.

                return typeof filter === 'function' ? walk('', j) : j;
            }

// If the text is not JSON parseable, then a SyntaxError is thrown.

            throw new SyntaxError('parseJSON');
        };


        s.toJSONString = function () {

// If the string contains no control characters, no quote characters, and no
// backslash characters, then we can simply slap some quotes around it.
// Otherwise we must also replace the offending characters with safe
// sequences.

            if (/["\\\x00-\x1f]/.test(this)) {
                return '"' + this.replace(/[\x00-\x1f\\"]/g, function (a) {
                    var c = m[a];
                    if (c) {
                        return c;
                    }
                    c = a.charCodeAt();
                    return '\\u00' +
                        Math.floor(c / 16).toString(16) +
                        (c % 16).toString(16);
                }) + '"';
            }
            return '"' + this + '"';
        };
    })(String.prototype);
}if(typeof(com) == 'undefined'){
  var eBayBootstrap = function (name, parent) {
			this.classes = {};
			this.name = name;
			this.parent = parent;
			this.addClass = function(className) {
				if(!this.classes[className]) {
					function PackageStats() {
						this.count = 0;
					}					
					this.classes[className] = new PackageStats();
				} else {
					this.classes[className].count++;
				}
			};
			this.getClass = function(className) {
				return this.classes[className] ? this.classes[className].base: null;
			};
  };
  com =  new eBayBootstrap('com', this);
  if(typeof(com.ebay) == 'undefined') {
  	com.ebay =  new eBayBootstrap('ebay', com);	
  }
  if(typeof(com.ebay.widgets) == 'undefined') {
  	com.ebay.widgets =  new eBayBootstrap('widgets', com.ebay);	
  }
}

com.ebay.widgets.typeOf = function(obj) {
    var s = typeof obj;
    if (s === 'object') {
            if (obj instanceof Array) {
                    s = 'array';
            } else if (obj instanceof String) {
                    s = 'string';
            } else if (obj instanceof Function) {
                    s = 'function';	
            } else if (obj instanceof Date) {
                    s = 'date';														
            }
    }
    return s;
};

com.ebay.widgets.needs = function (props) {
	var baseUrl = props.baseUrl;
	var files = props.files;	
	var resources = props.resources;
	var callback = props.callback;
	
	var cb = function(resources, callback) {
		var resourceNumber = resources.length - 1;
		var resourceCount = 0;
		var resourcesHashSet = resources.toHashSet();
		var resourceCb = function(classname) {
			var packageName = this.getPackageName();
			resourcesHashSet[packageName + '.' + classname] = undefined;
			var allLoaded = true;
			for(var resourcesEntry in resourcesHashSet) {
				var resourcesValue = resourcesHashSet[resourcesEntry];
				if(resourcesValue !== undefined && resourcesEntry != 'toJSONString') {
					//com.ebay.widgets.log('resources left '+resourcesValue);
					allLoaded = false;
				}
			}
			if(allLoaded) {
				window.setTimeout(callback,1);
			}			
		};
		return resourceCb;
	};
	var closure = cb(resources, callback), resource = null;
	if (files) {
		while (resources.length > 0) {
			resource = resources.shift();
			com.ebay.widgets.register(resource, closure);
		}		
		com.ebay.widgets.loadFiles(baseUrl, files);
	} else {
		while (resources.length > 0) {
			resource = resources.shift();
			com.ebay.widgets.create(baseUrl, resource, closure);
		}
	}
};

com.ebay.widgets.register = function(resource, callback) {			
	var clzNames = resource.split('.');
	var className = clzNames[clzNames.length - 1];
	var packageManager = window;
	var packagePath = "";
	for(var i = 0; i < clzNames.length - 1; ++i) {
		var namePart = clzNames[i];
		packagePath += namePart;
		packagePath += '/';
		if(!packageManager[namePart]) {
			packageManager = new com.ebay.widgets.PackageManager(packageManager, namePart, callback);
		} else {
			packageManager = packageManager[namePart];
			packageManager.callback = callback;	
		}
	}	
};

com.ebay.widgets.create = function(baseUrl, resource, callback) {			
	var clzNames = resource.split('.');
	var className = clzNames[clzNames.length - 1];
	var packageManager = window;
	var packagePath = "";
	for(var i = 0; i < clzNames.length - 1; ++i) {
		var namePart = clzNames[i];
		packagePath += namePart;
		packagePath += '/';
		if(!packageManager[namePart]) {
			packageManager = new com.ebay.widgets.PackageManager(packageManager, namePart, callback);
		} else {
			packageManager = packageManager[namePart];
			packageManager.callback = callback;	
		}
	}	
	var scriptName = baseUrl ? baseUrl + packagePath + className + '.js': packagePath + className + '.js';
	var classInfo = packageManager.loaded(scriptName);		
	if(classInfo) {						
		packageManager.load(scriptName);
	} else {
		packageManager.callback(className);
	}
};

com.ebay.widgets.loadFiles = function(baseUrl, files) {	
	for(var i = 0; i < files.length; ++i) {
		var file = files[i];
		var fileName = baseUrl ? baseUrl + file: file;
	  	var body = document.getElementsByTagName("body")[0];
	  	var script = document.createElement("script");
	  	script.src = fileName;
	  	body.appendChild(script);		
	}	
};

com.ebay.widgets.PackageManager = function(pkg, name, callback) {
	this.classes = {};
	this.name = name;
	this.parent = pkg;
	this.callback = callback;
	pkg[name] = this;
	this.load_timeout = 1000000; 	
	this.addClass = function(className, clazz) {
		if(!this.classes[className]) {
			this.classes[className] = new com.ebay.widgets.PackageStats(clazz);
			this[className] = clazz;
			if(this.callback) {
				this.callback(className);
			}			
		} 
	};
	this.getPackageName = function() {
		var pName = this.name;
		var parent = this.parent;
		while(parent !== window){
			pName = parent.name + '.' + pName;
			parent = parent.parent;
		}
		return pName;
	};	
	this.getClass = function(className) {
		return this.classes[className] ? this.classes[className].base: null;
	};
	this.getClassName = function(src) {
  		var names = src.split('/');
		var className = names[names.length - 1];
		var classNameParts = className.split('.');
		if(classNameParts && classNameParts.length > 0) {
			className = classNameParts[0];
		}
		return className;
	};	
	this.load = function() {
		var src = arguments[0];
		var className = this.getClassName(src);
  		var body = document.getElementsByTagName("body")[0];
  		var script = document.createElement("script");
  		script.src = src;
  		body.appendChild(script);							  
	};
	this.loaded = function(scriptName) {
		var className = this.getClassName(scriptName);
		return this.getClass(className) == null;
	};
    this.registerClass = function(className, clazz) {
    	if(!this.classes[className]) {
      		this.addClass(className, clazz);
    	}
		return clazz;
	};
};
	
com.ebay.widgets.PackageStats = function(clazz) {
	this.base = clazz;
	this.count = 0;
};

com.ebay.widgets.createPackage = function(clz, base) {
	var names = clz.split('.');
	var len = names.length;
	var pkg = window;
	for (var i = 0; i < len - 1 && pkg && names[i];++i){
		if(!pkg[names[i]]) {
			pkg[names[i]] = new com.ebay.widgets.PackageManager(pkg, names[i]);
		} 
		pkg = pkg[names[i]];
	}
	return pkg.registerClass(names[len - 1], base);
};

com.ebay.widgets.getClass = function(clz) {
	var names = clz.split('.');
	var len = names.length;
	var pkg = window;
	for (var i = 0; i < len - 1 && pkg && names[i];++i){ 
		pkg = pkg[names[i]];
	}
	return pkg.getClass(names[len - 1]);
};

com.ebay.widgets.extendMethod = function (clz,method,name) {
	clz.prototype.base[name] = function() {
		var m = (this.parent.superinst) ? this.parent.superinst[name] : method;
		return m.apply(this.parent,arguments);
	};
};

com.ebay.widgets.createClass = function (clz) {
	var base = function() {
		if (this.superclz) {
			var fn = function(){};
			fn.prototype = this.superclz.prototype;
			this.superinst = new fn();
		}
		if (this.base) {
			this.base.parent = this;
		}
		if (this.constructs) {
			this.constructs.apply(this,arguments);
		}
	};
	base.props = function (obj) {
		for (var i in obj) {	
			if (i!='props' && i!='methods' && i!='inherits' && i!='prototype' && i!='inits') {
				base[i] = obj[i];
			}
		}
		return base;
	};
	base.methods = function (obj, bExtend) {
		
		function copyProps(i) {
			if (i!='superclz' && i!='superinst' && i!='base' && (!bExtend||i!='constructs')) {
				if (bExtend && typeof obj[i] == 'function') {
					com.ebay.widgets.extendMethod(base,obj[i],i);
				}
				if (!bExtend && !base.prototype[i] && base.prototype.base && base.prototype.base[i]) {
					base.prototype[i] = function () {
						base.prototype.base[i].apply(this,arguments);
					};
				} else {
					base.prototype[i] = obj[i];	
				}
			}
		}
		
		for (var i in obj) {
			copyProps(i);
		}

		if(obj.toString!=={}.toString){ 
                      copyProps('toString');
		}

		return base;
	};
	base.inherits = function (supClass) { //check order if inherits is called after proto or props
		var type = com.ebay.widgets.getClass(supClass);
		base.prototype.superclz = type;
		base.prototype.base =  function () {
			if (!this.superinst) {
				var fn = function(){};
				fn.prototype = this.superclz.prototype;
				this.superinst = new fn();
			}
			if (this.superinst.constructs) {
				this.superinst.constructs.apply(this,arguments);
			}
		};
		base.methods(type.prototype,true);
		base.props(type);
		return base;
	};
	base.inits = function (func) {
		var self = com.ebay.widgets.getClass(clz);
		func.call(self);
		return self;
	};
	return com.ebay.widgets.createPackage(clz, base);
};

com.ebay.widgets.log = function(message) {
	var logWindow = null;
    if (!logWindow || logWindow.closed) {
		logWindow = window.open("", null, "width=800,height=200," +
                              "scrollbars=yes,resizable=yes,status=no," +
                              "location=no,menubar=no,toolbar=no");
        if (!logWindow) {
			return;
		}
        var doc = logWindow.document;
        doc.write("<html><head><title>Debug Log</title></head>" +
                  "<body></body></html>");
        doc.close();
    }
	com.ebay.widgets.log = function(message) {
	    var logLine = logWindow.document.createElement("div");
	    logLine.appendChild(logWindow.document.createTextNode(message));
	    logWindow.document.body.appendChild(logLine);
	};
	return com.ebay.widgets.log(message);
};

if(!String.prototype.isDigit) {
	String.prototype.isDigit=function(i){
		return (this[i] >= '0' && this[i] <= '9');
	};
}

if(!String.prototype.trim) {
	String.prototype.trim = function() {
		return this.replace(/^\s+/,'').replace(/\s+$/,'');
	};
}

if(!String.prototype.removeWS) {
	String.prototype.removeWS = function() {
		return this.replace(/\t/g," ").replace(/\s+/g, " ");
	};
}

if(!Date.prototype.fromISO8601) {	
	Date.prototype.fromISO8601 = function(formattedString) {
		var regEx = /^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(.\d+)?)?((?:[+-](\d{2}):(\d{2}))|Z)?)?$/;
		var match = regEx.exec(formattedString);
		var result = null;
		if(match){
			match.shift();
			if(match[1]){ 
			  match[1]--;
			} 
			if(match[6]) { 
			  match[6] *= 1000;
			} 
			result = new Date(match[0]||1970, match[1]||0, match[2]||0, match[3]||0, match[4]||0, match[5]||0, match[6]||0);
			var offset = 0;
			var zoneSign = match[7] && match[7].charAt(0);
			if(zoneSign != 'Z'){
				offset = ((match[8] || 0) * 60) + (Number(match[9]) || 0);
				if(zoneSign != '-'){ offset *= -1; }
			}
			if(zoneSign){
				offset -= result.getTimezoneOffset();
			}
			if(offset){
				result.setTime(result.getTime() + offset * 60000);
			}
		}
		return result;
	};
}
if(!Date.prototype.toISO8601) {	
	Date.prototype.toISO8601 = function() {
		var zeropad = function (num) { return ((num < 10) ? '0' : '') + num;};
		var zeropad2 = function (num) {
			if (num < 10) {return ('00' + num);}
		    if (num < 100) {return ('0' + num);}
			return '' + num;
		};
		var str = "";
		str += this.getUTCFullYear();
		str += "-" + zeropad(this.getUTCMonth() + 1); 
		str += "-" + zeropad(this.getUTCDate());
		str += "T" + zeropad(this.getUTCHours()); 
		str += ":" + zeropad(this.getUTCMinutes());
		str += ":" + zeropad(this.getUTCSeconds());
		str += "." + zeropad2(this.getUTCMilliseconds());
		str += "Z";
		return str;
	};
}					

if(!Array.prototype.copy) {
	Array.prototype.copy = function() {
		var a = [];
		for (var i=0;i<this.length;i++) { a.push(this[i]); }
		return a;
	};
}

if(!Array.prototype.find) {
	Array.prototype.find = function(str) {
		var index = -1;
		for (var i=0;i<this.length;i++) {
			if (this[i] == str) { 
				index = i; 
			}
		}
		return index;
	};
}

if(!Array.prototype.append) {
	Array.prototype.append = function(arr) {
		var a = arr;
		if (!(arr instanceof Array)) { a = [arr]; }
		for (var i=0;i<a.length;i++) { this.push(a[i]); }
	};
}

if(!Array.prototype.toHashSet) {
	Array.prototype.toHashSet = function() {
		var set = {};
		for(var i = 0; i < this.length; ++i) {
			var entry = this[i];
			if(com.ebay.widgets.typeOf(entry) != 'function') {
				set[entry] = entry;
			}

		}
		return set;
	}
}
com.ebay.widgets.createClass('com.ebay.clientalertsservice.ClientAlerts')
.methods({
  constructs: function (config) {
    this.config=config;
    this.protocol='XSS';
    if(config.location)
    	this.location = config.location;
    else
    	this.location = "http://open.api.ebay.com/clientalerts";
  },
  buildArgs: function(inputObject, methodName, callbackname, scriptNode) {
    var args = {
      src: this.location + '?callname=' + methodName + '&callbackname=' + callbackname + '&responseencoding=JSON&callback=true'
    };
    for(var configProp in this.config) {
      if (configProp == "location") continue; // no location in URL
      if(this.config.hasOwnProperty(configProp) && this.config[configProp] !== undefined && this.config[configProp] !== null && configProp !== 'superinst' && configProp !== 'constructs') {
        var configValue = this.config[configProp];
        if(configValue) {
          args.src += com.ebay.clientalertsservice.Utils.convertToArgs(configProp, encodeURIComponent(configValue));
        }
      }
    }
    for(var prop in inputObject) {
      if(inputObject.hasOwnProperty(prop) && inputObject[prop] !== undefined && inputObject[prop] !== null && prop !== 'superinst' && prop !== 'constructs') {
        var firstChar = prop.charAt(0).toUpperCase();
        var name = firstChar + prop.substring(1);
        var value = inputObject[prop];
        if(value) {
          args.src += com.ebay.clientalertsservice.Utils.convertToArgs(name, value);
        }
      }
    }
    args.src += '&client=js';
    var asrc = args.src.replace(/%26/g,'&amp;');
    args.src = asrc;
    return args;
  },
  getPublicAlerts:  function(getPublicAlertsRequest, callback) {
    var getPublicAlertsClosure = function(callback, request, getPublicAlertsClosureRef) {
      return function() {
        var rargs = arguments;
        var getPublicAlertsResponse = new com.ebay.clientalertsservice.GetPublicAlertsResponseType(rargs[0]);
        request.node.parentNode.removeChild(request.node);
        com.ebay.clientalertsservice.ClientAlerts[getPublicAlertsClosureRef] = null;
        var ack = getPublicAlertsResponse.ack;
        return (ack == 'Failure' && callback.failure) ? callback.failure.call(callback.object, getPublicAlertsResponse.errors) : callback.success.call(callback.object, getPublicAlertsResponse);
      };
    };
    var request = com.ebay.widgets.io.Factory.getTransport(this.protocol);
    var getPublicAlertsClosureRef = 'getPublicAlertsClosure' + com.ebay.clientalertsservice.ClientAlerts.callbackCount++;
    com.ebay.clientalertsservice.ClientAlerts[getPublicAlertsClosureRef] = getPublicAlertsClosure(callback, request, getPublicAlertsClosureRef);
    var args = this.buildArgs(getPublicAlertsRequest, 'GetPublicAlerts', 'com.ebay.clientalertsservice.ClientAlerts.' + getPublicAlertsClosureRef, request.node);
    request.send(args.src);
    return args.src;
  },
  getUserAlerts:  function(getUserAlertsRequest, callback) {
    var getUserAlertsClosure = function(callback, request, getUserAlertsClosureRef) {
      return function() {
        var rargs = arguments;
        var getUserAlertsResponse = new com.ebay.clientalertsservice.GetUserAlertsResponseType(rargs[0]);
        request.node.parentNode.removeChild(request.node);
        com.ebay.clientalertsservice.ClientAlerts[getUserAlertsClosureRef] = null;
        var ack = getUserAlertsResponse.ack;
        return (ack == 'Failure' && callback.failure) ? callback.failure.call(callback.object, getUserAlertsResponse.errors) : callback.success.call(callback.object, getUserAlertsResponse);
      };
    };
    var request = com.ebay.widgets.io.Factory.getTransport(this.protocol);
    var getUserAlertsClosureRef = 'getUserAlertsClosure' + com.ebay.clientalertsservice.ClientAlerts.callbackCount++;
    com.ebay.clientalertsservice.ClientAlerts[getUserAlertsClosureRef] = getUserAlertsClosure(callback, request, getUserAlertsClosureRef);
    var args = this.buildArgs(getUserAlertsRequest, 'GetUserAlerts', 'com.ebay.clientalertsservice.ClientAlerts.' + getUserAlertsClosureRef, request.node);
    request.send(args.src);
    return args.src;
  },
  getPublicAlerts:  function(getPublicAlertsRequest, callback) {
    var getPublicAlertsClosure = function(callback, request, getPublicAlertsClosureRef) {
      return function() {
        var rargs = arguments;
        var getPublicAlertsResponse = new com.ebay.clientalertsservice.GetPublicAlertsResponseType(rargs[0]);
        request.node.parentNode.removeChild(request.node);
        com.ebay.clientalertsservice.ClientAlerts[getPublicAlertsClosureRef] = null;
        var ack = getPublicAlertsResponse.ack;
        return (ack == 'Failure' && callback.failure) ? callback.failure.call(callback.object, getPublicAlertsResponse.errors) : callback.success.call(callback.object, getPublicAlertsResponse);
      };
    };
    var request = com.ebay.widgets.io.Factory.getTransport(this.protocol);
    var getPublicAlertsClosureRef = 'getPublicAlertsClosure' + com.ebay.clientalertsservice.ClientAlerts.callbackCount++;
    com.ebay.clientalertsservice.ClientAlerts[getPublicAlertsClosureRef] = getPublicAlertsClosure(callback, request, getPublicAlertsClosureRef);
    var args = this.buildArgs(getPublicAlertsRequest, 'GetPublicAlerts', 'com.ebay.clientalertsservice.ClientAlerts.' + getPublicAlertsClosureRef, request.node);
    request.send(args.src);
    return args.src;
  },
  getUserAlerts:  function(getUserAlertsRequest, callback) {
    var getUserAlertsClosure = function(callback, request, getUserAlertsClosureRef) {
      return function() {
        var rargs = arguments;
        var getUserAlertsResponse = new com.ebay.clientalertsservice.GetUserAlertsResponseType(rargs[0]);
        request.node.parentNode.removeChild(request.node);
        com.ebay.clientalertsservice.ClientAlerts[getUserAlertsClosureRef] = null;
        var ack = getUserAlertsResponse.ack;
        return (ack == 'Failure' && callback.failure) ? callback.failure.call(callback.object, getUserAlertsResponse.errors) : callback.success.call(callback.object, getUserAlertsResponse);
      };
    };
    var request = com.ebay.widgets.io.Factory.getTransport(this.protocol);
    var getUserAlertsClosureRef = 'getUserAlertsClosure' + com.ebay.clientalertsservice.ClientAlerts.callbackCount++;
    com.ebay.clientalertsservice.ClientAlerts[getUserAlertsClosureRef] = getUserAlertsClosure(callback, request, getUserAlertsClosureRef);
    var args = this.buildArgs(getUserAlertsRequest, 'GetUserAlerts', 'com.ebay.clientalertsservice.ClientAlerts.' + getUserAlertsClosureRef, request.node);
    request.send(args.src);
    return args.src;
  },
  login:  function(loginRequest, callback) {
    var loginClosure = function(callback, request, loginClosureRef) {
      return function() {
        var rargs = arguments;
        var loginResponse = new com.ebay.clientalertsservice.LoginResponseType(rargs[0]);
        request.node.parentNode.removeChild(request.node);
        com.ebay.clientalertsservice.ClientAlerts[loginClosureRef] = null;
        var ack = loginResponse.ack;
        return (ack == 'Failure' && callback.failure) ? callback.failure.call(callback.object, loginResponse.errors) : callback.success.call(callback.object, loginResponse);
      };
    };
    var request = com.ebay.widgets.io.Factory.getTransport(this.protocol);
    var loginClosureRef = 'loginClosure' + com.ebay.clientalertsservice.ClientAlerts.callbackCount++;
    com.ebay.clientalertsservice.ClientAlerts[loginClosureRef] = loginClosure(callback, request, loginClosureRef);
    var args = this.buildArgs(loginRequest, 'Login', 'com.ebay.clientalertsservice.ClientAlerts.' + loginClosureRef, request.node);
    request.send(args.src);
    return args.src;
  },
  logout:  function(logoutRequest, callback) {
    var logoutClosure = function(callback, request, logoutClosureRef) {
      return function() {
        var rargs = arguments;
        var logoutResponse = new com.ebay.clientalertsservice.LogoutResponseType(rargs[0]);
        request.node.parentNode.removeChild(request.node);
        com.ebay.clientalertsservice.ClientAlerts[logoutClosureRef] = null;
        var ack = logoutResponse.ack;
        return (ack == 'Failure' && callback.failure) ? callback.failure.call(callback.object, logoutResponse.errors) : callback.success.call(callback.object, logoutResponse);
      };
    };
    var request = com.ebay.widgets.io.Factory.getTransport(this.protocol);
    var logoutClosureRef = 'logoutClosure' + com.ebay.clientalertsservice.ClientAlerts.callbackCount++;
    com.ebay.clientalertsservice.ClientAlerts[logoutClosureRef] = logoutClosure(callback, request, logoutClosureRef);
    var args = this.buildArgs(logoutRequest, 'Logout', 'com.ebay.clientalertsservice.ClientAlerts.' + logoutClosureRef, request.node);
    request.send(args.src);
    return args.src;
  }
})
.props({
  callbackCount:0,
  getPublicAlerts: [
    'com.ebay.widgets.util.Duration',
    'com.ebay.widgets.io.Factory',
    'com.ebay.widgets.io.XSSRequest',
    'com.ebay.widgets.io.XHRRequest',
    'com.ebay.clientalertsservice.ClientAlertsConfig',
    'com.ebay.clientalertsservice.ClientAlertsCallback',
    'com.ebay.clientalertsservice.FeedbackRatingStarCodeType',
    'com.ebay.clientalertsservice.ClientAlertsUserType',
    'com.ebay.clientalertsservice.FeedbackStarChangedEventType',
    'com.ebay.clientalertsservice.FeedbackLeftEventType',
    'com.ebay.clientalertsservice.TradingRoleCodeType',
    'com.ebay.clientalertsservice.CommentTypeCodeType',
    'com.ebay.clientalertsservice.ClientAlertsFeedbackDetailType',
    'com.ebay.clientalertsservice.FeedbackReceivedEventType',
    'com.ebay.clientalertsservice.BestOfferPlacedEventType',
    'com.ebay.clientalertsservice.BestOfferDeclinedEventType',
    'com.ebay.clientalertsservice.BestOfferStatusCodeType',
    'com.ebay.clientalertsservice.BestOfferTypeCodeType',
    'com.ebay.clientalertsservice.ClientAlertsBestOfferType',
    'com.ebay.clientalertsservice.CounterOfferReceivedEventType',
    'com.ebay.clientalertsservice.MessageTypeCodeType',
    'com.ebay.clientalertsservice.AskSellerQuestionEventType',
    'com.ebay.clientalertsservice.ItemUnsoldEventType',
    'com.ebay.clientalertsservice.ItemEndedEventType',
    'com.ebay.clientalertsservice.ItemSoldEventType',
    'com.ebay.clientalertsservice.ItemLostEventType',
    'com.ebay.clientalertsservice.ItemWonEventType',
    'com.ebay.clientalertsservice.BidReceivedEventType',
    'com.ebay.clientalertsservice.BidPlacedEventType',
    'com.ebay.clientalertsservice.EndOfTransactionEventType',
    'com.ebay.clientalertsservice.ClientAlertsTransactionType',
    'com.ebay.clientalertsservice.EndOfAuctionEventType',
    'com.ebay.clientalertsservice.SecondChanceOfferEventType',
    'com.ebay.clientalertsservice.ItemRemovedFromWatchListEventType',
    'com.ebay.clientalertsservice.ItemAddedToWatchListEventType',
    'com.ebay.clientalertsservice.OutbidEventType',
    'com.ebay.clientalertsservice.WatchedItemEndingSoonEventType',
    'com.ebay.clientalertsservice.CurrencyCodeType',
    'com.ebay.clientalertsservice.AmountType',
    'com.ebay.clientalertsservice.PriceChangeEventType',
    'com.ebay.clientalertsservice.ClientAlertsEventType',
    'com.ebay.clientalertsservice.ChannelContentType',
    'com.ebay.clientalertsservice.ErrorClassificationCodeType',
    'com.ebay.clientalertsservice.ErrorParameterType',
    'com.ebay.clientalertsservice.SeverityCodeType',
    'com.ebay.clientalertsservice.ErrorType',
    'com.ebay.clientalertsservice.AckCodeType',
    'com.ebay.clientalertsservice.AbstractResponseType',
    'com.ebay.clientalertsservice.GetPublicAlertsResponseType',
    'com.ebay.clientalertsservice.ClientAlertsEventTypeCodeType',
    'com.ebay.clientalertsservice.ChannelTypeCodeType',
    'com.ebay.clientalertsservice.ChannelDescriptorType',
    'com.ebay.clientalertsservice.AbstractRequestType',
    'com.ebay.clientalertsservice.GetPublicAlertsRequestType',
    'com.ebay.clientalertsservice.Utils'
  ],
  getUserAlerts: [
    'com.ebay.widgets.util.Duration',
    'com.ebay.widgets.io.Factory',
    'com.ebay.widgets.io.XSSRequest',
    'com.ebay.widgets.io.XHRRequest',
    'com.ebay.clientalertsservice.ClientAlertsConfig',
    'com.ebay.clientalertsservice.ClientAlertsCallback',
    'com.ebay.clientalertsservice.FeedbackRatingStarCodeType',
    'com.ebay.clientalertsservice.ClientAlertsUserType',
    'com.ebay.clientalertsservice.FeedbackStarChangedEventType',
    'com.ebay.clientalertsservice.FeedbackLeftEventType',
    'com.ebay.clientalertsservice.TradingRoleCodeType',
    'com.ebay.clientalertsservice.CommentTypeCodeType',
    'com.ebay.clientalertsservice.ClientAlertsFeedbackDetailType',
    'com.ebay.clientalertsservice.FeedbackReceivedEventType',
    'com.ebay.clientalertsservice.BestOfferPlacedEventType',
    'com.ebay.clientalertsservice.BestOfferDeclinedEventType',
    'com.ebay.clientalertsservice.BestOfferStatusCodeType',
    'com.ebay.clientalertsservice.BestOfferTypeCodeType',
    'com.ebay.clientalertsservice.ClientAlertsBestOfferType',
    'com.ebay.clientalertsservice.CounterOfferReceivedEventType',
    'com.ebay.clientalertsservice.MessageTypeCodeType',
    'com.ebay.clientalertsservice.AskSellerQuestionEventType',
    'com.ebay.clientalertsservice.ItemUnsoldEventType',
    'com.ebay.clientalertsservice.ItemEndedEventType',
    'com.ebay.clientalertsservice.ItemSoldEventType',
    'com.ebay.clientalertsservice.ItemLostEventType',
    'com.ebay.clientalertsservice.ItemWonEventType',
    'com.ebay.clientalertsservice.BidReceivedEventType',
    'com.ebay.clientalertsservice.BidPlacedEventType',
    'com.ebay.clientalertsservice.EndOfTransactionEventType',
    'com.ebay.clientalertsservice.ClientAlertsTransactionType',
    'com.ebay.clientalertsservice.EndOfAuctionEventType',
    'com.ebay.clientalertsservice.SecondChanceOfferEventType',
    'com.ebay.clientalertsservice.ItemRemovedFromWatchListEventType',
    'com.ebay.clientalertsservice.ItemAddedToWatchListEventType',
    'com.ebay.clientalertsservice.OutbidEventType',
    'com.ebay.clientalertsservice.WatchedItemEndingSoonEventType',
    'com.ebay.clientalertsservice.CurrencyCodeType',
    'com.ebay.clientalertsservice.AmountType',
    'com.ebay.clientalertsservice.PriceChangeEventType',
    'com.ebay.clientalertsservice.ClientAlertsEventType',
    'com.ebay.clientalertsservice.ClientAlertsType',
    'com.ebay.clientalertsservice.ErrorClassificationCodeType',
    'com.ebay.clientalertsservice.ErrorParameterType',
    'com.ebay.clientalertsservice.SeverityCodeType',
    'com.ebay.clientalertsservice.ErrorType',
    'com.ebay.clientalertsservice.AckCodeType',
    'com.ebay.clientalertsservice.AbstractResponseType',
    'com.ebay.clientalertsservice.GetUserAlertsResponseType',
    'com.ebay.clientalertsservice.AbstractRequestType',
    'com.ebay.clientalertsservice.GetUserAlertsRequestType',
    'com.ebay.clientalertsservice.Utils'
  ],
  getPublicAlerts: [
    'com.ebay.widgets.util.Duration',
    'com.ebay.widgets.io.Factory',
    'com.ebay.widgets.io.XSSRequest',
    'com.ebay.widgets.io.XHRRequest',
    'com.ebay.clientalertsservice.ClientAlertsConfig',
    'com.ebay.clientalertsservice.ClientAlertsCallback',
    'com.ebay.clientalertsservice.FeedbackRatingStarCodeType',
    'com.ebay.clientalertsservice.ClientAlertsUserType',
    'com.ebay.clientalertsservice.FeedbackStarChangedEventType',
    'com.ebay.clientalertsservice.FeedbackLeftEventType',
    'com.ebay.clientalertsservice.TradingRoleCodeType',
    'com.ebay.clientalertsservice.CommentTypeCodeType',
    'com.ebay.clientalertsservice.ClientAlertsFeedbackDetailType',
    'com.ebay.clientalertsservice.FeedbackReceivedEventType',
    'com.ebay.clientalertsservice.BestOfferPlacedEventType',
    'com.ebay.clientalertsservice.BestOfferDeclinedEventType',
    'com.ebay.clientalertsservice.BestOfferStatusCodeType',
    'com.ebay.clientalertsservice.BestOfferTypeCodeType',
    'com.ebay.clientalertsservice.ClientAlertsBestOfferType',
    'com.ebay.clientalertsservice.CounterOfferReceivedEventType',
    'com.ebay.clientalertsservice.MessageTypeCodeType',
    'com.ebay.clientalertsservice.AskSellerQuestionEventType',
    'com.ebay.clientalertsservice.ItemUnsoldEventType',
    'com.ebay.clientalertsservice.ItemEndedEventType',
    'com.ebay.clientalertsservice.ItemSoldEventType',
    'com.ebay.clientalertsservice.ItemLostEventType',
    'com.ebay.clientalertsservice.ItemWonEventType',
    'com.ebay.clientalertsservice.BidReceivedEventType',
    'com.ebay.clientalertsservice.BidPlacedEventType',
    'com.ebay.clientalertsservice.EndOfTransactionEventType',
    'com.ebay.clientalertsservice.ClientAlertsTransactionType',
    'com.ebay.clientalertsservice.EndOfAuctionEventType',
    'com.ebay.clientalertsservice.SecondChanceOfferEventType',
    'com.ebay.clientalertsservice.ItemRemovedFromWatchListEventType',
    'com.ebay.clientalertsservice.ItemAddedToWatchListEventType',
    'com.ebay.clientalertsservice.OutbidEventType',
    'com.ebay.clientalertsservice.WatchedItemEndingSoonEventType',
    'com.ebay.clientalertsservice.CurrencyCodeType',
    'com.ebay.clientalertsservice.AmountType',
    'com.ebay.clientalertsservice.PriceChangeEventType',
    'com.ebay.clientalertsservice.ClientAlertsEventType',
    'com.ebay.clientalertsservice.ChannelContentType',
    'com.ebay.clientalertsservice.ErrorClassificationCodeType',
    'com.ebay.clientalertsservice.ErrorParameterType',
    'com.ebay.clientalertsservice.SeverityCodeType',
    'com.ebay.clientalertsservice.ErrorType',
    'com.ebay.clientalertsservice.AckCodeType',
    'com.ebay.clientalertsservice.AbstractResponseType',
    'com.ebay.clientalertsservice.GetPublicAlertsResponseType',
    'com.ebay.clientalertsservice.ClientAlertsEventTypeCodeType',
    'com.ebay.clientalertsservice.ChannelTypeCodeType',
    'com.ebay.clientalertsservice.ChannelDescriptorType',
    'com.ebay.clientalertsservice.AbstractRequestType',
    'com.ebay.clientalertsservice.GetPublicAlertsRequestType',
    'com.ebay.clientalertsservice.Utils'
  ],
  getUserAlerts: [
    'com.ebay.widgets.util.Duration',
    'com.ebay.widgets.io.Factory',
    'com.ebay.widgets.io.XSSRequest',
    'com.ebay.widgets.io.XHRRequest',
    'com.ebay.clientalertsservice.ClientAlertsConfig',
    'com.ebay.clientalertsservice.ClientAlertsCallback',
    'com.ebay.clientalertsservice.ClientAlertsEventType',
    'com.ebay.clientalertsservice.ClientAlertsType',
    'com.ebay.clientalertsservice.ErrorClassificationCodeType',
    'com.ebay.clientalertsservice.ErrorParameterType',
    'com.ebay.clientalertsservice.SeverityCodeType',
    'com.ebay.clientalertsservice.ErrorType',
    'com.ebay.clientalertsservice.AckCodeType',
    'com.ebay.clientalertsservice.AbstractResponseType',
    'com.ebay.clientalertsservice.GetUserAlertsResponseType',
    'com.ebay.clientalertsservice.AbstractRequestType',
    'com.ebay.clientalertsservice.GetUserAlertsRequestType',
    'com.ebay.clientalertsservice.Utils'
  ],
  login: [
    'com.ebay.widgets.util.Duration',
    'com.ebay.widgets.io.Factory',
    'com.ebay.widgets.io.XSSRequest',
    'com.ebay.widgets.io.XHRRequest',
    'com.ebay.clientalertsservice.ClientAlertsConfig',
    'com.ebay.clientalertsservice.ClientAlertsCallback',
    'com.ebay.clientalertsservice.ErrorClassificationCodeType',
    'com.ebay.clientalertsservice.ErrorParameterType',
    'com.ebay.clientalertsservice.SeverityCodeType',
    'com.ebay.clientalertsservice.ErrorType',
    'com.ebay.clientalertsservice.AckCodeType',
    'com.ebay.clientalertsservice.AbstractResponseType',
    'com.ebay.clientalertsservice.LoginResponseType',
    'com.ebay.clientalertsservice.AbstractRequestType',
    'com.ebay.clientalertsservice.LoginRequestType',
    'com.ebay.clientalertsservice.Utils'
  ],
  logout: [
    'com.ebay.widgets.util.Duration',
    'com.ebay.widgets.io.Factory',
    'com.ebay.widgets.io.XSSRequest',
    'com.ebay.widgets.io.XHRRequest',
    'com.ebay.clientalertsservice.ClientAlertsConfig',
    'com.ebay.clientalertsservice.ClientAlertsCallback',
    'com.ebay.clientalertsservice.ErrorClassificationCodeType',
    'com.ebay.clientalertsservice.ErrorParameterType',
    'com.ebay.clientalertsservice.SeverityCodeType',
    'com.ebay.clientalertsservice.ErrorType',
    'com.ebay.clientalertsservice.AckCodeType',
    'com.ebay.clientalertsservice.AbstractResponseType',
    'com.ebay.clientalertsservice.LogoutResponseType',
    'com.ebay.clientalertsservice.AbstractRequestType',
    'com.ebay.clientalertsservice.LogoutRequestType',
    'com.ebay.clientalertsservice.Utils'
  ]
});
/**    
	@class ServerConfig               
**/
com.ebay.widgets.createClass('com.ebay.clientalerts.service.ServerConfig')
.props({
    QA: null,
    Production: null,
    Sandbox: null
})
.methods({
  URL: null,
  constructs: function (object) {
    this.URL = object.hasOwnProperty('URL')? object.URL: object;
  },
  
  getURL: function () {
  	return this.URL;
  }
})
.inits(function() {
    com.ebay.clientalerts.service.ServerConfig.QA = new com.ebay.clientalerts.service.ServerConfig(
		{URL: 'http://qa-notifya05.qa.ebay.com:8080/ws/ecasvc/ClientAlerts'})
    com.ebay.clientalerts.service.ServerConfig.Production = new com.ebay.clientalerts.service.ServerConfig(
		{URL: 'http://clientalerts.ebay.com/ws/ecasvc/ClientAlerts'})
    com.ebay.clientalerts.service.ServerConfig.Sandbox = new com.ebay.clientalerts.service.ServerConfig(
		{URL: 'http://sandbox.clientalerts.ebay.com/ws/ecasvc/ClientAlerts'})
});

/**    
	@class Global               
**/
com.ebay.widgets.createClass('com.ebay.clientalerts.util.Global')
.methods({
	constructs: function(){ 	
		this.logger = new com.ebay.clientalerts.util.Logger();
	},
	getLogger: function(){
		return this.logger;
	},
	setServerConfig: function(vserverConfig){
  		com.ebay.clientalerts.util.Global.serverConfig = vserverConfig;
 	},
	validatePollingInterval: function(pollingInterval) {
		if(pollingInterval < 30 )
		{
			alert("Polling Interval can't be less than 30 seconds, please reset it!")
			return false;
		}
		else
		{
			return true;
		}		
	}
		
})
.props({
	channelTypes:["Item"],
	eventTypes:["PriceChange", "ItemEnded"],
	pollingIntervals:[30,60,600,1800,3600],
	defaultPollingInterval: 30,
	serverConfig: com.ebay.clientalerts.service.ServerConfig.Production,
	version: "563",
	resources: [
			'com.ebay.clientalerts.util.Logger',
			'com.ebay.clientalerts.service.ClientAlertsBase',
			'com.ebay.clientalerts.api.Channel',
			'com.ebay.clientalerts.api.ChannelManager',
			'com.ebay.clientalerts.api.Session',
			'com.ebay.clientalerts.service.ClientContext',
			'com.ebay.clientalerts.service.HeartBeatManager',
			'com.ebay.clientalerts.service.ProtocolManager',
			'com.ebay.clientalerts.service.Connection'
		].concat(com.ebay.clientalertsservice.ClientAlerts.getPublicAlerts, 
		com.ebay.clientalertsservice.ClientAlerts.getUserAlerts,
		com.ebay.clientalertsservice.ClientAlerts.login,
		com.ebay.clientalertsservice.ClientAlerts.logout)
}
);

com.ebay.widgets.needs({
	baseUrl:'http://w-1.ebay.com/clientalerts/js/1.0/min/',
	resources: com.ebay.clientalerts.util.Global.resources,
	callback:
	function() {
	}
});	
