// ldodge 010904: this file provides utility functions for Aplia to comply with proposed changes to IE in SP1b.
// all flash on the site should use these calls, excepting the config check
// if you would like to use the wmode parameter, use flashUtilsWmode.js instead

// 7/26/04 AKT Fix for bug #1233
// removed the conditional part of the following code because we
// believe that "scale=exactfit" should *always* be used for flash tool
// invocation. This is due to the use of Lightning. The same change is made
// a few lines down for the EMBED tag.

// 6/30/06 KB Please note that embedFlashDiv REQUIRES the img tag for correct display in IE WIN.
// For printing in Netscape and Firefox, it must be 0px.  Be sure to test display and printing in all browsers!


var FLASH_CLASS_ID = "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
var FLASH_CODEBASE = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0";
var FLASH_PLUGIN_PAGE = "http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash";
var FLASH_MIME_TYPE = "application/x-shockwave-flash";
var FLASH_SCRIPTACCESS = "sameDomain";
var FLASH_MENU = "false";
var FLASH_QUALITY = "high";
var FLASH_BGCOLOR = "#FFFFFF";
var FLASH_WIDTH = "100%";
var FLASH_HEIGHT = "100%";
var FLASH_SCALE = "exactfit";
var FLASH_WMODE = "transparent";

var printing = false;
var MAX_PRINT_WIDTH = 640;
var MAX_PRINT_HEIGHT = 800;

function embedFlashDiv(division, swf, flashvars, width, height, isPrint)
{
    //if (isPrint) printing = true; //global for setFlashHeight below
    if (isPrint) flashvars = flashvars + "&maxWidth=" + MAX_PRINT_WIDTH + "&maxHeight=" + MAX_PRINT_HEIGHT;
    var flashString =
        "<div id='" + division + "' style='width:" + width + "px; height:" + height + "px'>" +
        "<img src='/images/clear.gif' height='0px' width='0px' />" +
            "<object " +
            "   classid='" + FLASH_CLASS_ID + "'" +
            "   codebase='" + FLASH_CODEBASE + "'" +
            "   id = '" + division + "ID'" +
            "   width='" +  FLASH_WIDTH + "'" +
            "   height='" + FLASH_HEIGHT + "'" +
            "   >" +
            "   <PARAM name='movie' value='" + swf + "'>" +
            //"   <PARAM name='wmode' value='" + FLASH_WMODE + "'>" +
            "   <PARAM name='flashvars' value='" + flashvars + "'>" +
            "   <PARAM name='allowScriptAccess' value='" + FLASH_SCRIPTACCESS + "'>" +
            "   <PARAM name='menu' value='" + FLASH_MENU + "'>" +
            "   <PARAM name='quality' value='" + FLASH_QUALITY + "'>" +
            "   <PARAM name='bgcolor' value='" + FLASH_BGCOLOR + "'>";
    //if (isPrint) flashString += "   <PARAM name='scale' value='showAll'>";
    flashString +=
            "   <EMBED pluginspage='" + FLASH_PLUGIN_PAGE + "' " +
            "       type='" + FLASH_MIME_TYPE + "' " +
            "       src='" + swf + "' " +
            "       name='" + division + "ID'" +
            "       flashvars='" + flashvars + "' " +
            "       allowScriptAccess ='" + FLASH_SCRIPTACCESS + "' " +
            "       menu='" + FLASH_MENU + "' " +
            //"       wmode='" + FLASH_WMODE + "' " +
            "       quality='" + FLASH_QUALITY + "' " +
            "       bgcolor='" + FLASH_BGCOLOR + "' " +
            "       width='" + FLASH_WIDTH + "' " +
            "       height='" + FLASH_HEIGHT + "' ";
    //if (isPrint) flashString += "       scale='showAll' ";
    flashString += 
            "       />" +
            "</object> " +
        "</div> ";
    document.write(flashString);
}

var ieWin = false;

if (navigator.appName.indexOf('Microsoft') != -1){
  if (navigator.platform) {
      if (navigator.platform.indexOf("Win") != -1) {
          ieWin = true;
      }
  }
}

//Modify height and width of Flash movie for printing.
//Note requires scale=showAll to have been used in object/embed tags
function scaleQNAForPrint(divid, newH, newW)
{
    var scale = Math.min(MAX_PRINT_HEIGHT/newH, MAX_PRINT_WIDTH/newW);
    var scaledH = Math.round(newH * scale);
    var scaledW = Math.round(newW * scale);
    //alert ('scaleQNAForPrint ' + divid + ' newH:' + newH + ' newW:' + newW + ' scale:' + scale + ' scaledH:' + scaledH + ' scaledW:' + scaledW);
    document.getElementById(divid).style.height = scaledH+"px";
    document.getElementById(divid).style.width = scaledW+"px";
}

// Modify height of Flash movie...
function setFlashHeight(divid, newH)
{
    //alert('setFlashHeight ' + printing + ' ' + ieWin);
    if (printing && ieWin) {
        scaleQNAForPrint(divid, newH, 732);//need to call this when printing only.
    }
    else document.getElementById(divid).style.height = newH+"px";
}

// Modify the width and height of the Flash movie...
function setFlashDimensions(division, width, height){
//    if (printing && ieWin) {
//        scaleQNAForPrint(division, height, width);//need to call this when printing only.
//    }
//    else {
        document.getElementById(division).style.width = width+"px";
        document.getElementById(division).style.height = height+"px";
//    }
}

// url = full url with variables to swf, width = width of swf, height= height of swf, exactfit = 0 = no and 1 = yes to include
function writeFlash( url, width, height, exactfit ) {
    var fullFlashStr = "" +
            "<OBJECT classid='" + FLASH_CLASS_ID + "' codebase='" + FLASH_CODEBASE + "' width='" +  width + "' height='" + height + "'>" +
            "   <PARAM name='movie' value='" + url + "'>" +
            "   <PARAM name='menu' value='" + FLASH_MENU + "'>" +
            //"   <PARAM name='wmode' value='" + FLASH_WMODE + "'>" +
            "   <PARAM name='quality' value='" + FLASH_QUALITY + "'>" +
            "   <PARAM name='bgcolor' value='" + FLASH_BGCOLOR + "'>" +
            "   <PARAM name='scale' value='" + FLASH_SCALE + "'>" +
            "   <EMBED src='" + url + "' " +
            "       menu='" + FLASH_MENU + "' " +
            //"       wmode='" + FLASH_WMODE + "' " +
            "       quality='" + FLASH_QUALITY + "' " +
            "       bgcolor='" + FLASH_BGCOLOR + "' " +
            "       width='" + width + "' " +
            "       height='" + height + "' " +
            "       type='" + FLASH_MIME_TYPE + "' " +
            "       pluginspage='" + FLASH_SCALE + "' " +
            "       scale='" + FLASH_SCALE + "' " +
            "   >" +
            "   </EMBED>" +
            "</OBJECT>";
    //alert('writeFlash: ' + fullFlashStr);
    document.write(fullFlashStr);
}


function writeFlashWithFlashVars( url, flashvars, width, height, exactfit, objID) {
	writeFlashWithFlashVarsWmode( url, flashvars, width, height, exactfit, objID, false );
}

// url = full url with variables to swf, width = width of swf, height= height of swf, exactfit = 0 = no and 1 = yes to include
function writeFlashWithFlashVarsWmode( url, flashvars, width, height, exactfit, objID, wmodeOn ) {
	var sObjID = "";
	var sObjName = "";
	if (objID != null) {
		sObjID = "id='" + objID + "' ";
		sObjName = "name='" + objID + "' ";
	}
	var sParamWmode = "";
	var sEmbedWmode = "";
	if (wmodeOn == true) {
		sParamWmode = "   <PARAM name='wmode' value='" + FLASH_WMODE + "'>";
		sEmbedWmode = "       wmode='" + FLASH_WMODE + "' ";
	}

    var fullFlashStr = "" +
            "<OBJECT " + sObjID + "classid='" + FLASH_CLASS_ID + "' codebase='" + FLASH_CODEBASE + "' width='" +  width + "' height='" + height + "'>" +
            "   <PARAM name='movie' value='" + url + "'>" +
            "   <PARAM name='menu' value='" + FLASH_MENU + "'>" +
           	sParamWmode +
            "   <PARAM name='quality' value='" + FLASH_QUALITY + "'>" +
            "   <PARAM name='bgcolor' value='" + FLASH_BGCOLOR + "'>" +
            "   <PARAM name='scale' value='" + FLASH_SCALE + "'>" +
            "   <PARAM name='flashvars' value='" + flashvars + "'>" +
            "   <EMBED " + sObjName + "src='" + url + "' " +
            "       menu='" + FLASH_MENU + "' " +
            sEmbedWmode +
            "       quality='" + FLASH_QUALITY + "' " +
            "       bgcolor='" + FLASH_BGCOLOR + "' " +
            "       width='" + width + "' " +
            "       height='" + height + "' " +
            "       type='" + FLASH_MIME_TYPE + "' " +
            "       pluginspage='" + FLASH_SCALE + "' " +
            "       scale='" + FLASH_SCALE + "' " +
            "	    flashvars='" + flashvars + "' " +
            "   >" +
            "   </EMBED>" +
            "</OBJECT>";
    document.write(fullFlashStr);
}

function writeMe(str) {
    document.write(str);
}

function writeExperiment(url) {
	// first line of object tag
	document.write("<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" id=version width=100% height=95% align=center>");
	document.write("<PARAM name=movie value=\"" + url + "\">");
	//document.write("<PARAM name=wmode value=transparent>");
	document.write("<PARAM name=menu value=false><PARAM name=quality value=high><PARAM name=bgcolor value=#FFFFFF>");
	// embed tag
	document.write("<EMBED src=\"" + url + "\" ");
    //document.write("wmode=transparent ");
    document.write("menu=false quality=high bgcolor=#FFFFFF width=100% height=95% align=center type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"></EMBED></OBJECT>");
}

function writeTutorial(url) {
	// first line of object tag
	document.write("<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" id=version width=100% height=100% align=center>");
	document.write("<PARAM name=movie value=\"" + url + "\">");
	//document.write("<PARAM name=wmode value=transparent>");
	document.write("<PARAM name=menu value=false><PARAM name=quality value=high><PARAM name=bgcolor value=#DEE7E9>");
	// embed tag
	document.write("<EMBED src=\"" + url + "\" ");
    //document.write("wmode=transparent ");
    document.write("menu=false quality=high bgcolor=#DEE7E9 width=100% height=100% align=center type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"></EMBED></OBJECT>");
}

function doOpenLink(url) {
	if (url.indexOf("atext://") != -1) {
		// launch an Aplia Text module
		url = url.substr(8);
		var idx = url.indexOf("/");
		var i = url.substring(0, idx);
		url = url.substr(idx + 1);
		idx = url.indexOf("/");
		var c = url.substring(0, idx);
		url = url.substr(idx + 1);
		var m = url;
		popupApliaText(i, c, m, null);
	}
	else {
		// launch the specified url
		var h = screen.height;
		var w = screen.width;
		h = h * .7;
		w = w * .7;
		var loc = "toolbar=1,location=1,status=1,scrollbars=1,resizable=1,width=" + w + ",height=" + h;
		window.open(url,'Information',loc);
	}
}
