YAHOO.namespace("bd.services");
YAHOO.bd.services.MngHtm=function(){};

YAHOO.bd.services.MngHtm.prototype = {
	
	loadHTML:function (file,divId,jsToLoad_JSON) {
		var sUrl = file ;
		var onHtmCargado ;
		YAHOO.log("insertarFooter");
		
		function onCargaDeDatos(o) {
			YAHOO.log("Datos Cargados - divId=" + divId + " - ambito: " + this);
			YAHOO.util.Dom.get(o.argument[0]).innerHTML = o.responseText;
			if (YAHOO.lang.isFunction(o.argument[2].onLoadHTML)) {
				o.argument[2].onLoadHTML();
			}
			//Cargo el js que haga falta
			var jsToLoad_JSON = o.argument[1];
			//alert(jsToLoad_JSON + " isNull:" + YAHOO.lang.isUndefined(jsToLoad_JSON));
			if (!YAHOO.lang.isUndefined(jsToLoad_JSON) && !YAHOO.lang.isNull(jsToLoad_JSON)) {
				o.argument[2].cargarJS(jsToLoad_JSON.js,jsToLoad_JSON.requires);
			}
		};	
		//	
		function onErrorRespuestaDeBack(o) {
		  	YAHOO.log("Todo mal se clavo - ambito:" +  this);
		};
		
		var callback = 
		{
		success: onCargaDeDatos,
		failure: onErrorRespuestaDeBack,
		argument:[divId,jsToLoad_JSON,this]
		};
		var transaction = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback, null);
		
	},
	
	msgbox:function (mensaje) {
		//TODO Completar msgbox
		if (YAHOO.lang.isUndefined(YAHOO.miGlobal.pMsgbox)) {
					YAHOO.miGlobal.pMsgbox = new YAHOO.widget.Panel("panelMsgbox", {
					draggable:false, 
					width:"242px", 
					height:"155px", 
					close:true, 
					constraintoviewport:true,
					fixedcenter: true, 
					//x:200,y:200,
					zIndex:1300,
					underlay:"none",
					visible:false,
					modal:true
			
				} ); 
				YAHOO.miGlobal.pMsgbox.setBody('<p class="cuerpoMensaje"><br />'+mensaje+'</p>');
				YAHOO.miGlobal.pMsgbox.setHeader("<h1> </h1>")
				//YAHOO.miGlobal.pMsgbox.setHeader("</br>");
				//YAHOO.miGlobal.pMsgbox.setFooter('<p id="btCerrarMsgBox" onclick="YAHOO.miGlobal.pMsgbox.hide();">Cerrar</p>');
				YAHOO.miGlobal.pMsgbox.hideEvent.subscribe(function () {
					var el = new YAHOO.util.Element("panelMsgbox");	
					el.setStyle("display","none");	
				});
				YAHOO.miGlobal.pMsgbox.renderEvent.subscribe(function () { 
					//alert("render");
					YAHOO.miGlobal.pMsgbox.show();
					YAHOO.miGlobal.pMsgbox.center();
				})
				YAHOO.miGlobal.pMsgbox.render(document.body);
				
		} else 	{
			YAHOO.miGlobal.pMsgbox.setBody('<p class="cuerpoMensaje"><br />'+mensaje+'</p>');
			YAHOO.miGlobal.pMsgbox.show();
		}
		var el = new YAHOO.util.Element("panelMsgbox");	
		el.setStyle("display","block");
		YAHOO.miGlobal.pMsgbox.center();
		
		
	},
	
	working:function (boleano) {
		if (boleano==true) {
			if (YAHOO.lang.isUndefined(YAHOO.miGlobal.pWorking)) {
					YAHOO.miGlobal.pWorking = new YAHOO.widget.Panel("panelWorking", {
					draggabel:false, 
					width:"200px", 
					height:"100px", 
					close:false, 
					constraintoviewport:true,
					fixedcenter: true, 
					//x:200,y:200,
					zIndex:1300,
					underlay:"none",
					visible:false,
					modal:true
			
				} ); 
				YAHOO.miGlobal.pWorking.hideEvent.subscribe(function () {
					var el = new YAHOO.util.Element("panelWorking");	
					el.setStyle("display","none");	
				});
				YAHOO.miGlobal.pWorking.renderEvent.subscribe(function () { 
					//alert("render");
					YAHOO.miGlobal.pWorking.show();
					YAHOO.miGlobal.pWorking.center();
				})
				YAHOO.miGlobal.pWorking.setBody('<p> Cargando ... </p>');
				YAHOO.miGlobal.pWorking.render(document.body);
				YAHOO.miGlobal.pWorking.show();
			} else 	{
				YAHOO.miGlobal.pWorking.show();
			}	
			var el = new YAHOO.util.Element("panelWorking");	
			el.setStyle("display","block");
			YAHOO.miGlobal.pWorking.center();
			YAHOO.miGlobal.pWorking.center();
			YAHOO.miGlobal.pWorking.center();
			YAHOO.miGlobal.pWorking.center();
			YAHOO.miGlobal.pWorking.center();
			
			
			//alert('working' + boleano);
		}else{
			YAHOO.miGlobal.pWorking.hide();
			
		}
		
	},//Fin working
	//
	cargarJS:function (js,pRequires) {
		if (YAHOO.lang.isUndefined(js)){
			return null;
		}
		var loader = new YAHOO.util.YUILoader(); 
		 //Add the module to YUILoader 
	   var moduleName = new String(js);
	   moduleName=moduleName.split("/")[moduleName.split("/").length-1];
	   loader.base = 'lib/YahooUI/';
	   loader.addModule({ 
	        name: moduleName, //module name; must be unique 
	        type: "js", //can be "js" or "css" 
	        fullpath: js, //can use a path instead, extending base path 
	        //verifier: checkJSON, //the verifier function we just defined 
	        requires: pRequires //if this module had dependencies, we could define here 
	    }); 
		YAHOO.log("Cargando Modulo" + moduleName);
		loader.require(moduleName); //include the new  module 
	 
	    //Insert moduleName utility on the page, passing in our callback: 
	    function onJSLoad(){
			Yahoo.log("archivo js cargado");
			//alert("archivo js cargado");
		}
		loader.insert(onJSLoad); 
	}
	
};