function popUpWindow(desktopURL)
{
	var desktop = window.open(desktopURL,
		"_blank","toolbar=no,location=no,status=no,menubar=no,width=400,height=250,scrollbars=no,resizable=no");
}

function change_ahref(a, lid)
{
	a.href="link-odwiedz"+lid+".html";
	a.onmousedown="";
	return true;
}

function change_text (node, text, error)
{
	while (node.hasChildNodes())
		node.removeChild(node.firstChild);

	node.appendChild(document.createTextNode(text));
	if (error)
		node.setAttribute ('style', 'color: red');
	else
		node.setAttribute ('style', 'color: black');
}

function load_script (cid, snr)
{
	frm = document.getElementById ("link_form");
	dscr = document.getElementById ("tmp_link_script");
	if (dscr)
	{
		frm.removeChild (dscr);
	}

	script = document.createElement('script');
	script.type = "text/javascript";
	script.src = "index.php?op=scat_script&cid="+cid+'&snr='+snr;
	script.id = "tmp_link_script";

	select = document.getElementById ('link_scat_'+snr);
	select.options.length = 0;
	select.options[0] = new Option ("--proszę czekać--", -1);

	frm.appendChild (script);
}

function fetch_data ()
{
	frm = document.getElementById ('link_form');
	info = document.getElementById ('fetch_info');
	fscr = document.getElementById ('tmp_fetch_script');

	if (fscr)
	{
		frm.removeChild (fscr);
	}

	link_url = frm['link_url'].value;

	if (link_url.length < 1)
	{

		change_text (info, 'Proszę wpisać adres', true);
		return;
	}

	change_text (info,'Proszę czekać... pobieranie danych', false);

	script = document.createElement('script');
	script.type = "text/javascript";
	script.src = "index.php?op=fetch_script&url="+escape(link_url);
	script.id = "tmp_fetch_script";
	frm.appendChild (script);
}

function update_counter (textarea, cname, min, max)
{
	counter = document.getElementById (cname);
	len = textarea.value.length;
	change_text (counter, 'znaków: '+len, (len < min || len > max ? true : false));
}
