/*=====================================*\
 * ################################### *
 * # vBH Mod DB AJAX Support         # *
 * ################################### *
 * #  Developed for vBHackers (c)    # *
 * #  by Idan Bismut                 # *
 * ################################### *
\*=====================================*/

//***********************************************************************

/* *****[ INSTALL MOD ]***** */

function ajax_install_mod(threadid)
{
	ModDB_Install = new vB_AJAX_Handler(true);
	ModDB_Install.postid = threadid;
	ModDB_Install.onreadystatechange(ajax_callback_install_mod_complete);	
	ModDB_Install.send('hacksdb_process_ajax.php','do=install&tid=' + threadid);
}


function ajax_callback_install_mod_complete()
{
	if (ModDB_Install.handler.readyState == 4 && ModDB_Install.handler.status == 200)
	{
		// Split data input from php file to flag & text information
		var result_bits = ModDB_Install.handler.responseText.toString().split("|");
		var op_result = result_bits[0];
		var install_count = result_bits[1];
		var op_status_text = result_bits[2];
		var has_attachment = result_bits[3];
		var force_attachment_change = result_bits[4];
		var attachment_html = result_bits[5];
		if (op_result == 1)
		{
			// Update Counter
			fetch_object('install_count_status_' + ModDB_Install.postid).innerHTML = install_count; 
			// Fix Link
			fetch_object('install_link_' + ModDB_Install.postid).innerHTML = '<a href="hackinstall.php?do=uninstallhack&threadid='+ ModDB_Install.postid+'"  OnClick="javascript:ajax_uninstall_mod('+ ModDB_Install.postid+'); return false;" rel="nofollow">Uninstall Modification</a>'; 
			
			if (has_attachment == 1 && force_attachment_change == 1)
			{
				// if non-admin - change cell content to allow attachment d/l files
				fetch_object('mod_attachments_' + ModDB_Install.postid).innerHTML = attachment_html;	
			}
			//alert('DEBUG: callback OK\nop_res: '+op_result+'\nInstall_count: '+install_count+'\nInfo: '+op_status_text);	
		} else {
			//alert('DEBUG: callback BAD\nop_res: '+op_result+'\nInfo: '+op_status_text);			
		}
	}
}

/* *****[ UNINSTALL MOD ]***** */

function ajax_uninstall_mod(threadid)
{
	ModDB_UnInstall = new vB_AJAX_Handler(true);
	ModDB_UnInstall.postid = threadid;
	ModDB_UnInstall.onreadystatechange(ajax_callback_uninstall_mod_complete);	
	ModDB_UnInstall.send('hacksdb_process_ajax.php','do=uninstall&tid=' + threadid);
}


function ajax_callback_uninstall_mod_complete()
{
	if (ModDB_UnInstall.handler.readyState == 4 && ModDB_UnInstall.handler.status == 200)
	{
		// Split data input from php file to flag & text information
		var result_bits = ModDB_UnInstall.handler.responseText.toString().split("|");
		var op_result = result_bits[0];
		var install_count = result_bits[1];
		var op_status_text = result_bits[2];
		var has_attachment = result_bits[3];
		var force_attachment_change = result_bits[4];
		var attachment_html = result_bits[5];
		if (op_result == 1)
		{
			// Update Counter
			fetch_object('install_count_status_' + ModDB_UnInstall.postid).innerHTML = install_count;
			// Fix Link
			fetch_object('install_link_' + ModDB_UnInstall.postid).innerHTML = '<a href="hackinstall.php?do=installhack&threadid='+ ModDB_UnInstall.postid+'"  OnClick="javascript:ajax_install_mod('+ ModDB_UnInstall.postid+'); return false;" rel="nofollow">Install Modification</a>'; 
			// Allow to d/l attachment files
			if (has_attachment == 1 && force_attachment_change == 1)
			{
				// Allow to d/l attachment files
				fetch_object('mod_attachments_' + ModDB_UnInstall.postid).innerHTML = attachment_html;
			}
			//alert('DEBUG: callback OK\nop_res: '+op_result+'\nInstall_count: '+install_count+'\nInfo: '+op_status_text);
		} else {
			//alert('DEBUG: callback BAD\nop_res: '+op_result+'\nInfo: '+op_status_text);	
		}
	}
}