function onResize_Body()
{
	var nLeft = document.body.offsetWidth / 2 + 196;

//	if(typeof document.all.idFloatSearch == 'object')	document.all.idFloatSearch.style.left = nLeft;
	if(typeof document.all.StateInfo1 == 'object')		document.all.StateInfo1.style.left = nLeft;
}

function OpenWnd(strURL){
         var objWnd = window.open(strURL,"InfoDetail","scrollbars=no,height=500,width=400,left=10,top=10");
         objWnd.focus();
}
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 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-100;
    document.all.StateInfo1.style.left = x+10//document.body.offsetWidth / 2 + 196
    
//    if (document.body.clientWidth < 933){
//      document.all.StateInfo1.style.left=x-150;
//    }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){
		document.all['S'].value="0"
//        for(var i = 0; i < document.all['S'].length; i++){
//            document.all['S'][i].value="0"
//        }
    }else{
		document.all['S'].value="-1"
//        for(var i = 0; i < document.all['S'].length; i++){
//            document.all['S'][i].value="-1"
//        }

    }
}
function ChangeCloseout(bState){
    if(bState){
		document.all['C'].value="1"
//        for(var i = 0; i < document.all['C'].length; i++){
//            document.all['C'][i].value="1"
//        }
    }else{
		document.all['C'].value="3"
//        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 == "")& 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}
  return true
}
function ControlDataOrder(){
  if(document.OrderForm.DeliveryType.value == "-"){alert("Vyberte způsob dopravy.");return false}
  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;
  }
}

function Price_ChangeSubmitTitle (objBuy, CountID, Price, DPH)
{
	var Count, SumNoDPH
	Price = Price.replace(',','.')
	if (typeof objBuy == 'object' && typeof document.all[CountID] == 'object' && (!isNaN(Price)) && (!isNaN(DPH)))
	{
		Count = document.all[CountID].value;
		if (isNaN(Count)) return;
		SumNoDPH = Count * Price
		
		
		if (DPH==5) DPH='05'
		SumPrice = parseInt(((1+'.'+DPH)*Price*Count)*10) / 10
		SumPrice = SumPrice.toString()
		if (SumPrice.indexOf('.')>1)	{SumPrice += '0'}
		DPH = parseInt(DPH)
		if (DPH==0)	{objBuy.title = 'Vložit do košíku\t: '+Count+' ks\nCelkem\t\t: '+FormatPrice(SumPrice)+' Kč'}
		else					{objBuy.title = 'Vložit do košíku\t\: '+Count+' ks\nCena bez DPH\t: '+FormatPrice(SumNoDPH)+' Kč\nDPH ('+DPH+'%)\t: '+FormatPrice(SumPrice-SumNoDPH)+'%\n\nCelkem...\t: '+FormatPrice(SumPrice)+' Kč s DPH'}
	}
}

function FormatPrice(v)
{
	var nKor, nHal
	v = v.toString();
	v = v.replace(',','.');
	if (!isNaN(v))
	{
		v = Math.round(v*10);
		v = v.toString();
		nHal = v.substring(v.length-1,v.length) + '0';	if(nHal=='00')nHal='--';
		nKor = v.substring(0,v.length-1);				if(nKor=='')nKor='0';
		return nKor + ',' + nHal;
	}
}

//---- PriceList -------------------------
function DelProducer(nProd) {
	if (nDeleted==nProducers-1) return;
	document.all["bEnabled" + nProd].value='0';
	document.all["Producer" + nProd].style.display="none";
	nDeleted += 1;
}

function GetCategoriesIdNameForSelect(nTree,bAlsoDisabled,nIndex,nUserType) {
	var arrData,arrSubData,saCatID,nProID,sProNM;
	var el,r;
	nProID = document.all["ProdID" + nIndex].value;
	sProNM = document.all["ProdID" + nIndex].options(document.all["ProdID" + nIndex].selectedIndex).innerText;
	saCatID = document.all["CatID" + nIndex].value;
	var strReturn = showModalDialog("/Includes/PriceListSelectCatsOfProd.asp?TREE="+nTree+"&ProID="+nProID+"&DIS="+bAlsoDisabled+"&CatIDs="+saCatID+"&ADM="+nUserType+"&ProNM="+sProNM,"Info","status:no; center:yes; help:no; minimize:no;dialogWidth=350pt;dialogHeight=300pt");
	if (typeof(strReturn) == 'undefined') return;
	with(document.all["Categ"+nIndex]){
	       r = options.length;
	       for (var i=0; i<r; i++) {
	               options.remove(options.length-1);
	       }
	}
	arrData = strReturn.split("*");
	saCatID = "";
	for (var i=0; i<arrData.length-1; i++) {
	    arrSubData = arrData[i].split("/")
	    el = document.createElement("OPTION")
	    el.value = arrSubData[0];
	    el.text = arrSubData[1];
		saCatID += arrSubData[0] + "$"
	    document.all["Categ"+nIndex].options.add(el);
	}
	document.all["CatID"+nIndex].value = saCatID.substr(0,saCatID.length - 1);
	if (strReturn == "") {
		document.all["Categ"+nIndex].style.display = "none";
		document.all["ChooseCateg"+nIndex].style.display  = "inline";
	} else {
		document.all["Categ"+nIndex].style.display = "inline";
		document.all["ChooseCateg"+nIndex].style.display  = "none";
	}
}
function ClearCategories(nIndex) {
	var r;
	with(document.all["Categ"+nIndex]){
	       r = options.length;
	       for (var i=0; i<r; i++) {
	               options.remove(options.length-1);
	       }
	}
	document.all["CatID"+nIndex].value = "";
	document.all["Categ"+nIndex].style.display = "none";
	document.all["ChooseCateg"+nIndex].style.display  = "inline";
}
