function createRequestObject() {
    var req;
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest()
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP")
    } else {
        alert('Problem creating the XMLHttpRequest object')
    }
    return req;
}
var http = createRequestObject();
var httpa = createRequestObject();

function ucitajNagradne() {
    httpa.open('get', '/skripte/ucitaj_nagradne.php');
    httpa.onreadystatechange = dajNagradne;
    httpa.send(null)
}
function dajNagradne() {
    if (httpa.readyState == 4) {
        if(httpa.responseText != 'nema') {
          var divic = document.getElementById("nagradne");
          divic.innerHTML = httpa.responseText;  
          divic.style.display = 'block';
        }
        
        return false;
    }
}

function ucitaj(broj) {
    nek = Math.random();
    http.open('get', '/skripte/ostali.php?od=' + broj + '&kes=' + nek);
    http.onreadystatechange = dajOstale;
    http.send(null)
}
function dajOstale() {
    if (http.readyState == 4) {
        document.getElementById("ostale").innerHTML = http.responseText;
        return false
    }
}
function popratni(nesto) {
    document.getElementById('popratni_tekst').innerHTML = nesto
}

function ubaciAktuelni(koji) {
    neko = Math.random();
    http.open('get', '/skripte/aktuelni.php?koji=' + koji + '&kes=' + neko);
    http.onreadystatechange = ulivaAktuelni;
    http.send(null);
}
function ulivaAktuelni() {
    if (http.readyState == 4) {
        $("#aktuelni").html(http.responseText).fadeIn('slow');		var flashvars = {};		var params = {};		var attributes = {};	
        if($('#xfl').length)
           {
               if($('#xfl').height() == 90)
                  swfobject.embedSWF("ciza.swf", "ciza", "640", "2", "9.0.0","expressInstall.swf", flashvars, params, attributes);
           }
           else
            swfobject.embedSWF("ciza.swf", "ciza", "640", "2", "9.0.0","expressInstall.swf", flashvars, params, attributes);
        return false;
    }
}


function rand(n)
{
  return ( Math.floor ( Math.random ( ) * n + 1 ) );
}


var kolikoakt = arrakt.length;
var nj = kolikoakt;
nj = nj - 1;
var sad = rand(kolikoakt)-1;


function rotiraj() {
    ubaciAktuelni(arrakt[sad]);
    if (sad != kolikoakt) {
        sad++
    }
    if (sad == kolikoakt) {
        sad = 0
    }
    setTimeout("rotiraj()", 10000)
}

function autosuggest() {
    q = document.getElementById('trazilica').value;
    if (q != ' ') {
        nocache = Math.random();
        http.open('get', '/skripte/pretraga.php?q=' + q + '&nocache=' + nocache);
        http.onreadystatechange = autosuggestReply;
        http.send(null);
        q = " "
    }
}
function autosuggestReply() {
    if (http.readyState == 4) {
        document.getElementById('results').style.display = "block";
        document.getElementById('results').innerHTML = http.responseText;
        return false
    }
}
$(document).ready(function () {
    $('.slibe').click(function () {
        var velika = $(this).attr('id');
        $('.velika').attr('src', '/galerije/slike/' + velika);
        return false
    })
});

function dodajKomentar() {
    ne = Math.random();
    vid = document.getElementById('klip').value;
    ime = document.getElementById('fname').value;
    komentar = document.getElementById('komentar').value;
    email = document.getElementById('email').value;
    cap = document.getElementById('captcha').value;
    ip = document.getElementById('ip').value;
    http.open('get', '/skripte/komentar.php?vid=' + vid + '&ime=' + ime + '&cap=' + cap + '&email=' + email + '&komentar=' + komentar + '&ip=' + ip + '&kes=' + ne);
    http.onreadystatechange = komentarOdgovor;
    http.send(null)
}
function komentarOdgovor() {
    if (http.readyState == 4) {
        var odgovor = http.responseText;
        e = document.getElementById('uspjeh');
        l = document.getElementById('greska');
        k = document.getElementById('kom');
        if (odgovor != "greska") {
            e.innerHTML = odgovor;
            e.style.display = 'block';
            l.style.display = 'none';
            k.style.display = 'none';
            return odgovor
        } else {
            k.style.display = 'block';
            l.style.display = 'block'
        }
    }
}
function ukiniDivG() {
    document.getElementById("greska").style.display = "none"
}


function prikaziAnketu() {
        var loader=$('#loader');
	var pollcontainer=$('#pollcontainer');
	loader.fadeIn();
	//Load the poll form
	$.get('/skripte/poll.php', '', function(data, status){
		pollcontainer.html(data);
		animateResults(pollcontainer);
		pollcontainer.find('#viewresult').click(function(){
			//if user wants to see result
			loader.fadeIn();
			$.get('/skripte/poll.php', 'result=1', function(data,status){
				pollcontainer.fadeOut(1000, function(){
					$(this).html(data);
					animateResults(this);
				});
				loader.fadeOut();
			});
			//prevent default behavior
			return false;
		}).end()
		.find('#pollform').submit(function(){
			var selected_val=$(this).find('input[name=poll]:checked').val();
			if(selected_val!=''){
				//post data only if a value is selected
				loader.fadeIn();
				$.post('/skripte/poll.php', $(this).serialize(), function(data, status){
					$('#formcontainer').fadeOut(100, function(){
						$(this).html(data);
						animateResults(this);
						loader.fadeOut();
					});
				});
			}
			//prevent form default behavior
			return false;
		});
		loader.fadeOut();
	});
	}
	function animateResults(data){
		$(data).find('.bar').hide().end().fadeIn('slow', function(){
							$(this).find('.bar').each(function(){
								var bar_width=$(this).css('width');
								$(this).css('width', '0').animate({ width: bar_width }, 1000);
							});
						});
	}
	
	function epp_reklamniBlok(gdje, pozicija) {
            var cUbica = Math.random();
           if(gdje=='reklama_top')
              {
                 $.get("/skripte/baneri.php", {pozicija: pozicija, cUbica: cUbica},
                  function(data){
                    if(data.indexOf('<!--!!!-->')===0)
                       $("#rek350top").html(data);
                    else
                       $("#"+gdje).html(data);
                    if (data.indexOf('<!--!1002!-->')===0)
                       {
                          $('#ciza').hide();
                           setTimeout(resizeFloater, 12000);
                       }
                  });
              }
              else
		$("#"+gdje).load("/skripte/baneri.php?pozicija="+pozicija+"&cUbica="+cUbica);


	}
                function resizeFloater()
        {
           $('#xfl').animate({ height: '50px' }, 300 );
           $('#ciza').show();
        }
      
      
        function resizeFloater2()
        {
           $('#xfl').animate({ height: '700px' }, 700 );
           $('#ciza').hide();
            setTimeout(resizeFloater, 1200);
        }


        function ldst(lol)
        {

           $.post('/skripte/stat.php',{cl:'naslovnica',tp:'', kn:''});
        }

        function clickBanner(idb)
        {
           
           $.post('/skripte/clickcounter.php',{id: idb});
        }


/*1000x100 telecom oktobar*/
function resizeTelMinus()
        {
           $('#tel').animate({ height: '100px' }, 500 );
        }
        function resizeTelPlus()
        {
           $('#tel').animate({ height: '200px' }, 500 );
            //setTimeout(resizeFloater, 3000);
        }

/*350x300 telecom oktobar*/
 function hovex() {
          document.getElementById('tel350').style.width = "700px";
          document.getElementById('tel350').style.marginLeft = "-350px";
          document.getElementById('fremko').style.width = "700px";
          document.getElementById('fremko').style.left = "350px";
    }

    function hidex() {
        document.getElementById('tel350').style.width = "350px";
        document.getElementById('tel350').style.marginLeft = "0px";
        document.getElementById('fremko').style.width = "350px";
        document.getElementById('fremko').style.left = "0px";
       
       
    }

/*SAMO ZA VEGETA-MIX*/

         function prikazi() {

            document.getElementById('lijeviW').style.display = 'block';
            document.getElementById('desnoW').style.display = 'none';
            //lijeviW.style.display = "block";
            //desnoW.style.display = "none";
        }

        function sakrij() {

           // lijeviW.style.display = "none";
            //desnoW.style.display = "block";
            document.getElementById('lijeviW').style.display = 'none';
            document.getElementById('desnoW').style.display = 'block';
        }



/*SCORE MAG POPUP*/

function OTVORI_SCOREMAG()
{
      mywindow = window.open("http://source.ba/scoreMag/index.php", "SCORE_MAG", "location=0,status=0,scrollbars=0,menubar=0,resizable=0, width=436,height="+window.innerHeight);
    	
	var sirina=window.innerWidth/2;
	var konacnoX=sirina-218;
    mywindow.moveTo(konacnoX, 0);


}

setTimeout("UBIJ_FLOATER()",8000);

function UBIJ_FLOATER()
{
	var doc=document.getElementById('floaterSensia');

	if(doc!=null)
	{
		//doc.innerHtml='';
		doc.style.position='relative';
		//doc.style.width='0px';
		//doc.style.height='0px';
		//document.body.removeChild(doc);
	}
}




