$("#reg").ready(function(){

	myOS = BrowserDetect.OS;
	myBrowser = BrowserDetect.browser;

		$("#reg div.text").load('/_ajax/regform.html', function() {

			addCaptcha($("#lang li").attr('class'));

			// ADD BACK BUTTON VALUE FOR REG FORM

			$("input[name=Back]").val(window.location.href);


			// hide errors

		        $("#error_message").hide();
	
			// other variant:
			// $("input[name=Back]").attr("value",window.location.href);

			// CLOSE POPUP WITH FORM
			$("#hideme").click(function(){
				$("#reg").hide();
				if($("p.player")) { 
				$("p.player object").css('visibility', 'visible');
				$("p.player embed").css('visibility', 'visible');
			}
				return false;
			});


		if($.getURLParameter("Err")){

		if($("p.player")) {
				$("p.player object").css('visibility', 'hidden');
				$("p.player object").css('visibility', 'hidden');
				$("p.player embed").css('visibility', 'hidden');

		}

		$("#reg").show();
		$("#error_message").show();
		$("#error_message").html("<pre>" + $.getURLParameter("Err") + "</pre>");
		};


		}); // load()


		$("a.try").click(function(){


			if(myOS.indexOf('iPhone') != -1) {
				window.location = 'http://traderzone.sportsarbitrageworld.com/register.html';
				return false;
			}


			if(myBrowser.indexOf('Explorer') != -1) {
				document.getElementById("reg").style.position = 'absolute';
				document.getElementById("reg").style.top = 120 + document.body.scrollTop;
			}


			$("#reg").fadeIn("fast");
			if($("p.player")) {
				$("p.player object").css('visibility', 'hidden');
				$("p.player embed").css('visibility', 'hidden');
			}

			return false;

		});


		// SUB FUNCTION
		// detect language and create reCaptcha
	
		function addCaptcha(lng) {
		
		
			if(lng == 'ru') {
		                Recaptcha.create("6LeQoAUAAAAAAOuRA4oRVcfi7xIg5Kq8UZf31_9v",
		                    "recaptcha_div", {
		                    theme: "white",
				    lang: "ru",
		                    callback: Recaptcha.focus_response_field
  
		                    });

			} 
			else if (lng == 'it') {
	
		                Recaptcha.create("6LeQoAUAAAAAAOuRA4oRVcfi7xIg5Kq8UZf31_9v",
		                    "recaptcha_div", {
		                    theme: "white",
				    lang: "it",
		                    callback: Recaptcha.focus_response_field

		                    });

			}
			else {
		                Recaptcha.create("6LeQoAUAAAAAAOuRA4oRVcfi7xIg5Kq8UZf31_9v",
		                    "recaptcha_div", {
		                    theme: "white",
				    lang: "en",
		                    callback: Recaptcha.focus_response_field

		                    });
			}

		} // addCaptcha()



}); // lang ready
