//zjisteni IE prohlizece a dany do globalni promenne
var IE= null;
var ua = navigator.appName.toLowerCase();
if(ua.indexOf('explorer')>-1 ) {IE=true;}
//------------------
function addBookmark(url,title){
	if (window.sidebar){
		window.sidebar.addPanel(title, url,"");
	}else if (IE){
		window.external.AddFavorite(url, title);
	}else{
	 	alert('Váš prohlížeč bohužel nepodporuje automatické vkládání do oblíbených položek.');
	}
}
//---------------------
function getObj(name) { // zjisti dostupný objekt pro práci se stylem dokumentu
  if (document.getElementById) 
    return document.getElementById(name).style;
  else
    if (document.all) 
      return document.all[name].style;
    else
      if (document.layers) 
        return document.layers[name];
}
function objGet(x) {
	if (Boolean(document.getElementById)) return document.getElementById(x);
	else if (Boolean(document.all)) return eval('document.all.'+x);
	else if (Boolean(document.ids)) return eval('document.ids.'+x);
	else return null;
}
function BlikFunction() { 
  BlikOk=true; 
  if (BlikCount==0 && BlikOk==true){
    BlikObj.visibility="hidden";BlikOk=false;BlikCount=1
  } 
  if (BlikCount==1 && BlikOk==true){
    BlikObj.visibility="visible";BlikOk=false;BlikCount=0
  } 
  setTimeout('BlikFunction()',300); 
}
function goToCase(){
	window.location.href="/Order.asp?OrdSub=ok"	
}

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=auto,height=400,width=400,left=10,top=10");
         objWnd.focus();
}
function OpenWin(strURL){
         var objWin = window.open(strURL,"Info","scrollbars=yes,height=400,width=550,left=10,top=10");
         objWin.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;
}
//----------info okno-------------------------------------------------------
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-140;
    if (document.body.clientWidth < 933){
      document.all.StateInfo1.style.left=x-175;
    }else{
      document.all.StateInfo1.style.left=780;
    }
}
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.FirstName.value == "" || document.UserDataForm.LastName.value == ""){alert("Vyplňte jméno a příjmení.");return false}
  if(document.UserDataForm.Street.value == ""){alert("Vyplňte ulici.");return false}
  if(document.UserDataForm.HouseNo.value == ""){alert("Vyplňte číslo popisné (orientační).");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ě 8 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ě 8 znaků.");return false}
  return true
}
function ControlDataOrder(){
  if(document.OrderForm.Street.value == ""){alert("Vyplňte ulici.");return false}
  if(document.OrderForm.HouseNo.value == ""){alert("Vyplňte číslo popisné (orientační).");return false}	
  if(document.OrderForm.DeliveryPayment.value == "0"){alert("Vyberte způsob dopravy a platby.");return false}
  return true
}
var IdTime;
var intMaxCount;
function allHiddenMenu(objId){
     window.clearTimeout(IdTime);
      IdTime=null;
      for (id=1; id<=intMaxCount; id++){
        if (document.getElementById("ch"+id) != null){
        if (id != objId) document.getElementById("ch"+id).style.visibility = "hidden";
        }
      }
}
function chHiddenMenu(chID,pID){
     window.clearTimeout(IdTime);
      IdTime=null;
      for (id=1; id<=intMaxCount; id++){
        if (document.getElementById("ch"+id) != null){
          if(id > pID && id != chID){document.getElementById("ch"+id).style.visibility = "hidden";}
        }
      }
}
function outObj(){
     IdTime = window.setTimeout("allHiddenMenu(intMaxCount)",300);
}
function onRoot(hID,ID){
      var objElem = document.getElementById(ID);
      var x = 0;
      var y = 0;
      while (typeof objElem == 'object' && objElem.tagName != 'BODY'){ 
          x += objElem.offsetLeft;
          y += objElem.offsetTop;
          objElem = objElem.offsetParent;
      }
      allHiddenMenu(hID);
      x = x-6;
      y = y+18;
      x = x.toString() + 'px';
      y = y.toString() + 'px';
      if(document.getElementById('ch'+hID)!= null ){
           document.getElementById('ch'+hID).style.left = x;
           document.getElementById('ch'+hID).style.top = y;
           document.getElementById('ch'+hID).style.visibility = "visible";
      }
}
function onChildren(chID,ID,pID){
      var objElem = ID.parentElement;
      var x = 0;
      var y = 0;
      x += parseFloat(objElem.offsetWidth);
      while (typeof objElem == 'object' && objElem.tagName != 'BODY'){ 
          x += objElem.offsetLeft;
          y += objElem.offsetTop;
          objElem = objElem.offsetParent;
      };
      chHiddenMenu(chID,pID);
      if(document.getElementById('ch'+chID)!= null ){
           document.getElementById('ch'+chID).style.left = x;
           document.getElementById('ch'+chID).style.top = y;
           document.getElementById('ch'+chID).style.visibility = "visible";
      }
}
function ClearTime(){
     window.clearTimeout(IdTime);
}
