function companyClick( hrf )
{
	if( hrf )
	{
		try {
			if( popupCompanyWin )
			{
				return true; //popupCompanyWin.self.location.replace(hrf);
			}
			else
				popup(hrf, 'width', 360, 'height', 500);
		}
		catch ( e ) { popup(hrf, 'width', 360, 'height', 500); }
	}
	return false;
}

function viewCompany( url )
{
	if( url )
	{
		if( url.indexOf('#') !=  (url.length - 1) )
			return true;
	}
	return false;
}

// firmy/dodaj-firme
function CheckCompany( d )
{
	var msg="";
	if( !d )
		d = document.forms.CompanyForm;
	if( !d )
	{
		alert('Formularz nie odnaleziony');
		return false;
	}
	if( !msg && !CheckItem(d.companyname, 'string') )
		msg += "Proszę podać nazwę firmy.";
	if( !msg && d.telephone.value && !CheckItem(d.telephone, 'phone') )
		msg += "Podany nr. telefonu, " + d.telephone.value + ", jest nieprawidowy";
	if( !msg && d.fax.value && !CheckItem(d.fax, 'phone') )
		msg += "Podany nr. fax, " + d.fax.value + ", jest nieprawidowy";
	if( !msg && !CheckItem(d.email, 'email') )
		msg += "Podany adres email, " + d.email.value + ", jest nieprawidowy";
	if( !msg && !CheckItem(d.elements['id_category[]'], 'int') )
		msg += "Proszę zaznaczyć kategorię, w której chcesz umieścic firmę.";
	if( !msg && !CheckItem(d.summary, 'string') )
		msg += "Proszę wprowadzic opis działalności firmy.";
		if( msg )
		alert(msg);
	return (msg=="");
}

function checkCategory( obj )
{
	if( numSelected(obj) > 3 )
	{
		opt = getOptionByValue( obj, obj.value );
		opt.selected = false;
		alert('Dozwolone jest zaznaczenie tylko trzech kategorii.\nPierwsza z wybranych kategorii została odznaczona!');
		try{ if(obj.form.selectedCategories)
				obj.form.selectedCategories.value = getSelected(obj);
		}catch(e){}
		getSelected(obj);
		return false;
	}
	try{ if(obj.form.selectedCategories)
			obj.form.selectedCategories.value = getSelected(obj);
	}catch(e){}
	return true;
}

function numSelected( obj )
{
	var num = 0;
	if( obj )
	{
		for(var i = 0; i < obj.options.length; i++)
			if( obj.options[i].selected)
				num++;
	}
	return num;
}

function getSelected( obj )
{
	var selected = '';
	if( obj )
	{
		var j = 1;
		for(var i = 0; i < obj.options.length; i++)
			if( obj.options[i].selected)
				selected += (j++)+'. ' +obj.options[i].innerHTML+"\n";
	}
	return selected;
}

function getOptionByValue( obj, value )
{
	if( obj )
	{
		for(var i = 0; i < obj.options.length; i++)
			if( obj.options[i].value == value)
				return obj.options[i];
	}
	return null;
}


function o_attachClass( obj, classname )
{
	if( obj && classname )
		obj.className = obj.className + " " + classname;
}

function o_stripClass( obj, classname )
{
	if( obj && classname && obj.className )
	{
		var classes=obj.className.split(" ");
		var newclasses = Array();
		for( x in classes )
		{
			if( classes[x] != classname )	// check if it's the hidden class
				newclasses.push(classes[x]);
		}
		obj.className = newclasses.join(" ");
	}
}