//zjisteni IE prohlizece a dany do globalni promenne
var IE= null;
var ua = navigator.appName.toLowerCase();
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.all)) return eval('document.all.'+x);
	else if (Boolean(document.getElementById)) return document.getElementById(x);
	else if (Boolean(document.ids)) return eval('document.ids.'+x);
	else return null;
}

function ControlScript(strScript, strValue, strId) {
    window.frames['WinStat'].location.href = '/' + strScript + '.asp?value=' + strValue + '&id=' + strId;
}


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 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;
}

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 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);
}


//menu--------------------------------------------------
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";
        }
        if (document.getElementById("ch"+id+"b") != null){
        if (id != objId) document.getElementById("ch"+id+"b").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' && objElem.tagName != 'HTML'){
          x += objElem.offsetLeft;
          y += objElem.offsetTop;
          objElem = objElem.offsetParent;
      }
      allHiddenMenu(hID);
      if(IE){
	  	y = y+19;
	  	x = x+20;
	  }else{
	  	y = y+5;
	  	x = x;
	  }
      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);
}
//platby------------------------------------------------
function ShowPayment(strPayment){
	var strHtml,arrPayment,arrSubPayment
		if(typeof(strPayment) != "string"){
			objGet("PaymentArea").innerHTML = "";	
			objGet("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>";		
			}	
			objGet("PaymentArea").innerHTML = strHtml;
			objGet("DeliveryPriceCell").innerHTML = "";
			document.OrderForm.DeliveryPayment.value = "0";
		}
}
function ShowPriceDelivery(intPrice,intAlert,pkDelPayGroup){
		alert(arrPaymentLegend[intAlert]);
		objGet("DeliveryPriceCell").innerHTML = "Cena dopravy: " + intPrice + " Kč (bez DPH)";
		document.OrderForm.DeliveryPayment.value = pkDelPayGroup;
}
//-------------------------------------------------------
function ShowDate(strItem) {
     var strReturn = showModalDialog("/SelectDate.htm","","status:no; center:yes; help:no; minimize:no;dialogWidth=250pt;dialogHeight=200pt");
     if (strReturn == undefined){return;}
     strItem.value = strReturn;
}
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,oX,oY){
        document.getElementById('StateInfo3').innerHTML=strText;
        document.getElementById('StateInfo2').innerHTML="  probíhá připojování...";
        var x = oX-400;
        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.documentElement.scrollTop + 50;
        }
        x = (x+20).toString() + "px"
        y = (y-140).toString() + "px"
        document.getElementById('StateInfo1').style.top = y;
		document.getElementById('StateInfo1').style.left = x;
}

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}
	return true
}
function ControlDataOrder(){
	if(document.OrderForm.Firm.value == ""){alert("Zadejte název firmy nebo jméno a příjmení.");return false}
	if(document.OrderForm.Street.value == ""){alert("Zadejte ulici.");return false}
	if(document.OrderForm.City.value == ""){alert("Zadejte město.");return false}
	if(document.OrderForm.ZipCode.value == ""){alert("Zadejte PSČ.");return false}
	if (document.OrderForm.Phone.value == "") { alert("Zadejte telefon."); return false }
	if(document.OrderForm.Email.value == ""){alert("Zadejte email.");return false}
	if(document.OrderForm.DeliveryPayment.value == "0"){alert("Vyberte způsob dopravy a platby.");return false}
	return true
}
function ControlUserForm(){
	if(document.OrderForm.DeliveryType.value == "-"){alert("Vyberte způsob dopravy.");return false}
	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 == "") { alert("Vyplňte telefon."); return false }
	if(document.OrderForm.Email.value == ""){alert("Vyplňte email.");return false}
	if(document.OrderForm.DeliveryPayment.value == "0"){alert("Vyberte způsob dopravy a platby.");return false}
  
  return true

}
function WriteUsControlEmail(strAddr){
		if(strAddr != ""){return EmailControl(strAddr)}	
}	
function RunEmailControl(adresa){
	 re = /^[+_a-zA-Z0-9-]+(\.[+_a-zA-Z0-9-]+)*@[\.a-zA-Z0-9-]+\.[a-zA-Z0-9-]{2,4}$/;
    return adresa.search(re) == 0;
}
function EmailControl(address){
	if(RunEmailControl(address)){
		return true;
	}else{
		alert('Špatně vyplněný e-mail.')
		return false
	}
}  
