var currentcont = 1;
var minamized = 0;
var currentuserid = 1;
var safedel = 0;

function hidediv() {
if(document.getElementById('friendslist').style.visibility != 'hidden'){
document.getElementById('friendslist').style.visibility = 'hidden';
minamized = 0;
}else{
	document.getElementById('friendslist').style.visibility = 'visible'; 
	minamized = 1;
}
}
function showdiv() {
if(document.getElementById('friendslist').style.visibility == 'hidden'){
	document.getElementById('friendslist').style.visibility = 'visible';
	minamized = 1;
}
}
function addname (userid,username){
document.getElementById('iframechatform').src = "http://fragrush.com/Template/addnewchatcontact.php?id="+userid;
document.getElementById('chatbar').innerHTML += "<a class='section' onClick='chatnames("+userid+")' style='cursor:pointer;'>"+username.toString()+"</a>";
chatnames(userid);
}
function chatnames(userid){
if (currentuserid == userid && currentcont == 2){
hidediv();
}
else {
currentuserid = userid;
currentcont = 2;
filldiv('http://fragrush.com/Template/friendview.php?id='+userid+'&userid=','friendslist');
showdiv();
document.getElementById('friendviewarea').scrollTop = document.getElementById('friendviewarea').scrollHeight;
}
}
function friendlist(){
if (currentcont == 1){
	hidediv();
}
if (currentcont == 2){
filldiv('http://fragrush.com/Template/friendslist.php?userid=','friendslist');
currentcont = 1;
showdiv();
}
}
function refsec(){
if (currentcont == 2 && minamized == 1){
filldiv('http://fragrush.com/Template/friendviewfiller.php?id='+currentuserid+'&userid=','friendviewarea');
document.getElementById('friendviewarea').scrollTop = document.getElementById('friendviewarea').scrollHeight;
}
}
function refsecmainbar(){
filldiv('http://fragrush.com/Template/bottombarfiller.php?userid=','chatbar');
setTimeout("refsecmainbar()", 10000);
refsec();
document.getElementById('friendviewarea').scrollTop = document.getElementById('friendviewarea').scrollHeight;
}
function deltext(){
if (safedel == 1){
safedel = 0;
document.getElementById("chatpost").value = "";}
}
function OnSubmitForm(){
document.newchatpost.action ="http://fragrush.com/Template/newchatpost.php?id="+currentuserid;
document.newchatpost.target = "iframenewchatpost";
document.newchatpost.submit();
document.getElementById('friendviewarea').innerHTML += "<div class='darksection'>You: "+document.getElementById("chatpost").value+"</div>"+'<embed src="http://fragrush.com/IMG/beep2.mp3" autostart=true width=1 height=1></embed>';
document.getElementById('friendviewarea').scrollTop = document.getElementById('friendviewarea').scrollHeight;
safedel = 1;
setTimeout("deltext()", 100);
}
function filldiv(phpurl,divname)
  {
      var
          $http = null,
          $self = arguments.callee;

      if (window.XMLHttpRequest) {
          $http = new XMLHttpRequest();
      } else if (window.ActiveXObject) {
          try {
              $http = new ActiveXObject('Msxml2.XMLHTTP');
          } catch(e) {
              $http = new ActiveXObject('Microsoft.XMLHTTP');
          }
      }

      if ($http) {
          link = phpurl;
          $http.open('GET', link, true);
          $http.onreadystatechange = function()
          {
              if (/4|^complete$/.test($http.readyState)) {
                  document.getElementById(divname).innerHTML = $http.responseText;
              }
          };
                      
          
          $http.send(null);
      }
      
  }
  function Ajaxref()
			{
				var
					$http = null,
					$self = arguments.callee;

				if (window.XMLHttpRequest) {
					$http = new XMLHttpRequest();
				} else if (window.ActiveXObject) {
					try {
						$http = new ActiveXObject('Msxml2.XMLHTTP');
					} catch(e) {
						$http = new ActiveXObject('Microsoft.XMLHTTP');
					}
				}

				if ($http) {
					link = 'http://fragrush.com/Template/friendslistfiller.php?user=';
					$http.open('GET', link, true);
					$http.onreadystatechange = function()
					{
						if (/4|^complete$/.test($http.readyState)) {
							document.getElementById('friendlistarea').innerHTML = $http.responseText;
							setTimeout(function(){$self();}, 10000);
						}
					};
								
					
					$http.send(null);
				}

			}

