var Drag = {
obj : null,
dropTargets : [],
destinos : [],

init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper){
 o.onmousedown	= Drag.start;
 o.hmode	= bSwapHorzRef ? false : true ;
 o.vmode	= bSwapVertRef ? false : true ;
 o.root = oRoot && oRoot != null ? oRoot : o ;
 if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
 if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
 if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
 if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";
 o.minX = typeof minX != 'undefined' ? minX : null;
 o.minY	= typeof minY != 'undefined' ? minY : null;
 o.maxX	= typeof maxX != 'undefined' ? maxX : null;
 o.maxY	= typeof maxY != 'undefined' ? maxY : null;
 o.xMapper = fXMapper ? fXMapper : null;
 o.yMapper = fYMapper ? fYMapper : null;
 o.root.onDragStart	= new Function();
 o.root.onDragEnd	= new Function();
 o.root.onDrag		= new Function();
},
start : function(e){
  var o = Drag.obj = this;
  e = Drag.fixE(e);
  var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
  var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
  o.root.onDragStart(x, y);
  o.lastMouseX	= e.clientX;
  o.lastMouseY	= e.clientY;
  if (o.hmode) {
   if (o.minX != null){ o.minMouseX = e.clientX - x + o.minX; }
   if (o.maxX != null){ o.maxMouseX = o.minMouseX + o.maxX - o.minX; }
  } else {   
   if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
   if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
  }
  if (o.vmode) { 
   if (o.minY != null){ o.minMouseY = e.clientY - y + o.minY; }
   if (o.maxY != null){ o.maxMouseY = o.minMouseY + o.maxY - o.minY; }
  } else {
   if (o.minY != null){ o.maxMouseY = -o.minY + e.clientY + y; }
   if (o.maxY != null){ o.minMouseY = -o.maxY + e.clientY + y; }
  }
  document.onmousemove = Drag.drag;
  document.onmouseup   = Drag.detecta;
  return false;
},
drag : function(e){
 origemid = Drag.obj.id;
 e = Drag.fixE(e);
 var o = Drag.obj;
 var ey	= e.clientY;
 var ex	= e.clientX;
 var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
 var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
 var nx, ny;
 if (o.minX != null){ ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX); }
 if (o.maxX != null){ ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX); }
 if (o.minY != null){ ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY); }
 if (o.maxY != null){ ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY); }
 nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
 ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));
 if (o.xMapper){ nx = o.xMapper(y); }
 else if (o.yMapper){ ny = o.yMapper(x); }
 if( origemid != "..trashca." &&
     origemid != "..npage."   &&
     origemid != "..ppage." ){
      Drag.obj.root.style.zIndex = 0;
 }
 Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
 Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
 Drag.obj.lastMouseX	= ex;
 Drag.obj.lastMouseY	= ey;
 Drag.obj.root.onDrag(nx, ny);
 return false;
},
detecta : function(e){
 document.onmousemove = null;
 var ex = 0;
 var ey = 0;
 var left = 0;
 var top  = 0;
 var targPosx = 0;
 var targPosy = 0;
 var twidth  = 0;
 var theight = 0;
 var texto = "";
 var parametro = "";
 var flagmsie = "N";
 var scrollleft = 0;
 var scrolltop = 0;
 var clientLeft = 0;
 var clientTop = 0;
 origem = Drag.obj.name;
 origemid = Drag.obj.id;
 e = Drag.fixE(e);
 if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    scrolltop  = document.body.scrollTop;
    scrollleft = document.body.scrollLeft;
 } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    scrolltop  = document.documentElement.scrollTop;
    scrollleft = document.documentElement.scrollLeft;
 }
 if( document.body && ( document.body.clientLeft || document.body.clientTop ) ) {
    clientTop  = document.body.clientTop;
    clientLeft = document.body.clientLeft;
 } else if( document.documentElement && ( document.documentElement.clientLeft || document.documentElement.clientTop ) ) {
    clientTop  = document.documentElement.clientTop;
    clientLeft = document.documentElement.clientLeft;
 }
 if( scrollleft == "" || scrollleft == "undefined" ){ scrollleft = 0; }
 if( scrolltop == "" || scrolltop == "undefined" ){ scrolltop = 0; }
 if( clientLeft == "" || clientLeft == "undefined" ){ clientLeft = 0; }
 if( clientTop == "" || clientTop == "undefined" ){ clientTop = 0; }
 if(e.pageX || e.pageY){
    ex = e.pageX;
    ey = e.pageY;
    flagmsie = "N";
 } else {
    ex = e.clientX + scrollleft - clientLeft;
    ey = e.clientY + scrolltop  - clientTop;
    flagmsie = "S";
 }//if-else
 var flag_achou = "n";
 for(var i=0; i < Drag.dropTargets.length; i++){
    var curTarget  = Drag.dropTargets[i];
    var destino    = Drag.destinos[i];
    left = 0;
    top = 0;
    twidth = 0;
    theight = 0;
//  INI - Target Position  //
    while (curTarget.offsetParent){
     left += curTarget.offsetLeft;
     top  += curTarget.offsetTop;
     twidth = curTarget.offsetWidth;
     theight = curTarget.offsetHeight;
     curTarget = curTarget.offsetParent;
    }//while
    left += curTarget.offsetLeft;
    top  += curTarget.offsetTop;
    targPosx = left;
    targPosy = top;
//  FIM - Target Position  //
    var targWidth  = twidth;
    var targHeight = theight;

    if ( origemid == "..notepad." ||
         origem   == "..notepad." ||
         destino  == "..notepad." ){

//       Objetos que não devem interagir com Drag&Drop
         document.onmouseup = Drag.end;
         return false;//exit;//sai da funcao toda

    }else if ( (ex > targPosx) && (ex < (targPosx + targWidth)) &&
         (ey > targPosy) && (ey < (targPosy + targHeight)) &&
         (origem != destino) &&
         (origemid != "..trashca.") &&
         (destino != "..trashca.") &&
         (origemid != "..npage.") &&
         (destino != "..npage.") &&
         (origemid != "..ppage.") &&
         (destino != "..ppage.") ){
        flag_achou = "s";
        parametro = origem + "|" + destino + "|" + "" + "|" + "";
        Drag.ajax(parametro);
        document.onmouseup = Drag.end;
        setTimeout("window.document.location.reload()",900);
        return false;//exit;//sai da funcao toda
    }else if ( (ex > targPosx) && (ex < (targPosx + targWidth)) &&
         (ey > targPosy) && (ey < (targPosy + targHeight)) &&
         (origem != destino) &&
         (origemid != "..trashca.") &&
         (destino == "..trashca.") &&
         (origemid != "..npage.") &&
         (destino != "..npage.") &&
         (origemid != "..ppage.") &&
         (destino != "..ppage.") ){
//////////Colocou na Lixeira//////////
         var mensagem = "Delete?";
         var answer = confirm(mensagem); 
         if(answer){
          flag_achou = "s";
          parametro = origem + "|" + destino + "|" + "" + "|" + "";
          Drag.ajaxdel(parametro);
          Drag.obj.root.style.visibility = "hidden";
          Drag.obj.root.style.zIndex = "0";
          Drag.obj.root.style.top = "0px";
          Drag.obj.root.style.left = "0px";
         } else {
          Drag.obj.root.style.zIndex = "1";
          Drag.obj.root.style.top = "0px";
          Drag.obj.root.style.left = "0px";
         }
         document.onmouseup = Drag.end;
         return false;//exit;//sai da funcao toda          
    }else if ( (ex > targPosx) && (ex < (targPosx + targWidth)) &&
         (ey > targPosy) && (ey < (targPosy + targHeight)) &&
         (origem != destino) &&
         (origemid != "..trashca.") &&
         (destino != "..trashca.") &&
         (origemid != "..npage.") &&
         (destino == "..npage.") &&
         (origemid != "..ppage.") &&
         (destino != "..ppage.") ){
//////////Colocou na Next Page//////////
          parametro = origem + "|" + destino + "|" + "" + "|" + "";
          Drag.ajaxnext(parametro);
          Drag.obj.root.style.visibility = "hidden";
          Drag.obj.root.style.zIndex = "0";
          Drag.obj.root.style.top = "0px";
          Drag.obj.root.style.left = "0px";
          document.onmouseup = Drag.end;
          return false;//exit;//sai da funcao toda          
    }else if ( (ex > targPosx) && (ex < (targPosx + targWidth)) &&
         (ey > targPosy) && (ey < (targPosy + targHeight)) &&
         (origem != destino ) &&
         (origemid != "..trashca.") &&
         (destino != "..trashca.") &&
         (origemid != "..npage.") &&
         (destino != "..npage.") &&
         (origemid != "..ppage.") &&
         (destino == "..ppage.") ){
//////////Colocou na Previous Page//////////
          parametro = origem + "|" + destino + "|" + "" + "|" + "";
          Drag.ajaxprev(parametro);
          Drag.obj.root.style.visibility = "hidden";
          Drag.obj.root.style.zIndex = "0";
          Drag.obj.root.style.top = "0px";
          Drag.obj.root.style.left = "0px";
          document.onmouseup = Drag.end;
          return false;//exit;//sai da funcao toda          
    }else if ( (ex > targPosx) && (ex < (targPosx + targWidth)) &&
         (ey > targPosy) && (ey < (targPosy + targHeight)) &&
         (origem != destino) &&
         (origemid == "..trashca.") &&
         (destino == "..trashca.") &&
         (origemid != "..npage.") &&
         (destino != "..npage.") &&
         (origemid != "..ppage.") &&
         (destino != "..ppage.") ){
//////////Reposicionou a Lixeira//////////
         document.onmouseup = Drag.end;
         return false;//exit;//sai da funcao toda          
    }else if ( (ex > targPosx) && (ex < (targPosx + targWidth)) &&
         (ey > targPosy) && (ey < (targPosy + targHeight)) &&
         (origem != destino ) &&
         (origemid != "..trashca.") &&
         (destino != "..trashca.") &&
         (origemid == "..npage.") &&
         (destino == "..npage.") &&
         (origemid != "..ppage.") &&
         (destino != "..ppage.") ){
//////////Reposicionou a Next Page//////////
         document.onmouseup = Drag.end;
         return false;//exit;//sai da funcao toda          
    }else if ( (ex > targPosx) && (ex < (targPosx + targWidth)) &&
         (ey > targPosy) && (ey < (targPosy + targHeight)) &&
         (origem != destino ) &&
         (origemid != "..trashca.") &&
         (destino != "..trashca.") &&
         (origemid != "..npage.") &&
         (destino != "..npage.") &&
         (origemid == "..ppage.") &&
         (destino == "..ppage.") ){
//////////Reposicionou a Previous Page//////////
         document.onmouseup = Drag.end;
         return false;//exit;//sai da funcao toda
    } else {
////   Outros
    }//if-else
  }//for
},
ajax : function(p){
     var xmlHttp=null;
     var parameters;
     var porigem = p.split("|")[0];
     var pdestino = p.split("|")[1];
     var pleft = p.split("|")[2];
     var ptop = p.split("|")[3];
     var purl = "linkchange.php";
     try {
       xmlHttp=new XMLHttpRequest();
     } catch (e) {
       try {
       xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
       }
     }//try-catch
     var url=purl;
//// origem | destino | left | top
     var o = porigem;
     var d = pdestino;
     var l = pleft;
     var t = ptop;
     parameters = "o=" + escape(o) + "&d=" + escape(d) + "&l=" + l + "&t=" + t + "&sid=" + Math.random();
     xmlHttp.open("POST", url, true);
     xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     xmlHttp.setRequestHeader("Content-length", parameters.length);
     xmlHttp.setRequestHeader("Connection", "close");
     xmlHttp.send(parameters);
},
ajaxdel : function(p){
     var xmlHttp=null;
     var parameters;
     var porigem = p.split("|")[0];
     var pdestino = p.split("|")[1];
     var pleft = p.split("|")[2];
     var ptop = p.split("|")[3];
     var purl = "linkdel.php";
     try {
       xmlHttp=new XMLHttpRequest();
     } catch (e) {
       try {
       xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
       }
     }//try-catch
     var url=purl;
//// origem | destino | left | top
     var s = porigem;
     parameters = "s=" + escape(s) + "&sid=" + Math.random();
     xmlHttp.open("POST", url, true);
     xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     xmlHttp.setRequestHeader("Content-length", parameters.length);
     xmlHttp.setRequestHeader("Connection", "close");
     xmlHttp.send(parameters);
},
ajaxnext : function(p){
     var xmlHttp=null;
     var parameters;
     var porigem = p.split("|")[0];
     var pdestino = p.split("|")[1];
     var pleft = p.split("|")[2];
     var ptop = p.split("|")[3];
     var purl = "linknext.php";
     try {
       xmlHttp=new XMLHttpRequest();
     } catch (e) {
       try {
       xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
       }
     }//try-catch
     var url=purl;
//// origem | destino | left | top
     var s = porigem;
     parameters = "s=" + escape(s) + "&sid=" + Math.random();
     xmlHttp.open("POST", url, true);
     xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     xmlHttp.setRequestHeader("Content-length", parameters.length);
     xmlHttp.setRequestHeader("Connection", "close");
     xmlHttp.send(parameters);
},
ajaxprev : function(p){
     var xmlHttp=null;
     var parameters;
     var porigem = p.split("|")[0];
     var pdestino = p.split("|")[1];
     var pleft = p.split("|")[2];
     var ptop = p.split("|")[3];
     var purl = "linkprev.php";
     try {
       xmlHttp=new XMLHttpRequest();
     } catch (e) {
       try {
       xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
       }
     }//try-catch
     var url=purl;
//// origem | destino | left | top
     var s = porigem;
     parameters = "s=" + escape(s) + "&sid=" + Math.random();
     xmlHttp.open("POST", url, true);
     xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     xmlHttp.setRequestHeader("Content-length", parameters.length);
     xmlHttp.setRequestHeader("Connection", "close");
     xmlHttp.send(parameters);
},
addDropTarget : function(t){
 Drag.dropTargets.push(t);
},
addDestino : function(d){
 Drag.destinos.push(d);
},
end : function(){
 document.onmousemove = null;
 document.onmouseup   = null;
 Drag.obj.root.onDragEnd( parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
                          parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
 Drag.obj = null;
},
fixE : function(e){
 if (typeof e == 'undefined'){ e = window.event; }
 if (typeof e.layerX == 'undefined'){ e.layerX = e.offsetX; }
 if (typeof e.layerY == 'undefined'){ e.layerY = e.offsetY; }
 return e;
}
};
////////////////////////////////////////////////////////////////////////////////////////////
function esconder(nomeobj,pagina,nomecoded){
 var xmlHttp=null;
 var parameters;
 var pcategoria = nomecoded;
 var ppagina    = pagina;
 var obj = document.getElementById(nomeobj);
 var purl = "categshow.php";

 if(obj.style.display=='block'){
   obj.style.display='none';
// Chamar AJAX para categhide.php
    purl = "categhide.php";
 }else{
   obj.style.display='block';
// Chamar AJAX para categshow.php
   purl = "categshow.php";
 }//if-else
///////////////AJAX///////////////////
 try {
//  Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
 } catch (e) {
//  Internet Explorer
    try {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
 }//try-catch

  var url=purl;
//categoria | pagina
  var c = pcategoria;
  var p = ppagina;
  parameters = "c=" + c + "&p=" + p + "&sid=" + Math.random();
  xmlHttp.open("POST", url, true);
  xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlHttp.setRequestHeader("Content-length", parameters.length);
  xmlHttp.setRequestHeader("Connection", "close");
  xmlHttp.send(parameters);
}//esconder

////////////////////////////////////////////////////////////////////////////////////////////
function janelasecundaria (url){ 
   window.open(url,"janela1","width=350,height=200,scrollbars=NO");
}//janelaSecundaria

function janelasecundaria2 (url){ 
   window.open(url,"janela2","width=320,height=320,scrollbars=NO");
}//janelaSecundaria

function janelanotas (url){ 
   window.open(url,"janelanotas","width=500,height=350,scrollbars=NO");
}//janelanotas

//////////////////////////////////////////////////////////////////////////////////////
function menu(barra) {
 var navItems = document.getElementById(barra).getElementsByTagName("span");
  for (var i=0; i< navItems.length; i++) {
   if(navItems[i].className == "menuvertical" || navItems[i].className == "menuhorizontal"){
    if(navItems[i].getElementsByTagName('ul')[0] != null){
     navItems[i].onmouseover=function() {this.getElementsByTagName('ul')[0].style.display="block";}
     navItems[i].onmouseout=function() {this.getElementsByTagName('ul')[0].style.display="none";}
    }
   }
  }//for

}//menu