function item( id, caption, parent, main )
{
	this.id = id;
	this.caption = caption;
	this.parent = parent;
	this.main = main;
}

function coll()
{
	this.items = Array()
	this.addItem = addItem;
	this.fill = fill;
}
function addItem( item ) { this.items[ this.items.length ] = item; }

function fill( ctrl, parent, main, showGeneral )
{
	if ( ( parent > 0 ) || ( parent == -1 ) )
	{
		len = this.items.length; for( i = len; i >0 ; i-- ) ctrl.options[i] = null;
	}
	len = this.items.length;
	next_id = 0;
	if ( main == 0 )
	{
		if ( showGeneral )
		{
			ctrl.options[0] = new Option( "не важно", "-1", false, false );
			next_id = 1;
		}
	}

	for ( i=0; i < len; i++ )
	{
//		alert( i + ":" + this.items[i].parent + ":" + parent );
		var cParent = parseInt( this.items[i].parent );
		if ( cParent == parseInt( parent ) )
		{
			ctrl.options[next_id++] = new Option( this.items[i].caption, this.items[i].id, false, false );
		}
	}
	ctrl.selectedIndex = 0;
}

function isEmail( str )
{
	if ( str.length < 3 ) return false;
	part = Array();
	currentPartIndex = 0; part[currentPartIndex] = "";
	for ( i=0; i < str.length; i++ )
	{
		symbol = str.charAt(i);
		if ( ( symbol == "." ) || ( symbol == "@" ) )
		{
			currentPartIndex++;
			part[currentPartIndex] = "";
		}
		else
			part[currentPartIndex] = part[currentPartIndex] + symbol;
	}
		
	count = 0;
		
	for ( i=0; i < currentPartIndex + 1; i++ )
		if (! isNormal( part[i] ) ) count++;
		
	if ( count == 0 )
	{
		if ( str.indexOf("@") > -1 )
			res = true;
		else
			res = false;
	}
	else
		res = false;
		
	return res;
}

function checkAll( ctrlName, val )
{
	for ( i = 0; i < document.all.length; i++ )
	{
		v = document.all[i].name;
		if ( ( v != null ) && ( v != "" ) )
		if ( v.indexOf( ctrlName ) > -1 )
			document.all[i].checked = val;
	}
}

function isNormal( str )
{
	template = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890/-()";
	res = true;
	for ( i=0; i < str.length; i++ )
		if ( template.indexOf( str.charAt(i) ) == -1 ) res = false;
	return res;
}

