﻿
function InsertFlashElement(file,width,height)
{
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,16,0" width="' + width + '" height="' + height + '" VIEWASTEXT>');
	document.write('<param name="movie" value="' + file + '">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="wmode" value="window">');
	document.write('<embed src="' + file + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '" wmode="window"></embed>');
	document.write('</object>');
}

function replaceContentInnerHTML(contentID,inerHTML,toParent)
{
	var content = document.getElementById(contentID);
	content.innerHTML = "";
	content.innerHTML = inerHTML;
}

function InsertPDF (file, width, height)
{
	document.write ('<object id="pdf" height="'+height+'" width="'+width+'" classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" viewastext>');
	document.write ('<param name="src" value="'+file+'">');
	document.write ('<embed src="'+file+'" height="'+height+'" width="'+width+'"></embed>');
	document.write ('</object>');
}

//New version for new popups
function PopupInsertPDF (file, width, height, id)
{
	var objHtml = '<object id="pdf" height="'+height+'" width="'+width+'" classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" viewastext>';
	objHtml += '<param name="src" value="'+file+'" />';
	objHtml += '<embed src="'+file+'" height="'+height+'" width="'+width+'"></embed>';
	objHtml += '</object>';
	var div = document.getElementById (id);
	if (div) { div.innerHTML = objHtml; }
}

function InsertMovie360 (file, width, height, plugin)
{
	document.write ('<object id=spv width="'+width+'" height="'+height+'" classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=10,0,0,0" viewastext>');
	document.write ('<param name=src value="'+plugin+'">');
	document.write ('<param name=swURL value="'+file+'">');
	document.write ('<param name=swStretchStyle value=stage>');
	document.write ('<param name="swRemote" value="swContextMenu=FALSE">');
	document.write ('<param name=progress value=true>');
	document.write ('<param name=logo value=false>');
	document.write ('<embed id=spv width="'+width+'" height="'+height+'" type="application/x-director" pluginspage="http://www.macromedia.com/shockwave/download/" src="'+plugin+'" swurl="'+file+'" swstretchstyle=stage swRemote="swContextMenu=FALSE" progress=FALSE logo=FALSE></embed>');
	document.write ('</object>');
}

//New version for new popups
function PopupInsertMovie360 (file, width, height, plugin, id)
{
	var objHtml = '<object id=spv width="'+width+'" height="'+height+'" classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=10,0,0,0" viewastext>';
	objHtml += '<param name=src value="'+plugin+'">';
	objHtml += '<param name=swURL value="'+file+'">';
	objHtml += '<param name=swStretchStyle value=stage>';
	objHtml += '<param name="swRemote" value="swContextMenu=FALSE">';
	objHtml += '<param name=progress value=true>';
	objHtml += '<param name=logo value=false>';
	objHtml += '<embed id=spv width="'+width+'" height="'+height+'" type="application/x-director" pluginspage="http://www.macromedia.com/shockwave/download/" src="'+plugin+'" swurl="'+file+'" swstretchstyle=stage swRemote="swContextMenu=FALSE" progress=FALSE logo=FALSE></embed>';
	objHtml += '</object>';
	var div = document.getElementById (id);
	if (div) { div.innerHTML = objHtml; }
}

function InsertAppletBPI (price)
{
	var detect = navigator.userAgent.toLowerCase();
	var windowsIE = (checkPlatform("msie", detect) && checkPlatform("win", detect));
	var java_installed = false; 
	
	price = "0" + price;
	
	if (location.href.indexOf("#JavaInstall") > -1)
	{			
		document.write (InstallJava(price));
	}
	else
	{		
		if (windowsIE) 
		{   
			document.write('<applet name="sim" codebase="http://rep.bancobpi.pt/applets/habit/" archive="habitSiteBPI.jar" code="simHabitacao.class" id="simHabitacao" width="680" height="70" >');
			document.write('<param name="cliente" value="casasapo"/>');
			document.write('<param name="financiamento" value="' + price + '"/>');
			document.write('<param name="ve" value="' + price + '"/>');
			document.write('<param name="prazo" value="40"/>');
			document.write('<param name="uselink" value="1"/>');
			document.write('<div id="initJava" class="texto">Não têm o JAVA instalado/activado.<br><span class="verde"><a href="#JavaInstall" onclick="document.getElementById(\'initJava\').innerHTML = InstallJava(' + price + ');">Clique aqui</a></span> para instalar/activar</div>');
			document.write('</applet>');
		}
		else
		{
			for (x = 0; x < navigator.plugins.length; x++) 
			{
				if (navigator.plugins[x].name.indexOf('Java(TM)') != -1) 
				{
					java_installed = true;
					break;
				}
			}
			
			if (java_installed)
			{
				document.write('<applet name="sim" codebase="http://rep.bancobpi.pt/applets/habit/" archive="habitSiteBPI.jar" code="simHabitacao.class" id="simHabitacao" width="680" height="70" >');
				document.write('<param name="cliente" value="casasapo"/>');
				document.write('<param name="financiamento" value="' + price + '"/>');
				document.write('<param name="ve" value="' + price + '"/>');
				document.write('<param name="prazo" value="40"/>');
				document.write('<param name="uselink" value="1"/>');
				document.write('</applet>');
			}
			else
			{
				document.write('<div id="initJava" style="width:100%; padding-left:7px;">Não têm o JAVA instalado/activado.<br><span class="verde"><a href="#JavaInstall" onclick="document.getElementById(\'initJava\').innerHTML = InstallJava(' + price + ');">Clique aqui</a></span> para instalar/activar</div>');
			}
		}
	}
}

function checkPlatform(string, detect)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

function InstallJava(price)
{
	return '<iframe src="/Plugins/AppletBPI.aspx?price=' + price + '" frameborder="0" width="680" height="70" scrolling="no"></iframe>';
}

function GetAppletBPI(price)
{	
	var detect = navigator.userAgent.toLowerCase();
	var windowsIE = (checkPlatform("msie", detect) && checkPlatform("win", detect));
	
	if (windowsIE) 
	{   
		// Internet Explorer
		document.write('<object name="sim" classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" codebase="http://java.sun.com/update/1.6.0/jinstall-6u3-windows-i586-jc.cab#Version=6,0,030,2" width="680" height="70" id="simHabitacao" VIEWASTEXT="true">');
		document.write('<param name="code" value="simHabitacao.class">');
		document.write('<param name="archive" value="habitSiteBPI.jar">');
		document.write('<param name="codebase" value="http://rep.bancobpi.pt/applets/habit/">');
		document.write('<param name="cliente" value="casasapo">');
		document.write('<param name="financiamento" value="' + price + '">');
		document.write('<param name="ve" value="' + price + '">');
		document.write('<param name="prazo" value="40">');
		document.write('<param name="uselink" value="1">');
		document.write('<param name="type" value="application/x-java-applet;version=1.5">');
		document.write('<param name="scriptable" value="true">');
		document.write('</object>');
	}
	else
	{
		// NOT IE
		document.write('<applet name="sim" codebase="http://rep.bancobpi.pt/applets/habit/" archive="habitSiteBPI.jar" code="simHabitacao.class" id="simHabitacao" width="680" height="70" >');
		document.write('<param name="cliente" value="casasapo"/>');
		document.write('<param name="financiamento" value="' + price + '"/>');
		document.write('<param name="ve" value="' + price + '"/>');
		document.write('<param name="prazo" value="40"/>');
		document.write('<param name="uselink" value="1"/>');
		document.write('</applet>');
	}
}
