// deklarace promennych


var tvary = new Array();
var myShape = getURLVar("id");



// funkce pro zmenu nahledu pisma

function changePreview() {
  var index = document.getElementById("order-font").selectedIndex;
  document.getElementById("order-sample").src = nahledy[index + 1];
}

// funkce pro ziskani promenne z URL

function getURLVar(urlVarName) {
//divide the URL in half at the '?' 
var urlHalves = String(document.location).split('?');
var urlVarValue = '';
if(urlHalves[1]){
//load all the name/value pairs into an array 
var urlVars = urlHalves[1].split('&');
//loop over the list, and find the specified url variable 
for(i=0; i<=(urlVars.length); i++){
if(urlVars[i]){
//load the name/value pair into an array 
var urlVarPair = urlVars[i].split('=');
if (urlVarPair[0] && urlVarPair[0] == urlVarName) {
//I found a variable that matches, load it's value into the return variable 
urlVarValue = urlVarPair[1];
}
}
}
}
return urlVarValue;   
}

//funkce pro nastaveni spravne polozky podle promenne z URL

function setShape(shape) {
  if(shape != "") {
  
    var newShape = "ovaly-hladke";
  
    switch(shape) {
    case "84":
      newShape = "ovaly-hladke";
      break;
    case "85":
      newShape = "bohemia-ovaly-nova-rada";
      break;
    case "86":
      newShape = "obdelniky-nova-rada";
      break;
    case "87":
      newShape = "srdce";
      break;
    case "88":
      newShape = "fotostojanky-keramicke";
      break;
    case "96":
      newShape = "hrnecky";
      break;
    case "90":
      newShape = "fotostojanky-sklenene";
      break;
    case "92":
      newShape = "fotostojanky-sklenene";
      break;
    case "93":
      newShape = "tezitka";
      break;
    case "94":
      newShape = "privesky";
      break;
    case "95":
      newShape = "kalisky";
      break;
    default:
      newShape = "ovaly-hladke";
    }
  
    document.getElementById("order-shape").value = newShape;
  }
}

// obecna funkce pro vypnuti prvku formulare

function disableElement(elementID) {
  document.getElementById(elementID).disabled = true;
}

// obecna funkce pro zapnuti prvku formulare

function enableElement(elementID) {
  document.getElementById(elementID).disabled = false;
}

// souhrn funkci spoustenych pri nacteni stranky

function loadFunctions() {
  setShape(myShape);
  setSizes();
  changeBorder();
  disableElement("order-words");
  disableElement("order-font");
}

// souhrn funkci pri zmene vybraneho tvaru

function changeShapeFunctions() {
  changeBorder();
  setSizes();
}

// souhrn funkci pri zmene pozadavku na text na keramice

function toggleTextFunctions() {
  if(document.getElementById("order-text").checked == true) {
    enableElement("order-words");
    enableElement("order-font");
    changePreview();
  }
  else {
    disableElement("order-words");
    disableElement("order-font");
    document.getElementById("order-sample").src = nahledy[0];
  }
}

// funkce pro spravne nastaveni moznosti okraje

function changeBorder() {
  if(document.getElementById("order-shape").value == "bohemia-ovaly-nova-rada" || document.getElementById("order-shape").value == "bohemia-ovaly-stare-tvary") {
    document.getElementById("order-border-box").innerHTML = '<select class="textinput" name="order-border" id="order-border"><option value="stribrnavnejsi">Stříbrná linka (vnější)</option><option value="stribrnavnitrni">Stříbrná linka (vnitřní)</option><option value="stribrnatreti">Stříbrná linka (třetí)</option><option value="zlatavnejsi">Zlatá linka (vnější)</option><option value="zlatavnitrni">Zlatá linka (vnitřní)</option><option value="zlatatreti">Zlatá linka (třetí)</option></select>';
  }
  else {
    document.getElementById("order-border-box").innerHTML = '<select class="textinput" name="order-border" id="order-border"><option value="zadny">Žádný (fotografie až k okraji)</option><option value="bily">Bílý okraj 5 mm</option><option value="stribrna">Stříbrná linka</option><option value="zlata">Zlatá linka</option></select>';
  }
}

// funkce pro nastaveni moznosti rozmeru podle vybraneho tvaru

function setSizes() {
  var indexTvaru = document.getElementById("order-shape").selectedIndex;
  var completeOptions = '<select class="textinput" name="order-size" id="order-size">';
  for(var j = 0;j<sizeList[indexTvaru].length;j++) {
    completeOptions += '<option value="' + sizeList[indexTvaru][j] + '">' + sizeList[indexTvaru][j] + '</option>';
  }
  completeOptions += '</select>';
  document.getElementById("order-size-box").innerHTML = completeOptions;
}

