<!--
var ok = "1px solid #66cc66";
var err = "1px solid #ff0000";
var a1, a2, a3, a4;

function validate(field)
{
	switch(field)
	{
		case 'name':
			a1 = validate_name();
			break;
		case 'about':
			a2 = validate_about();
			break;
		case 'photo':
			a3 = validate_photo();
			break;
		case 'code':
			a4 = validate_code();
			break;
		case 'phone':
			a5 = validate_phone();
			break;
		default:
			a1 = validate_name();
			a2 = validate_about();
			a3 = validate_photo();
			a4 = validate_code();
			a5 = validate_phone();
			break;
	}

	submit.disabled = !a1 || !a2 || !a3 || !a4 || !a5;
}

function validate_name()
{
	var name = document.getElementById ("name");

	len = name.value.length;
	if ( len < 3 || len > 24 )
	{
		name.style.border = err;
		return false;
	}
	else
	{
		name.style.border = ok;
		return true;
	}
}

function validate_about()
{
	var about = document.getElementById ("about");
	var counter = document.getElementById ("counter");
	
	len = about.value.length;
	var sym_left = 120 - len;
	
	if ( len < 20 )
	{
		counter.innerHTML = "минимум&nbsp;&#8212; 20 символов";
	}
	else if ( sym_left > 0 )
	{
		counter.innerHTML = "остал" + decliner(sym_left,"ся","ось","ось") + " " + sym_left + " символ" + decliner(sym_left,"","а","ов");
	}
	else if ( sym_left < 0 )
	{
		sym_left = Math.abs(sym_left);
		counter.innerHTML = "<span class=\"err\">лимит превышен на " + sym_left + " символ" + decliner(sym_left,"","а","ов") + "</span>";
	}
	else
	{
		counter.innerHTML = "не осталось символов";
	}

	if ( len < 20 || len > 120 )
	{
		about.style.border = err;
		return false;
	}
	else
	{
		about.style.border = ok;
		return true;
	}
}

function validate_code()
{
	var code = document.getElementById ("tel_code");

	var new_code = 	code.value.replace(/[^0-9]+/g, "");
	if ( new_code != code.value )
	{
		code.value = new_code;
	}

	len = code.value.length;
	if ( len != 0 && len < 3 )
	{
		code.style.border = err;
		return false;
	}
	else
	{
		code.style.border = ok;
		return true;
	}
}

function validate_phone()
{
	var tel = document.getElementById ("telephone");

	var new_tel = tel.value.replace(/[^-0-9]+/g, "");
	if ( new_tel != tel.value )
	{
		tel.value = new_tel;
	}

	if ( tel.value.replace(/[^0-9]+/g, "").length < 5 )
	{
		tel.style.border = err;
		return false;
	}
	else
	{
		tel.style.border = ok;
		return true;
	}
}

function validate_photo()
{
	var photo = document.getElementById ("photo");

	len = photo.value.length;
	if ( len < 4 )
	{
		photo.style.border = err;
		return false;
	}
	else
	{
		photo.style.border = ok;
		return true;
	}
}


function decliner(n, one, two, five)
{
	var val;

	if ( n%10 == 1 && n%100 != 11)
		val = one;
	else if ( n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) )
		val = two;
	else
		val = five;

	return val;
}
//-->
