function hideinvitediv(id)
{
	document.getElementById(id).style.display="none";
}
function showinvitediv()
{
	document.getElementById("spinner333").style.display="block";
}
function show_dialog()
{
	//alert('<form action="" method="post"><table width="100%"><tr><td ><strong>Set your facebook status:</strong></td></tr><tr><td width="30%"> <textarea name="status" id="status" style="width:300px; height:100px;"></textarea><br /><br /><a href="#_" onclick="saveStatus();"><img  src="workingsoftware/submit.png" align="absbottom" /></a></td></tr></table></form>');
	
		document.getElementById('showinvitedivdata2').innerHTML = '<form action="" method="post"><table width="100%"><tr><td ><strong>Set your facebook status:</strong><a href="#_" onclick="hideinvitediv(\'spinner222\');"><img src="workingsoftware/close.png" align="right" style="padding-bottom:7px;" /></a></td></tr><tr><td width="30%"> <textarea name="status" id="status" style="width:300px; height:40px;"></textarea><br /><br /><a href="#_" onclick="saveStatus();"><img  src="workingsoftware/submit.png" align="absbottom" /></a></td></tr></table></form>';
document.getElementById('spinner222').style.display='block';

}

var inam;
function update_user_box() {
uid = FB.Facebook.apiClient.get_session().uid;
InsertRecord2(uid)
//checkRecord(uid);

  var user_box = document.getElementById("user");
  document.getElementById("showinvitedivdata").style.display="block";
  var checkfblogin = document.getElementById("checkfblogin").value;
	if(checkfblogin == '' || checkfblogin == ' ')
	{

loginchecking(uid);
		
		
		
	}
	
  // add in some XFBML. note that we set useyou=false so it doesn't display "you"
if(uid != '')
{
	document.getElementById('connect').style.display = 'none';
}
user_box.innerHTML =
	  "<span>"
	+ "Welcome back (<fb:name uid='loggedinuser' useyou='false' size='q'></fb:name>)"
	+ "<fb:profile-pic uid='loggedinuser' facebook-logo='true'></fb:profile-pic>"
	+ "</span>";

  // because this is XFBML, we need to tell Facebook to re-process the document 
  FB.XFBML.Host.parseDomTree();
}
function loginchecking(uid)
{
	
		inam=GetXmlHttpObject();
	if (inam==null)
	  {
	  alert ("Your browser does not support XMLHTTP!");
	  return;
	  }
	var url="gen_form.php";
	url=url+"?user_id="+uid;
	inam.onreadystatechange=stateChangedinam;
	inam.open("GET",url,true);
	inam.send(null);
}
function stateChangedinam()
{
if (inam.readyState==4)
  {
  document.getElementById("inputformsetdatas").innerHTML=inam.responseText;
  
//document.getElementById('facebooklogin').submit();
  }
}
function update_user_box2() {
uid = FB.Facebook.apiClient.get_session().uid;
checkRecord(uid);

  var user_box = document.getElementById("user");
  document.getElementById("showinvitedivdata").style.display="block";
  // add in some XFBML. note that we set useyou=false so it doesn't display "you"
if(uid != '')
{
	document.getElementById('search').style.display = 'none';
}
user_box.innerHTML =
	  "<span>"
	+ "Welcome back (<fb:name uid='loggedinuser' useyou='false' size='q'></fb:name>)"
	+ "<fb:profile-pic uid='loggedinuser' facebook-logo='true'></fb:profile-pic>"
	+ "</span>";

  // because this is XFBML, we need to tell Facebook to re-process the document 
  FB.XFBML.Host.parseDomTree();
}
//////////////////////////////////////////////////////////////////////////////

var xmlhttp23;
function InsertRecord2(uid)
{

	xmlhttp23=GetXmlHttpObject();
	if (xmlhttp23==null)
	  {
	  alert ("Your browser does not support XMLHTTP!");
	  return;
	  }
	var url="save_ajax.php";
	url=url+"?user_id="+uid;
	url=url+"&Action=UpdateRecord";
	xmlhttp23.onreadystatechange=stateChanged22;
	xmlhttp23.open("GET",url,true);
	xmlhttp23.send(null);
}

function stateChanged22()
{
if (xmlhttp23.readyState==4)
  {
  //document.getElementById("showinvitedivdata2").innerHTML=xmlhttp.responseText;
  //document.getElementById("showinvitedivdata2").style.display="none";
  //window.location.href = 'login.tpl.php';
  //document.getElementById("formdata").style.display="none";
  }
}

//////////////////////////////////////////////////////////////////////////////
       
var xmlhttp
function checkRecord(uid)
{

	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Your browser does not support XMLHTTP!");
	  return;
	  }
	var url="login_ajax.php";
	url=url+"?user_id="+uid;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
  {
  //show_dialog();
	document.getElementById("showinvitedivdata2").innerHTML=xmlhttp.responseText;
  document.getElementById("spinner222").style.display="block";
  }
}

function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  return new XMLHttpRequest();
	  }
	if (window.ActiveXObject)
	  {
	  // code for IE6, IE5
	  return new ActiveXObject("Microsoft.XMLHTTP");
	  }
	return null;
}  
function checkForm()
{
	if(document.getElementById("location").value == '|Y' || document.getElementById("username").value == '')
	{
		var msg=''
		if(document.getElementById("location").value == '|Y')
		{
			msg+="Please select your location.";
		}
		if(document.getElementById("username").value == '')
		{
			msg+="Please enter username.";
		}
		alert(msg);
		return false;
	}else{
		
		InsertRecord();
	}
}

var xmlhttp2;
function InsertRecord()
{

	xmlhttp2=GetXmlHttpObject();
	if (xmlhttp2==null)
	  {
	  alert ("Your browser does not support XMLHTTP!");
	  return;
	  }
	 var user_id = document.getElementById('user_id').value;
	 var age = document.getElementById('age').value;
	 var location = document.getElementById('location').value;
	 var username = document.getElementById('username').value;
	
	var url="save_ajax.php";
	url=url+"?user_id="+user_id;
	url=url+"&location="+location;
	url=url+"&age="+age;
	url=url+"&username="+username;
	xmlhttp2.onreadystatechange=stateChanged22222;
	xmlhttp2.open("GET",url,true);
	xmlhttp2.send(null);
}

function stateChanged22222()
{
if (xmlhttp2.readyState==4)
  {
  document.getElementById("showinvitedivdata2").innerHTML=xmlhttp2.responseText;
  document.getElementById("spinner222").style.display="none";
  //window.location.href = 'http://fatzoo.comindex.php';
  //document.getElementById("formdata").style.display="none";
  }
}
var xmlhttp3;
function saveStatus()
{
		xmlhttp3=GetXmlHttpObject();
	if (xmlhttp3==null)
	  {
	  alert ("Your browser does not support XMLHTTP!");
	  return;
	  }
	 var status = document.getElementById('status').value;
	 
	var url="set_status.php";
	url=url+"?status="+status;
	xmlhttp3.onreadystatechange=stateChanged3;
	xmlhttp3.open("GET",url,true);
	xmlhttp3.send(null);
}
function stateChanged3()
{
if (xmlhttp3.readyState==4)
  {
  document.getElementById("showinvitedivdata2").innerHTML=xmlhttp3.responseText;
  document.getElementById("spinner222").style.display="none";
  //document.getElementById("formdata").style.display="none";
  }
}

function checkUserName()
{
	if(document.getElementById("username").value == '')
	{
		document.getElementById("usermsgdiv").innerHTML = 'Please enter username!';
		return false;
	}else{
		
		checkUsersidName();
	}
}
var xmlhttp4;
function checkUsersidName()
{
		xmlhttp4=GetXmlHttpObject();
	if (xmlhttp4==null)
	  {
	  alert ("Your browser does not support XMLHTTP!");
	  return;
	  }
	 var username = document.getElementById('username').value;
	 
	var url="check_username.php";
	url=url+"?username="+username;
	xmlhttp4.onreadystatechange=stateChanged4;
	xmlhttp4.open("GET",url,true);
	xmlhttp4.send(null);
}
function stateChanged4()
{
if (xmlhttp4.readyState==4)
  {
  document.getElementById("usermsgdiv").innerHTML=xmlhttp4.responseText;
  document.getElementById("usermsgdiv").style.display="block";
  
  }
}
function clearText()
{
	document.getElementById("username").value='';
}




/////////////////////////////////////
function submitformwithvalue(uid,pass)
{
	
	document.getElementById("fbuser").value = uid;
	document.getElementById("fbpass").value = pass;
	document.getElementById("facebooklogin").submit();
}

