
var xmlhttp

//######################################//
// FUNCTIONS USED BY MULTIPLE TEMPLATES //
//######################################//

/**
* Get our XML object so we can do some AJAX magic!
*/
function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}

//######################################//
// STYLE TEMPLATE: yourtanks_view       //
//######################################//

//Used to hide/unhide comment box
var comment_box_count = 0;

/**
* Get comment form html so we can add comment to image.
*/
function getCommentForm(str)
{
	//Get our XML Object
	xmlhttp=GetXmlHttpObject();
	//Make sure we have javascript enabled.
	if (xmlhttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	}
  	//Build URL to send to server
	var url="http://www.plantedtank.net/forums/yourtanks_ajax.php?do=getCommentBox&id="+str;
	//Link to function that receives response
	xmlhttp.onreadystatechange=getCommentForm_response;
	//Open and Send AJAX request
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
/**
* Handle server's response from getCommentForm().
*/
function getCommentForm_response()
{
	//We are ready to change page html
	if (xmlhttp.readyState==4)
	{
		//Show box html
		if(comment_box_count == 0)
    	{
			document.getElementById("commentForm").innerHTML=xmlhttp.responseText;
			comment_box_count = 1;
    	}
    	//Hide box.
    	else
    	{
			document.getElementById("commentForm").innerHTML="";
			comment_box_count = 0;
    	}
  	}
}
/**
* Function to delete comment from profile.
*/
function deleteComment(str)
{
	//Get our xml object
	xmlhttp=GetXmlHttpObject();
	//Make sure we have javascript enabled
	if (xmlhttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}

	var url="http://www.plantedtank.net/forums/yourtanks_ajax.php?do=deleteComment" + str;
	//Link to function
	xmlhttp.onreadystatechange=deleteComment_response;
	//Open request and send
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
/**
* Handle the server's response to deleteComment()
*/
function deleteComment_response()
{
	//Make sure it is complete
	if (xmlhttp.readyState==4)
	{
		//Reload the comment table
		document.getElementById("commentTable").innerHTML=xmlhttp.responseText;
	}
}

/**
* Function to update tank rating.
*/
function updateRating_view(str)
{

	//Get our XML Object
	xmlhttp=GetXmlHttpObject();
	//Make sure we have javascript enabled.
	if (xmlhttp==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	}
  	//Build URL to send to server
	var url="http://www.plantedtank.net/forums/yourtanks_ajax.php?do=updateRating_view"+str;
	//Link to function that receives response
	xmlhttp.onreadystatechange=updateRating_view_response;
	//Open and Send AJAX request
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);

}
/**
* Handle server reponse from updateRating_view
*/
function updateRating_view_response()
{
	//We are ready to change page html
	if (xmlhttp.readyState==4)
	{
        xmlDoc=xmlhttp.responseXML;
        document.getElementById("rating_image").innerHTML='<img src="'+ xmlDoc.getElementsByTagName("rating_image")[0].childNodes[0].getAttribute('src') + '" />';
        document.getElementById("message").innerHTML=xmlDoc.getElementsByTagName("message")[0].childNodes[0].nodeValue;
	}

}
function deleteProfile_view(str)
{
	var result = confirm("Are you sure you want to delete this Profile?");
	if(result)
	{
		//Get our XML Object
		xmlhttp=GetXmlHttpObject();
		//Make sure we have javascript enabled.
		if (xmlhttp==null)
		{
			alert ("Your browser does not support AJAX!");
			return;
		}
		//Build URL to send to server
		var url="http://www.plantedtank.net/forums/yourtanks_ajax.php?do=deleteProfile_view&id="+str;
		//Link to function that receives response
		xmlhttp.onreadystatechange=deleteProfile_view_response;
		//Open and Send AJAX request
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}
}
/**
* Handle server reponse from updateRating_view
*/
function deleteProfile_view_response()
{
	//We are ready to change page html
	if (xmlhttp.readyState==4)
	{
        window.location.reload();
	}

}

/**
* Function call to delete image when browsing homepage.
*/
function deleteProfile_homepage(str)
{
	var result = confirm("Are you sure you want to delete this Profile?");
	if(result)
	{
		//Get our XML Object
		xmlhttp=GetXmlHttpObject();
		//Make sure we have javascript enabled.
		if (xmlhttp==null)
	  	{
	  		alert ("Your browser does not support AJAX!");
	  		return;
	  	}
	  	//BUild URL to send to server
		var url="http://www.plantedtank.net/forums/yourtanks_ajax.php?do=deleteProfile_homepage"+str;
		//Link to function that receives response
		xmlhttp.onreadystatechange=deleteProfile_homepage_response;
		//Open and Send AJAX request
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}
}
/**
* Handle server reponse from deleteProfile_homepage
*/
function deleteProfile_homepage_response()
{
	//We are ready to change page html
	if (xmlhttp.readyState==4)
	{
		document.getElementById("profileTable").innerHTML=xmlhttp.responseText;
	}

}
//#######################################//
// STYLE TEMPLATE: yourtanks_myFavorites //
//#######################################//
/**
* Function call to set favorite for profile when browsing myFavorites.
*/
function setFavorite_myFavorites(str)
{

	//Get our XML Object
	xmlhttp=GetXmlHttpObject();
	//Make sure we have javascript enabled.
	if (xmlhttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	//Build URL to send to server
	var url="http://www.plantedtank.net/forums/yourtanks_ajax.php?do=setFavorite_myFavorites"+str;
	//Link to function that receives response
	xmlhttp.onreadystatechange=setFavorite_myFavorites_response;
	//Open and Send AJAX request
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);

}
/**
* Handle server reponse from setFavorite_myFavorites
*/
function setFavorite_myFavorites_response()
{
	//We are ready to change page html
	if (xmlhttp.readyState==4)
	{
		document.getElementById("profileTable").innerHTML=xmlhttp.responseText;
	}

}
/**
* Function call to delete image when browsing homepage.
*/
function deleteProfile_myFavorites(str)
{
	var result = confirm("Are you sure you want to delete this Profile?");
	if(result)
	{
		//Get our XML Object
		xmlhttp=GetXmlHttpObject();
		//Make sure we have javascript enabled.
		if (xmlhttp==null)
	  	{
	  		alert ("Your browser does not support AJAX!");
	  		return;
	  	}
	  	//BUild URL to send to server
		var url="http://www.plantedtank.net/forums/yourtanks_ajax.php?do=deleteProfile_myFavorites"+str;
		//Link to function that receives response
		xmlhttp.onreadystatechange=deleteProfile_myFavorites_response;
		//Open and Send AJAX request
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}
}
/**
* Handle server reponse from deleteProfile_homepage
*/
function deleteProfile_myFavorites_response()
{
	//We are ready to change page html
	if (xmlhttp.readyState==4)
	{
		document.getElementById("profileTable").innerHTML=xmlhttp.responseText;
	}

}

//####################################//
// STYLE TEMPLATE: yourtanks_homepage //
//####################################//
/**
* Function call to set favorite for profile when browsing homepage.
*/
function setFavorite_homepage(str)
{

	//Get our XML Object
	xmlhttp=GetXmlHttpObject();
	//Make sure we have javascript enabled.
	if (xmlhttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	//BUild URL to send to server
	var url="http://www.plantedtank.net/forums/yourtanks_ajax.php?do=setFavorite_homepage"+str;
	//Link to function that receives response
	xmlhttp.onreadystatechange=setFavorite_homepage_response;
	//Open and Send AJAX request
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);

}
/**
* Handle server reponse from setFavorite_homepage
*/
function setFavorite_homepage_response()
{
	//We are ready to change page html
	if (xmlhttp.readyState==4)
	{
		document.getElementById("profileTable").innerHTML=xmlhttp.responseText;
	}

}
//#################################//
// STYLE TEMPLATE: yourtanks_admin //
//#################################//
/**
* Function call to delete image when browsing homepage.
*/
function undeleteProfile_admin(str)
{
	var result = confirm("Are you sure you want to undelete this Profile?");
	if(result)
	{
		//Get our XML Object
		xmlhttp=GetXmlHttpObject();
		//Make sure we have javascript enabled.
		if (xmlhttp==null)
	  	{
	  		alert ("Your browser does not support AJAX!");
	  		return;
	  	}
	  	//BUild URL to send to server
		var url="http://www.plantedtank.net/forums/yourtanks_ajax.php?do=undeleteProfile_admin"+str;
		//Link to function that receives response
		xmlhttp.onreadystatechange=undeleteProfile_admin_response;
		//Open and Send AJAX request
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}
}
/**
* Handle server reponse from deleteProfile_homepage
*/
function undeleteProfile_admin_response()
{
	//We are ready to change page html
	if (xmlhttp.readyState==4)
	{
		document.getElementById("profileTable").innerHTML=xmlhttp.responseText;
	}

}