var formSubmitValue = 'processing...' // this is the global onclick value of a form submit button

function downloadPlugin(theUrl) {
  theNewWin = window.open(theUrl,'plugin','width=800,height=560,scrollbars=yes,resizable=yes,location=yes,toolbar=yes');
  theNewWin.focus(); // if the window exists, bring it to the front
}

//function downloadPlugin() { // currently for development
//  document.getElementById('flashObject').style.visibility='visible';
//  document.getElementById('link01').style.display='none';
//  document.getElementById('link02').style.display='';
//}

//function removePlugin() { // currently for development
//  document.getElementById('flashObject').style.visibility='hidden';
//  document.getElementById('link01').style.display='';
//  document.getElementById('link02').style.display='none';
//}

function turnMeOff(id) { // for development only
  document.getElementById(id).style.display="none";
}

function popArticle(theUrl) { // standard content popup for articles
  theNewWin = window.open(theUrl,'emeraldArticle','width=640,height=500,scrollbars=yes,resizable=yes');
  theNewWin.focus(); // if the window exists, bring it to the front
}

function popApplyNowForm(theUrl) { // standard popup for job applications
  theNewWin = window.open(theUrl,'emeraldApplyNow','width=600,height=580,scrollbars=yes,resizable=yes');
  theNewWin.focus(); // if the window exists, bring it to the front
}

function popCalculator(theUrl) { // standard content popup for calculators
  theNewWin = window.open(theUrl,'emeraldCalculator','width=640,height=500,scrollbars=yes,resizable=yes');
  theNewWin.focus(); // if the window exists, bring it to the front
}

function popContactUsForm(theUrl) { // standard popup for the contact form
  theNewWin = window.open(theUrl,'emeraldContactUs','width=600,height=580,scrollbars=yes,resizable=yes');
  theNewWin.focus(); // if the window exists, bring it to the front
}

function popEseminar(theUrl) { // standard content popup for eSeminars
  theNewWin = window.open(theUrl,'emeraldEseminar','width=623,height=536,resizable=yes');
  theNewWin.focus(); // if the window exists, bring it to the front
}

function popForm(theUrl,theClass) { // standard content popup for standard forms
  if (theClass == 'quoteRequest') {
    theNewWin = window.open(theUrl,'emeraldForm','width=560,height=500,scrollbars=yes,resizable=yes');
  }
  else {
    theNewWin = window.open(theUrl,'emeraldForm','width=540,height=500,scrollbars=yes,resizable=yes');
  }
  theNewWin.focus(); // if the window exists, bring it to the front
}

function popNewsletter(theUrl) { // standard content popup for newsletters
  theNewWin = window.open(theUrl,'emeraldNewsletter','width=640,height=500,scrollbars=yes,resizable=yes');
  theNewWin.focus(); // if the window exists, bring it to the front
}

function popSeminarSignupForm(theUrl) { // standard popup for seminar sign ups
  theNewWin = window.open(theUrl,'emeraldSeminarSignup','width=600,height=580,scrollbars=yes,resizable=yes');
  theNewWin.focus(); // if the window exists, bring it to the front
}

function printPage() {
  window.print();
}

/*///////////////////   iFrames and Navigation   ///////////////////*/

function hideIBuffer() { // iBuffer is the spacer image placeholder for the iFrame, show one, hide the other
if (document.getElementById('iBuffer')){
  document.getElementById('iBuffer').style.display='none';
  }
}

function showIBuffer() { // iBuffer is the spacer image placeholder for the iFrame show one, hide the other
if (document.getElementById('iBuffer')){
  document.getElementById('iBuffer').style.display='';
  }
}

function hideIframe() { // iFrame will cause the DDM to freak,...if there's an iFrame, we hide it on DDM mouseover
if (document.getElementById('marketWatch_iContent')){
  document.getElementById('marketWatch_iContent').style.display='none';
showIBuffer();
  }
if (document.getElementById('glossary_iContent')){
  document.getElementById('glossary_iContent').style.display='none';
showIBuffer();
  }
}

function showIframe() { // on DDM mouseout, if there's an iFrame, we show it.
if (document.getElementById('marketWatch_iContent')){
document.getElementById('marketWatch_iContent').style.display='';
hideIBuffer();
  }
if (document.getElementById('glossary_iContent')){
document.getElementById('glossary_iContent').style.display='';
hideIBuffer();
  }
}

function marketWatch_iFrameGo(url) {
if (document.getElementById('marketWatch_iContent')){
  showIframe(); // unhides the iFrame so we can target it.
  document.getElementById('marketWatch_iContent').src=url; // iFrame target (client side...we don't want to refresh the page!)
  }
else {window.location='subMarketWatch.cfm?url=' +url; // iFrame target (CF handled...server side)
  }
}
/*///////////////////   function for removing HTML declared borders from tables in custom forms in IE   ///////////////////*/
function unBorderTables() {
  for (i=0;i<=29;i++) {
    if(document.getElementsByTagName("table")[i])
    document.getElementsByTagName("table")[i].border=0;
  }
}
/*///////////////////   legacy scripts for backward compatibility   ///////////////////*/

function open_window(url) {
  mywin = window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=400,height=335');  
}

function new_window(url,wx,hx) {
  newwin = window.open(url,"win",'toolbar=0,location=0,directories=0,scrollbars=1,resizable=1,status=1,menubar=0,width='+wx+',height='+hx);  
}


/*///////////////////   new standard pop-up window code   ///////////////////*/

var NewBox = null; 

function infobox(strURL, strWidth, strHeight) { 
 if (NewBox != null && !NewBox.closed) 
   NewBox.close(); 
 var strOptions=""; 
   strOptions="toolbar=0,directories=0,status=1,menubar=0,resizable=1,"+ 
     "scrollbars=1,location=0,height="+strHeight+",width="+strWidth; 
 NewBox = window.open(strURL, 'NewBox', strOptions); 
 NewBox.focus(); 
}

var FileBox = null; 

function filebox(strURL, strWidth, strHeight) { 
 if (FileBox != null && !FileBox.closed) 
   FileBox.close(); 
 var strOptions=""; 
   strOptions="toolbar=0,directories=0,status=1,menubar=0,resizable=1,"+ 
     "scrollbars=1,location=0,height="+strHeight+",width="+strWidth; 
 FileBox = window.open(strURL, 'FileBox', strOptions); 
 FileBox.focus(); 
}

function open_windowMainNav(url) 
{
myMainNavwin = window.open(url,"win",'toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1,width=600,height=450,left=1,top=1');  
}

/*///////////////////   tooltip pop-up box code   ///////////////////*/

function getElementById(id) {
  if (document.getElementById) {
    return document.getElementById(id);
  } else if (document.all) {
    return eval("document.all." + id);
  } else if (document.layers) {
    return eval("document.layers." + id);
  } else{
    return null;
  }
}

function infoLink(theId,which,event){
  if(which=="over"){
    getElementById(theId).style.display="";
    drawBox(event,theId)
  } else {
    getElementById(theId).style.display="none";
  }
}

function drawBox(event,target) {
  var y = event.clientY;
  var scrollY = (window.pageYOffset) ? window.pageYOffset : document.body.scrollTop;
  getElementById(target).style.top = y + scrollY + 20 + "px";
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}



/**
 * SWFObject v1.5.1: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept == "undefined") var deconcept = {};
if(typeof deconcept.util == "undefined") deconcept.util = {};
if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = {};
deconcept.SWFObject = function(swf, id, w, h, ver, c, quality, xiRedirectUrl, redirectUrl, detectKey) {
	if (!document.getElementById) { return; }
	this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = {};
	this.variables = {};
	this.attributes = [];
	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }
	if(w) { this.setAttribute('width', w); }
	if(h) { this.setAttribute('height', h); }
	if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
	this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion();
	if (!window.opera && document.all && this.installedVer.major > 7) {
		// only add the onunload cleanup if the Flash Player version supports External Interface and we are in IE
		// fixes bug in some fp9 versions see http://blog.deconcept.com/2006/07/28/swfobject-143-released/
		if (!deconcept.unloadSet) {
			deconcept.SWFObjectUtil.prepUnload = function() {
				__flash_unloadHandler = function(){};
				__flash_savedUnloadHandler = function(){};
				window.attachEvent("onunload", deconcept.SWFObjectUtil.cleanupSWFs);
			}
			window.attachEvent("onbeforeunload", deconcept.SWFObjectUtil.prepUnload);
			deconcept.unloadSet = true;
		}
	}
	if(c) { this.addParam('bgcolor', c); }
	var q = quality ? quality : 'high';
	this.addParam('quality', q);
	this.setAttribute('useExpressInstall', false);
	this.setAttribute('doExpressInstall', false);
	var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
	this.setAttribute('xiRedirectUrl', xir);
	this.setAttribute('redirectUrl', '');
	if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
}
deconcept.SWFObject.prototype = {
	useExpressInstall: function(path) {
		this.xiSWFPath = !path ? "expressinstall.swf" : path;
		this.setAttribute('useExpressInstall', true);
	},
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name] || "";
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name] || "";
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = [];
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs[variablePairs.length] = key +"="+ variables[key];
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "PlugIn");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ (this.getAttribute('style') || "") +'"';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += '/>';
		} else { // PC IE
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "ActiveX");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ (this.getAttribute('style') || "") +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			var pairs = this.getVariablePairs().join("&");
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			swfNode += "</object>";
		}
		return swfNode;
	},
	write: function(elementId){
		if(this.getAttribute('useExpressInstall')) {
			// check to see if we need to do an express install
			var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
			if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
				this.setAttribute('doExpressInstall', true);
				this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
			var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			n.innerHTML = this.getSWFHTML();
			return true;
		}else{
			if(this.getAttribute('redirectUrl') != "") {
				document.location.replace(this.getAttribute('redirectUrl'));
			}
		}
		return false;
	}
}

/* ---- detection functions ---- */
deconcept.SWFObjectUtil.getPlayerVersion = function(){
	var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else if (navigator.userAgent && navigator.userAgent.indexOf("Windows CE") >= 0){ // if Windows CE
		var axo = 1;
		var counter = 3;
		while(axo) {
			try {
				counter++;
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+ counter);
//				document.write("player v: "+ counter);
				PlayerVersion = new deconcept.PlayerVersion([counter,0,0]);
			} catch (e) {
				axo = null;
			}
		}
	} else { // Win IE (non mobile)
		// do minor version lookup in IE, but avoid fp6 crashing issues
		// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		}catch(e){
			try {
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				PlayerVersion = new deconcept.PlayerVersion([6,0,21]);
				axo.AllowScriptAccess = "always"; // error if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
			} catch(e) {
				if (PlayerVersion.major == 6) {
					return PlayerVersion;
				}
			}
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			} catch(e) {}
		}
		if (axo != null) {
			PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
		}
	}
	return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
	this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
	this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
	this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
}
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
/* ---- get value of query string param ---- */
deconcept.util = {
	getRequestParameter: function(param) {
		var q = document.location.search || document.location.hash;
		if (param == null) { return q; }
		if(q) {
			var pairs = q.substring(1).split("&");
			for (var i=0; i < pairs.length; i++) {
				if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
					return pairs[i].substring((pairs[i].indexOf("=")+1));
				}
			}
		}
		return "";
	}
}
/* fix for video streaming bug */
deconcept.SWFObjectUtil.cleanupSWFs = function() {
	var objects = document.getElementsByTagName("OBJECT");
	for (var i = objects.length - 1; i >= 0; i--) {
		objects[i].style.display = 'none';
		for (var x in objects[i]) {
			if (typeof objects[i][x] == 'function') {
				objects[i][x] = function(){};
			}
		}
	}
}
/* add document.getElementById if needed (mobile IE < 5) */
if (!document.getElementById && document.all) { document.getElementById = function(id) { return document.all[id]; }}

/* add some aliases for ease of use/backwards compatibility */
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject; // for legacy support
var SWFObject = deconcept.SWFObject;


// IE6 1px border problem
function checkBodyWidth()
{
  var isIE = navigator.appName.match("Internet Explorer") ? true:false;
  if (isIE)
  {
    document.getElementsByTagName("body")[0].onresize = function(){shiftContainer()};
    shiftContainer();
  }
}

function shiftContainer()
{
  if (document.body.clientWidth || document.documentElement.clientWidth)
  {
    if ((document.body.clientWidth)%2 == 1 || (document.documentElement.clientWidth)%2 == 1)
    {
      document.getElementById("container").style.left = "1px";
    }
    else
    {
      document.getElementById("container").style.left = "0";
    }
  }
}

// Event.onReady(function(){checkBodyWidth();});

// NYL Life Insurance Awareness Month
var NYL= {
  "NothVideo" : function() {
    Dialog.info( "<iframe src=\"/files/nyl/nyl-insAware.html\" frameborder=\"0\" style=\"width:335px; height:325px;\"></iframe>", { windowParameters: {
          className:"black alphacube",
          width: 385,
          height: 335,
          closable: true,
          draggable: true,
          destroyOnClose: true
        }
      }
    );
  },
  "ComfortZoneCamp" : function() {
    Dialog.info( "<iframe src=\"/files/nyl/comfortZoneCamp.html\" frameborder=\"0\" style=\"width:335px; height:325px;\"></iframe>", { windowParameters: {
          className:"black alphacube",
          width: 385,
          height: 335,
          closable: true,
          draggable: true,
          destroyOnClose: true
        }
      }
    );
  },
  "anniversary165" : function() {
    Dialog.info( "<iframe src=\"/files/nyl/anniversary165.html\" frameborder=\"0\" style=\"width:950px; height:525px;\"></iframe>", { windowParameters: {
          className:"black alphacube",
          width: 970,
          height: 536,
          closable: true,
          draggable: true,
          destroyOnClose: true
        }
      }
    );
  },
  "ALegacyOfLove" : function() {
    Dialog.info( "<iframe src=\"/files/NYL/ALegacyOfLove-video.html\" frameborder=\"0\" style=\"width:654px; height:412px;\"></iframe>", { windowParameters: {
          className:"black alphacube",
          width: 674,
          height: 425,
          closable: true,
          draggable: true,
          destroyOnClose: true
        }
      }
    );
  }
}
