function isInteger (s)
{
  var i;

  for (i = 0; i < s.length; i++)
  {
    // Check that current character is number.
    var c = s.charAt(i);
    if (!isDigit(c)) return false;
  }

  // All characters are numbers.
  return true;
}

function isEmpty(s)
{
  return ((s == null) || (s.length == 0))
}

function isWhitespace (s)
{
	var i;
	var whitespace = " \t\n\r";

	// Is s empty?
  if (isEmpty(s)) return true;

  // Search through string's characters one by one
  // until we find a non-whitespace character.
  // When we do, return false; if we don't, return true.
  for (i = 0; i < s.length; i++)
  {
    // Check that current character isn't whitespace.
    var c = s.charAt(i);

    if (whitespace.indexOf(c) == -1) return false;
  }

  // All characters are whitespace.
  return true;
}

function isEmail (s)
{
  // is s whitespace?
  if (isWhitespace(s)) return false;
  
  // there must be >= 1 character before @, so we
  // start looking at character position 1
  // (i.e. second character)
  var i = 1;
  var sLength = s.length;
  
  // look for @
  while ((i < sLength) && (s.charAt(i) != '@'))
  {
    i++
  }
  
  if ((i >= sLength) || (s.charAt(i) != '@')) return false;
  else i += 2;
  
  // look for .
  while ((i < sLength) && (s.charAt(i) != '.'))
  {
    i++
  }
  
  // there must be at least one character after the .
  if ((i >= sLength - 1) || (s.charAt(i) != '.')) return false;
  else return true;
}

function CheckOrderForm()
{
	var theForm = document.getElementById('order_form');
	var submit = true;

  if(theForm.typ_platby.selectedIndex==0)
  {
		alert('Vyberte prosím: Způsob platby a dodání');
		theForm.typ_platby.focus();
		submit = false;
  }

	if (theForm.email.value == '' && submit)
	{
		alert('Zadejte prosím: E-mail');
		theForm.email.focus();
		submit = false;
	}
	
	if (!isEmail(theForm.email.value) && submit)
	{
		alert('Zadejte prosím: platný E-mail');
		theForm.email.focus();
		submit = false;
  }
	
	if (theForm.telefon.value == '' && submit)
	{
		alert('Zadejte prosím: Telefon');
		theForm.telefon.focus();
		submit = false;
	}
	
	if (theForm.fakturacna_meno.value == '' && submit)
	{
		alert('Zadejte prosím: Jméno, Příjmění / Název firmy');
		theForm.fakturacna_meno.focus();
		submit = false;
	}
	
	if (theForm.fakturacna_ulica.value == '' && submit)
	{
		alert('Zadejte prosím: Ulice');
		theForm.fakturacna_ulica.focus();
		submit = false;
	}
	
	if (theForm.fakturacna_cislo.value == '' && submit)
	{
		alert('Zadejte prosím: Číslo');
		theForm.fakturacna_cislo.focus();
		submit = false;
	}
	
	if (theForm.fakturacna_mesto.value == '' && submit)
	{
		alert('Zadejte prosím: Město');
		theForm.fakturacna_mesto.focus();
		submit = false;
	}
	
	if (theForm.fakturacna_psc.value == '' && submit)
	{
		alert('Zadejte prosím: PSČ');
		theForm.fakturacna_psc.focus();
		submit = false;
	}
	
	if (theForm.dodacia_meno.value == '' && submit)
	{
		alert('Vyplňte nebo zkopírujte Dodací adresu');
		theForm.dodacia_meno.focus();
		submit = false;
	}
	
	if (theForm.dodacia_ulica.value == '' && submit)
	{
		alert('Vyplňte nebo zkopírujte Dodací adresu');
		theForm.dodacia_ulica.focus();
		submit = false;
	}
	
	if (theForm.dodacia_cislo.value == '' && submit)
	{
		alert('Vyplňte nebo zkopírujte Dodací adresu');
		theForm.dodacia_cislo.focus();
		submit = false;
	}
	
	if (theForm.dodacia_mesto.value == '' && submit)
	{
		alert('Vyplňte nebo zkopírujte Dodací adresu');
		theForm.dodacia_mesto.focus();
		submit = false;
	}
	
	if (theForm.dodacia_psc.value == '' && submit)
	{
		alert('Vyplňte nebo zkopírujte Dodací adresu');
		theForm.dodacia_psc.focus();
		submit = false;
	}
	
  return submit;
}

function ShowPaymentBox()
{
  var typ_platby        = document.getElementById('typ_platby');
  var payment_info_box  = document.getElementById('payment_info_box');
  platba=typ_platby.options[typ_platby.selectedIndex].value.substr(0,1);
  if(platba=='3')
  {
    payment_info_box.style.display = '';
  }
  else
  {
    payment_info_box.style.display = 'none';
  }
}
