var xmlHttp5;

var boxcount = 0;
var userId =0;

function gallerybox(userId)
{
		
		document.getElementById("boxgallery").innerHTML='<img src="images/loading.gif" align="center" />';
		xmlHttp5=GetXmlHttpObject();
		if (xmlHttp5==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  }
		  
		var url="boxes/gallery.php?userId="+userId;
		url=url+"&sid="+Math.random();
		xmlHttp5.onreadystatechange=stateChangedbox;
		xmlHttp5.open("GET",url,true);
		xmlHttp5.send(null);
		
}
function commentbox(userId)
{
		
		document.getElementById("boxcomment").innerHTML='<img src="images/loading.gif" align="center" />';
		xmlHttp5=GetXmlHttpObject();
		if (xmlHttp5==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  }
		  
		var url="boxes/testimonial.php?userId="+userId;
		url=url+"&sid="+Math.random();
		xmlHttp5.onreadystatechange=stateChangedbox;
		xmlHttp5.open("GET",url,true);
		xmlHttp5.send(null);
}
function videosbox(userId)
{
		
		document.getElementById("boxvideos").innerHTML='<img src="images/loading.gif" align="center" />';
		xmlHttp5=GetXmlHttpObject();
		if (xmlHttp5==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  }
		  
		var url="boxes/videos.php?userId="+userId;
		url=url+"&sid="+Math.random();
		xmlHttp5.onreadystatechange=stateChangedbox;
		xmlHttp5.open("GET",url,true);
		xmlHttp5.send(null);
}

function chatbox(Id)
{
		userId = Id;
		
		document.getElementById("boxchat").innerHTML='<img src="images/loading.gif" align="center" />';
		xmlHttp5=GetXmlHttpObject();
		if (xmlHttp5==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  }
		  
		var url="boxes/chat.php?userId="+userId;
		url=url+"&sid="+Math.random();
		xmlHttp5.onreadystatechange=stateChangedbox;
		xmlHttp5.open("GET",url,true);
		xmlHttp5.send(null);
}





function managemenu(name,id,option)
{
		
		document.getElementById("load").innerHTML='<img src="images/loading.gif" align="center" />';
		xmlHttp5=GetXmlHttpObject();
		if (xmlHttp5==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  }
		  
		var url="manage-school-info.php?name="+name+"&id="+id+"&option="+option;
		url=url+"&sid="+Math.random();
		xmlHttp5.onreadystatechange=stateChanged;
		xmlHttp5.open("GET",url,true);
		xmlHttp5.send(null);
}

var charstart = 'A';//default

function set_charstart(char)
{
	charstart = char;
	browse_unitown_users(1,'','','','');
}

function browse_unitown_users(page,type,keyword,gender,onlyphotos)
{
		if(type=='')
		type = '';
		if(keyword=='')
		keyword = '';
		if(gender=='')
		gender='';
		if(onlyphotos=='')
		onlyphotos='';
		
		//alert(page+type+keyword+gender+onlyphotos);
		document.getElementById("load").innerHTML='<img src="images/loading.gif" align="center" />';
		document.getElementById("load2").innerHTML='<img src="images/loading.gif" align="center" />';
		xmlHttp5=GetXmlHttpObject();
		if (xmlHttp5==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  }
		  
		var url="includes/browse-unitown-users.php?charstart="+charstart+"&page="+page+"&type="+type+"&keyword="+keyword+"&gender="+gender+"&onlyphotos="+onlyphotos;
		url=url+"&sid="+Math.random();
		xmlHttp5.onreadystatechange=stateChanged_browse;
		xmlHttp5.open("GET",url,true);
		xmlHttp5.send(null);
}


function adddeclinefriend(uuf_id,option,name)
{
if(option=='decline')
{
	var agree=confirm("Decline "+name+" as your friend?");
		
		
	if (agree){
			
		document.getElementById("load").innerHTML='<img src="images/loading.gif" align="center" />';
		xmlHttp5=GetXmlHttpObject();
		if (xmlHttp5==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  }
		  
		var url="includes/friend-request-add-decline.php?uuf_id="+uuf_id+"&option="+option+"&id="+name;
		url=url+"&sid="+Math.random();
		xmlHttp5.onreadystatechange=stateChangedaddfriend;
		xmlHttp5.open("GET",url,true);
		xmlHttp5.send(null);
		
		
	}
	else{
	
	return false;
	
	}
}
else
{
		
			
		document.getElementById("load").innerHTML='<img src="images/loading.gif" align="center" />';
		xmlHttp5=GetXmlHttpObject();
		if (xmlHttp5==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  }
		  
		var url="includes/friend-request-add-decline.php?uuf_id="+uuf_id+"&option="+option+"&id="+name;
		url=url+"&sid="+Math.random();
		xmlHttp5.onreadystatechange=stateChangedaddfriend;
		xmlHttp5.open("GET",url,true);
		xmlHttp5.send(null);
		
		
}	
}



function stateChangedbox() 
{ 
	
	if (xmlHttp5.readyState==4)
	{ 
	
			boxcount++;
			if(boxcount==1){
				
				document.getElementById("boxchat").innerHTML=xmlHttp5.responseText;
				gallerybox(userId);
				
			}
			else if(boxcount==2){
				
				document.getElementById("boxgallery").innerHTML=xmlHttp5.responseText;
				videosbox(userId);
			
			}
			else if(boxcount==3){
				
				document.getElementById("boxvideos").innerHTML=xmlHttp5.responseText;
				commentbox(userId);
			
			}
			else if(boxcount==4){
				
				document.getElementById("boxcomment").innerHTML=xmlHttp5.responseText;
			
			}
			
			
			
	
	}

}

function stateChangedaddfriend() 
{ 

	if (xmlHttp5.readyState==4)
	{ 
			
			document.getElementById("friendrequestcontent").innerHTML=xmlHttp5.responseText;
			document.getElementById("load").innerHTML='';
	
	}

}

function stateChanged() 
{ 

	if (xmlHttp5.readyState==4)
	{ 
			
			document.getElementById("menu").innerHTML=xmlHttp5.responseText;
			document.getElementById("load").innerHTML='';
	
	}

}

function stateChanged_browse() 
{ 

	if (xmlHttp5.readyState==4)
	{ 
			document.getElementById("load").innerHTML='';
			document.getElementById("load2").innerHTML='';
			document.getElementById("browse-user").innerHTML=xmlHttp5.responseText;
			
	
	}

}
function GetXmlHttpObject()
{
	//alert('vv');
var xmlHttp5=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp5=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp5=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp5=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp5;
}

function deleteComment(testimonial_id) { 

 win = new Window( { className: 'alphacube', url: 'includes/confirm-delete-testimonial-form.php?testimonial_id='+testimonial_id,
    title: '<strong>Confirm Delete Comment</strong>', width:400,
    height:300, destroyOnClose: true, recenterAuto:false } ); 
 	win.showCenter();
	win.show(true);

}
