







var submitcount = 0;

function emailValid(eMail)
{
	return !(eMail.indexOf('@')==-1 || eMail.indexOf('.')==-1 
			|| (eMail.lastIndexOf('@')!=eMail.indexOf('@'))
			|| (eMail.charAt(0) == '@')
			|| (eMail.charAt(eMail.length-1) == '@'));
}


function checkFirstRegister(theForm)
{
	// guard against multiple submit
	if (submitcount == 0)
	{
		submitcount++;
	}
	else
	{
		return false;
	}

	var errors = "";
		
	if (theForm.elements['EMail'].value.length < 1) {
		errors = errors + "Missing EMail\n";
	}
	else {
		if (!emailValid(theForm.elements['EMail'].value))
			errors = errors + "Invalid Email Address\n";
	}

	if (theForm.elements['userName'].value.length < 1)
		errors = errors + "Missing Username\n";

	if (theForm.elements['userName'].value.length < 3 
			|| theForm.elements['userName'].value.length > 16)
		errors = errors + "Invalid username\n";
	
	if (theForm.elements['password1'].value.length < 1)
		errors = errors + "Missing Password\n";

	if (theForm.elements['password1'].value.length < 6 
			|| theForm.elements['password1'].value.length > 16)
		errors = errors + "Password has to be at least 6 characters\n";

	if (theForm.elements['password1'].value != theForm.elements['password2'].value)
		errors = errors + "Passwords don't match\n";

		
	if (errors.length > 0)
	{
		alert(errors);
		submitcount = 0;
		return false;
	}
	else
	{
		return true;
	}
}

function checkFullRegister(theForm)
{
	// guard against multiple submit
	if (submitcount == 0)
	{
		submitcount++;
	}
	else
	{
		return false;
	}

	var errors = "";

/*
	if (theForm.elements['firstName'].value.length < 1)
		errors = errors + "Missing First Name\n";
		
	if (theForm.elements['familyName'].value.length < 1)
		errors = errors + "Missing Family Name\n";
*/

	if (theForm.elements['street'].value.length < 1)
		errors = errors + "Missing Street address\n";

	if (theForm.elements['zip'].value.length < 1)
		errors = errors + "Missing Zipcode\n";

	if (theForm.elements['city'].value.length < 1)
		errors = errors + "Missing City\n";

//	if (theForm.elements['state'].value.length < 1)
//		errors = errors + "Missing State\n";

	//The country element is not present when customer updates his profile. 
	if(theForm.elements['country']!=null)
	{
		if (theForm.elements['country'].selectedIndex == 0)
			errors = errors + "Missing Country\n";
	}

	if (theForm.elements['phone'].value.length < 1)
		errors = errors + "Missing Phone number\n";

	if (errors.length > 0)
	{
		alert(errors);
		submitcount = 0;
		return false;
	}
	else
	{
		return true;
	}
}


function checkFirstProfile(theForm)
{
	// guard against multiple submit
	if (submitcount == 0)
	{
		submitcount++;
	}
	else
	{
		return false;
	}

	var errors = "";

	if (theForm.elements['EMail'].value.length < 1) {
		errors = errors + "Missing EMail\n";
	}
	else {
		if (!emailValid(theForm.elements['EMail'].value))
			errors = errors + "Invalid Email Address\n";
	}


	if ((theForm.elements['oldPassword'].value.length == 0)
			&& (theForm.elements['password1'].value.length > 0))
		errors = errors + "Missing Password\n";

	if (theForm.elements['password1'].value != theForm.elements['password2'].value)
		errors = errors + "Passwords don't match\n";

	if (errors.length > 0)
	{
		alert(errors);
		submitcount = 0;
		return false;
	}
	else
	{
		return true;
	}
}

