    var gRefer = parent.location.href;		
    
    function autotab(original,destination)
    {
    	if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
			destination.focus();
    }
    
    function getCheckedValue(radioObj) {
  	if(!radioObj)
  		return "";
  	var radioLength = radioObj.length;
  	if(radioLength == undefined)
  		if(radioObj.checked)
  			return radioObj.value;
  		else
  			return "";
  	for(var i = 0; i < radioLength; i++) {
  		if(radioObj[i].checked) {
  			return radioObj[i].value;
  		}
  	}
  	return "";
    }

		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 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 isNumeric(s) {
			if(s == null)
			return false;
		
			if(s.length == 0)
			return false;
		
			for(var i=0; i<s.length; ++i)
			{
				if("1234567890".indexOf(s.charAt(i)) < 0)
				{
					return false;
				}
			}
			return true;
			}
			
			function GetCookie (name) {  
       var arg = name + "=";  
       var alen = arg.length;  
       var clen = document.cookie.length;  
       var i = 0;  
       while (i < clen) {    
       var j = i + alen;    
       if (document.cookie.substring(i, j) == arg)      
       return getCookieVal (j);    
       i = document.cookie.indexOf(" ", i) + 1;    
       if (i == 0) break;   
       }  
       return null;
      }

      function getCookieVal(offset) {
      var endstr = document.cookie.indexOf (";", offset);
      if (endstr == -1)
      endstr = document.cookie.length;
      return unescape(document.cookie.substring(offset, endstr));
      }
      
      function CheckHear()
			{
				var tbl=document.getElementById("aCell");
				var source = GetCookie('adv');
				
				if (source != null)
			 	{
			 		tbl.innerHTML='<input type="hidden" name="hear_about" value="FRXC_AR.Cookie.' + source + '">';
			 	}
			 	else if (document.demo_account_form.hear_about1.value == 'FRXC_AR.DropDown.WebsiteOnline_Ad')
				{										
					tbl.innerHTML='<select name="hear_about" class="bodyblack"><option value="">اختار</option><option value="">----------------------------------------------</option><Option value="FRXC_AR.DropDown.WebsiteOnline_Ad.Ameinfo.com">Ameinfo.com</option><Option value="FRXC_AR.DropDown.WebsiteOnline_Ad.Menafn.com">Menafn.com</option><Option value="FRXC_AR.DropDown.WebsiteOnline_Ad.Menareport.com">Menareport.com</option><Option value="FRXC_AR.DropDown.WebsiteOnline_Ad.Other_Website">موقع آخر</option></select>'
				}									
				else if (document.demo_account_form.hear_about1.value == 'FRXC_AR.DropDown.MagazineNewspaper')
				{
				tbl.innerHTML='<input type="hidden" name="hear_about" value="FRXC_AR.DropDown.MagazineNewspaper">'
				}
			  else if (document.demo_account_form.hear_about1.value == 'FRXC_AR.DropDown.Search_Engine')
				{
				tbl.innerHTML='<input type="hidden" name="hear_about" value="FRXC_AR.DropDown.Search_Engine">'
				}
				else if (document.demo_account_form.hear_about1.value == 'FRXC_AR.DropDown.TVRadio')
				{
				tbl.innerHTML='<input type="hidden" name="hear_about" value="FRXC_AR.DropDown.TVRadio">'
				}
				else if (document.demo_account_form.hear_about1.value == 'FRXC_AR.DropDown..Word_Of_Mouth')
				{
				tbl.innerHTML='<input type="hidden" name="hear_about" value="FRXC_AR.DropDown..Word_Of_Mouth">'
				}
				else if (document.demo_account_form.hear_about1.value == 'FRXC_AR.DropDown.Trade_Show')
				{
				tbl.innerHTML='<input type="hidden" name="hear_about" value="FRXC_AR.DropDown.Trade_Show">'
				}		
				else
			 	{				 		
			  	tbl.innerHTML='<input type="hidden" name="hear_about" value="FRXC_AR.DropDown..Word_Of_Mouth">'
			  }			
			}
			
			function CheckCountry()
			{
				 if (document.demo_account_form.country.value == 'United Kingdom')
				 {
				 	window.location = "http://www.forex.com/forex_demo_account_uk.html";
				 }  
		  }



  function ValidateForm() {
      //now verify the form fields

      if (document.demo_account_form.country.value == 'United Kingdom') {
          window.location = "http://www.forex.com/forex_demo_account_uk.html";
      }

      var source = GetCookie('adv');

      if ((source == null) && (document.demo_account_form.hear_about1 != null)) {
          if ((document.demo_account_form.hear_about1.selectedIndex == 2) && (document.demo_account_form.hear_about == null)) {
              CheckHear();
          }
      }


      //make sure that the first name is not blank.
      if ((document.demo_account_form.first_name.value.length == 0) || (isNumeric(document.demo_account_form.first_name.value))) {
          //it isn't so show the user an alert and go to that field
          alert("الرجاء ادخال اسمك الأول");
          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) || (isNumeric(document.demo_account_form.last_name.value))) {
          //it isn't so show the user an alert and go to that field
          alert("الرجاء ادخال اسمك الأخير");
          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("الرجاء ادخال البلد");
          document.demo_account_form.country.focus();
          //and return false so the form doesn't get submitted
          return false;
      }

      //make sure the user has entered a city   
      if (document.demo_account_form.city.value.length == 0) {
          alert("الرجاء أدخل ميدنتك");
          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 < 6) {
          //it isn't so show the user an alert and go to that field
          alert("الرجاء ادخال رقم الهاتف صالح العمل");
          document.demo_account_form.phone.focus();
          //and return false so the form doesn't get submitted
          return false;
      }

      //trim leading and trailing spaces to help users with invalid emails
      document.demo_account_form.email.value = trim(document.demo_account_form.email.value);

      //make sure the email address is formatted properly
      if (checkemail() == false) {
          alert("يرجى منكم فحص البريد الالكتروني، أنه ليس صحيحا");
          document.demo_account_form.email.focus();
          //and return false so the form doesn't get submitted

          return false;
      }

      document.demo_account_form.password.value = trim(document.demo_account_form.password.value);

      if (document.demo_account_form.password.value.length < 4) {
          //it isn't so show the user an alert and go to that field
          alert("يرجى دخول كلمة السر، متكونة من 4 حروف على الأقل");
          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(document.demo_account_form.password.value) == false) {
          alert("الرجاء الكتابة بالأحرف الانكليزية فقط من دون استعمال أرقام");
          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 (source == null) {
          if ((document.demo_account_form.hear_about1.selectedIndex == 0) || (document.demo_account_form.hear_about1.selectedIndex == 1)) {
              //if statement failed so ask the user to pick one!
              alert("الرجاء اخبارنا كيف سمعت عن شركتنا");
              document.demo_account_form.hear_about1.focus();
              //and return false so the form doesn't get submitted                                
              return false;
          }
      }

      if ((source == null) && (document.demo_account_form.hear_about1 != null)) {
          if ((document.demo_account_form.hear_about1.selectedIndex == 2)) {
              if (document.demo_account_form.hear_about == null) {
                  CheckHear();
                  alert("الرجاء اخبارنا كيف سمعت عن شركتنا");
                  document.demo_account_form.hear_about.focus();
                  return false;
              }
              else if (document.demo_account_form.hear_about.selectedIndex < 2) {
                  alert("الرجاء اخبارنا كيف سمعت عن شركتنا");
                  document.demo_account_form.hear_about.focus();
                  return false;
              }
          }
      }


      //everything checks out, final checkout, then submit the form
      if (document.demo_account_type.demotype[0].checked == true)
          document.demo_account_form.fx_sub_company.value = "FARM";
      else
          if (document.demo_account_type.demotype[1].checked == true)
          document.demo_account_form.fx_sub_company.value = "FARS";
      else
          document.demo_account_form.fx_sub_company.value = "FARS";

      setwsEntityHigh("NA");
      return true;
  }