function submitToPopup(currentForm, action)
{
	window.open("", "popup", "width=100,height=50,left=" + (screen.width  - 100)/2 + ",top=" + (screen.height  - 50)/2 + ",scrollbars=no,statusbar=no");
	currentForm.action = action;
	currentForm.target = "popup";
	currentForm.submit();
}
function submitRegular(currentForm, action)
{
	currentForm.action = action;
	currentForm.submit();
}

function validateForm(currentForm)
{
	var valid = true;
	var radiovalid = true;
	var passwordMatch = true;
	var elementsInputs;
	
 	elementsInputs = currentForm.elements;
 
	//regular tests
	for (var intCounter = 0; intCounter < elementsInputs.length; intCounter++)
	{
		currentField = elementsInputs[intCounter];
		
		if (currentField.type != "button" && currentField.type != "hidden" && currentField.type != "radio")
		{
			if (currentField.name == "Email")
			{
				if (validateEmail(currentField.value))
				{
					currentField.style.backgroundColor = "#FFFFFF";
				}
				else
				{
					valid = false;
					
					currentField.style.backgroundColor = "#FFD5D6";
				}
			}
			else if (currentField.name == "imagefile2" || currentField.name == "imagefile3" || currentField.name == "imagefile4" || currentField.name == "imagefile5")
			{
				//imagevelden die niet gecontroleerd hoeven te worden	
			}
			else
			{
				if (validateText(currentField.value))
				{
					currentField.style.backgroundColor = "#FFFFFF";
				}	
				else
				{
					valid = false;
					
					currentField.style.backgroundColor = "#FFD5D6";
				}
			}
		}
		else if(currentField.type == "radio")
		{
			radiovalid = false;
			
			group = currentForm.elements[currentField.name];

			for(var k=0; k < group.length;k++) 
			{
				if(group[k].checked)
				{
					radiovalid = true;
				}
			}
		}
		else
		{
			//niet controleren	
		}
	}
	
	//Password test
	if(elementsInputs["Password2"])
	{
		if (elementsInputs["Password"].value != elementsInputs["Password2"].value)
		{
			passwordMatch = false;
			
			elementsInputs["Password"].style.backgroundColor = "#FFD5D6";
			elementsInputs["Password2"].style.backgroundColor = "#FFD5D6";
		}
	}
	
	if (!radiovalid)
	{
		alert("Please check all fields");
		
		return false;
	}
	else if (!valid)
	{
		alert("Please check the red marked fields");
		
		return false;
	}
	else if (!passwordMatch)
	{
		alert("Please make sure your passwords match");
		
		return false;
	}
	else
	{
		return true;
	}
}

function validateEmail(value)
{
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (emailFilter.test(value)) 
	{ 
		return true; 
	} 
}
	
function validateText(value)
{
	if (value != "" && value != "notselected")
	{
		return true;
	}
}