﻿var submitError;
function postAction(value)
{
	document.getElementById('mcAction').value = value;
	document.getElementById('form1').submit();
}

function create() {
	submitError = false;

	var email = document.getElementById('txtEmail');
	var name = document.getElementById('txtName');
	var surname = document.getElementById('txtSurname');
	var address = document.getElementById('txtAddress');
	var city = document.getElementById('txtCity');
	var zip = document.getElementById('txtZip');
	var company = document.getElementById('txtCompany');
	var username = document.getElementById('txtUsername');
	var password = document.getElementById('txtPassword');
	
	// Validate email
	checkEmailField(email);
	checkEmptyField(name);
	checkEmptyField(surname);
	checkEmptyField(address);
	checkEmptyField(city);
	checkEmptyField(zip);
	checkEmptyField(company);
	checkEmptyField(username);
	checkEmptyField(password);
	
	if (!submitError)
		postAction('create');
}

function checkEmailField(el)
{
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(el.value) == false) {
		el.nextSibling.style.display = '';
		submitError = true;
	}
	else
		el.nextSibling.style.display = 'none';
}

function checkEmptyField(el)
{
	if (el.value == '')
	{
		el.nextSibling.style.display = '';
		submitError = true;
	}
		
	if (el.value != '')
		el.nextSibling.style.display = 'none';
}