// JavaScript Document

var otvoreno = new Array();
var podebljano = new Array();
var zboldano = '';

function otvori(r, id) {
	li = document.getElementById('li_' + r + '_' + id);
	if (li.style.display == 'block') {
		li.style.display = 'none';
		otvoreno[r] = '';
		odboldaj();
	} else {
		li.style.display = 'block';
		//2e5082
		document.getElementById('li' + (id - 1)).style.fontWeight = 'bold';
		odboldaj();
		zatvori(r, id);
		otvoreno[r] = 'li_' + r + '_' + id;
		podebljano[r] = 'li' + (id - 1);
	}
}

function zatvori(r, id) {
	for (i=r;i<otvoreno.length;i++) {
		if (document.getElementById(otvoreno[i]) && (otvoreno[i] != 'li_' + r + '_' + id)) {
			document.getElementById(otvoreno[i]).style.display = 'none';
		}
		if (document.getElementById(podebljano[i]) && (podebljano[i] != 'li' + (id - 1))) {
			document.getElementById(podebljano[i]).style.fontWeight = 'normal';
		}
	}
}

function zboldaj(r, id) {
	li = document.getElementById('li' + id);
	odboldaj();
	li.style.fontWeight = 'bold';
	zatvori(r, id);
	zboldano = 'li' + id;
}

function odboldaj() {
	if (document.getElementById(zboldano)) {
		document.getElementById(zboldano).style.fontWeight = 'normal';
		zboldano = '';
	}
}

function uvjetno_odboldaj(id) {
	if (document.getElementById(zboldano) && (zboldano != 'li' + (id - 1))) {
		document.getElementById(zboldano).style.fontWeight = 'normal';
		zboldano = '';
	}
}

function osvjezi(id, r) {
	li = document.getElementById('li_' + r + '_' + id);
	uvjetno_odboldaj(id);
	zatvori(r, id);
}

var sirina = 644;
var pomak = 28;
var z = 0;
var ul_visible = '';

function move(x) {

	div = document.getElementById('slikice_container');
	currentX = parseInt(div.offsetLeft);
	currentWidth = parseInt(div.offsetWidth);

	z = z + 1;

	if(z >= sirina/pomak) {
		z = 0;
	}

	if (x < 0 && currentX < 0) {
		move_fw();
	} else if (x > 0 && currentX > -(Math.floor(currentWidth/sirina) * sirina)) {
		move_back();
	}

	if (z > 0) setTimeout("move("+x+")", 1);
}

function move_fw() {
	div = document.getElementById('slikice_container');
	div.style.left = currentX + pomak + "px";
}

function move_back() {
	div = document.getElementById('slikice_container');
	div.style.left = currentX - pomak + "px";
}

function otkrij(Id) {
	sakrij();
	ul = document.getElementById(Id);
	ul.style.display = 'block';
	ul_visible = Id;
}

function sakrij() {
	if (document.getElementById(ul_visible))
	{
		ul_visible = document.getElementById(ul_visible);
		ul_visible.style.display = 'none';
	}
}

function sakrij_slikice() {
	document.getElementById('slikice').style.display = 'none';
	document.getElementById('left_scroll').style.display = 'none';
	document.getElementById('right_scroll').style.display = 'none';
	document.getElementById('left').innerHTML = '&nbsp;';
}

function otkrij_slikice() {
	document.getElementById('slikice').style.display = 'block';
	document.getElementById('left_scroll').style.display = 'block';
	document.getElementById('right_scroll').style.display = 'block';
}

function goto(parametar) {
	if (parametar != '') {
		update_content ('left', 'izbornik/' + parametar + '.php');
	}
}

function swapPic(n,o){

	if (document.getElementById('img1')) {
		new Effect.Appear('img'+n, { duration: 3 });
		new Effect.Fade('img'+o, { duration: 3 });

		if(n == 6) nn = 1; else nn = n + 1;
		if(o == 6) oo = 1; else oo = o + 1;

		setTimeout("swapPic("+nn+","+oo+")", 5000);
	}
}

var status = 0;

function checkinput(input) {
	el = document.getElementById(input);
	if (el.value != '') { el.style.borderColor = '#002447'; return 0; } else { el.style.borderColor = '#cc0000'; return 1; }
}

function checkform() {

		element = 'ime';
		status += checkinput(element);

		element = 'prezime';
		status += checkinput(element);

		element = 'tvrtka';
		status += checkinput(element);

		element = 'adresa';
		status += checkinput(element);

		element = 'ptt';
		status += checkinput(element);

		element = 'mjesto';
		status += checkinput(element);

		element = 'telefon';
		status += checkinput(element);

		element = 'fax';
		status += checkinput(element);

		if (status > 0) {
			alert ('Molimo popunite prazna polja označena crvenom bojom. Broj grešaka je ' + status);
			return false;
		}  else {
			update_contentGET('prikaz_artikla', 'moja_kosarica.php?iL=1', 'upit');
		}
}

/************************************************************************************************************

loadFlash.js

************************************************************************************************************/

function loadFlash(s, w, h, m, mt, ml) {

	if (m == 'transparent') {

		wmode = ' wmode="transparent"';
		wmodeparam = '	<param name="wmode" value="transparent">';

	} else {

		wmode = '';
		wmodeparam = '';
	}

	var f = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + w + '" height="' + h + '" style="margin-top:' + mt + 'px; margin-left:' + ml + 'px; float:left; ">'
	+	'	<param name="movie" value="' + s + '">'
	+	'	<param name="quality" value="best">'
	+	'	<param name="play" value="true">'
	+	'	<param name="menu" value="false">'
	+	wmodeparam
	+	'	<embed pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" src="' + s + '" width="' + w + '" height="' + h + '" quality="best" play="true" menu="false"' + wmode + '></embed>'
	+	'</object>';

	document.write(f);
}

/************************************************************************************************************

ajax.js

************************************************************************************************************/

var enableCache = true;
var jsCache = new Array();
var dynamicContent_ajaxObjects = new Array();

function ajax_showContent(divId,ajaxIndex){

	document.getElementById(divId).innerHTML = dynamicContent_ajaxObjects[ajaxIndex].response;
	if(enableCache) jsCache[divId] = dynamicContent_ajaxObjects[ajaxIndex].response;
	dynamicContent_ajaxObjects[ajaxIndex] = false;
}

function update_content(divId,url){

	var divCt = document.getElementById(divId);
	var ajaxIndex = dynamicContent_ajaxObjects.length;

	divCt.innerHTML = '<img src="images/loader.gif" alt="refreshing..." style="height:10px; width:54px; padding:13px 10px 5px 10px; " />';
	dynamicContent_ajaxObjects[ajaxIndex] = new sack();
	dynamicContent_ajaxObjects[ajaxIndex].requestFile = url;
	dynamicContent_ajaxObjects[ajaxIndex].onCompletion = function(){ ajax_showContent(divId,ajaxIndex); };
	dynamicContent_ajaxObjects[ajaxIndex].runAJAX();
}

function sack(file) {
	this.xmlhttp = null;

	this.resetData = function() {
		this.method = "POST";
  		this.queryStringSeparator = "?";
		this.argumentSeparator = "&";
		this.URLString = "";
		this.encodeURIString = true;
  		this.execute = false;
  		this.element = null;
		this.elementObj = null;
		this.requestFile = file;
		this.vars = new Object();
		this.responseStatus = new Array(2);
  	};

	this.resetFunctions = function() {
  		this.onLoading = function() { };
  		this.onLoaded = function() { };
  		this.onInteractive = function() { };
  		this.onCompletion = function() { };
  		this.onError = function() { };
		this.onFail = function() { };
	};

	this.reset = function() {
		this.resetFunctions();
		this.resetData();
	};

	this.createAJAX = function() {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				this.xmlhttp = null;
			}
		}

		if (! this.xmlhttp) {
			if (typeof XMLHttpRequest != "undefined") {
				this.xmlhttp = new XMLHttpRequest();
			} else {
				this.failed = true;
			}
		}
	};

	this.setVar = function(name, value){
		this.vars[name] = Array(value, false);
	};

	this.encVar = function(name, value, returnvars) {
		if (true == returnvars) {
			return Array(encodeURIComponent(name), encodeURIComponent(value));
		} else {
			this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
		}
	}

	this.processURLString = function(string, encode) {
		encoded = encodeURIComponent(this.argumentSeparator);
		regexp = new RegExp(this.argumentSeparator + "|" + encoded);
		varArray = string.split(regexp);
		for (i = 0; i < varArray.length; i++){
			urlVars = varArray[i].split("=");
			if (true == encode){
				this.encVar(urlVars[0], urlVars[1]);
			} else {
				this.setVar(urlVars[0], urlVars[1]);
			}
		}
	}

	this.createURLString = function(urlstring) {
		if (this.encodeURIString && this.URLString.length) {
			this.processURLString(this.URLString, true);
		}

		if (urlstring) {
			if (this.URLString.length) {
				this.URLString += this.argumentSeparator + urlstring;
			} else {
				this.URLString = urlstring;
			}
		}

		// prevents caching of URLString
		this.setVar("rndval", new Date().getTime());

		urlstringtemp = new Array();
		for (key in this.vars) {
			if (false == this.vars[key][1] && true == this.encodeURIString) {
				encoded = this.encVar(key, this.vars[key][0], true);
				delete this.vars[key];
				this.vars[encoded[0]] = Array(encoded[1], true);
				key = encoded[0];
			}

			urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
		}
		if (urlstring){
			this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
		} else {
			this.URLString += urlstringtemp.join(this.argumentSeparator);
		}
	}

	this.runResponse = function() {
		eval(this.response);
	}

	this.runAJAX = function(urlstring) {
		if (this.failed) {
			this.onFail();
		} else {
			this.createURLString(urlstring);
			if (this.element) {
				this.elementObj = document.getElementById(this.element);
			}
			if (this.xmlhttp) {
				var self = this;
				if (this.method == "GET") {
					totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
					this.xmlhttp.open(this.method, totalurlstring, true);
				} else {
					this.xmlhttp.open(this.method, this.requestFile, true);
					try {
						this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
					} catch (e) { }
				}

				this.xmlhttp.onreadystatechange = function() {
					switch (self.xmlhttp.readyState) {
						case 1:
							self.onLoading();
							break;
						case 2:
							;//self.onLoaded();
							break;
						case 3:
							self.onInteractive();
							break;
						case 4:
							self.response = self.xmlhttp.responseText;
							self.responseXML = self.xmlhttp.responseXML;
							self.responseStatus[0] = self.xmlhttp.status;
							self.responseStatus[1] = self.xmlhttp.statusText;

							if (self.execute) {
								self.runResponse();
							}

							if (self.elementObj) {
								elemNodeName = self.elementObj.nodeName;
								elemNodeName.toLowerCase();
								if (elemNodeName == "input"
								|| elemNodeName == "select"
								|| elemNodeName == "option"
								|| elemNodeName == "textarea") {
									self.elementObj.value = self.response;
								} else {
									self.elementObj.innerHTML = self.response;
								}
							}
							if (self.responseStatus[0] == "200") {
								self.onCompletion();
							} else {
								self.onError();
							}

							self.URLString = "";
							break;
					}
				};

				this.xmlhttp.send(this.URLString);
			}
		}
	};

	this.reset();
	this.createAJAX();
}
function update_contentGET(divId, url, form_name, submit_name) {

	document.getElementById(divId).style.display = 'block';

	//alert(eval("document." + form_name));
	var ajaxIndex = dynamicContent_ajaxObjects.length;
	dynamicContent_ajaxObjects[ajaxIndex] = new sack();

	//get POST elements
	for(i=0;eval("document." + form_name + ".elements[" + i + "]")!=undefined;i++){
		name = eval("document." + form_name + ".elements[" + i + "].name");
		type = eval("document." + form_name + ".elements[" + i + "].type");
		value = eval("document." + form_name + ".elements[" + i + "].value");
		value = escape(value);
		name = escape(name);
		//alert('name: '+name+'\ntype: '+type+'\nvalue: '+value);
		if(	type=='input'	||
			type=='select'	||
			type=='option'	||
			type=='textarea'||
			type=='text'	||
			type=='select-one' ||
			type=='hidden'
		)
			dynamicContent_ajaxObjects[ajaxIndex].setVar(name, value);
		if((type=='checkbox' || type=='radio')&& eval("document." + form_name + ".elements[" + i + "].checked"))
			dynamicContent_ajaxObjects[ajaxIndex].setVar(name, value);
		if(type=='submit' && submit_name==name)
			dynamicContent_ajaxObjects[ajaxIndex].setVar(name, value);
	}

	dynamicContent_ajaxObjects[ajaxIndex].requestFile = url;	// Specifying which file to get
	//dynamicContent_ajaxObjects[ajaxIndex].requestFile = eval("document." + form_name + ".action");
	dynamicContent_ajaxObjects[ajaxIndex].onLoaded = 'Loaded content - please wait';
	dynamicContent_ajaxObjects[ajaxIndex].onCompletion = function(){ ajax_showContent(divId,ajaxIndex,url); };
	dynamicContent_ajaxObjects[ajaxIndex].runAJAX();

}


/************************************************************************************************************

map.js

************************************************************************************************************/

function load() {

	document.getElementById("prikaz_artikla").innerHTML = '';
	var newdiv = document.getElementById("prikaz_artikla").appendChild(document.createElement("div"));
	newdiv.id = 'map';
	//var mapdiv = document.getElementById("map");
	newdiv.style.width = '100%';
	newdiv.style.height = '500px';

	if (GBrowserIsCompatible()) {

		var map = new GMap2(document.getElementById("map"));

		map.addControl(new GSmallMapControl());
		map.setCenter(new GLatLng(46.023295258648612, 15.902591943740816), 10);

		map.setMapType(G_NORMAL_MAP);

		var icon1 = new GIcon();
		icon1.image = "images/flag.png";
		icon1.iconSize = new GSize(50, 30);
		icon1.iconAnchor = new GPoint(25, 15);
		icon1.infoWindowAnchor = new GPoint(25, 0);

		var point1 = new GLatLng(46.023295258648612, 15.902591943740816);
		var marker1 = new GMarker(point1, icon1);
		map.addOverlay(marker1);
		GEvent.addListener(marker1, "click", function() {  marker1.openInfoWindowHtml("<img src='images/flag.png' alt='' style='margin: 15px 15px 15px 0;' /><span style='font-size:0.7em;'><strong>DEKOR tvornica rasvjete d.o.o.</strong><br />K.Š.Gjalskog 27/1<br />49210 Zabok, Hrvatska</span>") });
	}
}

/************************************************************************************************************

checkBrowser.js

************************************************************************************************************/

var agt = navigator.userAgent.toLowerCase();
var appVer = navigator.appVersion.toLowerCase();

var is_minor = parseFloat(appVer);
var is_major = parseInt(is_minor);

var is_opera = (agt.indexOf("opera") != -1);
var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
var is_opera6 = (agt.indexOf("opera 6") != -1 || agt.indexOf("opera/6") != -1);

var iePos  = appVer.indexOf('msie');
if (iePos !=-1) {
	is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));  //added missing ; - 030617 - bdn
	is_major = parseInt(is_minor);
}

var is_konq = false;
var kqPos   = agt.indexOf('konqueror');
if (kqPos !=-1) {
	is_konq  = true;
	is_minor = parseFloat(agt.substring(kqPos+10,agt.indexOf(';',kqPos)));
	is_major = parseInt(is_minor);
}

var is_getElementById   = (document.getElementById) ? "true" : "false";
var is_getElementsByTagName = (document.getElementsByTagName) ? "true" : "false";
var is_documentElement = (document.documentElement) ? "true" : "false";

var is_firefox = (agt.indexOf('firefox')!=-1)?true:false;
var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
var is_khtml  = (is_safari || is_konq);

var is_gecko = ((!is_khtml)&&(navigator.product)&&(navigator.product.toLowerCase()=="gecko"))?true:false;
var is_gver  = 0;
if (is_gecko) is_gver=navigator.productSub;

var is_moz   = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1) && (is_gecko) && ((navigator.vendor=="")||(navigator.vendor=="Mozilla")));

if (is_moz) {
   var is_moz_ver = (navigator.vendorSub)?navigator.vendorSub:0;
   if(!(is_moz_ver)) {
	   is_moz_ver = agt.indexOf('rv:');
	   is_moz_ver = agt.substring(is_moz_ver+3);
	   is_paren   = is_moz_ver.indexOf(')');
	   is_moz_ver = is_moz_ver.substring(0,is_paren);
   }
   is_minor = is_moz_ver;
   is_major = parseInt(is_moz_ver);
}

var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1) && (!is_khtml) && (!(is_moz)));

if ((navigator.vendor) && ((navigator.vendor=="Netscape6")||(navigator.vendor=="Netscape")) && (is_nav)) {
   is_major = parseInt(navigator.vendorSub);
   is_minor = parseFloat(navigator.vendorSub);
}

var is_ie = ((iePos!=-1) && (!is_opera) && (!is_khtml));
