// getPageScroll()
// Returns array with x,y page scroll values.
// Code from - quirksmode.org
var c;
var si, so; //intervals

function getPageScroll(){
    var yScroll, xScroll;
    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
        xScroll = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
        yScroll = document.documentElement.scrollTop;
        xScroll = document.documentElement.scrollLeft;
    } else if (document.body) {// all other Explorers
        yScroll = document.body.scrollTop;
        xScroll = document.body.scrollLeft;
    }
    arrayPageScroll = new Array('',yScroll,xScroll) 
    return arrayPageScroll;
}

// getPageSize()
// Returns array with page width, height and window width, height
// Code from - quirksmode.org

function getPageSize(){	
    var xScroll, yScroll;	

    if (window.innerHeight && window.scrollMaxY) {	
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;
	
    if (self.innerHeight) {	// all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }		

    // for small pages with total height less then height of the viewport

    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else { 
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport

    if(xScroll < windowWidth){	
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }

    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
    return arrayPageSize;
}

function getScrollerWidth() {
    var scr = null;
    var inn = null;
    var wNoScroll = 0;
    var wScroll = 0;

    // Outer scrolling div
    scr = document.createElement('div');
    scr.style.position = 'absolute';
    scr.style.top = '-1000px';
    scr.style.left = '-1000px';
    scr.style.width = '100px';
    scr.style.height = '50px';
    // Start with no scrollbar
    scr.style.overflow = 'hidden';

    // Inner content div
    inn = document.createElement('div');
    inn.style.width = '100%';
    inn.style.height = '200px';

    // Put the inner div in the scrolling div
    scr.appendChild(inn);
    // Append the scrolling div to the doc
    document.body.appendChild(scr);

    // Width of the inner div sans scrollbar
    wNoScroll = inn.offsetWidth;
    // Add the scrollbar
    scr.style.overflow = 'auto';
    // Width of the inner div width scrollbar
    wScroll = inn.offsetWidth;

    // Remove the scrolling div from the doc
    document.body.removeChild(
    document.body.lastChild);

    // Pixel width of the scroller
    //return (wNoScroll - wScroll);
return 0


}


function doResize() {
  overlay = document.getElementById("overlay");
  c = document.getElementById('subcontent');
  overlay.style.width = '100%';

  var arrayPageSize = getPageSize();

  overlay.style.height = arrayPageSize[1] + 'px';
  overlay.style.width = '100%';
  
  c.style.left = (arrayPageSize[2]/2)-(c.offsetWidth/2)+"px";
}

function doScroll() {
  var arrayPageScroll = getPageScroll();
  c = document.getElementById('subcontent');
  c.style.top =  arrayPageScroll[1] + 100 + 'px';
}

function fadeIn (){

  if (document.all) toggleSelects('hidden');

  var arrayPageSize = getPageSize();

  overlay = document.createElement("div");
  overlay.id = 'overlay';
  
  setOpacity(overlay,75);
  
  document.body.appendChild(overlay);
  
  var pageHeight = document.body.scrollHeight;
  var pageWidth = document.body.scrollWidth;

  overlay.style.height = pageHeight + 'px';
  overlay.style.width = pageWidth + 'px';
  
  var BoxHolder = document.createElement("div");
  document.body.appendChild(BoxHolder);
  BoxHolder.innerHTML = '<div id="subcontent"><DIV style="width: 450px; background: #FFFFFF; border: solid 1px #CCCCCC;"><div style="width: 100%; border-bottom: solid 1px #CCCCCC; float: left;"><div style="float: left;"><img src="/img/site/logo_small.jpg" style="margin: 3px;"></div><div style="float: right;"><a href="javascript:;" onClick="startSlide(\'up\', \'subcontent\');return false;"><b style="color: #333333;">Inchide</b><img src="/img/icons/close.gif" vspace="10" hspace="10" align="absmiddle"></a></div></div><div style="clear: both; padding: 5px;"><h3>Abonare la Newsletter</h3></div><div style="clear: both;"><div style="float: left; width: 70%; padding: 5px 10px;"><b>De ce sa ma abonez?</b><br /><br />Pentru a primi in fiecare zi cele mai importante stiri, cursul de schimb al principalelor valute, prognoza meteo in cele mai importante orase.</div><div style="float: right; width: 25%; text-align: center;"><img src="/img/site/envelope.gif"></div></div><div id="newsletter_content" style="clear: both; border-top: solid 1px #E3E3E3; border-bottom: solid 1px #E3E3E3; background: #F9F9F9; margin: 20px; padding: 10px;"><div style="width: 100%; text-align: center;"><b>Adresa de email:</b> &nbsp; <input name="newsletter_email" id="newsletter_email" size="35" type="text" class="search"></div><div style="width: 100%; text-align: center; padding-top: 15px;"><input type="button" class="btn_letter" NAME="btn_submit" id="newsletter_button" VALUE="" onclick="this.disabled = true; register(dom_get_element(\'newsletter_email\').value);"></div></div><div style="clear: both; text-align: center; border-top: solid 1px #CCCCCC; background: #F4F4F4; padding: 8px;"><h3>sursa ta zilnica de stiri</h3></div></div></div>';
}


function fadeOut () {    
  c.style.display = 'none';
  overlay.style.display = 'none';
}


function toggleSelects(state) {
  selects = document.getElementsByTagName('select');
  for (i=0;i<selects.length;i++) selects[i].style.visibility = state;
}

function startSlide(direction, el) {

  var arrayPageSize = getPageSize();
  var arrayPageScroll = getPageScroll();
  
  if (direction=='down') {
    
    c = document.getElementById(el);
    
    c.style.top =  ((c.offsetHeight * -1) + arrayPageScroll[1]) + 'px';
    c.style.left = (arrayPageSize[2]/2)-(c.offsetWidth/2)+"px";
    si = setInterval("slideIn()",25);
  } else {
    so = setInterval("slideOut()",25);
  }
}

function slideIn(container,direction) {
  var arrayPageScroll = getPageScroll();
  
  ct = parseInt(c.style.top)
  ct < (arrayPageScroll[1] + 100) ? c.style.top = (ct + 30) + 'px' : clearInterval(si);
}

function slideOut(container) {
  var arrayPageScroll = getPageScroll();
  ct = parseInt(c.style.top);   
  if (ct > (c.offsetHeight * -1) + arrayPageScroll[1]) {
    c.style.top = (ct-30) + 'px'
  } else {
    clearInterval(so);
    toggleSelects('visible');
    fadeOut();
  }
}
