var bwidth = dimenzije2();

var persistclosecq = 1 //set to 0 or 1. 1 means once the bar is manually closed, it will remain closed for browser session
var startX = (bwidth / 2) - (425/2) //set x offset of bar in pixels
//var startXC = width/2 - (barheight=document.getElementById("reklama").offsetHeight/2);
var startYtop = -300 // pocetni index diva
var startY = 150 //set y offset of bar in pixels
var verticalpos = "fromtop" //enter "fromtop" or "frombottom"
var kasnjenje = 5 // koliko sekundi da kasni
var k = kasnjenje * 1000;
var period = 31 * 3 // Na koliko dugo da ne otvara div ako je jednom zatvorio u danima ?
function iecompattestcq(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function closebar(){
var cookie_date = new Date ( );
cookie_date.setTime ( cookie_date.getTime() + 60 * 60 * 1000 * 24 * period );
if (persistclosecq)
document.cookie="facebookvizio=1;expires=" + cookie_date.toGMTString() + ";path=/";
document.getElementById('reklama').style.visibility= 'hidden';
}

function staticbarcq(){
	barheight=document.getElementById("reklama").offsetHeight
	
	var nscq = (navigator.appName.indexOf("Netscape") != -1) || window.opera;
	var d = document;
	function mlcq(id){
		var elcq=d.getElementById(id);
		if (!persistclosecq || persistclosecq && get_cookie("facebookvizio")==""){
			elcq.style.visibility="visible"
			///elcq.y = startYtop;
			}
		if(d.layers)elcq.style=elcq;
		elcq.sPcq=function(x,y){this.style.left=x+"px";this.style.top=y+"px";};
		elcq.x = startX;
		if (verticalpos=="fromtop")
		elcq.y = startYtop;
		else{
		elcq.y = nscq ? pageYOffset + innerHeight : iecompattestcq().scrollTop + iecompattestcq().clientHeight;
		elcq.y -= startY;
		}
		return elcq;
	}
	window.stayTopLeft=function(){
		if (verticalpos=="fromtop"){
		var pYcq = nscq ? pageYOffset : iecompattestcq().scrollTop;
		ftlObjcq.y += (pYcq + startY - ftlObjcq.y)/20;
		}
		else{
		var pYcq = nscq ? pageYOffset + innerHeight - barheight: iecompattestcq().scrollTop + iecompattestcq().clientHeight - barheight;
		ftlObjcq.y += (pYcq - startY - ftlObjcq.y)/20;
		}
		ftlObjcq.sPcq(ftlObjcq.x, ftlObjcq.y);
		setTimeout("stayTopLeft()", 18);
	}
	ftlObjcq = mlcq("reklama");
	stayTopLeft();
}


function dimenzije2(){
var winW = 200
var winH
if (document.body && document.body.offsetWidth) {
    winW = document.body.offsetWidth;
    winH = document.body.offsetHeight;
  }
if (document.compatMode=='CSS1Compat' && document.documentElement &&  document.documentElement.offsetWidth ) {
    winW = document.documentElement.offsetWidth;
    winH = document.documentElement.offsetHeight;
    }
if (window.innerWidth && window.innerHeight) {
    winW = window.innerWidth;
    winH = window.innerHeight;
     }
return winW
}


function dimenzije(){
var viewportwidth;
var viewportheight;
  
// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
    
if (typeof window.innerWidth != 'undefined')
  {
    viewportwidth = window.innerWidth,
    viewportheight = window.innerHeight
    }
                    
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
 else if (typeof document.documentElement != 'undefined'
      && typeof document.documentElement.clientWidth !=
   'undefined' && document.documentElement.clientWidth != 0)
    {
   viewportwidth = document.documentElement.clientWidth,
  viewportheight = document.documentElement.clientHeight
   }
                    
     // older versions of IE
                              
   else
  {
     viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
     viewportheight = document.getElementsByTagName('body')[0].clientHeight
   }
return viewportwidth
}


function start_sa_kasnjenjem(){
setTimeout('staticbarcq()',k);
}

// AJAX FUNKCIJA ZA LISTU

function dodajnalistu(){
  //    var email2 = documet.getElementById('email_fb_lista').value
//  var za_proveru = documet.getElementById('email_fb_lista').value;
  var email = document.getElementById('email_fb_lista').value; 
//    var where = 'reklame';
    
     //alert(email);
     ajax_req('/facebook_popup_ajax.php?op=novosti&email=' + email  +'','rezultat');
}

function ajax_req(url, target) {
  document.getElementById(target).innerHTML = '<img src="http://www.vizioshop.com/images/indicator.gif" />';
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req != undefined) {
    req.onreadystatechange = function() {ajaxDone(url, target);};
    req.open("GET", url, true);
    req.send("");
  }
}  

function ajaxDone(url, target) {
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.getElementById(target).innerHTML = req.responseText;
    } else {
      document.getElementById(target).innerHTML="Error:\n"+ req.status + "\n" +req.statusText;
    }
  }
}







if (window.addEventListener)
window.addEventListener("load", start_sa_kasnjenjem, false)
else if (window.attachEvent)
window.attachEvent("onLoad", start_sa_kasnjenjem)
else if (document.getElementById)
window.onload=start_sa_kasnjenjem
