function MakeWizard() {
    $("#SignupForm").formToWizard({ submitButton: 'SaveAccount' });
    $("#makeWizard").hide();
    $("#info").fadeIn(400);
}
var notCheck = false;
var toDownload = new Array();
var sizeUpdateStarted = false;
function sizeUpdate(dontTypeSize){
	sizeUpdateStarted = true;
	
    var drpSize=5120;
    var allsize=0;
    var countfile=0;
    var x32 = (document.SignupForm.x32.checked?'x86':false);
    var x64 = (document.SignupForm.x64.checked?'x64':false);
    var WinXP = false;
    var WinVista7 = false;

    if (document.SignupForm.WinXP.checked) { var WinXP = 'XP'; }
    if (document.SignupForm.Win7.checked) { var WinVista7 = 'Vista7'; }
    
    if (!dontTypeSize) { $('.devices input').attr({checked: true, disabled: false}); }
    
    devicesNeed = (document.SignupForm.sound.checked?'sound ':' ') + 
                  (document.SignupForm.video.checked?'video ':' ') + 
                  (document.SignupForm.lan.checked?'lan ':' ') + 
                  (document.SignupForm.wifi.checked?'wifi ':' ') + 
                  (document.SignupForm.chipset.checked?'chipset ':' ') + 
                  (document.SignupForm.massstorage.checked?'massstorage ':' ') + 
                  (document.SignupForm.bluetooth.checked?'bluetooth ':' ') + 
                  
                  (document.SignupForm.modem.checked?'modem ':' ') + 
                  (document.SignupForm.webcamera.checked?'webcamera ':' ') + 
                  (document.SignupForm.cardreader.checked?'cardreader ':' ') + 
                  (document.SignupForm.cpu.checked?'cpu ':' ') + 
                  (document.SignupForm.inputdev.checked?'inputdev ':' ') + 
                  (document.SignupForm.monitor.checked?'monitor ':' ') + 
                  (document.SignupForm.printer.checked?'printer ':' ') + 
                  (document.SignupForm.scaner.checked?'scaner ':' ') + 
                  (document.SignupForm.usb.checked?'usb ':' ') + 
                  (document.SignupForm.other.checked?'other ':' ');
    //alert(devicesNeed);
    
    toDownload = new Array();
    for (i in file_name){
        if ((platform[i] != x32) && (platform[i] != x64)) { continue; }
        if (devicesNeed.indexOf(type[i]) == -1) { continue; }
    
        if ((windows[i] == WinVista7) || (windows[i] == WinXP)) {
            allsize += parseInt(size[i]);
            toDownload[toDownload.length] = i;
            countfile++;
        }
    }
    
    document.getElementById('allsize').innerHTML=Math.ceil(allsize/1024)+' Mb';
    document.getElementById('download_size').innerHTML=Math.ceil(allsize/1024);
    document.getElementById('countfile').innerHTML = uTrnt.getFilesIndexToDownload().length;//countfile;
    
    if (!notCheck) {
		thanks='<br><br> Огромная благодарность <a href="http://driverpacks.net/" target="_blank">driverpacks.net</a> за качественные сборки! <br> Спасибо администраторам серверов: <a href="http://www.dedicated-server.ru/" target="_blank">dedicated-server.ru</a>, <a href="http://nashalife.ru/" target="_blank">nashalife.ru</a> и <a href="http://playforce.ru/" target="_blank">playforce.ru</a>';
		if (((x32) && (WinXP)) && (!WinVista7)) {
			//document.getElementById('allsize').innerHTML='1799 Mb';
			//document.getElementById('countfile').innerHTML='1';	//DRPSu10-x32-XP.rar
			//document.getElementById('links').innerHTML='<p>Одним архивом: <a href="http://narod.ru/disk/18948809000/DRPSu10-x32-XP.rar.html" target="_blank">DRPSu10-x32-XP</a> | <a href="ftp://drp:drp@driverpacks.drp.su/DRPSu10-x32-XP.rar">DRP Su Server</a> | <a href="http://letitbit.net/download/6151.637f39d07bfc05279befe32fdb/DRPSu10_x32_XP.rar.html" target="_blank">LetitBit</a> | <a href="http://depositfiles.com/files/sjt67vs4m/DRPSu10-x32-XP.rar" target="_blank">Deposit</a></p> <p>MD5: 2C64F453103DF0DFC0107B4B92DFF6AA</p>';
			//document.getElementById('links').innerHTML+=thanks;
		}
		else if (((WinVista7) && (WinXP)) && (!x64)) {
			//document.getElementById('allsize').innerHTML='2496 Mb';
			//document.getElementById('countfile').innerHTML='1';	//DRPSu10_x32.rar
			//document.getElementById('links').innerHTML='<p>Одним архивом: <a href="http://letitbit.net/download/7158.798e9f1018ba1b6147c88a524f/DRPSu10_x32.rar.html" target="_blank">LetitBit</a> | <a href="http://turbobit.net/mh21z1a0d92o.html" target="_blank">TurboBit</a> | <a href="http://srv1.drp.su/DRPSu10-x32.rar">DRP Su Server</a> <br> <a href="http://tfile.ru/forum/download.php?id=275818&amp;uk=1111111111">Torrent</a> - <a href="http://tfile.ru/forum/viewtopic.php?t=63676" target="_blank">Как качать с tfile.ru?</a></p> <p>MD5: FD7669CD747DCD50769AB885331E5CC3</p>';
			//document.getElementById('links').innerHTML+=thanks;
		}
		else if ((WinVista7) && ((!x64) && (!WinXP))) {
			//document.getElementById('allsize').innerHTML='790 Mb';
			//document.getElementById('countfile').innerHTML='1';	//DRPSu10-x32-Vista7.rar
			//document.getElementById('links').innerHTML='<p>Одним архивом: <a href="http://narod.ru/disk/18947461000/DRPSu10-x32-Vista7.rar.html" target="_blank">DRPSu10-x32-Vista7</a> | <a href="http://srv1.drp.su/DRPSu10-x32-Vista7.rar">DRP Su Server</a> | <a href="http://letitbit.net/download/5944.53d90942afb86ce2710b45cc7c/DRPSu10_x32_Vista7.rar.html" target="_blank">LetitBit</a> | <a href="http://depositfiles.com/files/3iudo8z8x/DRPSu10-x32-Vista7.rar" target="_blank">Deposit</a></p> <p>MD5: B60F2062377B056123C96564B4A1BBEB</p>';
			//document.getElementById('links').innerHTML+=thanks;
		}
		else if ((WinVista7) && (WinXP) && (x32) && (x64)) {
			//document.getElementById('allsize').innerHTML='3326 Mb';
			//document.getElementById('countfile').innerHTML='1';	//DRPSu10-x32-x64.rar
			//document.getElementById('links').innerHTML='<p>Одним архивом: <a href="ftp://drp:drp@driverpacks.drp.su/DRPSu10-x32-x64.rar">DRPSu10-x32-x64</a> | <a href="http://turbobit.net/sk2yy7d0gvo8.html" target="_blank">TurboBit</a> | <!--<a href="http://artx.911.lgg.ru/DRPSu10-x32-x64.rar">DRPSu10-x32-x64</a> |--> <a href="http://tfile.ru/forum/download.php?id=272503&amp;uk=1111111111">Torrent</a> - <a href="http://tfile.ru/forum/viewtopic.php?t=63676" target="_blank">Как качать с tfile.ru?</a> <!-- | <a href="http://letitbit.net/download/5381.53600b423392249ebffff920a8/DRPSu10_x32_x64.rar.html" target="_blank">LetitBit</a>--></p> <p>MD5: 8D452B82A01D17D4B6E2DF1FE5DE8E94</p>';
			//document.getElementById('links').innerHTML+=thanks;
		}
		else { fillLinks(toDownload); }
	}
	else { fillLinks(toDownload); }
    
    
    if (!dontTypeSize){
        var typeSize = new Array();
        
        for (i in file_name){
            if (isNaN(typeSize[type[i]])) { typeSize[type[i]] = 0; }
            
            if ((platform[i] != x32) && (platform[i] != x64)) {
                continue;
            }
            
            if ((windows[i] == WinVista7) || (windows[i] == WinXP)) {
                typeSize[type[i]] += parseInt(size[i]);
            }
        }
        typeSize['drp']=drpSize;
        
		// Fixed undefined values in typeSize array
		var typeSizeNames = ['drp','sound','video','lan','wifi','chipset','massstorage','bluetooth','modem','webcamera','cardreader','cpu','inputdev','monitor','printer','scaner','usb','other'];
		for ( x in typeSizeNames )
			if ( typeof typeSize[typeSizeNames[x]] == 'undefined' ) {
				typeSize[typeSizeNames[x]] = 0;
			}
		
        for (x in typeSize){
            if (typeSize[x] == 0) {
                document.forms['SignupForm'].elements[x].disabled=true;
                document.forms['SignupForm'].elements[x].checked=false;
            }
        }
		
        document.forms['SignupForm'].elements['drp'].disabled=true;
       
        document.getElementById('drp-size').innerHTML=Math.ceil(typeSize['drp']/1024)+' Mb';
        document.getElementById('sound-size').innerHTML=Math.ceil(typeSize['sound']/1024)+' Mb';
        document.getElementById('video-size').innerHTML=Math.ceil(typeSize['video']/1024)+' Mb';
        document.getElementById('lan-size').innerHTML=Math.ceil(typeSize['lan']/1024)+' Mb';
        document.getElementById('wifi-size').innerHTML=Math.ceil(typeSize['wifi']/1024)+' Mb';
        document.getElementById('chipset-size').innerHTML=Math.ceil(typeSize['chipset']/1024)+' Mb';
        document.getElementById('massstorage-size').innerHTML=Math.ceil(typeSize['massstorage']/1024)+' Mb';
        document.getElementById('bluetooth-size').innerHTML=Math.ceil(typeSize['bluetooth']/1024)+' Mb';
        document.getElementById('modem-size').innerHTML=Math.ceil(typeSize['modem']/1024)+' Mb';
        document.getElementById('webcamera-size').innerHTML=Math.ceil(typeSize['webcamera']/1024)+' Mb';
        document.getElementById('cardreader-size').innerHTML=Math.ceil(typeSize['cardreader']/1024)+' Mb';
        document.getElementById('cpu-size').innerHTML=Math.ceil(typeSize['cpu']/1024)+' Mb';
        document.getElementById('inputdev-size').innerHTML=Math.ceil(typeSize['inputdev']/1024)+' Mb';
        document.getElementById('monitor-size').innerHTML=Math.ceil(typeSize['monitor']/1024)+' Mb';
        document.getElementById('printer-size').innerHTML=Math.ceil(typeSize['printer']/1024)+' Mb';
        document.getElementById('scaner-size').innerHTML=Math.ceil(typeSize['scaner']/1024)+' Mb';
        document.getElementById('usb-size').innerHTML=Math.ceil(typeSize['usb']/1024)+' Mb';
        document.getElementById('other-size').innerHTML=Math.ceil(typeSize['other']/1024)+' Mb';
        
        if ((!document.SignupForm.Win7.checked) && (!document.SignupForm.WinXP.checked)) {
            document.getElementById('step0Next').style.visibility = "hidden";
        }
        else {
            document.getElementById('step0Next').style.visibility = "";
        }
        
        if ((!document.SignupForm.x32.checked) && (!document.SignupForm.x64.checked)) {
            document.getElementById('step1Next').style.visibility = "hidden";
        }
        else {
            document.getElementById('step1Next').style.visibility = "";
        }
    }
    notCheck = false;
	
	sizeUpdateStarted = false;
}

function fillLinks(toDownload){
    serv="ftp://drp:drp@driverpacks.drp.su/";
    
    ret='<ol start="0"><li><b>DriverPack Solution 10 (5 Mb) - <a href="ftp://drp:drp@driverpacks.drp.su/DRPSu/DRPSu10-Mini.exe">Скачать</a></b></li>';
    
    ret+='';
    for (x in toDownload){
        ret += '<li>';
        ret += file_name[toDownload[x]] + ' - <a href="'+serv+path[toDownload[x]]+'/'+file_name[toDownload[x]]+'.7z">Скачать</a>';
        
        ret += '</li>';
    }
    ret+='</ol>';
    //document.getElementById('links').innerHTML=ret;
}

function downloadProgressBar(value,status) {
	progressBar_target=value;
    progressBar_target++;
	$("#progressbar").progressBar(progressBar_target, {
		boxImage: '..\\..\\ico\\infobar\\progress\\progressbar.gif',
		barImage: {
			0:  '..\\..\\ico\\infobar\\progress\\progressbg_red.gif',
			30: '..\\..\\ico\\infobar\\progress\\progressbg_orange.gif',
			70: '..\\..\\ico\\infobar\\progress\\progressbg_green.gif'
		}
	});
	if ( typeof status === 'object' ) {
		$('#download_downloaded').text(status['downloaded']);
		$('#download_speed').text(status['speed']);
		$('#download_eta').text(status['eta']);
		if ( status['status'].search(/check/i) != -1 )
			$('#download_status').text('подготовка');
		if ( status['status'].search(/start/i) != -1 )
			$('#download_status').text('загрузка');
		if ( status['status'].search(/pause/i) != -1 )
			$('#download_status').text('пауза');
		if ( status['status'].search(/stop/i) != -1 )
			$('#download_status').text('остановлено');
		if ( value == 100 )
			$('#download_status').text('завершено');
		if ( status['status'].search(/error/i) != -1 )
			$('#download_status').text('ошибка');
	}
}
/**
	Updates an config arrays: 
		file_name, path, type, size, windows, platform.
	@param array $files 	An list of paths to drivers with prefix 'drp\'.
	@param array $sizes		An list of sizes of files in bytes.
*/
function updateConfigArrays(files,sizes) {
	while ( sizeUpdateStarted == true ) ;

	file_name = [];
	path = [];
	type = [];
	size = [];
	windows = [];
	platform = [];
	var y = 0;
	
	for(var x in files) {
		var file = files[x];
		if ( file.search(/(^|\\)drp\\/) == -1 )
			continue;
		// Detecting arrays
		y++;
		size[y] = Math.round(sizes[x]/1024);
		path[y] = file.replace(/(^.*drp\\)|(\\?[^\\]+$)/gi,"");
		file_name[y] = file.replace(/(^.+\\)|(.7z)/gi,"");
		var name = path[y]+'\\'+file_name[y];
		platform[y] = name.search(/[_\-]x64[_\-\\$]/) != -1
			? 'x64' : 'x86';
		windows[y] = name.search(/wnt6|vista/i) != -1
			? "Vista7" : "XP";
		if ( file_name[y].search(/audio|sound/i) != -1 ) 				type[y]='sound';
		else if ( file_name[y].search(/chipset/i) != -1 ) 				type[y]='chipset';
		else if ( file_name[y].search(/bluetooth/i) != -1 ) 			type[y]='bluetooth';
		else if ( file_name[y].search(/graphics|video/i) != -1 ) 		type[y]='video';
		else if ( file_name[y].search(/wlan/i) != -1 ) 					type[y]='wifi';
		else if ( file_name[y].search(/lan/i) != -1 ) 					type[y]='lan';
		else if ( file_name[y].search(/massstorage|masstorage/i) != -1 ) type[y]='massstorage';
		else if ( file_name[y].search(/broadband|modem/i) != -1 ) 		type[y]='modem';
		else if ( file_name[y].search(/webcam/i) != -1 ) 				type[y]='webcamera';
		else if ( file_name[y].search(/hid|touchpad|mouse|input/i) != -1 ) type[y]='inputdev';
		else if ( file_name[y].search(/cardreader/i) != -1 ) 			type[y]='cardreader';
		else if ( file_name[y].search(/cpu/i) != -1 ) 					type[y]='cpu';
		else if ( file_name[y].search(/monitor/i) != -1 )				type[y]='monitor';
		else if ( file_name[y].search(/printer/i) != -1 )				type[y]='printer';
		else if ( file_name[y].search(/scanner/i) != -1 ) 				type[y]='scaner';
		else if ( file_name[y].search(/usb/i) != -1 ) 					type[y]='usb';
		else type[y]='other';
	}
	count = y;
	
	sizeUpdate();
}



$(document).ready(function() {
	$(".checklist .checkbox-select").click(
		function(event) {
			event.preventDefault();
			$(this).parent().addClass("selected");
			$(this).parent().find(":checkbox").attr("checked","checked");
			sizeUpdate();
			return false;
		}
	);
	
	$(".checklist .checkbox-deselect").click(
		function(event) {
			event.preventDefault();
			$(this).parent().removeClass("selected");
			$(this).parent().find(":checkbox").removeAttr("checked");
			sizeUpdate();
			return false;
		}
	);
	
	$(".devices label").click(
		function(event) {
			notCheck = true;
			sizeUpdate(true);
		}
	);

});


function init() {
    MakeWizard();
    sizeUpdate();
}
window.onload = init;
