if (!Array.prototype.indexOf)
{
	Array.prototype.indexOf = function(elt /*, from*/)
	{
		var len = this.length;
		
		var from = Number(arguments[1]) || 0;
		from = (from < 0) ? Math.ceil(from) : Math.floor(from);
		
		if (from < 0)
		{
			from += len;
		}
		
		for (; from < len; from++)
		{
			if ((from in this) && (this[from] === elt))
			{
				return from;
			}
		}
		
		return -1;
	};
}

function validate(exceptions)
{
	var inputs = [document.getElementsByTagName('input'),  document.getElementsByTagName('textarea')];
	var validates = true;
	var skip;
	var sub_validate_count;
	var i, j, k, l;
	var incomplete_fields = 0;
	
	for (i = 0; i < inputs.length; i++)
	{
		for (j = 0; j < inputs[i].length; j++)
		{
			if (inputs[i][j].id)
			{
				if (inputs[i][j].value.replace(/\s+/, '').length == 0)
				{
					skip = false;
					
					for (k = 0; k < exceptions.length; k++)
					{
						if (typeof(exceptions[k]) == 'object')
						{
							if (exceptions[k].indexOf(inputs[i][j].id) != -1)
							{
								sub_validate_count = 0;
								
								for (l = 0; l < exceptions[k].length; l++)
								{
									if (document.getElementById(exceptions[k][l]).value.replace(/\s+/, '').length != 0)
									{
										sub_validate_count++;
									}
								}
								
								if ((sub_validate_count == 0) || (sub_validate_count == exceptions[k].length))
								{
									skip = true;
								}
							}
						}
						else
						{
							if (exceptions[k] == inputs[i][j].id)
							{
								skip = true;
							}
						}
					}
					
					if (skip)
					{
						inputs[i][j].style.borderStyle = '';
						inputs[i][j].style.borderColor = '';
						inputs[i][j].style.borderWidth = '';
					}
					else
					{
						validates = false;
						incomplete_fields++;
						
						inputs[i][j].style.borderStyle = 'solid';
						inputs[i][j].style.borderColor = 'red';
						inputs[i][j].style.borderWidth = '2px';
					}
				}
				else
				{
					inputs[i][j].style.borderStyle = '';
					inputs[i][j].style.borderColor = '';
					inputs[i][j].style.borderWidth = '';
				}
			}
		}
	}
	
	if (!validates)
	{
		window.alert('There are ' + incomplete_fields + ' fields that have not been completed.');
	}
	
	return validates;
}