//zjisteni IE prohlizece a dany do globalni promenne
var IE= null;
var ua = navigator.appName.toLowerCase();
if(ua.indexOf('explorer')>-1 ) {IE=true;}
var objItem;
//---vrati top umisteni---------------------
function returnTop(strId){
	var y = 0;
	if(typeof objGet(strId) == 'object'){
		var objElem = objGet(strId);
		y = parseFloat(objElem.offsetHeight);
		while(typeof objElem == 'object' && objElem.tagName != 'BODY'){
			y += objElem.offsetTop;
			objElem = objElem.offsetParent;
		};
	}
	return y;
}
//----kontrola hledani-----------------------
function ContrSearch(strText){
	if(strText.length < 2){
		alert('Zadejte aspoň 2 znaky.');
		return false;
	}else{
		return true;
	}
}
//----prace s querystringem------------------
function getQuery(sName){
	var arrTemp = window.location.search.substr(1).split("&");
	var arrHttp = new Array();
	for(var i = 0; i < arrTemp.length; i++){
		arrHttp[arrTemp[i].split("=")[0]] = unescape(arrTemp[i].split("=")[1]);
		}
	return arrHttp[sName]
}
//----------------------------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;
}
//----Cookies-------
function SaveCookies(Name, Value, Validity){
	var Cas = new Date();
	Validity = Validity*86400000;
	Cas.setTime(Cas.getTime()+Validity);
	document.cookie=Name+"="+escape(Value)+"; expires="+Cas.toGMTString()+"; path=/";
}
function LoadSubCookies(Name,SubName){
	var arrTemp = LoadCookies(Name).split("&");
	var arrCook = new Array();
	for(var i = 0; i < arrTemp.length; i++){
		arrCook[arrTemp[i].split("=")[0]] = unescape(arrTemp[i].split("=")[1]);
		}
	return arrCook[SubName]
	}
function LoadCookies(Name)
{
	var Data = " "+document.cookie+";";
	var NameCookies = " "+Name+"=";
	var End, Result;
	var Begin = Data.indexOf(NameCookies);
	if (Begin!=-1){
		Begin+=NameCookies.length;
		End = Data.indexOf(";", Begin);
		Result = Data.substring(Begin, End);
		Result = unescape(Result);
	} else {
		Result = 0;
	}
	return Result;
}
//-----------------
function OpenWnd(strURL){
         var objWnd = window.open(strURL,"InfoDetail","scrollbars=no,resizable=yes,height=500,width=400,left=10,top=10");
         objWnd.focus();
}
function GetCetelem(intPrice){
		var nW = 450;
		var nH = 280;
		var posW;
		var posH;
		posW = (document.body.clientWidth/2) - (nW/2)
		posH = (screen.height/2) - (nH/2)
		var objWin = window.open("/Secure/WebCalculatorCetelem.asp?price=" + intPrice,"Info","scrollbars=no,resizable=no,height="+nH.toString()+"px,width="+nW.toString()+"px,left="+posW.toString()+"px,top="+posH.toString()+"px");
		objWin.focus();
}
function OpenWin(strURL,nW,nH){
		var posW
		var posH
		posW = (document.body.clientWidth/2) - (nW/2)
		posH = (screen.height/2) - (nH/2)
		var objWin = window.open(strURL,"Info","scrollbars=no,resizable=yes,height="+nH.toString()+"px,width="+nW.toString()+"px,left="+posW.toString()+"px,top="+posH.toString()+"px");
		objWin.focus();
}
function OpenHref(strURL){
	var objWin = window.open(strURL,"Info","scrollbars=yes,resizable=yes,height=500px,width=650px,left=10px,top=10px");
	return (typeof(objWin)!="object")?true:false;
}
function OpenUrl(strURL,nW,nH,sScroll){
	var objWin = window.open(strURL,"Info","scrollbars="+sScroll+",resizable=yes,height="+nH+"px,width="+nW+"px,left=10px,top=10px");
	return (typeof(objWin)!="object")?true:false;
}
function ControlNumber(){
     if ((event.keyCode != 43) && ( (event.keyCode < 48) || (event.keyCode > 57) ) ) event.returnValue = false;
}
function DelSpace(strId){
	var Temp = objGet(strId).value
	for(var i = 0; i < Temp.length; i++){
		if(Temp.indexOf(' ') > 0){Temp = Temp.replace(' ','')}
	}
	objGet(strId).value = Temp
}
function ControlPhone(strId){
	DelSpace(strId);
	var Temp = objGet(strId).value
	if(Temp.length > 13 && Temp.substring(0,1) == '+'){Temp = Temp.replace(Temp.substring(0,4),'')}
	objGet(strId).value = Temp
}
//----------info okno-------------------------------------------------------
function InfoWindow(strAddress) {
       showModalDialog(strAddress,"Info","status:no; center:yes; help:no; minimize:no;dialogWidth=450pt;dialogHeight=320pt");
}
function Wlh(strAddress) {
       window.location.href = strAddress;
}
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 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
	}
}

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.documentElement.scrollTop + 50;
        }
        x = (x-175).toString() + "px"
        y = (y-140).toString() + "px"
        document.getElementById('StateInfo1').style.top = y;
		document.getElementById('StateInfo1').style.left = "772px";
}

function LocState(strCode,intCount,oX,oY){
    window.parent.frames['WinStat'].location.href="/InfoState.asp?ID="+strCode+"&CN="+intCount
	PositionInfo("On-line stav",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.Country.value == ""){alert("Vyberte prosím stát.");return false}
	if(document.UserDataForm.Firm.value == ""){alert("Vyplňte název firmy (jméno a příjmení).\n\nV případě problémů kontaktujte registrace@alzasoft.cz");return false}
	if(document.UserDataForm.Street.value == ""){alert("Vyplňte ulici.\n\nV případě problémů kontaktujte registrace@alzasoft.cz");return false}
	if(document.UserDataForm.City.value == ""){alert("Vyplňte město.\n\nV případě problémů kontaktujte registrace@alzasoft.cz");return false}
	if(document.UserDataForm.ZipCode.value == ""){alert("Vyplňte PSČ.\n\nV případě problémů kontaktujte registrace@alzasoft.cz");return false}
	if(document.UserDataForm.Phone.value == ""){alert("Vyplňte telefon.\n\nV případě problémů kontaktujte registrace@alzasoft.cz");return false}
	if(document.UserDataForm.Email.value == ""){alert("Vyplňte prosím email.\n\nV případě problémů kontaktujte registrace@alzasoft.cz");return false}
	if(document.UserDataForm.Login.value == ""){alert("Vyplňte přihlašovací jméno.\n\nV případě problémů kontaktujte registrace@alzasoft.cz");return false}
	if(document.UserDataForm.Login.value.length < 5){alert("Přihlašovací jméno musí mít minimálně 5 znaků.\n\nV případě problémů kontaktujte registrace@alzasoft.cz");return false}
	if(document.UserDataForm.Password.value == ""){alert("Vyplňte heslo.\n\nV případě problémů kontaktujte registrace@alzasoft.cz");return false}
	if(document.UserDataForm.Password.value.length < 5){alert("Heslo musí mít minimálně 5 znaků.\n\nV případě problémů kontaktujte registrace@alzasoft.cz");return false}
	if(document.UserDataForm.Password.value != document.UserDataForm.PasswordControl.value){alert("Špatně zadané heslo.Zadejte prosím znovu.");return false}
	// if(document.UserDataForm.DeliveryType.value == ""){alert("Vyberte způsob dopravy.");return false}
	return EmailControl(document.UserDataForm.Email.value);
	return true
}
function ControlDataOrder(sNoStor,sNoStock,sLongNo){
	if(document.OrderForm.DeliveryPayment.value == "0"){alert("Vyberte způsob dopravy a platby.");return false}
	if(intDelActual == 218 && document.OrderForm.InfoText.value == "" ){alert("Do pole \"Upřesňující a doplňující informace\" uveďte prosím datum a minimálně čtyřhodinový interval pro doručení Vaší objednávky.");return false}
	if(intDelActual != 219){
		if(document.OrderForm.DeliveryFirm.value == "" && document.OrderForm.DeliveryName.value == ""){alert("Zadejte název firmy nebo jméno a příjmení v dodací adrese.");return false}
		if(document.OrderForm.DeliveryCity.value == ""){alert("Zadejte město v dodací adrese.");return false}
		if(document.OrderForm.DeliveryZipCode.value == ""){alert("Zadejte PSČ v dodací adrese.");return false}
	}
	if(sNoStock.length > 0){alert("Položky zboží " + sNoStock + " nejsme schopni dodat ani objednat do konce roku 2005, odstraňte prosím tyto položky z Vašeho košíku, vyberte alternativní skladové produkty a odešlete košík znovu.\n\nZboží " + sNoStock + " bude možno objednat až po 1.lednu 2006.");return false}
	if(sLongNo.length > 0){alert("Produkty " + sNoStock + " jsou dočasně nedostupné a není je možné momentálně objednat.\n\nVyřaďte je prosím z košíku a vyberte alternativní zboží.");return false}
	if(sNoStor.length > 0){
		if(window.confirm("Zboží " + sNoStor + " není v tuto chvíli skladem.\n-----------------\nOpravdu si přejete odeslat košík ke zpracování?")){
			return true;
			}else{
			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;
  }
}
//zahlasovani ankety funguje pod netscapem(4.7+) mozilou(1.3) ie....
function VoteInquiry(plngAns){
	document.forms.frmInq.InqAns.value = plngAns;
	document.forms.frmInq.submit();
}
