var JSONP = {
	/*Guarda la referencia al script*/
	script: null,
	options: {},
	/*Realiza la llamada a la url especificada*/
	call: function(url, options){
		//Comprobacion de las opciones
		if(!options) this.options = {};
		this.options.callback = options.callback || function(){};
		this.options.callbackParamName = options.callbackParamName || "callback";
    this.options.params = options.params || [];
		//Determina si se debe añadir el parámetro separado por ? o por &
		var separator = url.indexOf("?") > -1? "&" : "?";
		/*Serializa el objeto en una cadena de texto con formato URL*/
		var params = [];
		for(var prop in this.options.params){
			params.push(prop + "=" + encodeURIComponent(options.params[prop]));
		}
		var stringParams = params.join("&");
		//Crea el script o borra el usado anteriormente
		var head = document.getElementsByTagName("head")[0];
		if(this.script){
			head.removeChild(script);
		}
		script = document.createElement("script");
		script.type = "text/javascript";
		//Añade y carga el script, indicandole que llame al metodo process
		script.src = url + separator + stringParams + (stringParams?"&":"") + this.options.callbackParamName +"=JSONP.process";
    head.appendChild(script);
	},
	/*Recibe el resultado*/
	process: function(data) {
		this.options.callback(data);
	}
};

