/* ========================================================
	Component-fetching File
	Started: 3.25.2008
	Version: 3.25.2008
	Copyright 2007-2008 Michael Wallar
   ======================================================== */
   
//============================================================
// Getting it on with the AJAX
//============================================================
function getcomps($id) {
	var xhr = new XMLHttpRequest();
	var url = "http://iem.rp-addict.com/core/comps.php?id="+$id;
	var ele = "extras_"+$id;
	var ele2 = "getcomps_"+$id;
	xhr.open("GET", url, true);
	xhr.onreadystatechange = function(){
		if ( xhr.readyState == 4 ) {
			if ( xhr.status == 200 ) {
				document.getElementById(ele).innerHTML = xhr.responseText;
				var cont = '<a title="Close Components" href="index.php?type=mod&show=' + $id + '" onclick="javascript:closeextra(' + $id + '); return false;" alt="View Components"><img src="style/comps_close.png" /></a>';
				document.getElementById(ele2).innerHTML = cont;
			} else {
				document.body.innerHTML = "ERROR";
			}
		}
	};
	xhr.send(null);
}

function closeextra($id) {
	var ele = "extras_"+$id;
	var ele2 = "getcomps_"+$id;
	var cont = '<a title="Get Components" href="index.php?type=mod&show=' + $id + '" onclick="javascript:getcomps(' + $id + '); return false;" alt="View Components"><img src="style/comps.png" /></a>';
	document.getElementById(ele).innerHTML = '';
	document.getElementById(ele2).innerHTML = cont;
}

//============================================================
// Stop reading my comments. Jerk, you're just like Kiyohiko 
// Azuma. Jerk-face. You jerky-jerky, jerk-face.
//============================================================
function ic($id) {
	var xhr = new XMLHttpRequest();
	var url = "http://iem.rp-addict.com/core/tcs.php?f=i&id="+$id;
	var ele = "ic_"+$id;
	var cont = '<span id="uc_' + $id + '"><a title="Uninstall Component (' + $id + ')" href="#Uninstall Component (' + $id + ')" onclick="javascript:uc(\'' + $id + '\'); return false;" alt="Uninstall Component (' + $id + ')"><img src="style/brick_delete.png" /></a></span>';
	xhr.open("GET", url, true);
	xhr.onreadystatechange = function(){
		if ( xhr.readyState == 4 ) {
			if ( xhr.status == 200 ) {
				document.getElementById(ele).innerHTML = xhr.responseText;
				document.getElementById(ele).innerHTML = cont;
			} else {
				document.body.innerHTML = "ERROR: Could not run scripts. Make sure you have an up-to-date browser, and JavaScript enabled.";
			}
		}
	};
	xhr.send(null);
}
function uc($id) {
	var xhr = new XMLHttpRequest();
	var url = "http://iem.rp-addict.com/core/tcs.php?f=u&id="+$id;
	var ele = "uc_"+$id;
	var cont = '<span id="ic_' + $id + '"><a title="Install Component (' + $id + ')" href="#Install Component (' + $id + ')" onclick="javascript:ic(\'' + $id + '\'); return false;" alt="Install Component (' + $id + ')"><img src="style/brick_add.png" /></a></span>';
	xhr.open("GET", url, true);
	xhr.onreadystatechange = function(){
		if ( xhr.readyState == 4 ) {
			if ( xhr.status == 200 ) {
				document.getElementById(ele).innerHTML = xhr.responseText;
				document.getElementById(ele).innerHTML = cont;
			} else {
				document.body.innerHTML = "ERROR: Could not run scripts. Make sure you have an up-to-date browser, and JavaScript enabled.";
			}
		}
	};
	xhr.send(null);
}
//============================================================
// Mass (Un)Installs
//============================================================
function icA1($id) {
	var xhr = new XMLHttpRequest();
	var url = "http://iem.rp-addict.com/core/tcsA1i.php?id="+$id;
	var ele = "extras_"+$id;
	xhr.open("GET", url, true);
	xhr.onreadystatechange = function(){
		if ( xhr.readyState == 4 ) {
			if ( xhr.status == 200 ) {
				document.getElementById(ele).innerHTML = xhr.responseText;
				getcomps($id);
			} else {
				document.body.innerHTML = "ERROR: Could not run scripts. Make sure you have an up-to-date browser, and JavaScript enabled.";
			}
		}
	};
	xhr.send(null);
}
function ucA1($id) {
	var xhr = new XMLHttpRequest();
	var url = "http://iem.rp-addict.com/core/tcsA1u.php?id="+$id;
	var ele = "extras_"+$id;
	xhr.open("GET", url, true);
	xhr.onreadystatechange = function(){
		if ( xhr.readyState == 4 ) {
			if ( xhr.status == 200 ) {
				document.getElementById(ele).innerHTML = xhr.responseText;
				getcomps($id);
			} else {
				document.body.innerHTML = "ERROR: Could not run scripts. Make sure you have an up-to-date browser, and JavaScript enabled.";
			}
		}
	};
	xhr.send(null);
}
function icA2($id) {
	var xhr = new XMLHttpRequest();
	var url = "http://iem.rp-addict.com/core/tcsA2i.php?id="+$id;
	xhr.open("GET", url, true);
	xhr.onreadystatechange = function(){
		if ( xhr.readyState == 4 ) {
			if ( xhr.status == 200 ) {
				document.getElementById('components').innerHTML = xhr.responseText;
			} else {
				document.body.innerHTML = "ERROR: Could not run scripts. Make sure you have an up-to-date browser, and JavaScript enabled.";
			}
		}
	};
	xhr.send(null);
}
function ucA2($id) {
	var xhr = new XMLHttpRequest();
	var url = "http://iem.rp-addict.com/core/tcsA2u.php?id="+$id;
	xhr.open("GET", url, true);
	xhr.onreadystatechange = function(){
		if ( xhr.readyState == 4 ) {
			if ( xhr.status == 200 ) {
				document.getElementById('components').innerHTML = xhr.responseText;
			} else {
				document.body.innerHTML = "ERROR: Could not run scripts. Make sure you have an up-to-date browser, and JavaScript enabled.";
			}
		}
	};
	xhr.send(null);
}