// JavaScript Document
function cambiaUrl(Url){
	window.location = Url;
}
	
function cambiaPantalla(vUrl,datos,funcion){
	clase=this;
	var contenedor=this.idContPri;
	clase.chequeaEventosAjax(true);
	clase.controlAjax.add({
		type: "POST",
		data: datos,
		url: vUrl,
		success: function(html){
			$(contenedor).html(html);
			eval(funcion);
			if(datos) $().cmDebug({tipo:'url', texto:'-- Datos enviados: '+datos});
			if(funcion) $().cmDebug({tipo:'url', texto:'-- Funci&oacute;n ejecutada: '+funcion});
			$().cmDebug({tipo:'ajax', texto:'<strong>AJAX: Cambio de Pantalla:</strong> Secci&oacute;n cambiada con &eacute;xito a '+vUrl});
			if(("#header").length > 0)
			cmm = new cmwMenu("#header","#cmmMenuFlash", cmw.dirImg);	
		},
		error: function(msj){
			$().cmDebug({tipo:'ajax', texto:'<strong>Cambio de Secci&oacute;n:</strong> Error producido '+msj});
		}
	 });
							  
}

function cambiaSeccion(vUrl,datos,funcion){
	var clase = this;
	var contenedor=clase.idContSec;
	var camposTxt = "";
	var valoresTxt= "";
	var dirSeccion = vUrl.split("/");
	var urlModulo = "";
	jQuery.each(dirSeccion,function(i){
		if(!(i+1 == dirSeccion.length)) urlModulo += this+"/";
	});
	clase.urlModulo = urlModulo;
	
	eval(funcion);
	
	if(datos && datos!==undefined){		
		var valores=datos.split("&");			
		for(i=0;i<valores.length;i++){
			var condiciones=valores[i].split("=");			
			for(j=0;j<condiciones.length;j+=2){				
				var campo=condiciones[j];
				var valor=condiciones[j+1];				
				camposTxt=camposTxt+","+condiciones[j];
				valoresTxt=valoresTxt+","+condiciones[j+1];				
			}
		}
	}	
	
	camposTxt = camposTxt+',seccion';	
	valoresTxt = valoresTxt+','+vUrl;
	
	$("#pantalla").css({overflow : "hidden"});
	$("#cargaSeccion").css({overflow : "hidden"});
	
	$.post("./sistema/cmworks/herramientas/detonante.php",{
		   
		accion: "actualizarSessionM", 
		camposTxt: camposTxt,
		valoresTxt: valoresTxt
	
	},function(){
			$().cmDebug({
				tipo:'ajax', 
				texto:'<strong>Variables de sesi&oacute;n:</strong> Campos:'+camposTxt+" Valores:"+valoresTxt
			});
			$.post("./sistema/cmworks/herramientas/btnAcciones.php",{
				dirImgs: clase.dirImg,
				idSeccion:cmw.idSeccion
			},function(toolbarDatos){				  
				clase.controlAjax.add({
					url: vUrl,
					success: function(html){
						$(contenedor).html(html);
						botonesT = new Array();
						if(!(toolbarDatos == "")){
							datosT = toolbarDatos.split("**");
							jQuery.each(datosT,function(){
								var valores = this.split(";;");
								var botonT = new Array();
								jQuery.each(valores,function(){
									eval("botonT"+this+";");							 
								});
								botonesT.push(botonT);
							});
						}
						cmw.actualizarToolbar(botonesT);
						if(datos) $().cmDebug({
							tipo:'info', texto:'-- Datos enviados: '+datos
						});
						if(funcion) $().cmDebug({
							tipo:'info', 
							texto:'-- Funci?n ejecutada: '+funcion
						});
						$().cmDebug({
							tipo:'ajax', 
							texto:'<strong>Cambio de Secci&oacute;n:</strong> Secci&oacute;n cambiada con &eacute;xito a '+vUrl});
						},
					error: function(msj){
						$().cmDebug({
							tipo:'url', 
							texto:'<strong>Cambio de Secci&oacute;n:</strong> Error producido '+msj
						});
					}
				});
			});
		}
	);		
}
