//zjisteni IE prohlizece a dany do globalni promenne
var IE = null;

var gstrDialogText = "";
var oHeight;
var oWidth;


var ua = navigator.appName.toLowerCase();
if(ua.indexOf('explorer')>-1 ) {IE=true;}
var objItem;
//----------------------------x = nazev prvku
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;
}
//presmerovani po vyberu vyrobce-------------
function redirectForProducer(strAddress){
	window.location.href=strAddress
	}

function ControlScript(strScript,strValue,strId){
	window.frames['WinStat'].location.href='/'+strScript+'.asp?value='+strValue+'&id='+strId;
}

//problikavani po prdani do kosiku------
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); 
}
//menu horni--------------------------------------------------------------------
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+20;
      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);
}


function StandartDialog(strText){
	if(gstrDialogText.length == 0){
		gstrDialogText = strText;
	}else{
		gstrDialogText = gstrDialogText + "<br /><br />" + strText;
	}
	strText = strText.replace('\n','<br />')
	var strTextDialog = '<div class="tac" id=""DialogTemp"">' + gstrDialogText + '</div><br />';
	Dialog(0,0,3,strTextDialog,2,250,'');
}
function Dialog(oX,oY,intTypXY,strText,intButt,intWidth,strScript){
    var y = 0;
    var x = 0;
    SelectHidden(1);
	if(intTypXY == 1){
        if (IE){
                var e = event.srcElement;
                while (typeof e == 'object' && e.tagName != 'BODY'){
                        y += e.offsetTop;
                        x += e.offsetLeft;
                        e = e.offsetParent;
                };
        }else{
                var y = oY + document.documentElement.scrollTop;
                var x = oX - 60;
        }
        x = (x).toString() + "px"
        y = (y-140).toString() + "px"
	}else if(intTypXY == 2){
		if (IE){
			var y = oY + document.documentElement.scrollTop;
			var x = oX;
			x = (x).toString() + "px"
			y = (y).toString() + "px"
		}else{
			var y = oY + 50 + document.documentElement.scrollTop;
			var x = oX;
			x = (x).toString() + "px"
			y = (y).toString() + "px"
		}
    }else{
    	ActualSize()
    	oX = oWidth;
    	oY = oHeight;
        x = ((oX-intWidth)/2).toString() + "px"
        y = ((oY/3) + document.documentElement.scrollTop).toString() + "px"	    
    }

	if(intButt == '1'){
		strText = strText + '<div class="tac"><input type="button" value="ANO" onclick="' + strScript + '" class="inpGreenSm w80" /> <input type="button" onclick="DialogClear();" value="NE" class="inpGreySm w80" /></div>';
	}
	if(intButt == '2'){
		strText = strText + '<div class="tac"><input onclick="DialogClear();" type="button" value="OK" class="inpGreenSm w80" /></div>';
	}
	if(intButt == '3'){
		strText = strText + '<div class="tac"><input type="button" value="ANO" onclick="DialogClear();" class="inpGreenSm w80" /> <input type="button" value="NE" onclick="' + strScript + '" class="inpGreySm w80" /></div>';
	}
	if(intButt == '4'){
		strText = strText + '<div class="tac"><input type="button" value="OK" onclick="' + strScript + '" class="inpGreenSm w80" /> <input type="button" value="Zavřít" onclick="DialogClear();" class="inpGreySm w80" /></div>';
	}
	if(intButt == '5'){
		strText = strText + '<div class="tac"><input type="button" value="ANO" onclick="DialogClear();" class="inpGreySm w80" /> <input type="button" value="NE" onclick="' + strScript + '" class="inpGreySm w80" /></div>';
	}
	if(intButt == '6'){
		strText = strText + '<div class="tac"><input onclick="' + strScript + '" type="button" value="OK" class="inpGreenSm w80" /></div>';
	}
    intWidth = intWidth.toString() + "px";

	objGet('DialogSub').style.width = intWidth;
	objGet('DialogSub').innerHTML = strText;
    objGet('Dialog').style.top = y;
	objGet('Dialog').style.left = x;
	objGet('Dialog').className = 'DialogActiv'
}

function DialogClear() {
    objGet('Dialog').className = 'Dialog'
    objGet('DialogSub').innerHTML = "";
    gstrDialogText = "";
    SelectHidden(2);
}

function SelectHidden(intAction) {
    if (IE) {
        if (navigator.appVersion.indexOf('MSIE 7') < 0) {
            var allObjects = document.getElementsByTagName("select");
            for (var i = 0; i < allObjects.length; i++) {
                if (intAction == 1) { allObjects[i].style.visibility = 'hidden' }
                if (intAction == 2) { allObjects[i].style.visibility = 'visible' }
            }
        }
    }
}

function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;

}

function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}

function ActualSize() {
    oHeight = winH();
    oWidth = winW();
}

function winH() {
    if (window.innerHeight)
        return window.innerHeight;
    else if
   (document.documentElement &&
   document.documentElement.clientHeight)
        return document.documentElement.clientHeight;
    else if
   (document.body && document.body.clientHeight)
        return document.body.clientHeight;
    else
        return screen.height;
}
function winW() {
    if (window.innerWidth)
        return window.innerHeight;
    else if
   (document.documentElement &&
   document.documentElement.clientWidth)
        return document.documentElement.clientWidth;
    else if
   (document.body && document.body.clientWidth)
        return document.body.clientWidth;
    else
        return screen.width;
}

//platby------------------------------------------------   && document.getElementById && document.childNodes
function ShowPayment(strPayment){
	var strHtml,arrPayment,arrSubPayment
	if(IE){
		if(typeof(strPayment) != "string"){
			document.all.PaymentArea.innerHTML = "";	
			document.all.DeliveryPriceCell.innerHTML = "";
			document.OrderForm.DeliveryPayment.value = "0";
		}else{
			strHtml = "";
			arrPayment = strPayment.split("#");
			for(var i=0; i<arrPayment.length-1; i++){
				arrSumPayment = arrPayment[i].split("|");
				strHtml += "<input type='radio' name='PaymentSel' onClick='ShowPriceDelivery(\"" + arrSumPayment[2] + "\","+arrSumPayment[3]+","+arrSumPayment[0]+");'>" + arrSumPayment[1] + "<br>";		
			}	
			document.all.PaymentArea.innerHTML = strHtml;
			document.all.DeliveryPriceCell.innerHTML = "";
			document.OrderForm.DeliveryPayment.value = "0";
		}		
	}else{
		if(typeof(strPayment) != "string"){
			document.getElementById("PaymentArea").innerHTML = "";	
			document.getElementById("DeliveryPriceCell").innerHTML = "";
			document.OrderForm.DeliveryPayment.value = "0";
		}else{
			strHtml = "";
			arrPayment = strPayment.split("#");
			for(var i=0; i<arrPayment.length-1; i++){
				arrSumPayment = arrPayment[i].split("|");
				strHtml += "<input type='radio' name='PaymentSel' onClick='ShowPriceDelivery(\"" + arrSumPayment[2] + "\","+arrSumPayment[3]+","+arrSumPayment[0]+");'>" + arrSumPayment[1] + "<br>";		
			}	
			document.getElementById("PaymentArea").innerHTML = strHtml;
			document.getElementById("DeliveryPriceCell").innerHTML = "";
			document.OrderForm.DeliveryPayment.value = "0";
		}
	}
}
function ShowPriceDelivery(intPrice,intAlert,pkDelPayGroup){
		alert(arrPaymentLegend[intAlert]);
		if(IE){
			document.all.DeliveryPriceCell.innerHTML = "Cena dopravy: " + intPrice + " Kč (bez DPH)";
			document.OrderForm.DeliveryPayment.value = pkDelPayGroup;	
		}else{
			document.getElementById("DeliveryPriceCell").innerHTML = "Cena dopravy: " + intPrice + " Kč (bez DPH)";
			document.OrderForm.DeliveryPayment.value = pkDelPayGroup;
		}
}
//---------------------------------------------------------------------------
function OpenWnd(strURL){
         var objWnd = window.open(strURL,"InfoDetail","scrollbars=no,height=500,width=400,left=10,top=10");
         objWnd.focus();
}
function OpenHref(strURL){
	var objWin = window.open(strURL,"InfoDetail","scrollbars=no,height=630,width=630,left=10,top=10");
	return (typeof(objWin)!="object")?true:false;
}
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 Lsc(nId,nActId,nProvision){
	if(document.getElementById('i'+nId) != null){
		if(document.getElementById('i'+nId).src.indexOf("/Img/Plus.gif") > -1){
			window.frames['WinStat'].location.replace('/WriteSubTree.asp?Id='+nId+'&Act='+nActId+'&Prv='+nProvision);
		}else{
			document.getElementById('i'+nId).src = "/Img/Plus.gif";
			document.getElementById('s'+nId).style.display = "none";
		}
	}
}
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,oX,oY){
        document.getElementById('StateInfo3').innerHTML=strText;
        document.getElementById('StateInfo2').innerHTML="  probíhá připojování...";
        var x = oX;
        if (IE){
                var e = event.srcElement;
                var y = 0;
                while (typeof e == 'object' && e.tagName != 'BODY'){
                        y += e.offsetTop;
                        e = e.offsetParent;
                };
        }else{
                var y = oY + document.body.scrollTop;    
        }
		y = y - 140;
		x = x - 175;
		y = y.toString() + 'px';
		x = x.toString() + 'px';   
        document.getElementById('StateInfo1').style.top=y;
        document.getElementById('StateInfo1').style.left=x;
}
function LocState(strCode,intCount,oX,oY){
    window.parent.frames['WinStat'].location.href="/InfoState.asp?ID="+strCode+"&CN="+intCount
    PositionInfo("Stav na skladě",oX,oY);
}
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 == "")& 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 ControlUserDataSubmit2() {
    var emailre = /^[+_A-Za-z0-9](([_\.\-]?[+_a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/;
    var streetre = /(.*) [0-9](.*)/;

    if (document.UserDataForm.Login.value == "") {
        alert("Vyplňte email.");
        return false
    } else {
        if (document.UserDataForm.Login.value.search(emailre) != 0) { alert('Email je ve špatném tvaru'); 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.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 }
    
    return true
}




function ControlDataOrder(){
  	if(document.OrderForm.DeliveryPayment.value == "0"){alert("Vyberte způsob dopravy a platby.");return false}
  return true
}
function ControlSubmit(){
  if((document.OrderForm.FirstName.value == "" ||document.OrderForm.LastName.value == "")& document.OrderForm.Firm.value == ""){alert("Vyplňte název firmy nebo jméno a příjmení.");return false}
  if(document.OrderForm.Street.value == ""){alert("Vyplňte ulici.");return false}
  if(document.OrderForm.City.value == ""){alert("Vyplňte město.");return false}
  if(document.OrderForm.ZipCode.value == ""){alert("Vyplňte PSČ.");return false}
  if (document.OrderForm.Phone.value == "" & document.OrderForm.Email.value == "") { alert("Vyplňte telefon nebo email."); return false }
  return true
}
