// funny bunny homepage JS
var site_root = 'http://www.tooshocking.com/';

function xmlHttp()
{
	var xmlHttp;
	
	try
	{
		// Opera 8.0+, Firefox, Safari
		xmlHttp = new XMLHttpRequest();
	} 
	catch (e)
	{
		// Internet Explorer Browsers
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		 catch (e) 
		{
			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e)
			{
				// Something went wrong
				alert("Your browser does not support AJAX.");
				return false;
			}
		}
	}
	return xmlHttp;
}

function friend_req(id){
	var ajaxRequest = xmlHttp();

	ajaxRequest.open("GET", site_root+"addfriend.php?action=request&fid="+id+"&rn="+Math.random(), true);
	ajaxRequest.send(null);
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			if(ajaxRequest.status == 200){
			document.getElementById("friend_req").innerHTML = ajaxRequest.responseText;
			}else{
			document.getElementById("friend_req").innerHTML = "Server not Responding";
			}
		}
	}
}

function commentAdd()
{
	var ajaxRequest;
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser does not support AJAX.");
				return false;
			}
		}
	}
	
	var comment = document.getElementById("cmt_comment").value;
	var video = document.getElementById("cmt_id").value;
	
	if(document.getElementById("cmt_comment").value.length < 2)
	{
		document.getElementById("commentResponse").innerHTML = "Please enter a comment";
	}
	else
	{
		if(document.getElementById("cmt_comment").value.length > 500)
		{
			document.getElementById("commentResponse").innerHTML = "Comment Too Long";
		}
		else
		{
		
			ajaxRequest.open("GET", site_root+"comment.php?comment="+comment+"&id="+video+"&type=profile&rn="+Math.random(), true);
			ajaxRequest.send(null);
			ajaxRequest.onreadystatechange = function(){
				if(ajaxRequest.readyState == 4)
				{
					if(ajaxRequest.status == 200)
					{
					document.getElementById("commentResponse").innerHTML = ajaxRequest.responseText;
					
					document.getElementById("commentBox").style.display = "none";
					}
					else
					{
					document.getElementById("commentResponse").innerHTML = "Server Not Responding";
					}
				}
		}
	}
}
}