/*
Zabezpiecza przed ogl?daniem zawarto?ci ramki bez pozosta?ej struktury strony.
*/

/*function loadMainPage(portalUrl, minHeight) {
	if(top == self)
		top.location.href = portalUrl;		
	sizeController(minHeight,78);
}*/		


/*********** Google Analytics **********************/
 
 function initGoogleAnalytics() {
	 var ad = document.location.href;
	 var pr = document.location.protocol;
	 var d = 2 + pr.length;
	 var e = d + 5; 
	 var a = ad.substring(d, e);
	  /* wykluczone zostaly serwery 10.10.*, localhost, osozdemo */
	 if(a!='10.10'&&a!='local'&&a!='osozd'){	
		var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
		document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
	
		try {
			var pageTracker = _gat._getTracker("UA-6935566-1");
			pageTracker._trackPageview();
		} catch(err) {
		}
  	}
 } 

 initGoogleAnalytics();

/*********** Google Analytics **********************/

function loadMainPageServices(portalUrl, minHeight){	
	if(navigator.userAgent.indexOf("Opera")>-1){
		top.frames['content'].document.getElementById('main').style.visibility = 'visible';		
	}
	resizeFrames(1);		
	bodyMinHeight = document.body.scrollHeight+78;   
	minHeight = (minHeight>bodyMinHeight?minHeight:bodyMinHeight);	

	if(top == self)
		top.location.href = portalUrl;		
		sizeControllerServices(minHeight,78);	
}

function sizeControllerServices(minHeight,gap) {
	sizeControllerServices(minHeight,gap, 2000);
}
  
function sizeControllerServices(minHeight,gap, timeout) {
	try {
		if(minHeight == null)
			return;
		
		if (gap == null) gap = 78;
	
		var currWindowHeight = top.document.body.clientHeight - 5; // aktualny rozmiar okna
		var forcedHeight = currWindowHeight;
		
		
		if(currWindowHeight < document.body.scrollHeight + gap || currWindowHeight < minHeight){
           forcedHeight = (document.body.scrollHeight>minHeight?document.body.scrollHeight:minHeight) + gap;
        }
			
		if(top.document.getElementById('content')!=null){
			if((forcedHeight+'px') != top.document.getElementById('content').style.height) {
	//			alert('Min height: ' + minHeight + '; Current height:' + currWindowHeight);
				top.document.getElementById('content').style.height = forcedHeight+'px';
				top.frames['content'].document.getElementById('leftbar').style.height = forcedHeight-gap+'px';
				top.frames['content'].document.getElementById('main').style.height = forcedHeight-gap+'px';
				top.frames['content'].document.getElementById('rightbar').style.height = forcedHeight-gap+'px';
			}
		}
		setTimeout('sizeControllerServices('+minHeight+')', timeout);
	}
	catch(e) {
		alert(e);
	}
}


function loadMainPage(portalUrl, minHeight, ekp){	
	if(navigator.userAgent.indexOf("Opera")>-1){
		top.frames['content'].document.getElementById('main').style.visibility = 'visible';		
	}
	resizeFrames(1);
	minHeight = document.body.scrollHeight+(ekp==true?0:78);
	
  if (portalUrl!=null) {
    var s = portalUrl + '/';
    if (s.indexOf("/osoz-spc/")>=0) {
      minHeight = minHeight > 630 ? minHeight : 630;  
    }
  } 	
	
	if(top == self && ekp != 'PLJ')
		top.location.href = portalUrl;		
	if(ekp)	
		sizeController(minHeight,0);	
	else 	
		sizeController(minHeight,78);	
}

/* Dla stron, gdzie menu jest wieksze od strony - jest brana wartosc minimalna strony minHeight! */
function minLoadMainPage(portalUrl, minHeight){	
	if(navigator.userAgent.indexOf("Opera")>-1){
		top.frames['content'].document.getElementById('main').style.visibility = 'visible';		
	}
	resizeFrames(1);
	bodyMinHeight = document.body.scrollHeight+78;
	minHeight = (minHeight>bodyMinHeight?minHeight:bodyMinHeight);
	
	if(top == self)
		top.location.href = portalUrl;		

		sizeController(minHeight,78);	
}


/* Klasa kontrolera wymiarow okna */
function sizeController(minHeight,gap) {
	try {
		if(minHeight == null)
			return;
		
		if (gap == null) gap = 78;
	
		var currWindowHeight = top.document.body.clientHeight - 5; // aktualny rozmiar okna
		var forcedHeight = currWindowHeight;
		
		if(currWindowHeight < minHeight)
			forcedHeight = minHeight;
			
		if(top.document.getElementById('content')!=null){
 			if((forcedHeight+'px') != top.document.getElementById('content').style.height) {
	//			alert('Min height: ' + minHeight + '; Current height:' + currWindowHeight);
				top.document.getElementById('content').style.height = forcedHeight+'px';
				top.frames['content'].document.getElementById('leftbar').style.height = forcedHeight-gap+'px';
				top.frames['content'].document.getElementById('main').style.height = forcedHeight-gap+'px';
				top.frames['content'].document.getElementById('rightbar').style.height = forcedHeight-gap+'px';
			}
		}
		setTimeout('sizeController('+minHeight+')', 2000);
	}
	catch(e) {
		alert(e);
	}
}
/*
Zmienia rozmiar wszystkich ramek ("przemieszcza si?" w strukturze ramek 
od podstawowego okna ("od g?ry")).
*/
function resizeFrames(height) {	
	if(top.document.getElementById('content')!=null)
	{
		top.document.getElementById('content').style.height = height+'px';
		top.frames['content'].document.getElementById('leftbar').style.height = height+'px';
		top.frames['content'].document.getElementById('rightbar').style.height = height+'px';
		top.frames['content'].document.getElementById('main').style.height = height+'px';
		if((top.frames['content'].document.getElementById('leftbar')!=null)&&
			(top.frames['content'].document.getElementById('leftbar').document!=null)&&
			(top.frames['content'].document.getElementById('leftbar').document.getElementById('cnt_button') != null))
			setCounter();
		else 
			setTimeout("setCounter()",200);
	}
}
function show(id){
	if("loading"==id){
			var object = top.document.getElementById(id);
			var width = top.document.body.scrollWidth;
			var height = top.document.body.scrollHeight;
			
			var d = window.innerHeight || document.documentElement.clientHeight;
	
			if(d>height)
				height = d; 

		if(object){			
			object.style.top="0px";
			object.style.left="0px";
			object.style.width=width+"px";
			object.style.height=height+"px";
		}
	}
	if(top.document.getElementById){
		obj = top.document.getElementById(id);
		   if(obj != null)
			obj.style.display = "block";
	}	
}
function hide(id){
	if(top.document.getElementById){
		obj = top.document.getElementById(id);
			if(obj != null) 
				obj.style.display = "none";
	}
}
function setCounter() {
//	top.frames['content'].frames['leftbar'].document.getElementById('cnt_button').style.bottom = 5+'px'
}
function setTopPage(url) {
	top.location.href = url;
}
function replaceTopPage(url) {
	top.location.replace(url);
}
function setContentPage(url) {
	top.content.location.href = url;
}
function setStatsPage(url) {
	top.content.statsbar.location.href = url;
}
function setMenuPage(url) {
	top.content.leftbar.location.href = url;
}
function setSubmenuPage(url) {
	top.content.rightbar.location.href = url;
}
function setMainPage(url) {
	if(navigator.userAgent.indexOf("Opera")>-1){
		top.frames['content'].document.getElementById('main').style.visibility = 'hidden';
		top.frames['content'].document.getElementById('main').style.height = '100px';
	}
	top.content.main.location.href = url;	
//	replaceMainPage(url);
}
function replaceMainPage(url) {
	top.content.main.location.replace(url);
}
function setPage(url) {
	window.location.href = url;
}
/* rozszerza wysoko?? ramkek w kt?rych znajduje si? strona z kt?rej funkcja jest wywo?ywana */
function resizeParentFrames(height){
/*
Strona ma sama zmienia? rozmiar
	parent.parent.document.getElementById('leftbar').style.height = height+'px';
	parent.parent.parent.document.getElementById('content').style.height = height+'px';				
	parent.parent.document.getElementById('rightbar').style.height = height+'px';				
	parent.parent.document.getElementById('center').style.height = height+'px';						
	parent.parent.leftbar.document.getElementById('cnt_button').style.bottom = 5+'px';
*/
}
function LoadCounter(obj,obj_name,counter_id,counter_button_id){	    	
    if((obj.document.getElementById(counter_id)!=null)&&(obj.document.getElementById(counter_button_id)!=null)){
	    obj.document.getElementById(counter_id).src='../main/counter?t='+(new Date()).getTime();
		obj.document.getElementById(counter_button_id).style.display='';			
	}else{						
		setTimeout('LoadCounter('+obj_name+',"'+obj_name+'","'+counter_id+'","'+counter_button_id+'")',200);			
	}
}
/* Obs?uguje wyskakuj?ce okienka na stronach z logowaniem */
function showWindow(file, aCatalog) {
	var lWidth = 770;
	var lHeight = 400;
	var lTop = (screen.height / 2) - (lHeight / 2);
	var lLeft = (screen.width / 2) - (lWidth / 2);
	if (aCatalog == null) { 
		aCatalog = "auth";
	}
	aPath = '../../../osoz-resources/template/osozportals/'+aCatalog+'/html/opis';
	window.open(aPath+'/'+file+'.html', '', 'height='+lHeight+', width='+lWidth+', resizable=false, scrollbars=yes, top=' + lTop + ', left=' + lLeft);
}
/* Potrzebne do wyskakuj?cego okienka ze strumieniem danych w systemie (ekran z logowaniem) */
function showTransactions() {
	var lWidth = 770;
	var lHeight = 400;
	var lTop = (screen.height / 2) - (lHeight / 2);
	var lLeft = (screen.width / 2) - (lWidth / 2);
	window.open('../../servlet/auth/dataStream', 'Transakcje', 'height='+lHeight+', width='+lWidth+', resizable=false, scrollbars=yes, top=' + lTop + ', left=' + lLeft);
}
/*
Otwiera nowe okno przegladarki i ustawia w nim okreslona informacje o logowaniu.
*/
var recentPop = null;
function showLoginInfo(type) {
	switch(type) {
		case 'klawiatura':
			file = 'klawiatura';
		break;
		case 'czytnikKodowKreskowych':
			file = 'czytnikKodowKresk';
		break;
		case 'czytnikKartProcesorowych':
			file = 'czytnikKartProc';
		break;
		case 'czytnikCechBiometrycznych':
			file = 'czytnikCechBio';
		break;
		default:
			file = 'brakInfo';
		break;
	}
	var lWidth = 770;
	var lHeight = 400;
	var lTop = (screen.height / 2) - 200;
	var lLeft = (screen.width / 2) - 385;
	if (recentPop!=null)recentPop.close();
	recentPop = window.open('../../../osoz-resources/template/osozportals/auth/html/sposobyLogowania/'+file+'.html', 'OSOZ', 'height='+lHeight+', width='+lWidth+', resizable=false, scrollbars=yes, top=' + lTop + ', left=' + lLeft);
}
/*
?adowanie licznika dla strony autoryzacyjnej.
*/
function LoadAuthCounter(obj,obj_name,counter_id,counter_button_id){	    	
    if((obj.document.getElementById(counter_id)!=null)&&(obj.document.getElementById(counter_button_id)!=null)){
	    obj.document.getElementById(counter_id).src='../main/counter?t='+(new Date()).getTime();
		obj.document.getElementById(counter_button_id).style.display='';
	}else{						
		setTimeout('LoadAuthCounter('+obj_name+',"'+obj_name+'","'+counter_id+'","'+counter_button_id+'")',200);			
	}
}
function newWindow(url) {
	var lWidth = 770;
	var lHeight = 400;
	var lTop = (screen.height / 2) - (lHeight / 2);
	var lLeft = (screen.width / 2) - (lWidth / 2);
	window.open(url, 'OSOZ', 'height='+lHeight+', width='+lWidth+', resizable=false, scrollbars=yes, top=' + lTop + ', left=' + lLeft);
}
function newWindow(url, lWidth, lHeight) {
	if(isNaN(lWidth))
		lWidth = 770;
	if(isNaN(lHeight))
		lHeight = 400;
	var lTop = (screen.height / 2) - (lHeight / 2);
	var lLeft = (screen.width / 2) - (lWidth / 2);
	window.open(url, 'OSOZ', 'height='+lHeight+', width='+lWidth+', resizable=false, scrollbars=yes, top=' + lTop + ', left=' + lLeft);
}
function resizableWindow(url, lWidth, lHeight) {
	if(isNaN(lWidth))
		lWidth = 770;
	if(isNaN(lHeight))
		lHeight = 400;
	var lTop = (screen.height / 2) - (lHeight / 2);
	var lLeft = (screen.width / 2) - (lWidth / 2);
	window.open(url, 'OSOZ', 'height='+lHeight+', width='+lWidth+', resizable=yes, scrollbars=yes, top=' + lTop + ', left=' + lLeft);
}

	/* przeladowuje frame content */ 
	function reloadContent(portalUrl,portalUrlQueryString){
		if(portalUrlQueryString==null)portalUrlQueryString='';
		top.content.location.replace(portalUrl+'/servlet/main/index'+portalUrlQueryString);
	}
	
	/* Przeladowuje g??wn? i contenta podczas wylogowywania */
	function reloadContentOnLogout(portalUrl){
		top.location.replace(portalUrl + '/servlet/main/indexhtml');	
		top.content.location.replace(portalUrl + '/servlet/about/info');
	}
	/* ustawia parametr val w menu */
	function setMenu(val){
		var loc = top.content.leftbar.location;
		var link = loc.protocol+"//"+loc.host+loc.pathname;		
		top.content.leftbar.location.href = link+"?miName="+val;
	}
	/* ustawia parametr val w submenu */
	function setSubmenu(val) {
		var loc = top.content.rightbar.location;
		var link = loc.protocol+"//"+loc.host+loc.pathname;		
		top.content.rightbar.location.href = link+"?smiName="+val;
	}
