/////////////////////////////////////////////////////
//	Purple Monkey
//
//  Flash Detection & Embedding
//
//	Created By: Ray Schauer
//  Created On: 4/28/2005
//
//	Last Modified On: 04/21/2006
//	Last Modified By: Pooja Singh
//
//
//  Thank you http://www.quirksmode.org/ for the
//  inspiration...
//
//  No thanks to Eolas for their embed patent...
//
//  ----------------------------------------------
//  Accepts
//  ----------------------------------------------
//  URL: html for flash object embeding. The file is XHTML formatted.
//  ID : id of div to replace with html from URL
//  MIN: minimum version of flash which must be installed
//  CUR: current high version of flash (required because IE is dumb) 
//
//  ----------------------------------------------
//  Example Usage
//  ----------------------------------------------
//  <div id="flashcontainer">
//		This is where the NON-Flash version goes.
//  </div>
//  ...
//  <SCRIPT type="text/javascript">
//      //<![CDATA[
//      <!--
//			embedflash('externalflash.html', 'flashcontainer',6,8); 
//      //-->
//      //]]>
//  </SCRIPT>
//
/////////////////////////////////////////////////////

function embedflash(url, containerid, minversion, currentversion){
//	currentversion = 9;
//	// Check for proper version of flash
//	if (!flashInstalled(minversion,currentversion)){
//       return false;
//    }
	
    // AJAX test
	var page_request = false
	if (window.XMLHttpRequest) { 
		// if Mozilla, Safari etc
		page_request = new XMLHttpRequest();
	} else if (window.ActiveXObject){ 
	    // if IE
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e){
			try {
				page_request = new ActiveXObject("Microsoft.XMLHTTP");
			}		
			catch (e){}
		}		
	}else {
		return false;
	}

	if (navigator.userAgent == "Mozilla/4.0 (compatible; MSIE 5.23; Mac_PowerPC)") {
		//removes error message while loading
		eval(containerid).innerHTML="";	

		ie523containerid = containerid;
		iframe = document.createElement("iframe");
		iframe.name = "dataiframe";
		iframe.id = "dataiframe";
		iframe.width=0;
		iframe.height=0;
		iframe.document.onreadystatechange = loadie523page;
		iframe.src=url;
		document.getElementsByTagName('head')[0].appendChild(iframe);

	} else {
		// Begin embedding
		page_request.onreadystatechange=function(){
			loadpage(page_request, containerid);
		}	
		page_request.open('GET', url, true);
		page_request.send(null);
	}
}

function loadie523page(){
	if (iframe.document.readyState == "interactive") {
		eval(ie523containerid).innerHTML=frames["dataiframe"].document.documentElement.outerHTML;
		//document.getElementsByTagName('head')[0].removeChild(iframe);
	}
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function flashInstalled(min,current) {

	var installed = 0;
	var version = 0;

	if (navigator.plugins && navigator.plugins.length) {
		// Standard Flash Detection
		x = navigator.plugins["Shockwave Flash"];
		if (x) {
			installed = 1;
			if (x.description) {
				y = x.description;
				version = y.charAt(y.indexOf('.')-1);
			}
		} else {
			installed = 0;
		}
	} else {
		// IE flash detection
		current = current + 1;
		for(var i=current; i>0; i--){
			version = 0;
			installed = 0;
			try{
				var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i);
				version = i;
				installed = 1;
				break;
			} catch(e){
				// We really don't do anything with this.
				// It is here to keep IE from throwing
				// an error.
			}
		}
	}

	// Perform Final Test
	// We MUST have min or higher
	if (installed == 1 && version >= min) {
		return true;
	} else {
		return false;
	}
}