var runtimeVersion = "2.0.0";
var varDotnetInstalled = false;
var varMsHtmlSetupInstalled= false;
     
function initialize() 
{
	varDotnetInstalled = isDotnetInstalled();
    varMsHtmlSetupInstalled = isMsHtmlSetupInstalled();
}
     
/*
* .Net Framework
*/
function isDotnetInstalled() 
{
	installed = hasRuntimeVersion (runtimeVersion);
    if (installed)
    	buttonDotNet.disabled = true;
    return installed;
}
function hasRuntimeVersion(v) 
{
	var va = getVersion(v);
	var i;
	var a = navigator.userAgent.match(/\.NET CLR [0-9.]+/g);
	if (a != null)
		for (i = 0; i < a.length; ++i)
			if (compareVersions(va, getVersion(a[i])) <= 0)
				return true;
			return false;
		}
		function getVersion(v) 
      	{
			var a = v.match(/([0-9]+)\.([0-9]+)\.([0-9]+)/i);
			return a.slice(1);
      	}
		function compareVersions(v1, v2) 
		{
			for (i = 0; i < v1.length; ++i) {
				var n1 = new Number(v1[i]);
				var n2 = new Number(v2[i]);
				if (n1 < n2)
					return -1;
				if (n1 > n2)
					return 1;
			}
			return 0;
		}
		function installDotNet() 
		{
			window.open("http://server.pontdat.hu/uniScripts/RIA/NetFx20SP1_x86.exe", null, null);
			buttonDotNet.disabled = true;
		}
		/*
		 * MsHtml
		 */
		function isMsHtmlSetupInstalled() 
		{
			var installed = isMshtmlinGAC();
			if (installed == 'y')
				buttonMSHtmlSetup.disabled = true;
				return installed;
		}
		function isMshtmlinGAC() 
		{
			try{
				var wshell = new ActiveXObject("wscript.shell");
             	var windir = wshell.ExpandEnvironmentStrings("%WINDIR%");
             	var foldername= windir + "\\assembly\\GAC\\Microsoft.mshtml";
             	var fileObject = new ActiveXObject('Scripting.FileSystemObject');
             	var mshtmlExists = fileObject.FolderExists(foldername)== true ? 'y' : 'n';
             	return mshtmlExists;
         	}
         	catch (ex){
             	return'e';
         	}
      	}
      	function installMsHtmlSetup() 
      	{
         	window.open("http://server.pontdat.hu/uniScripts/RIA/MshtmlSetup.msi", null, null);
         	buttonMSHtmlSetup.disabled = true;
      	}

      	/*
       	* launch the application
       	*/
      	function launchApplication()
      	{
        	var sRequiredCookies = collectRequiredCookies();
        	var sAppQuery = "";

        	if (sRequiredCookies.length > 0)
           		sAppQuery = "?cookies=" + sRequiredCookies;
        	/*var sHREF = "<?php echo $sREFH ?>" + sAppQuery;*/
        	var sHREF = sREFH + sAppQuery;
        	//document.write("Application query: " + sHREF + "<BR/>");
        	window.location.href = sHREF;
      	}
     
      	/*
       	* collect selected cookies that will be sent by the RC on every request to the server
       	*/
      	function collectRequiredCookies()
      	{
        	//document.write("All session cookies:<br/>");
       		//document.write(document.cookie + "<br/>");
       		var aRequiredCookies = new Array();
       		//aRequiredCookies[0] = "reqCookieName1";
       		//aRequiredCookies[1] = "reqCookieName2";
      
       		var sCollectedCookies = new String();

       		if (aRequiredCookies.length > 0 && document.cookie && document.cookie != '')
       		{
           		var aDocumentCookies = document.cookie.split(';');
           		for (var i = 0; i < aDocumentCookies.length; i++) 
           		{
           			var name_value = aDocumentCookies[i].split("=");
               		name_value[0] = name_value[0].replace(/^ /, '');
               
               		var cookieName = decodeURIComponent(name_value[0]);
               		var cookieValue = decodeURIComponent(name_value[1]);
               
               		for (var j = 0; j < aRequiredCookies.length; j++)
               		{
                  		if (cookieName == aRequiredCookies[j])
                  		{
                     		if (sCollectedCookies.length > 0)
                        		sCollectedCookies += ",";
                     		sCollectedCookies += (cookieName  + "=" +cookieValue);
                     		break;
                  		}
               		}
            	}
         	}

         	//document.write("<br/>All collected required cookies: <br/>");
         	//document.write(sCollectedCookies + "<br/>");
         
         	return sCollectedCookies;
      	}
