	var Delay = 0;//Seconds after them clicking the link, the gateway vanishes. 
	var AppearDelay = 0;//Seconds before gateway appears
	var oldHistLength = 99999;
	var historyOffset = parseFloat(document.getElementById("historyOffset").innerHTML);
	var ipAddress = document.getElementById("ipAddress").innerHTML;
	var stop_scroll = false;
	setInterval ( "checkHistory()", 1500 );
	
    function checkHistory() {
	   // alert(oldHistLength);
	   // alert(history.length - 1 - historyOffset);
	   if (oldHistLength < history.length)
	   {
			document.getElementById("nosend").src = document.getElementById("sendSrc").innerHTML;
			if (document.getElementById("free-premium").innerHTML == "false") {
				removegateway();
				oldHistLength = history.length;
				
				var dataSend = 'ip=' + ipAddress;
			
				//start the ajax
				$.ajax({
					//this is the php file that processes the data and send mail
					url: "gateway.php",	
					
					//GET method is used
					type: "GET",

					//pass the data			
					data: dataSend,		
					
					//Do not cache the page
					cache: false,
					
					//success
					success: function (sendform) {
						if (sendform == "Error 1") {
							// Error
						} else {
							// All bueno
						}
					}
				});
			} else {
				var completedIns = document.getElementById("completedIns").innerHTML;
				var neededIns = document.getElementById("neededIns").innerHTML;
				var finishedIns = document.getElementById("finishedIns").innerHTML;
				
				var dataSend = 'ip=' + ipAddress + '&completed_ins=' + completedIns + '&needed_ins=' + neededIns + '&finished_ins=' + finishedIns;
				
				// start the AJAX
				$.ajax({
					//this is the php file that processes the data and send mail
					url: "cpa-process.php",	
					
					//GET method is used
					type: "GET",

					//pass the data			
					data: dataSend,		
					
					//Do not cache the page
					cache: false,
					
					//success
					success: function (sendform) {
						if (sendform == "Error 1") {
							// Error
						} else {
							// All bueno
						}
					}
				});
				
				if (document.getElementById("finished").innerHTML == "true") {
					removegateway();
					oldHistLength = history.length;
					window.location.href = "http://clickatext.com/free-reg.php";
				} else {
					removegateway();
					oldHistLength = history.length;
				}
			}
	   }
	}
	
    function scrolltop(){
		if(stop_scroll==true){
			scroll(0,0);
		}
	}
	
	
	
	function delayappearance()
	{
        setTimeout("setupgateway()", AppearDelay*1000);
        
    }

	
	function setupgateway()
	
	{
	    stop_scroll = true;
	    window.scrollTo(0,0);
	    document.body.style.overflow = "hidden"
		var Left = $(window).width() /2;
		Left = Left - $('#gatewaydiv').width()/2;
		
		var Top = $(window).height() /2;
		Top = Top - $('#gatewaydiv').height()/2;
		
		$('#gatewaydiv').css('top', Top+'px').css('left', Left+'px').css('display', 'inline').css('visibility', 'visible');
		$('#gatewayDimmer').width($('html').width());
		$('#gatewayDimmer').height($('html').height());
		$('#gatewayDimmer').css('display','block');
		// document.getElementById("no1").src = document.getElementById("offer").innerHTML;
		// setTimeout("setHist()", 2000);
	}
	
	function setHist() {
		document.getElementById("clickBlock").style.display = "none";
		oldHistLength = history.length;
		// alert(oldHistLength);
	}
	
	function removegateway()
	{
	    stop_scroll = false;
	    document.body.style.overflow = ""
		$('#gatewaydiv').css('visibility', 'hidden');
		$('#gatewayDimmer').css('display','none');
		document.getElementById("gatewaydiv").style.display = "none";
	}
	
	$(document).ready(function()
	{
		$('.offerlink').click(function()
		{
			setTimeout('removegateway()', Delay*1000);
		});
		
		delayappearance();
		
		// setTimeout(setHist(), 3000);
	});

