// JavaScript Document
version = navigator.appVersion.toLowerCase();
agent = navigator.userAgent.toLowerCase();
ie = (version.indexOf('msie') > -1);
ie50 = (version.indexOf('msie 5.0') > -1);
win = (version.indexOf('windows') > -1);
opera = (agent.indexOf('opera') > -1);
lastSelectIDVZORNIK=0;
function objGet(x) {
	if (typeof x != 'string') {
		return x
	} else {
		if (Boolean(document.getElementById)) {
			return document.getElementById(x)
		} else {
			if (Boolean(document.all)) {
				return eval('document.all.' + x)
			} else {
				return null
			}
		}
	}
}
function ow(url, jmeno, w, h) {
	window.open(url, jmeno, 'resizable=1,top=20,left=20,menubar=0,scrollbars=yes,width=' + w + ',height=' + h)
}
var lastSelectedSampler = new Array();
function selectSampler(id, price, vvalue, mena) {
	var zz = objGet("samplerinput_" + id);
	if (zz) {
		zz.value = vvalue
	}

	if (lastSelectedSampler[id] > 0) {
		objGet('sample' + lastSelectedSampler[id]).className = 'sb'
	}
	lastSelectedSampler[id] = vvalue;
	var bb = objGet('sample' + lastSelectedSampler[id]);
	if (bb){ bb.className = 'ssb';}
	price = objGet('samplePrice' + vvalue);
	if (price) {
		price = price.innerHTML;
		price = price.substring(0, price.indexOf(mena));
		price = price.substring(0, price.indexOf(" "));
		objGet("samplerprice_" + id).value = price
	} else {
	  var cc = objGet("samplerprice_" + id);
    if (cc){cc.value = 0;}
	}
	PrepocitejCenu();
}
function ZmenaCenyVzorkovniku(id, cena, mena, nazev) {
	var samplePrice = objGet("samplePrice" + id);
	if (samplePrice) {
		if (cena > 0) {
			samplePrice.innerHTML = "+" + cena.toString() + " " + mena
		} else {
			samplePrice.innerHTML = ""
		}
	} else {
		samplePrice = objGet("sample" + id);
		if (cena > 0) {
			samplePrice.innerHTML = nazev + " + " + cena.toString() + " " + mena
		} else {
			samplePrice.innerHTML = nazev
		}
		if (samplePrice.value) {
			var pole = samplePrice.value.split("_");
			selectSamplerNoClass(pole[0], pole[1], pole[2]);
			samplePrice.value = pole[0] + "_" + cena.toString() + "_" + id + "_" + mena;
			samplePrice.onclick = "selectSamplerNoClass(" + pole[0] + ",'" + cena.toString() + "','" + id + "','" + mena + "');"
		}
	}
}
function selectSamplerNoClass(id, price, vvalue, mena, idvazba_na_vzornik) {
  	if (price != parseFloat(price)) {
  		price = 0
  	}
if (idvazba_na_vzornik){
//  	alert(idvazba_na_vzornik);
  	pole = idvazba_na_vzornik.split("|"); 
  	for(y=1;y<pole.length;y++){
      //nejdrive smazu obsah predchoziho vybraneho vzorniku
      if (lastSelectIDVZORNIK){
          poleNone = lastSelectIDVZORNIK.split("|"); 
        	for(y1=1;y1<poleNone.length;y1++){
              var zz1 = objGet("vzornikID_"+poleNone[y1]);
              if (zz1){
                zz1.innerHTML = "";
                zz1.style.display = "none";
              }
          }
      }
  	 
    	var zz = objGet("vzornikID_"+pole[y]);
      if (zz) {
 //      alert(pole[y]);
        zz.innerHTML = vzornik[pole[y]];
        zz.style.display = "";
      }
      
    }
    lastSelectIDVZORNIK = idvazba_na_vzornik;
}
	
	objGet("samplerinput_" + id).value = vvalue;
	lastSelectedSampler[id] = vvalue;
	objGet("samplerprice_" + id).value = price;
	var samplerLink = objGet("samplerlink_" + id);
	if (samplerLink) {
		var poleRada = objGet("samplerlist_" + samplerLink.value).value.split("|");
		var pamsamplePrice;
		for (i = 0; i < poleRada.length - 1; i++) {
			var Vzorek = poleRada[i].split(";");
			var _id = Vzorek[0];
			var priplatek = Vzorek[1];
			var procenta = Vzorek[2];
			var nazev = Vzorek[3];
			if (procenta > 0) {
				var priceNew = (parseInt(priplatek, 10) + parseInt((price) * (procenta / 100), 10));
				var samplePrice = objGet("sample" + _id);
				if ((samplePrice) && (samplePrice.value)) {
					var pole = samplePrice.value.split("_");
					var idSampleSelect = objGet("samplerinput_" + pole[0]);
					pamsamplePrice = objGet("sample" + idSampleSelect.value)
				} else {
					pamsamplePrice = false
				}
				ZmenaCenyVzorkovniku(_id, priceNew, mena, nazev);
				if (pamsamplePrice) {
					var pole1 = pamsamplePrice.value.split("_");
					selectSamplerNoClass(pole1[0], pole1[1], pole1[2], pole1[3])
				}
				var sp = objGet("sample" + _id);
				if (sp) {
					if (sp.className == 'ssb') {
						selectSampler(samplerLink.value, 0, _id, mena)
					}
				}
			} else {
				ZmenaCenyVzorkovniku(_id, "", mena, nazev)
			}
		}
	}
	PrepocitejCenu()
}
function changeSamplerNoClass(vvalue) {
	var pole = vvalue.split("_");
	selectSamplerNoClass(pole[0], pole[1], pole[2])
}
function checkSampler(id, price, vvalue) {
	var sumPrice = 0;
	var poleRada = objGet("samplerinput_" + id).value.split(",");
	if (objGet("sample" + vvalue).checked === true) {
		sumPrice = parseInt(objGet("samplerprice_" + id).value, 10);
		poleRada[poleRada.length] = vvalue;
		objGet("samplerprice_" + id).value = parseInt(sumPrice, 10) + parseInt(price, 10)
	} else {
		objGet("samplerprice_" + id).value -= price;
		for (i = 0; i < poleRada.length; i++) {
			if (poleRada[i] == vvalue) {
				poleRada.splice(i, 1)
			}
		}
	}
	objGet("samplerinput_" + id).value = poleRada.toString();
	PrepocitejCenu()
}
function PrepocitejCenu() {
	var i, sumPrice = 0;
	var samples = document.getElementsByName('samplerprice');
	for (i = 0; i < samples.length; i++) {
		CheckNum = parseInt(samples[i].value, 10);
		if (!isNaN(CheckNum)) {
			sumPrice += parseInt(samples[i].value, 10)
		}
	}
	if (objGet("atypprice")) {
		var atypprice = objGet("atypprice").value;
		if (atypprice > 0) {
			sumPrice += parseInt(atypprice, 10)
		}
	}
	objGet('sumSamples').innerHTML = parseInt(sumPrice, 10)
}
function clearSampler(obj1, numobj, tthis, vvalue) {
	objGet("samplerinput" + obj1).value = vvalue;
	var i;
	for (i = 0; i != numobj; i++) {
		obja = "sam" + obj1 + i;
		var o = objGet(obja);
		o.className = 'sb'
	}
	tthis.className = 'ssb'
}
function display(elementID) {
	var id;
	if ((ie) & !(opera)) {
		id = "area" + elementID;
		document.all.item(id).style.display = "block"
	} else {
		id = "area" + elementID;
		var bz = document.getElementById(id);
		if (bz) {
			bz.style.display = "block"
		}
	}
}
function undisplay(elementID) {
	var a = objGet("area" + elementID);
	if (a) {
		a.style.display = "none"
	}
}
var SENDER_TAG_NAME = "SPAN";
var SENDER_CLASS = "email";
var _ELEMENT_NODE = 1;
var ZAVINAC = "at";
var Vzor = new RegExp('(.*)\\(' + ZAVINAC + '\\)(.*)');
function GoEmaily(e) {
	if ((e.tagName == SENDER_TAG_NAME) && (e.className == SENDER_CLASS)) {
		s = e.innerHTML;
		email = s.replace(Vzor, "$1@$2");
		e.removeChild(e.firstChild);
		a = e.appendChild(document.createElement("A"));
		a.setAttribute("href", "mailto:" + email);
		a.className = "m";
		a.appendChild(document.createTextNode(email))
	}
	var i;
	for (i = 0; i < e.childNodes.length; i++) {
		if (e.childNodes[i].nodeType == _ELEMENT_NODE) {
			GoEmaily(e.childNodes[i])
		}
	}
}
function Go() {
	if (navigator.userAgent.indexOf("Opera") == -1) {
		GoEmaily(document.documentElement)
	}
}

function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
  offset = document.cookie.indexOf(search)
  if (offset != -1) {
    offset += search.length
   end = document.cookie.indexOf(";", offset);
  if (end == -1) end = document.cookie.length;
  returnvalue=unescape(document.cookie.substring(offset, end))
  }
  }
 return returnvalue;
}

function set_cookie(Name,Value){
 document.cookie= Name+"="+Value;
}

function sss(name){
 var s = get_cookie(name+"ds");
 var a = objGet("descriptionSection");
 if ((s=="none") || (s=="block")){
   a.style.display = s;
 }
   a.style.display = s;
}

function HideDS(name){
	var a = objGet("descriptionSection");
	if (a.style.display == "none"){
    a.style.display = "block";
    set_cookie(name+"ds","block");
  }else{
    a.style.display = "none";
    set_cookie(name+"ds","none");
  }  
}


