//-----------------------------------
function SwitchFirmOn() {
	document.all.SwitchVisFirm.style.display='inline';
	document.all.SwitchVisName.style.display='none';
	document.all.SwitchVisICO.style.display='inline';
	document.all.SwitchVisDIC.style.display='inline';
	document.all.SwitchVisSureName.style.display='none';
	document.all.FirmID.readOnly=false;
	document.all.FirmID.style.background='#FFFFFF';
}
//-----------------------------------
function SwitchFirmOff() {
	document.all.SwitchVisFirm.style.display='none';
	document.all.SwitchVisName.style.display='inline';
	document.all.SwitchVisICO.style.display='none';
	document.all.SwitchVisDIC.style.display='none';
	document.all.SwitchVisSureName.style.display='inline';
	document.all.FirmID.readOnly=true;
	document.all.FirmID.style.background='#DDDDDD';
	document.all.FirmID.value=document.all.LastNameID.value + ', ' + document.all.FirstNameID.value;
}
//-----------------------------------
function NameChange() {
	if (document.all.bFirm0.checked == true)
		document.all.Firm.value=document.all.LastNameID.value + ', ' + document.all.FirstNameID.value;
}
//-----------------------------------
function ShowBuyInfo(objBuy, CountID, Price, DPH) {
	Price = Price.replace(',','.');
	if (typeof objBuy == 'object' && typeof document.all[CountID] == 'object' && (!isNaN(Price)) && (!isNaN(DPH))) {
		CountID = document.all[CountID].value;
		xDPH = DPH;
		if (DPH.length == 1) { xDPH='0' + DPH };
		SumPrice = parseInt(((1+'.'+xDPH)*Price*CountID)*10) / 10;
		SumPrice = SumPrice.toString();
		if (SumPrice.indexOf('.') > 1) {SumPrice += '0'};
		objBuy.title = '\n  Vložit do košíku:\n\n  '+CountID+' ks\n  '+Price+' Kč bez DPH\n  +'+DPH+'% DPH\n\n  Celkem : '+SumPrice+' Kč s DPH  \n';
	}
}
//-----------------------------------
function ShowPointsInfo(objBuy, CountID, nPoints) {
	if (typeof objBuy == 'object' && typeof document.all[CountID] == 'object' && (!isNaN(nPoints))) {
		CountID = document.all[CountID].value;
		SumPoints = nPoints*CountID;
		SumPoints = SumPoints.toString();
		objBuy.title = '\n  Vložit do košíku:\n\n  '+CountID+' ks\n  '+nPoints+' bodů\n\n  Celkem : '+SumPoints+' bodů.  \n';
	}
}
//-----------------------------------
function SelectCat() {
	document.cookie = "BrowVyr=0;";
	BrowseVyr.style.display = 'none';
	BrowseCat.style.display = 'inline';
	if (typeof BrowseCatVyr == 'object') BrowseCatVyr.style.display = 'none';
}
//-----------------------------------
function SelectVyr() {
	document.cookie = "BrowVyr=1;";
	BrowseCat.style.display = 'none';
	BrowseVyr.style.display = 'inline';
	if (typeof BrowseCatVyr == 'object') BrowseCatVyr.style.display = 'none';
}
//-----------------------------------
function SelectCatVyr() {
	document.cookie = "BrowVyr=1;";
	BrowseCat.style.display = 'none';
	BrowseVyr.style.display = 'none';
	BrowseCatVyr.style.display = 'inline';
}
//-----------------------------------
function BrowseOrOpenCat(iCat, iSub) {
	// iCat0..(n-1) ... ID rozkládacího divu = "Cat" + 1..n
	// iSub0..(n-1) ... ID rozkládacího subdivu = "Cat" + 1..n + "x" + "1..m"
	var i = 0;
	var ii;
	var sDisplay = "none";

	document.cookie = "Lev1=-1;";
	document.cookie = "Lev2=-1";
	while (document.all["Cat" + i] != null) {
		/* na Amonu už chtějí vždy rozbalený 1. level ...

		// ulozeni rozkliknute kategorie / rozkliknuti / zakliknuti
		if (i == iCat) {
			if (iSub != -1) {
				document.all["Cat" + i].style.display = "inline";
				document.cookie = "Lev1=" + iCat + ";";
			}
			else {
				if (document.all["Cat" + i].style.display == "none") {
					document.all["Cat" + i].style.display = "inline";
					document.cookie = "Lev1=" + iCat + ";";
				}
				else
					document.all["Cat" + i].style.display = "none";
			}
		}
		else
			document.all["Cat" + i].style.display = "none";
		*/

		// ulozeni rozkliknute kategorie / rozkliknuti / zakliknuti
		ii = 0;
		while (document.all["Cat" + i + "x" + ii] != null) {
			if ((iCat == i) && (iSub == ii) && (document.all["Cat" + i + "x" + ii].style.display == "none")) {
				document.all["Cat" + i + "x" + ii].style.display = "inline";
				document.cookie = "Lev2=" + ii + ";";
			}
			else
				document.all["Cat" + i + 'x' + ii].style.display = "none";
			ii += 1;
		}
		i += 1;
	}
}
//-----------------------------------
function fnParamChanger(v)
{
	if(typeof document.all.idParamChanger == 'object')
	{
		n = v.indexOf('<!--')
		if (!isNaN(n))
		{
			v = v.substr(n+4)
			n = v.indexOf('-->')
			if (!isNaN(n))
			{
				v = v.substr(0, n)
				v=v.replace(' ','&nbsp;')
				document.all.idParamChanger.innerHTML = v;
			}
		}
	}
}
//-----------------------------------
function showRollover(img_id, img_state)
{
	img_id.src = '/img/roll_' + img_state + '.gif';
}
//-----------------------------------
function showTRHighlighted(tr_id, p_color)
{
	tr_id.style.background = p_color;
}
//-----------------------------------
function onAction(imgName){
       document [imgName].src = eval(imgName + "on.src")
  }
//-----------------------------------
function offAction(imgName){
        if (oldImgName.substring(0,4)!=imgName.substring(0,4)){
              document [imgName].src = eval(imgName + "off.src")
            }
  }
//-----------------------------------
function OpenWnd(strURL){
         var objWnd = window.open(strURL,"InfoDetail","scrollbars=no,height=500,width=400,left=10,top=10");
         objWnd.focus();
}
//-----------------------------------
function AddBuy(strName, intPrice, intDph, strCode) {
        var strData,strReturn
        strData = strName+"&"+intPrice+"&"+intDph+"&"+strCode
        strReturn = showModalDialog("/AddUpdBuy.asp",strData,"status:no; center:yes; help:no; minimize:no;dialogWidth=350pt;dialogHeight=200pt");
        if (strReturn == "1"){ActionCookies('BZbuy')
        }else if (strReturn == "2"){window.location.href="/order.asp"}
}
//-----------------------------------
function AddBuyDetail(strName, intPrice, intDph, strCode) {
        var strData,strReturn
        strData = strName+"&"+intPrice+"&"+intDph+"&"+strCode
        strReturn = showModalDialog("/AddUpdBuy.asp",strData,"status:no; center:yes; help:no; minimize:no;dialogWidth=350pt;dialogHeight=200pt");
        if (strReturn == "1"){
                        window.opener.ActionCookies('BZbuy')
        }else if (strReturn == "2"){
                        window.opener.location.href="/order.asp";
                        window.close();
                }
}
//-----------------------------------
function ActionCookies(strName){
        var strString,strSum1,strSum2,intSuma;
        strSum2 = new Array();
        intSuma = 0;

        strString = ExtractCookies(strName);
        if (strString > ""){
                strSum1 = strString.split("#");
                for (var i=0; i< strSum1.length-1; i++){
                              strSum2[i] = strSum1[i].split("&");
                        intSuma += BarterComma(strSum2[i][1])*BarterComma(strSum2[i][4]);
                }
                document.all.CompletPrice.value =  FormatNumber(intSuma);
        }
}
//-----------------------------------
function DeleteCookies(strName){
        var vyprs=new Date();
        vyprs.setDate(vyprs.getDate() - 365);
        document.cookie=strName+"=; expires="+vyprs.toGMTString()+";";
        vyprs.setDate(365 + 365 + vyprs.getDate());
        document.cookie=strName+"=; expires="+vyprs.toGMTString()+";";
        document.all.CompletPrice.value = "0.00";
}
//-----------------------------------
function InsTreeCook(intId,idTree){
        var vyprs=new Date();
        vyprs.setDate(vyprs.getDate() - 365);
        document.cookie="category"+idTree+"="+intId+"; expires="+vyprs.toGMTString()+";";
        vyprs.setDate(365 + 365 + vyprs.getDate());
        document.cookie="category"+idTree+"="+intId+"; expires="+vyprs.toGMTString()+";";
}
//-----------------------------------
function InsertCookies(strName,strData){
        var vyprs=new Date();
        vyprs.setDate(vyprs.getDate() - 365);
        document.cookie=strName+"="+strData+"; expires="+vyprs.toGMTString()+";";
        vyprs.setDate(365 + 365 + vyprs.getDate());
        document.cookie=strName+"="+strData+"; expires="+vyprs.toGMTString()+";";
}
//-----------------------------------
function ExtractCookies(strName){
        var cookieList=document.cookie.split("; ");
        var cookieArray = new Array();
        var name = "#"
        for (var i=0; i < cookieList.length; i++){
                if(cookieList[i].indexOf(strName)>-1){
                      if( cookieList[i].indexOf("=")>-1){name = cookieList[i].split("=");}
                 }
        }
        if (name != "#"){
                        return name[1];
        }else{
                        return "none";
        }
}
//-----------------------------------
function ParseCookies(strName){
        var strCook = ExtractCookies(strName)
        if (strCook != "none"){
                var strList = strCook.split("a");
                for (var i=0; i < strList.length-1; i++){
                  if(typeof(document.all[strList[i]+'a']) == "object"){document.all[strList[i]+'a'].click();}
                }
     }
}
//-----------------------------------
function FormatNumber(text){
        var mezi = BarterComma(text);
        mezi = ''+Math.round(parseFloat(mezi) * 100);
        var desetiny = mezi.substring(mezi.length-2, mezi.length);
        var cele = mezi.substring(0,mezi.length-2);
        if (parseFloat(mezi) < 1){
                var mezi = "0."+desetiny;
        }else{
                var mezi = cele+"."+desetiny;
        }
        return mezi;
}
//-----------------------------------
function BarterComma(text){
        var mezi = ''+text;
        if (mezi.indexOf(',') != -1){
                mezi = mezi.split(",");
                mezi = mezi[0]+"."+mezi[1];
        }else{
                mezi = text;
        }
        return parseFloat(mezi);
}
//-----------------------------------
function ControlNumber(){
     if ((event.keyCode <48) || (event.keyCode >57)) event.returnValue = false;
}
//-----------------------------------
function InfoWindow(strAddress) {
       showModalDialog(strAddress,"Info","status:no; center:yes; help:no; minimize:no;dialogWidth=450pt;dialogHeight=320pt");
}
//-----------------------------------
function WriteDate(){
    var strDay=new Date();
    var d=strDay.getDay();
    if (d==1) {document.writeln('pondělí') }
    else { if (d==2) {document.writeln('úterý') }
    else { if (d==3) {document.writeln('středa') }
    else { if (d==4) {document.writeln('čtvrtek') }
    else { if (d==5) {document.writeln('pátek') }
    else { if (d==6) {document.writeln('sobota') }
    else { if (d==0) {document.writeln('neděle') }}}}}}};
    document.writeln(strDay.getDate(),'.',strDay.getMonth()+1,'.',strDay.getFullYear());
    }
//-----------------------------------
function EmailControl(f){
    if ((f=='' || f=='vas@email.cz') ||(f.indexOf('@') < 1 || f.indexOf('@') != f.lastIndexOf('@') || f.lastIndexOf('.') < f.lastIndexOf('@')+2  || f.lastIndexOf('.') > (f.length-3) || f.lastIndexOf('.') < (f.length-4))){
       alert('Nesprávný formát emailu');
       return false;
       }
    return true;
}
//-----------------------------------
function ShowSearchMenu(x){
    if (x == 1){
        document.all.SearchTable.style.display='';
    }else{
        document.all.SearchTable.style.display='none';
    }
}
//-----------------------------------
function LocInfo(){
    document.all.StateInfo2.innerHTML="  probíhá připojování...";
    var e = event.srcElement;
    var y = 0;
    var x = 0;
    while (typeof e == 'object' && e.tagName != 'BODY'){
          y += e.offsetTop;
          e = e.offsetParent;
    };
    x = (window.screen.width/2)+375
    document.all.StateInfo1.style.top=y-140;
    document.all.StateInfo1.style.left=x;
}
//-----------------------------------
function PositionInfo(strText){
    document.all.StateInfo3.innerHTML=strText;
    document.all.StateInfo2.innerHTML="  probíhá připojování...";
    var e = event.srcElement;
    var y = 0;
    var x = event.clientX;
    while (typeof e == 'object' && e.tagName != 'BODY'){
          y += e.offsetTop;
          e = e.offsetParent;
    };
    document.all.StateInfo1.style.top = y - 180;
    if (document.body.clientWidth < 933){
      document.all.StateInfo1.style.left = x + 100;
    }else{
      document.all.StateInfo1.style.left = 800;
    }
}
//-----------------------------------
function LocState(strCode,intCount){
    window.parent.frames['WinStat'].location.href="/InfoState.asp?ID="+strCode+"&CN="+intCount
    PositionInfo("On-line stav");
}
//-----------------------------------
function ChangeStorage(bState){
    if(bState){
        for(var i = 0; i < document.all['S'].length; i++){
            document.all['S'][i].value="0"
        }
    }else{
        for(var i = 0; i < document.all['S'].length; i++){
            document.all['S'][i].value="-1"
        }

    }
}
//-----------------------------------
function ChangeCloseout(bState){
    if(bState){
        for(var i = 0; i < document.all['C'].length; i++){
            document.all['C'][i].value="1"
        }
    }else{
        for(var i = 0; i < document.all['C'].length; i++){
            document.all['C'][i].value="3"
        }

    }
}
//-----------------------------------
function ControlUserDataSubmit(){
  if(document.UserDataForm.Firm.value == ""){alert("Vyplňte název firmy nebo jméno a příjmení.");return false}
  if(document.UserDataForm.Street.value == ""){alert("Vyplňte ulici.");return false}
  if(document.UserDataForm.City.value == ""){alert("Vyplňte město.");return false}
  if(document.UserDataForm.ZipCode.value == ""){alert("Vyplňte PSČ.");return false}
  if(document.UserDataForm.Phone.value == ""){alert("Vyplňte telefon.");return false}
  if(document.UserDataForm.Email.value == ""){alert("Vyplňte email.");return false}
  if(document.UserDataForm.Login.value == ""){alert("Vyplňte přihlašovací jméno.");return false}
  if(document.UserDataForm.Login.value.length < 5){alert("Přihlašovací jméno musí mít minimálně 5 znaků.");return false}
  if(document.UserDataForm.Password.value == ""){alert("Vyplňte heslo.");return false}
  if(document.UserDataForm.Password.value.length < 5){alert("Heslo musí mít minimálně 5 znaků.");return false}
  if(document.UserDataForm.Password2.value == ""){alert("Vyplňte potvrzení hesla.");return false}
  if(document.UserDataForm.Password2.value.length < 5){alert("Potvrzení hesla musí mít minimálně 5 znaků.");return false}
  if(document.UserDataForm.Password.value != document.UserDataForm.Password2.value){alert("Zadaná hesla se musí shodovat!");return false}
  return true
}
//-----------------------------------
function ControlDataOrder(){
  if(document.OrderForm.DeliveryType.value == "-"){alert("Vyberte způsob dopravy.");return false}
  if(document.OrderForm.PaymentType.value == "-"){alert("Vyberte způsob platby.");return false}
  if(!confirm("Prosím, přesvědčete se, jestli máte zvolenu správnou velikost vybraného zboží.\nPokud nevíte, jak velikost zvolit, klikněte na odkaz 'Jak nakoupit', kde se dozvíte vše potřebné.\n\nChcete svou objednávku potvrdit?"))
	return false;
  else
	return true;
  return true
}
//-----------------------------------
function ControlPassword(NameOne,NameTwo){
	if (document.all[NameOne].value != document.all[NameTwo].value)
	{
		alert("Špatně zadané heslo.");
		document.all[NameOne].value = "";
		document.all[NameTwo].value = "";
		document.all[NameOne].focus();
		return false;
	}
	else
	{
		return true;
	}
}
// ###   FCE PRO DIALOG ZADANI VOLITELNYCH PARAMETRU   ###
var gsFormSuffix, gsFormIndex;

function BuyOrSetVariableParams(sFormSuffix,sFormIndex) {
	var sSelects, nWindowHeight;
	gsFormIndex = sFormIndex;
	gsFormSuffix = sFormSuffix;

	sSelects = document.all["DivForPars" + sFormSuffix + sFormIndex].innerHTML;
	// ve skeletu musí být ve fci GetFormattedParams "ParamItem" psáno CASE-SENSITIVE !!!
	if (sSelects == "") {
		document.all["BuyForm" + sFormSuffix + sFormIndex].submit();
		PositionInfo('Objednávka');
	} else {
		// 22 je výška selectu - definováno raději i podle stylu!
		// nWindowHeight = 86 + 22 * (sSelects.split("ParamItem").length);
		document.all.DivForParams.innerHTML = document.all["DivForPars" + sFormSuffix + sFormIndex].innerHTML;
		document.all.ParamCaption.innerText = document.all["BuyForm" + sFormSuffix + sFormIndex].NameItem.value;
		document.all.ParamTbl.style.top =  window.event.srcElement.offsetTop - 110;
		document.all.ParamTbl.style.left =  window.event.srcElement.offsetLeft - 130;
		document.all.ParamTbl.style.display = 'inline';
	}
}

function CopyParamsBack() {
	document.all["DivForPars" + gsFormSuffix + gsFormIndex].innerHTML = document.all.DivForParams.innerHTML;
	document.all["BuyForm" + gsFormSuffix + gsFormIndex].submit();
	PositionInfo('Objednávka');
}
