                var isMac = (navigator.userAgent.indexOf("Macintosh") != -1);
                var isWin = (navigator.userAgent.indexOf("Windows 95") != -1 || navigator.userAgent.indexOf("Windows NT") != -1);
                var isNS =  (navigator.appName == "Netscape");
                var isIE =  (navigator.userAgent.indexOf("MSIE") != -1);
                var ieWin = (navigator.userAgent.indexOf("MSIE") != -1 && (navigator.userAgent.indexOf("Windows 95") != -1 || navigator.userAgent.indexOf("Windows NT") != -1));		
		
		function checkemail(){
			var testresults;			
			var str=document.demo_account_form.email.value;
			var filter=/^(['_a-z0-9-+]+)(\.['_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,5})$/i
			if (filter.test(str))
				testresults=true
			else				
				testresults=false				
			return (testresults)			
			}
			
			
			function CheckCountry()
			{
				var tbl=document.getElementById("labelid");
				var tbl2=document.getElementById("fieldid");
				
				if (document.demo_account_form.country.value == 'Canada')
				{					
					tbl.innerHTML='<font color="red">*</font><b>Province:</b>'
					tbl2.innerHTML='<select name="state" class="textblackformorange" onchange="CheckProvince();"><option value="" selected>Choose Province</option><option value="">------------------------------</option><option value="Alberta">Alberta</option><option value="British Columbia">British Columbia</option><option value="Manitoba">Manitoba</option><option value="New Brunswick">New Brunswick</option><option value="Newfoundland and Labrador">Newfoundland and Labrador</option><option value="Northwest Territory">Northwest Territory</option><option value="Nova Scotia">Nova Scotia</option><option value="Nunavut">Nunavut</option><option value="Ontario">Ontario</option><option value="Prince Edward Island">Prince Edward Island</option><option value="Quebec">Quebec</option><option value="Saskatchewan and Yukon">Saskatchewan and Yukon</option></select><input type="hidden" name="city" value="N/A">'
				}					
				else if (document.demo_account_form.country.value == 'United States')
					{
						tbl.innerHTML='<font color="red">*</font><b>State:</b>'
						tbl2.innerHTML='<select name="state" class="textblackformorange"><option value="" selected>Choose State</option><option value="">------------------------------</option><OPTION value="Alabama">Alabama</option><OPTION value="Alaska">Alaska</option><OPTION value="Arizona">Arizona</option><OPTION value="Arkansas">Arkansas</option><OPTION value="California">California</option><OPTION value="Colorado">Colorado</option><OPTION value="Connecticut">Connecticut</option><OPTION value="Delaware">Delaware</option><OPTION value="Florida">Florida</option><OPTION value="Georgia">Georgia</option><OPTION value="Hawaii">Hawaii</option><OPTION value="Idaho">Idaho</option><OPTION value="Illinois">Illinois</option><OPTION value="Indiana">Indiana</option><OPTION value="Iowa">Iowa</option><OPTION value="Kansas">Kansas</option><OPTION value="Kentucky">Kentucky</option><OPTION value="Louisiana">Louisiana</option><OPTION value="Maine">Maine</option><OPTION value="Maryland">Maryland</option><OPTION value="Massachusetts">Massachusetts</option><OPTION value="Michigan">Michigan</option><OPTION value="Minnesota">Minnesota</option><OPTION value="Mississippi">Mississippi</option><OPTION value="Missouri">Missouri</option><OPTION value="Montana">Montana</option><OPTION value="Nebraska">Nebraska</option><OPTION value="Nevada">Nevada</option><OPTION value="New Hampshire">New Hampshire</option><OPTION value="New Jersey">New Jersey</option><OPTION value="New Mexico">New Mexico</option><OPTION value="New York">New York</option><OPTION value="North Carolina">North Carolina</option><OPTION value="North Dakota">North Dakota</option><OPTION value="Ohio">Ohio</option><OPTION value="Oklahoma">Oklahoma</option><OPTION value="Oregon">Oregon</option><OPTION value="Pennsylvania">Pennsylvania</option><OPTION value="Rhode Island">Rhode Island</option><OPTION value="South Carolina">South Carolina</option><OPTION value="South Dakota">South Dakota<OPTION value="Tennessee">Tennessee</option><OPTION value="Texas">Texas</option><OPTION value="Utah">Utah</option><OPTION value="Vermont">Vermont</option><OPTION value="Virginia">Virginia</option><OPTION value="Washington">Washington</option><OPTION value="Washington DC">Washington DC</option><OPTION value="West Virginia">West Virginia</option><OPTION value="Wisconsin">Wisconsin</option><OPTION value="Wyoming">Wyoming</option></select><input type="hidden" name="city" value="N/A">'
					}
			  else if (document.demo_account_form.country.value == 'United Kingdom')
			  	{
			  		window.location = "openaccount_demo_uk.html" + "?FirstName=" + document.demo_account_form.first_name.value + "&LastName=" + document.demo_account_form.last_name.value + "&Company=" + document.demo_account_form.company.value;
			  	}			  	
				else if (document.demo_account_form.country.value.length > 0)
			 	{
			 		tbl.innerHTML='<font color="red">*</font><b>City:</b>'
			  	tbl2.innerHTML='<input type="text" name="city" size="25" maxlength="50" class="textblackformorange"><input type="hidden" name="state" value="N/A">'				
			  }			
			}
			
			function CheckProvince()
			{
				if (document.demo_account_form.country.value == 'Canada') {
					if (document.demo_account_form.state.value == 'British Columbia') {
						window.location = "openaccount_demo_canada.html" + "?FirstName=" + document.demo_account_form.first_name.value + "&LastName=" + document.demo_account_form.last_name.value + "&Company=" + document.demo_account_form.company.value;
					}						
					}
				}

                function ValidateForm(){
                	
                	//now verify the form fields
                	      
                	      if (((document.demo_account_form.country.value == 'United States') || (document.demo_account_form.country.value == 'Canada')) && (document.demo_account_form.state == null))
                	      {
                	      	CheckCountry();                	      	                	      	
                	      } 
                	      
                	      if ((document.demo_account_form.country.selectedIndex > 1) && (document.demo_account_form.country.value != 'United States') && (document.demo_account_form.country.value != 'Canada') && (document.demo_account_form.city == null))
                	      {
                	      	CheckCountry();                	      	                	      	
                	      } 
                	
                        //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 state field is not blank.
                        if ((document.demo_account_form.country.value == 'Canada') || (document.demo_account_form.country.value == 'United States'))
                        {                                          
                            if (document.demo_account_form.state.selectedIndex < 2)  {
                                    //it isn't so show the user an alert and go to that field
                                    if (document.demo_account_form.country.value == 'Canada')
				                            {					
                                    	alert ("Please choose your province");
                                    	document.demo_account_form.state.focus();
                                    }
 		                                else if (document.demo_account_form.country.value == 'United States')
 		                                	{
 		                                	alert ("Please choose your state");
 		                                	document.demo_account_form.state.focus();
 		                                }
                                    //and return false so the form doesn't get submitted
                                    
                                    return false;
                            }
                          }
                          
                       if ((document.demo_account_form.country.value != 'Canada') && (document.demo_account_form.country.value != 'United States') && (document.demo_account_form.country.selectedIndex > 1))
                       {														
														if (document.demo_account_form.city.value.length == 0)  {
															alert ("Please enter your city");
                              document.demo_account_form.city.focus();                              
                              return false;
                            }
                       }
                        
                        //make sure that the phone field is not blank.
                        if (document.demo_account_form.phone.value.length == 0)  {
                                //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;
			}

                        
                        //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)) && ((document.demo_account_form.hear_about2.selectedIndex == 0) || (document.demo_account_form.hear_about2.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 hasn't picked two referrers
			if ((document.demo_account_form.hear_about.selectedIndex > 1) && (document.demo_account_form.hear_about2.selectedIndex > 1))
                        {
                                //you can't pick 2!
                                alert ("Error: Hear about us\n\nPlease choose one");
                                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 trading profile box
			if ((document.demo_account_form.trading_profile[0].checked == false) && (document.demo_account_form.trading_profile[1].checked == false) && (document.demo_account_form.trading_profile[2].checked == false) && (document.demo_account_form.trading_profile[3].checked == false))
			{
				//Trading profile needs to be selected
				alert ("Please select your trading profile");
				document.demo_account_form.trading_profile[0].focus();
				//and return false so the form doesn't get submitted
				
                        	return false;
                        }
                        
                        
                        //everything checks out, submit the form
                        return true;
                }
