// Detect OS
var colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem","WQL");
var enumItems = new Enumerator(colItems);
var objShell = new ActiveXObject("Shell.Application");
var fullpath1 = document.location.pathname;
var current_dir = fullpath1.substring(0,fullpath1.lastIndexOf('\\')+1);
var OSVersion = 5;
var OSVersionSP = 0;

for (; !enumItems.atEnd(); enumItems.moveNext()) {
	var OSfullName = enumItems.item().Caption;
	var objItem = OSfullName.toLowerCase();
	var OSServicePack = enumItems.item().CSDVersion;
	var OSVersionS=enumItems.item().Version.replace(/.\d\d.*/,"");
}

//if (objItem.indexOf("7") != "-1") {
//  alert(alert_win7notSupport);
//  window.close(); WScript.Sleep(1);
//}

switch(OSVersionS)
{
	case '5.1':OSVersion=5.1;break;
	case '6.0':OSVersion=6;break;
	case '6.1':OSVersion=6.1;break;
	case '6.2':OSVersion=6.2;break;
	case '6.3':OSVersion=6.3;break;
	default: OSVersion=5;

}

//ServicePack
try {
	if (OSServicePack.indexOf("Service Pack") != "-1") {
		OSServicePack = OSServicePack.replace(/Service Pack /i,"").replace('null','').replace('undefined','');
		OSVersionSP = parseInt(OSServicePack);
	}
}
catch (e) {}
//ServicePack

//Fix IE 9/10 bugs and Feature
winRun('reg add "HKCU\\Software\\Microsoft\\Internet Explorer\\Styles" /v "MaxScriptStatements" /t REG_DWORD /d 0xffffffff /f',true,'',true);
winRun('reg add "HKLM\\Software\\Microsoft\\Internet Explorer\\Styles" /v "MaxScriptStatements" /t REG_DWORD /d 0xffffffff /f',true,'',true);
winRun('reg add "HKCU\\SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_NINPUT_LEGACYMODE" /v "mshta.exe" /t REG_DWORD /d 0x00000000 /f',true,'',true); //Touch Screen enabled
winRun('reg add "HKCU\\SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_GPU_RENDERING" /v "mshta.exe" /t REG_DWORD /d 0x00000001 /f',true,'',true); //GPU rendering enabled


if (current_dir.substr(0,1) == "\\") {
	//Pass control to the launcher when running on the network
	if (OSVersion >= 6) {
		objShell.ShellExecute("DriverPackSolution.exe", "", 0 , "runas", 1);
	}
	else {
		WshShell.Run("DriverPackSolution.exe",0,false);
	}
	window.close();
}

/*
if ((OSVersion >= 6) && (OSVersion != 6.2)) {
	//ToDo: DRP should check admin rights
	//ToDo: In IE10 is not possible to get the command line, so you need to do through WMI. And do not check the condition on Windows to version IE.
	// Run as administrator
	if (dpa.commandLine.indexOf('Run') == "-1") {
		objShell.ShellExecute("tools\\mshta.exe", dpa.commandLine + " Run", 0 , "runas", 1);
		window.close();
	}
}
*/


//Modify function 'WshShell.Run'
//Can run x64 programms
function winRun(src,hideMode,wait,bit64,timeout,onComplete,onTimeout_call){
	//try {
		if (!src) { return false; }
		if (!hideMode) { hideMode=false; }
		if (!wait) { wait=false; }
		hideMode=(hideMode?'0':'1');
		wait=!(wait?false:true);

		if (bit64&&is64) {
			hideMode=true;
			wait=false;
			src = 'tools\\cmd64.exe /C '+src;
		}

		//alert(typeof(onComplete));
		if (typeof(onComplete)=='function') {
			if (hideMode=='1') { oExec = WshShell.Exec(src); }
			//else { oExec = WshShell.Exec('tools\\hstart'+(is64?'64':'')+'.exe /NOCONSOLE /WAIT "cscript.exe //nologo tools\\start.vbs "'+src+'" '+hideMode+' '+wait+'"'); }
			  else { oExec = WshShell.Exec('tools\\start.exe "'+current_dir+'" "'+src+'" "'+hideMode+'" "'+wait+'"'); }
			winRun_process(oExec,onComplete,timeout,onTimeout_call);
			return oExec;
		}
		else { return WshShell.Run(src,hideMode,wait); }
	//}
	//catch(e) { return false; }
}

function winRun_process(oExec,onComplete,timeout,onTimeout_call,count){
	if (!count) { count=1; }
	if (!timeout) { timeout=60; }

	if (oExec.Status=='0') {
		//Too long wait
		if (timeout<count){
			if (typeof(onTimeout_call)=='function') {
				onTimeout_call(oExec);
			}
			return;
		}

		//Waiting...
		setTimeout(function (){ winRun_process(oExec,onComplete,timeout,onTimeout_call,(count+1)) },1000);
	}
	else {
		//When the process is completed
		onComplete(oExec);
	}
}

function taskkill(PID){
	if (typeof(PID)=="number"){
		WshShell.Run("TASKKILL /T /F /PID "+PID,0,true);
	}
	else if (typeof(PID)=="string"){
		WshShell.Run("TASKKILL /T /F /im "+PID,0,true);
	}
}


//IE version
try {
	IEVers = RegRead('HKLM\\SOFTWARE\\Microsoft\\Internet Explorer\\Version').split('.');
	IEVers = parseInt(IEVers[0]);
	if (typeof(IEVers)!='number') { IEVers = 0; }
}catch(e) { IEVers = 0; }

try {
	if (IEVers==0){
		//Determined on the UserAgent
		var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(navigator.userAgent) != null) {
			IEVers = parseInt( RegExp.$1 );
		}
	}
}catch(e) { IEVers = 0; }

//Fix for IE10
try {
	if ((OSVersion>=6.2) && (IEVers < 10)) {
		IEVers = RegRead('HKLM\\SOFTWARE\\Microsoft\\Internet Explorer\\svcVersion').split('.');
		IEVers = parseInt(IEVers[0]);
		if (typeof(IEVers)!='number') { IEVers = 10; }
	}
}catch(e) { IEVers = 10; }
//Fix for IE10
//alert(IEVers);
//IE version

//JavaScript version
var JSVersion = ScriptEngine()+" "+ScriptEngineMajorVersion()+"."+ScriptEngineMinorVersion();
//alert(JSVersion);


var isTouch = (window.navigator.msMaxTouchPoints>0?true:false);
