
function IsValidEmail(email)
{
	var re=new RegExp("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");

	return re.test(email);
}


function OnDownloadClick()
{
	//debugger;
	var name=$("try_it_name").value;
	var email=$("try_it_email").value;

	if(name=="" || name=="Your name")
	{
		alert("Enter your name.");
		$("try_it_name").focus();
		return;
	}


	if(!IsValidEmail(email))
	{
		alert("Enter valid e-mail.");
		$("try_it_email").focus();
		return;
	}

	$("TryItForm").request(
	{
		onSuccess: function(transport)
		{
			$("TryItForm").setOpacity(1);
			var response = transport.responseText;
			if(response=="ok")
			{
				//alert("Registration success.");
				window.location="download.html";
			}
			else
			{
			//	alert(response);
			}
		}
		,
		onFailure: function(transport)
		{
			$("TryItForm").setOpacity(1);
			alert('Error. Something went wrong...');
			//alert(transport.responseText);
		}
	});

	$("TryItForm").setOpacity(0.2);
}

function OnTextBoxLostFocus(textBox, text)
{
	if(textBox.value=="")
		textBox.value=text;
}

function OnTextBoxReGetFocus(textBox, text)
{
	if(textBox.value==text)
		textBox.value="";
}

function WriteAffiliate()
{
	var query = ParseQuerystring();
	if (query["affiliate_pro_tracking_id"] != null) {
		new Ajax.Request("inc/affiliate.php", {
			method: "get",
			parameters: {affiliate_id: query["affiliate_pro_tracking_id"]},
			onSuccess: function(){
				GetAffiliateParam();
			}
		});
	} else {
		GetAffiliateParam();
	}
}

function GetAffiliateParam()
{
	new Ajax.Request("inc/affiliate.php", {
		method: "post",
		parameters: {check: 1},
		onSuccess: function(http){
			if (http.responseText) {
				var affiliateReferences = document.getElementsByTagName("a");
				if (affiliateReferences != null) {
					for (var i=0; i < affiliateReferences.length; i++) {
						if (affiliateReferences[i].id == "buyNowLink") {
							affiliateReferences[i].href += http.responseText;
						}
					}
				}
			}
		}
	});
}