// JavaScript Document

function validate()
	{


		var validated = true;

		var message = '';

		if($('#action').val() == "activate")
		{

			return true;

		}



		

		
		

		if($('#password').val()=="")
		{

			message += "Password field cannot be blank<br>";

			validated = false;

		}

		var email_filter = /.+?@.+?\..+/;


		if(!email_filter.test($('#email_id').val()))
		{

			message += "Please enter a valid email id. It doubles up as your username<br>";

			validated = false;

		}

		if(message)
		{

			$("#message").html("<div class='error'>"+message+"</div>");


		}

		return validated;

	}


	function submit_form()
	{

		if(validate())
		{

			var queryString = $('#main_form').formSerialize();



			$.getJSON("//app.visualwebsiteoptimizer.com/create_account.php?jsoncallback=?", queryString, process_response);

			$("#message").html("Loading... <img src='/images/ajax-loader.gif'/>");

			if(typeof(_wg_goal)=="function")
			{

				_wg_goal(48, 'signed_up', 1);
			}

			if(typeof(_vis_opt_register_conversion)=="function")
			{

				register_custom_conversions();

			}

			if(typeof(pageTracker)!="undefined")
			{

				pageTracker._trackPageview("/signed_up");

			}


			$('body').append("<iframe src='http://v2.visualwebsiteoptimizer.com/track_trial_signup.php' width='1' height='1' style='display:none'></iframe>");



			//Google Adwords conversions

			var AdWordsImage = new Image();
			AdWordsImage.src = 'https://www.googleadservices.com/pagead/conversion/1055891044/?label=muArCKTy3gEQ5Ly-9wM&amp;guid=ON&amp;script=0';

		}


	}

	function register_custom_conversions()
{
	if(typeof(_vwo_exp_ids) != "undefined")
{
    for(var l=0;l<_vwo_exp_ids.length;l++)
    {
        id = _vwo_exp_ids[l];

        for(_vwo_goal_id in _vwo_exp[id].goals)
              {
            if(_vwo_exp[id].goals[_vwo_goal_id].type=='CUSTOM_GOAL')
                   {

                         _vis_opt_register_conversion(_vwo_goal_id, id);
						 break;
          }
       }
}

}

}

	function process_response(responseText)
	{


		 $("#message").html("<div class='"+responseText["status"]+"'>"+responseText["message"]+"</div>");

		 if($("#plan")!="FREE_TRIAL")
		 {

		 	if(typeof(responseText["merchant_id"]) != "undefined" && typeof(responseText["twco_product_id"]) != "undefined")
		 	{

		 		var url = "https://www.2checkout.com/checkout/spurchase?fixed=Y&sid=1419843&product_id="+responseText["twco_product_id"]+"&quantity=1&tco_currency=USD&merchant_order_id="+escape(responseText["merchant_id"]);

				window.location = url;


		 	} else
			{
				
				if(responseText["status"]=="success")
				{
			
					window.location = 'http://v2.visualwebsiteoptimizer.com/';
				}
			}
		 } else
		 {
		 	alert("An unspecified error occurred. Please contact us (info@wingify.com) to resolve this.");


		 }





	}


	

