var octopvCAB_topobject = new Object();
octopvCAB_topobject.onComplete=null;


function octopv_canDoCabInstall(){
	var userAgent = navigator.userAgent.toLowerCase();
	function thisIs(str){ return (userAgent.indexOf(str) != -1); }
	octopv_debug("Testing for cab. userAgent is: "+userAgent, arguments.callee);

	if(!thisIs("windows")){
		// not windows.
		octopv_debug("Can not do cab install since OS is not windows.", arguments.callee);
		return false;
	}
	
	if(!thisIs("msie")){
		// not explorer.
		octopv_debug("Can not do cab install since browser is not ie.", arguments.callee);
		return false;
	}

	// Temporarily disabled for all vista users.
	if(thisIs("windows nt 6.0")){
		// we have vista 
		octopv_debug("Can not do cab install since we are on vista. ", arguments.callee);
		return false;
	}

/*	
	if(thisIs("msie 7.0") && thisIs("windows nt 6.0")){
		// we have vista ie 7
		octopv_debug("Can not do cab install since we are on vista with ie 7.", arguments.callee);
		return false;
	}*/

	return true;
}

function octopv_doCabInstall(indiv, onComplete){
	octopvCAB_topobject.onComplete = onComplete;
	var variant = (typeof octoshapeVariant == 'string')?octoshapeVariant:""; 
	var html = '<OBJECT onreadystatechange="javascript:octopv_cabReadychange();" CODEBASE="http://www.octoshape.com/files/octosetup'+variant+'.cab#version=1.0.0.0" id="OctoshapeCabInstaller" CLASSID="CLSID:7D4733C0-C43B-4A81-AF43-F9B20D1F8348" width="0" height="0" >';
	html += '</OBJECT>';
	octopv_writeToDiv(indiv, html);
}

function octopv_cabReadychange(dontWait){
	try{
		var state = document.all["OctoshapeCabInstaller"].readyState;
		octopv_debug("Ready state changed to "+state, arguments.callee);
		if(state==4){
			if(octopvCAB_topobject.onComplete!=null){
				octopvCAB_topobject.onComplete();
			}
		}
	}catch(ex){
		if(typeof dontWait == 'boolean' && !dontWait){
			octopv_debug("Ready state not defined: "+ex, arguments.callee);
			// If we do not report complete back here then we might end up in an 
			// error state where we never report back.
			if(octopvCAB_topobject.onComplete!=null){
				octopvCAB_topobject.onComplete();
			}
		}else{
			octopv_debug("Ready state not defined: "+ex+" trying to wait a little ... ", arguments.callee);
			window.setTimeout("octopv_cabReadychange(true);",500);
		}
	}
}



/************************** PRIVATE FUNCTIONS ***********************************/

window.octopv_fileInitInstallerCab=true; 

