
function addfriend(requestTo,requestFrom) {
  document.getElementById('errors').style.display = 'none';

  // Check to make sure this user is logged in first
  if(requestFrom == null || requestFrom == '') {
    window.location = '/members/logins.php';
    return false;
  }
  
  // get the ajax object
  xmlHttp = GetXmlHttpObject();
  
  // Form the URL to send
  var url = "/members/request.php?r="+requestFrom+"&u="+requestTo;

  xmlHttp.onreadystatechange = checkFriend;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

// function used to display the message back to the screen after the database validation is done
function checkFriend() 
{ 
  if(xmlHttp.readyState == 4)
  { 
    if(xmlHttp.responseText == 'sameUser'){
      document.getElementById('errors').style.display = 'block';
      
      document.getElementById('errors').innerHTML = 'You cant add yourself as a friend';
      return false;
    }
    
    if(xmlHttp.responseText == 'alreadyFriends'){
      document.getElementById('errors').style.visibility = 'visible';
      document.getElementById('errors').style.display = 'block';
      
      document.getElementById('errors').innerHTML = 'Your already friends with this user';
      return false;
    }
    
    if(xmlHttp.responseText == 'requestSent'){
      document.getElementById('errors').style.visibility = 'visible';
      document.getElementById('errors').style.display = 'block';
      
      document.getElementById('errors').innerHTML = '<font color="#008C00">Your friend request has been sent</font>';
      return false;
    }
    
    if(xmlHttp.responseText == 'blocked'){
      document.getElementById('errors').style.visibility = 'visible';
      document.getElementById('errors').style.display = 'block';
      
      document.getElementById('errors').innerHTML = 'This user has blocked you';
      return false;
    }
  }
}

function blockuser(requestTo,requestFrom) {
  document.getElementById('errors').style.display = 'none';

  // Check to make sure this user is logged in first
  if(requestFrom == null || requestFrom == '') {
    window.location = '/members/logins.php';
    return false;
  }
  
  // get the ajax object
  xmlHttp = GetXmlHttpObject();
  
  // Form the URL to send
  var url = "/members/block.php?r="+requestFrom+"&u="+requestTo;

  xmlHttp.onreadystatechange = checkBlock;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

// function used to display the message back to the screen after the database validation is done
function checkBlock() 
{ 
  if(xmlHttp.readyState == 4)
  { 
    if(xmlHttp.responseText == 'requestSent'){
      document.getElementById('errors').style.visibility = 'visible';
      document.getElementById('errors').style.display = 'block';
      
      document.getElementById('errors').innerHTML = '<font color="#008C00">You have blocked this user</font>';
      return false;
    }
    
    if(xmlHttp.responseText == 'blocked'){
      document.getElementById('errors').style.visibility = 'visible';
      document.getElementById('errors').style.display = 'block';
      
      document.getElementById('errors').innerHTML = 'You have already blocked this user';
      return false;
    }
    
    if(xmlHttp.responseText == 'sameUser'){
      document.getElementById('errors').style.visibility = 'visible';
      document.getElementById('errors').style.display = 'block';
      
      document.getElementById('errors').innerHTML = 'You cannot block yourself';
      return false;
    }
  }
}

function subscribe(subscribeTo,subscriber) {
  document.getElementById('errors').style.display = 'none';

  // Check to make sure this user is logged in first
  if(subscriber == null || subscriber == '') {
    window.location = '/members/logins.php';
    return false;
  }
  
  // get the ajax object
  xmlHttp = GetXmlHttpObject();
  
  // Form the URL to send
  var url = "/members/subscribes.php?sub="+subscriber+"&subto="+subscribeTo;

  xmlHttp.onreadystatechange = checksubscription;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

// function used to display the message back to the screen after the database validation is done
function checksubscription() 
{ 
  if(xmlHttp.readyState == 4)
  { 
    if(xmlHttp.responseText == 'sameUser'){
      document.getElementById('errors').style.display = 'block';
      
      document.getElementById('errors').innerHTML = 'You cannot subscribe to your own videos';
      return false;
    }
    
    if(xmlHttp.responseText == 'requestSent'){
      document.getElementById('errors').style.visibility = 'visible';
      document.getElementById('errors').style.display = 'block';
      
      document.getElementById('errors').innerHTML = '<font color="#008C00">You have been subscribed to this users videos</font>';
      return false;
    }
    
    if(xmlHttp.responseText == 'blocked'){
      document.getElementById('errors').style.visibility = 'visible';
      document.getElementById('errors').style.display = 'block';
      
      document.getElementById('errors').innerHTML = 'You have already subscribed to this users videos';
      return false;
    }
  }
}
