var yandexBar=true;
var startPack_load = false;
var pn=1, prog=[], cat=[], cmd1=[], cmd2=[];

try {
	if (fso.FileExists('programs\\settings.js')) { inc('programs\\settings.js'); startPack_load = true; }
	else { startPack_load = false; }
}
catch(e) { startPack_load = false; }
try {
	if (!fso.FileExists('tools\\yabar.msi')) { yandexBar = false; hideOrShow('yabar_inst_div',true); hideOrShow('yabar_start_div',true); hideOrShow('yabar_search_div',true); }
}
catch(e) { yandexBar = true; }


function yabar_install(){
	if (!yandexBar) { return; }
	var yabar_type = '';
	var yabar = false;

	if (document.getElementById('yabar_inst').checked) { yabar = true; }
	if (document.getElementById('yabar_start').checked){ yabar_type += 'YAHOMEPAGE="y" '; yabar = true; }
	if (document.getElementById('yabar_search').checked){ yabar_type += 'YAQSEARCH="y" '; yabar = true; }
	if ((!document.getElementById('yabar_inst').checked) && ((document.getElementById('yabar_start').checked) || (document.getElementById('yabar_search').checked))){ yabar_type += 'ILIGHT=1 '; yabar = true; }

	if (yabar){
		//alert('msiexec /i tools\\yabar.msi '+yabar_type+'VENDORSPECIFIC="'+version+'" /qn');
		//return false;
		WshShell.Run('msiexec /i tools\\yabar.msi '+yabar_type+'VENDORSPECIFIC="drp11" /qn',0,false);
	}
}


window.attachEvent('onload',startPack);
function startPack(){
	if (startPack_load) {
		var last_cat=null;
		var html='';
		for (i=1;i<prog.length;i++){
			if (fso.FileExists('programs\\'+cmd1[i])) {
				if (last_cat!=cat[i]) {
					if (last_cat!=null) { html+='</span></div>'; }
					html+='<div class="cat"><span>'+cat[i]+'<br>';
				}
				last_cat = cat[i];
			
				html+='<label><input type="checkbox" checked="" id="program'+i+'" /> '+prog[i]+'</label><br>';
			}
		}
		document.getElementById('catalog').innerHTML=html;
	}
}


function startPackRun(){
	yabar_install();
	if (!document.getElementById('StartPackChk').checked) { return; }
	
	
	var program_count = [];
	for (i=1;i<prog.length;i++){
		if (document.getElementById('program'+i).checked) { program_count[program_count.length] = i; }
	}
	if (program_count.length==0) { return; }
	
	infobar_runInstall('Начинаем установку программ',program_count.length);
	
	for (i=0;i<program_count.length;i++){
		WshShell.Run('programs\\'+cmd1[program_count[i]]+' '+cmd2[program_count[i]],1,true);
		prBarNext(i);
	}
}
