var title = "XpressConnect by Cloudpath Networks"
var productName = "XpressConnect"
var signer = "Cloudpath Networks, Inc."

var url = location.protocol + "//" + location.host + location.pathname;
if (url.lastIndexOf('/') >= 0) {
   url = url.substring(0, url.lastIndexOf('/') + 1);
}
var productFriendlyName = "Network Wizard"


function getPageName()
{
  var sPath = window.location.pathname;
  var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
  sPage = sPage.substring(0, sPage.lastIndexOf('.'));
  return sPage;
}

function doOnLoad()
{
  var sPage = getPageName();
  if (sPage == "page1") {
    checkEula();
  } else if (sPage == "page2") {
    // Do nothing.
  } else if (sPage == "page3") {
    // This catches the situation where there is no java.  Typically, this would be
    // caught by the javascript in the page3.html file.  So, we can sleep a bit without
    // affecting most people.  If this time is to short, a newly initializing java install
    // will fail.
    setTimeout('testJava()', 800);
  } else if (sPage == "page4_applet") {
    showHelp();
  } else if (sPage == "page4_activex_inner") {
    // Do nothing.
  } else if (sPage == "page4_download") {
    // Do Nothing.
  } else if (sPage == "page5") {
    // Do Nothing.
  }
}

function doEndOfBody()
{
  var sPage = getPageName();
  if (sPage == "page1") {
    checkEula();
  } else if (sPage == "page2") {
    // Do Nothing.
  } else if (sPage == "page3") {
    // Do Nothing.
  } else if (sPage == "page4_applet") {
    // Do Nothing.
  } else if (sPage == "page4_activex_inner") {
    try {
     	xc.wasSuccessful();
     	// Control is running
      hide('howto_table');
    } catch (e) {
      // Control is not running.
    }
  } else if (sPage == "page4_javaws") {
    // Thread off the redirect so that html loads completely.
    setTimeout('gotoWebstart()', 500);
  } else if (sPage == "page4_download") {
    // Do Nothing.
  } else if (sPage == "page5") {
    // Do Nothing.
  }
}	
	
/* PAGE 1 SCRIPTS */
function checkEula() { 
  try {
    var x = document.getElementById('button-large');
    if (x != null) {
      x.href='page3.html';
    }

    if (document.getElementById('eula') == null || document.getElementById('eula').checked) {
      var button = document.getElementById('button-disabled');
    	if (button != null) {
        button.id = 'button-large';
        button.href = 'page3.html';
    	}
    } else {
      var button = document.getElementById('button-large');
      if (button != null) {
        button.id = 'button-disabled';
        button.href = '#';
    	}
    }
  } catch (e) {
  }
}		


/* PAGE 3 SCRIPTS */
function testJava()
{
  var javaUsable = false;
  var wasRedirected = false;
  try {
    wasRedirected = detection.wasRedirected();
    status = "Java is usable.";
  } catch (e) {
    javaUsable = false;      
    wasRedirected = false;
    status = "Java is not usable.";
  }
	
  if (wasRedirected) { 
    // Nothing to do.  User was redirected. 
  } else if (javaUsable) {
    // User has java and needs redirected.
    document.location.href="page4_applet.html";
  } else if (navigator.appName.indexOf('Microsoft') >= 0) {
    // No java but windows, so let's try activeX.
    document.location.href="page4_activex.html";
  } else {
    // No java and not windows, so tell user to download.
    document.location.href="page4_download.html?no_java=1&no_activex=1";
  }
}

function skipJavaTest()
{
   if (navigator.appName.indexOf('Microsoft') >= 0) {
      // No java but windows, so let's try activeX.
      document.location.href="page4_activex.html";
   } else {
      // No java and not windows, so tell user to download.
      document.location.href="page4_download.html";
   }   
}

/* PAGE 4 APPLET SCRIPTS */
var errorDisplayed = false;
var appletResponded = false;

// Also uses by activex.
function show(tableName) 
{ 
	 document.getElementById(tableName).style.display = '';
} 

// Also uses by activex.
function hide(tableName) 
{ 
	 document.getElementById(tableName).style.display = 'none'; 
} 

function createLoading()
{
	 createTable("Step 2: " + productName + " is loading...", 
		"<table width='100%' cellpadding='4' cellspacing='0' ><tr><td style='height:10px;'></td></tr><tr><td><ol style='font-family: verdana; font-size: 8pt;'><li>A form should automatically display similar to the image below.</li><li>When prompted, verify that the publisher is '<b>" + signer + "</b>'.</li><li>Click '<b>Run</b>'.</li></font></ol></td></tr><tr><td align='center'><img src='images/JavaSecurityPopup.jpg'/></td></tr><tr style='height:10px;'><td></td></tr></table><table width='100%' cellpadding='0' cellspacing='0'>  <tr id='line'><td></td></tr><tr bgcolor='CCCCCC'><td width='100%'><img width='100%' height='15' src='images/MovingStatus.gif'/></td></tr><tr id='line'><td></td></tr><tr style='height: 10px;'><td></td></tr><tr><td style='font-family: verdana; font-size: 8pt;'>If the form does not display or you prefer not to use the Java Applet, click here to go to the <a href='page4_download.html?cancel_java=1'>manual download page.</a></td></tr></table>", 
		"000066", "inner_loading_table");
}

// Also uses by activex.
function createTable(title, message, borderColor, tableName, display)
{
	if (display == null || display == '') {
		display='block';
	}	
	document.write("<table style='display:" + display + ";' id='" + tableName + "' cellpadding=0 cellspacing=0 width='100%'><tr><td>");    	
	document.write(message);
	document.write("</td></tr></table>");
//	document.getElementById("title").innerHTML = title;
}

function permissionDenied()
{
	 appletResponded=true;
	 show("header_info");
	 hide('title');
	 hide('xc');
	 document.getElementById("header_info").innerHTML="<br/><img src='images/Error.gif'/>&nbsp;<font id='error'>" + productName + " was not granted permission to execute.  If you clicked 'Cancel' on the popup form, you will need to close the browser to try again.  Please close the browser and try again.  </font><br/><br/><font id='title'>To manually install " + productName + ", <a href='page4_download.html?cancel_java=1'>click here.</a></font>";
}

function permissionGranted()
{
		appletResponded=true;
		hide('header_info');
}

function done(successful)
{
	// This is called when the applet completes.
	try {
		if (successful) {
			document.location = "page5.html";
		} else {
			document.location = "page4_download.html?java_failed=1";
		}
	} catch (e) { 
		if (errorDisplayed) {
			// That's ok.  This is handled by the contents of the object tag.
		} else {
			document.location = "page4_download.html?java_failed=2";
		}
	}
}

function showHelp()
{
	if (appletResponded == false) {
		show('header_info');
	}
}

/** PAGE 4 ACTIVEX SCRIPTS */
function getServerUrl()
{
	if (location.href.lastIndexOf('/') >= 0) {
		lastSlash=location.href.lastIndexOf('/')+1;
		return location.href.substring(0, lastSlash);
	} else {
		return location.href;
	}
}

// Also uses show()
// Also uses hide(name);

function createUnsupportedBrowserActivex()
{
	 window.location='page4_download.html?no_activex=1';
}

function createHowToActivex()
{
		createTable("Activating " + productName + " is easy...", 
		"<table width='100%' cellpadding='4' cellspacing='0' >" + 
			"<tr><td><ol style='font-family: verdana; font-size: 8pt;'><li>Click on the information bar and select '<b>Install ActiveX Control...</b>'</li><font color='999999'><li>When prompted, verify that the publisher is '<b>" + signer + "</b>'.</li><li>Click '<b>Install</b>'.</li><li>The control will open within a few moments.</li></ol></td></tr><tr><td><img src='images/ActivexPrompt.jpg'/></td></tr><tr style='height=10px;'><td></td></tr><tr><td><ul style='font-family: verdana; font-size: 8pt;'><li>If the information bar is not visible, click <a href='?now=" + new Date().getTime() + "'>'<b>Refresh</b>'</a>.</li><li>If the information bar still does not display or you prefer not to use the ActiveX control, click here to go to the <a href='page4_download.html?cancel_activex=1'>manual download page.</a></li></ul></td></tr></table>", "000066", "howto_table", "");
}

function startActivex()
{
  try {
    xc.setServerUrl(getServerUrl());
    xc.setIpAddress(getCurrentIp());
    errorDisplayed = false;
    hide("howto_table");
    xc.height = 140;
    document.getElementById("ActivexDiv").style.visibility="visible";
    setTimeout('startActivex2()', 0);
  } catch (e) {
	setTimeout('startActivex()', 200);
  }
}

function startActivex2()
{
  xc.start();

  show('continue');
  if (xc.wasSuccessful()) {
    window.location = "page5.html";
  } else {
    window.location = "page4_download.html?activex_failed=1";
  }
}


function permissionGrantedActivex()
{
	appletResponded=true;
}

function doneActivex()
{
}

function gotoWebstart()
{
  window.location="page4_webstart.php";
}

/* PluginDetect v0.1.6 by Eric Gerds */ 
var PluginDetect={minIEver:5.5,getNum:function(A){if(!A){return null}var m=/[\d][\d\.\_,-]*/.exec(A);return m?m[0].replace(/[\.\_-]/g,","):null},hasMimeType:function(_3){var s,t,z,M=_3.constructor==String?[_3]:_3;for(z=0;z<M.length;z++){s=navigator.mimeTypes[M[z]];if(s&&s.enabledPlugin){t=s.enabledPlugin;if(t.name||t.description){return s}}}return null},findNavPlugin:function(N,_6){var _7=N.constructor==String?N:N.join(".*"),numS=_6===false?"":"\\d";var i,re=new RegExp(_7+".*"+numS+"|"+numS+".*"+_7,"i");var _9=navigator.plugins;for(i=0;i<_9.length;i++){if(re.test(_9[i].description)||re.test(_9[i].name)){return _9[i]}}return null},getAXO:function(_a){var _b,e;try{_b=new ActiveXObject(_a);return _b}catch(e){}return null},num:function(A){return (typeof A!="string"?false:(/\d/).test(A))},compareNums:function(_d,_e){if(!this.num(_d)||!this.num(_e)){return 0}var m1=_d.split(","),m2=_e.split(","),x,p=parseInt;for(x=0;x<m1.length;x++){if(p(m1[x],10)>p(m2[x],10)){return 1}if(p(m1[x],10)<p(m2[x],10)){return -1}}return 0},formatNum:function(num){if(!this.num(num)){return null}var n=num.replace(/[\.\_]/g,","),i;n=n.split(",").concat(["0","0","0","0"]);return n.slice(0,4).join(",")},initScript:function(){var $=this,IE;$.reload=1;$.isIE=(/*@cc_on!@*/false);$.IEver=-1;if($.isIE){var IE=(/msie\s*\d\.{0,1}\d*/i).exec(navigator.userAgent),progid,x;if(IE){$.IEver=parseFloat((/\d.{0,1}\d*/i).exec(IE[0]),10)}progid=["ShockwaveFlash.ShockwaveFlash","Msxml2.XMLHTTP","Microsoft.XMLDOM","Msxml2.DOMDocument","TDCCtl.TDCCtl","Shell.UIHelper","Scripting.Dictionary"];$.ActiveXEnabled=false;for(x=0;x<progid.length;x++){if($.getAXO(progid[x])){$.ActiveXEnabled=true;break}}};if($.ActiveXEnabled&&$.IEver>=$.minIEver){$.head=document.getElementsByTagName("head")[0];var T=document.createElement("script");T.setAttribute("type","text/vbscript");var Y=["<!"+"--","function PluginDetect1(c)","on error resume next","PluginDetect1=false","dim head, r","set head=PluginDetect.head","set r=head.firstChild","if TypeName(r)=\"HTMLObjectElement\" then","r.setAttribute \"classid\", c","if not TypeName(r.getAttribute(\"object\")) = \"Nothing\" then","PluginDetect1=true","if r.getAttribute(\"readyState\")<4 then","r.clearAttributes()","head.removeChild(r)","end if","else r.clearAttributes()","head.removeChild(r)","end if","end if","r=\"Nothing\"","head=\"Nothing\"","end function","--"+">"];T.setAttribute("text",Y.join("\n"));if($.head.firstChild){$.head.insertBefore(T,$.head.firstChild)}else{$.head.appendChild(T)}$.vbscript=false;var e;$.head.insertBefore(document.createElement("object"),$.head.firstChild);try{if(PluginDetect1("")===false){$.vbscript=true}}catch(e){}}},init:function(_17){var $=this,IE,p;_17=_17.toLowerCase().replace(/\s/g,"");p=$.plugin=$[_17];if(!p){return -3}if(typeof p.minversion=="undefined"){p.minversion={}}if(typeof p.version=="undefined"){p.version=null}if(typeof p.installed=="undefined"){p.installed=null}$.garbage=false;if($.isIE&&!$.ActiveXEnabled){return -2}return 1},isMinVersion:function(_19,_1a){var $=PluginDetect,i=$.init(_19);if(i<0){return i}if(!$.num(_1a)){return -3}var p=$.plugin,m=p.minversion;_1a=$.formatNum(_1a);if(typeof m["a"+_1a]=="undefined"){if(p.installed==null&&p.getCodeBaseVersion&&$.IEver>=p.minIEver){var tmp,x;for(x in m){tmp=$.compareNums(_1a,x.substring(1,x.length));if(m[x]==1&&tmp<=0){return 1}if(m[x]==-1&&tmp>=0){return -1}}m["a"+_1a]=$.isActiveXObject(_1a)?1:-1}else{if(p.installed==null){p.getVersion()}if(p.installed==-1){m["a"+_1a]=-1}else{if(p.version==null){m["a"+_1a]=0}else{m["a"+_1a]=($.compareNums(p.version,_1a)>=0?1:-1)}}}}$.cleanup();return m["a"+_1a];return -3},getVersion:function(_1e){return null},cleanup:function(){var $=this;if($.garbage&&typeof window.CollectGarbage!="undefined"){window.CollectGarbage()}},isActiveXObject:function(_22){var $=this,result,s="<object width=\"1\" height=\"1\" "+"style=\"display:none\" "+$.plugin.getCodeBaseVersion(_22)+">"+$.plugin.HTML+"</object>";$.head.insertBefore(document.createElement("object"),$.head.firstChild);$.head.firstChild.outerHTML=s;result=$.vbscript?PluginDetect1($.plugin.classID):$.detect($.plugin.classID);return result},detect:function(_24){var $=this,result;$.head.firstChild.setAttribute("classid",_24);result=$.head.firstChild.getAttribute("object")?true:false;if(!result||$.head.firstChild.getAttribute("readyState")<4){$.head.firstChild.clearAttributes();$.head.removeChild($.head.firstChild);$.garbage=true}return result},search:function(){},dummy1:0};PluginDetect.initScript();PluginDetect.java={mimeType:"application/x-java-applet",classID:"clsid:8AD9C840-044E-11D1-B3E9-00805F499D93",JavaVersions:["1.7.0.15","1.6.0.15","1.5.0.12","1.4.2.13","1.3.1.18"],searchJava:function(M){if(!M){return null}var G,e,x3,x4;var AXO=ActiveXObject;var T=M.split("."),J="JavaPlugin."+T[0]+T[1],v=T[0]+"."+T[1]+".";for(x3=T[2];x3>=0;x3--){for(x4=T[3];x4>=0;x4--){G=x4<10?"0"+x4:x4;try{new AXO(J+x3+"_"+G);return v+x3+"_"+G}catch(e){}}if(J+x3=="JavaPlugin.131"){return null}try{new AXO(J+x3);return v+x3}catch(e){}}return null},minIEver:5.5,HTML:"<param name=\"code\" value=\"A14999.class\" />",getCodeBaseVersion:function(v){var r=this.getDigits(v),$=PluginDetect;if($.compareNums(v,"1,4,1,02")<0){v=r[0]+","+r[1]+","+r[2]+","+r[3]}else{if($.compareNums(v,"1,5,0,02")<0){v=r[0]+","+r[1]+","+r[2]+","+r[3]+"0"}else{v=Math.round((parseFloat(r[0]+"."+r[1],10)-1.5)*10+5)+","+r[2]+","+r[3]+"0"+",0"}}return "codebase=\"#version="+v+"\""},digits:[1,9,32,32],getDigits:function(n){/([\d]+)[,_\.]([\d]+)[,_\.]([\d]+)[,_\.]([\d]+)/.test(n);return [RegExp.$1,RegExp.$2,RegExp.$3,RegExp.$4]},queryJava:function(){var $=PluginDetect,nav=navigator.userAgent,j=window.java,e;if(!/firefox/i.test(nav)||($.hasMimeType("application/x-java-vm")&&navigator.javaEnabled())){if(!/PluginDetect=reload/.test(window.location.search)&&typeof j!="undefined"&&typeof j.lang!="undefined"){if($.reload==1&&/mac/i.test(nav)&&/ppc/i.test(nav)&&/firefox/i.test(nav)){setTimeout("if(PluginDetect.reload==1)window.location.replace(window.location.href+(/\\?/.test(window.location.search)?\"\":\"?\")+\"PluginDetect=reload&\")",100)}if(typeof j.lang.System!="undefined"){$.reload=0;return (j.lang.System.getProperty("java.version")+" ")}$.reload=0}}return null},getVersion:function(){var _38=null,$=PluginDetect;if(!$.isIE){var p1,p,mt;p=$.findNavPlugin(["Java","Plug-in"]);mt=$.hasMimeType(this.mimeType);if(p){p1=$.getNum(p.description)}if(p1&&mt&&navigator.javaEnabled()){_38=p1}if(!_38){p=this.queryJava();if(p){_38=p}}this.installed=-1;if(_38){this.installed=1}else{if(/macintosh/i.test(navigator.userAgent)&&/safari/i.test(navigator.userAgent)&&mt&&navigator.javaEnabled()){this.installed=0}}}else{var x,tmp=null;if($.IEver>=this.minIEver){_38=$.search();this.installed=_38?1:-1}else{for(x=0;x<this.JavaVersions.length;x++){tmp=this.searchJava(this.JavaVersions[x]);if(tmp){_38=tmp;break}}this.installed=_38?1:($.getAXO("JavaPlugin")?0:-1)}}this.version=$.formatNum($.getNum(_38))}};

function getParameterValue( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
