/**
* Enlarge clicked article
*/
function enlargeNews (obj) {
  var news = obj.parentNode.parentNode;
  news.toggleClass('more');
  /*
  //var p = news.getElements('img[name$=pic_author]')[0];
  var p = news.getElements('img')[0];
  if (p.src.indexOf('Imgs')!=-1) {
  p.getParent().setStyle("display", "block");
}  */
  return false;    
}  
/**
* Ligar/desligar todas
*/
function toogleNewsEnlarge (obj) {
  var p = $$('.news h2 a');
  for (i=0 ; i<p.length ; i++) {
    enlargeNews(p[i]);    
  }
  if (obj.innerHTML=='Em detalhe') {
    obj.innerHTML = 'Minimizar';
  } else {
    obj.innerHTML = 'Em detalhe';
  }
}

InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;

function myFlash_DoFSCommand(command, args)                {
  var myFlashObj = InternetExplorer ? document.getElementById("myFlash") : document.myFlash;
  refreshDistrito (args);
}
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && 
    navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
  document.write('<SCRIPT LANGUAGE=VBScript\> \n');
  document.write('on error resume next \n');
  document.write('Sub myFlash_FSCommand(ByVal command, ByVal args)\n');
  document.write(' call myFlash_DoFSCommand(command, args)\n');
  document.write('end sub\n');
  document.write('<\/SCRIPT\> \n');
} 


function refreshDistrito(args) {
  //var mapaObj = isInternetExplorer ? document.all.mapa : document.mapa;
  
  if ($("outermap")) {
    window.location = "/implementadores/pesquisa/&distrito=" + args;  
  } else {
    $("content").innerHTML = "<div style='width:400px; padding-top:30px;'><img src='/interface/imgs/ajax_load.gif' alt='Loading' /></div>";
    
    var url1 = "/ajax/implementadores/pesquisa/&distrito="+args;      
    
    
    new Request.HTML({url:url1, method: 'get', evalScripts: 'false', update: $("content"),
                      headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'}
                     }).send();
  }
}



function showhide(id){
  if(document.getElementById(id).style.display == 'none'){
    document.getElementById(id).style.display = 'block';
  }else{
    document.getElementById(id).style.display = 'none';
  }
}
function show(id){
  document.getElementById(id).style.display = 'block';
}
function hide(id){
  document.getElementById(id).style.display = 'none';
}
function popUp(URL) {
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=500,height=350,left = 376,top = 132');");
}
function disableButton (button) {
  if (document.all || document.getElementById)
    button.disabled = true;
  else if (button) {
    button.oldOnClick = button.onclick;
    button.onclick = null;
    button.oldValue = button.value;
    button.value = 'DISABLED';
  }
}
function retrieveData(id){
  document.getElementById(id).innerHTML = "<img src='/interface/imgs/loading.gif' width='80' height='10' border='0' alt='' />";
  document.getElementById("bridgeFrame").src = "/catalogo/getinfo.php?id=" + id;
  document.getElementById("cube"+id).innerHTML = "<a href='javascript: fecha(" + id + ");'><img src='/interface/imgs/iminus.gif' border='0' alt='' /></a>";
}
function innerbrowse(obj,id,file){
  document.getElementById(id).innerHTML = "<img src='/interface/imgs/loading.gif' width='80' height='10' border='0' alt='' />";
  document.getElementById("bridgeFrame").src = file + "&selected=" + obj.value;
}
function iframeCallback(doc,id){
  myData = doc.getElementById("mydata");
  document.getElementById(id).innerHTML = myData.innerHTML;
}
function fecha(id){
  document.getElementById(id).innerHTML = "";
  document.getElementById("cube"+id).innerHTML = "<a href='javascript: retrieveData(" + id + ");'><img src='/interface/imgs/iplus.gif' border='0' alt='' /></a>";
}
function updateDiv(div,text){
  var obj = document.getElementById(div);
  obj.innerHTML = text;
}  


// <PG> Colocar animação, ao passar o rato por cima, abrir as sub-páginas. (menu esquerdo)
window.addEvent('domready', function() {
  

  
  //<PG> Se existir produtos idênticos, acrescentar tabela no proddetalhe
  if(document.getElementById('prod-identico')){
    
    var id_prod_detail = document.getElementById('id_prod_detail').innerHTML;
    var url_prod_identicos = "/ajax/nocache/produtos/produtos-identicos&prod_ref=" + id_prod_detail;
    var req = new Request({
      method: 'get',
      url: url_prod_identicos,
      onRequest: function() { 
        document.getElementById('prod-identico').innerHTML = "<img src='/interface/imgs/loader.gif' alt='em actualização'>";
      },
      onComplete: function(response) { 
        document.getElementById('prod-identico').innerHTML = response; 
      }
    }).send();
    
  }
  
});

