﻿// JScript File
var _floating_timer = null;
var _floating_on = null;

function ShowFloating(sid)
{
	if((_floating_on != null) && (_floating_on != sid)) {
		HideFloating(_floating_on);
	}
	
	var el = document.getElementById(sid);
	el.style.display = "block";	
	
	_floating_on = sid;
}

function QueueFloating(sid)
{
	ShowFloating(sid);
}

function HideFloating(sid, el)
{

	var el = document.getElementById(sid);
	el.style.display = "none";	
	
	_floating_on = null;
}

var _searchBlock = null;
var _searchBlockFilter = null;
var _helperContentCache; 
var _requestPending = false;
var _requestQueued = false;

function divTransition(executeMode)
{
	if(_searchBlockFilter) {
		if(executeMode)
			_searchBlockFilter.Play();
		else
			_searchBlockFilter.Apply();
	}
}

function onSearchFieldEnter()
{		
	var div = getSearchBlock();
	divTransition(false);
	div.innerHTML = _helperContentCache;
	div.style.display = "block";
	divTransition(true);
}

var _hidingTimer = null;

function _onSearchFieldLeave()
{
	var div = getSearchBlock();
	divTransition(false);
	div.style.display = "none";
	divTransition(true);
	_hidingTimer = null;
}

function onSearchFieldLeave()
{
	if (_hidingTimer != null)
	{
		window.clearTimeout(_hidingTimer);
		_hidingTimer = null;
	}
	_hidingTimer = window.setTimeout("_onSearchFieldLeave()", 500, "javascript");
}

var _typingTimer = null;

function onSearchFieldTyping()
{	
	if(document.all) {
		if(window.event.keyCode == 13)
			return;
	}
			

	if(!_requestPending) {
		if(_typingTimer != null) {
			window.clearTimeout(_typingTimer);
			_typingTimer = null;
		}
	
		_typingTimer = window.setTimeout(runSearchHelp, 1000, "javascript");		
	} else {
		_requestQueued = true;
	}
}

function __runSearchHelp(__ctl1, __url1)
{
	_requestQueued = false;
	_requestPending = true;
	
	var divContent = document.getElementById("divSerch_Content");
	var divCode = document.getElementById("divDynamicCodeHolder");
	var strSearchExpression = document.getElementById(__ctl1).value;
	
	if(strSearchExpression == "") {
		_requestPending = false;
		return;
	}
	
	divTransition(false);
	
	deleteAllChildElement(divContent);		
	
	if(strSearchExpression.length == 0) {
		getSearchBlock().innerHTML = _helperContentCache;
		return;
	}
	
	var divMoment = document.createElement("div");
	divMoment.style.textAlign = "center";
	divMoment.style.margin = "20px 0px";
	var elMsg = document.createTextNode("Moment prosím ...");
	divMoment.appendChild(elMsg);
	divContent.appendChild(divMoment);
	divTransition(true);
	
	deleteAllChildElement(divCode);		
	var scriptElement = document.createElement("script");
	scriptElement.language = "javascript";	
	scriptElement.src = __url1 + "?qry=" + encodeURI(strSearchExpression);
	//window.prompt("ms", scriptElement.src);
	divCode.appendChild(scriptElement);	
	
}

function __dynsrch_createElement(tagName)
{	
	if(tagName.charAt(0) == "#") {
		return document.createTextNode(tagName.substring(1, tagName.length));
	} else {
		return document.createElement(tagName);
	}
}


function searchHelpCallback(elContent)
{
	var divContent = document.getElementById("divSerch_Content");
	
	divTransition(false);	
	deleteAllChildElement(divContent);			
		
	divContent.style.display = "none";
	elContent(divContent, __dynsrch_createElement);	
	divContent.style.display = "block";

	 
    divContent.style.display = "block";	
	divTransition(true);
	
	_requestPending = false;
	
	if(_requestQueued) {
		runSearchHelp();
	}
}

function deleteAllChildElement(el)
{
	while(el.childNodes.length>0) {
		el.removeChild(el.firstChild);
	}
}

var _trtr_index = 0;
//var _trtr_texts = new Array("Eurotel   602-222-777",  "T-Mobile 603-222-777", "Oskar    777-222-777");
var _trtr_texts = [ " tel:   605-350-325" ];

function _trtr_rotate()
{
	var el = document.getElementById("tdPhoneRotatorLabel");
	
	var _el_f = null;
	
	if(document.all) {			
			var t = document.getElementById("tabPhoneRotatorTable");
			t.style.filter = "progid:DXImageTransform.Microsoft.Wipe(GradientSize=.50, wipeStyle=1, motion='forward', duration=2.0)";			
			
			_el_f  = t.filters[0];
			
			_el_f.Apply();
	}
		
	
	el.removeChild(el.firstChild);
	var newText = document.createTextNode(_trtr_texts[_trtr_index++]);
	_trtr_index = _trtr_index % _trtr_texts.length;
	el.appendChild(newText);
	
	if(document.all) {	
		_el_f.Play();
	}
	
	window.setTimeout("_trtr_rotate()", 5000);
}

function render_searchhelp()
{
    var _htmlcode = "<div id='divSerch_Content' style='border: #71c2ed 1px solid; width: 400px; xheight: 320px; padding: 8px; background-color: white;'>" +
                "<p style='font-weight: bold'>Rádi Vám s vyhledáním Vašeho produktu pomůžeme.</p>" +
                "<p>Jakmile napíšete první dva znaky hledaného názvu nebo kódu výrobku, budeme Vám průběžně ukazovat výsledky vyhledávání. Produkty (kategorie, značky) zobrazíte kliknutím " +
                "na odkaz v okně nebo na tlačítko „hledej“.</p></div>";
        
    document.write(_htmlcode); 
}

function construct_top_menu(elParent, menuArray, columns, itemClass)
{
    var nItems = menuArray.length / 2;
    var nRows = Math.floor((nItems + (columns - 1)) / columns);    
 
    var elTab = document.createElement("table");   
    var elTabBody = document.createElement("tbody");
    
    for(var nRow = 0; nRow < nRows; ++nRow) {
        var elRow = document.createElement("tr");
        for(var nCol = 0; nCol < columns; ++nCol) {
            var elCell = document.createElement("td");
            
            var itmIdx = nCol * nRows + nRow;
            
            if(itmIdx >= nItems) {
                elCell.appendChild(document.createTextNode(" "));
            } else {
                
                var elItem = document.createElement("div");
                elItem.className = itemClass;
                
                var elAnchor = document.createElement("a");
                elAnchor.href = menuArray[itmIdx*2 + 1] 
                elAnchor.appendChild(document.createTextNode(menuArray[itmIdx*2]));                
                                
                elItem.appendChild(elAnchor);
                elCell.appendChild(elItem);
            }
            
            elRow.appendChild(elCell);
        }
        elTabBody.appendChild(elRow);
    }
    
    elTab.appendChild(elTabBody);
    
    elParent.appendChild(elTab);
}