/*
Name: 
	testMsxml3Sp2
	test code based on document found at
	http:support.microsoft.com/default.aspx?scid=kb;[LN];Q308563
Purpose:
	Test if client has Msxml3 Sp2 installed
	Returns true if the client has Msxml3 Sp2
	Returns false if the client doesn't have Msxml3 Sp2.
	Returns false if it fails to instantiate Msxml3 object.
*/
function testMsxml3Sp2()
{
	try{

		var xmldoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
		xmldoc.async = false;
		xmldoc.validateOnParse = false;
		xmldoc.load("xml/test.xml"); // test.xml and external.xml must be in current folder.
		if(xmldoc.parseError.errorCode != 0){
			 // xmlload failed.
			 //alert("failed to load xml");
			 return false;
		}

		var nodeTest = xmldoc.documentElement.selectSingleNode("ExternalElement");

	
		if(nodeTest){
			return true; // Sp2 installed
		}
		else{
			// no node is returned with the MSXML 3.0 parser. 
			return false; // Sp2 not installed
		}
	}
	catch(e)
	{
		// assume that it failed to instantiate Msxml3 dom document
		return false;
	}
}

/*
Name:
	IsFirstTimeInstall

Purpose:
	To determine if this is the machine's first time
	installation

Return value:
	true if this is the first time installation.
	Otherwise, false.
*/

function IsFirstTimeInstall()
{
	top.SDKInstall.ClearError();
	var strLocation = top.SDKInstall.InstallLocation;
	var strError = top.SDKInstall.Error;
	top.SDKInstall.ClearError();

	if("Not Set" == strError)
	{
		return true;
	}else{
		return false;	
	}
}

/*	
-------------------------------------------------------
Name:
	getBuildNumber

Description:
	Retrieves the build number from version.xml
	If failed, it returns "NA".
	Otherwise, it returns the build number.
	
Parameters:
	None

Return Value:	
	the build number
-------------------------------------------------------		
*/
function getBuildNumber()
{
	var oNode = null;

	try{

		xmlVersion = new ActiveXObject("Microsoft.XMLDOM");
		xmlVersion.async = false;
		xmlVersion.load("xml/version.xml");

		oNode = xmlVersion.selectSingleNode("//SDKBuildInfo/BuildNumber");

	}
	catch(e){}

	return (oNode)? oNode.text : "NA";
}

function getBuildNumberFull()
{
	var oNode = null;

	try{

		xmlVersion = new ActiveXObject("Microsoft.XMLDOM");
		xmlVersion.async = false;
		xmlVersion.load("xml/version.xml");

		oNode = xmlVersion.selectSingleNode("//SDKBuildInfo/BuildNumberFull");
	}
	catch(e){}

	return (oNode)? oNode.text : "NA";
}

/*	
-------------------------------------------------------
Name:
	checkControl

Description:
	Checks that the SDK Update Control has been created.  
	If not, navigates to a page which explains that they 
	need the control installed in order to view this page.  
	
Parameters:
	None

Return Value:	
	None
-------------------------------------------------------		
*/
function checkControl()
{
	if( (top.SDKInstall == null) || (top.Versions == null) )
	{
		window.navigate('nocontrol.htm');
	}
}

/*	
-------------------------------------------------------
Name:
	onWeb

Description:
	Returns a boolean value indicating whether the page is 
	begin served from the Web or as the result of a file 
	open.  
	
Parameters:
	None

Return Value:	
	Boolean
-------------------------------------------------------		
*/
function onWeb()
{
	if(document.location.protocol=='http:')
	{
		return true;
	}
	else
	{
		return false;
	}
}

/*	
-------------------------------------------------------
Name:
	onTest

Description:
	Returns a boolean value indicating whether the page is 
	begin served from a test web site. 
	
Parameters:
	None

Return Value:	
	Boolean
-------------------------------------------------------		
*/
function onTest()
{
	if(document.location.href.indexOf('microsoft.com')== -1)
	{
		return true;
	}
	else
	{
		return false;
	}
}


/*	
-------------------------------------------------------
Name:
	gotoSDKInfo

Description:
	Opens the info page for the named SDK
	
Parameters:
	strKeyword - keyword for the SDK home page to open

Return Value:	
	None
-------------------------------------------------------		
*/
function gotoSDKInfo(strKeyword)
{
	top.strSDK=strKeyword;
	window.navigate('sdkinfo.htm');
}

/*	
-------------------------------------------------------
Name:
	displayError

Description:
	Displays an error to the user
	
Parameters:
	strError - the error to display

Return Value:	
	None
-------------------------------------------------------		
*/
function displayError(strError)
{
		
	if(top.SDKInstall != null && strError.length == 0)
	{
		if(top.SDKInstall.Error.length > 0)
		{
			strError = top.SDKInstall.Error;
			top.SDKInstall.ClearError();
		}
	}	

	if (strError.length > 0)
		alert(strError);
	else
		alert('Empty error string')	

}

/*	
-------------------------------------------------------
Name:
	is64Bit

Description:
	Returns a boolean value indicating whether the machine
	running the install is 64-bit.  
	
Parameters:
	None

Return Value:	
	Boolean
-------------------------------------------------------		
*/
function is64Bit()
{
	if(navigator.userAgent.indexOf('Win64') > -1)
	{
		return true;
	}else{
		return false;	
	}	
}
