/* 
vim:enc=utf8:fenc=utf8
 * IZBORNICI 
 */
var x, y, to = false;

function OtvoriZatvori( e ) {

	// Standardni početak
	var th;
	if (e.target) th = e.target;
	else if (e.srcElement) th = e.srcElement;
	if (th.nodeType == 3) th = th.parentNode;
	li = th.parentNode;

	if( li.lastChild.tagName == "UL" ) {
		x = li.lastChild;
		if( li.className == "otvoreno" ) {
			x.o = 1;
			Smanji();
		} else {
			x.o = 0;
			li.className = "otvoreno";
			x.style.height = 0; 
			xh = 0;
			x.maxH = x.childNodes.length * 22;
			Povecaj();
		}
	}

	try {
		e.cancelBubble = true;
		e.stopPropagation();
	} catch( e ) {
	}
}

/*
 * Zatvaranje okomitog podizbornika
 */
function Smanji( ) {
	clearTimeout( to );
	try {
		x.style.height = Math.max(0, x.offsetHeight - 10 ) + "px";
	} catch( e ) {
		x.style.height = "";
	}

	if( x.offsetHeight > 0 ) {
		to = setTimeout( "Smanji()", 10 );
	} else {
		li.className = "zatvoreno";
	}
}

/*
 * Otvaranje okomitog podizbornika
 */
function Povecaj( ) {
	clearTimeout( to );
	try {
		xh = Math.min(x.maxH, xh + 10 );
		x.style.height = "";
		x.style.height = xh + "px";
	} catch( e ) {
		x.style.height = "";
	}
	if( xh < x.maxH ) {
		to = setTimeout( "Povecaj()", 10 );
	} else {
		x.style.height = "";
	}
}

/* 
 * Pretvaranje linkova u JavaScript
 */
function SrediLijeviIzbornik() {
	try {
		Sredi( document.getElementById( "lIzbornik" ).firstChild.firstChild );
		var g = document.getElementById( "gdjeSam" );
		var brisi = false;
		for( i=0; i<g.childNodes.length; i++ ) {
			if( g.childNodes[i].nodeName == "A" ) {
			  if ( brisi ) {
				  g.childNodes[i].href = "javaScript:void(0)";
			  }
			  brisi = true;
			}
		}

	} catch( e ) {
	}

	try {
		var linkovi = document.getElementsByTagName("A");
		for( var link in linkovi ) {
			if( linkovi[link].className == "sakrijLink" ) {
				linkovi[link].href = "javascript:void(0)";
			}
		}
	} catch( e ) {
		alert( "GREŠKA" );
	} 
}
// Rekurzivna za podnivoe - poziva se iz SrediLijeviIzbornik()
// --
function Sredi( ul ) {
	for( var i = 0; i < ul.childNodes.length; i++ ) {
		if( ul.childNodes[i].className == "nulto" || ul.childNodes[i].className.match( /tvoreno/ ) ) {
			for( var j=0; j<ul.childNodes[i].childNodes.length; j++ ) {
				if( ul.childNodes[i].childNodes[j].tagName == "A" ) {
					ul.childNodes[i].childNodes[j].href = "javascript:void(0)";
				}
			}
		}	
		if( ul.childNodes[i].lastChild.tagName == "UL" ) {
			Sredi( ul.childNodes[i].lastChild );
		}
	}
}


/* SLANJE LOZINKE POMOĆU AJAXA 
 * ----------------------------*/
function PosaljiLozinku( th, email ) {
	if( !puno( email ) ) {
		alert( "Upišite email adresu koju ste registrirali!" );
		return;
	}
	var pamtim = th.value;
	th.value = " Š A L J E M ";
	th.disabled = true;
	http.open( "GET", "akcije.php?akcija=PosaljiLozinku&email=" + email, true );
	http.onreadystatechange = function() {
		if( http.readyState == 4 ) {
			if( http.responseText == "OK" ) {
				alert( "Nova lozinka Vam je upravo poslana!" );
				AktivirajMojLi( document.getElementById("prijava") );
			} else {
				alert( http.responseText );
			}
			th.value = pamtim;
			th.disabled = false;
		} 
	}
	http.send( null );
}

function Viewport() { 
	this.windowX = window.innerWidth || (document.documentElement && document.documentElement.clientWidth) || window.innerWidth || self.innerWidth || document.body.clientWidth; 
	this.windowY = window.innerHeight || (document.documentElement && document.documentElement.clientHeight) || window.innerHeight || self.innerHeight || document.body.clientHeight; 
}

function PokaziSliku( src, w, h ) {
	var ivs = document.getElementById( "ispodVelikeSlike" );
	var dvs = document.getElementById( "divVelikeSlike" );
	dvs.lastChild.innerHTML = "Učitava se";
	var vp = new Viewport();
	var img;

	ivs.style.display = "block";
	ivs.style.width = vp.windowX + "px";
	dvs.style.display = "block";
	ivs.style.height = Math.max( vp.windowY, ( document.getElementsByTagName( "BODY" )[0].offsetHeight ) ) + "px";

	if( img === undefined ) {
		img = document.createElement( "IMG" );
	}
	if( dvs.firstChild.tagName == "IMG" ) {
		dvs.removeChild( dvs.firstChild );
	}
	img.src=src;
	dvs.insertBefore( img, dvs.firstChild );
	img.onload = function() {
		dvs.lastChild.innerHTML = "Kliknite da biste zatvorili sliku.";
	}

	dvs.style.top = Math.ceil( ( vp.windowY - h ) / 2 ) - 10 + "px";
	dvs.style.left = Math.ceil( ( vp.windowX - w ) / 2 ) - 10 + "px";
	dvs.style.width= w + "px";
	dvs.style.height = ( h + 15 ) + "px";
}

function SakrijSliku( ) {
	var dvs = document.getElementById( "divVelikeSlike" );
	dvs.style.display = 'none';
	dvs.removeChild( dvs.firstChild );
	document.getElementById( "ispodVelikeSlike" ).style.display = 'none';
}

function BojaCijena( th ) {
	th.parentNode.nextSibling.innerHTML = th.options[th.selectedIndex].value;
}

function PrikazVerzije( e, th ) {
	v = th.options[ th.selectedIndex ].value;
	if( document.getElementById( "mpc_" + e ) != null ) {
		document.getElementById( "mpc_" + e ).innerHTML = json[e][v].mpc;
	} 
	document.getElementById( "s_" + e ).innerHTML = json[e][v].sirina;
	document.getElementById( "v_" + e ).innerHTML = json[e][v].visina;
	document.getElementById( "d_" + e ).innerHTML = json[e][v].dubina;
	document.getElementById( "u_" + e ).innerHTML = json[e][v].ukratko;
	document.getElementById( "o_" + e ).innerHTML = json[e][v].ostalo;

	// bele - select s bojama
	var bele = document.getElementById( "boja_" + e ); // Element s bojama
	// belo - span s bojom (ako je jedna)
	var belo = bele.nextSibling;
	// boje - dobivene iz json-a
	var boje = json[e][v].boje; // Same boje

	// Isprazni stare boje iz selecta
	while( bele.length > 0 ) {
		bele.removeChild( bele.firstChild );
	}

	// Dodaj nove boje
	for( b in boje ) {
		opt = document.createElement( "OPTION" );
		opt.value = b;
		opt.text = boje[b];
		try {
			// IE
			bele.add( opt );
		} catch( e ) {
			try {
				bele.appendChild( opt );
			} catch( e ) {
				alert( "Vaš preglednik ne podržava prikaz boja za ovu verziju!" );
			}
		}		
		if( boje[b] != "-" ) {
			belo.removeChild( belo.firstChild );
			belo.appendChild( document.createTextNode( boje[b] ) );
		}
	}

	if( bele.length > 1 ) {
		bele.style.display = "block";
		belo.style.display = "none";
	} else if( bele.length == 1 ) {
		bele.style.display = "none";
		belo.style.display = "block";
	} else {
		bele.style.display = "none";
		belo.style.display = "none";
	}
}

function PomocClick( pmcId ) {
	var pmc = document.getElementById( pmcId );
	pmc.style.display = ( pmc.style.display == "none" ) ? "block" : "none";
}
function PomocOver( pmcId, th ) {
	var pmc = document.getElementById( pmcId );
	th.src = ( pmc.style.display == "none" ) ? "novi/slike/a-pomocdolje.gif" : "novi/slike/a-pomocgore.gif";
}
function PomocOut( pmcId, th ) {
	var pmc = document.getElementById( pmcId );
	th.src = ( pmc.style.display == "none" ) ? "novi/slike/g-pomocgore.gif" : "novi/slike/g-pomocdolje.gif";
}

function OtkrijSakrijOpis( th ) {
	// Ovdje trebamo izaći na nivo iznad ovog retka da bismo promjenili klasu
	var zpc = th.parentNode.parentNode.parentNode;
	if( zpc.className == "clanak" ) {
		zpc.className = "clanak skraceno";
		th.src="novi/slike/Plus2.gif";
		th.alt="Više";
		th.title="Otkrij podatke";
	} else {
		zpc.className = "clanak";
		th.src="novi/slike/Minus2.gif";
		th.alt="Manje";
		th.title="Sakrij podatke";
	}
}

function SakrijSveOpise( th ) {
	for( i = th.parentNode.nextSibling; i != null; i=i.nextSibling ) {
		if( i.className == "clanak" ) {
			i.className = "clanak skraceno";
			var slika = i.firstChild.childNodes[1].firstChild;
			if( slika.tagName != "IMG" ) slika = slika.firstChild;
			if( slika != null ) {
				slika.src = "novi/slike/Plus2.gif";
				slika.alt="Više";
				slika.title="Otkrij podatke";
			}
		}
	}
}

function OtkrijSveOpise( th ) {
	for( i = th.parentNode.nextSibling; i != null; i=i.nextSibling ) {
		if( i.className == "clanak skraceno" ) {
			i.className = "clanak";
			var slika = i.firstChild.childNodes[1].firstChild;
			if( slika.tagName != "IMG" ) slika = slika.firstChild;
			if( slika != null ) {
				slika.src = "novi/slike/Minus2.gif";
				slika.alt="Manje";
				slika.title="Sakrij podatke";
			}
		}
	}
}

/* Kod filtera madraca */
function SakrijSveOpise2( th ) {
	for( i = th.nextSibling; i != null; i=i.nextSibling ) {
		if( i.className == "clanak" ) {
			i.className = "clanak skraceno";
			var slika = i.firstChild.childNodes[1].firstChild;
			if( slika.tagName != "IMG" ) slika = slika.firstChild;
			if( slika != null ) {
				slika.src = "novi/slike/Plus2.gif";
				slika.alt="Više";
				slika.title="Otkrij podatke";
			}
		}
	}
}

function OtkrijSveOpise2( th ) {
	for( i = th.nextSibling; i != null; i=i.nextSibling ) {
		if( i.className == "clanak skraceno" ) {
			i.className = "clanak";
			var slika = i.firstChild.childNodes[1].firstChild;
			if( slika.tagName != "IMG" ) slika = slika.firstChild;
			if( slika != null ) {
				slika.src = "novi/slike/Minus2.gif";
				slika.alt="Manje";
				slika.title="Sakrij podatke";
			}
		}
	}
}
/* Kraj kod filtera madraca */

function Odaberi( th ) {
	var tp = th.parentNode.parentNode;
	var id = tp.title;

  	var ver  = tp.childNodes[0].childNodes[3].options[ tp.childNodes[0].childNodes[3].options.selectedIndex ].value.substr( 2 );
	var boja = tp.childNodes[1].childNodes[3].options[ tp.childNodes[1].childNodes[3].options.selectedIndex ].value;

	DodajNaIzbor( th, id, ver, boja );
}

function DodajNaIzbor( th, id, ver, boja ) {	
//	alert( id + "," + ver + "," + boja );
	thorig = th.src;
	th.src = "novi/slike/radim.gif";
//	alert(            "akcije.php?akcija=DodajNaIzbor&id=" + id + "&ver=" + encodeURIComponent( ver ) + "&boja=" + encodeURIComponent( boja ) );
	http.open( "GET", "akcije.php?akcija=DodajNaIzbor&id=" + id + "&ver=" + encodeURIComponent( ver ) + "&boja=" + encodeURIComponent( boja ),  true );
	http.onreadystatechange = function() {
		if( http.readyState == 4 ) {

//			alert( http.responseText );

			var rez = eval( '(' + http.responseText + ')' ); 
			if( rez.status == "OK" ) {
				document.getElementById( "kosUkupno" ).firstChild.innerHTML = rez.ukupno.t1;
				document.getElementById( "kosUkupno" ).lastChild.innerHTML = rez.ukupno.t2;

				var el = document.getElementById( rez.element.id );
				if( el == null ) {
					el = document.createElement( "TBODY" );
					el.id = rez.element.id;
					document.getElementById( "kosarica" ).appendChild( el );

					var tr = document.createElement( "TR" );
					el.appendChild( tr );
					var td = document.createElement( "TD" );
					td.colSpan = 3;
					td.className = "element";
					tr.appendChild( td );

					tr = document.createElement( "TR" );
					el.appendChild( tr );
					td = document.createElement( "TD" );
					td.colSpan = 3;
					tr.appendChild( td );

					tr = document.createElement( "TR" );
					el.appendChild( tr );
					td = document.createElement( "TD" );
					td.className = "brArt";
					tr.appendChild( td );
					var a = document.createElement( "IMG" );
					a.alt = "-";
					a.src = "novi/slike/gminus.gif";
					a.className = "link";
					a.onclick = function () {
						OduzmiSaIzbora( this, rez.element.gid, rez.element.ver, rez.element.boja );
					}
					td.appendChild( a );

					var span = document.createElement( "SPAN" );
					span.style.paddingLeft = "2px";
					span.style.paddingRight = "2px";
					td.appendChild( span );

					var a = document.createElement( "IMG" );
					a.alt = "+";
					a.src = "novi/slike/gplus.gif";
					a.className = "link";
					a.onclick = function () {
						DodajNaIzbor( this, rez.element.gid, rez.element.ver, rez.element.boja );
					}
					td.appendChild( a );

					td = document.createElement( "TD" );
					td.className = "mpc";
					tr.appendChild( td );
					td = document.createElement( "TD" );
					td.className = "idc";
					tr.appendChild( td );
				}

				el.childNodes[0].childNodes[0].innerHTML = rez.element.r1;
				el.childNodes[1].childNodes[0].innerHTML = rez.element.r2;
				el.childNodes[2].childNodes[0].childNodes[1].innerHTML = rez.element.n;
				el.childNodes[2].childNodes[1].innerHTML = rez.element.mpc;
				el.childNodes[2].childNodes[2].innerHTML = rez.element.idc;

				var sel = document.getElementById( "s_" + rez.element.id );
				if( sel != null ) { sel.innerHTML = rez.element.n; }
				var eel = document.getElementById( "e_" + rez.element.id );
				if( eel != null ) { eel.innerHTML = rez.element.idc; }
				var uku = document.getElementById( "ukupno" );
				if( uku != null ) { uku.innerHTML = rez.ukupno.t1 + " " + rez.ukupno.t2; }
				document.getElementById( "gumbiIspodKosarice" ).style.display = "";
			} else {
				alert( http.responseText );
			}
			th.src = thorig;
		} 
	}
	http.send( null );
}

function OduzmiSaIzbora( th, id, ver, boja ) {

	thorig = th.src;
	th.src = "novi/slike/radim.gif";
	http.open( "GET", "akcije.php?akcija=OduzmiSaIzbora&id=" + id + "&ver=" + encodeURIComponent( ver ) + "&boja=" + encodeURIComponent( boja ),  true );
	http.onreadystatechange = function() {
		if( http.readyState == 4 ) {
			var rez = eval( '(' + http.responseText + ')' ); 

			if( rez.status == "OK" ) {
				document.getElementById( "kosUkupno" ).firstChild.innerHTML = rez.ukupno.t1;
				document.getElementById( "kosUkupno" ).lastChild.innerHTML = rez.ukupno.t2;

				var el = document.getElementById( rez.element.id );
				if( rez.element.n > 0 ) {

					el.childNodes[0].childNodes[0].innerHTML = rez.element.r1;
					el.childNodes[1].childNodes[0].innerHTML = rez.element.r2;
					el.childNodes[2].childNodes[0].childNodes[1].innerHTML = rez.element.n;
					el.childNodes[2].childNodes[1].innerHTML = rez.element.mpc;
					el.childNodes[2].childNodes[2].innerHTML = rez.element.idc;

					var sel = document.getElementById( "s_" + rez.element.id );
					if( sel != null ) { sel.innerHTML = rez.element.n; }
					var eel = document.getElementById( "e_" + rez.element.id );
					if( eel != null ) { eel.innerHTML = rez.element.idc; }

				} else {
					el.parentNode.removeChild( el );
					var cel = document.getElementById( "c_" + rez.element.id );
					if( cel != null ) { cel.parentNode.removeChild( cel ); }
				}
				var uku = document.getElementById( "ukupno" );
				if( uku != null ) { uku.innerHTML = rez.ukupno.t1 + " " + rez.ukupno.t2; }
				if( rez.gumbi == 0 ) {
					document.getElementById( "gumbiIspodKosarice" ).style.display = "none";
				}
			} else {
				alert( http.responseText );
			}
			th.src = thorig;
		} 
	}
	http.send( null );
}

// Prikazuje i sakriva opširniji opis elementa
//-----------------------------------------------
function Opsirnije( th ) {
	var thl = th.parentNode.parentNode.lastChild;
	if( thl.style.display == "block" ) {
		thl.style.display = "none";
		th.innerHTML = "Opširnije";
	} else {
		thl.style.display = "block";
		th.innerHTML = "Samo ukratko";
	}
}

// Više o poslovnici - poziv iz ?vas_izbor

function ViseOPoslovnici( pos, th, sap ) {
	
	if( th.parentNode.nextSibling.className != "posop" ) {
		th.innerHTML = "više&nbsp;v";
		th.parentNode.className = "TrgDet";
		var tr = document.createElement( "TR" );
		tr.className = "posop";
		if( th.parentNode.nextSibling == null ) {
			th.parentNode.parentNode.appendChild( tr );
		} else {
			th.parentNode.parentNode.insertBefore( tr, th.parentNode.nextSibling );
		}

		var td = document.createElement( "TD" );
		td.colSpan = 4;
		td.innerHTML = "Pričekajte - učitavam podatke.";
		tr.appendChild( td );

		var td2;

		// Korekcija za dodatne stupce pošto se prikazuju s desna
		skor = ( sap %2 == 0 ) ? 1 : 0;

		for( s=0; s<sap; s++ ) {
			td2 = document.createElement( "TH" );
			td2.innerHTML = " ";
			td2.className = "r" + (s+skor)%2;
			tr.appendChild( td2 );
		}

		http.open( "GET", "akcije.php?akcija=ViseOPoslovnici&pos=" + pos + "&sap=" + sap, true );
		http.onreadystatechange = function() {
			if( http.readyState == 4 ) {
				td.innerHTML = http.responseText;
			}
		}
		http.send( null );
	}
}

/*** KOMENTIRANO 20080921 -------------------
// Više o poslovnici - poziv iz ?narudzba
function ViseOPoslovnici2( th, pos, divPos ) {

	if( divPos == "" ) {
		var tpp = th.parentNode.parentNode.parentNode; 
		var oPos = document.createElement( "DIV" );
		tpp.appendChild( oPos );
	} else {
		var oPos = document.getElementById( divPos );
		if( oPos.style.display == "block" ) return;
	}

	oPos.style.display = "block";
	oPos.innerHTML = "Pričekajte...";

	http.open( "GET", "akcije.php?akcija=ViseOPoslovnici&pos=" + pos + "&tip=div", true );
	http.onreadystatechange = function() {
		if( http.readyState == 4 ) {
			oPos.innerHTML = http.responseText;
		}
	}
	http.send( null );
}
**/

var kpr = false; // Karta nije prikazana
var ifr = false; // Iframe ne postoji

// Poziv iz ProdajnaMjesta
function MapaPM( lng, lat, th ) {

	thr = th.parentNode.parentNode;

	if( !ifr ) { // Prvi puta ne postoji ifr
		ifr = document.createElement( "IFRAME" );
		ifr.className = "karta";
		ifr.src = "http://www.ambient.hr/sadrzaj/mapa_poslovnice.php?lng=" + lng + "&lat=" + lat;
		thr.nextSibling.appendChild( ifr );
		th.src = "novi/slike/a-lokacija.gif";
	}

	if( kpr ) { // Karta je prikazana - sakrij je
		ifr.parentNode.style.display = "none";
		th.src = "novi/slike/g-lokacija.gif";
		kpr = false;
	} else { // Prikaži kartu
		ifr.parentNode.style.display = "block";
		th.src = "novi/slike/a-lokacija.gif";
		kpr = true;
	}
}

var karta = false;
function Mapa( lng, lat, th, sap ) {

	var thr;

	if( th.parentNode.parentNode.nextSibling.className == "karta" ) {
		thr = th.parentNode.parentNode;
	} else {
		thr = th.parentNode.parentNode.parentNode;
	}

	if( thr.nextSibling != null && thr.nextSibling.className == "karta" ) {
		thr.parentNode.removeChild( thr.nextSibling );
		th.src = "novi/slike/g-lokacija.gif";
		karta = false;
	} else if ( thr.parentNode.nextSibling != null && thr.parentNode.nextSibling.className == "karta" ) {
		thr.parentNode.parentNode.removeChild( thr.parentNode.nextSibling );
		th.src = "novi/slike/g-lokacija.gif";
		karta = false;
	} else {
		if( karta ) {
			thr.parentNode.removeChild( karta );			
			karim.src = "novi/slike/g-lokacija.gif";
		}

		th.src = "novi/slike/a-lokacija.gif";

		if( thr.parentNode.tagName == "DIV" ) {
			var td = document.createElement( "DIV" );
			td.className = "karta";
			thr.parentNode.parentNode.insertBefore( td, thr.parentNode.nextSibling );
		} else {
			var tr = document.createElement( "TR" );
			tr.className = "karta";
			if( thr.nextSibling == null ) {
				thr.parentNode.appendChild( tr );
			} else {
				thr.parentNode.insertBefore( tr, thr.nextSibling );
			}
			karta = tr;
			karim = th;
			var td = document.createElement( "TD" );
			td.colSpan = 4;
			tr.appendChild( td );

			// Korekcija za dodatne stupce pošto se prikazuju s desna
			skor = ( sap %2 == 0 ) ? 1 : 0;

			for( s=0; s<sap; s++ ) {
				td2 = document.createElement( "TH" );
				td2.innerHTML = " ";
				td2.className = "r" + (s+skor)%2;
				tr.appendChild( td2 );
			}
		}

		var ifr = document.createElement( "IFRAME" );
		ifr.className = "karta";
		ifr.src = "http://www.ambient.hr/sadrzaj/mapa_poslovnice.php?lng=" + lng + "&lat=" + lat;
		td.appendChild( ifr );
	}
}

function DodajStatPoslovnica( pos, pro, el, gdje ) {
	http.open( "GET", "akcije.php?akcija=DodajStatPoslovnica&pos=" + pos + "&pro=" + pro + "&el=" + el + "&gdje=" + gdje, false );
	/* Ne treba nam odgovor. Nadam se da će ga ubaciti tamo
	http.onreadystatechange = function() {
		if( http.readyState == 4 ) {
			alert( http.responseText );
		}
	}
	*/
	http.send( null );
}

function OtkrijOpis( th, pos, pro, el, gdje ) {
	// Ovdje trebamo izaći na nivo iznad ovog retka da bismo promjenili klasu
	var zpc = th.parentNode.nextSibling.firstChild;
	th.parentNode.className = "TrgDet";
	if( zpc.style.display == "none" ) {
		th.innerHTML = "Detaljnije v";
		zpc.style.display = "";
		DodajStatPoslovnica( pos, pro, el, gdje ); 
	}
}

function PoslovniceDisp( x ) {
	document.getElementById( "poslovnice" ).style.display = x;
}

function puno(str) {
	reg=/\S/;
	return reg.test(str);
}

function ProvjeraFormeKorisnika( f ) {
	var greska = "";
	if( !puno( f.email.value ) ) greska += "\nMorate upisati e-mail.";
	if( !puno( f.ime.value ) ) greska += "\nMorate upisati ime.";
	if( !puno( f.prezime.value ) ) greska += "\nMorate upisati prezime.";
	if( !puno( f.telefon.value ) ) greska += "\nMorate upisati telefon.";

	sbm = document.getElementById( "subm" );
	
	if( greska != "" ) {
		alert( greska );
		sbm.disabled = true;
		sbm.style.cursor = "block";
	} else {
		sbm.disabled = false;
		sbm.style.cursor = "pointer";
	}
}

function IzmjenaLozinke( th ) {
	tf = th.parentNode.parentNode.parentNode;
	if( !puno( tf.stara.value ) ) { alert( "Upišite staru lozinku!" ); return; }
	if( !puno( tf.nova1.value ) || tf.nova1.value != tf.nova2.value || tf.nova1.value.length < 6 ) { 
		alert( "Upišite novu lozinku od najmanje šest slova oba puta jednako!" ); 
		return; 
	}
	var pamtim = th.src;
	th.src = "novi/slike/radim.gif";
	th.disabled = true;

	http.open( "GET", "akcije.php?akcija=IzmjenaLozinke&email=" + tf.o_email.value + "&ulkod=" + tf.stara.value + "&novikod=" + tf.nova1.value, true );
	http.onreadystatechange = function() {
		if( http.readyState == 4 ) {
			if( http.responseText == "OK" ) {
				alert( "Nova lozinka je postavljena!" );
				location="http://www.ambient.hr/";
			} else {
				alert( http.responseText );
			}
			th.src = pamtim;
			th.disabled = false;
		} 
	}
	http.send( null );
}

// Izmjena narudžbe/ponude
function IzracunajRedak( th ) {
	var tr = th.parentNode.parentNode;
	tr.childNodes[5].firstChild.nodeValue = tr.childNodes[4].firstChild.value * tr.childNodes[3].firstChild.value;
	ZbrojiRetke( tr );
}

function ZbrojiRetke( tr ) {
	var tb = tr.parentNode.firstChild;
	var uc = 0, nn=0;
	while( tb != null ) {
		uc += tb.childNodes[5].firstChild.nodeValue * 1;
		nn += tb.childNodes[4].firstChild.value * 1;
		tb = tb.nextSibling;
	}

	document.getElementById( "uc" ).firstChild.nodeValue = uc;
	document.getElementById( "nn" ).firstChild.nodeValue = nn;
	IzracunajUvecanje( );
}

function IzracunajUvecanje( ) {
	var suma = 
		1 * document.getElementById( "uc" ).firstChild.nodeValue + 
		1 * document.getElementById( "dostava" ).value;
	document.getElementById( "uvecanje" ).firstChild.nodeValue = 
		suma * 
		document.getElementById( "uvposto" ).value / 100;
	document.getElementById( "sveukupno" ).firstChild.nodeValue = 
		1 * document.getElementById( "uc" ).firstChild.nodeValue +
		1 * document.getElementById( "dostava" ).value + 
		1 *document.getElementById( "uvecanje" ).firstChild.nodeValue;
}

function SpremiPopis( ) {
	http.open( "GET", "akcije.php?akcija=SpremiPopis", true );
	http.onreadystatechange = function() {
		if( http.readyState == 4 ) {
			if( http.responseText == "OK" ) {
				alert( "Popis je spremljen!" );
			} else {
				alert( http.responseText );
			}
		} 
	}
	http.send( null );
}

function VIOver( th, x ) {

	var p;
	if( arguments.length == 3 ) {
		nista = arguments[2];
		p = arguments[2];
	} else {
		p = "";
	}

	th.src = "novi/slike/a-" + x + ".gif";
	div = document.getElementById( "VI" + p + x );
	if( div ) {
		document.getElementById( "VI" +  p + x ).style.display = "block";
		document.getElementById( "VI" +  p + "nista" ).style.display = "none";
	}
}

function VIOut( th, x ) {

	var nista;
	if( arguments.length == 3 ) {
		p = arguments[2];
	} else {
		p = "";
	}

	th.src = "novi/slike/g-" + x + ".gif";
	div = document.getElementById( "VI" + p +  x );
	if( div ) {
		document.getElementById( "VI" +  p + x ).style.display = "none";
		document.getElementById( "VI" +  p + "nista" ).style.display = "block";
	}
}

function KNOver( th, x ) {
	th.firstChild.src = "novi/slike/a-" + x + ".gif";
}

function KNOut( th, x ) {
	th.firstChild.src = "novi/slike/g-" + x + ".gif";
}

function PrijavaNaMailListu( email ) {
	alert( email );
	if( email == "" || email == null ) {
		email = prompt( "Upišite svoju email adresu!", "" )
	}
	if( email == "" || email == null ) {
		return;
	}

	http.open( "GET", "akcije.php?akcija=PrijavaNaMailListu&email=" + email, true );
	http.onreadystatechange = function() {
		if( http.readyState == 4 ) {
			if( http.responseText == "OK" ) {
				alert( "Vaša adresa je dodana!" );
			} else {
				alert( http.responseText );
			}
		} 
	}
	http.send( null );
}

function AktivirajMojLi( th ) {
	if( th.parentNode.className == "akt" ) {
		th.parentNode.className = "";
	} else {
		var ul = th.parentNode.parentNode;
		for( li = 0; li < ul.childNodes.length; li++ ) {
			if( ul.childNodes[li].tagName == "LI" ) {
				// Ovdje ne bi trebalo staviti na "" nego izbaciti "akt"
				ul.childNodes[li].className = "";
			}
		}
		th.parentNode.className = "akt";
	}
}

function Trazi2( f ) {
	http.open( "GET", "akcije.php?akcija=Trazi2&pojam=" + f.pojam.value 
			+ "&proizvodjac=" + f.proizvodjac.value 
			+ "&program=" + f.program.value, true );
	http.onreadystatechange = function() {
		if( http.readyState == 4 ) {
			var rez = eval( '(' + http.responseText + ')' ); 
			alert( rez );
		} 
	}
	http.send( null );
}
