var xhr = false;
var smileys=new Array(':)' ,':-)',':(',':-(',':D',';-)',';)',':o', ':-o' ,'8-)', '8)', ':|', ':-|', ":'-(", ":'(", ":p", ":-p", ":s", ":-s", ":x", ":-x");
var Status="";
var mutual=0;
var search="";

function xml_httpObject(){
  if (window.XMLHttpRequest) {
     xhr = new XMLHttpRequest();
   }
   else if (window.ActiveXObject) {
     try {
       xhr = new ActiveXObject("Microsoft.XMLHTTP");
       if(!xhr)
 	 xhr= new ActiveXobject("Msxml2.XMLHTTP");
      }
     catch (e) { }
  }
  return xhr;
}		

function display_smiley(imgSource){
 mystatus=$('update_status').value; 
 
 if(mystatus!=""){
  $('update_status').value= mystatus+" "+imgSource;
 }
 else{
  $('update_status').value= imgSource;
 }
 $('update_status').focus();
}

function status_submit(){
 mystatus=$('update_status').value;
 url='statusUpdate.php?status='+mystatus;
 if(mystatus==""){
    return;
  }
 else{
   getstatus(url);   
 }
}


function getstatus(url){
 var xhr=xml_httpObject();
  if (xhr) {
     xhr.onreadystatechange = statusContents;
     xhr.open("GET", url, true);
     xhr.send(null);
  }
  else {
     document.getElementById("mystatus_update").innerHTML = "Your browser does not support all the features of this application";
  }
}

function statusContents() {
  if (xhr.readyState == 4) {
     if (xhr.status == 200) {
        var outMsg =xhr.responseText;
      }
      else {
	var outMsg = "There was a problem communicating with the server program";
      }
    $("mystatus_update").innerHTML = outMsg;
    $('update_status').value="";
   }
  
}

function profileFriends(url,m){
//profileFriends.php?user={$owner->user_info.user_username}&v=friends&m=1
mutual=m;
url="profileFriends.php?user="+url+"&v=friends&m="+m;

 var xhr=xml_httpObject();
  if (xhr) {
     xhr.onreadystatechange = profileFriendsContents;
     xhr.open("GET", url, true);
     xhr.send(null);
  }
  else {
     $("profileFriends").innerHTML = "Your browser does not support all the features of this application";
  }
}

function profileFriendsContents() {
  if (xhr.readyState == 4) {
     if (xhr.status == 200) {
        var outMsg =xhr.responseText;
      }
      else {
	var outMsg = "There was a problem communicating with the server program";
      }
   
    $("profileFriends").innerHTML = outMsg;
   }
  
}

function friendsForm_submit(owner){
search=$("friendsForm_text").value;
url="profileFriends.php?user="+owner+"&v=friends&m="+mutual+"&search="+search;
 var xhr=xml_httpObject();
  if (xhr) {
     xhr.onreadystatechange = profileFriendSearch;
     xhr.open("GET", url, true);
     xhr.send(null);
  }
  else {
     $("profileFriends").innerHTML = "Your browser does not support all the features of this application";
  }
}

function profileFriendSearch() {
  if (xhr.readyState == 4) {
     if (xhr.status == 200) {
        var outMsg =xhr.responseText;
      }
      else {
	var outMsg = "There was a problem communicating with the server program";
      }
   
    $("profileFriends").innerHTML = outMsg;
    $("friendsForm_text").value=search;
    $("friendsForm_text").focus();
   }
  
}


