var phone_checked = 0;

function check_form() {
  if (document.form.name.value.length < 5) {
    alert('\n    Molim Vas upisite ime i prezime!\n    ');
    document.form.name.focus();
    document.form.name.select();
    return false;
  }
  var text=document.form.email.value;
  if (text.length < 5) {
    alert('\n    Molim Vas upisite E-mail adresu!\n    ');
    document.form.email.focus();
    document.form.email.select();
    return false;
  }
  if (text.indexOf('@') == -1) {
    alert('\n    E-mail adresa nije ispravna!\n    \n        Proverite!\n');
    document.form.email.focus();
    document.form.email.select();
    return false;
  }

  if (text.indexOf('.') == -1) {
    alert('\n    E-mail adresa nije ispravna!\n    \n        Proverite!\n');
    document.form.email.focus(); 
    document.form.email.select();
    return false;
  }
  if ((text.length-text.lastIndexOf('.'))>4 || (text.length-text.lastIndexOf('.'))<2) {
    alert('\n    E-mail adresa nije ispravna!\n    \n        Proverite!\n');
    document.form.email.focus();
    document.form.email.select();
    return false;
  }
  if (text.indexOf('.')==text.indexOf('@')+1) {
    alert('\n    E-mail adresa nije ispravna!\n    \n        Proverite!\n');
    document.form.email.focus();
    document.form.email.select();
    return false;
  }
  
  if (document.form.phone.value.length < 3) {
    if(phone_checked==0) {
      alert('\n    Molimo Vas da ostavite broj telefona kako bismo mogli\n    da Vas i na taj način kontaktiramo i potvrdimo porudžbinu.');
      document.form.phone.focus();
      document.form.phone.select();
      phone_checked = 1;
      return false;
    }
    if(phone_checked==1) {
      alert('\n -    Ako ne želite da ostavite broj telefona upišite xxx!    -\n    ');
      document.form.phone.focus();
      document.form.phone.select();
      phone_checked = 1;
      return false;
    }
  }
  if (!document.form.pay_accept.checked) {
    alert('  \n  Niste prihvatili obavezu da ćete izvršiti plaćanje!  \n   ');
    document.form.pay_accept.focus();
    document.form.pay_accept.select();
    return false;
  }
}
