﻿
var gCCompIDs = ''
var gCCompnTree = 1 //specialita elektrosveta
var goCurrentImg;
var gCompareOnClick = false; 
var	gTimer_cl
var gCl_ev
var dCl_iid
var	strFullPath = "http://www.elektrosvet.cz/"
var strDomain = "elektrosvet.cz"
var globalni_cislo = 0;
var sg = new Object();

var Br = new BrCheck()

function getE(objectID) {
	return document.getElementById(objectID);
}

function BrCheck()
{
	this.VER	= navigator.appVersion;
	this.AGENT	= navigator.userAgent;
	this.DOM	= document.getElementById ? true:false;

	this.OP5	= this.AGENT.indexOf("Opera 5")>-1							?true:false;
	this.OP6	= this.AGENT.indexOf("Opera 6")>-1							?true:false;
	this.OP7	= this.AGENT.indexOf("Opera 7")>-1							?true:false;
	this.OP		= (this.OP5 || this.OP6 || this.OP7);

	this.IE4	= (document.all && !this.DOM && !this.OP)					?true:false;
	this.IE5	= (this.VER.indexOf("MSIE 5")>-1 && this.DOM && !this.OP)	?true:false; 
	this.IE6	= (this.VER.indexOf("MSIE 6")>-1 && this.DOM && !this.OP)	?true:false;
	this.IE		= (this.IE4 || this.IE5 || this.IE6);

	this.NS4	= (document.layers && !this.DOM)							?true:false;
	this.NS7	= (this.DOM && parseInt(this.VER) >= 5 && this.AGENT.lastIndexOf('Netscape')<this.AGENT.lastIndexOf('7'))?true:false;
	this.NS6	= (this.DOM && parseInt(this.VER) >= 5 && !this.NS7)		?true:false;
	this.NS		= (this.NS4 || this.NS6 || this.NS7);

	return this;
}

function SelectSearchRadio(nId){
	var objForm = document.forms.dagFormSearch;
	
	objForm.filter[nId].checked = true;
	
	
}

function cl_min (ev) {
	if (window.event) {ev = window.event}
	var hi = document.getElementById("hi"+this.iid);
//	var td = hi.firstChild.firstChild.firstChild;
	hi.innerHTML = "<b style='COLOR: #AEB0C5'>" + this.sName + "</b><br><img src='" + this.thsrc + "'>"
//	img.src = this.thsrc;
	hi.style.width = this.thw;
	hi.style.height = this.thh;
	hi.style.left = (objOffsetX(document.getElementById("lhi"+this.iid))) + "px";
	hi.style.top = (objOffsetY(document.getElementById("lhi"+this.iid))-150) + "px";
	//this.offsetLeft; 
	//(objPos(this).x +10) + "px";
	//leftPosition(this) + "px";
	//this.offsehiop; 
	//(objPos(this).y + 10) + "px";
	//(topPosition(this) + 35) + "px";
	if (goCurrentImg){
		goCurrentImg.style.display = "none";
		ldiv = getE("l" + goCurrentImg.id);
		ldiv.className = "ll-product-line";
	}
	hi.style.display = "inline";
	ldiv = getE("l" + hi.id);
	ldiv.className = "ll-product-line-a";
	goCurrentImg = hi;
}

function cl_mout (ev, iid) {
	if (window.event) {ev = window.event}
	var hi = document.getElementById("hi"+iid);
	hi.style.display = "none";
}

function cl_timeout(){
		gTimer_cl = setTimeout("cl_mout(gCl_ev, gCl_iid);", 100);
}

function lf(n,ev,f,w,h,iid,sName){
	
//	if (Br.IE || Br.OP) {
		n.thsrc = f;
		n.thw = w;
		n.thh = h;
		n.iid = iid;
		n.sName = sName;
		gCl_ev = ev;
		gCl_iid = iid;
		n.onmouseout = cl_timeout;
		n.onmouseover = cl_min;
		n.onmouseover(ev);
//	}
}

function objOffsetX(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 objOffsetY(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 CCompChCli(o, id)
{
	
	var cd = getE("CompDiv");
	var PocetComp = 0;
	var q;
	var bCompOn = false;
//	if (o)
	if(o.id=='DetailCompare'){
		hidDetail = getE('hiDetailCompare');
		bCompOn = (hidDetail.value == 0);
		if (bCompOn){hidDetail.value = 1}else{hidDetail.value = 0}
	}
	else if(o.id.indexOf('Best') == -1){
		gCompareOnClick = true;
		bCompOn = (o.className=='bt-bs-arr-a' || o.className=='bt-cl-arr-a')
		if (bCompOn){
			if (o.className=='bt-bs-arr-a'){o.className='bt-bs-arr-b'; o.title='Již je porovnáván';}
			if (o.className=='bt-cl-arr-a'){o.className='bt-cl-arr-b'; o.title='Již je porovnáván';}
		}
		else
		{
			if (o.className=='bt-bs-arr-b'){o.className='bt-bs-arr-a'; o.title='Porovnat';}
			if (o.className=='bt-cl-arr-b'){o.className='bt-cl-arr-a'; o.title='Porovnat';}
		}
	}
	else
	{
		bCompOn = (o.className=='bt-bs-arr-a' || o.className=='bt-bs-arr-b')
		if (bCompOn){
			if (o.className=='bt-bs-arr-a'){o.className='bt-bs-arr-ap'; o.title='Porovnat';}
			if (o.className=='bt-bs-arr-b'){o.className='bt-bs-arr-bp'; o.title='Již je porovnáván';}
		}
		else
		{
			if (o.className=='bt-bs-arr-ap'){o.className='bt-bs-arr-a'; o.title='Porovnat';}
			if (o.className=='bt-bs-arr-bp'){o.className='bt-bs-arr-b'; o.title='Již je porovnáván';}
		}
	}
	
	//klikám-li v seznamu a stejný je i v nejprodávanějších, změnit i tam, a naopak
	secComp = getE("idCCompBest_" + id)
	if (secComp){
		if (bCompOn){
			if (secComp.className=='bt-bs-arr-a'){secComp.className='bt-bs-arr-ap'; o.title='Porovnat';}
			if (secComp.className=='bt-bs-arr-b'){secComp.className='bt-bs-arr-bp'; o.title='Již je porovnáván';}
		}
		else
		{
			if (secComp.className=='bt-bs-arr-ap'){secComp.className='bt-bs-arr-a'; o.title='Porovnat';}
			if (secComp.className=='bt-bs-arr-bp'){secComp.className='bt-bs-arr-b'; o.title='Již je porovnáván';}
		}
	}
	secComp = getE("idCComp_" + id)
	if (secComp){
		if (bCompOn){
			if (secComp.className=='bt-bs-arr-a'){secComp.className='bt-bs-arr-b'; o.title='Již je porovnáván';}
			if (secComp.className=='bt-cl-arr-a'){secComp.className='bt-cl-arr-b'; o.title='Již je porovnáván';}
		}
		else
		{
			if (secComp.className=='bt-bs-arr-b'){secComp.className='bt-bs-arr-a'; o.title='Porovnat';}
			if (secComp.className=='bt-cl-arr-b'){secComp.className='bt-cl-arr-a'; o.title='Porovnat';}
		}
	}
	//end klikám-li
	
	if (bCompOn)
	{
		if (gCCompIDs.indexOf('|'+id+'|') < 0)
			gCCompIDs += '|'+id+'|'

		if (gCCompIDs != '') {CCompOn()}
		if (gCCompIDs != '') {PocetComp = 1}
		q = gCCompIDs;
		while(q.indexOf('||') > -1) {
			q = q.replace('||', ',');  
			PocetComp = PocetComp + 1;
			}
			if (PocetComp == 1){sCountName = " produkt"}
			if (PocetComp > 1 & PocetComp < 5){sCountName = " produkty"}
			if (PocetComp > 4){sCountName = " produktů"}
//			cd.innerHTML = 'POROVNAT celkem ' + PocetComp + sCountName;
			cd.innerHTML = 'Porovnání: <a href="javascript: CCompGo()">' + PocetComp + ' zboží</a> (<a href="javascript: CCompDel()">odebrat</a>)';
	}
	else
	{
		gCCompIDs = gCCompIDs.replace('|'+id+'|', '');

		if (gCCompIDs == '') {CCompOff()}
		if (gCCompIDs != '') {PocetComp = 1}
		q = gCCompIDs;
		while(q.indexOf('||') > -1) {
			q = q.replace('||', ','); 
			PocetComp = PocetComp + 1;
		}
		if (gCCompIDs == '') {
//			cd.innerHTML = 'Žádne zboží k porovnání';
			cd.innerHTML = '';
			hidDetail = getE('hiDetailCompare');
			if (hidDetail) hidDetail.value = 0;
		}
		 else
		{
			if (PocetComp == 1){sCountName = " produkt"}
			if (PocetComp > 1 & PocetComp < 5){sCountName = " produkty"}
			if (PocetComp > 4){sCountName = " produktů"}
//			cd.innerHTML = 'POROVNAT celkem ' + PocetComp + sCountName;
			cd.innerHTML = 'Porovnání: <a href="javascript: CCompGo()">' + PocetComp + ' zboží</a> (<a href="javascript: CCompDel()">odebrat</a>)';
		}
	}
	
	InsertCookies('CComp'+gCCompnTree,gCCompIDs);
}

function CCompChOn()
{
	for (var i=1; ; i++){
		ch = getE("hidCComp_" + i);
		if (!ch) break;
		imgC = getE("idCComp_" + ch.value)
		if (imgC.className=='bt-bs-arr-b'){
			imgC.className='bt-bs-arr-a';
			imgC.title='Porovnat';
		}
		if (imgC.className=='bt-cl-arr-b'){
			imgC.className='bt-cl-arr-a'
			imgC.title='Porovnat';
		}
		if (gCCompIDs.indexOf('|'+ch.value+'|') > -1) {
			if (imgC.className=='bt-bs-arr-a'){
				imgC.className='bt-bs-arr-b';
				imgC.title='Již je porovnáván';
			}
			if (imgC.className=='bt-cl-arr-a'){
				imgC.className='bt-cl-arr-b';
				imgC.title='Již je porovnáván';
			}
		}
	}			
//best
	for (var i=1; ; i++){
		ch = getE("hidCCompBest_" + i);
		if (!ch) break;
		imgC = getE("idCCompBest_" + ch.value)
		if (imgC.className=='bt-bs-arr-ap'){
			imgC.className='bt-bs-arr-a';
			imgC.title='Porovnat';
		}
		if (imgC.className=='bt-bs-arr-bp'){
			imgC.className='bt-bs-arr-b';
			imgC.title='Již je porovnáván';
		}
		if (gCCompIDs.indexOf('|'+ch.value+'|') > -1) {
			if (imgC.className=='bt-bs-arr-a'){
				imgC.className='bt-bs-arr-ap';
				imgC.title='Porovnat';
			}
			if (imgC.className=='bt-bs-arr-b'){
				imgC.className='bt-bs-arr-bp';
				imgC.title='Již je porovnáván';
			}
		}
	}			
}

function CCompChOff()
{
	for (var i=1; ; i++){
		ch = getE("hidCComp_" + i);
		if (!ch) break;
		imgC = getE("idCComp_" + ch.value)
		if (imgC.className=='bt-bs-arr-b'){
			imgC.className='bt-bs-arr-a';
			imgC.title='Porovnat';
		}
		if (imgC.className=='bt-cl-arr-b'){
			imgC.className='bt-cl-arr-a';
			imgC.title='Porovnat';
		}
	}
//best
	for (var i=1; ; i++){
		ch = getE("hidCCompBest_" + i);
		if (!ch) break;
		imgC = getE("idCCompBest_" + ch.value)
		if (imgC.className=='bt-bs-arr-ap'){
			imgC.className='bt-bs-arr-a';
			imgC.title='Porovnat';
		}
		if (imgC.className=='bt-bs-arr-bp'){
			imgC.className='bt-cl-arr-b';
			imgC.title='Již je porovnáván';
		}
	}
}

function CCompGo()
{
	var q = gCCompIDs;
	
	while(q.indexOf('||') > -1) q = q.replace('||', ',')
	while(q.indexOf('|') > -1) q = q.replace('|', '')
	
	if (gCCompIDs==''){alert('Zvolte si zboží k porovnání')}
	else {document.location = strFullPath + '/Compare.asp?DPGS='+q+'&ntree='+gCCompnTree}
}


function CCompOn()
{
	var im = getE("idCCompGo");
	var de = getE("idCCompDel");

	if (im)
	{
		im.src = im.src.replace('_CCmp.html', '_CCmpEnable.html');
		im.style.cursor = 'Hand';
		im.alt = 'Porovnej vybrané zboží';
	}
		
	if (de)
	{
		de.className = 'show';
		de.style.cursor = 'hand';
	}
}


function CCompOff()
{
	var im = getE("idCCompGo");
	var de = getE("idCCompDel");

	if (im)
	{
		im.src = im.src.replace('_CCmpEnable.html', '_CCmp.html');
		im.style.cursor = '';
		im.alt = 'Zaškrtněte nejprve zboží k porovnání';
	}
	if (de)
	{
		de.className = 'hide';
		de.style.cursor = 'hand';
	}
}


function CCompStartup(nTree)
{
	gCCompnTree = nTree.toString()
	gCCompIDs = ExtractCookies('CComp'+gCCompnTree).replace('none','')
	var cd = getE("CompDiv");
	var PocetComp = 1;
	var q;
	var sCountName;
	
	if (gCCompIDs != '')
	{
		CCompOn();
		CCompChOn();
		q = gCCompIDs;
		while(q.indexOf('||') > -1) {
			q = q.replace('||', ','); 
			PocetComp = PocetComp + 1;
			}
			if (PocetComp == 1){sCountName = " produkt"}
			if (PocetComp > 1 & PocetComp < 5){sCountName = " produkty"}
			if (PocetComp > 4){sCountName = " produktů"}
//			cd.innerHTML = 'POROVNAT celkem ' + PocetComp + sCountName;
			cd.innerHTML = 'Porovnání: <a href="javascript: CCompGo()">' + PocetComp + ' zboží</a> (<a href="javascript: CCompDel()">odebrat</a>)';
	}
	else
	{
//		cd.innerHTML = 'Žádne zboží k porovnání';
//		cd.innerHTML = '';
	}
}


function CCompDel()
{
	var cd = getE("CompDiv");
	gCCompIDs = '';
	InsertCookies('CComp'+gCCompnTree,gCCompIDs);
	CCompOff();
	CCompChOff();
//	cd.innerHTML = 'Žádne zboží k porovnání';
	cd.innerHTML = '';
	hidDetail = getE('hiDetailCompare');
	if(hidDetail){hidDetail.value = 0}
}

function onSelectStart()
{
	if (window.event.srcElement.name == 'EXPS' ||
	window.event.srcElement.name == 'ICO' ||
	window.event.srcElement.name == 'DIC' ||
	window.event.srcElement.name == 'Mobil' ||
	window.event.srcElement.name == 'Street' ||
	window.event.srcElement.name == 'Availability' ||
	window.event.srcElement.name == 'ZipCode' ||
	window.event.srcElement.name == 'DeliveryFirm' ||
	window.event.srcElement.name == 'DeliveryStreet' ||
	window.event.srcElement.name == 'DeliveryFirstName' ||
	window.event.srcElement.name == 'DeliveryCity' ||
	window.event.srcElement.name == 'DeliveryLastName' ||
	window.event.srcElement.name == 'DeliveryZipCode' ||
	window.event.srcElement.name == 'DeliveryAddress' ||
	window.event.srcElement.name == 'Phone' ||
	window.event.srcElement.name == 'City' ||
	window.event.srcElement.name == 'BankAccount' ||
	window.event.srcElement.name == 'Email' ||
	window.event.srcElement.name == 'Firm' ||
	window.event.srcElement.name == 'Fax' ||
	window.event.srcElement.name == 'FirstName' ||
	window.event.srcElement.name == 'LastName' ||
	window.event.srcElement.name == 'BankCode' ||
	window.event.srcElement.name == 'SpecifickySymbol' ||
	window.event.srcElement.name == 'Maturity' ||
	window.event.srcElement.name == 'YourInternalOrderNumber' ||
	window.event.srcElement.name == 'DeliveryAddress' ||
	window.event.srcElement.name == 'DeliveryType' ||
	window.event.srcElement.name == 'InfoText' ||
	window.event.srcElement.name == 'PaymentType'
)
		return true;
	window.event.cancelBubble = true;
	window.event.returnValue = false;
	return false;
}

function ValidateClaim(f)
{
	if (f.ClaimName.value==''){alert('Vyplňte Jméno a příjmení'); f.ClaimName.focus(); return false;}
	if (f.ClaimTel.value==''){alert('Vyplňte Telefon'); f.ClaimTel.focus(); return false;}
	if (f.ClaimEmail.value==''){alert('Vyplňte E-mail'); f.ClaimEmail.focus(); return false;}
	if (f.ClaimCode.value==''){alert('Vyplňte Kód zboží'); f.ClaimCode.focus(); return false;}
	if (f.ClaimNumber.value==''){alert('Vyplňte Výrobní číslo zboží'); f.ClaimNumber.focus(); return false;}
	if (f.ClaimInvoice.value==''){alert('Vyplňte Číslo faktury, objednávky'); f.ClaimInvoice.focus(); return false;}
	if (f.ClaimComent.value==''){alert('Vyplňte Popis závady'); f.ClaimComent.focus(); return false;}

	return true;
}

function ShowDate(strItem) {
     var strReturn = showModalDialog("http://elektronika.elektrosvet.cz/SelectDate.htm","","status:no; center:yes; help:no; minimize:no;dialogWidth=250pt;dialogHeight=200pt");
     if (strReturn == undefined){return;}
     strItem.value = strReturn;
}
function fnParamChanger(v)
{
	if(typeof document.all.idParamChanger == 'object')
	{
		n = v.indexOf('<!--')
		if (!isNaN(n))
		{
			v = v.substr(n+4)
			n = v.indexOf('-->')
			if (!isNaN(n))
			{
				v = v.substr(0, n)
				v=v.replace(' ','&nbsp;')
				document.all.idParamChanger.innerHTML = v;
				document.all.NameItem.value = document.all.Name.value + v;
			}
		}
	}
}

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 OpenWnd700(strURL){
         var objWnd = window.open(strURL,"InfoDetail","scrollbars=yes,height=600,width=400,left=10,top=10");
         objWnd.focus();
}

function AddBuy(strName, intPrice, intDph, strCode) {
        var strData,strReturn
        strData = strName+"&"+intPrice+"&"+intDph+"&"+strCode
        strReturn = showModalDialog("http://elektronika.elektrosvet.cz/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("http://elektronika.elektrosvet.cz/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="http://elektronika.elektrosvet.cz/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()+";domain=" + strDomain + ";path=/";
        vyprs.setDate(365 + 365 + vyprs.getDate());
        document.cookie=strName+"="+strData+";expires="+vyprs.toGMTString()+";domain=" + strDomain + ";path=/";
}

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=='váš@email.cz' || f=='na@email.cz') ||(f.indexOf('@') < 1 || f.indexOf('@') != f.lastIndexOf('@') || f.lastIndexOf('.') < f.lastIndexOf('@')+2  || f.lastIndexOf('.') > (f.length-3) || f.lastIndexOf('.') < (f.length-5))){
       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="http://elektronika.elektrosvet.cz/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 == "")& 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.bDeliveryUse.checked){
    if((document.UserDataForm.DeliveryFirstName.value == "" ||document.UserDataForm.DeliveryLastName.value == "")& document.UserDataForm.DeliveryFirm.value == ""){alert("Vyplňte název dodací firmy nebo jméno a příjmení.");return false}
    if(document.UserDataForm.DeliveryStreet.value == ""){alert("Vyplňte dodací ulici.");return false}
    if(document.UserDataForm.DeliveryCity.value == ""){alert("Vyplňte dodací město.");return false}
    if(document.UserDataForm.DeliveryZipCode.value == ""){alert("Vyplňte dodací PSČ.");return false}
  } 


  if(document.UserDataForm.Login)
  {
    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)
  {
    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(nNoRegister){
    if(nNoRegister==1)
    {
        if(document.OrderForm.FirstName.value == "" ||document.OrderForm.LastName.value == ""){alert("Vyplňte 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.bDeliveryUse.checked){
	    if((document.OrderForm.DeliveryFirstName.value == "" ||document.OrderForm.DeliveryLastName.value == "")& document.OrderForm.DeliveryFirm.value == ""){alert("Vyplňte název dodací firmy nebo jméno a příjmení.");return false}
	    if(document.OrderForm.DeliveryStreet.value == ""){alert("Vyplňte dodací ulici.");return false}
	    if(document.OrderForm.DeliveryCity.value == ""){alert("Vyplňte dodací město.");return false}
	    if(document.OrderForm.DeliveryZipCode.value == ""){alert("Vyplňte dodací PSČ.");return false}
		}
    }
  
	var RadioChecked = false;
	for (var i=0; i < document.OrderForm.DeliveryType.length; i++){
		if(document.OrderForm.DeliveryType[i].checked){RadioChecked = true}
        }
	if(!RadioChecked){alert("Vyberte způsob dopravy.");return false}
	RadioChecked = false;
	for (var i=0; i < document.OrderForm.PaymentType.length; i++){
		if(document.OrderForm.PaymentType[i].checked){RadioChecked = true}
        }
	if(!RadioChecked){alert("Vyberte způsob platby.");return false}

//    if(document.OrderForm.DeliveryType.value == "-"){alert("Vyberte způsob dopravy.");document.OrderForm.DeliveryType.focus();return false}
//    if(document.OrderForm.PaymentType.value == "-"){alert("Vyberte způsob platby.");document.OrderForm.PaymentType.focus();return false}

  return true;
}

function UnleashHideSpecial(objcheck, objHiddenTd, objsubcheck, objSubHiddenTd)
{
if(getE(objcheck).checked == true && getE(objHiddenTd).style.display == "none")
	{
		if(getE(objsubcheck).checked == true && getE(objcheck).checked == true)
			{
			getE(objSubHiddenTd).style.display = "block";
			}
		getE(objHiddenTd).style.display = "block";
	} 
else if(getE(objcheck).checked == false && getE(objHiddenTd).style.display == "block")
	{
		getE(objSubHiddenTd).style.display = "none";
		getE(objHiddenTd).style.display = "none";
	}
else
	{
		getE(objSubHiddenTd).style.display = "none";
		getE(objHiddenTd).style.display = "none";
	}
}
//******************************************************************************
function formatNumber(nNumber)
{

    if(!isNaN(nNumber))
    {
        
        var re=/ /g;
        var sOUT="";
        var sPIN=nNumber.toString();
        var sPINdec='';
        var nCount=0

        if(sPIN.indexOf(".")!=-1)
        {
            sPINdec=sPIN.substring(sPIN.indexOf(".")+1,sPIN.length)   
            sPIN=sPIN.substring(0,sPIN.indexOf("."))   

            sPINdec=sPINdec.substring(0,2)
            for(var i=sPINdec.length;i<2;i++){sPINdec+="0"}
        }
        else
        {
            sPINdec="00";   
        }

        for(var i=sPIN.length-1;i>=0;i--)
        {
        	sOUT=sPIN.charAt(i)+sOUT;

        	if(((sOUT.length-nCount)%3)==0)
        	{
        		sOUT=" "+sOUT;
        		nCount=nCount+1;
        	}
        }


        sOUT+=","+sPINdec;
        sOUT=sOUT.replace(re,"&nbsp;");


    }
    else
    {
        var sOUT="#ERROR#";
    }

    return sOUT;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// VALIDACE FORMULARE PREHLEDU OBJEDNAVEK ////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getF(formName)
{
	return document.forms[formName]
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function validateOrded_change_fEnable(no, typ)
{
	var f = getF('FFF')
	f.fType.value   = typ;
	f.fEnable.value = no;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function validateOrder_ByLast()
{
	var f = getF('FFF')
	if(isNaN(f.LastOrder.value))	{alert('Zadaný počet posledních objednávek není číslo!');	f.LastOrder.focus();	return;}
	if(f.LastOrder.value == '')		{alert('Zadejte počet posledních objednávek!');				f.LastOrder.focus();	return;}
	if(f.LastOrder.value == 0)		{alert('Ale ale, posledních 0 ...??... \n8-)');				f.LastOrder.focus();	return;}
	validateOrded_change_fEnable(1);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function validateOrder_One()
{
	var f = getF('FFF')
	if(f.n_Doklad.value == '')		{alert('Zadejte její číslo!');								f.n_Doklad.focus();	return;}
	if(f.n_Doklad.value == 0)		{alert('Ale ale, č. 0 ...??... \n8-)');						f.n_Doklad.focus();	return;}
	validateOrded_change_fEnable(1, 'One');
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function validateOrder_ByDate()
{
	var f = getF('FFF')
	if(!isDate(f.OneDay.value))	{alert('Neplatný formát data!');								f.OneDay.focus();		return;}
	validateOrded_change_fEnable(1);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function validateOrder_List()
{
	var f = getF('FFF')
	if(!isDate(f.d_D1.value))		{alert('Neplatný formát data OD!');							f.d_D1.focus();		return;}
	if(!isDate(f.d_D2.value))		{alert('Neplatný formát data DO!');							f.d_D2.focus();		return;}
	if(!validatedateftomto(f.d_D1.value, f.d_D2.value))
	{
		alert('Datum OD je větší než DO!');
		f.d_D1.focus();
		return;
	}
	validateOrded_change_fEnable(1, 'List');
}

/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////

function isDate(fDate)
{	var status = true
	a = fDate.split(".")
	if (a.length!=3) {status = false}
	if (isNaN(a[0]) || a[0]<1 || a[0]>31) {status = false}
	if (isNaN(a[1]) || a[1]<1 || a[1]>12) {status = false}
	if (isNaN(a[2]) || a[2]<1900 || a[2]>2100) {status = false}
	if ((a[1]==4 || a[1]==6 || a[1]==9 || a[1]==11) && (a[0]>30)) {status = false}
	if (a[1]==2 && a[2]%4==0) {if ((a[0]>29)) {status = false}}
	if (a[1]==2 && a[2]%4!=0) {if ((a[0]>28)) {status = false}}
	return status
}

function validatedateftomto(pdateFrom, pdateTo)
{	dF = pdateFrom.split(".")
	dT = pdateTo.split(".")
	OK=true

	if ((parseInt(dF[2])<parseInt(dT[2])) && OK) return true;
	if ((parseInt(dF[2])<=parseInt(dT[2])) && OK) OK=true; else OK=false;
	if ((parseInt(dF[1])<parseInt(dT[1])) && OK)  return true;
	if ((parseInt(dF[1])<=parseInt(dT[1])) && OK) OK=true; else OK=false;
	if ((parseInt(dF[0])<parseInt(dT[0])) && OK) return true;
	if ((parseInt(dF[0])<=parseInt(dT[0])) && OK) OK=true; else OK=false;
	if (!OK) return false;
	return true;
}

function fn_DetailPage_Ask(formChild)
{
	var f = formChild.form;
	
	if (!EmailControl(f.AskEmail.value))
	{
		f.AskEmail.focus();
		return false
	}
	
	var url = '';
	
	url += 'http://elektronika.elektrosvet.cz/Includes/DetailPage_Question_IFR.asp'
	url += '?CD='			+ f.Code.value.toString()
	url += '&Name='			+ f.Name.value.toString()
	url += '&AskQuestion='	+ f.AskQuestion.value.toString()
	url += '&AskEmail='		+ f.AskEmail.value.toString()
	
	document.all.WinStat.src = url;
	
	f.AskQuestion.value='\n\nOdesílám...'
	
	return false;
}

function fn_DetailPage_Send(formChild)
{
	fn_DetailPage_SendInit()

	var f = formChild.form;

	if (!EmailControl(f.SendToEmail.value))
	{
		f.SendToEmail.focus();
		return false
	}

	if (!EmailControl(f.SendFromEmail.value))
	{
		f.SendFromEmail.focus();
		return false
	}
		
	var url = '';
	
	url += 'http://elektronika.elektrosvet.cz/Includes/DetailPage_SendUrl_IFR.asp'
	url += '?CD='				+ f.Code.value.toString()
	url += '&Name='				+ f.Name.value.toString()
	url += '&SendToEmail='		+ f.SendToEmail.value.toString()
	url += '&SendFromEmail='	+ f.SendFromEmail.value.toString()
	url += '&SendFromName='		+ f.SendFromName.value.toString()
	url += '&SendFromComent='	+ f.SendFromComent.value.toString()

	document.all.WinStat.src = url;
	
	f.SendFromComent.value='\n\nOdesílám...'
	
	return false;
}

function fn_DetailPage_SendInit()
{
	document.all.idDetailPage_Send1.className = 'Show';
	document.all.idDetailPage_Send2.className = 'Show';
	document.all.idDetailPage_Send3.c;
}
function SetDPH(sDPH, sURL) {
	var vyprs=new Date();
	vyprs.setDate(vyprs.getDate() + 14);

	if (sDPH=='s') {
		document.cookie="DPH=s; expires="+vyprs.toGMTString()+";domain=" + strDomain + ";path=/";
	} else {
		document.cookie="DPH=bez; expires="+vyprs.toGMTString()+";domain=" + strDomain + ";path=/";
	}
	//if (document.all.RedirOnListCagChange!=null) window.location.href=sURL;
	window.location.href=sURL;
}
function checkPaymentType(nPymentType)
{
	if (nPymentType == 'Platební kartou'){
//		window.location.href = "https://www.elektrosvet.cz/order.asp?card=true";
		getE('tr_paymentcards').style.visibility = "visible";}
	else
		getE('tr_paymentcards').style.visibility = "hidden";
}
function MarkCategory(MarkLI, MarkUL)
{
	if (getE(MarkLI).className == 's-full')
	{
		getE(MarkLI).className = '';
		getE('ul' + MarkLI).style.display = "none";
	}
	else
	{
		getE(MarkLI).className = 's-full';
		getE('ul' + MarkLI).style.display = "inline";
	}
}
function DeliverySame(bChecked)
{
	if (bChecked) {
	getE('DeliveryFirm').value = getE('Firm').value;
	getE('DeliveryFirstName').value = getE('FirstName').value;
	getE('DeliveryLastName').value = getE('LastName').value;
	getE('DeliveryStreet').value = getE('Street').value;
	getE('DeliveryCity').value = getE('City').value;
	getE('DeliveryZipCode').value = getE('ZipCode').value;
	}
	getE('DeliveryFirm').readOnly = bChecked;
	getE('DeliveryFirstName').readOnly = bChecked;
	getE('DeliveryLastName').readOnly = bChecked;
	getE('DeliveryStreet').readOnly = bChecked;
	getE('DeliveryCity').readOnly = bChecked;
	getE('DeliveryZipCode').readOnly = bChecked;
	if (bChecked) {
		getE('DeliveryFirm').style.backgroundColor = "#ECEEF4";
		getE('DeliveryFirstName').style.backgroundColor = "#ECEEF4";
		getE('DeliveryLastName').style.backgroundColor = "#ECEEF4";
		getE('DeliveryStreet').style.backgroundColor = "#ECEEF4";
		getE('DeliveryCity').style.backgroundColor = "#ECEEF4";
		getE('DeliveryZipCode').style.backgroundColor = "#ECEEF4";
	}
	else
	{
		getE('DeliveryFirm').style.backgroundColor = "#FFFFFF";
		getE('DeliveryFirstName').style.backgroundColor = "#FFFFFF";
		getE('DeliveryLastName').style.backgroundColor = "#FFFFFF";
		getE('DeliveryStreet').style.backgroundColor = "#FFFFFF";
		getE('DeliveryCity').style.backgroundColor = "#FFFFFF";
		getE('DeliveryZipCode').style.backgroundColor = "#FFFFFF";
	}
}

      sg.act = false;
      sg.xml = null;
      sg.init = function() {
         sg.xml = (window.XMLHttpRequest ? new XMLHttpRequest : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : false)); 
         if ( !sg.xml ) {
              sg.act = false;
         } else {
              sg.act = true;
         }
         sg.encFunc = encodeURIComponent ? encodeURIComponent : escape;
      }
      sg.send = function(text) {
          if ( !sg.act ) { return true; }
          if (sg.xml.readyState != 0) { sg.xml.abort(); }
          sg.xml.open("GET.html","http://elektronika.elektrosvet.cz/naseptavac_return.asp?value=" + text, true);
          sg.xml.onreadystatechange = function() {
              if (sg.xml.readyState == 4) { 
                if (sg.xml.status == 200) { 
                  sg.display(sg.xml.responseText);
                }
              }
          }
          sg.xml.send(null);
          return true;
      }
      sg.display = function(data) {
          document.getElementById("suggest_div").innerHTML = data;
			if (data.length > 1) {
				document.getElementById("suggest_div").style.visibility = "visible";
				getE('typtree').style.visibility = 'hidden';
			}
      }
      
function fn() {
	window.setTimeout("fn2()", 50);
}
function fn2() {
	if (document.getElementById("EXPS").value > ""){
		return stisknuta_klavesa(document.getElementById("EXPS").value);
	}
	else
	{
		document.getElementById("suggest_div").style.visibility = "hidden";
		getE('typtree').style.visibility = 'visible';
	}
}

function odesli(cislo, text) {
    if (cislo == globalni_cislo) { sg.send(escape(text)); }
}

function stisknuta_klavesa(text) {
    if (sg.xml.readyState != 0) { sg.xml.abort(); }
    globalni_cislo = (globalni_cislo + 1) % 100;
    setTimeout("odesli(" + globalni_cislo + ", '" + text + "');", 600);
    return true;
}
