//AC_RunAcitiveContent.js
//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    
    
    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

//browser.js
// Returns true if current browser is Netscape.
function isNS() {
	var name = navigator.appName;
    return (name.substring(0,1) == 'N');
}

// Returns true if current platform is Macintosh.
function isMac() {
	var version = navigator.appVersion;
	return (version.indexOf("Mac") >= 0);
}
function IEWindows()
{
	var name = navigator.appName;
	if (name.substring(0,1) == 'M')
	{
		var version = navigator.appVersion;
		return (version.indexOf("Windows") >= 0);		
	}
	else return false;
}

//common.js

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function addLoadEvent(func) {	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}
}

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s) {
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag) {
	var i;
    var returnString = "";
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year) {
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr) {
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("Please format the date as mm/dd/yyyy.")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month.")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day.")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear+".")
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date.")
		return false
	}
	return true
}


function popupFull(url, height, width, name, options, xpos, ypos) {

	url = "/mccann" + url;

    // Set height, width, and name if the values arent being passed in.
    if(height == null)
       height = 500;
    if(width == null)
       width = 600;
    if(name == null)
       name = "newWindow";
    
    if (xpos == null)
		xpos = (screen.width / 2) - (width / 2);
	
	if (ypos == null)
		ypos = (screen.height / 2) - (height / 2);

	var size     = "height=" + height + ",width=" + width;
	var position = ",left=" + xpos + ",top=" + ypos + ",screenX=" + xpos + ",screenY=" + ypos;
	var options  = "," + options;

	var popupWindow = window.open(url, name, size + position + options);
	popupWindow.focus();
}

function popupResource(url, height, width, name, options) {

	

    // Set height, width, and name if the values arent being passed in.
    if(height == null)
       height = 500;
    if(width == null)
       width = 600;
    if(name == null)
       name = "newWindow";
       
	var xpos = (screen.width / 2) - (width / 2);
	var ypos = (screen.height / 2) - (height / 2);

	var size     = "height=" + height + ",width=" + width;
	var position = ",left=" + xpos + ",top=" + ypos + ",screenX=" + xpos + ",screenY=" + ypos;
	var options  = "," + options;

	var popupWindow = window.open(url, name, size + position + options);
	popupWindow.focus();
}
	
function popup(url) {
    popupFull(url, 400, 565, "popupWindow");
}

function popupP(url, height, width) {
    popupFull(url, height, width, "popupWindow");
}

function popupPrintable(url, height, width) {
    popupPrintableFull(url, height, width, "popupWindow");
}

function popupResizeable(url, height, width, name) {
	popupFull(url, height, width, name, "status=no,menubar=no,scrollbars=yes, resizable=yes");
}

function popupPrintableFull(url, height, width, name) {
	popupFull(url, height, width, name, "status=no,menubar=yes,scrollbars=yes, resizable=yes");
}

function popupNoScrolls(url, height, width, name) {
	popupFull(url, height, width, name, "status=no,menubar=no,scrollbars=no");
}

function popupNoScrollsNoResize(url, height, width, name, xpos, ypos) {
	popupFull(url, height, width, name, "status=yes,menubar=no,scrollbars=no,resizable=no", xpos, ypos);
}

function doClose() {
	opener.location.href = opener.location.href;
	self.close();
}
	
//delivery.js
var radioButtonImage_selected = "/mccann/images.map/standard_icon_ball_red.gif";
var radioButtonImage_unselected = "/mccann/images.map/standard_icon_ball_clear.gif";

//var radioButtonImage_selected = "/mccann/images.map/standard_icon_check_green.gif";
//var radioButtonImage_unselected = "/mccann/images.map/standard_icon_check_clear.gif";

var checkBoxImage_checked = "/mccann/images.map/standard_icon_check_red.gif";
var checkBoxImage_unchecked= "/mccann/images.map/standard_icon_check_clear.gif";

var aboveSpace = 82;
var belowSpace = 88;
var difference=0
var topPassage=26
var topQuestion=26
var bottomPassage=26
var bottomQuestion=26
var directionsWidth=0.1
var passagesWidth=0.9

var preload = new Image();
preload.src = radioButtonImage_selected;
preload.src = radioButtonImage_unselected;
function testImages()
{
	document.write('<div id="loadImages"><img src="/mccann/images.map/standard_icon_ball_red.gif"><img src="/mccann/images.map/standard_icon_ball_clear.gif"></div>');
	document.getElementById('loadImages').style.display="none";
}
function findHeightMac() {
	difference = document.belowImage.offsetTop - document.aboveImage.offsetTop;
	difference = difference - 87;
}

function findHeightNS() {

	document.write('<table id ="myDiv" name=test width=100% border="0" cellpadding="0" cellspacing="0" bgcolor="#666698" height=100%>')
	document.write('<tr>')
	document.write('<td id ="myDiv2" height=92 valign="top"><img name=aboveImage1 src="" height=92 width=1 border=0></td>')
	document.write('</tr>')
	document.write('<tr>')
	document.write('<td id ="myDiv3" valign="top"><img name=spacer1 src="" height=0 width=1 border=0></td>')
	document.write('</tr>')
	document.write('<tr>')
	document.write('<td id ="myDiv4" height=87 valign="bottom"><img name=belowImage1 src="" height=87 width=1 border=0></td>')
	document.write('</tr>')
	document.write('</table>')

	var agt=navigator.userAgent; 
    if (agt.indexOf('Safari')>-1)
		difference = 500;
	else
	{
		difference = document.belowImage1.y - document.aboveImage1.y;
		difference = difference - 87;
	}
    //alert("Difference = " + difference);
	document.getElementById('body').removeChild(document.getElementById("myDiv"));
	document.getElementById('body').setAttribute('bgcolor','#6599FF');
}

function hasChild(parent, child) 
{
      if (parent.hasChildNodes()) {
        for (var i=0; i<parent.childNodes.length;i++) {
    
        }
      }            
}

function createTable() {
	var elm = document.getElementById("testCell");
	var elm1 = document.getElementById("testTable");
	var elmP = document.getElementById("testTableP");
	var elmD = document.getElementById("testTableD");
	var passage = document.getElementById("question");
	var name =navigator.appName;

	if (elm != null && elm1 != null && elmP != null && elmD != null && passage != null) {
		if (isNS() || isMac()) {
			elm.setAttribute('height', difference);
			elm.setAttribute('class', 'TR.layoutTable1');
			elm.setAttribute('border', 3);
			elm1.setAttribute('height', difference);
			elmP.setAttribute('height', difference*passagesWidth);
			elmD.setAttribute('height', difference*directionsWidth);
			passage.setAttribute('height', difference*passagesWidth-bottomPassage-topPassage);
			var h = difference*passagesWidth-bottomPassage-topPassage;
			document.write('<style>.passage_scroll{height:'+h+'; overflow:auto;}</style>');
		}
		else {
			elmP.setAttribute('height','95%');
			elmD.setAttribute('height','5%');
			document.write('<style>table.middle{height:100%;} table.data{height:100%;} .passage_scroll{height:100%;overflow:auto;}</style>');
		}
	}
}
// Returns true if current browser is Netscape.
function isNS() {
	var name = navigator.appName;
    return (name.substring(0,1) == 'N');
}

// Returns true if current platform is Macintosh.
function isMac() {
	var version = navigator.appVersion;
	return (version.indexOf("Mac") >= 0);
}

function submitEssay(link,message,control)
{
	if (control=="finish" && message!="")
		alert(replace(unescape(message),"+"," "));
	//alert(unescape(message));
	window.location.href=link
}
function initTimer(timerLimit,countUp,secElap,endsMessage,warningsMessage,warningsTime)
{
	
	secElapsed=secElap
	setSeconds()
	//intSetSeconds=setTimeout('setSeconds()', 1000);
	count=countUp
	timeLimit=timerLimit
	endMessage=endsMessage
	warningMessage=warningsMessage
	warningTime=warningsTime
}
function initSec(timerLimit,secElap)
{	
	secElapsed=secElap	
	timeLimit=timerLimit
	//alert(document.cursor.sessionTime.value)
	
}
function updateTimeLimit(timerLimit)
{
	timeLimit=timerLimit
}
function clearIntervalForSave()
{
	clearTimeout(intSetSeconds);
}
function setSeconds()
{
	secElapsed=secElapsed+1;
	if (warningTime!=-99)
	{
		if (flagWarningMessage==false)
		{
			var messTime=timeLimit*60-secElapsed
			if (warningTime*60==messTime)
			{
				alertWarning();
				flagWarningMessage=true;
			}
		}
	}
	intSetSeconds=setTimeout('setSeconds()', 1000);
}

function alertWarning()
{
	//alert("bhghy")
	alert(unescape(replace(warningMessage,"+"," ")))
}
function saveTimer(obj)
{
	if(obj!=null && count){	
		var secs=0;
		if (count=="down")
		{
			secs =timeLimit*60-secElapsed;
		}
		else
		{
			secs = secElapsed;	
		}
		var secElap=0;
		if (timeLimit!=-99)
		{
		    if (count=="down")
			    secElap=timeLimit*60-secs;
			else
			    secElap=secs;
		}
		else secElap=secs;
		eval(obj).value=secElap;
	}
}



function addFlashFile(bgColor,path)
{
	/*var bAgent = window.navigator.userAgent;
    var bAppName = window.navigator.appName;
	var x = document.getElementById('testTimer');	
    if (bAppName == 'Netscape') {
    
       	
		var y = document.createElementNS("http://www.w3.org/1999/xhtml", "object");
		y.setAttribute("data",path );
		y.setAttribute("type", "application/x-shockwave-flash");
		y.setAttribute("width", 69);
		y.setAttribute("height", 21);
        y.setAttribute("bgcolor", bgColor);
		
    }
    else 
    {
    	if (isMac()==false)
    	{
			var myswf = new SWFEmbedder(path); 
			myswf.setSWFSize(69,21);
			myswf.setSWFID("clock");
			myswf.setDivID("div_test");
			myswf.embedSWF();	
		}
		
	}	
	x.appendChild(y); */
}
	CLASSID_ATTR = "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
	CODEBASE_ATTR = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,65,0";
	TYPE_ATTR = "application/x-shockwave-SWF";
	PLUGINS_PAGE_ATTR = "http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";

	function SWFEmbedder(SWFFile){ 
	if (!document.getElementById || !document.createElement) return 0; //exit
	this.SWFFile = SWFFile;
	}
	
	SWFEmbedder.prototype.setSWFSize = function(SWFWidth, SWFHeight){
	this.SWFWidth = SWFWidth;
	this.SWFHeight = SWFHeight;
	}
	
	SWFEmbedder.prototype.setSWFID = function(SWFID){
	this.SWFID = SWFID;
	}
	
	SWFEmbedder.prototype.setDivID = function(divID){
	this.divID = divID;
	}
	
	SWFEmbedder.prototype.embedSWF = function(){
	// get the document body element - the correct way
	this.documentBody = document.getElementById("testTimer")
	// according to the user-agent architecture create elements to embed SWF
	this.SWFDivision = document.createElement("font");
	this.SWFDivision.setAttribute("id", this.divID);
	this.objectNode =  document.createElement("object"); // Mozilla
	this.paramNode = document.createElement("param"); // Mozilla
	//did't work for MSIE
	this.embedNode = document.createElement("embed"); // MSIE
	this.infoP = document.createElement("font");
	this.infoA = document.createElement("font");
	this.infoText = document.createTextNode("");
                                                 
	//this.infoA.setAttribute("href", PLUGINS_PAGE_ATTR);
	//this.infoA.appendChild(this.infoText);
	//this.infoP.appendChild(this.infoA);
	// embed tag for msie
	this.embedNode.setAttribute("src", this.SWFFile);
	this.embedNode.setAttribute("type", TYPE_ATTR);
	this.embedNode.setAttribute("name", this.SWFID);
	this.embedNode.setAttribute("width", this.SWFWidth);
	this.embedNode.setAttribute("height", this.SWFHeight);
	// we check if the user agent supports ActiveX or Plug-in API
	 if (window.ActiveXObject) {	
	this.SWFDivision.appendChild(this.embedNode);
	this.documentBody.appendChild(this.SWFDivision);
	} else { 
	// if the user agent uses plug-in api
	// we do not use *src* but *data* in order to use movie param
	// works well with Player version over 6.0.47.0
	this.objectNode.setAttribute("data", this.SWFFile); 
	this.objectNode.setAttribute("type", TYPE_ATTR);
	this.objectNode.setAttribute("id", this.SWFID);
	this.objectNode.setAttribute("width", this.SWFWidth);
	this.objectNode.setAttribute("height", this.SWFHeight);
	this.paramNode.setAttribute("movie", this.SWFFile);
	// work as expected
	this.objectNode.appendChild(this.paramNode);
	this.SWFDivision.appendChild(this.objectNode);
	this.documentBody.appendChild(this.SWFDivision);
		}
	}

	SWFEmbedder.prototype.removeSWF = function()
	{
		this.documentBody.removeChild(this.SWFDivision);
	}
	
	
	function replace(str,text,by) {
    var strLength = str.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return str;

    var i = str.indexOf(text);
    if ((!i) && (text != str.substring(0,txtLength))) return str;
    if (i == -1) return str;

    var newstr = str.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(str.substring(i+txtLength,strLength),text,by);

    return newstr;
}
/*************************************************************************************/
/*  Title: PNG Fix
/*  Fix poor support for PNG alpha transparency in IE 5.5 & 6.
/*  Replaces all images with .png extension with a transparent spacer.gif with the
/*  same dimensions (CSS) and applies alpha transparent PNG as background (which
/*  is supported in IE 5.5 & 6).
/*************************************************************************************/
function correctPNG(){
	if(navigator.userAgent.indexOf('MSIE 5.5') != -1 || navigator.userAgent.indexOf('MSIE 6.0') != -1){
		for(var i = 0; i < document.images.length; i++){
			var img = document.images[i];
			var imgName = img.src.toUpperCase();
			if(imgName.indexOf(".PNG") != -1){
				img.src = img.src.substring(0, (imgName.indexOf(".PNG") + 4));
				var imgID = (img.id) ? 'id="' + img.id + '" ' : "";
				var imgClass = (img.className) ? 'class="' + img.className + '" ' : "";
				var imgTitle = (img.title) ? 'title="' + img.title + '" ' : 'title="' + img.alt + '" ';
				var imgStyle = img.style.cssText;
				var imgWidth = (img.width > 0) ? img.width : getNumber(img.currentStyle.width);
				var imgHeight = (img.height > 0) ? img.height : getNumber(img.currentStyle.height);
				if (img.align == "left") imgStyle = "float:left;" + imgStyle;
				if (img.align == "right") imgStyle = "float:right;" + imgStyle;
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
				var strNewHTML = "<img src=\"/mccann/images.map/spacer.gif\" " + imgID + imgClass + imgTitle + " style=\"width:" + imgWidth + "px; height:" + imgHeight + "px;" + imgStyle + " float:left; visibility:visible; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img.src + "', sizingMethod='scale');\" />";
				//var strNewHTML = "<img src=\"" + img.src + "\" alt="" />";
				img.outerHTML = strNewHTML;
				//alert(strNewHTML);
				i = i - 1;
			}
		}
	}
}

function getNumber(numString){
	var regx = new RegExp("[^0-9]", "g");
	var newNum = numString.replace(regx, '');
	return newNum;
}

if(window.attachEvent){
	window.attachEvent("onload", correctPNG);
}
//protocol.js
/* Return the protocol of the current URL (e.g. http or https). */
function getProtocol() {
    var url = "" + window.location;
    var index = url.indexOf(":");
    var protocol = "http";
    if (index >= 0)
        protocol = url.substring(0, index);
    return protocol;
}
