function hide(tag) {
css=document.getElementById(tag).style;
if(css.display=="none") css.display=""; else css.display="none";
return false;
}
function verify() {
var conf = window.confirm("Jesi li siguran?");
if(!conf){return false;}
else{return true;}
}
function closex(tag) {
document.getElementById(tag).style.display="none";
document.getElementById(tag).innerHTML="";
return false;
}
function getPageScroll(){
	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 getPageSize(){

	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;
	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;
	}
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}
function findPosX(obj){
var curleft=0;
if(obj.offsetParent){
while(obj.offsetParent) {
curleft+=obj.offsetLeft;
obj=obj.offsetParent; }}
else if(obj.x) curleft+=obj.x;
return curleft;
}
function findPosY(obj){
var curtop=0;
if(obj.offsetParent){
while(obj.offsetParent){
curtop+=obj.offsetTop
obj=obj.offsetParent; }}
else if(obj.y)
curtop+=obj.y;
return curtop;
}

function fillModel(f){
	fID=f[f.selectedIndex].value;

	var mod = document.frm_katalog.modelID;
	mod.selectedIndex=-1;

	document.frm_katalog.modelID.options.length = 0;
	document.frm_katalog.printerID.options.length = 0;
	var n=0;

	if(modeli_ink[fID]) {
		mod.options[0] = new Option("Tinteni","");
		mod.options[0].disabled=true;
		mod.options[0].className ="modelgrp";
		for(i=0;i<modeli_ink[fID].length;i++)
		{
			var op = new Option();
			op.text = modeli_ink[fID][i];
			op.value = modeli_ink[fID][i];
			op.className ="modelopt";
			mod.options[i+1] = op;
			n=i;
		}
		n++;
		n++;
	}
	if(modeli_laser[fID]) {
		mod.options[n] = new Option("Laserski","");
		mod.options[n].disabled=true;
		mod.options[n].className ="modelgrp";
		for(i=0;i<modeli_laser[fID].length;i++)
		{
			var op = new Option();
			op.text = modeli_laser[fID][i];
			op.value = modeli_laser[fID][i];
			op.className ="modelopt";
			mod.options[i+n+1] = op;
		}
	}

}

function fillPrinter(p){
	if(!p) return;
	if(p.selectedIndex<0) return;
	pID=p[p.selectedIndex].value;
	f=document.frm_katalog.firmaID;
	fID=f[f.selectedIndex].value;
	id = fID+'_'+pID;

	document.frm_katalog.printerID.options.length = 0;
	if(printeri[id]) {
		for(i=0;i<printeri[id].length;i++)
		{
			document.frm_katalog.printerID.options[i] = new Option(printeri[id][i],printeri[id][i]);
		}
	}
}
function delPrinter(tag,pid) {
	if( verify() ) {
		ajax('/del_printer.php',tag,'printerID='+pid);
	}
}

function ajaxGS(a){
	var s=getPageScroll();
	var x=findPosX(document.getElementById('admin'));
	var cs = document.getElementById ('container_spremnik');
	cs.style.top = (s[1]+250)+'px';
	cs.style.left = (x+530)+'px';
	ajax('/get_spremnici.php','container_spremnik',a);
}

function ffirma(a){
	parent.location='/index.php?mode=admin&sub=printeri&firmaID='+a.options[a.selectedIndex].value;
}

function printerAddFirma()
{
	var a=$('firmaID');
	var b=$('tipID');
	ajax('/admin_get_spremnici.php','addSpremnici','firmaID='+a.options[a.selectedIndex].value + '&tipID='+b.options[b.selectedIndex].value);
}

function showPrinter(p) {
	var printer=p[p.selectedIndex].value;
	var m = document.frm_katalog.modelID;
	var model=m[m.selectedIndex].value;

	var f = document.frm_katalog.firmaID;
	var firma=f[f.selectedIndex].value;


	ajax('/show_item.php','itemArea','printer='+printer+'&model='+model+'&firma='+firma,'kosaricaAnimacija()');

	kosaricaAnimacija();
}
function addSpremnik(id,org){
	ajax('/spremnik_add.php','kosarica','spremnikID='+id+'&org='+org+'&act=add');

	var spval = document.getElementById('spremnikVal'+id+'_'+org);
	spval.value = parseInt(spval.value)+1;
	document.getElementById('kosarica_link').style.display=""
}

function deleteSpremnik(id,org){
	//if ( verify() ) {
		var spval = document.getElementById('spremnikVal'+id+'_'+org);
		spval.value = parseInt(spval.value)-1;
		if(parseInt(spval.value)<=0) spval.value=0;
		ajax('/spremnik_add.php','kosarica','spremnikID='+id+'&org='+org+'&act=del');
	//}
}
function delSpremnik(id,me){
	if ( verify() ) {
		ajax('/spremnik_del.php',me,'spremnikID='+id);
	}
}

// dreganje loga
function mrlj(){
	var target = $('target');
	var box = $('logo');
	var fx = new Fx.Styles(target, {
		duration: 1000,
		wait: false,
		transition: Fx.Transitions.Elastic.easeInOut
	});
	/*
	target.setStyles({
		'top': box.getTop(),
		'left': 40
	});*/

	box.addEvent('mousedown', function(event){
		event = new Event(event);
		fx.start({
			'top': [event.page.y - 25],
			'left': [event.page.x - 25]
		});
		event.stop();
	});

	new Drag.Base(target, {
	 	onComplete: function(){
			fx.start(this.s);
		},
	 	onStart: function(){
			this.s = {
				'left': 0,
				'top': this.element.getTop()
			};
		}
	 });
}

function bam(){
	setTimeout("bum()",1000);
}

// žigosanje
function bum(){
	$('logo').setStyle('display','');

	var fx = new Fx.Styles($('target'), {
		duration: 1000,
		wait: false,
		transition: Fx.Transitions.Elastic.easeInOut
	});
	$('target').setStyles({
		'top': -200,
		'left': 400
	});
	fx.start({'left': 0,'top': 0});
}

function kosaricaAnimacija(){

	var target = $('macula-mini');
	var fx2 = new Fx.Styles(target, {
		duration: 2000,
		wait: false,
		transition: Fx.Transitions.Back.easeOut
	});

	$$('.dodaj').each(function (box){

		box.addEvent('mousedown', function(event){

			target.setStyle('display','block');

			event = new Event(event);

			target.setStyle('left',event.page.x - 25);
			target.setStyle('top',event.page.y - 25);



			fx2.start({
				'top': $('kosarica').getTop()+5,
				'left': $('kosarica').getLeft()+5
			});
			//event.stop();
		});

	});


}
