//---------------------------------------------------------------------
var OrdersImpColor = '#FF0000';
var OrdersColor = '#000000';
var ExtraImp = new Number();
var MyElementType = new Array();
//Extra
ExtraImp["zathitnyj_kod"] = 0 ;
MyElementType["zathitnyj_kod"] = 'text' ;
//Extra


function assocCount(Assoc)
{
	c=0;
	for (MyElement in Assoc) c++;
	return c;
}
function assocTrueCount(Assoc)
{
	c=0;
	for (MyElement in Assoc) if (Assoc[MyElement]) c++;
	return c;
}
function Clear ()
{
	for (MyElement in ExtraImp) 
	{
		bool = false;
		if (MyElementType[MyElement] == 'select')
		{
			if (document.getElementById(MyElement).selectedIndex > -1)
				bool = true;
		}
		else if (MyElementType[MyElement] == 'checkbox')
		{
			for (i = 0; ; i++)
			{
				if (!(obj = document.getElementById('extra['+MyElement+']['+i+']')))
					break;
				if (obj.checked)
				{	bool = true; break;	}
			}
		}
		else if (MyElementType[MyElement] == 'text')
		{
			if (document.getElementById(MyElement).value.length > 3)
				bool = true;
		}
		if (bool)
		{
			ExtraImp[MyElement] = 1;
			document.getElementById('div_'+MyElement).style.color=OrdersColor;
		}
		else
		{
			ExtraImp[MyElement] = 0;
			document.getElementById('div_'+MyElement).style.color=OrdersImpColor;
		}
	}
	CheckFields();
}
function CheckGroup(id)
{
	bool = false;
	for (i = 0; ; i++)
	{
		if (!(obj = document.getElementById('extra['+id+']['+i+']')))
			break;
		if (obj.checked)
		{	bool = true; break;	}
	}
	divobj = document.getElementById('div_'+id);
	if (bool)
	{
		ExtraImp[id] = 1;
		divobj.style.color=OrdersColor;
	}
	else
	{
		ExtraImp[id] = 0;
		divobj.style.color=OrdersImpColor;
	}
	CheckFields();
}
function CheckTextField (id, bool)
{
	res = 0;
	if (document.getElementById(id).value.length > 3)
	{
		document.getElementById('div_'+id).style.color= OrdersColor;
		res = 1;
	}
	else document.getElementById('div_'+id).style.color=OrdersImpColor;
	if (bool)
		return res;
	else
	{
		ExtraImp[id] = res;
		CheckFields();
	}
	
}
function CheckSelectField (id)
{
	if (document.getElementById(id).selectedIndex > -1)
	{
		document.getElementById('div_'+id).style.color= OrdersColor;
		ExtraImp[id] = 1;
	}
	else 
	{
		document.getElementById('div_'+id).style.color=OrdersImpColor;
		ExtraImp[id] = 1;
	}
	CheckFields();
}

function CheckFields()
{
	names = new Array('name', 'phone');
	var empt = 0;
	for (i = 0; i < names.length; i++)
		empt+=CheckTextField(names[i], true);
	Count = names.length+assocCount(ExtraImp);
	res = empt + assocTrueCount(ExtraImp);
	if (res == Count)
		document.getElementById('button').disabled = false;
	else
		document.getElementById('button').disabled = true;
}


