// JavaScript Document

// over-ride the alert method only if this a newer browser.
// Older browser will see standard alerts
if(document.getElementById) {

	window.alert = function(txt) {

		CustomAlert(txt);
	}
}

var moz=(document.getElementById&&!document.all)?1:0;

var arrayPageSize = Array();

	overlayDuration = 0.2;	// shadow fade in/out duration
	resizeSpeed = 10;
	resizeDuration = (11 - resizeSpeed) * 0.15;


function CustomAlert(header)
{
	arrayPageSize =  getPageSize();
	hideSelectBoxes();
	hideFlash();
	var d = document
	var msg = d.createElement("span")
	msg.innerHTML = header;
	mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
	mObj.id = "modalContainer";
	mObj.style.display = 'none';
	 // make sure its as tall as it needs to be to overlay all the content on the page
	mObj.style.height = arrayPageSize[1] +'px';//  + getPageScroll()[1] + 'px' //+ getPageScroll()[1];
	
	// create the DIV that will be the alert 
	alertObj =  d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
	alertObj.id = "alertBox";
	alertObj.style.top = arrayPageSize[3] /2 - 20 + getPageScroll()[1]  + 'px';

	alertObj.style.left = ((bx()/2) - (250))+'px';//bt();		
	msg1 = alertObj.appendChild(d.createElement("p"));
	msg2 = alertObj.appendChild(d.createElement("p"));	
	msg1.id="btnCont";	
	msg1.appendChild(msg);
	btnOk = d.createElement('input');
//	btnOk.value = 'Potrdi';
//	btnOk.id='closeBtn';
	btnOk.src='/library/images/btn_potrdi.gif';
	btnOk.type ='image';
	btnOk.onclick = function() {
		d.getElementsByTagName("body")[0].removeChild(d.getElementById("modalContainer"));
		d.getElementsByTagName("body")[0].removeChild(d.getElementById("alertBox"));
		showSelectBoxes();
		showFlash();
		return false; 
	}
	msg2.style.textAlign='center';
	msg2.appendChild(btnOk);

	new Effect.Appear('modalContainer', { duration: overlayDuration, from: 0.0, to: 0.4 });


	
	//besedilo.focus();
	


}

// removes the custom alert from the DOM
function removeCustomAlert() {
	document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
//	clearTimeout(b);
}

//CustomConfirm

if(document.getElementById) {

	window.confirm = function(txt) {
		return CustomConfirm(txt);
		
		
	}
}

var moz=(document.getElementById&&!document.all)?1:0;

var arrayPageSize = Array();

	overlayDuration = 0.2;	// shadow fade in/out duration
	resizeSpeed = 10;
	resizeDuration = (11 - resizeSpeed) * 0.15;


function CustomConfirm(params)
{
arrayPageSize =  getPageSize();
	   var indeks;
	   

	   
	   this.msg    = typeof params.message != 'undefined' ?

		  params.message : '';

	   this.seznam    = typeof params.seznam != 'undefined' ?

		  params.seznam : '';

	   this.arrZ    = typeof params.arrZ != 'undefined' ?

		  params.arrZ : '';
		  
	   this.KodaOpreme    = typeof params.KodaOpreme != 'undefined' ?

		  params.KodaOpreme : '';	
		  
	   this.cancel    = typeof params.cancel != 'undefined' ?

		  params.cancel : '';		  
		  

	   ok_cb   = typeof params.ok_cb != 'undefined' ? params.ok_cb

		  : function() {};

	   cncl_cb = typeof params.cancel_cb != 'undefined' ?

		  params.cancel_cb : function() {};



	   this.ok_cb = function() {

	   	ok_cb(params.arrZ,indeks);
		new Effect.Fade('modalContainer', { duration: overlayDuration});
		
		d.getElementsByTagName("body")[0].removeChild(d.getElementById("modalContainer"));
		d.getElementsByTagName("body")[0].removeChild(d.getElementById("alertBox"));
		//PristejZahtevane(KodaOpreme, arrZ);


	   };



	   this.cncl_cb = function() {

		//PristejZahtevane(KodaOpreme, arrZ);
		cncl_cb(params.KodaOpreme);
		new Effect.Fade('modalContainer', { duration: overlayDuration});
		
		d.getElementsByTagName("body")[0].removeChild(d.getElementById("modalContainer"));
		d.getElementsByTagName("body")[0].removeChild(d.getElementById("alertBox"));


	   };





	var d = document
	var header = '<p>'+ this.msg+'</p>';
	header+='<p>'+this.seznam+'</p>';
	var msg = d.createElement("span")	
	msg.innerHTML = header;
	
	mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
	mObj.id = "modalContainer";
	mObj.style.display = 'none';
	 // make sure its as tall as it needs to be to overlay all the content on the page
	mObj.style.height = arrayPageSize[1]  + 'px' //+ getPageScroll()[1];
	
	// create the DIV that will be the alert 
	alertObj =  d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
	alertObj.id = "alertBox";
	alertObj.style.top = arrayPageSize[3] /2 - 20 + getPageScroll()[1]  + 'px';

	alertObj.style.left = ((bx()/2) - (250))+'px';//bt();		
	msg1 = alertObj.appendChild(d.createElement("p"));
	msg1.id="btnCont";	
	msg1.appendChild(msg);
	msg2 = alertObj.appendChild(d.createElement("p"));
	msg2.id="gumbi";		
	msg2.style.textAlign='center';
	btnOk = d.createElement('input');
//	btnOk.value = 'Potrdi';
//	btnOk.id='closeBtn';
	btnOk.style.marginRight='10px';
	btnOk.type ='image';
	btnOk.src='/library/images/btn_potrdi.gif';
	
	btnOk.onclick = this.ok_cb;
	msg2.appendChild(btnOk);
	
	btnNo = d.createElement('input');
//	btnNo.value = 'Prekliči';
//	btnNo.id='closeBtn';
	btnNo.type ='image';
	btnNo.src='/library/images/btn_preklici.gif';
	new Effect.Appear('modalContainer', { duration: overlayDuration, from: 0.0, to: 0.4 });	
	btnNo.onclick = this.cncl_cb;
if( this.cancel)
	msg2.appendChild(btnNo);


}

// removes the custom alert from the DOM
function removeCustomAlert() {
	document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
//	clearTimeout(b);
}


function getPageSize11(){

	

	var xScroll, yScroll;

	

	if (window.innerHeight && window.scrollMaxY) {	

		xScroll = window.innerWidth + window.scrollMaxX;

		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;

	

//	console.log(self.innerWidth);

//	console.log(document.documentElement.clientWidth);



	if (self.innerHeight) {	// all except Explorer

		if(document.documentElement.clientWidth){

			windowWidth = document.documentElement.clientWidth; 

		} else {

			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;

	}



//	console.log("xScroll " + xScroll)

//	console.log("windowWidth " + windowWidth)



	// for small pages with total width less then width of the viewport

	if(xScroll < windowWidth){	

		pageWidth = xScroll;		

	} else {

		pageWidth = windowWidth;

	}

//	console.log("pageWidth " + pageWidth)



	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 

	return arrayPageSize;

}



function getPageScroll11(){



	var xScroll, yScroll;



	if (self.pageYOffset) {

		yScroll = self.pageYOffset;

		xScroll = self.pageXOffset;

	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict

		yScroll = document.documentElement.scrollTop;

		xScroll = document.documentElement.scrollLeft;

	} else if (document.body) {// all other Explorers

		yScroll = document.body.scrollTop;

		xScroll = document.body.scrollLeft;	

	}



	arrayPageScroll = new Array(xScroll,yScroll) 

	return arrayPageScroll;

}

function showSelectBoxes(){

	var selects = document.getElementsByTagName("select");

	for (i = 0; i != selects.length; i++) {

		selects[i].style.visibility = "visible";

	}

}



// ---------------------------------------------------



function hideSelectBoxes(){

	var selects = document.getElementsByTagName("select");

	for (i = 0; i != selects.length; i++) {

		selects[i].style.visibility = "hidden";

	}

}

function by()
{
var moz=(document.getElementById&&!document.all)?1:0;
return (moz) ? self.innerHeight : document.body.clientHeight;



	
}
function bx()
{
var moz=(document.getElementById&&!document.all)?1:0;
return (moz) ? self.innerWidth : document.body.offsetWidth;

}

function bo()
{
	return (moz) ? window.pageYOffset : document.body.scrollTop;
}

function bt()
{
	with(document.getElementById('alertBox').style)
	{
		
		top = bo()+by()/2-100;
	}
		b = setTimeout('bt()',10);
}
