var arrError = new Array;

var recievercount = 3;
var recievermax = 6;

function addfriend()
{
	if(recievercount <= recievermax)
	{
		recievercount++;
		var recieverblock = '<br class="clear" /><label for="vriend_naam_' + recievercount + '">Naam vriend </label><input type="text" name="vriend_naam_' + recievercount + '" id="vriend_naam_' + recievercount + '" class="text" /><div class="formerror">&laquo;  <b>LET OP!</b> Vul het veld juist in</div><br class="clear" />';
		recieverblock += '<label for="vriend_email_' + recievercount + '">E-mail adres </label><input type="text" name="vriend_email_' + recievercount + '" id="vriend_email_' + recievercount + '" class="text" /><div class="formerror">&laquo;  <b>LET OP!</b> Vul het veld juist in</div><br class="clear" />';

		var wrapper = new Element('div');
		wrapper.setProperty('id', 'reciever_' + recievercount);
		wrapper.innerHTML = recieverblock;
		wrapper.injectInside("more_friends");
	}
}

function checkSendAFriend()
{
	$('error').innerHTML = '';
	var EmailExpression = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if($('naam').value == '')
	{
		arrError.push('Je hebt je eigen naam nog niet ingevuld');
	}
	
	if($('boodschap').value == '')
	{
		arrError.push('Je hebt nog geen persoonlijke boodschap ingevuld');
	}
	
	
	if(!EmailExpression.test($('email').value))
	{
		arrError.push('Je eigen e-mailadres is niet geldig of niet ingevuld');
	}
	
	for(var i = 1; i < recievercount; i++)
	{
		if(
			(
				( $('vriend_naam_' + i).value != '' )
				&&
				( $('vriend_email_' + i).value != '' )
				&&
				( !EmailExpression.test($('vriend_email_' + i).value) )
			)
			||
			(
				( ( $('vriend_naam_' + i).value == '' ) && ( $('vriend_email_' + i).value != '' ) )
				||
				( ( $('vriend_email_' + i).value == '' ) && ( $('vriend_naam_' + i).value != '' ) )
			)
		)
		{
			console.log(i);
			arrError.push('Je hebt gegevens van een vriend niet goed ingevuld');
			i = recievercount;
		}
	}
	
	if(arrError.length == 0)
	{
		$('form').submit();
		return true;
	}
	else
	{
		handleErrors(arrError);
		return false;
	}
}

function checkStap1()
{
  // $('error').innerHTML = '';
	
	if($('naam').value == '')
	{
		arrError.push('Er is nog geen naam ingevuld');
	}
	
	var EmailExpression = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(EmailExpression.test($('email')) || $('email').value == '')
	{
		arrError.push('Er is nog geen (geldig) E-mail adres ingevuld');
	}
	
	if($('stad').value == '')
	{
		arrError.push('Er is nog geen stad geselecteerd');
	}
  // if($('verhaal').value == '')
  // {
  //  arrError.push('Je hebt nog niet verteld waarom je groen bent');
  // }
  // 
  // if($('straat').value == '')
  // {
  //  arrError.push('Er is nog geen straatnaam ingevuld');
  // }

	if(arrError.length == 0)
	{
		$('form').submit();
		return true;
	}
	else
	{
		handleErrors(arrError);
		return false;
	}
}

function checkStap2()
{
	$('error').innerHTML = '';
	
  // if($('foto').value == '')
  // {
  //  arrError.push('Er is nog geen foto bijgevoegd');
  // }    
	
}

function handleErrors()
{
	strErrors = '';
	for(var i = 0; i < arrError.length; i++)
	{
		strErrors += '- ' + arrError[i] + '<br />';
	}
	
	arrError.length = 0;
  $('error').innerHTML = strErrors;
	return false;
}

function insertKey(argForm, argField)
{
	myForm = document.forms[argForm];
	myForm[argField].value = 'aNtIsPaMkEy!!11';
}
