function readCookie(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function adc_showDisclaimer()
{
	arrayPageSize = getPageSize();
	adc_controlWindow(arrayPageSize[1] + 'px', 'hidden');
	var disp =  "";   
	var x = readCookie('cirilica');
      
    if (x == null) adc_controlDisclaimer('block');
    else {
  // vladimir haxor da prikaze sve kako treba nakon refresha default strane      
        adc_controlDisclaimer('none');
		adc_controlWindow('auto', 'auto');
        }
}

// overlay i sloj preko njega se koriste i za pregled za stampu
  
function printPreview(display) {
    document.getElementById('o_iframe').style.display = display;
    adc_controlDisclaimer(display,1);
}

function adc_confirmDisclaimer(status)
{
    if (status == 1)
    {
        adc_createCookie('cirilica', 1, 0);
        adc_controlDisclaimer('none');
// vladimir haxor za prikaz default.aspx kao treba u IE6             
		adc_controlWindow('auto', 'auto');
		refreshBackground();
    }
    else
    {
        window.location = "http://www.ujn.sr.gov.yu";
    }    
}

function adc_controlWindow(height, overflow)
{
	bod = document.getElementsByTagName('body')[0];
	bod.style.height = height;
	bod.style.overflow = overflow;

	htm = document.getElementsByTagName('html')[0];
	htm.style.height = height;
	htm.style.overflow = overflow;
	
	bodc = document.getElementById('adc-container');
	bodc.style.height = height;
	bodc.style.overflow = overflow;
	
}


function adc_controlDisclaimer(display,fluidSize)
{
	arrayPageSize = getPageSize();

	var oConfirm = document.getElementById('o_confirm');
    var oBackground = document.getElementById('o_background');

	oBackground.style.display = display;
	oConfirm.style.display = display;

    if (arguments.length == 1) {
	    var windowLeft = arrayPageSize[0];	
	    var windowTop = arrayPageSize[1];
	    var confirmWidth = oConfirm.offsetWidth;
	    var confirmHeight = oConfirm.offsetHeight;
    	
	    if (confirmWidth > windowLeft)
	    {
		    confirmWidth = windowLeft - 100;
		    oConfirm.style.width = confirmWidth + "px";
	    }
	    if (confirmHeight > windowTop)
	    {
		    confirmHeight = windowTop - 125;
		    oConfirm.style.height = confirmHeight + "px";
	    }
    		
	    var marginLeft = 0;
	    var marginTop = 0;

	    marginTop = (windowTop / 2) - (confirmHeight / 2)
	    marginLeft = (windowLeft / 2) - (confirmWidth / 2)

	    if (marginTop < 0) marginTop = 0;
	    if (marginLeft < 0) marginLeft = 0;
    	
	    oConfirm.style.top = marginTop + "px";
	    oConfirm.style.left = marginLeft + "px";
    }
}

function adc_createCookie(name, value, days)
{
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
    }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

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 getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
    }

function refreshBackground () 
{
    try
    {
        document.getElementById("MainTable").style.display = "none";
	    document.getElementById("MainTable").style.display = "block";
	}
	catch (err)
	{
	    //R.M. Ima bre da radi or else!!
	    setTimeout("refreshBackground()", 1000);
	}
	
}

 function hh() {
    var h1 = ((document.getElementById("o_confirm").offsetHeight > document.body.offsetHeight)?document.getElementById("o_confirm").offsetHeight + 100:document.body.offsetHeight + 100);
    document.getElementById("o_background").style.height = h1 + "px";
    document.getElementById("o_iframe").style.height = h1 + "px";
    var newWidth = Math.ceil(document.body.offsetWidth/6.74).toString() + "mm";
    toggleByRule("UJN_Main_Print","#printContent","width",newWidth + " !important"); // podesavanje sirine stampe prema rezoluciji browsera
    document.getElementById("o_confirm").style.display = "block";
    document.getElementById("o_confirm").style.display = "none";
    }
    
function toggleByRule(sheet,cssClass,attr,newValue) // daje novu vrednost newValue atributu attr u klasi cssClass u css-u sheet  
  {
  if ( 'undefined' != typeof document.styleSheets) {
    var sheets = document.styleSheets;
    var j, i = sheets.length,
        s, rtype, rs, r, str;

    while ( i-- ) {
      s = sheets[i];
      if (s.href.indexOf(sheet)!=-1)    {
        // Determine rule type - IE rules, Moz cssRules
        rtype = ( typeof s.rules != 'undefined' )? 'rules' : 'cssRules';

        if ( typeof s[rtype] != 'undefined' ) {
            rs = s[rtype];
            j = rs.length;

        while ( j-- ) {
          r = rs[j];
          if (cssClass == r.selectorText) { 
            var txt = r.style.cssText.toLowerCase();
            r.style.cssText = txt.replace(txt.split(attr)[1].split(";")[0],":"+newValue);
            return;
            }
          }
        }
      }
    }
  }
 }