// JavaScript Document


var store = new Array();

// SB 1
store[1] = new Array();

store[1][0] = new Array();

store[1][0][0] = new Array();
store[1][0][0]['name'] = 'Ofset (nejčastěji)';
store[1][0][0]['value'] = '1';

store[1][0][1] = new Array();
store[1][0][1]['name'] = 'Vizitky EXPRES';
store[1][0][1]['value'] = '2';

// SB 2

store[2] = new Array();

store[2][1] = new Array();

store[2][1][0] = new Array();
store[2][1][0]['name'] = 'jednostranná';
store[2][1][0]['value'] = 'jednostranná';

store[2][1][1] = new Array();
store[2][1][1]['name'] = 'oboustranná';
store[2][1][1]['value'] = 'oboustranná';



store[2][2] = new Array();

store[2][2][0] = new Array();
store[2][2][0]['name'] = 'jednostranná - barevná';
store[2][2][0]['value'] = 'jednostranná - barevná';

store[2][2][1] = new Array();
store[2][2][1]['name'] = 'oboustranná - barevná/černá';
store[2][2][1]['value'] = 'oboustranná - barevná/černá';

store[2][2][2] = new Array();
store[2][2][2]['name'] = 'oboustranná - barevná';
store[2][2][2]['value'] = 'oboustranná - barevná';


// SB 3
store[3] = new Array();

store[3][0] = new Array();

store[3][0][0] = new Array();
store[3][0][0]['name'] = 'Ofset (nejčastěji)';
store[3][0][0]['value'] = '1';

store[3][0][1] = new Array();
store[3][0][1]['name'] = 'Vizitky EXPRES';
store[3][0][1]['value'] = '2';


// SB 4

store[4] = new Array();

store[4][1] = new Array();

store[4][1][0] = new Array();
store[4][1][0]['name'] = 'jednostranná';
store[4][1][0]['value'] = 'jednostranná';

store[4][1][1] = new Array();
store[4][1][1]['name'] = 'oboustranná';
store[4][1][1]['value'] = 'oboustranná';


store[4][2] = new Array();

store[4][2][0] = new Array();
store[4][2][0]['name'] = 'jednostranná - barevná';
store[4][2][0]['value'] = 'jednostranná - barevná';

store[4][2][1] = new Array();
store[4][2][1]['name'] = 'oboustranná - barevná/černá';
store[4][2][1]['value'] = 'oboustranná - barevná/černá';

store[4][2][2] = new Array();
store[4][2][2]['name'] = 'oboustranná - barevná';
store[4][2][2]['value'] = 'oboustranná - barevná';


function init () {
	var box = document.frm.s1;
	var list = store[1][0];
	box.options[0] = new Option ('Vyberte typ vizitky...', '');
	for (i = 0; i < list.length; i++) {
		box.options[i] = new Option (list[i]['name'], list[i]['value']);
	}
	

}
	
function populate (s) {
	var box = eval ('document.frm.s' + (s-1));
	var box2 = eval ('document.frm.s' + s);
	var num = box.options[box.selectedIndex].value;

	if (store[s] == null || store[s][num] == null) {
		for (i = s; i <= 2; i++) {
			var box_res = eval ('document.frm.s' + i);
			box_res.options.length = 0;
			box_res.options[0] = new Option ('Není dostupná žádná položka.', 1);
		}
		return;
	}
	
	var list = store[s][num];
	box2.options.length = 0;
	box2.options[0] = new Option ('-Počet-', '');
	for (i = 0; i < list.length; i++) {
		box2.options[i] = new Option (list[i]['name'], list[i]['value']);
	}

	// jeste provedeme reset nasledujicich
	for (i = s + 1; i <= 2; i++) {
		var box_res = eval ('document.frm.s' + i);
		box_res.options.length = 0;
		box_res.options[0] = new Option ('Není dostupná žádná položka.', '');
	}
}  

function init2()
{
	var box2 = document.frm2.s3;
	var list2 = store[3][0];
	box2.options[0] = new Option ('Vyberte typ vizitky...', '');
	for (i = 0; i < list2.length; i++) {
		box2.options[i] = new Option (list2[i]['name'], list2[i]['value']);
	}
}


function populate2 (s) {
	var box = eval ('document.frm2.s' + (s-1));
	var box2 = eval ('document.frm2.s' + s);
	var num = box.options[box.selectedIndex].value;

	if (store[s] == null || store[s][num] == null) {
		for (i = s; i <= 2; i++) {
			var box_res = eval ('document.frm2.s' + i);
			box_res.options.length = 0;
			box_res.options[0] = new Option ('Není dostupná žádná položka.', 1);
		}
		return;
	}
	
	var list = store[s][num];
	box2.options.length = 0;
	box2.options[0] = new Option ('-Počet-', '');
	for (i = 0; i < list.length; i++) {
		box2.options[i] = new Option (list[i]['name'], list[i]['value']);
	}

	// jeste provedeme reset nasledujicich
	for (i = s + 1; i <= 2; i++) {
		var box_res = eval ('document.frm2.s' + i);
		box_res.options.length = 0;
		box_res.options[0] = new Option ('Není dostupná žádná položka.', '');
	}
} 

function checkSelectKalkul()
{
    // kalkulace
    var sablona = document.getElementById("navrh").value;
    
    if (sablona == "použít šablonu 290,-")
    {
      document.getElementById("kontakty").disabled = false;
    }
    if (sablona == "Ne")
    {
      document.getElementById("kontakty").disabled = true;
      document.getElementById("kontakty").selectedIndex = 0;
    }    
    if (sablona == "návrh na míru 490,-")
    {
      document.getElementById("kontakty").disabled = false;
    }   

}

function checkSelect()
{    
    // objednavka - kontakty
    var sablonaObjednavka = document.getElementById("navrhObjednavka").value;
    
    if (sablonaObjednavka == "použít šablonu 290,-")
    {
      document.getElementById("kontaktyObjednavka").disabled = false;
      document.getElementById("vzoryObjednavka").disabled = false;
      
      if (tiskObjednavka == "oboustranný")
      {
        alert ("Návrh dle vzoru je pouze jednostranný v případě, že chcete oboustranný návrh, musíte si návrh druhé strany dodat.");
      }
    }
    if (sablonaObjednavka == "Ne")
    {
      document.getElementById("kontaktyObjednavka").disabled =true;
      document.getElementById("kontaktyObjednavka").selectedIndex = 0;
      document.getElementById("vzoryObjednavka").disabled = true;
      document.getElementById("vzoryObjednavka").selectedIndex = 0;
    }    
    if (sablonaObjednavka == "návrh na míru 490,-")
    {
      document.getElementById("kontaktyObjednavka").disabled = false;    
      document.getElementById("vzoryObjednavka").disabled = true;
      document.getElementById("vzoryObjednavka").selectedIndex = 0;
    }     
     
}

function checkKontakty()
{
        var jmeno = document.getElementById("jmenoObjednavka").value;
        var email = document.getElementById("emailObjednavka").value;
        var mesto = document.getElementById("mestoObjednavka").value;
        var chyba = "";

        if (jmeno == "")
        {
            chyba = chyba + "Jméno a příjmení nebylo vyplněno.\n";
        }  
        if (email == "")
        {
            chyba = chyba + "Email nebyl vyplněn.\n";
        }  
        if (mesto == "")
        {
            chyba = chyba + "Fakturační adresa nebyla vyplněna.\n";
        }    
        
       if(!zkontroluj_email(email)) 
       {
          chyba = chyba + "Zadaný E-mail není ve správném tvaru.\n";
       }    

        
        if (chyba == "")
        {
            return true;
        }      
        
        alert (chyba);        
        return false;
}

function zkontroluj_email(adresa)
{
  re = /^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,6}$/;
  return adresa.search(re) == 0;
}


function checkVizitky()
{
      var pocet = document.getElementById("pocetObjednavka").value;
      var typ = document.getElementById("typObjednavka").value;
      var navrh = document.getElementById("navrhObjednavka").value;
      var vzor = document.getElementById("vzoryObjednavka").value;
      var platba = document.getElementById("platbaObjednavka").value;
      
      var chyba = "";
      
      if (pocet > 0)
      {
        if (typ == 1)
        {
          if (pocet % 1000 == 0 && pocet != 0) 
          {
            return true; 
          }
          else
          {
            chyba = "Vizitky Ofset 300g lze objednávat pouze po 1000 kusech.\n";
          }
        }
        if (typ == 3)
        {
              var kont = true;
              if (pocet == 20000 || (pocet % 20000) == 0){  kont = true;   }
              else if (pocet == 10000 || (pocet % 10000) == 0){  kont = true;   }
              else if (pocet == 5000 || (pocet % 5000) == 0){  kont = true;   }
              else if (pocet == 2500 || (pocet % 2500) == 0){  kont = true;   }
              else if (pocet == 1000 || (pocet % 1000) == 0){  kont = true;   }
              else if (pocet == 500 || (pocet % 500) == 0){  kont = true;   }
              else if (pocet == 250 || (pocet % 250) == 0){  kont = true;   }
              else  { kont = false;  }        
          if (kont == true) 
          {
            if (platba == "dobírka po ČR")
            {
              chyba = "Vizitky Ofset 350g lze platit pouze předem bankovním převodem.";
            }
            else
            {
              return true;
            } 
          }
          else
          {
            chyba = "Vizitky Ofset 350g lze objednávat pouze po 250, 500, 1000, 2500, 5000, 10000, 20000 kusech a nebo jejich násobcích.\n";
          }
        }      
        if (typ == 2)
        {
          if (pocet % 100 == 0 && pocet != 0)
          {
            return true; 
          }
          else
          {
            chyba = "Vizitky EXPRES lze objednávat pouze po 100 kusech.\n";
          }
        }
      }
      else
      {
        chyba = "Byl zadán záporný počet vizitek!.\n";
      }
      if (navrh == "použít šablonu 290,-" && vzor == "žádný")
      {
        chyba = chyba + "Musíte vybrat, kterou šablonu (který vzor) chcete použít.";
      }
      alert (chyba);
      return false;      
}


function inicializace()
{
  document.getElementById("kontakty").disabled = true;
  document.getElementById("kontaktyObjednavka").disabled = true;
  document.getElementById("vzoryObjednavka").disabled = true;
  
  checkSelect();
  
  init(); 
  populate(2);
    
  init2(); 
  populate2(4);
}
