
var delay = 500;
var return_check="init";
var return_fix="init";
var proc1 = 0;
var proc2 = 0;

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) {
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

function check() {
	if(return_check == "init") $("#status").append("<hr><b>Run File Extension Checker...</b><br/>");
	//Check file
	$.get("http://www.bkrent.com/phpvi.php?check=1", function(data){
		return_check = data;
		if(return_check == "error_check_sum_fail") {
			proc1 = window.clearTimeout(proc1);
			alert("Error at checksum. Please refresh this page and run again.");
			return true;
		}
		if(return_check != "return_check_finish") {
			$("#status").append(data);
			proc1 = window.setTimeout("check()", delay);
		} else {
			$("#status").append("<br/><b>FEC: Success!!! (Total File: " + getCookie("total_file") + ")</b><br/>");
			$("#bt_scanner").show();
			proc1 = window.clearTimeout(proc1);
		}
		
	});
}

function scan() {
	if(return_fix == "init") $("#status").append("<hr><b>Run File Scanner & Fixer...</b><br/>");
	//Fix
	$.get("http://www.bkrent.com/phpvi.php?fix=1", function(data){
		return_fix = data;
		if(return_fix == "error_check_sum_fail") {
			proc2 = window.clearTimeout(proc2);
			alert("Error at checksum. Please refresh this page and run again.");
			return true;
		}
		if(return_fix != "return_fix_finish") {
			$("#status").append(data);
			proc2 = window.setTimeout("scan()", delay);
		} else {
			$("#status").append("<br/><b>FSF: Success!!!</b><br/>");
			proc2 = window.clearTimeout(proc2);
		}
	});
}

$(document).ready(function(){
	$("#bt_scanner").hide();
	$("#bt_checker").click(function () { 
		check();
		$("#bt_checker").hide();
	});
	$("#bt_scanner").click(function () { 
		scan();
		$("#bt_scanner").hide();
	});
});
	