function check(radio)
{
	option = -1;
	for(i = radio.length - 1; i > -1; i --)
	{
		if(radio[i].checked)
		{
			option = i;
			i = -1;
		}
	}
	if(option != -1) return true;
	else return false;
}

function isnum(txt)
{
	var chars = "0123456789.";
	var isnum = true;
	var char;
	for(i = 0; i < txt.length && isnum == true; i ++)
	{
		char = txt.charAt(i);
		if(chars.indexOf(char) == -1) isnum = false;
	}
	return isnum;
}

function trim(str)
{
	while(str.substring(0, 1) == " ") str = str.substring(1, str.length);
	while(str.substring(str.length - 1, str.length) == " ") str = str.substring(0, str.length - 1);
	return str;
}

function validare()
{
	var cssbun = '#fff';
	var cssrau = '#fcc';
	// agentie
	if(trim(document.form.agentie.value) == '')
	{
		alert('Introduceti numele agentiei!');
		document.form.agentie.focus();
		document.form.agentie.style.backgroundColor = cssrau;
		return false;
	}
	else document.form.agentie.style.backgroundColor = cssbun;
	// adresa
	if(trim(document.form.adresa.value) == '')
	{
		alert('Introduceti adresa agentiei!');
		document.form.adresa.focus();
		document.form.adresa.style.backgroundColor = cssrau;
		return false;
	}
	else document.form.adresa.style.backgroundColor = cssbun;
	// oras
	if(trim(document.form.oras.value) == '')
	{
		alert('Introduceti numele orasului!');
		document.form.oras.focus();
		document.form.oras.style.backgroundColor = cssrau;
		return false;
	}
	else document.form.oras.style.backgroundColor = cssbun;
	// judet
	if(document.form.judet.selectedIndex == 0)
	{
		alert('Selectati judetul corespunzator!');
		document.form.judet.focus();
		document.form.judet.style.backgroundColor = cssrau;
		return false;
	}
	else document.form.judet.style.backgroundColor = cssbun;
	// telefon
	if(trim(document.form.telefon.value) == '')
	{
		alert('Introduceti numarul de telefon!');
		document.form.telefon.focus();
		document.form.telefon.style.backgroundColor = cssrau;
		return false;
	}
	else document.form.telefon.style.backgroundColor = cssbun;
	// email
	var email = trim(document.form.email.value);
	if(email != '' && email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1)
	{
		alert('E-mail-ul introdus nu este corect!');
		document.form.email.focus();
		document.form.email.style.backgroundColor = cssrau;
		return false;
	}
	else if(email == '')
	{
		alert('Introduceti adresa de e-mail!');
		document.form.email.focus();
		document.form.email.style.backgroundColor = cssrau;
		return false;
	}
	else document.form.email.style.backgroundColor = cssbun;
	// societate
	if(trim(document.form.societate.value) == '')
	{
		alert('Introduceti numele societatii!');
		document.form.societate.focus();
		document.form.societate.style.backgroundColor = cssrau;
		return false;
	}
	else document.form.societate.style.backgroundColor = cssbun;
	// cod fiscal
	var cod = trim(document.form.codfiscal.value);
	if(cod == '')
	{
		alert('Introduceti codul fiscal!');
		document.form.codfiscal.focus();
		document.form.codfiscal.style.backgroundColor = cssrau;
		return false;
	}
	else document.form.codfiscal.style.backgroundColor = cssbun;
	// reg comert
	if(trim(document.form.regcomert.value) == '')
	{
		alert('Introduceti nr. de la reg. comertului!');
		document.form.regcomert.focus();
		document.form.regcomert.style.backgroundColor = cssrau;
		return false;
	}
	else document.form.regcomert.style.backgroundColor = cssbun;
	// username
	var username = trim(document.form.username.value);
	if(username == '')
	{
		alert('Introduceti un nume de utilizator!');
		document.form.username.focus();
		document.form.username.style.backgroundColor = cssrau;
		return false;
	}
	else if(username.indexOf(' ') != -1)
	{
		alert('Nu sunt permise spatiile in numele de utilizator!');
		document.form.username.focus();
		document.form.username.style.backgroundColor = cssrau;
		return false;
	}
	else document.form.username.style.backgroundColor = cssbun;
	// password
	var password = trim(document.form.password.value);
	if(password == '')
	{
		alert('Introduceti o parola de acces!');
		document.form.password.focus();
		document.form.password.style.backgroundColor = cssrau;
		return false;
	}
	else document.form.password.style.backgroundColor = cssbun;
	// passconf
	var passconf = trim(document.form.passconf.value);
	if(passconf == '')
	{
		alert('Confirmati parola introdusa!');
		document.form.passconf.focus();
		document.form.passconf.style.backgroundColor = cssrau;
		return false;
	}
	else if(passconf != password)
	{
		alert('Parolele introduse nu corespund!');
		document.form.passconf.focus();
		document.form.passconf.style.backgroundColor = cssrau;
		return false;
	}
	else document.form.passconf.style.backgroundColor = cssbun;
}
