function toggle(div_id) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) {	el.style.display = 'block';}
	else {el.style.display = 'none';}
}
function blanket_size(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	} 
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv1 = document.getElementById(popUpDivVar);
	popUpDiv_height=blanket_height/2-250;//150 is half popup's height
	popUpDiv1.style.top = popUpDiv_height + 'px';
}
function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv1 = document.getElementById(popUpDivVar);
	window_width=window_width/2-400;//150 is half popup's width
	popUpDiv1.style.left = window_width + 'px';
}
function popup(windowname) {
	blanket_size(windowname);
	window_pos(windowname);
	toggle('blanket');
	toggle(windowname);   /*toggle('popUpDivLoginTL');toggle('popUpDivLoginTR');toggle('popUpDivLoginBL');toggle('popUpDivLoginBR');*/
	if 	(windowname == 'popUpDivLogin')
		{document.getElementById('username').focus();}
}

/* POP up 2 */
//function toggle(div_id) {
//	var el = document.getElementById(div_id);
//	if ( el.style.display == 'none' ) {	el.style.display = 'block';}
//	else {el.style.display = 'none';}
//}
//function blanket_size(popUpDivVar) {
//	if (typeof window.innerWidth != 'undefined') {
//		viewportheight = window.innerHeight;
//	} else {
//		viewportheight = document.documentElement.clientHeight;
//	}
//	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
//		blanket_height = viewportheight;
//	} else {
//		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
//			blanket_height = document.body.parentNode.clientHeight;
//		} else {
//			blanket_height = document.body.parentNode.scrollHeight;
//		}
//	} 
//	var blanket = document.getElementById('blanket');
//	blanket.style.height = blanket_height + 'px';
//	var popUpDiv2 = document.getElementById(popUpDivVar);
//	popUpDiv_height=blanket_height/2-300;//150 is half popup's height
//	popUpDiv2.style.top = popUpDiv_height + 'px';
//}
//function window_pos(popUpDivVar) {
//	if (typeof window.innerWidth != 'undefined') {
//		viewportwidth = window.innerHeight;
//	} else {
//		viewportwidth = document.documentElement.clientHeight;
//	}
//	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
//		window_width = viewportwidth;
//	} else {
//		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
//			window_width = document.body.parentNode.clientWidth;
//		} else {
//			window_width = document.body.parentNode.scrollWidth;
//		}
//	}
//	var popUpDiv2 = document.getElementById(popUpDivVar);
//	window_width=window_width/2-400;//150 is half popup's width
//	popUpDiv2.style.left = window_width + 'px';
//}
//function popup(windowname) {
//	blanket_size(windowname);
//	window_pos(windowname);
//	toggle('blanket');
//	toggle(windowname);		
//}

/* For image pre-load */
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
//	alert('sfg');
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

/* FaceBook */

function fbinit()
/*{
	facebook_onload(true);
      FB_RequireFeatures(["XFBML", "CanvasUtil"], function()
      {
        FB.Facebook.init("d7b64a05c42bbda2ef8bb5d116138452", "xd_receiver.htm");
        FB.Facebook.get_sessionState().waitUntilReady(function()
        {
          update_user_box();
        });
      });

    };
}*/


{FB.init("d7b64a05c42bbda2ef8bb5d116138452", "xd_receiver.htm", {"ifUserConnected" : update_user_box});
    FB_RequireFeatures(["XFBML", "CanvasUtil"], function()
    {
      FB.Facebook.init("d7b64a05c42bbda2ef8bb5d116138452", "xd_receiver.htm");
     // FB.Facebook.get_sessionState().waitUntilReady(function()
//      {
	//   window.alert("Session is ready");
        //If you want to make Facebook API calls from JavaScript do something like
    //    FB.Facebook.apiClient.friends_get(null, function(result, ex) {
          //Do something with result
		//						window.alert("Friends list: " + result);
       //   });

  //    });
    });
}
   

function update_user_box() {
var user_box = document.getElementById("user");
  // add in some XFBML. note that we set useyou=false so it doesn't display "you"   &nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;
user_box.innerHTML =
      "<span>"
    + "Welcome, <fb:name uid=loggedinuser useyou=false></fb:name>.&nbsp;&nbsp;|&nbsp;&nbsp;"
	+ "<a onclick='javascript: fblogout();' href='#'>Logout</a>&nbsp;&nbsp;|&nbsp;&nbsp;"
	+ "<fb:profile-pic uid=loggedinuser facebook-logo=true linked='false' width='60px' height='60px' size='normal'></fb:profile-pic>&nbsp;&nbsp;"
//	+ "<a onclick='fb.Connect.LogoutAndRedirect('/index.htm')' href='#'>Logout</a>"
	+ "</span>";

  // because this is XFBML, we need to tell Facebook to re-process the document 
FB.XFBML.Host.parseDomTree();
}


function fblogout() {
FB.Connect.Logout
// because this is XFBML, we need to tell Facebook to re-process the document 
FB.XFBML.Host.parseDomTree();

//var user_box = document.getElementById("user");
//user_box.innerHTML = "<a href='#'><fb:login-button size='large' background='white' length='long'></fb:login-button></a>";

//document.getElementById('user').innerHTML = '<a href="#"><fb:login-button size="large" background="white" length="long"></fb:login-button></a>';
document.getElementById('user').innerHTML = '<p><a href="#" onclick="popup("popUpDiv1")">Login</a></p><p><a href="#"><fb:login-button size="large" background="white" length="long" onlogin="update_user_box();"></fb:login-button></a></p>';
//window.location.reload();
}



/*function updateUI() {
        var user = FB.Facebook.apiClient.get_session() ? FB.Facebook.apiClient.get_session().uid : null;
        var singleton=FB.Connect._singleton;
        var nextUrl=FBIntern.Uri.addQueryParameters(FB.XdComm.Server.singleton.get_receiverUrl(),'fb_login&fname=_parent&ses
sion=loggedout')
        singleton._ensureLoginHandler();
        singleton._logoutCallback="http://www.mydomain.com/ndex.php";
        logoutUrl=FBIntern.Utility.getFacebookUrl('www')+'logout.php?app_key='+FB.Facebook.apiKey+'&session_key='+encodeURIC
omponent(FB.Facebook.apiClient.get_session().session_key)+'&next='+encodeURIComponent(nextUrl);
        FB.Facebook.apiClient.set_session(null);
        singleton.set__userInfo(null);
        singleton._logoutIframe=FB.XdComm.Server.singleton.createNamedHiddenIFrame('fbLogout',logoutUrl,'fb_logout',null);
}*/

