	/* Gets the URL Parameters */
	function gup( name )
		{
		  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		  var regexS = "[\\?&]"+name+"=([^&#]*)";
		  var regex = new RegExp( regexS );
		  var results = regex.exec( window.location.href );
		  if( results == null )
		    return "";
		  else
		    return results[1];
		}
		
		
	/* Sets a variable called parameter for the parameter */
	
	var param = gup( 'src' );

	$(function(){
		$("#registration-form").validate();
		$("#registration-form").submit( function() { onFormSubmit(); });
		
		/* We're using this landing page for the email autoresponse campaigns. This small function applies a new
		   MKTO campaign name if the person clicked through from the email campaign so we can properly attribute
		   the source of the campaign */
		if( param == "email" ){
			$("[name=MKTOCampaignName]").attr("value", "Email: 2010: BDR PP Funnel: Try Before You Buy: 5NPo");
		}
		if( param == "ch" ){
			$("[name=MKTOCampaignName]").attr("value", "Email: 2010: BDR CH Funnel: Try Before You Buy: 5O5F");
		}
		if( param == "outs" ){
			$("[name=MKTOCampaignName]").attr("value", "Email: 2010: Outsourcing Nurturing Funnel: Try Before You Buy: 5O12");
		}
		if( param == "req" ){
			$("[name=MKTOCampaignName]").attr("value", "Email: 2010: Requirements Opps Funnel: Try Before You Buy: 5OHu");
		}
		if( param == "cci" ){
			$("[name=MKTOCampaignName]").attr("value", "Email: 2010: Call Contacted Interested Funnel: Try Before You Buy: 5QcH");
		}
		if( param == "decm" ){
			$("[name=MKTOCampaignName]").attr("value", "Email: 2010: Decision Maker Funnel: Try Before You Buy: 5R1C");
		}
		if( param == "netsuite" ){
			$("[name=MKTOCampaignName]").attr("value", "Other: 2010: NetSuite Partner Page: Try Before You Buy: 5Rxu");
		}
		/* For Lyne's Funnel */
		if( param == "lt" ){
			$("[name=MKTOCampaignName]").attr("value", "Email: 2010: BDR LT Funnel: Try Before You Buy: 5Vyv");
		}
		/* For linkedin special promotion */
		if( param == "webli" ){
			$("[name=MKTOCampaignName]").attr("value", "Web Advertisement: LinkedIn: Try Before You Buy: 5WXQ");
		}
		/* For For ECO/BOM/ECN/etc. Template drip campaigns */
		if( param == "tem" ){
			$("[name=MKTOCampaignName]").attr("value", "Email: 2011: Template Funnel: Try Before You Buy: 5aF1");
		}
		/* For For ECO/BOM/ECN/etc. Template drip campaigns */
		if( param == "gen" ){
			$("[name=MKTOCampaignName]").attr("value", "Email: 2011: Generic Followup Funnel: Try Before You Buy: 5bcy");
		}
		/* For Q211 BOM Funnel Campaign */
		if( $(document).getUrlParam("src") == "bomf" ){
			$("[name=MKTOCampaignName]").attr("value", "Email: 2011: BOM Funnel: Try Before You Buy: 5fAA");
		}
		/* For Q211 BOM Template Funnel Campaign */
		if( $(document).getUrlParam("src") == "bomtf" ){
			$("[name=MKTOCampaignName]").attr("value", "Email: 2011: BOM Template Funnel: Try Before You Buy: 5fAZ");
		}
		
		/* lightwindow function */
		$.fn.colorbox.settings.opacity = "0.5"; 
		$.fn.colorbox.settings.transition = "none";
			
		/* Open the registration page in a light window */
		$(".launchTOS").colorbox({href:"/trial/includes/tos.html",width:"850", height:"620", iframe:true});
	
		$("#otherOffers .item1 a").click(function(){
			var currentLink = this.href;
			var popupWidth = 640;
			var popupHeight = 427;
			$.fn.colorbox({href:currentLink, open:true,innerWidth:popupWidth, innerHeight:popupHeight, iframe:true});
			return false;
		});
	
		$("#trialOffers .item1 a").click(function(){
			var currentLink = this.href;
			var popupWidth = 940;
			var popupHeight = 675;
			$.fn.colorbox({href:currentLink, open:true,innerWidth:popupWidth, innerHeight:popupHeight, iframe:true});
			return false;
		});
	
		$("#trialOffers .item2 a").click(function(){
			var currentLink = this.href;
			var popupWidth = 940;
			var popupHeight = 754;
			$.fn.colorbox({href:currentLink, open:true,innerWidth:popupWidth, innerHeight:popupHeight, iframe:true});
			return false;
		});
	
		$("#trialOffers .item3 a").click(function(){
			var currentLink = this.href;
			var popupWidth = 940;
			var popupHeight = 709;
			$.fn.colorbox({href:currentLink, open:true,innerWidth:popupWidth, innerHeight:popupHeight, iframe:true});
			return false;
		});
	
		$("#otherOffers .item3 a").click(function(){
			var currentLink = this.href;
			var popupWidth = 690;
			var popupHeight = 551;
			if (jQuery.browser.msie){
				if(parseInt(jQuery.browser.version) < 8) {
					$.fn.colorbox({href:currentLink, open:true,innerWidth:popupWidth, innerHeight:popupHeight+2, iframe:true});
				}
				else {
					$.fn.colorbox({href:currentLink, open:true,innerWidth:popupWidth, innerHeight:popupHeight, iframe:true});
				}
			}
			else{
				$.fn.colorbox({href:currentLink, open:true,innerWidth:popupWidth, innerHeight:popupHeight, iframe:true});
			}
			return false;
		});
		
		/* qtips function */
		$.fn.qtip.styles.customStyle = {// Last part is the name of the style
			color:"#36393d",
			width:175,
			border:{
				width:3,
				radius:7
			},
			name:"blue",
			tip:true
		}
		$('.tooltip:eq(0)').qtip({
			content: "Please enter a valid email address that you can access. We will be sending your Arena login credentials to this email address.",
			style: 'customStyle',
			position: {corner: {target: 'topMiddle', tooltip: 'bottomMiddle'}}
		})
	});
	function onFormSubmit(){
		if ($("#registration-form").valid() == true){
			$("form button").after("<div class='loadingButton'>Please wait...</div>").css("display","none");
			$(".form-error-message").slideUp("fast");
			$.cookie('registered', 'yes', { path: '/', expires: 90 });
			$.cookie('TCRegistered', 'yes', { path: '/', expires: 90 });
			if ($.cookie("TCPending")==(null)){
				$.cookie('TCPending', 'yes', { path: '/', expires: 3 });
			}
			if ($("#purchase-id-gen").attr("value") == ("on")){ 
				var retURL = $("[name=retURL]").attr("value");
				var newURL = retURL + "?orderid=" + Math.ceil(100000000000*Math.random());
				$("[name=retURL]").attr("value", newURL);
			}
		}
		else{
			$("h2").addClass("remove");
			$(".form-error-message").fadeIn("normal");
		}

		/* if purchase-id-gen is 'on' add a random purchase ID to the retURL  */
		
	}
