function checkLang()
{
var mess="";
var lang=document.nolang.lang.value;
if(document.nolang.ime.value=="")
	mess="Ime in priimek??\n";

var email=document.nolang.email.value;	
mess+=valEmail(email);

if(mess!=="OK")
	alert(mess);
else{		
	document.nolang.action="index.php?action=nolang&lang="+lang+"&k=1";
	document.nolang.submit();
}	
}

function izbor_jezika()
{
	var sel=document.getElementById("jezik");
	var lang=sel.options[sel.selectedIndex].value;
	switch(lang){
		case 'hr':
			window.location="http://www.molbaonline.com";
			break;
		default:	
			window.location="index.php?action=nolang&lang="+lang;
			break;
	}

}

function mapa(windowURL){
	var sirina  = 440;
	var visina  = 440;
	
	var leftpos = (screen.width - sirina)/2;
	var toppos  = (screen.height - visina)/2;
	
	return window.open(windowURL,'','width='+sirina+',height='+visina+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,top='+toppos+',left='+leftpos+'')
}

function oknonew(windowURL){
    var nWindow = window;

    nWindow = window.open(windowURL);
    nWindow.blur();
}

function okno(windowURL){
	var sirina  = 520;
	var visina  = 520;

	var leftpos = (screen.width - sirina)/2;
	var toppos  = (screen.height - visina)/2;
    var nWindow = window;

      nWindow = window.open(windowURL,'','width='+sirina+',height='+visina+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,hscrollbar=no,resizable=yes,copyhistory=no,top='+toppos+',left='+leftpos+'');
	  nWindow.blur();
}

function okno1(windowURL){
  var sirina  = 400;
  var visina  = 560;

  var leftpos = (screen.width - sirina)/2;
  var toppos  = (screen.height - visina)/2;
    var nWindow = window;

      nWindow = window.open(windowURL,'','width='+sirina+',height='+visina+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,hscrollbar=no,resizable=yes,copyhistory=no,top='+toppos+',left='+leftpos+'');
    nWindow.focus();
}

function korak(windowURL){
	var sirina  = 400;
	var visina  = 220;

	var leftpos = (screen.width - sirina)/2;
	var toppos  = (screen.height - visina)/2;

	return window.open(windowURL,'','width='+sirina+',height='+visina+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,hscrollbar=no,resizable=yes,copyhistory=no,top='+toppos+',left='+leftpos+'')
	korak.focus()
}

function cc(windowURL){
	var sirina  = 500;
	var visina  = 450;

	var leftpos = (screen.width - sirina)/2;
	var toppos  = (screen.height - visina)/2;
	
	return window.open(windowURL,'','width='+sirina+',height='+visina+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,hscrollbar=no,resizable=yes,copyhistory=no,top='+toppos+',left='+leftpos+'')
	cc.focus()
}

function redirect(windowURLa,windowURLb)
{
  if(windowURLa == windowURLb)
    window.location=windowURLa;
  else
  {
    if(document.naroci["formula"].checked)
      window.location=windowURLb;
    else
      window.location=windowURLa;
  }
}

function emoneta(izbira)
{
  if(izbira == "PlatinumPopust")
  {
    if(document.naroci["formula"].checked)
    {
      document.naroci.action="index.php?action=moneta&what=PlatinumPopustFormula";
      document.naroci.submit();
    }
    else
    {
      document.naroci.action="index.php?action=moneta&what=PlatinumPopust";
      document.naroci.submit();
    }
  }
  else if(izbira == "RegularPopust")
  {
    if(document.naroci["formula"].checked)
    {
      document.naroci.action="index.php?action=moneta&what=RegularPopustFormula";
    }
    else
    {
      document.naroci.action="index.php?action=moneta&what=RegularPopust";
    }
  }
  else if(izbira == "Regular48")
  {
    if(document.naroci["formula"].checked)
    {
      document.naroci.action="index.php?action=moneta&what=RegularFormula48";
    }
    else
    {
      document.naroci.action="index.php?action=moneta&what=Regular48";
    }
  }
  else if(izbira == "Platinum48")
  {
    if(document.naroci["formula"].checked)
    {
      document.naroci.action="index.php?action=moneta&what=PlatinumFormula48";
    }
    else
    {
      document.naroci.action="index.php?action=moneta&what=Platinum48";
    }
  }
  else if(izbira == "Platinum")
  {
    if(document.naroci["formula"].checked)
    {
      document.naroci.action="index.php?action=moneta&what=PlatinumFormula";
    }
    else
    {
      document.naroci.action="index.php?action=moneta&what=Platinum";
    }
  }
  else if(izbira == "Regular")
  {
    if(document.naroci["formula"].checked)
    {
      document.naroci.action="index.php?action=moneta&what=RegularFormula";
    }
    else
    {
      document.naroci.action="index.php?action=moneta&what=Regular";
    }
  }

  document.naroci.submit();
}

function ponovi_vnos(what)
{
  if(!document.check.confirmationID)
  {
    document.check.action="index.php?action=formular&ukaz=" + what;
    document.check.submit();
  }
  else
  {
    document.check.action="index.php?action=moneta&what=" + what;
    document.check.submit();
  }
}

function open_formula()
{
  window.location=mesecnik1.bonus1.options[mesecnik1.bonus1.selectedIndex].value;
}

function open_formula1()
{
  window.location=mesecnik2.bonus2.options[mesecnik2.bonus2.selectedIndex].value;
}

function preview()
{
document.save.action="index.php?action=predogled&ukaz=zahteven";
actualize();
document.save.submit();
}

function refresh()
{
  alert("POZOR! Da ne bi izgubili teksta, ki ste ga sestavili, \n\nprosim, da obvezno kliknite na gumb OK - hvala!");
  actualize();
  document.save.submit();
}

function trim(str)
{
  var start = 0;
  var end = str.length;

  for(i = 0; i < str.length; i++)
  {
    if(str.charAt(i) == " ")
      start++;
    else
      break;
  }
  for(i = str.length-1; i >= 0; i--)
  {
    if(str.charAt(i) == " ")
      end--;
    else
      break;
  }

  if(end == 0)
    start = 0;
  str = str.substring(start,end);

  return str;
}

function valEmail(emailStr)
{
  /* The following variable tells the rest of the function whether or not
  to verify that the address ends in a two-letter country or well-known
  TLD.  1 means check it, 0 means don't. */
  var checkTLD=1;

  /* The following is the list of known TLDs that an e-mail address must end with. */
  var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

  /* The following pattern is used to check if the entered e-mail address
  fits the user@domain format.  It also is used to separate the username
  from the domain. */
  var emailPat=/^(.+)@(.+)$/;

  /* The following string represents the pattern for matching all special
  characters.  We don't want to allow special characters in the address.
  These characters include ( ) < > @ , ; : \ " . [ ] */
  var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

  /* The following string represents the range of characters allowed in a
  username or domainname.  It really states which chars aren't allowed.*/
  var validChars="\[^\\s" + specialChars + "\]";

  /* The following pattern applies if the "user" is a quoted string (in
  which case, there are no rules about which characters are allowed
  and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
  is a legal e-mail address. */
  var quotedUser="(\"[^\"]*\")";

  /* The following pattern applies for domains that are IP addresses,
  rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
  e-mail address. NOTE: The square brackets are required. */
  var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

  /* The following string represents an atom (basically a series of non-special characters.) */
  var atom=validChars + '+';

  /* The following string represents one word in the typical username.
  For example, in john.doe@somewhere.com, john and doe are words.
  Basically, a word is either an atom or quoted string. */
  var word="(" + atom + "|" + quotedUser + ")";

  // The following pattern describes the structure of the user
  var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

  /* The following pattern describes the structure of a normal symbolic
  domain, as opposed to ipDomainPat, shown above. */
  var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");


  /* Finally, let's start trying to figure out if the supplied address is valid. */


  /* Begin with the coarse pattern to simply break up user@domain into
  different pieces that are easy to analyze. */
  var matchArray=emailStr.match(emailPat);
  if (matchArray == null)
  {
    /* Too many/few @'s or something; basically, this address doesn't
    even fit the general mould of a valid e-mail address. */
    error = "Napačen E-mail (preverite @ in pike)";
    return error;
  }

  var user=matchArray[1];
  var domain=matchArray[2];

  // Start by checking that only basic ASCII characters are in the strings (0-127).
  for (i=0; i < user.length; i++)
  {
    if (user.charCodeAt(i) > 127)
    {
      error = "Napačen E-mail (preverite del pred @)";
      return error;
    }
  }
  for (i=0; i < domain.length; i++)
  {
    if (domain.charCodeAt(i)>127)
    {
      error = "Napačen E-mail (preverite del za @)";
      return error;
    }
  }

  // See if "user" is valid
  if (user.match(userPat)==null)
  {
    // user is not valid
    error = "Napačen E-mail (preverite del pred @)";
    return error;
  }

  /* if the e-mail address is at an IP address (as opposed to a symbolic
  host name) make sure the IP address is valid. */
  var IPArray=domain.match(ipDomainPat);
  if (IPArray != null)
  {
    // this is an IP address
    for (var i=1;i <= 4;i++)
    {
      if (IPArray[i]>255)
      {
        error = "Napačen E-mail (ciljni IP je nepravilen)";
        return error;
      }
    }
    return true;
  }

  // Domain is symbolic name.  Check if it's valid.
  var atomPat=new RegExp("^" + atom + "$");
  var domArr=domain.split(".");
  var len=domArr.length;
  for (i=0;i<len;i++)
  {
    if (domArr[i].search(atomPat)==-1)
    {
      error = "Napačen E-mail (preverite del za @)";
      return error;
    }
  }

  /* domain name seems valid, but now make sure that it ends in a
  known top-level domain (like com, edu, gov) or a two-letter word,
  representing country (uk, nl), and that there's a hostname preceding
  the domain or country. */
  if (checkTLD && (domArr[domArr.length-1].length != 2) && (domArr[domArr.length-1].search(knownDomsPat) == -1))
  {
    error = "Napačen E-mail (preverite končnico)";
    return error;
  }

  // Make sure there's a host name preceding the domain.
  if (len < 2)
  {
    error = "Napačen E-mail (preverite del za @)";
    return error;
  }

  // If we've gotten this far, everything's valid!
  return "OK";
}

function check(form)
{
  var empty = false;

  for(var i = 0; i < form.elements.length; i++)
  {
    if(form.elements[i].type == "text")
    {
      form.elements[i].value = trim(form.elements[i].value);
      if(form.elements[i].value == "")
      {
        if(form.elements[i].name != "telefon")
          form.elements[i].value = " ";
        else
          empty = true;
      }
    }
  }
  if(!empty)
  {
    email = valEmail(form.email.value);

    var words = 1;
    for(i = 0; i < form.ime.value.length; i++)
    {
      if(form.ime.value.charAt(i) == " ")
        words++;
    }

    if((words > 1) && (email == "OK"))
    {
      if(form.password && form.rpassword)
      {
        if(form.password.value != form.rpassword.value)
        {
          alert("Gesli se ne ujemata!");
          return false;
        }
        else if(form.password.value.length < 8)
        {
          alert("Geslo je prekratko");
          return false;
        }
        else
          return true;
      }

      if(!form.confirmationID)
        form.action="index.php?action=preveri";
      else
        form.action="index.php?action=preveri&ukaz=moneta";
      return true;
    }
    else if(words <= 1)
    {
      alert("Prosim vpišite ime IN priimek!");
      return false;
    }
    else if(email != "OK")
    {
      alert(email);
      return false;
    }
  }
  else
  {
    alert("Izpolniti morate vsa polja!");
    return false;
  }
}

function changer()
{
  if((narocilnica.what.value == "PlatinumPopustFormula") || (narocilnica.what.value == "PlatinumPopust") || (narocilnica.what.value == "RegularPopustFormula") || (narocilnica.what.value == "RegularPopust"))
  {
    if(narocilnica.platinum.checked && narocilnica.formula.checked)
      narocilnica.what.value="PlatinumPopustFormula";
    if(narocilnica.platinum.checked && !narocilnica.formula.checked)
      narocilnica.what.value="PlatinumPopust";
    if(!narocilnica.platinum.checked && narocilnica.formula.checked)
      narocilnica.what.value="RegularPopustFormula";
    if(!narocilnica.platinum.checked && !narocilnica.formula.checked)
      narocilnica.what.value="RegularPopust";
  }
  if((narocilnica.what.value == "RegularFormula") || (narocilnica.what.value == "Regular") || (narocilnica.what.value == "PlatinumFormula") || (narocilnica.what.value == "Platinum"))
  {
    if(narocilnica.platinum.checked && narocilnica.formula.checked)
      narocilnica.what.value="PlatinumFormula";
    if(narocilnica.platinum.checked && !narocilnica.formula.checked)
      narocilnica.what.value="Platinum";
    if(!narocilnica.platinum.checked && narocilnica.formula.checked)
      narocilnica.what.value="RegularFormula";
    if(!narocilnica.platinum.checked && !narocilnica.formula.checked)
      narocilnica.what.value="Regular";
  }
  if((narocilnica.what.value == "RegularFormula48") || (narocilnica.what.value == "PlatinumFormula48") || (narocilnica.what.value == "Platinum48") || (narocilnica.what.value == "Regular48"))
  {
    if(narocilnica.platinum.checked && narocilnica.formula.checked)
      narocilnica.what.value="PlatinumFormula48";
    if(narocilnica.platinum.checked && !narocilnica.formula.checked)
      narocilnica.what.value="Platinum48";
    if(!narocilnica.platinum.checked && narocilnica.formula.checked)
      narocilnica.what.value="RegularFormula48";
    if(!narocilnica.platinum.checked && !narocilnica.formula.checked)
      narocilnica.what.value="Regular48";
  }
}

function checkSola(form)
{
  var empty = false;

  for(var i = 0; i < form.elements.length; i++)
  {
    if(form.elements[i].type == "text")
    {
      form.elements[i].value = trim(form.elements[i].value);
      if((form.elements[i].value == "") && (form.elements[i].disabled == false))
      {
        message = "Prosim izpolnite vsa polja!";
        empty = true;
      }
    }
    else if(form.elements[i].type == "select-one")
    {
      if(form.elements[i][form.elements[i].selectedIndex].value == "")
      {
        message = "Prosim izberite odgovor!";
        empty = true;
      }
    }
  }
  if(!empty)
  {
    email = valEmail(form.email.value);

    if(email != "OK")
    {
      alert(email);
      return false;
    }
    else
      return true;
  }
  else
  {
    alert(message);
    return false;
  }
}

function checkOther(dropdown)
{
  if(dropdown[dropdown.selectedIndex].value == "10")
  {
    document.getElementById("other_i").disabled = false;
    document.getElementById("other").style.display = "inline";
  }
  else
  {
    document.getElementById("other_i").disabled = true;
    document.getElementById("other").style.display = "none";
  }
}		