function resizeIFrame(frameId) {
      try
      {
				f = document.getElementById(frameId);
				if (navigator.appName == 'Netscape')
				   // Mozila
				   f.style.height = f.contentWindow.document.body.offsetHeight + 30 + "px";
				else
					 {
				   // IE
				   //f.style.height = f.contentWindow.document.body.scrollHeight + 30 + "px";				   
				   f.style.width = "705px";				   
				   f.style.height = "4000px";				   
				  }
			}
      catch(err)  
      {
			    f.style.height = "5300px";
                //window.status = err.message;
				//alert(err.message);
      }
}

/* HERE IS THE EVENT DEFINITION */
function resizeIFrameEvent(evt) {  
	var ieKey = "srcElement";  
	var mozKey = "currentTarget";  
	var IFrameObj;  
	evt[mozKey] ? IFrameObj = evt[mozKey] : IFrameObj = evt[ieKey];  
	fitIframe(IFrameObj);
}

/* THIS FUNCTION FITS THE IFRAME TO DOCUMENT SIZE */
function fitIframe(IFrameObj) {
	var IFrameDoc;
	//if (IFrameObj.contentDocument) {  
	if (navigator.appName != 'Microsoft Internet Explorer') {
	   // Mozilla, Safari etc
	   IFrameObj.style.height = IFrameObj.contentWindow.document.body.offsetHeight + 30 + "px";   
	} else if (IFrameObj.contentWindow) {  
	   // IE5.5 and above
	   IFrameDoc = IFrameObj.contentWindow.document;  
	   if(IFrameDoc.body!=null) { // the IE event fires too often, and fires before IFrame is loaded, in which case doc==null.  It fires AGAIN once it loads fully, so ignore the first time   
	      try {       
	          var table = document.getElementById(IFrameObj.parentName);   
	          } 
	      catch (e) { alert('IE5.5+: Unable to locate IFrames parent table: '+IFrameObj.parentName ); }   
	      try {
	          var height=parseInt(IFrameDoc.body.scrollHeight)+20;
                 table.style.height=height;      
	          IFrameObj.style.height=height;
                if (parseInt(IFrameObj.style.height) != height) {
                    // IE9+
                    //height=parseInt(IFrameDoc.body.getAttribute("scrollHeight", 0))+20;
	             //height=parseInt(IFrameDoc.body.scrollHeight)+20;
                    table.style.height=height+"px";      
   	             IFrameObj.style.height=height+"px";
//alert("h "+IFrameDoc.body.scrollHeight);
                    }
	          } 
	      catch (e) { alert('IE5.5+: Unable to get size of IFrame: '+IFrameObj.name ); }  
	   } // if IFrameDoc!=null
	} else if (IFrameObj.document) {  
		// IE5  
	  IFrameDoc = IFrameObj.document;  
	  try {
	      document.getElementById(IFrameObj.parentName).style.height=IFrameDoc.body.scrollHeight-IFrameDoc.body.offsetHeight;  
	      } 
	  catch (e) { alert('IE 5.0: Unable to located IFrames parent table or get size of IFrame: '+IFrameObj.parentName ); }
	} else {  
	  alert('fitIframe was unable to detect the browser version');  
	  return true;
	}
}


/***********************************************
* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function ajaxpage4acc(url, containerid, altcontainerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
{
page_request = new XMLHttpRequest();
}
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP");
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false

if ( altcontainerid === undefined ) { altcontainerid = ""; }

if ( altcontainerid.substring(0,6) == "iframe" ) {
     
     // create table
     var reportTable  = document.createElement( "TABLE" );
     reportTable.name = altcontainerid+"_iframe_table";
     reportTable.id=reportTable.name;
     reportTable.width="100%";
     reportTable.style.border="0px";
     var reportTBody = document.createElement ("TBODY"); // required by IE only, doesn't hurt FF
     var reportRow = document.createElement( "TR" );
     var reportCell = document.createElement( "TD" );
     reportRow.appendChild(reportCell);
     reportTBody.appendChild(reportRow);
     reportTable.appendChild(reportTBody);
     // create iframe
     var myContainer = document.getElementById(containerid);
     removeTagElements(containerid);
     var reportIFrame = document.createElement("iframe");
     reportIFrame.name = altcontainerid;
     reportIFrame.id = reportIFrame.name;
     reportIFrame.scrolling="no";
     reportIFrame.frameBorder="0";
     reportIFrame.style.height = "100%";
     reportIFrame.style.width = "100%";
     reportIFrame.style.border="0px";
     reportIFrame.src=url;
     reportIFrame.setAttribute("style","width:705px; BACKGROUND-IMAGE: url('http://www.cafehrasnica.com/Slike/ajax-loader.gif'); background-position: 2% 3%; BACKGROUND-REPEAT: no-repeat;");
     reportIFrame.parentName = reportTable.name;
     reportCell.appendChild(reportIFrame);
     myContainer.appendChild(reportTable);                                        
     if (navigator.appName != 'Microsoft Internet Explorer') {
       // Mozilla, Safari etc
       reportIFrame.addEventListener('load', resizeIFrameEvent, false) ;
     } else {                                                                         
     	 //IE
      reportIFrame.attachEvent("onreadystatechange", resizeIFrameEvent );
       /* Bug fix for IE (added v1.1):  IFrames created by JavaScript don't actually have a "name" in IE's internals */
       if(document.all) {        
	        if(self.frames[reportIFrame.id].name != reportIFrame.name) {
	           self.frames[reportIFrame.id].name  = reportIFrame.name;
	         }
       }
     }
} else {

   page_request.onreadystatechange=function(){
   loadpage4acc(page_request, containerid);
   }
   page_request.open('GET', url, true)
   page_request.send(null)
}

}

function loadpage4acc(page_request, containerid, tabid, tabs, tabhref, tabimg){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
{
     var myResponse = page_request.responseText;
     //alert(myResponse);
     var myContainer = document.getElementById(containerid);
     removeTagElements(containerid);
     var newdiv = document.createElement("div");
     if (navigator.appName == 'Microsoft Internet Explorer') {
        myContainer.appendChild(newdiv);
     }
     newdiv.innerHTML = "<input type=\"hidden\"/>"+myResponse;
     //alert(newdiv.innerHTML);
     if (navigator.appName != 'Microsoft Internet Explorer') {
        myContainer.appendChild(newdiv);
     }
}
}

function ajaxpage(url, containerid, altcontainerid) {

     var tabid    = "big_tab_content";
     var tabs     = "tabsMedia";
     var tabhref  = "tab3";
     var tabimg   = "animatedImg";
     var extratab = "extratab";

     // Trigger mouse click
     $('#'+tabs+' #'+tabid).trigger('click');
     $('#'+tabs+' #'+tabid).css({'background-image' : 'url(http://www.cafehrasnica.com/Slike/ajax-loader.gif)'});  
     $('#'+tabs+' #'+tabid).css({'background-repeat' : 'no-repeat'});  
     $('#'+tabs+' #'+tabid).css({'background-position' : 'left center'});  
     $('#'+tabs+' #'+containerid).text("Loading...");
     $('#'+tabs+' #'+extratab).css({'color' : 'red'});
     $('#'+tabs+' #'+extratab).css({'font-size' : '1.5em'});
     //$('*').css({'cursor' : 'progress'}); 

     if ( altcontainerid === undefined ) { altcontainerid = ""; }
     
     if ( altcontainerid.substring(0,6) == "iframe" ) {    
          
          // create table
          var reportTable  = document.createElement( "TABLE" );
          reportTable.name = altcontainerid+"_iframe_table";
          reportTable.id=reportTable.name;
          reportTable.width="100%";
          reportTable.style.border="0px";
          var reportTBody = document.createElement ("TBODY"); // required by IE only, doesn't hurt FF
          var reportRow = document.createElement( "TR" );
          var reportCell = document.createElement( "TD" );
          reportRow.appendChild(reportCell);
          reportTBody.appendChild(reportRow);
          reportTable.appendChild(reportTBody);
          // create iframe
          var myContainer = document.getElementById(containerid);
          removeTagElements(containerid);
          var reportIFrame = document.createElement("iframe");
          reportIFrame.name = altcontainerid;
          reportIFrame.id = reportIFrame.name;
          reportIFrame.scrolling="no";  
          reportIFrame.frameBorder="0";
          reportIFrame.style.height = "100%";
          reportIFrame.style.width = "100%";
          reportIFrame.style.border="0px";
          reportIFrame.src=url;
	      //reportIFrame.setAttribute("style","width:705px; BACKGROUND-IMAGE: url('http://www.cafehrasnica.com/Slike/vrti_guzicom_na_plazi.gif'); background-position: 2% 3%; BACKGROUND-REPEAT: no-repeat;");
          reportIFrame.setAttribute("style","width:705px; height:20px; BACKGROUND-IMAGE: url('http://www.cafehrasnica.com/Slike/ajax-loader.gif'); background-position: 2% 3%; BACKGROUND-REPEAT: no-repeat;");
          reportIFrame.parentName = reportTable.name;
          reportCell.appendChild(reportIFrame);
          myContainer.appendChild(reportTable);
          if (navigator.appName != 'Microsoft Internet Explorer') {
            // Mozilla, Safari etc
            reportIFrame.addEventListener('load', resizeIFrameEvent, false) ;
          } else {
          	 //IE
            reportIFrame.attachEvent("onreadystatechange", resizeIFrameEvent );
            /* Bug fix for IE (added v1.1):  IFrames created by JavaScript don't actually have a "name" in IE's internals */
            if(document.all) {
     	        if(self.frames[reportIFrame.id].name != reportIFrame.name) {
     	           self.frames[reportIFrame.id].name  = reportIFrame.name;
     	         }
            }
         }
 
         $('#'+tabs+' #'+tabid).css({'background-image' : 'none'});
         $('*').scrollTop($('#'+tabhref).position().top) ;

     } else {

        var page_request = false
        if (window.XMLHttpRequest) // if Mozilla, Safari etc
        {
        page_request = new XMLHttpRequest();
        }
        else if (window.ActiveXObject){ // if IE
        try {
        page_request = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e){
        try{
        page_request = new ActiveXObject("Microsoft.XMLHTTP")
        }
        catch (e){}
        }
        }
        else
        return false
        
		    // // empty iframe if full
		    // if (navigator.appName != 'Microsoft Internet Explorer') {
		    // 	  // Mozilla, Safari etc
		    // 	  var iFrameElement = document.getElementById('rightiframe');
		    //     iFrameElement.setAttribute("src","http://www.cafehrasnica.com/junk.php");
		    //     iFrameElement.setAttribute("style","width:0px; height:0px; BACKGROUND-IMAGE: none;");
		    //     //$('#rightiframe').trigger('onload');
		    // } else {
		    // 	  //IE
		    // 	  window.frames['rightiframe'].location = "http://www.cafehrasnica.com/junk.php";
		    // 	  resizeIFrame('rightiframe', '0px', '0px');
		    // }	  
        
        page_request.onreadystatechange=function(){
            loadpage(page_request, containerid, tabid, tabs, tabhref, tabimg);
        }
        
        page_request.open('GET', url, true)
        page_request.send(null)
     }
}

function loadpage(page_request, containerid, tabid, tabs, tabhref, tabimg){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
{

     var myResponse = page_request.responseText;
     //alert(myResponse);
     var myContainer = document.getElementById(containerid);
     removeTagElements(containerid);
     var newdiv = document.createElement("div");
     if (navigator.appName == 'Microsoft Internet Explorer') {
        myContainer.appendChild(newdiv);
     }
     newdiv.innerHTML = "<input type=\"hidden\"/>"+myResponse;
     //alert(newdiv.innerHTML);
     if (navigator.appName != 'Microsoft Internet Explorer') {
        myContainer.appendChild(newdiv);
     }
     $('#'+tabs+' #'+tabid).css({'background-image' : 'none'});
     //$('#'+tabimg).attr("src","http://cafehrasnica.com/Slike/globe_animated2.gif");  
     //$('*').css({'cursor' : 'auto'}); //pointer
     // jump to the tab content
     $('*').scrollTop($('#'+tabhref).position().top) ;

}
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}

function removeTagElements(elem)
{
	if ( typeof(elem)!='undefined' )
	{
		if ( elem.hasChildNodes() )
		{
  		while ( elem.childNodes.length >= 1 )
    	{ 
	  		elem.removeChild( elem.firstChild );         
  		} 
  	}	
  }	
}

// Za radio buttons na anketi
function getCheckedRadioValue(radioObj) {
	if(!radioObj) {
		return "";
	}
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// Za submit button na anketi
function anketaShowResults(cod,odgovor,container) {
	  //alert("here");
	  var rbid=getCheckedRadioValue(document.anketa.id);
	  if (rbid=="") {
	  	//alert("Neophodno je izabrati jedan od ponudjenih odgovora.");
	  	// show_popup("Neophodno je izabrati jedan od ponudjenih odgovora.", 300);
	  	// popup DIV "popup_custom" is created in index.php 
	  	show_custom_popup('popup_custom', '350', '<h2>Informacija</h2><p>Neophodno je da izaberete jedan od ponudjenih odgovora.</p>');
	  } 
	  else {
	     //alert("container="+container);
	     var js_func_name = "ajaxpage4acc('vzpolls_uski/vote.php?ajax=1&cod="+cod+"&id="+rbid+"&odgovor="+odgovor+"','"+container+"');";
	     //alert(js_func_name);
	     // execute js function dynamically
	     var retval = eval(js_func_name);
	  }
}

//Standalone function to display popup window with faded background
function show_custom_popup(popID, popWidth, popText) {
    //popID    Popup Name (DIV element)
    //popWidth Popup Width
    //Fade in the Popup and add close button
    //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
	if ($('#' + popID).height() == 0)
	    popHeight = 52;
	else
        popHeight = $('#' + popID).height();

	var popMargTop = (popHeight / 2)-180;    
		
    var popMargLeft = ($('#' + popID).width() + 80) / 2;

   var logoimg = '<img src="Slike/chcom_favico.png" width="50px" height="50px" align="left" style="margin: 0px 10px 0 20px;" />';
   $('#' + popID).html(logoimg+popText);
   $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="Slike/close_pop.png" class="btn_close" title="Zatvori window" alt="Zatvori" /></a>');

    //Apply Margin to Popup
    $('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });
    
	//Fade in Background
    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('#fade').css({'filter' : 'alpha(opacity=60)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 
    return false;
}


$(document).ready(function() {

   // Custom Tooltips
   $(".tip_trigger").hover(function(){
   		tip = $(this).find('.tip');
   		tip.show(); //Show tooltip
   	}, function() {
   		tip.hide(); //Hide tooltip		  
   })

   //Popup modal window
   //When you click on a link with class of poplight and the href starts with a # 
   $('a.poplight[href^=#]').click(function() {
       var popID = $(this).attr('rel'); //Get Popup Name
       var popURL = $(this).attr('href'); //Get Popup href to define size
   
       //Pull Query & Variables from href URL
       var query= popURL.split('?');
       var dim= query[1].split('&');
       var popWidth = dim[0].split('=')[1]; //Gets the first query string value
   
       //Fade in the Popup and add close button
       $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="Slike/close_pop.png" class="btn_close" title="Zatvori window" alt="Zatvori" /></a>');
   
       //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
       var popMargTop = (($('#' + popID).height() + 0) / 2)-220;
       var popMargLeft = ($('#' + popID).width() + 80) / 2;
   
       //Apply Margin to Popup
       $('#' + popID).css({
           'margin-top' : -popMargTop,
           'margin-left' : -popMargLeft
       });
   
       //Fade in Background
       $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
       $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 
   
       return false;
   });
   
   //Close Popups and Fade Layer
   $('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
       $('#fade , .popup_block').fadeOut(function() {
           $('#fade, a.close').remove();  //fade them both out
       });
       return false;
   });


});


