// libreria para manipulacion de la grilla jqGrid
		
		var jq ={
			response:'',
			content:'',
			bloqueado:'Y',
			showAccion:function(){		
				
				$("#divespecifica").slideDown();	
				
				
				if ($("input[@name=nombreSel]").val()!="")
				{
					var nombre = this.getSelected($("input[@name=nombreSel]").val());
					if (nombre.length < 28 )
						$("#seleccionado").html(nombre);
					else
						$("#seleccionado").html(nombre.substr(0,29)+"..");						
				}

				if ($("input[@name=thumbnail]").val()!= "")
				{ 
						$("#imagen_show").attr("src",$("input[@name=uploadDir]").val() + this.getSelected($("input[@name=thumbnail]").val()));
						$("#imagen_show").attr("title",this.getSelected($("input[@name=nombreSel]").val()));			
				}		
				if(typeof(afterSelect) == 'function')afterSelect();		
			},			
			abrir:function(title, url , id, width, height){
					var alto;alto = (document.all ? document.body.offsetHeight + document.body.scrollHeight: window.innerHeight + window.scrollMaxY);
					//tapado,un zindex mas que el mas alto
					//var maxzindex = 0;$("div,img").each(function(){var z = $(this).css("z-index"); if(z>maxzindex)maxzindex=z;});
					//$("<div>").addClass("tapado").css("height",alto).appendTo("body");
					
	
					this.bloqueado='N'; //bloqueamos para que no se pueda grabar 2 veces
					var nom = title.replace(" ","");nom = title.replace(" ","");							
					
					nom = nom.substr(0,5);  //titulo sobre acciones
					
					$("div.flora").remove(); //una sola ventana a la vez
					var div = document.createElement('div');
					if(nom!='')
						div.id = nom;
					else
						div.id = 'id';
					$(div).addClass("flora");
					
					$(div).appendTo("#divframe"); 
					$("object").hide(); //ocultamos flashes
					$("input[@name=frame]").val(url);$("input[@name=dialog]").val(div.id);
					$("#"+div.id).dialog({ draggable:false, resizable:false, modal:true, width:width, height:height, title: title });		
					this.getUrl(div , url, id, width, height, title);
			},			
			cambiar:function(title, url , id, width, height){
				var val = 0;
				if(id!="")
					val = this.getSelected($("input[@name=idSel]").val());
				var open = "window.location='" + url + "?1&" + id + "=" + val + "&reload=Y'";
				eval(open);
			},
			newWindow:function(title, url , id, width, height){
				var val = 0;
				if(id!="")
					val = this.getSelected($("input[@name=idSel]").val());
				var open = "window.open('" + url + "?1&" + id + "=" + val + "')";
				eval(open);
			},
			getUrl:function(div , url, id , width, height, title){
				var val = 0;
				if(id!="")
					val = this.getSelected($("input[@name=idSel]").val());
					
				$.ajax({
						//async: false,
						type: "POST",
						url: url,
						data:  "1=1&" + id + "=" +  val,
						beforeSend: function(){
							$(div).html("<img src='"+$("input[@name=url]").val()+"template/BEbase/images/iconos/loading.gif"+"' />Cargando..");
						},
						success: function(responseText) {
								$(div).html(decodeURIComponent(responseText));		
								
								$("input").not("[@type=file]").each( function(){ this.value = decodeURI(this.value); } );
								if(typeof(onLoad) == "function")
									onLoad();
								//scripts en la ventana bajo la clase script
								eval($("div.flora").find("span.script").html());	
							}						
					});
			},			
			reload:function(actualizar){	
					
					$("#"+$("input[@name=dialog]").val()).dialog("close");
					$("input.formulario,input.formularioRequerido").unbind("click");		
					$("input.formulario,textarea,input.formularioRequerido,input.persiana").not("[@type=file]").each( function()
					//$("input.formulario,input.formularioRequerido,input.persiana").not("[@type=file]").each( function()
					{this.value = encodeURI(this.value); } );
						
					if((actualizar==undefined))
						actualizar=true;
					
					$("input[@name=reload]").val("Y");					
					var parametros = $("input,textarea,select").serialize();	
					if(this.bloqueado=='N')
					{
					this.bloqueado='Y';
					$.ajax({
							//async: false,
							type: "POST",
							url: $("input[@name=frame]").val(),
							data:   parametros,							
							success: function(responseText) {
								$("input[@type=file]").each(function(){ 
									f = this;
									f.name= "_" + responseText + f.name;
									$(f).appendTo("#files");								
								});
								
								if ( (jq.strpos(responseText,'ERROR')>-1) || (jq.strpos(responseText,'NOTA')>-1) )
									alert(responseText);
			
									if(actualizar==true)
										//i=0;
										document.forms[0].submit();		
									else
									{
										jq.cerrar();
										jq.response = responseText;
										if(typeof(OnReload) == "function")
											OnReload();
									}	
								$(".tapado").remove();
							}			
						});
					}
			},	
			wysiwyg:function(id){
				tinyMCE.init({
				
				// General options
				//mode : "textareas",
				mode : "exact",
				elements: id,
				theme : "advanced",
				plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
				// Theme options
				theme_advanced_buttons1 : "bold,italic,underline,|,pastetext,removeformat,|,bullist,numlist",
				theme_advanced_buttons2 : "outdent,indent,undo,redo,|,backcolor,link,unlink",
				theme_advanced_buttons3 : "",
				theme_advanced_buttons4 : "",
				theme_advanced_toolbar_location : "top",
				theme_advanced_toolbar_align : "left",
				theme_advanced_statusbar_location : "bottom",
				theme_advanced_resizing : true,
				// Example content CSS (should be your site CSS)
				content_css : $("input[@name=url]").val()+"template/BEbase/css/noticias/"+ id +".css",
				// Drop lists for link/image/media/template dialogs
				template_external_list_url : "js/template_list.js",
				external_link_list_url : "js/link_list.js",
				external_image_list_url : "js/image_list.js",
				media_external_list_url : "js/media_list.js",
				// Replace values for the template plugin
				template_replace_values : {
				username : "Some User",
				staffid : "991234"
				}
			  });	
			},
			wysSerialize:function(name){
				var id = $("textarea[@name="+ name +"]").attr("id");
				//return $("textarea[@name="+ name +"]").val();
				return tinyMCE.get(id).getContent();
				//return encodeURIComponent(tinyMCE.get(name));
			},
			inc:function(filename)
			{
			script = document.createElement('script');
			script.src = filename;
			script.type = 'text/javascript';
			document.getElementsByTagName('head')[0].appendChild(script);
			},
			
			init:function(){
				
				$("#divgeneral").show();
				
				this.asignarEnter("#grillaFiltro","buscarGrilla();");
				this.asignarEnter("#filtroInput","jq.buscarTitulo();");
				if ($("input[@name=thumbnail]").val()== "")
				{
					$("#imagen_show").attr("src",$("input[@name=uploadDir]").val()+"blank.gif");
					$("#imagen_show").attr("width","1");
				}
								
				$("#grillaFiltro").click(function(){$(this).select();});
				//boton salir
				$("#salir").click(function(){window.location=''+$("input[@name=url]").val()+'backend/seguridad/login.php';});
				//opciones del menu
				$(".clickMenu ul > li").each(function(){$(this).click(function(){eval($(this).find("span").attr("onclick"));});});			
			},
			
			getSelected:function (campo)
			{
				if($("#list2").size()>0){ //si usamos la grilla de siempre
					var id = $("#list2").getSelectedRow(); 
					if (id) { 
						var ret = $("#list2").getRowData(id); 
						var exec = "ret."+campo;
						var fin = eval(exec);
						return fin;
						}
				}//si usamos la simple
				else{
					return noticia_id;
				}
			},
			asignarEnter:function (input,funcion)
			{
				$(input).keyup(function (e) {
      			if ( e.which == 13 )
      				eval(funcion);
      			if ( e.keyCode == 13 )
      				eval(funcion);
      			});
			},
			enable:function(checkbox, element)
			{
				if ( checkbox.checked == true )
      				$("input[@name="+element+"]").removeAttr("disable");
      			else
      				$("input[@name="+element+"]").attr("disable","disable");
      		},
      		buscarTitulo:function()
      		{
      			window.location='home.php?titulo='+$('input[@name=titulo]').val();
      		},
      		showDiv:function(name)
			{
				$("div.step").hide();
				$("#"+name).slideDown("slow");
      		},
      		showTab:function(name)
			{
				$("div.tab").hide();
				$("#"+name).show();
      		},
			mostrar:function(div){
	
				if ( $("#a" + div).html() == "[+]" )
					$("#a" + div).html("[-]");
				else
					$("#a" + div).html("[+]");
					
				$("#" + div).toggle("slow");
			},
			mostrarUnico:function(div){
	
				//$("div.tab").not("#a" + div).hide();
				//$("a.persiana").not("#a" + div).html("[+]");
				
				if ( $("#a" + div).html() == "[+]" )
				{
					$("#a" + div).html("[-]");
					$("#" + div).slideDown("slow");
				}
				else
				{
					$("#a" + div).html("[+]");
					$("#" + div).slideUp("slow");
				}					
				
			},
			cerrar:function(){
				$("#" + $("input[@name=dialog").val()).dialog("close");
				$("div.flora").remove();
			},
			/*
			resaltar:function(name){
				var id = $("textarea[@name=" + name + "]").attr("id");
				tinymce.EditorManager.editors[id].execCommand('mceSetCSSClass',false,'backamarillo');return false;
			},*/
			resizeText:function(obj,width){
		
				var textsize = $(obj).css("font-size");textsize = textsize.replace("px","");
				var cols = Math.ceil(width/textsize); cols = cols*1.73; //1.73 numero magico
				var rows = Math.ceil(obj.value.length/cols);
				if(rows != $(obj).attr("rows"))
					$(obj).attr("rows",rows); 
			},
			removeTags:function(name){
			 	if($("textarea[@name="+name+"]").val()){
			 		var strInputCode = $("textarea[@name="+name+"]").val();
			 		var strTagStrippedText = strInputCode.replace(/<p>/g,''); //removes <p>
			 		strTagStrippedText = strTagStrippedText.replace(/<\/p>/g,'<br/>'); //replace </p> with <br/>
			 		return strTagStrippedText;
			 	}	
			},
			getSelectedText:function(textarea,ini,fin){
				
					if(ini==undefined) ini = "<r>";
					if(fin==undefined) fin = "</r>";
					
					//crappy browser sniffer 
					var isFF = false; 
					var textselected = false; 
					if(navigator.userAgent.toLowerCase().indexOf("firefox") > 0){ 
						isFF = true; 
					} 
					var myArea = document.getElementsByName(textarea)[0]; 
					var begin,selection,end; 
					if (isFF == true){ 
						if (myArea.selectionStart!= undefined) {  
							begin = myArea.value.substr(0, myArea.selectionStart);  
							selection = myArea.value.substr(myArea.selectionStart, myArea.selectionEnd - myArea.selectionStart);  
							end = myArea.value.substr(myArea.selectionEnd); 
							if (selection.length > 0){ 
								textselected = true; 
							} 
					} 
					}else{ 
						if (window.getSelection){ 
							selection = window.getSelection(); 
						}else if (document.getSelection){ 
							selection = document.getSelection(); 
						}else if (document.selection){ 
							selection = document.selection.createRange().text; 
						} 
						var startPos = myArea.value.indexOf(selection); 
						if (startPos!= 0){ 
							var endPos = myArea.value.indexOf(selection) + selection.length; 
							begin = myArea.value.substr(0,startPos); 
							end = myArea.value.substr(endPos, myArea.value.length); 
							textselected = true; 
						} 
					}  
				 
				 if(textselected==true)
				 {
					 myArea.value = begin + ini + selection + fin + end; 
					 myArea.focus(); 
				}
				else
					alert("No se ha seleccionado ningun texto.");
				
			},
			strpos:function(str, ch) {
				for (var i = 0; i < str.length; i++)
					if (str.substring(i, ch.length) == ch) 
						return i;
				return -1;
			}
		}
		
		$(document).ready( function(){  //$("#loading").show();
		if(typeof(jq.init) == 'function')jq.init();} );
		
		
