﻿var IFrame = {
	arreglo : [],
	_fr : function(indice){
		var self = this;
		self.indice = indice;
		self.frameID = 'IFrameFnLoad_' + self.indice;		
		self.onfinish = function(response){};
		self.loaded = function(){};
		self.response = "";
		self.fcreate = function(src){
			var capa = document.createElement("DIV");
			if(!src)src = "about:blank";
			var htm =  '<iframe style="display:none" src="'+src+'" name="'+self.frameID +'"  id="'+self.frameID +'" ';
			htm += 'onload="IFrame.arreglo['+self.indice+'].loaded()"></iframe>';
			capa.innerHTML = htm;
        	document.body.appendChild(capa);
		}
		self.init = function(src){
			self.fcreate(src);
        	document.getElementById(self.frameID).onComplete = function(str){
				self.response = str;
				self.onfinish(str);	
			};
		}
		self.loaded = function(){
			var id = 'IFrameFnLoad_' + self.indice;
			var frame=document.getElementById(id);
			if (frame.contentDocument){var d = frame.contentDocument;
			}else if (frame.contentWindow){var d = frame.contentWindow.document;
			}else{var d = window.frames[id].document;}
			if(d.location.href=="about:blank"){return;}  
			if(typeof(frame.onComplete)=='function'){frame.onComplete(d.body.innerHTML);}
    	}
		
	},
	_add : function(){
	    var me = this;
		var indice = me.arreglo.length;
		me.arreglo[indice] = new me._fr(indice);
		var obj = me.arreglo[indice];
		return obj;
	}
}
