<!--

/*
 * Test for browser type and redirect to 3D world
 * @param:
 *  <web>: url of regular webpage (IE) 
 *  <flyshell>: url of flyshell (Firefox or Flock)
 */
function testBrowserAndGoTo3D(project,main_page){
    var web = "http://www.3D.GeoID.be/" + project + "/" + main_page;
    var flyshell = "http://www.3D.GeoID.be/" + project + "/" + "3D.flyshell";
    //alert("test browser en TE");
    var other = false;
    var nAgt = navigator.userAgent;
	var browsername;
	if ((nAgt.indexOf("MSIE"))!=-1) {
		 browserName  = "Microsoft Internet Explorer";
	}
	/*else if ((nAgt.indexOf("Opera"))!=-1) {
		browserName  = "Opera";
		//browserName  = "Microsoft Internet Explorer";
		//alert("Sorry! This application is not supported for your Opera browser. Use Firefox, Flock or Internet Explorer instead.");
		//window.location.href = flyshell;
		//window.location.href = "http://www.3D.GeoID.be/viralGame/test.aspx";
		//return 0;
	}*/
	else if ((nAgt.indexOf("Flock"))!=-1) {
		browserName  = "Flock";
	}
	/*else if ((nAgt.indexOf("Safari"))!=-1) {
		browserName  = "Safari";
		alert("Sorry! This application is not supported for your Safari browser. Use Firefox, Flock or Internet Explorer instead.");
		return 0;
	}*/
	else if ((nAgt.indexOf("Firefox"))!=-1) {
		browserName  = "Firefox";
	}
	else{
	    other = true;
	}
	if(!other){ // IE, FF or Fock => detecterTE can be used
	    if (!detecterTE()) alert("Please install the plugin. Click on GetTerraExplorer!"); 
	    else{
	         var name = navigator.appName;
		     if (name == "Microsoft Internet Explorer"){
		     //if ((name == "Microsoft Internet Explorer") || (browserName == "Microsoft Internet Explorer")){
		       PageMethods.goTo3D(web,onSuccess, onFailure);
               function onSuccess(result) {
               
                   //go to the new location (random string added)
                   window.location.href = String(result);
               }
               function onFailure(error) {
                   alert(error);
               }
		     } 
		     else if (browserName == "Firefox" || browserName == "Flock") window.location.href = flyshell;
	    }
	  }
	  else{ // other browser than IE, FF or Fock => 
    	    //window.location.href = "http://www.3D.GeoID.be/demosite/3D.aspx" + "?qstr=" + project + "/" + main_page;
    	    //window.location.href = flyshell;
    	    alert("Sorry, this application is not supported by your browser. Use Firefox, Flock or Internet Explorer instead.");

	  }
}

/*
 * Immediately redirect to <url>
 * This method is useful when the site <url> performs already the browser check, e.g. "./viralGame/welcome.aspx"
 */
function go2URL(url){
	window.location.href = url;
}
	

/////////////////////////////////////////////////////////////////////////////
//
//	DetectTE - help detecting if TerraExplorer is installed
//
//	The 'version' parameter indicate if we are interested to know if a specific
//  version of TerraExplorer is installed.
//
//  Usage:
//  ------------------------------------------------------
//
//  if (DetectTE("5.0.0"))
//		alert("TerraExplorer version 5.0.0 is installed");
//
//  ------------------------------------------------------
//
//  if (DetectTE(""))
//		alert("TerraExplorer installed");
//
/////////////////////////////////////////////////////////////////////////////
function DetectTE(version1,version2)
{
	var agent = navigator.userAgent.toLowerCase();

	if ( agent.indexOf('msie') != -1 && agent.indexOf('win') != -1 )
		return DetectTEOnIE(version1,version2);
	else
		return DetectTEMisc(version1,version2);
}

function DetectTEMisc(version1,version2)
{
	var appSkyline = "application/Skyline.TerraExplorer";
	var appSkylineb = "application/Skyline.TerraExplorer";
	var mimetype = navigator.mimeTypes[appSkyline];
 //if (navigator.plugins["Shockwave Flash"]) alert("installed");
 
	if (mimetype == undefined || mimetype == "")
		return 0;
	if (version1 == undefined || version1 == "" || version2 == undefined || version2 == "")
		return 1;
	appSkyline = appSkyline + "." + version1;

	mimetype = navigator.mimeTypes[appSkyline];

	if (mimetype == undefined || mimetype == "")
	{	appSkylineb = appSkylineb + "." + version2;

		mimetype = navigator.mimeTypes[appSkylineb];
		if (mimetype == undefined || mimetype == "")
			{return 0;}
	}

	return 1;
}

function DetectTEOnIE(version1,version2)
{
	try
	{
		var TETester = new ActiveXObject("TEDetect.TETest");

		if (TETester == undefined)
			return 0;

		if (TETester.Type == "NA")
			return 0;	// An installation exist but needs to be "repaired"

		if (version1 == undefined || version1 == "" || version2 == undefined || version2 == "")
			return 1;

		var ExistingVer;
		ExistingVer = TETester.Major + "." + TETester.Minor + "." + TETester.Build;

		if ((version1 != ExistingVer) &&  (version2 != ExistingVer))
			return 0;
	}
	catch(err)
	{
		return 0;
	}

	return 1;
}

function detecterTE()
{	return DetectTE("6.0.0","6.0.1");
}

function abspath()
{
	var abspath = unescape(window.location.href);
	index=abspath.lastIndexOf("/");
	abspath = abspath.substring(0,index);

	if(abspath.substring(0,1) == "/")
		abspath = abspath.substring(1,abspath.length)

	for (var i=abspath.length-1; i>=0; i--)
	{
	  if (abspath.substring(i,i+1) == "\\")
	  {
		 abspath = abspath.substring(0,i);
		 break;
	  }
	}

        return(abspath);

}




// -->


