﻿/* spustni meniji */
var timeout = 500;
var closetimer = 0;
var menuitem = 0;

function MenuOpen(id) {
	CancelTimer();
	MenuClose();
	menuitem = $('#menu').find('#' + id).css('display', 'block');
}

function MenuClose() {
	if(menuitem) menuitem.css('display', 'none');
}

function Timer(id) {
	closetimer = window.setTimeout(MenuClose, timeout);
}

function CancelTimer() {
	if(closetimer) {
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

/* preverjanje vnosnih polj */
function isEmpty(input, msg)
{
	if (input.value.length == 0)
	{
		alert(msg)
		input.focus()
		return false
	} 
	return true
}

function checkDeposit(amount, deposit, msg)
{
	if (besedilo.value.length == 0)
	{
		alert(msg)
		besedilo.focus()
		return false
	} 
	return true
}


function isEmail(input, msg)
{
	if (input.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	else
	{
		alert(msg);
		input.focus();
		return false;
	}
}

function isMoreThanMax(input, msg) {
	var num = input.value.replace(/\./g,"");
	var inputval = parseFloat(num.replace(",", "."));
	if ((!(isNaN(inputval))) && inputval <= 50000)
		return true;
	else
	{
		alert(msg);
		input.focus();
		return false;
	}
}


function isSelected(radio, msg)
{
  blnOK = false
  for (var intIndex = 0; intIndex < radio.length; intIndex++)
  {
    if (radio[intIndex].checked)
    {
      blnOK = true
    }
  }
  if (blnOK)
  {
    return true
  }
  else
  {
    alert(msg)
    return false
  }
}

/* spustni meniji */
var timeout    = 500;
var closetimer = 0;
var menuitem = 0;

function Share(id) {
	CancelTimer();
	MenuClose();
	menuitem = $('#menu').find('#' + id).css('display', 'block');
}

function MenuClose() {
	if(menuitem) menuitem.css('display', 'none');
}

function Timer(id) {
	closetimer = window.setTimeout(MenuClose, timeout);
}

function CancelTimer() {
	if(closetimer) {
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}
	 
$(document).ready(function() {
	/* prikazovanje/skrivanje vsebine */
	$('#content .faq a').click( function() {
		var id = $(this).attr('id');
		$('#content .faq div#answer' + id).toggle();
	});
	/* prikaz galerije */
	$(function() {
		$('#content .gallery a').lightBox({
			fixedNavigation: true,
			overlayBgColor: '#000',
			overlayOpacity: 0.75
		});
	});	
});

function FormatMoney(input)
{
    input.value = fmtMoney(MoneyToFloat2(input.value));
    return;
}

//@ http://jsfromhell.com/number/fmt-money [v1.0]
function fmtMoney(n, c, d, t){ //v1.0
    var m = (c = Math.abs(c) + 1 ? c : 2, d = d || ",", t = t || ".",
        /(\d+)(?:(\.\d+)|)/.exec(n + "")), x = m[1].length > 3 ? m[1].length % 3 : 0;
    return (x ? m[1].substr(0, x) + t : "") + m[1].substr(x).replace(/(\d{3})(?=\d)/g,
        "$1" + t) + (c ? d + (+m[2] || 0).toFixed(c).substr(2) : "");
}
 
function MoneyToFloat2(input)
{
  var strMoney, intMoneyLength, intIndex, strInteger;

  strMoney = new String(input);
  intIndex = 0;
  while (strMoney.substring(intIndex, intIndex+1) == '0') {intIndex++};

  intMoneyLength = strMoney.length;
  strMoney = strMoney.substring(intIndex, intMoneyLength);

  strInteger = new String("");
  intFracIndex = intMoneyLength;
  for (intIndex=0; intIndex<intMoneyLength; intIndex++)
  {
    if (strMoney.substring(intIndex,intIndex+1) == ".")
    {
      continue
    };
    if (strMoney.substring(intIndex,intIndex+1) == ",")
    {
      intFracIndex = intIndex + 1;
      break;
    };
    strInteger += strMoney.substring(intIndex,intIndex+1);
  }
  if (strInteger.length == 0) 
  {
    strInteger = "0";
  }
  
  strFrac = new String("");
  for (intIndex = intFracIndex; ((intIndex < intMoneyLength) && (intIndex < intIndex + 2)); intIndex++)
  {
    strFrac += strMoney.substring(intIndex, intIndex+1);
  }
  if (strFrac.length == 0) 
  {
    strFrac = "0";
  }

  if (isNaN(strInteger) || isNaN(strFrac))
  {
    return 0;
  }
  else
  {
    return strInteger + "." + strFrac;
  }	
}
