function getModels(source, dest_id)
{
    /*
    with jQuery ;)
    $("#"+dest_id).removeOption(/./);
    $("#"+dest_id).addOption('null','---');
    if (source == undefined) return (false);
    $.each(source, function(i,a)
    {
        $("#"+dest_id).addOption(a,a);
    });
    $("#"+dest_id).selectOptions('null');
    */
    
    var dest = document.getElementById(dest_id);
    dest.options.length = 0;
    
    addOption(dest_id,'---','null');
    
    if (source == undefined) return (false);
    
    for (var a in source)
    {
        addOption(dest_id,source[a],source[a]);
    }
}

function addOption(select_id, text, value)
{
        dest = document.getElementById(select_id);
        var y=document.createElement('option');
        y.text = text;
        y.value = value;
        try
          {
          dest.add(y,null); // standards compliant
          }
        catch(ex)
          {
          dest.add(y); // IE only
          }
}


function resizeElement(element_id, max)
{
    elem = document.getElementById(element_id);
    h = elem.parentNode.parentNode.scrollHeight;
    //alert(h);
    if (h < 850) h = 850;
    /*if (h > max) h = max; //alert(h);
    */
    elem.style.height = h + 'px';
    //elem.style.height = 150 + 'px';
}

function Scroll(element_id, timeout)
{
    if (typeof window.pos === 'undefined') window.pos = 0;
    if (typeof window.pos2 === 'undefined') window.pos2 = 0;
    obj=document.getElementById(element_id);
    if (obj.scrollHeight <= obj.parentNode.clientHeight) return;
    obj.onmouseover = pauseScroll;
    obj.onmouseout = function onmouseout(event) {startScroll(element_id, timeout);}
    window.pos -= 1;
    obj.style.top = window.pos+'px';
    
    t = window.setTimeout( "Scroll('"+element_id+"',"+timeout+");" ,  timeout);
    
    if (window.pos == 0 - (obj.scrollHeight - obj.parentNode.clientHeight) && typeof obj2 === 'undefined')
    {
        obj2 = obj.cloneNode(true);
        obj2.setAttribute('id',element_id + '_tmp');
        obj2.onmouseover = pauseScroll;
        obj2.onmouseout = function onmouseout(event) {startScroll(element_id, timeout);}
        obj.parentNode.appendChild(obj2);
        window.pos2 = window.pos + obj.scrollHeight;
    }
    if (typeof obj2 !== 'undefined')
    {
        window.pos2 -= 1;
        obj2.style.top = window.pos2+'px';
        
        if(window.pos == 0 - (obj.scrollHeight))
        {
            window.pos = window.pos2 + obj2.scrollHeight;    
        }
        
        
        if (window.pos2 == 0 - (obj2.scrollHeight))
        {
            window.pos2 = window.pos + obj.scrollHeight;    
        }
        
    }

}

function pauseScroll()
{
    window.clearTimeout(t);
}

function startScroll(element_id, timeout)
{
    t = window.setTimeout( "Scroll('"+element_id+"',"+timeout+");" ,  timeout);
}

function openfoto($fid, $lit, $max_lit)
{
	window.open('?go=foto&fid='+$fid+'&lit='+$lit+'&lits='+$max_lit, $fid, 'left=60,top=90,width=900,height=680,toolbar=0,resizable=0,scrollbars=yes')
}

function timedown()
{
	for(i = 0; i < window.ile; i++)
	{
		id = 'th'+i;
		if (!document.getElementById(id)) break;
		t = document.getElementById(id).innerHTML;
		t = t - 1;
		if (t < 0)
		{
			document.getElementById(id).innerHTML = '0';
			id = 't'+i;
			document.getElementById(id).innerHTML = "00:00:00 <i>Oferta nieaktualna</i>";
		} else {
			document.getElementById(id).innerHTML = t;
			id = 't'+i;
			h = Math.floor(t / 3600);
			if (h < 10) h = '0'+h;
			t = t % 3600;
			m = Math.floor(t / 60);
			if (m < 10) m = '0'+m;
			s = t % 60;
			if (s < 10) s = '0'+s;
			document.getElementById(id).innerHTML = h+':'+m+':'+s;
		}
	}
	setTimeout("timedown()", 1000);
}

