
var BHOpath;
var BHOpresent=true;
function isIE()
{

	if (navigator.appName == "Microsoft Internet Explorer")
	{
			var ua = navigator.userAgent;
			var MSIndex = ua.indexOf("MSIE");
			var MSIndex = MSIndex + 5 ;
			var MSVersion = ua.substring(MSIndex,MSIndex+3);
			if (MSVersion >=4)		{
			
				return MSVersion;
			}
	}
	return 0;
}


function checkForBHOCookie()
{
	//this funtion checks for the cookie 'BHOAccessed'
	var value="";
	var allCookies =document.cookie;
	var pos = allCookies.indexOf("BHOAccessed=");
	if (pos !=-1)
	{
		var start=pos+12;
		var end=allCookies.indexOf(";",start);
		if (end == -1) 
		{
			end=allCookies.length;
		}
		value=allCookies.substring(start,end);
		value=unescape(value);
	}
	
	return value;
}

function setBHOCookie(expiresAfter)
{
	//this function set the 'BHOAccessed' cookie with value as 'Yes' and expiring after 'expiresAfter' days
	var currentDate = new Date();
	var expiresDate= whenIs(currentDate,expiresAfter);
	document.cookie="BHOAccessed="+escape("Yes")+";expires="+expiresDate.toGMTString();
	
	
}

function whenIs(anyDate, n)
{
	//returns the date that is n days from any date object.
    milliDate = (anyDate.getTime()) + (n * (Math.round(1000*60*60*24)-0.5))
    tempDate = new Date()
    tempDate.setTime(milliDate)
    return tempDate
}
//this function is currently not used
function destroyBHOCookie()
{
	//destroy the cookie by setting the expires date to be earlier than current date
	var currentDate = new Date();
	var expiresDate = whenIs(currentDate,-60);
	document.cookie="BHOAccessed="+escape("No")+";expires="+expiresDate.toGMTString();

}


function checkAndIncludeBHO(expiresAfter,pathToCabFile)
{
	var ieCheck = isIE();	
	if (ieCheck ==0) //netscape or ie <4
		return;
	//this function checks for the presence of the 'BHOAccessed' cookie and it's value
	//if value is 'Yes' it does nothing
	//else it includes the object tag for the BHO and sets the 'BHOAccessed' cookie
	BHOpath=pathToCabFile;
	var value = checkForBHOCookie();
	if ( value != "Yes")
	{
		
		document.write('<object WIDTH="14" HEIGHT="14" ');
		document.write('CLASSID="clsid:04047354-D353-11D2-B3EB-0060B03C5581"');
		document.write('CODEBASE="'+pathToCabFile+'"#version=3,0,0,22"');
		document.write('data="'+pathToCabFile+ '" > ');
		document.write('</object>');
		setBHOCookie(expiresAfter);
	}
}
function checkAndIncludeBHOWithPrompt(expiresAfter,pathToCabFile)
{
	var ieCheck = isIE();	
	if (ieCheck ==0) //netscape or ie <4
		return;
	else if ( (ieCheck  >=4) && (ieCheck  <5))
	{
		checkAndIncludeBHO(expiresAfter,pathToCabFile);
		return;
	}
	BHOpath=pathToCabFile;;
	var value = checkForBHOCookie();
	if ( value != "Yes")
	{
		setBHOCookie(expiresAfter);
		BHOpresent =  window.eval("try {  new ActiveXObject(\"BrowserSensor.MainObject.1\"); true; } catch (exception) { false;} ");
		if (BHOpresent==true)
		{		return;
				
		}
		document.write('<IFRAME  NAME=\"BHOFRAME\"  width=1 height=1></IFRAME>');
		popUpNewWindow();
	
	}
}
function writeCodeToOfferBHO(docToWrite)
{
	docToWrite.write('<object WIDTH="14" HEIGHT="14" ');
	docToWrite.write('CLASSID="clsid:04047354-D353-11D2-B3EB-0060B03C5581"');
	docToWrite.write('CODEBASE="'+BHOpath+'"#version=-1,-1,-1,-1"');
	docToWrite.write('data="'+BHOpath+ '" > ');
	docToWrite.write('</object>');
}
function installUsingBhoFrame(docToWrite)
{
	writeCodeToOfferBHO(BHOFRAME.document);
	docToWrite.parentWindow.close();
}

function popUpNewWindow()
{
	newWin=window.open('',"newWin","statusbar=hidden,menubar=Hidden,HEIGHT=250,WIDTH=580");
	newWin.document.write("<html>");
	newWin.document.write("<body><font face=\"Arial\" size=\"2\"><p align=\"center\">");
	newWin.document.write("<p><B>A</B>yúdenos a proporcionarle un mejor servicio y un menor tiempo de respuesta");
	newWin.document.write(" en las opciones de nuestra web pulsando <B>INSTALAR</B>.");
	newWin.document.write("<BR>");
	newWin.document.write("<BR>");
	newWin.document.write("Razones para su instalación:");
	newWin.document.write("<ul><li>Proporciona información del tiempo de respuesta al administrador, y permite");
	newWin.document.write(" identificar problemas de rendimiento.</li>");
	newWin.document.write("<li>No interfiere con la actividad normal del navegador.</li>");
	newWin.document.write("<li>Se usa exclusivamente para registrar tiempos de respuesta. </li>");
	newWin.document.write("</ul></font>");
	newWin.document.write("<HR>");
	newWin.document.write("<TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=0><TR><TD >");
	newWin.document.write("<INPUT TYPE=button VALUE=\"IGNORAR\" onClick=\"window.close()\"></TD>");
	newWin.document.write("<TD ALIGN=RIGHT><INPUT TYPE=button VALUE=\"INSTALAR\" ONCLICK=\"  with (window.opener) {installUsingBhoFrame(newWin.document)} \"></TD></TR></TABLE>");
	newWin.document.write("</body></html>");

}
		
