                var gRefer = parent.location.href;		
		
		function checkemail(){
			var testresults;			
			var str=document.demo_account_form.email.value;
			var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
			if (filter.test(str))
				testresults=true
			else				
				testresults=false				
			return (testresults)			
			}
			
		function trim(s) {
  			while (s.substring(0,1) == ' ') {
    			s = s.substring(1,s.length);
  			}
  			while (s.substring(s.length-1,s.length) == ' ') {
    			s = s.substring(0,s.length-1);
  			}
  			return s;
			}
			
		function isAlpha(s) {
			if(s == null)
			return false;
		
			if(s.length == 0)
			return false;
		
			for(var i=0; i<s.length; ++i)
			{
				if("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".indexOf(s.charAt(i)) < 0)
				{
					return false;
				}
			}
			return true;
			}
	
		
                function ValidateForm(){
      				
			//now verify the form fields
			
												//make sure the user has checked a lesson
												if ((document.demo_account_form.lttf[0].checked == false) && (document.demo_account_form.lttf[1].checked == false))
												{
													//A lesson needs to be picked
													alert ("Please select a course");
													document.demo_account_form.lttf[0].focus();
													//and return false so the form doesn't get submitted				
                        	return false;
                        }
			
						
			                  //make sure that the first name is not blank.
                        if (document.demo_account_form.first_name.value.length == 0)  {
                                //it isn't so show the user an alert and go to that field
                                alert ("Please enter your first name");
                                document.demo_account_form.first_name.focus();
                                //and return false so the form doesn't get submitted
                                
                                return false;
                        }
                                
                        //make sure that the last name field is not blank.
                        if (document.demo_account_form.last_name.value.length == 0)  {
                                //it isn't so show the user an alert and go to that field
                                alert ("Please enter your last name");
                                document.demo_account_form.last_name.focus();
                                //and return false so the form doesn't get submitted
                                
                                return false;
                        }

                        //make sure that the country field is not blank.
                        if (document.demo_account_form.country.value.length == 0)  {
                                //it isn't so show the user an alert and go to that field
                                alert ("Please enter your country");
                                document.demo_account_form.country.focus();
                                //and return false so the form doesn't get submitted
                                
                                return false;
                        }
                        
                        //make sure that the phone field is not blank.
                        if (document.demo_account_form.phone.value.length < 6)  {
                                //it isn't so show the user an alert and go to that field
                                alert ("Please enter your phone number");
                                document.demo_account_form.phone.focus();
                                //and return false so the form doesn't get submitted
                                
                                return false;
                        }
                        
                        //make sure that the email field is not blank.
                        if (document.demo_account_form.email.value.length == 0)  {
                                //it isn't so show the user an alert and go to that field
                                alert ("Please enter your email");
                                document.demo_account_form.email.focus();
                                //and return false so the form doesn't get submitted
                                
                                return false;
                        }
                        
                        //make sure the email address is formatted properly
                        if (checkemail()==false)
                        {
                        	alert ("Please check your email address, it is not valid");
                        	document.demo_account_form.email.focus();
                        	//and return false so the form doesn't get submitted
                                
                                return false;
                        }
                        
                        //make sure that the password field is not blank and is greater than 3
												if (document.demo_account_form.password.value.length < 3)  {
													//it isn't so show the user an alert and go to that field
													alert ("Please enter a password with at least 4 characters");
													document.demo_account_form.password.focus();
													//and return false so the form doesn't get submitted
      									                          
													return false;
												}
			
												var emailtest = trim(document.demo_account_form.password.value);
												
												if (emailtest.length < 3)  {
													//it isn't so show the user an alert and go to that field
													alert ("Please enter a password with at least 4 characters");
													document.demo_account_form.password.focus();
													//and return false so the form doesn't get submitted
      									                          
													return false;
												}
												
												//make sure the password is alpha chars only
                        if (isAlpha(emailtest)==false)
                        {
                        	alert ("Please use only alpha numeric characters [a-z, A-Z, 0-9]");
                        	document.demo_account_form.password.focus();
                        	//and return false so the form doesn't get submitted
                                
                                return false;
                        }
                        
                        //make sure the user has picked a referrer
                        if ((document.demo_account_form.hear_about.selectedIndex == 0) || (document.demo_account_form.hear_about.selectedIndex == 1))
                        {
                                //if statement failed so ask the user to pick one!
                                alert ("Please let us know where you heard of us");
                                document.demo_account_form.hear_about.focus();
                                //and return false so the form doesn't get submitted                                
                                return false;
                        }	
                        
                        //make sure the user has checked a forex experience box
												if ((document.demo_account_form.forex_experience[0].checked == false) && (document.demo_account_form.forex_experience[1].checked == false) && (document.demo_account_form.forex_experience[2].checked == false) && (document.demo_account_form.forex_experience[3].checked == false))
												{
													//Trading information needs to be selected
													alert ("Please pick how much experience you have");
													document.demo_account_form.forex_experience[0].focus();
													//and return false so the form doesn't get submitted				
                        	return false;
                        }
                        
                        return true;
                				}
