function createSortable(theId, theClass){
var clases=new Array(theClass);// que clases se van a aceptar
   Sortable.create(theId,{tag:"div",hoverclass:"hoverSortable",constraint: false,dropOnEmpty:true,
      onChange:function(){
	  var order=Sortable.serialize(theId);
 	$('debug').innerHTML='<strong>'+theId+' </strong>'+order;
	  }
    });
	}
function createDroppable(theId,theClass,logic){
	Droppables.add(theId, {
	  accept: theClass,
	  hoverclass:"hoverSortable",
	  onDrop: function(element) {
	   // $('shopping_cart_text').update('Dropped the ' + element.alt + ' on me.');
	    $('debug2').innerHTML=element.id;
	   droppableReact(element.id,theId,logic);
	  // element.remove();
	  }
	});
}
function droppableReact(id1,id2,logic){
	//if(confirm('lo movemos?')){
		 width = defecto(logic, 'foro', true);
		 $('debug2').innerHTML=id1+'-'+id2;
		 goAJAX('','foro.admin.ajax.php','acc=move&logic='+logic+'&id1='+id1+'&id2='+id2,'','','0','0');
		 $(id1).remove();
	//}
}
	
	
function showSysWindow(winName,winTitle,winDivId,File,w,h){
 	if(!isDefined(get(winName))){
  var win = new Window({id: winName, className: "mac_os_x", title: winTitle, width:w, height:h, wiredDrag: true,showEffectOptions:{duration:'0.0'},hideEffectOptions:{duration:'0.0'},recenterAuto:true}); 
  win.setDestroyOnClose(); 
  win.showCenter();
  win.setConstraint(true, {left:0, right:0, top: 30, bottom:10});
  win.toFront();
  win.setHTMLContent('<div class="winContent"><div id="'+winDivId+'"></div></div>');
  
   goAJAX(winDivId,File,'');
	}else{
			get(winName).toFront;
			}

}
function showWin(href,title,w,h,winDivId,winTitle){
	if(!isDefined(w)||(w=='')){w=600;}
	if(!isDefined(h)||(h=='')){h=400;}
	if(!isDefined(winDivId)||(winDivId=='')){
		var winDivId='div'+str_replace(' ','',title);
		}
	if(!isDefined(winTitle)||(winTitle=='')){
		var winTitle='win'+str_replace(' ','',title);
		}
	
	href=href+'&hwnd='+Math.floor(Math.random( ) * 999 - 2) + 1;
	showSysWindow(winTitle,title,winDivId,href,w,h);
	return false;
	}

function showEditF(id,width,height){
	width = defecto(width, 500, true);
	height = defecto(height, 340, true);
	showWin('foro.edit.ajax.php?logic=foro&id='+id,'Editar Foro',width,height,'ajaxEditF'+id,'winEditF'+id);
	return false;
}

function showEditT(id,width,height){
	width = defecto(width, 500, true);
	height = defecto(height, 340, true);
	showWin('foro.edit.ajax.php?logic=tema&id='+id,'Editar Tema',width,height,'ajaxEditT'+id,'winEditT'+id);
	return false;
}

function defecto(valor, defecto, quiero_null){
	quiero_null = quiero_null || false;
    if (quiero_null){
        valor = (typeof valor == 'undefined') ? defecto : valor;
    }else{
        valor = valor || defecto;
    }
    return valor;
}


function showDeleteF(id,titulo){
	if(confirm("¿Desea eliminar el foro: " + titulo + "?")){
		if(! confirm("¿Desea mover los subforos y temas a otro foro existente")){
			document.location.href = "foro.admin.ajax.php?acc=delete&logic=foro&forum_id=" + id;
		}
	}
	return false;
}

function showDeleteT(id,titulo){
	if(confirm("¿Desea eliminar el tema: " + titulo + "?")){
		document.location.href = "foro.admin.ajax.php?acc=delete&logic=tema&tema_id=" + id;
	}
	return false;
}

function createTip(element,content){
	new Tip(element, content,{
		style: 'darkgrey',
		stem: 'topLeft',
		hook: { tip: 'topLeft', mouse: true },
		offset: { x: 2, y: 2 }  , 
		closeButton: false,
		showOn: 'click',
		hideOthers: true,
		hideOn: false,
		fixed:true,
		width:90,
		hideAfter:1
	});
}

function createTipInfo(element,content,widthX){
	new Tip(element, content,{
		style: 'protoblue',
		stem: 'topLeft',
		hook: { tip: 'topLeft', mouse: true },
		offset: { x: 2, y: 2 }  , 
		closeButton: false,
		showOn: 'click',
		hideOthers: true,
		hideOn: false,
		fixed:true,
		width:widthX,
		hideAfter:1
	});	
}
//MOSTRAR-OCULTAR
function Help(section) {
  q=window.open('index.php?mod=help&section='+section, 'Help', 'scrollbars=1,resizable=1,width=450,height=400');
}
function ShowOrHide(d1, d2) {
  if (d1 != '') DoDiv(d1);
  if (d2 != '') DoDiv(d2);
}
function DoDiv(id) {
  var item = null;
  if (document.getElementById) {
	item = document.getElementById(id);
  } else if (document.all){
	item = document.all[id];
  } else if (document.layers){
	item = document.layers[id];
  }
  if (!item) {
  }
  else if (item.style) {
	if (item.style.display == "none"){ item.style.display = ""; }
	else {item.style.display = "none"; }
  }else{ item.visibility = "show"; }
}
//CONTADOR CARACTERES 
function getObject(obj) {
  var theObj;
  if(document.all) {
  if(typeof obj=="string") {
  return document.all(obj);
  } else {
  return obj.style;
  }
  }
  if(document.getElementById) {
  if(typeof obj=="string") {
  return document.getElementById(obj);
  } else {
  return obj.style;
  }
  }
  return null;
}
function Contar(entrada,salida,texto,caracteres) {
var entradaObj=getObject(entrada);
var salidaObj=getObject(salida);
var longitud=caracteres - entradaObj.value.length;
if(longitud <= 0) {
longitud=0;
texto='<span class="disable"> '+texto+' </span>';
entradaObj.value=entradaObj.value.substr(0,caracteres);
}
salidaObj.innerHTML = texto.replace("{CHAR}",longitud);
}
function foros_mostrarConfig(enl){
	if(document.getElementById('configuraciones').style.display == "none"){
		document.getElementById('configuraciones').style.display = "block";
		enl.innerHTML = "Ocultar configuraci&oacute;n";
	}else{
		document.getElementById('configuraciones').style.display = "none";
		enl.innerHTML = "Mostrar configuraci&oacute;n";
	}
}
//ResizingTextArea*****************************************************************************
var ResizingTextArea = Class.create();
ResizingTextArea.prototype = {
    defaultRows: 1,
    initialize: function(field)
    {
        this.defaultRows = Math.max(field.rows, 1);
        this.resizeNeeded = this.resizeNeeded.bindAsEventListener(this);
        Event.observe(field, "click", this.resizeNeeded);
        Event.observe(field, "keyup", this.resizeNeeded);
    },
 
    resizeNeeded: function(event)
    {
        var t = Event.element(event);
        var lines = t.value.split('\n');
        var newRows = lines.length + 1;
        var oldRows = t.rows;
        for (var i = 0; i < lines.length; i++)
        {
            var line = lines[i];
            if (line.length >= t.cols) newRows += Math.floor(line.length / t.cols);
        }
        if (newRows > t.rows) t.rows = newRows;
        if (newRows < t.rows) t.rows = Math.max(this.defaultRows, newRows);
    }
}
//ResizingTextArea*****************************************************************************
function cambiarHREFLogin(element){
	href = element.href;
	element.href = href + "&web_data="+escape(document.location.href);
	return true;
}


function cambioCateroria(i){
	$('cfxiframe').style.display='';
	var c='&gear=posts&acc=SeleccionCategoria';
	goAJAX('cfxiframe','ajax.php','&id='+i+c);	
}
function cambiarCategoria(idP,idC){
		var c='&gear=posts&acc=CambioCategoria';
		goAJAX('cfxiframe','ajax.php','&idP='+idP+c+'&idC='+idC);	
}

function cambioOtros(i){
	$('cfxiframe').style.display='';
	var c='&gear=posts&acc=CambiosOtros';
	goAJAX('cfxiframe','ajax.php','&id='+i+c);	
}

function cambioImg(i){
	$('cfxiframe').style.display='';
	var c='&gear=posts&acc=ImgPost';
	goAJAX('cfxiframe','ajax.php','&id='+i+c);	
}

function GuardarcambioPost(id,valor,que){
	var c='&gear=posts&acc=CambiosOtrosGuardar';
	goAJAX('cfxiframe','ajax.php','&id='+id+c+'&valor='+valor+'&que='+que);	
}

function Siguienteimg(){
	CantidadI=parseInt(CantidadI);
	imgMuestra++;
	if(imgMuestra == CantidadI){
		imgMuestra=1;
	}
	var contenido='<div class="minitituloImg"><b>'+titulos[imgMuestra]+'</b></div><div style="position:relative"> <span class="numeroImagen">'+imgMuestra+'</span> <img src="'+images[imgMuestra]+'" /></div><div style="display:none;"><img src="'+images[imgMuestra+1]+'" /></div>';
	
	$('contenidoImgAl').style.height=alto[imgMuestra]+'px';
	$('altoSig').style.height=alto[imgMuestra]+'px';
	$('altoAnt').style.height=alto[imgMuestra]+'px';
		
	$('ImagenAmplia').innerHTML=contenido;
		
}

function Anteriorimg(x,Tx){
	CantidadI=parseInt(CantidadI);
	imgMuestra--;
	if(imgMuestra == 0){
		imgMuestra=CantidadI-1;
	}
	var contenido='<div class="minitituloImg"><b>'+titulos[imgMuestra]+'</b></div><div style="position:relative"><span class="numeroImagen">'+imgMuestra+'</span> <img src="'+images[imgMuestra]+'" /></div><div style="display:none;"><img src="'+images[imgMuestra+1]+'" /></div>';
	
	$('contenidoImgAl').style.height=alto[imgMuestra]+'px';
	$('altoSig').style.height=alto[imgMuestra]+'px';
	$('altoAnt').style.height=alto[imgMuestra]+'px';
	
	$('ImagenAmplia').innerHTML=contenido;
		
}

function playList(id){
	$('anadeVideo').style.display='';
	var c='&gear=playList&acc=anadir';
	goAJAX('anadeVideo','ajax.php','&id='+id+c);		
}

function crearPlaylist(id,titulo,description,tags){
	if(titulo==''){
		alert('coloca un titulo a tu Nueva lista');
		return false;		
	}else if(description==''){
		alert('Coloca una Descripcion de tu Play List');	
		return false;
		exit();
	}else{
		var c='&gear=playList&acc=crearPlaylist';
		goAJAX('anadeVideo','ajax.php','&id='+id+c+'&titulo='+titulo+'&descripcion='+description+'&tags='+tags);		
		return false;
	}
}

function anadirItemPlayList(id,idP,titulo){
	var c='&gear=playList&acc=anadirNuevo';
	goAJAX('anadeVideo','ajax.php','&idP='+idP+c+'&id='+id+'&titulo='+titulo);		
	return false;
	
}

function makeSortablePlayList(zid2,orden,id){
	var i='Ordenar=ordenarList&orden='+orden+'&id='+id;
	var clases=new Array('imagenlocal');
   Sortable.create(zid2,{tag:'div',hoverclass:'hoverSortable',constraint: false,only:clases,
   onChange:function(){
	var order=Sortable.serialize(zid2);
	 order=str_replace(zid2+'[]=',',',order);
	 order=str_replace('&','',order);
	 var c='&gear=playList';
	goAJAX('cambios','../ajax.php',i+'&ids='+order+c);
}})}

function borrarItemData(idP,id,titulo){
	var c='&gear=playList&acc=borrar';
	goAJAX('cambios','ajax.php','&idP='+idP+c+'&id='+id+'&titulo='+titulo);		
	return false;
}

function SeleccionImagenPost(id,idp){
	var respuesta;
	var misO=$$('chec');
	for (i=0;i<misO.length;i++){
		$(misO[i]).id.checked=0;
	}
	$('chec'+id).checked=1;
	var c='&gear=playList';
	goAJAX('ImgprincipalPlayList','../ajax.php','&cambiaThumb=cambio&id='+id+c+'&idp='+idp);
		
}

function MensageUser(){
	$('MensageUser').style.display='';
	$('MensageUser').innerHTML=$('mensajeparauser').innerHTML;
	new Effect.Pulsate($('MensageUser'),{direction: 'top-left'});
	setTimeout("new Effect.Appear($('MensageUser'),{direction: 'top-left'});",2000);
	}
	
	
function megusta(i,id,valor){
	var c='&gear=megusta';
	goAJAX(i,'../ajax.php','&dato='+i+c+'&id='+id+'&valor='+valor);
}

function ouvre(tex) {
	ff=window.open(tex,"popup","width=600px,height=400px,left=50%,top=50%")
} 

function muestra(id,cla,titulo,ancho){
	$(id).style.display='none';
	new Tip(cla, $(id).innerHTML, {
	style: 'protoblack',
	title: titulo,
	stem: 'topMiddle',
	hook: {tip: 'topMiddle', mouse: false},
		offset: { x: 45, y: -5},
	closeButton: true,
	showOn: 'click',
	hideOthers: true,
	radius:5,
	border:5,
	hideOn: false,
	width:ancho
	});	

}


function Siguentepaso(tip,url_next){
	
	if(tip!='3'){
		$('paso'+tip).style.display='none';
		tip++;
		$('paso'+tip).style.display='';
	}else{
		//goAJAX('paso'+tip,'../ajax.php',c);
		$('expla01').style.display='none';
		url = 'ajax.php?gear=general&acc=explicacion.inicial';
		new Ajax.Request(url, {  method: 'get',  onSuccess: function(transport) {document.location.href=url_next;}});
	}
	
}

function selectAll(obj) {
	objDiv = document.getElementById(obj)
	objDiv.focus();
	objDiv.select();
}


var wa2OM_ocupado='1';
function wa2OcultarMostrar(id_a_mostrar,motrar){
	if(wa2OM_ocupado=='1' && motrar && $(id_a_mostrar).style.display =='none'){
		wa2OM_ocupado='0';
		new Effect.SlideDown(id_a_mostrar, {duration: 0.3});
		setTimeout("wa2OM_ocupado='1';",500);
	}
}
