function LTrim(str)

{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {

      var j=0, i = s.length;

      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      s = s.substring(j, i);
   }
   return s;
}


function RTrim(str)

{

   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      s = s.substring(0, i+1);
   }

   return s;
}

function Trim(str)

{
   return RTrim(LTrim(str));
}

function showHideZip()
{
	if (document.getElementById("f_CountryID").value == 226)
	{
		document.getElementById("trZip").style.display = "";
		document.getElementById("trCity").style.display = "none";
	}
	else
	{
		document.getElementById("trZip").style.display = "none";
		document.getElementById("trCity").style.display = "";
	}
	
}

//Validate the user's input
function checkForm(theForm)
{
if ( document.getElementById("UNameF").value.length < 2 )
	{
		alert("Enter your first name.")
		document.getElementById("UNameF").focus();
		return false;
	}
if ( document.getElementById("UNameL").value.length < 2 )
	{
		alert("Enter your last name.")
		document.getElementById("UNameL").focus();
		return false;
	}

var numb = /\d/;
if (numb.test(document.getElementById("UNameF").value))
	{
		alert("Don't enter any digits as your name.")
		document.getElementById("UNameF").focus();
		return false;
	}	
	
if (numb.test(document.getElementById("UNameL").value))
{
		alert("Don't enter any digits as your name.")
		document.getElementById("UNameL").focus();
		return false;
	}	
if ( document.getElementById("UGender").value == 'x')
{
		alert("Choose your gender.")
		document.getElementById("UGender").focus();
		return false;
	}	
	
	if (document.getElementById("f_CountryID").value == 226)
	{
		if ( document.getElementById("UZipCode").value.length != 5 )
		{
			alert("Enter your zip code without spaces (e.g. 12345).")
			document.getElementById("UZipCode").focus();
			return false;
		}
	}
	else
	{
		if ( document.getElementById("UCity").value.length < 2 )
		{
			alert("Enter your city.")
			document.getElementById("UCity").focus();
			return false;
		}
	}
	
theForm.UEmail.value = Trim(theForm.UEmail.value);
var filter = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,4})(\]?)$/; // valid
if (!filter.test(document.getElementById("UEmail").value))
	{
		alert ("Enter a valid email address.");
		document.getElementById("UEmail").focus();
		return false;
	}

if ( !document.getElementById("avcb").checked )
{
	alert ("To register with playonPar, you must agree to our Terms of Use.");
	return false;
}
	
// Knoppen disablen
if (document.all||document.getElementById)
	{
		for (i=0;i<theForm.length;i++)
		{
			var tmpobj=theForm.elements[i]
			if(tmpobj.type.toLowerCase()=="submit")
			tmpobj.disabled=true
		}
	}
}
