// ZSite CMS
// JavaScript IP adress string validator
// IPv4 [x][x]x.[x][x]x.[x][x]x.[x][x]x adress are confirmed valid
// (c) Zagorodnikov Anton 2007

function zsite_validate_ipadress(text)
{
    if(text.length < 1)
    {
	zsite_validation_error = "empty_string";
	return false;
    }
    
    //now get all of IP adress number groups
    var ipnumbers = Array();
    var counter = 0;
    var dotposition = text.search("[\.]");
    while(dotposition > 0)
    {
	ipnumbers[counter] = text.substring(0,dotposition);
	text = text.substr(dotposition+1,text.length);
	dotposition = text.search("[\.]");
	counter++;
    }
    ipnumbers[counter] = text;
    counter++;
    
    if(counter != 4)
    {
	zsite_validation_error = ZLOCALE("IP adress must contain 4 number groups");
	return false;    
    }

    //now check numbers
    var c = 0;
    for(c = 0; c < counter; c++)
    {
	if((ipnumbers[c].length < 1)||(ipnumbers[c].length > 3))
	{
	    zsite_validation_error = ZLOCALE("IP numbers must be 1-3 number length (0-254)");
	    return false;
	}
	if(ipnumbers[c].search("[^0-9]") > 0)
	{
	    zsite_validation_error = ZLOCALE("IP number must contain only numbers divided by dots");
	    return false;
	}
    }
    
    return true;
}
