
var allDemands=new Array();



function SendDemand(ajaxUrl,descType,demand_id)
{

	//if(!pageIsLoaded())
	//	return false;	

    demand_id=SearchDemandInitialize(demand_id);
	
	

     var divid_description=allDemands[demand_id]['descriptionElmId'];

    var divid_count='search-count';
    var divid_count_parent='search-count-win';

    //sledovanie ci zobrazit search v clankoch alebo v nehnutelnostiach
    if(allDemands[demand_id]['purposeElm'] && allDemands[demand_id]['purposeElm'].value==-1)
    {
        // --- vyhladavanie v clankoch

        // skryt count
        if(gE(divid_count_parent))
            hE(gE(divid_count_parent));


        if(gE(divid_description))
            gE(divid_description).innerHTML='';
        
        
       
        // skryt elementy
        if(allDemands[demand_id]['articlesElm'])
        {
            var liArticles=allDemands[demand_id]['articlesElm'].parentNode;
            var ulSearch=liArticles.parentNode;
            if(!ulSearch)
            	return false;
            var allLis=ulSearch.getElementsByTagName('li');
            if(allLis)
            	for(keyVal in allLis)
            		if(allLis[keyVal].style)
            			hE(allLis[keyVal]);
            sE(liArticles);
            sE(allDemands[demand_id]['purposeElm'].parentNode);
        }
        return false;
    }
    else
    {
    	// --- vyhladavanie v nehnutelnostiach

        // zobrazit elementy
       
        if(allDemands[demand_id]['articlesElm'])
        {
            var liArticles=allDemands[demand_id]['articlesElm'].parentNode;
            var ulSearch=liArticles.parentNode;
            if(!ulSearch)
            	return false;
            var allLis=ulSearch.getElementsByTagName('li');
            if(allLis)
            	for(keyVal in allLis)
            		if(allLis[keyVal].style)
            			sE(allLis[keyVal]);
            hE(liArticles);
        }    

    }
		
    var formId='search';
    if(demand_id!='' && demand_id>0)
    {
    	
    	formId=formId+demand_id;
    }



    if(gE(divid_description))
    {
        if(descType==undefined || !descType )
            descType='horizontal';
        submitForm(gE(formId),divid_description,'',ajaxUrl+'?action=description&type='+descType,'GET',true);
    }

    if(gE(allDemands[demand_id]['buttonElmId']))
    {
        submitForm(gE(formId),allDemands[demand_id]['buttonElmId'],'',ajaxUrl+'?action=button','GET',true);
    }

    if(gE(divid_count_parent))
        sE(gE(divid_count_parent));
    if(gE(divid_count))
    {
    	submitForm(gE(formId),divid_count,'',ajaxUrl+'?action=count','GET',true);
     }
        //runPhpScript(ajaxUrl+'?action=count',post,divid_count);



}


function SearchDemandInitialize(demand_id)
{
	var demand_id_index;
    if(demand_id==undefined)
        demand_id='';
    if(!demand_id)
        demand_id_index='0';
    else
        demand_id_index=demand_id;
    if(!allDemands[demand_id_index])
    {
    	allDemands[demand_id_index]=new Array();
        var postfix=demand_id;
         //allDemands[demand_id_index]['categElm']=gE('category'+postfix);
         //allDemands[demand_id_index]['localElm'] =gE('locality'+postfix);
         allDemands[demand_id_index]['priceElm'] =gE('price'+postfix);
         allDemands[demand_id_index]['areaElm'] =gE('area'+postfix);
         allDemands[demand_id_index]['purposeElm'] =gE('purpose'+postfix);
         allDemands[demand_id_index]['advertiserElm'] =gE('advertiser'+postfix);
         allDemands[demand_id_index]['articlesElm'] =gE('articles_text'+postfix);
         allDemands[demand_id_index]['descriptionElmId'] ='search-description' + postfix;
         allDemands[demand_id_index]['buttonElmId'] ='search-button' + postfix;	


    }
    return demand_id_index;
}



var allSearchPartsToClose = new Array();

function SearchOnOpenPart(id,script)
{
	allSearchPartsToClose[id]=script;
    for (keyVal in allSearchPartsToClose)
    {
        if(keyVal != id)
        {
        	eval(allSearchPartsToClose[keyVal]);
        }
    }
}





// ------- PRICE --------------------------------------------------------------------------

var allPriceDivs = new Array();

function SearchPriceClick(id,ajaxUrl,titleId,demand_id,position_type)
{


    // inicalizacia
    if(!allPriceDivs[id])
    {

        demand_id=SearchDemandInitialize(demand_id);
        allPriceDivs[id]=new Array();

        var elmTtile=gE(titleId);
        //var outputDivOld=gE(id);
        var outputDiv = document.createElement('DIV');


        var pos=getElmPosition(elmTtile);
        var size=getElmSize(elmTtile);

        addCls(outputDiv,'rollout');
        addCls(outputDiv,'d-n');

        var cssProps='';
        cssProps = 'position:absolute;display:block;z-index:15;';
        switch(position_type)
        {
            case "right":
                cssProps  = cssProps +  'top:'+(pos.y)+'px;left:'+(pos.x+size.x)+'px;';
            break;
            case "bottom":
            default:
                cssProps = cssProps + 'top:'+(pos.y+size.y)+'px;left:'+(pos.x)+'px;';
            break;
        }
        outputDiv.style.cssText =   cssProps ;

        //outputDiv.innerHTML = outputDivOld.innerHTML;

        //outputDivOld.parentNode.removeChild(outputDivOld);
        outputDiv.setAttribute('id',id);

        document.body.appendChild(outputDiv);




        var post='&div_id='+id+'&demand_id='+demand_id;
        runPhpScript(ajaxUrl+'?action=price',post,id,'SearchPriceGetElements(\''+id+'\')');

        allPriceDivs[id]['elm']=outputDiv;

        eval('allPriceDivs[\''+id+'\'][\'elm\'].onmousemove = function(){SearchPriceHiding(\''+id+'\',false);};');
        eval('allPriceDivs[\''+id+'\'][\'elm\'].onmouseout = function(){SearchPriceHiding(\''+id+'\',true);};');



        if(!allPriceDivs[id]['elm'])
            return false;

        //allPriceDivs[id]['ajaxUrl']=ajaxUrl;


        allPriceDivs[id]['title_elm']=elmTtile;



        if(allDemands[demand_id]['priceElm'])
        {

            allPriceDivs[id]['hidden_elm']= allDemands[demand_id]['priceElm'];
        }



        allPriceDivs[id]['curency_id']=22;
        allPriceDivs[id]['price_type_id']=302;




        //  predvyplnit hodnoty
        var data=allPriceDivs[id]['hidden_elm'].value.split(',');

        var curency_str='Sk';
        var curency_id=new String(data[0]);
        var price_type_id=new String(data[1]);

        if(curency_id=='22' && price_type_id=='302')
            curency_str='Sk';
        if(curency_id=='22' && price_type_id=='303')
            curency_str='Sk/ m&sup2;';
        if(curency_id=='22' && price_type_id=='304')
            curency_str='Sk/mesiac';
        if(curency_id=='8' && price_type_id=='302')
            curency_str='&euro;';
        if(curency_id=='8' && price_type_id=='303')
            curency_str='&euro;/ m&sup2;</sup>';
        if(curency_id=='8' && price_type_id=='304')
            curency_str='&euro;/mesiac';



    }

    if(!allPriceDivs[id]['elm'])
        return false;

    // ak je otvorene - zavri
    if(allPriceDivs[id]['isopen'])
    {
    	SearchPriceClose(id);
        SearchPriceSend(id);
    }
    // inak - otvor
    else
    {
    	SearchPriceOpen(id);
    }
}




function SearchPriceGetElements(id)
{
	//alert(id);
    var curency_str='Sk';
    allPriceDivs[id]['price_from_elm']=gE(id+'price_from');
        allPriceDivs[id]['price_to_elm']=gE(id+'price_to');
        allPriceDivs[id]['price_around_elm']=gE(id+'price_around');

        allPriceDivs[id]['cur_from_elm']=gE(id+'cur_from');
        allPriceDivs[id]['cur_to_elm']=gE(id+'cur_to');
        allPriceDivs[id]['cur_around_elm']=gE(id+'cur_around');

        allPriceDivs[id]['cur_from_elm_list']=gE(id+'cur_from_list');
        allPriceDivs[id]['cur_to_elm_list']=gE(id+'cur_to_list');
        allPriceDivs[id]['cur_around_elm_list']=gE(id+'cur_around_list');

        allPriceDivs[id]['cur_from_elm'].innerHTML=curency_str;
        allPriceDivs[id]['cur_to_elm'].innerHTML=curency_str;
        allPriceDivs[id]['cur_around_elm'].innerHTML=curency_str;

        sE(allPriceDivs[id]['cur_from_elm']);
        sE(allPriceDivs[id]['cur_to_elm']);
        sE(allPriceDivs[id]['cur_around_elm']);

         var data=allPriceDivs[id]['hidden_elm'].value.split(',');
        if(data[2])
            allPriceDivs[id]['price_from_elm'].value=new String(data[2]);
        if(data[3])
            allPriceDivs[id]['price_to_elm'].value=new String(data[3]);
        if(data[4])
            allPriceDivs[id]['price_around_elm'].value=new String(data[4]);



}
function SearchPriceAroundKeyUp(id)
{
	if(allPriceDivs[id]['price_around_elm'].value!='')
    {
        allPriceDivs[id]['price_from_elm'].value='';
        allPriceDivs[id]['price_to_elm'].value='';
    }

}

function SearchPriceFromToKeyUp(id)
{
	allPriceDivs[id]['price_around_elm'].value='';
}

function SearchPriceClose(id,forced)
{
	if(forced == undefined)
        forced=true;

    if(forced || allPriceDivs[id]['allowHide'])
    {
        // zobrazit selecty - hack pre IE
        showSelects(document);

        hE(allPriceDivs[id]['elm']);
        allPriceDivs[id]['isopen']=false;

        // skryt aj vsetky roletky - meny
        SearchShowCurrencies(id,allPriceDivs[id]['cur_from_elm_list'],true);
        SearchShowCurrencies(id,allPriceDivs[id]['cur_to_elm_list'],true);
        SearchShowCurrencies(id,allPriceDivs[id]['cur_around_elm_list'],true);



    }

}


// skryt za nejaky cas
function SearchPriceHiding(id,set)
{
   if(set)
   {
    allPriceDivs[id]['allowHide']=true;
    allPriceDivs[id]['hideTimer']=window.setTimeout('SearchPriceClose(\''+id+'\',false)',3000);
   }
   else
   {
    allPriceDivs[id]['allowHide']=true;
    window.clearTimeout(allPriceDivs[id]['hideTimer']);
   }
}


function  SearchPriceOpen(id)
{
	allPriceDivs[id]['isopen']=true;
    sE(allPriceDivs[id]['elm']);
    SearchOnOpenPart(id,'SearchPriceClose(\''+id+'\');');

    // skryt selecty - hack pre IE
    hideSelects(document);

}

function SearchPriceSend(id)
{
	var data='';



    data += allPriceDivs[id]['curency_id'] + ',';
    data += allPriceDivs[id]['price_type_id'] + ',';
    data += allPriceDivs[id]['price_from_elm'].value + ',';
    data += allPriceDivs[id]['price_to_elm'].value + ',';
    data += allPriceDivs[id]['price_around_elm'].value + ',';

    allPriceDivs[id]['hidden_elm'].value=data;




    /// odoslat ajaxom - len ak boli zmenene
     if(allPriceDivs[id]['data_last'] != data && allPriceDivs[id]['hidden_elm'].onchange)
        allPriceDivs[id]['hidden_elm'].onchange();


   //uchovanie sucasnych udajov
   allPriceDivs[id]['data_last']=data;


    // zmenit title na aktualny text :
   if(allPriceDivs[id]['price_around_elm'].value)
   {
     wE(allPriceDivs[id]['title_elm'],'okolo '+allPriceDivs[id]['price_around_elm'].value+' '+allPriceDivs[id]['cur_from_elm'].innerHTML);
   }
   else
   {
     var titleTxt='';
     if(allPriceDivs[id]['price_from_elm'].value)
        titleTxt+='od '+allPriceDivs[id]['price_from_elm'].value+' ';
     if(allPriceDivs[id]['price_to_elm'].value)
        titleTxt+='do '+allPriceDivs[id]['price_to_elm'].value;
     if(titleTxt)
     {
        titleTxt+=' '+allPriceDivs[id]['cur_from_elm'].innerHTML;
        wE(allPriceDivs[id]['title_elm'],titleTxt);
     }
     else
       wE(allPriceDivs[id]['title_elm'],'Vyber cenu...');
   }

}

function SearchPriceInputOnKeyDown(id,ev)
{
	ev = ev || window.event;
    var keyCode = ev.keyCode;

    if( keyCode==13)
         {
            //alert('enter');
            SearchPriceClick(id);
            return false;
         }
     return true;
}

function SearchSetCurrency(id,textElm,cur_id,price_id)
{
	var text=textElm.innerHTML;

    hE(allPriceDivs[id]['cur_from_elm_list']);
    hE(allPriceDivs[id]['cur_to_elm_list']);
    hE(allPriceDivs[id]['cur_around_elm_list']);

    wE(allPriceDivs[id]['cur_from_elm'],text);
    wE(allPriceDivs[id]['cur_to_elm'],text);
    wE(allPriceDivs[id]['cur_around_elm'],text);

    sE(allPriceDivs[id]['cur_from_elm'].parentNode);
    sE(allPriceDivs[id]['cur_to_elm'].parentNode);
    sE(allPriceDivs[id]['cur_around_elm'].parentNode);

     allPriceDivs[id]['curency_id']=cur_id;
     allPriceDivs[id]['price_type_id']=price_id;

    //search_cenaE=gE("search_cena");hE(search_cenaE);
    //search_rozlohaE=gE("search_rozloha");hE(search_rozlohaE);

    SearchPriceSend(id);

}


function SearchShowCurrencies(id,listId,forceClose,demand_id)
{


   var elm=gE(listId);

    if(forceClose)
    {
    	// zobrazovanie skryvanie roletky - s typmi a currencies
        if(elm)
            hE(elm);

        // zobrazenie / skrytie -dalsich elementov - len kvoli IE bugu --------
        if(allPriceDivs[id]['cur_from_elm_list'].getAttribute('id') == listId)
        {
            sE(allPriceDivs[id]['cur_to_elm'].parentNode);
            sE(allPriceDivs[id]['cur_around_elm'].parentNode);

        }
        if(allPriceDivs[id]['cur_to_elm_list'].getAttribute('id') == listId)
        {
            sE(allPriceDivs[id]['cur_around_elm'].parentNode);
        }
    }
    else
    {
        demand_id=SearchDemandInitialize(demand_id);
        // zobrazovanie a skryvanie jednotlivych typov(riadkov) - podla purpose_id
        var purposeElm;
        if(allDemands[demand_id]['purposeElm'])
            purposeElm= allDemands[demand_id]['purposeElm'];

        //var purposeElm=gE('purpose');

        if(purposeElm && purposeElm.value==300)
           var class2show='price-purpose-300';
        else if(purposeElm && purposeElm.value==301)
            var class2show='price-purpose-301';

        if(class2show)
        {
            var allLis=elm.getElementsByTagName('li');
            for (var i=0; i<allLis.length; i++)
                if(allLis[i].className == class2show)
                    sEi(allLis[i]);
                else
                    hE(allLis[i]);
        }
        // zobrazovanie skryvanie roletky - s typmi a currencies
        if(elm)
            switchE(elm);

        // zobrazenie / skrytie -dalsich elementov - len kvoli IE bugu --------
        if(allPriceDivs[id]['cur_from_elm_list'].getAttribute('id') == listId)
        {
            hsE(allPriceDivs[id]['cur_to_elm'].parentNode);
            hsE(allPriceDivs[id]['cur_around_elm'].parentNode);

        }
        if(allPriceDivs[id]['cur_to_elm_list'].getAttribute('id') == listId)
        {
            hsE(allPriceDivs[id]['cur_around_elm'].parentNode);
        }
    }

}


// ------- AREA --------------------------------------------------------------------------

var allAreaDivs=new Array();

function SearchAreaClick(id,ajaxUrl,titleId,demand_id,position_type)
{


    // inicalizacia
    if(!allAreaDivs[id])
    {
        demand_id=SearchDemandInitialize(demand_id);
        allAreaDivs[id]=new Array();

        var elmTtile=gE(titleId);
        //var outputDivOld=gE(id);
        var outputDiv = document.createElement('DIV');


        var pos=getElmPosition(elmTtile);
        var size=getElmSize(elmTtile);

        addCls(outputDiv,'rollout');
        addCls(outputDiv,'d-n');
        var cssProps='';
        cssProps = 'position:absolute;display:block;z-index:15;';
        switch(position_type)
        {
            case "right":
                cssProps  = cssProps +  'top:'+(pos.y)+'px;left:'+(pos.x+size.x)+'px;';
            break;
            case "bottom":
            default:
                cssProps = cssProps + 'top:'+(pos.y+size.y)+'px;left:'+(pos.x)+'px;';
            break;
        }
        outputDiv.style.cssText =   cssProps ;

        //outputDiv.innerHTML = outputDivOld.innerHTML;

        //outputDivOld.parentNode.removeChild(outputDivOld);
        outputDiv.setAttribute('id',id);

        document.body.appendChild(outputDiv);

        var post='&div_id='+id;
        runPhpScript(ajaxUrl+'?action=area',post,id,'SearchAreaGetElements(\''+id+'\')');


        allAreaDivs[id]['elm']=outputDiv;
        eval('allAreaDivs[\''+id+'\'][\'elm\'].onmousemove = function(){SearchAreaHiding(\''+id+'\',false);};');
        eval('allAreaDivs[\''+id+'\'][\'elm\'].onmouseout = function(){SearchAreaHiding(\''+id+'\',true);};');


        if(!allAreaDivs[id]['elm'])
            return false;

        //allAreaDivs[id]['ajaxUrl']=ajaxUrl;

        allAreaDivs[id]['title_elm']=elmTtile;


         if(allDemands[demand_id]['areaElm'])
            allAreaDivs[id]['hidden_elm']= allDemands[demand_id]['areaElm'];



    }

     if(!allAreaDivs[id]['elm'])
            return false;


    // ak je otvorene - zavri
    if(allAreaDivs[id]['isopen'])
    {
        SearchAreaClose(id);
        SearchAreaSend(id);
    }
    else
        SearchAreaOpen(id);

}



function SearchAreaGetElements(id)
{
	//  predvyplnit hodnoty
        allAreaDivs[id]['area_from_elm']=gE(id+'area_from');
        allAreaDivs[id]['area_to_elm']=gE(id+'area_to');
        allAreaDivs[id]['area_around_elm']=gE(id+'area_around');

         var data=allAreaDivs[id]['hidden_elm'].value.split(',');
         var str='';
        if(data[0])
            allAreaDivs[id]['area_from_elm'].value=new String(data[0]);
        if(data[1])
            allAreaDivs[id]['area_to_elm'].value=new String(data[1]);
        if(data[2])
            allAreaDivs[id]['area_around_elm'].value=new String(data[2]);


}
function SearchAreaAroundKeyUp(id)
{
    if(allAreaDivs[id]['area_around_elm'].value!='')
    {
        allAreaDivs[id]['area_from_elm'].value='';
        allAreaDivs[id]['area_to_elm'].value='';
    }

}

function SearchAreaFromToKeyUp(id)
{
    allAreaDivs[id]['area_around_elm'].value='';
}


function SearchAreaClose(id,forced)
{
    if(forced == undefined)
        forced=true;

    if(forced || allAreaDivs[id]['allowHide'])
    {
        hE(allAreaDivs[id]['elm']);
        allAreaDivs[id]['isopen']=false;
    }

}


// skryt za nejaky cas
function SearchAreaHiding(id,set)
{
   if(set)
   {
    allAreaDivs[id]['allowHide']=true;
    allAreaDivs[id]['hideTimer']=window.setTimeout('SearchAreaClose(\''+id+'\',false)',3000);
   }
   else
   {
    allAreaDivs[id]['allowHide']=true;
    window.clearTimeout(allAreaDivs[id]['hideTimer']);
   }
}

function SearchAreaOpen(id)
{
    allAreaDivs[id]['isopen']=true;
    sE(allAreaDivs[id]['elm']);
    SearchOnOpenPart(id,'SearchAreaClose(\''+id+'\');');
}

function SearchAreaInputOnKeyDown(id,ev)
{
    ev = ev || window.event;
    var keyCode = ev.keyCode;

    if( keyCode==13)
         {
            //alert('enter');
            SearchAreaClick(id);
            return false;
         }
     return true;
}


function SearchAreaSend(id)
{
    var data='';
    data += allAreaDivs[id]['area_from_elm'].value + ',';
    data += allAreaDivs[id]['area_to_elm'].value + ',';
    data += allAreaDivs[id]['area_around_elm'].value + ',';


    allAreaDivs[id]['hidden_elm'].value=data;


   /// odoslat ajaxom - len ak boli zmenene
    if(allAreaDivs[id]['data_last'] != data && allAreaDivs[id]['hidden_elm'].onchange)
        allAreaDivs[id]['hidden_elm'].onchange();


   //uchovanie sucasnych udajov
   allAreaDivs[id]['data_last']=data;

   // zmenit title na aktualny text :
   if(allAreaDivs[id]['area_around_elm'].value)
   {
    wE(allAreaDivs[id]['title_elm'],'okolo '+allAreaDivs[id]['area_around_elm'].value+' m&sup2;');
   }
   else
   {
   	 var titleTxt='';
     if(allAreaDivs[id]['area_from_elm'].value)
        titleTxt+='od '+allAreaDivs[id]['area_from_elm'].value+' ';
     if(allAreaDivs[id]['area_to_elm'].value)
        titleTxt+='do '+allAreaDivs[id]['area_to_elm'].value;
     if(titleTxt)
     {
        titleTxt+=' m&sup2;';
        wE(allAreaDivs[id]['title_elm'],titleTxt);
     }
     else
       wE(allAreaDivs[id]['title_elm'],'Vyber rozlohu...');
   }


}

// ------- PURPOSE ID / CLANKY --------------------------------------------------------------------------


var allPurposesDivs=new Array();

function SearchPurposeClick(id,ajaxUrl,demand_id,position_type)
{

    demand_id=SearchDemandInitialize(demand_id);
    // inicalizacia
    if(!allPurposesDivs[id])
    {
        allPurposesDivs[id]=new Array();

         //allPurposesDivs[id]['ajaxUrl']=ajaxUrl;


        allPurposesDivs[id]['title_elm']=gE(id+'-title');
         if(allDemands[demand_id]['purposeElm'])
            allPurposesDivs[id]['hidden_elm']= allDemands[demand_id]['purposeElm'];

        //allPurposesDivs[id]['hidden_elm']=gE('purpose');


        var outputDivOld=gE(id);
        var outputDiv = document.createElement('DIV');


        var pos=getElmPosition(allPurposesDivs[id]['title_elm']);
        var size=getElmSize(allPurposesDivs[id]['title_elm']);

        addCls(outputDiv,'rollout');
        addCls(outputDiv,'d-n');
        var cssProps='';
        cssProps = 'position:absolute;display:block;z-index:1500;';
        switch(position_type)
        {
            case "right":
                cssProps  = cssProps +  'top:'+(pos.y)+'px;left:'+(pos.x+size.x)+'px;';
            break;
            case "bottom":
            default:
                cssProps = cssProps + 'top:'+(pos.y+size.y)+'px;left:'+(pos.x)+'px;';
            break;
        }
        outputDiv.style.cssText =   cssProps ;

        outputDiv.innerHTML = outputDivOld.innerHTML;

        outputDivOld.parentNode.removeChild(outputDivOld);
        outputDiv.setAttribute('id',id);

        document.body.appendChild(outputDiv);

        allPurposesDivs[id]['elm']=outputDiv;
        eval('allPurposesDivs[\''+id+'\'][\'elm\'].onmousemove = function(){SearchPurposeHiding(\''+id+'\',false);};');
        eval('allPurposesDivs[\''+id+'\'][\'elm\'].onmouseout = function(){SearchPurposeHiding(\''+id+'\',true);};');


        if(!allPurposesDivs[id]['elm'])
            return false;



    }

     if(!allPurposesDivs[id]['elm'])
            return false;


    // ak je otvorene - zavri
    if(allPurposesDivs[id]['isopen'])
    {
        SearchPurposeClose(id);
        SearchPurposeSend(id);
    }
    else
        SearchPurposeOpen(id);

}




function SearchPurposeClose(id,forced)
{
    if(forced == undefined)
        forced=true;

    if(forced || allPurposesDivs[id]['allowHide'])
    {
        // zobrazit selecty - hack pre IE
        showSelects(document);

        hE(allPurposesDivs[id]['elm']);
        allPurposesDivs[id]['isopen']=false;
    }

}


// skryt za nejaky cas
function SearchPurposeHiding(id,set)
{
   if(set)
   {
    allPurposesDivs[id]['allowHide']=true;
    allPurposesDivs[id]['hideTimer']=window.setTimeout('SearchPurposeClose(\''+id+'\',false)',3000);
   }
   else
   {
    allPurposesDivs[id]['allowHide']=true;
    window.clearTimeout(allPurposesDivs[id]['hideTimer']);
   }
}


function SearchPurposeOpen(id)
{
    allPurposesDivs[id]['isopen']=true;
    sE(allPurposesDivs[id]['elm']);
    SearchOnOpenPart(id,'SearchPurposeClose(\''+id+'\');');
    // skryt selecty - hack pre IE
    hideSelects(document);
}

function SearchPurposeRowClick(id,value,text)
{

    allPurposesDivs[id]['title_elm'].innerHTML=text;
    allPurposesDivs[id]['hidden_elm'].value=value;
    SearchPurposeClose(id);
    SearchPurposeSend(id);
    return false;
}


function SearchPurposeSend(id)
{
    var data=allPurposesDivs[id]['hidden_elm'].value;


   /// odoslat ajaxom - len ak boli zmenene
    if(allPurposesDivs[id]['data_last'] != data && allPurposesDivs[id]['hidden_elm'].onchange)
        allPurposesDivs[id]['hidden_elm'].onchange();



   //uchovanie sucasnych udajov
   allPurposesDivs[id]['data_last']=data;


}








//---------------------------------+
//CARPE  S l i d e r        1.3  |
//2005 - 12 - 10                 |
//By Tom Hermansson Snickars     |
//Copyright CARPE Design         |
//http://carpe.ambiprospect.com/ |
//---------------------------------+

//carpeGetElementByID: Cross-browser version of "document.getElementById()"
function carpeGetElementById(element)
{
	if (document.getElementById) element = document.getElementById(element);
	else if (document.all) element = document.all[element];
	else element = null;
	return element;
}
//carpeLeft: Cross-browser version of "element.style.left"
function carpeLeft(elmnt, pos)
{
	if (!(elmnt = carpeGetElementById(elmnt))) return 0;
	if (elmnt.style && (typeof(elmnt.style.left) == 'string')) {
		if (typeof(pos) == 'number') elmnt.style.left = pos + 'px';
		else {
			pos = parseInt(elmnt.style.left);
			if (isNaN(pos)) pos = 0;
		}
	}
	else if (elmnt.style && elmnt.style.pixelLeft) {
		if (typeof(pos) == 'number') elmnt.style.pixelLeft = pos;
		else pos = elmnt.style.pixelLeft;
	}
	return pos;
}
//carpeTop: Cross-browser version of "element.style.top"
function carpeTop(elmnt, pos)
{
	if (!(elmnt = carpeGetElementById(elmnt))) return 0;
	if (elmnt.style && (typeof(elmnt.style.top) == 'string')) {
		if (typeof(pos) == 'number') elmnt.style.top = pos + 'px';
		else {
			pos = parseInt(elmnt.style.top);
			if (isNaN(pos)) pos = 0;
		}
	}
	else if (elmnt.style && elmnt.style.pixelTop) {
		if (typeof(pos) == 'number') elmnt.style.pixelTop = pos;
		else pos = elmnt.style.pixelTop;
	}
	return pos;
}
//moveSlider: Handles slider and display while dragging

function moveSlider(evnt)
{
	var evnt = (!evnt) ? window.event : evnt; // The mousemove event
	if (mouseover) 
	{ // Only if slider is dragged
		x = pxLeft + evnt.screenX - xCoord // Horizontal mouse position relative to allowed slider positions
		if (x > sliderObj.xMax) x = sliderObj.xMax // Limit horizontal movement
		if (x < 0) x = 0 // Limit horizontal movement

		
		if(sliderObj.actualJid == 1)
			x=sliderObj.val1=Math.max(sliderObj.val0,x);
		else if(sliderObj.val1)
			x=sliderObj.val0=Math.min(sliderObj.val1,x);	
			
		
		//alert(sliderObj.id);
		carpeLeft(sliderObj.id, x+shift)  // move slider to new horizontal position
		sliderVal = sliderObj.val0  // pixel value of slider regardless of orientation
		sliderPos = (sliderObj.pxLen / sliderObj.valCount) * Math.round(sliderObj.valCount * sliderVal / sliderObj.pxLen)
		var v0 = Math.round((sliderPos * sliderObj.scale + sliderObj.fromVal) * // calculate display value
			Math.pow(10, displayObj.dec)) / Math.pow(10, displayObj.dec);
		sliderVal = sliderObj.val1  // pixel value of slider regardless of orientation
		sliderPos = (sliderObj.pxLen / sliderObj.valCount) * Math.round(sliderObj.valCount * sliderVal / sliderObj.pxLen)
		var v1 = Math.round((sliderPos * sliderObj.scale + sliderObj.fromVal) * // calculate display value
			Math.pow(10, displayObj.dec)) / Math.pow(10, displayObj.dec);
		displayObj.value =  v0+','+v1; // v // put the new value in the slider display element
		
		
		
		return false;
	}
	return
	
	
}
//moveSlider: Handles the start of a slider move.
function slide(evnt, orientation, length, from, to, count, decimals, displayId, shiftSecond)
{
	
	if (!evnt) evnt = window.event;
	sliderObj = (evnt.target) ? evnt.target : evnt.srcElement; // Get the activated slider element.
	sliderObj.pxLen = length // The allowed slider movement in pixels.
	sliderObj.actualJid=(shiftSecond>0?1:0);
	sliderObj.valCount = count ? count - 1 : length // Allowed number of values in the interval.
	displayObj = carpeGetElementById(displayId) // Get the associated display element.
	
	var v=displayObj.value;
	var values=v.split(',');
	sliderObj.val0=values[0];
	sliderObj.val1=values[1];
	
	//alert('slide');
	displayObj.dec = decimals // Number of decimals to be displayed.
	sliderObj.scale = (to - from) / length // Slider-display scale [value-change per pixel of movement].
	if (orientation == 'horizontal') { // Set limits for horizontal sliders.
		sliderObj.fromVal = from
		sliderObj.xMax = length
	}
	if (sliderObj.actualJid==1)
		shift=shiftSecond; 
	else 
		shift=0;
	pxLeft = carpeLeft(sliderObj.id)-shift // Sliders horizontal position at start of slide.
	xCoord = evnt.screenX // Horizontal mouse position at start of slide.
	mouseover = true
	document.onmousemove = moveSlider // Start the action if the mouse is dragged.
	document.onmouseup = sliderMouseUp // Stop sliding.
}
//sliderMouseup: Handles the mouseup event after moving a slider.
//Snaps the slider position to allowed/displayed value. 
function sliderMouseUp()
{
	mouseover = false // Stop the sliding.
	v = (displayObj.value) ? displayObj.value : 0 // Find last display value.
	
	if(displayObj.onchange)
	{
		//alert('onchange');
		displayObj.onchange();
	}
	
	pos = (v - sliderObj.fromVal)/(sliderObj.scale) // Calculate slider position (regardless of orientation).
	if (sliderObj.xMax == 0) carpeTop(sliderObj.id, pos) // Snap vertical slider to corresponding display position.
	if (document.removeEventListener) { // Remove event listeners from 'document' (Moz&co).
			document.removeEventListener('mousemove', moveSlider, false);
			document.removeEventListener('mouseup', sliderMouseUp, false);

	}
	else if (document.detachEvent) { // Remove event listeners from 'document' (IE&co).
			document.detachEvent('onmousemove', moveSlider);
			document.detachEvent('onmouseup', sliderMouseUp);
			document.releaseCapture();

	}
}
