function openNewWin(theURL,winName,features)
{
	window.open(theURL,winName,features);
}

function jumpMenu(targ,selObj,http,restore)
{
	eval(targ+".location='"+http+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}

function classChange(newClass, obj)
{
	var object = null;

	if (document.getElementById)
	{
		object = document.getElementById(obj);
	}
	else if (document.all)
	{
		object = document.all[obj];
	}
	else if (document.layers)
	{
		object = document.layers[obj];
	}

	if ( object )
	{
		object.className = newClass;
	}
}

function hide(what, obj)
{
	var div = null;

	if (document.getElementById)
	{
		div = document.getElementById(obj);
	}
	else if (document.all)
	{
		div = document.all[obj];
	}
	else if (document.layers)
	{
		div = document.layers[obj];
	}
	
	if (!div) {	}
	else if (div.style)
	{
		if (what == 'show')
		{
			div.style.display = 'block';
		}
		else
		{
			div.style.display = 'none';
		}
	}
	else
	{
		if (what == 'show')
		{
			div.visibility = 'show';
		}
		else
		{
			div.visibility = 'hidden';
		}
	}
}

function myswitch(obj)
{
	var div = null;

	if (document.getElementById)
	{
		div = document.getElementById(obj);
	}
	else if (document.all)
	{
		div = document.all[obj];
	}
	else if (document.layers)
	{
		div = document.layers[obj];
	}
	
	if (!div) {	}
	else if (div.style)
	{
		if (div.style.display != 'none')
		{
			div.style.display = 'none';
		}
		else
		{
			div.style.display = 'block';
		}
	}
	else
	{
		if (div.visibility == 'hidden')
		{
			div.visibility = 'show';
		}
		else
		{
			div.visibility = 'hidden';
		}
	}
}

function switch_file_type(new_type)
{
	if (new_type == 0)
	{
		hide("hide", "file_forms");
		hide("hide", "add_file");
		hide("hide", "add_add_file");
	}
	else if (new_type == 1)
	{
		if (file_type == 0)
		{
			hide("show", "add_file");
		}
		else
		{
			hide("show", "file_forms");
			hide("hide", "add_file");
		}

		hide("hide", "add_add_file");
	}
	else if (new_type == 2)
	{
		hide("show", "file_forms");
		hide("show", "add_file");
		hide("show", "add_add_file");
	}
}

function switch_img_type(new_type)
{
	if (new_type == 0)
	{
		hide("hide", "image_forms");
		hide("hide", "add_image");
	}
	else if (new_type == 1)
	{
		if (img_type == 0)
		{
			hide("show", "add_image");
		}
		else
		{
			hide("show", "image_forms");
			hide("hide", "add_image");
		}
	}
	else if (new_type == 2)
	{
		hide("show", "image_forms");
		hide("show", "add_image");
	}
}

function swap_img_src(src1, src2, obj)		// carefull - src MUST be an absolute path !
{
	var object = document.getElementById(obj);

	if (object && object.src == src1)
	{
		object.src = src2;
	}
	else if( object )
	{		
		object.src = src1;
	}
}

function textCounter( field, maxlimit, countfield, alert )
{
	if ( maxlimit && field.value.length > maxlimit )
	{
		field.value = field.value.substring( 0, maxlimit );
		
		if ( alert )
		{
			alert( alert );
		}

		return false;
	}
	else
	{
		countfield.value = field.value.length;
	}
}

function unsafe_value( input )
{
	input = replace( input, '&amp;', '&' );
	input = replace( input, '&gt;', '>' );
	input = replace( input, '&lt;', '<' );
	input = replace( input, '&quot;', '"' );
	input = replace( input, '&#036;', '$' );
	input = replace( input, '&#33;', '!' );
	input = replace( input, '&#39;', "'" );
	input = replace( input, '<BR>', "\n" );
	input = replace( input, '<BR/>', "\n" );

	return input;
}

function safe_value( input )
{
	input = replace( input, '&', '&amp;' );
	input = replace( input, '>', '&gt;' );
	input = replace( input, '<', '&lt;' );
	input = replace( input, '"', '&quot;' );
	input = replace( input, '$', '&#036;' );
	input = replace( input, '!', '&#33;' );
	input = replace( input, "'", '&#39;' );
	input = replace( input, "\n", '<BR/>' );

	return input;
}

// http://www.krikkit.net/howto_javascript_copy_clipboard.html
function clip( txt, auto )
{
	if ( window.clipboardData ) 
	{
		window.clipboardData.setData('Text', txt);
		return true;
	}
	else if ( window.opera ) {
		if (! auto )
			alert("Funkcja nie jest dostepna na Operze, przykro nam...");
	}
	else if (window.netscape) 
	{
		try {
			netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
		}
		catch( e ) {
			return false;
		}

		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;

		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;

		trans.addDataFlavor('text/unicode');

		var str = new Object();
		var len = new Object();

		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);

		var copytext=txt;

		str.data=copytext;

		trans.setTransferData("text/unicode",str,copytext.length*2);

		var clipid=Components.interfaces.nsIClipboard;

		if (!clip) return false;

		clip.setData(trans,null,clipid.kGlobalClipboard);
		return true;
	}

	return false;
}