// ZSite CMS
// JavaScript variable name validator
// variable name must begin with a letter and
// can contain latin letters, numbers, and
// underscore symbol
// (c) Zagorodnikov Anton 2007

function zsite_validate_variablename(text)
{
    if(text.length < 1)
    {
	zsite_validation_error = "empty_string";
	return false;
    }

    var charpos = text.search("[^A-Za-z0-9_]");
    if(text.length > 0 && charpos >= 0)
    {
	//some inappropriate character found
	zsite_validation_error = "invalid_character";
	return false;
    }

    if(text[0] == "_")
    {
	zsite_validation_error = "underscore_begin";
	return false;
    }

    if((text[0] == "0")||(text[0] == "1")||(text[0] == "2")||(text[0] == "3")||(text[0] == "4")||(text[0] == "5")||(text[0] == "6")||(text[0] == "7")||(text[0] == "8")||(text[0] == "9"))
    {
	zsite_validation_error = "number_begin";
	return false;
    }

    return true;
}
