var http = false;
var http2 = false;

if(navigator.appName == "Microsoft Internet Explorer") {
  http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
  http = new XMLHttpRequest();
} 

function replacehtml(id,url) {

  http.open("GET", url, true);
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
		alert("Your password has been sent, please check your email.");
      //document.getElementById(id).innerHTML = http.responseText;
	 // if(http.responseText.search('alert') > 0)
	 // {
	//	  alert("Sorry, promo code not recognised");
	//  }
    }
  }
  http.send(null);
 
}

function logoutall()
{
	document.getElementById("loader").src = "detailsfromfb.php";
}

function forgotpassword() {
var reply = prompt("Forgotten Password: Please enter your email address", "")
if(reply != "")
{
replacehtml('reply','http://waystosave.net.au/site/ajax2.php?email='+encodeURIComponent(reply));
}
}

function fblogin()
{
	FB.Connect.requireSession();
	setTimeout("loader1()", 5000);
		document.getElementById("loader").src = "detailsfromfb.php";
	// 
}
function loader1()
{
	document.getElementById("loader").src = "detailsfromfb.php";
}

function loader2()
{
	document.getElementById("loader").src = "fbnotify.php";
}
function emlogin(o)
{
	//o.email
	//o.password
	
	document.getElementById("loader").src = "loginem.php?username="+o.email+"&password="+o.password;
	
	// users tree
}

function emlogout()
{
	FB.Connect.logout();
	document.getElementById("loader").src = "logout.php";
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=550,height=600,left = 710,top = 300');");
}

function popUp2(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=774,height=700,left = 710,top = 300');");
}
function footercontact()
{
	popUp('popup/index.html');
}
function footerprivacy()
{
	popUp('privacy/index.html');
}

function footerprize()
{
	popUp('prizepopup/index.html');
}

function fbinvite()
{
	FB.Connect.requireSession();
	popUp2('invitefriends.php');
	//document.getElementById('invitefb').style.display="block";
	//document.getElementById("overinvite").src = "invitefriends.php";
}
/*
 * The facebook_onload statement is printed out in the PHP. If the user's logged in
 * status has changed since the last page load, then refresh the page to pick up
 * the change.
 *
 * This helps enforce the concept of "single sign on", so that if a user is signed into
 * Facebook when they visit your site, they will be automatically logged in -
 * without any need to click the login button.
 *
 * @param already_logged_into_facebook  reports whether the server thinks the user
 *                                      is logged in, based on their cookies
 *
 */
function facebook_onload(already_logged_into_facebook) {
  // user state is either: has a session, or does not.
  // if the state has changed, detect that and reload.
  FB.ensureInit(function() {
      FB.Facebook.get_sessionState().waitUntilReady(function(session) {
          var is_now_logged_into_facebook = session ? true : false;

          // if the new state is the same as the old (i.e., nothing changed)
          // then do nothing
          if (is_now_logged_into_facebook == already_logged_into_facebook) {
            //return;
          }

          // otherwise, refresh to pick up the state change
          document.getElementById("loader").src = "detailsfromfb.php";
        });
    });
}

/*
 * Our <fb:login-button> specifies this function in its onlogin attribute,
 * which is triggered after the user authenticates the app in the Connect
 * dialog and the Facebook session has been set in the cookies.
 */
function facebook_onlogin_ready() {
  // In this app, we redirect the user back to index.php. The server will read
  // the cookie and see that the user is logged in, and will deliver a new page
  // with content appropriate for a logged-in user.
  //
  // However, a more complex app could use this function to do AJAX calls
  // and/or in-place replacement of page contents to avoid a full page refresh.
  //refresh_page();
  //call in iframe
  document.getElementById("loader").src = "detailsfromfb.php";
  refresh_page();
}

/*
 * Do a page refresh after login state changes.
 * This is the easiest but not the only way to pick up changes.
 * If you have a small amount of Facebook-specific content on a large page,
 * then you could change it in Javascript without refresh.
 */
function refresh_page() {
	
	
    //document.getElementById("flashxyid").fbloginr({first:"Stephen",last:"Oliver",email:"stephen2earth@gmail.com",password:"helloWorld!",postcode:"2176"});
}

/*
 * Prompts the user to grant a permission to the application.
 */
function facebook_prompt_permission(permission) {
  FB.ensureInit(function() {
    FB.Connect.showPermissionDialog(permission);
  });
}

/*
 * Show the feed form. This would be typically called in response to the
 * onclick handler of a "Publish" button, or in the onload event after
 * the user submits a form with info that should be published.
 *
 */
function facebook_publish_feed_story(form_bundle_id, template_data) {
  // Load the feed form
  FB.ensureInit(function() {
          FB.Connect.showFeedDialog(form_bundle_id, template_data);
          //FB.Connect.showFeedDialog(form_bundle_id, template_data, null, null, FB.FeedStorySize.shortStory, FB.RequireConnect.promptConnect);

      // hide the "Loading feed story ..." div
      ge('feed_loading').style.visibility = "hidden";
  });
}

/*
 * If a user is not connected, then the checkbox that says "Publish To Facebook"
 * is hidden in the "add trees" form.
 *
 * This function detects whether the user is logged into facebook but just
 * not connected, and shows the checkbox if that's true.
 */
function facebook_show_feed_checkbox() {
  FB.ensureInit(function() {
      FB.Connect.get_status().waitUntilReady(function(status) {
          if (status != FB.ConnectState.userNotLoggedIn) {
            // If the user is currently logged into Facebook, but has not
            // authorized the app, then go ahead and show them the feed dialog + upsell
            checkbox = ge('publish_fb_checkbox');
            if (checkbox) {
              checkbox.style.visibility = "visible";
            }
          }
        });
    });
}
