var AllowSubmission = false;

function properCase(a)
{
var b="";
var notyet=true;
for (i=0;i<=a.length;i++)
	{
	m = a.substr(i,1)
	b += (notyet) ? m.toUpperCase() : m.toLowerCase();
	notyet = ((m.toUpperCase() == m.toLowerCase()) && (m!="'"))
	}
return b
}


function FormatPostCode(TextBox, CountryCombo)
{

var a=0;
var b=0;
var InStr="";
var Counter=0;
var NumNumericCharsInMiddle=2;

InStr = TextBox.value.toUpperCase();
if ((CountryCombo.value==226) || CountryCombo.value==1)
	{
	//User is in UK. See that postcode is appropriately formatted.
	
	if ((InStr.charAt(0) < 65) || (InStr.charAt(0) > 90)) return 0;

	if (InStr.length<4) return 0;

	b = InStr.length;

	while (a < b)
		{
		if ((InStr.charCodeAt(a) > 47) && (InStr.charCodeAt(a) < 58))
			{
			// Numeric
			if (Counter == 3) { NumNumericCharsInMiddle += 1; }
			if (Counter == 2) { Counter = 3; }
			if (Counter == 1) { Counter = 2; }
			}

		if ((InStr.charCodeAt(a) > 64) && (InStr.charCodeAt(a) < 91))
			{
			// Alphabetic
			if (Counter == 0) { Counter = 1; }
			if (Counter == 3) { Counter = 4; }
			}

		if (InStr.charAt(a) == " ")
			{
			InStr = InStr.substr(0, a) +  InStr.substr(a+1, InStr.length - a);
    			b-=1;
			a-=1;
			}
		a+=1;

		}

	if (Counter<4) return 0;

	//Postcode is a correctly entered UK postcode. Now all it needs is a space in the middle...

	a=InStr.length;
	while (a>0)
		{
		if ((InStr.charCodeAt(a)>47) && (InStr.charCodeAt(a)<58))
			{
			if (NumNumericCharsInMiddle==4)
				{ NumNumericCharsInMiddle=0; }
			else
				{ InStr = (InStr.substr(0, a) + " " + InStr.substr(a, InStr.length - a));
				TextBox.value = InStr;				
				return 1;
				}
			}
		a-=1;
		}

	}
else
	{
	TextBox.value=TextBox.value.toUpperCase();
	}
}


function CheckChars(TextBox, allowStr)
{

var a=0;
var b=0;
var x;
var y = TextBox.value;
b = y.length;

for (a=0;a<b;a++)
	{
	x = y.charAt(a);
	if (allowStr.indexOf(x)==-1)
		{
		//fail
		alert2("You have entered a disallowed character.", "alshobbies.com");
		a=y.length;
		TextBox.focus();
		return 0;
		}
	}
return 1;
}


function CheckNotEmpty (TextBox, desc)
{
if (TextBox.value=="")
	{
	msg = "You cannot leave the " + desc + " text box empty, this information is required.";
	alert2(msg, "alshobbies.com");
	TextBox.focus();
	return 0;
	}
return 1;
}


function CheckUKPostCode(TextBox)
{

PCode = TextBox.value.toUpperCase();

if (PCode.indexOf(" ")==-1)
	{
	alert2("You have entered an invalid UK postcode. If you are not in the UK, please select your country.", "alshobbies.com");
	return 0;
	}

var a = PCode.charCodeAt(0);
var b = PCode.length;
var c;
var IsOk = 0;

if ((b < 5) || (b > 8))
	{
	alert2("UK Postcodes are between 5 and 8 characters long", "alshobbies.com");
	TextBox.focus();
	return 0;
	}

if ((a < 65) || (a > 90))
	{
	alert2("The first character of a UK postcode is always a letter of the alphabet.", "alshobbies.com");
	TextBox.focus();
	return 0;
	}

a = PCode.charCodeAt(b-1);
if ((a < 65) || (a > 90))
	{
	alert2("The last character of a UK postcode is always a letter of the alphabet.", "alshobbies.com");
	TextBox.focus();
	return 0;
	}

for (a=1;a<(b-1);a++)
	{
	c = PCode.charCodeAt(a);
	if ((c > 47) && (c < 58)) { a=b; IsOk=1; }
	}

if (IsOk==0)
	{
	alert2("All UK Postcodes contain a number.", "alshobbies.com");
	TextBox.focus();
	}

return IsOk;

}

// Used in all pages to submit a form and optionally set a hidden 
// form varaible called 'navigate' to direct navgiation3
function submitForm(formName, navigateValue)
{
if ((navigateValue != null) && (navigateValue != ""))
	{
	document.forms[formName].navigate.value = navigateValue;
	}
AllowSubmission = true;
document.forms[formName].submit();
}

function StopNoise(evnt)
{
//alert(evnt.keyCode);
try
	{ if (evnt.keyCode==13) return false; }
	catch(Err1)
		{
		try
			{ if (evnt.which==13) return false; }
			catch(Err2)
				{
				/* Give Up */
				}
		}
}
