var timer = null;
var speed = 8; //1 is  slow
var endTop = 70;
var endLeft = 10;

function Init()
{
    endLeft = Math.round(parseInt(document.body.offsetWidth) - parseInt(getEl('signup').offsetWidth))/2;
} 
//******************************************************
// Simple little function to get Elements as an object
//******************************************************
function getEl(id)
{
	var el = document.getElementById(id);
	return el;
}
//******************************************************
// Function to show Elements
//******************************************************
function showEl(id)
{
	getEl(id).style.display ="";
}
//******************************************************
// Function to hide Elements
//******************************************************
function hideEl(id)
{
	getEl(id).style.display ="none";
	if (id=='signup'){
	  showEl('s_varsta');
	  showEl('s_motorizare');
	}
}

//******************************************************
// Function to move Element
//******************************************************
function moveEl(id)
{
    var endLeft = Math.round(parseInt(document.body.offsetWidth) - parseInt(getEl('signup').offsetWidth))/2;
    
	var signup = getEl(id);
	var currentTop = parseInt(signup.offsetTop);
	var currentLeft = parseInt(signup.offsetLeft);
	
	var keepMoving = false;
	//Move
	if (currentTop <= endTop)
	{
		signup.style.top = (currentTop + speed) + "px";
		keepMoving = true;
	}
	if(currentLeft <= endLeft)
	{	
		signup.style.left = (currentLeft + speed) + "px";
		keepMoving = true;
	}
	if (keepMoving)
	{
		startMove(id);
	}
	else
	{
		endMove();
	}
}
//******************************************************
// Function to start the move
//******************************************************
function startMove(id)
{   
    if (readCookie('notshow')!=1){
	hideEl('s_varsta');
	hideEl('s_motorizare');
	var signup = getEl('signup');
	signup.top=10;
	signup.left=-405;
	showEl('signup');
    Init();
	timer = setTimeout("moveEl('"+id+"')", 10);}
}
//******************************************************
// Function to end the move
//******************************************************
function endMove()
{
	clearTimeout(timer);
}

var xmlHttp3;

function getSubscription(){
  xmlHttp3=GetXmlHttpObject();
  if (xmlHttp3==null){
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="addmember.php";
  url=url+"?fname="+document.getElementById("fname").value;
  url=url+"&lname="+document.getElementById("lname").value;
  url=url+"&email="+document.getElementById("email").value;
  url=url+"&validator="+document.getElementById("validator").value;
  url=url+"&sid="+Math.random();
  xmlHttp3.onreadystatechange=getSubscriptionStateChanged;
  xmlHttp3.open("GET",url,true);
  xmlHttp3.send(null);
} 

function getSubscriptionStateChanged() { 
  if (xmlHttp3.readyState==4){ 
    alert(xmlHttp3.responseText);
	if (xmlHttp3.responseText=='Inregistrarea a avut loc cu succes!'){
	  createCookie('notshow','1'); hideEl('signup');
	}
  }
}