// Declaratii variabile
// Blocul curent din header
var headerBlock = 1;
var states = new Array();

    states[1] = "0";
    states[2] = "0";
    states[3] = "0";

var news_states = new Array();
for (var i=0; i<100; i++) {
  news_states[i] = 0;
}

// Schimb inner html-ul unui div
function changeContent(id,shtml) {
  if (document.getElementById || document.all) {
    var el = document.getElementById? document.getElementById(id): document.all[id];
    
    if (el && typeof el.innerHTML != "undefined") {
      el.innerHTML = shtml;
    }
	}
}

// Show/Hide la un bloc de continut din header
function SwitchHeader(id) {
  var imgBaseDir = "images/site/header/";
  var imgPaths = new Array();
  
  imgPaths[1] = "software";
  imgPaths[2] = "hosting";
  imgPaths[3] = "media";
  
  if (id != headerBlock) {
    // Ascund blocul curent
    document.getElementById("header_block_" + headerBlock).style.display = "none";
    document.getElementById("headerBtn" + headerBlock).src = imgBaseDir + imgPaths[headerBlock] + ".gif";
    document.getElementById("headerBtn" + headerBlock).style.cursor = "pointer";
    
    // Initializez blocul curent cu cel nou si fac show la acesta
    headerBlock = id;
    //document.getElementById("header_block_" + headerBlock).style.display = "block";
    document.getElementById("headerBtn" + headerBlock).src = imgBaseDir + imgPaths[id] + "_active.gif";
    document.getElementById("headerBtn" + headerBlock).style.cursor = "normal";
    Effect.Appear("header_block_" + headerBlock); return false;
  }
}

// Functii generale JS
function MM_swapImgRestore() {
  var i, x, a = document.MM_sr; 
  
  for(i=0; a&&i<a.length&&(x=a[i])&&x.oSrc; i++) {
    x.src = x.oSrc;
  }
}

function MM_preloadImages() {
  var d=document;
  
  if(d.images) {
    if(!d.MM_p) {
      d.MM_p=new Array();
    }
      
    var i, j=d.MM_p.length, a=MM_preloadImages.arguments;
    
    for(i=0; i<a.length; i++) {
      if (a[i].indexOf("#") != 0) {
        d.MM_p[j] = new Image;
        d.MM_p[j++].src = a[i];
      }
    }
  }
}

function MM_findObj(n, d) {
  var p, i, x;
  
  if(!d) {
    d = document;
  }
  
  if((p = n.indexOf("?")) > 0 && parent.frames.length) {
    d = parent.frames[n.substring(p+1)].document;
    n = n.substring(0,p);
  }
  
  if(!(x = d[n]) && d.all) {
    x = d.all[n];
  }
  
  for (i = 0; !x&&i<d.forms.length; i++) {
    x = d.forms[i][n];
  }
  
  for(i=0; !x&&d.layers&&i<d.layers.length; i++) {
    x = MM_findObj(n,d.layers[i].document);
  }
  
  if(!x && d.getElementById) {
    x = d.getElementById(n);
  }
  
  return x;
}

function MM_swapImage() {
  var i, j=0, x, a=MM_swapImage.arguments;
  
  document.MM_sr = new Array;
  for(i=0; i<(a.length-2); i+=3) {
    if ((x = MM_findObj(a[i]))!=null) {
      document.MM_sr[j++] = x;
      if(!x.oSrc) {
        x.oSrc=x.src;
      }
      
      x.src = a[i+2];
    }
  }
}

// Logout pentru FEU
function doLogout() {
  window.location="/index.php?mact=FrontEndUsers,m3,logout,1&m3returnid=17&page=17";
}

// GoBack to prev page
function goBack() { 
	window.history.back(); 
}

// Procesez toate actiunile executate la onLoad
function ProcessOnLoadActions () {
  // Afisez primul proiect
  proiectCurent = 1;
  document.getElementById('project_' + proiectCurent).style.display = "block";
}

// Afiseaza proiectul anterior
function PrevProj () {
  document.getElementById('project_' + proiectCurent).style.display = "none";
  if (proiectCurent == 1) {
    proiectCurent = nrProiecte;
  } else {
    proiectCurent--;
  }

  changeContent("nav_counter", proiectCurent + " / " + nrProiecte);
  
  //document.getElementById('project_' + proiectCurent).style.display = "block";
  Effect.Appear('project_' + proiectCurent); return false;
}

// Afiseaza proiectul urmator
function NextProj () {
  document.getElementById('project_' + proiectCurent).style.display = "none";
  if (proiectCurent == nrProiecte) {
    proiectCurent = 1;
  } else {
    proiectCurent++;
  }
  
  changeContent("nav_counter", proiectCurent + " / " + nrProiecte);
  
  //document.getElementById('project_' + proiectCurent).style.display = "block";
  Effect.Appear('project_' + proiectCurent); return false;
}

// Afisez sau ascund blocul drop down definit de ID
function DropDownBtn (id) {
  if (states[id] == 0) {
    document.getElementById("drop_down_btn_" + id).src = 'images/site/drop_down_btn_up.gif';
    states[id] = 1;
    Effect.SlideDown('drop_down_block_' + id); return false;
  } else {
    states[id] = 0;
    document.getElementById("drop_down_btn_" + id).src = 'images/site/drop_down_btn_down.gif';
    Effect.SlideUp('drop_down_block_' + id); return false;
  }
}

// Afisez div-ul activ din dreptul arhivei curente
function ShowActiveArchive() {
  document.getElementById("right_arrow_block").style.top = document.getElementById("right_inner").offsetHeight + document.getElementById("archive_active_block").offsetTop - 513 + "px";
  document.getElementById("right_arrow_td").style.height = document.getElementById("archive_active_block").offsetHeight - 4 + "px";
  document.getElementById("right_arrow_block").style.display = "block";
}

// Drop down la prima stire din pagina
function ShowFirstNews() {
  for (var i=0; i<100; i++) {
    if (document.getElementById("news_dd_block_" + i) != undefined) {
      document.getElementById("news_dd_block_" + i).style.display = "block";
      document.getElementById("news_dd_btn_" + i).src = "images/site/news_dd_up.gif";
      news_states[i] = 1;
      
      break;
    }
  }
}

// Collapse sau expand la stirea ID din pagina
function ToogleNewsDD(id) {
  if (news_states[id] == 1) {
    news_states[id] = 0;
    document.getElementById("news_dd_btn_" + id).src = "images/site/news_dd_down.gif";
    document.getElementById("news_dd_block_" + id).style.display = "none";
  } else {
    for (var i=0; i<100; i++) {
      if (document.getElementById("news_dd_block_" + i) != undefined) {
        document.getElementById("news_dd_btn_" + i).src = "images/site/news_dd_down.gif";
        document.getElementById("news_dd_block_" + i).style.display = "none";
        news_states[i] = 0;
      }
    }
    document.getElementById("news_dd_block_" + id).style.display = "block";
    news_states[id] = 1;
    document.getElementById("news_dd_btn_" + id).src = "images/site/news_dd_up.gif";
  }
}

// Daca EM == 1 (exact match) afisez ca activa stirea cu timestamp-ul dat ca parametru
function ToogleActiveNews(id) {
  for (var i=0; i<100; i++) {
    if (document.getElementById("news_dd_block_" + i) != undefined) {
      document.getElementById("news_dd_btn_" + i).src = "images/site/news_dd_down.gif";
      document.getElementById("news_dd_block_" + i).style.display = "none";
      news_states[i] = 0;
    }
  }

  news_states[id] = 1;
  document.getElementById("news_dd_btn_" + id).src = "images/site/news_dd_up.gif";
  document.getElementById("news_dd_block_" + id).style.display = "block";
}

// Afisez div-ul activ din dreptul produsului curent
function ShowActiveProduct() {
  document.getElementById("right_arrow_block").style.top = document.getElementById("right_inner").offsetHeight + document.getElementById("archive_active_block").offsetTop - 513 + "px";
  document.getElementById("right_arrow_td").style.height = document.getElementById("archive_active_block").offsetHeight - 4 + "px";
  document.getElementById("right_arrow_block").style.display = "block";
}

// Afisez div-ul activ din dreptul serviciului curent
function ShowActiveService() {
  document.getElementById("right_arrow_block").style.top = document.getElementById("right_inner").offsetHeight + document.getElementById("archive_active_block").offsetTop - 927 + "px";
  document.getElementById("right_arrow_td").style.height = document.getElementById("archive_active_block").offsetHeight - 4 + "px";
  document.getElementById("right_arrow_block").style.display = "block";
}
