function getElement(id) {
  var elem;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( id );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[id];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[id];
  return elem;
}

function validate_email(email) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	return reg.test(email);
}

function validateForm(fields){
	var valid=true;
	for(indice in fields)
	{
		var field_name = fields[indice];
		valid = valid && getElement(field_name).value != "";
		if(field_name == 'email')
			valid = valid && validate_email(getElement(field_name).value);
		if(field_name == 'phone')
			valid = valid && (getElement(field_name).value).length >4;
	}
	if(valid)
		return true;
	else
	{
		for(indice in fields)
		{
			var field_name = fields[indice];
			if(getElement(field_name).value == "")
				getElement('span'+field_name).className = "text-title";
			else
				getElement('span'+field_name).className = "hide";
			if(field_name == 'email')
			{
				if(!validate_email(getElement(field_name).value))
					getElement('span'+field_name).className = "text-title";
				else
					getElement('span'+field_name).className = "hide";
			}
			if(field_name == 'phone')
			{
				if((getElement(field_name).value).length <5)
					getElement('span'+field_name).className = "text-title";
				else
					getElement('span'+field_name).className = "hide";
			}
		}
		return false;
	}
}