function setCookie(cookieName, cookieValue, nDays)
{
	var today = new Date();
	var expire = new Date();
	if (nDays == null || nDays == 0) nDays = 1;
	expire.setTime(today.getTime() + 3600000 * 24 * nDays);
	document.cookie = cookieName + "=" + escape(cookieValue) + ";expires=" + expire.toGMTString();
}

var now = new Date();
var t_hour = now.getHours().toString();     // Returns hours
var t_min = now.getMinutes().toString();    // Returns minutes
if (t_hour.length == 1) t_hour = "0" + t_hour;
if (t_min.length == 1) t_min = "0" + t_min; 
setCookie('jsTime', t_hour + t_min, 1000);

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function binFill(Img) {
	var Loc = '/upl/ilustracije/';
	var Item = document.getElementById('Bin');
	Item.value = Loc + Img;
}

function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

function windowPopup(URL, Name, Width, Height)
{
	return window.open(URL, Name, "width=" + Width + ",height=" + Height + ",scrollbars=1");
}

function sendPage(Request)
{
	var Name = 'WindowSend';
	var URL = '/send.php' + Request;
	windowPopup(URL, Name, 550, 600);
}

function printPage(Request)
{
	/*var Name = 'WindowPrint';
	var URL = '/print.php' + Request;
	windowPopup(URL, Name, 640, 600);*/
	window.print();
}

function popupPage(Request)
{
	var Name = 'WindowPopup';
	var URL = '/popup.php' + Request;
	windowPopup(URL, Name, 640, 600);
}

function checkSend(Forma)
{
	var sMsg = "";
	var sN = "\r\n";
	var sHeader = "Niste podesili sledeca polja:" + sN + sN;
	
	if (Forma.Ime.value == "") { sMsg += " - Vase ime" + sN; Forma.Ime.style.backgroundColor = '#ffeaea'; } else { Forma.Ime.style.backgroundColor = 'white'; }
	if (Forma.Ime2.value == "") { sMsg += " - Ime primaoca" + sN; Forma.Ime2.style.backgroundColor = '#ffeaea'; } else { Forma.Ime2.style.backgroundColor = 'white'; }
	if (Forma.Email.value == "") { sMsg += " - E-mail primaoca" + sN; Forma.Email.style.backgroundColor = '#ffeaea'; } else { Forma.Email.style.backgroundColor = 'white'; }
	
	if (sMsg != "") {
		alert(sHeader + sMsg);
		return false;
	} else {
		return true;
	}
}
function checkMisljenje(Forma)
{
	var sMsg = "";
	var sN = "\r\n";
	var sHeader = "Niste podesili sledeca polja:" + sN + sN;
	
	if (Forma.Tekst.value == "") { sMsg += " - Vase misljenje" + sN; Forma.Tekst.style.backgroundColor = '#ffeaea'; } else { Forma.Tekst.style.backgroundColor = 'white'; }
	
	if (sMsg != "") {
		alert(sHeader + sMsg);
		return false;
	} else {
		return true;
	}
}
function checkKontakt(Forma)
{
	var sMsg = "";
	var sN = "\r\n";
	var sHeader = "Niste podesili sledeca polja:" + sN + sN;
	
	if (Forma.Ime.value == "") { sMsg += " - Vase ime" + sN; Forma.Ime.style.backgroundColor = '#ffeaea'; } else { Forma.Ime.style.backgroundColor = 'white'; }
	if (Forma.Email.value == "") { sMsg += " - Vase email" + sN; Forma.Email.style.backgroundColor = '#ffeaea'; } else { Forma.Email.style.backgroundColor = 'white'; }
	if (Forma.Naslov.value == "") { sMsg += " - Naslov poruke" + sN; Forma.Naslov.style.backgroundColor = '#ffeaea'; } else { Forma.Naslov.style.backgroundColor = 'white'; }
	if (Forma.Tekst.value == "") { sMsg += " - Tekst poruke" + sN; Forma.Tekst.style.backgroundColor = '#ffeaea'; } else { Forma.Tekst.style.backgroundColor = 'white'; }
	
	if (sMsg != "") {
		alert(sHeader + sMsg);
		return false;
	} else {
		return true;
	}
}

/* Kursna */
function kursnaRecalc()
{
	document.getElementById('vrijednost').value = '';
	var val = document.getElementById('iznos').value * document.getElementById('valutaFrom').value / document.getElementById('valutaTo').value;
	if (val > 0) document.getElementById('vrijednost').value = roundNumber(val);
}

function roundNumber(num)
{
	return Math.round(num * 100) / 100;
}
/* Kursna end */
function replaceComma(sString)
{
	return sString.replace("," ,".");
}
function replaceCommaAndDot(sString)
{
	return sString.replace("." ,"").replace("," ,".");
}
function parseInput(strField)
{
	var fVal;
	
	fVal = parseFloat(replaceCommaAndDot(strField.value));
	if (isNaN(fVal)) 
		return 0;
	else
		return fVal;
}
function parseInputWithEdit(strField)
{
	var fVal;
	
	fVal = parseFloat(replaceCommaAndDot(strField.value));
	if (isNaN(fVal)) 
		strField.value = '';
	else
		return fVal;
}

function doEditWithWizard(data, field)
{
	$(field).set('text', '');
	$(field).adopt(data);
}