// MSLL Javascript
//gloabl vars
var body_ref ;
var count=10;
var xml_response;
if (/WebKit/i.test(navigator.userAgent)) {
var safari=true;
}
var http = get_http_object();
//dean edwards onload{}
function init() {

    if (arguments.callee.done) return;
    arguments.callee.done = true;
    if (_timer) clearInterval(_timer);
	/* our stuff begins */

/*contact permission form, tests to see if it's set to yes and opens up the form fields */
	if (($('permissionToContactNo'))&&($('permissionToContactNo').checked==true)) {
		show("contactInfoLayer")
	}

	/*form stuff */

	/*these trigger omniture events */

if ($("trackInfoKitSignupInitiatedEvent")){
	setTimeout('trackInfoKitSignupInitiatedEvent()', 100);
}
if ($("trackInfoKitSignupCompletedEvent")){
setTimeout('trackInfoKitSignupCompletedEvent()', 100);
}
if ($("trackInfoKitSignupCompletedEventMembership")){
setTimeout('trackInfoKitSignupCompletedEvent()', 100);
}
if ($("trackNewsletterSignupInitiatedEvent")){
setTimeout('trackNewsletterSignupInitiatedEvent()', 500);
}
if ($("trackNewsletterSignupCompleteEvent")){
setTimeout('trackNewsletterSignupCompleteEvent()', 500);
}
if ($("trackNewsletterSignupCompletedEventMembership")){
setTimeout('trackNewsletterSignupCompleteEvent()', 500);
}
if ($("trackViewWebeventEvent")){
setTimeout('trackViewWebeventEvent()', 750);
}
if ($("trackWebeventRegistrationInitiatedEvent")){
setTimeout('trackWebeventRegistrationInitiatedEvent()', 1000);
}
if ($("trackWebeventRegistrationCompletedEvent")){
setTimeout('trackWebeventRegistrationCompletedEvent()', 1250);
}
if ($("trackMembershipEnrollmentInitiatedEvent")){
setTimeout('trackMembershipEnrollmentInitiatedEvent()', 500);
}

if(document.getElementById("exit-survey")){
	var exit = document.getElementById("exit-survey");
	exit.onclick=function() {
		box.show(document.getElementById("exit-message"));
		return false;
	}
};

if(document.body.className == "segmentation-survey"){
	$("menu").className="disabled";
	var menuLinks = $("menu").getElementsByTagName("a");
	for(i=0;i<menuLinks.length;i++){
		menuLinks[i].onclick=function(){
			return false;
		};
	};

	var checkLoadTimer = setInterval(function() {
        if ($("footer-nav")) {
			$("footer-nav").className="disabled";
			
			var footerLinks = $("footer-nav").getElementsByTagName("a");
			for(i=0;i<footerLinks.length;i++){
				footerLinks[i].onclick=function(){
					return false;
				};
			};
			clearInterval(checkLoadTimer);      
        }
    }, 100);
};

var box = {
	show : function(obj) {
		var cloakDiv = document.getElementById("cloak-div");
	    var closeButton = document.getElementById("btn-return-to-survey");
    	cloakDiv.style.visibility="visible"
    	obj.style.visibility="visible";
        box.position(obj);
        addEvent(window,"resize",function() {
			box.position(obj);
		 });
		addEvent(window,"scroll",function() {
			box.position(obj);
		 });
		closeButton.onclick=function() {
			box.hide(obj);
			return false;
		}
	},
	hide :  function(obj) {
		var cloakDiv = document.getElementById("cloak-div");
	    var closeButton = document.getElementById("btn-continue");
	    cloakDiv.style.visibility="hidden"
	    obj.style.visibility="hidden";
	    obj.style.left="-1000px";
		removeEvent(window,"resize",function() {
			box.position(obj);
		 });
		removeEvent(window,"scroll",function() {
			box.position(obj);
		 });
    },
    position : function(obj) {
	var cloakDiv = document.getElementById("cloak-div");
    var scrollOffset = new Array;
		if (self.pageYOffset){
			scrollOffset[0] = self.pageXOffset;
			scrollOffset[1] = self.pageYOffset;
		}
		else if (document.documentElement && document.documentElement.scrollTop){
			scrollOffset[0] = document.documentElement.scrollLeft;
			scrollOffset[1] = document.documentElement.scrollTop;
		}
		else if (document.body){
			scrollOffset[0] = document.body.scrollLeft;
			scrollOffset[1] = document.body.scrollTop;
		}
    	var docHeight = (typeof( window.innerHeight ) == 'number') ? docHeight = window.innerHeight : docHeight = document.documentElement.clientHeight;
    	var docWidth = (typeof( window.innerWidth ) == 'number') ? docWidth = window.innerWidth : docWidth = document.documentElement.clientWidth;
    	cloakDiv.style.height=(docHeight)+scrollOffset[1]+50+"px";
    	obj.style.left=(docWidth/2)-((obj.offsetWidth/2)+scrollOffset[0])+"px";
    	obj.style.top=(docHeight/2)-((obj.offsetHeight/2)+scrollOffset[1])+"px";
    }
};

if ($("login")) {
		old_login = $('login').innerHTML;
	}
	/*masthead controls */
	/*sets the function on the login control */
	if ($("login-button")){
		addEvent($("login-button"), "click",function() { open_login(); $('login-button').className='fake-button on';return false;});
	}
	if ($("register")){
		var anchor=$("register").getElementsByTagName("a")[0];
		addEvent($("register"), "click",function() {document.location.href=anchor.href});
		//bnp-addEvent($("login-button"), "click",function() { open_login(); $('login-button').className='fake-button on';return false;});
	}
	/*f there's a logout button, set its function */
	if ($('logout-button'))
		addEvent($('logout-control'), "click", function(){ ajax_login(this,'out');return false;});
	/*f there's a forgot password link, set its function */
	if ($('forgot')) addEvent($('forgot'), "click", function() { forgot();return false; });
	/*font controllers */
	if ($('font-size-1')) {
	addEvent($('font-size-1'), "click", function() { font_size(1);trackChangeFontSizeEvent('1');return false;});
	addEvent($('font-size-2'), "click", function() { font_size(2);trackChangeFontSizeEvent('2');return false;});
	addEvent($('font-size-3'), "click", function(){ font_size(3);trackChangeFontSizeEvent('3');return false;})
	}
	check_cookie();
	/*sets a ref to the body*/
	body_ref=document.body;
	/*a couple of IE hacks*/
	/*@cc_on @*/
	/*@if (@_jscript_version <= 5.6)
		set_nav("menu");
	if ($('left-col-ads')) {
		if ($('navigation')) {
			var theNewHeight = (document.getElementById("left-col-ads").offsetHeight + document.getElementById("navigation").offsetHeight + 25);
			if (document.getElementById("main-content").offsetHeight < theNewHeight){
				document.getElementById("main-content").style.height = theNewHeight + "px";
			}
		}
	};

	if ($('ads')) {
		var theNewHeight = (document.getElementById("ads").offsetHeight + 80);
		if (document.getElementById("main-content").offsetHeight < theNewHeight){
			document.getElementById("main-content").style.height = theNewHeight + "px";
		}
	};
	/*@end @*/
	/*@cc_on @*/
	/*@if (@_win32)
  	document.execCommand("BackgroundImageCache", false, true);
	/*@end @*/
	/* set button mouseovers */
	if ($('form-page')) set_buttons();
	/*Set bubbles on archive pages*/
	if ($('archives')||$('archives2'))	setDescriptions();
	/*sets the function of the login form */
	if ($('form1')) addEvent($('form1'),"submit",function(){ajax_login(this,'in');return false});
	if ($('left-col-ads')) {
		if ($('navigation')) {
			var theNewHeight = (document.getElementById("left-col-ads").offsetHeight + document.getElementById("navigation").offsetHeight + 25);
			if (document.getElementById("main-content").offsetHeight < theNewHeight){
				document.getElementById("main-content").style.minHeight = theNewHeight + "px";
				/*@cc_on @*/
				/*@if (@_win32)
					document.getElementById("main-content").style.height = theNewHeight + "px";
				/*@end @*/
			}
		}
	};

	if ($('ads')) {
		var theNewHeight = (document.getElementById("ads").offsetHeight + 80);
		if (document.getElementById("main-content").offsetHeight < theNewHeight){
			document.getElementById("main-content").style.minHeight = theNewHeight + "px";
		}
	};

	if ($('authorize')) {
		var authorizeCheck = $('authorize').getElementsByTagName('input')[0];
		addEvent(authorizeCheck, "click", function() { manageChecks(this) });
		manageChecks(authorizeCheck);
	};

	if ($('archives')) {
		var archiveItems = getElementsByClass('archive-item');
		for (var i = 0; i < archiveItems.length; i += 2) {
			addClass(archiveItems[i],"even");
		}
	};

	if ($('category-anchors')) {
		var temp = $('main-content').removeChild($('category-anchors'));
		$('main-content').insertBefore(temp,$("category-placeholder"));
	};
	if (getElementsByClass('privacy-policy')){
		var privacypolicy = getElementsByClass('privacy-policy');
		for (var i=0; i < privacypolicy.length; i++) {
			addEvent(privacypolicy[i],"click",function() { window.open(this.href,'popup','width=950,height=600,scrollbars=yes',true);return false});
		}
	};
	/*Build glossary links*/
	var glossary;
	glossary = getElementsByClass('glossary');
	if(document.body.className != "segmentation-survey"){
		for (var i=0; i < glossary.length; i++){
			if (glossary[i].className=="glossary animation"){
				if (glossary[i].rel){
					args=glossary[i].rel;
					addEvent(glossary[i],"click", function() { trackInternalCampaignClick(args);window.open(this.href,'animation','width=640,height=510,scrollbars=no',true);return false});
				}
				else {
					addEvent(glossary[i],"click", function() { window.open(this.href,'animation','width=640,height=510,scrollbars=no',true);return false } );
				}
			}
			else if (glossary[i].className=="glossary assessment") {
				addEvent(glossary[i],"click", function() { window.open(this.href,'assessment','width=720,height=600,scrollbars=no',true);return false } );
			}
			else {
				var thelink = glossary[i].href;
				if (thelink.indexOf("#") ==-1) {
					addEvent(glossary[i],"click", function() { window.open( this.href ,'popup','width=640,height=400,scrollbars=yes',false );return false } );
					
				}
				else {
					
					thehash=getEnd(thelink,"#");
					if (thelink.indexOf("?") > -1) {
						thechar="&"
					}
					else {
						thechar="?"
					}
					thenewlink = searchAndReplace(thelink,"#"+thehash,'')+thechar+"term="+thehash+"#"+thehash;
					addEvent(glossary[i],"click", function() { window.open( thenewlink ,'popup','width=640,height=400,scrollbars=yes',false );return false } );
				}
			}
		}
	};
	
	var externalLinks = getElementsByClass('external');
	for (var i=0; i<externalLinks.length; i++) {
		externalLinks[i].target = "_blank";
	};
	
	
	/*build PDF links */
	var pdfs = getElementsByClass('pdflink');
	for (var i=0; i < pdfs.length; i++) {
		if (pdfs[i].rel) {
			args=pdfs[i].rel
			addEvent(pdfs[i],"click",function() { trackInternalCampaignClick(args),window.open(this.href,'pdf','width=640,height=400,scrollbars=yes,resizable=yes',true);return false });
		} else {
			addEvent(pdfs[i],"click",function() { window.open(this.href,'pdf');return false });

		}
	}
	var vids = getElementsByClass('video-popup');
	for (var i=0; i < vids.length; i++) {

			addEvent(vids[i],"click",function() { spanishVidPopup(this);return false });
			}




	/* add event handler to spawn pop-up for clicked on tech support links */
	var support = getElementsByClass('webevent-support-link');
	for (var i=0; i < support.length; i++) {
		addEvent(support[i],"click",function() { window.open(this.href,'popup','width=495,height=490,scrollbars=yes',true);return false });
	}
	var support = getElementsByClass('view-webcast');
	for (var i=0; i < support.length; i++) {
		addEvent(support[i],"click",function() { window.open(this.href,'popup','width=500,height=490,scrollbars=no',true);return false });
	}
//stops a "double-click" double form submissionS
	if ($("REG_FORM:reg-button")) {
		  addEvent($("REG_FORM:reg-button"), "click", working);
		  addEvent($("REG_FORM:reg-button"), "click", stopIt);
	}
	if ($("REG_FORM:create-account")) {
		  addEvent($("REG_FORM:create-account"), "click", working);
		  addEvent($("REG_FORM:create-account"), "click", stopIt);
	}

	if ($("REG_FORM:btn-request-info-kit")) {
		  addEvent($("REG_FORM:btn-request-info-kit"), "click", working);
		  addEvent($("REG_FORM:btn-request-info-kit"), "click", stopIt);
	}

	if ($("newsletterForm:btn-sign-up")) {
			addEvent($("newsletterForm:btn-sign-up"), "click", working);
		  addEvent($("newsletterForm:btn-sign-up"), "click", stopIt);
	}
	if ($("newsletterForm")) {

		  addEvent($("newsletterForm"), "submit", working);
	}
	if ($("REG_FORM")) {

		  addEvent($("REG_FORM"), "submit", working);
	}

//END INIT
};

if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", init, false);
}
/*@cc_on @*/
/*@if (@_win32)
(function () {
	try {
		document.documentElement.doScroll('left');
	} catch (e) {
		setTimeout(arguments.callee, 50);
		return;
	}
	// no errors, fire
	init();
})();
/*@end @*/
if (safari) { // sniff

	var _timer = setInterval(function() {
        if (/loaded|complete/.test(document.readyState)) {
        }
    }, 10);
}
window.onload = init;

//library functions //
function addEvent(element, type, handler) {
	if (!handler.$$guid) handler.$$guid = addEvent.guid++;
	if (!element.events) element.events = {};
	var handlers = element.events[type];
	if (!handlers) {
		handlers = element.events[type] = {};
		if (element["on" + type]) {
			handlers[0] = element["on" + type];
		}
	}
	handlers[handler.$$guid] = handler;
	element["on" + type] = handleEvent;
};
addEvent.guid = 1;
function removeEvent(element, type, handler) {
	if (element.events && element.events[type]) {
		delete element.events[type][handler.$$guid];
	}
};
function handleEvent(event) {
	var returnValue = true;
	event = event || fixEvent(window.event);
	var handlers = this.events[event.type];
	for (var i in handlers) {
		this.$$handleEvent = handlers[i];
		if (this.$$handleEvent(event) === false) {
			returnValue = false;
		}
	}
	return returnValue;
};
function fixEvent(event) {
	event.preventDefault = fixEvent.preventDefault;
	event.stopPropagation = fixEvent.stopPropagation;
	return event;
};
fixEvent.preventDefault = function() {
	this.returnValue = false;
};
fixEvent.stopPropagation = function() {
	this.cancelBubble = true;
};
function getFirstChild(element) {
    element = element.firstChild;
    return element && element.nodeType != 1 ? nextSibling(element) : element;
};
function getPreviousSibling(element) {
    do {
        element = element.previousSibling;
    } while ( element && element.nodeType != 1 );
    return element;
};
function getNextSibling(element) {
    do {
        element = element.nextSibling;
    } while ( element && element.nodeType != 1 );
    return element;
};
function getLastChild(element) {
   element = elem.lastChild;
    return element && element.nodeType != 1 ? prevSibling(element) : element;
};
function addClass(element, className) {
    if (!hasClass(element, className)) {
      element.className += (element.className ? " " : "") + className;
    }
};
function hasClass(element, className) {
    var regexp = new RegExp("(^|\\s)" + className + "(\\s|$)");
    return regexp.test(element.className);
};

function removeClass(element, className) {
    var regexp = new RegExp("(^|\\s)" + className + "(\\s|$)", "g");
    element.className = trim(element.className.replace(regexp, "$2"));
};

function toggleClass(element, className) {
    if (hasClass(element, className)) {
      removeClass(element, className);
    } else {
      addClass(element, className);
    }
};
function getText(e) {
    var t = "";
	e = e.childNodes || e;
	for ( var j = 0; j < e.length; j++ ) {
        t += e[j].nodeType != 1 ?
            e[j].nodeValue : text(e[j].childNodes);
    }
    return t;
};
function trim(string) {
  return string.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
};
function getElementsByClass(searchClass,node,tag)
{
    var classElements = new Array();
    if ( node == null )
        node = document;
    if ( tag == null )
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
    for (i = 0, j = 0; i < elsLen; i++)
    {
        if ( pattern.test(els[i].className) )
        {
            classElements[j] = els[i];
            j++;
        }
    }
return classElements;
}
//An image preloader //
function preload_images(){
	var pics = new Array()
	for(var i=0;i<arguments.length;i++){
        pics[i]=new Image();
        pics[i].src=arguments[i];
		}
 }
 //ppk scripts that I use all the time
function findPosTop(obj)
{
    var curtop = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curtop += obj.offsetTop;
			obj = obj.offsetParent;

        }
    }
    else if (obj.y)
        curtop += obj.y;
        return curtop;
}
function findPosLeft(obj)
{
    var curleft = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        	}
    }
    else if (obj.x)
        curleft += obj.x;
        return curleft;
}

function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}


function setFunction(theObj,theEventHandler,theFunction)
{
    if (typeof theObj == "string")
    {
        theObj = $(theObj);
    }
    theObj.setAttribute(theEventHandler,theFunction);
    if (theObj[theEventHandler])
    {
		theObj[theEventHandler]=new Function(theFunction);
    }
}
function insertAfter(parent, node, referenceNode) {
	 parent.insertBefore(node, referenceNode.nextSibling);
};
/*a cookie class. From Javascript: the definitve guide */
function Cookie(name)
{
this.$name= name;
var allcookies = document.cookie;
if (allcookies=="") return;
var cookies = allcookies.split(';');
var cookie = null;
	for (var i=0;i<cookies.length; i++)
	{
		if (cookies[i].substring(0, name.length+1) == (name+"="))
		{
			cookie=cookies[i];
			break;
		}
	}

if (cookie==null) return;
var cookieval=cookie.substring(name.length+1)
var a= cookieval.split('&');
	for (var i=0; i< a.length; i++)
	{
		this[a[i][0]] = decodeURIComponent(a[i][1]);
	}
}

Cookie.prototype.store = function(daysToLive, path, domain, secure) {
var cookieval="";
	for (var prop in this)
	{
		if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function'))
		continue;
		if (cookieval != "") cookieval += "&";
		cookieval +=prop + ":" +encodeURIComponent(this[prop]);
	}
var cookie = this.$name + "=" + cookieval;
	if (daysToLive || daysToLive ==0)
	{
		cookie +="; max-age=" + (daysToLive*24*60*60);
	}
if (path) cookie += "; path="+path;
if (domain) cookie += "; domain="+domain;
if (secure) cookie += "; secure"
document.cookie = cookie;
}

Cookie.prototype.remove = function(path, domain, secure) {
	for (var prop in this)
	{
		if(prop.charAt(0) != '$' && typeof this[prop] != 'function')
		delete this[prop]
	}
this.store(0, path, domain, secure);
}

Cookie.enabled= function() {
if (navigator.cookieEnable != undefined) return navigator.cookieEnabled;
if (Cookie.enabled.cache != undefined) return Cookie.enabled.cache;
document.cookie = "testcookie-test; max-age=100000";
var cookies= document.cookie;
	if (cookies.indexOf(textcookie-test) == -1) {
		return Cookie.enabled.cache= false;
	}
	else
	{
		document.cookie = "testcookie-test;max-age=0";
		return Cookie.enabled.cache= true;
	}
}

//end library functions//


//msll functions
var stopIt = function() {
	this.onclick = function(){ return false; }
};

function addParam(url, paramName, paramValue) {
 if(url == "") {
 	return "?" + paramName + "=" + paramValue;
 } else {
	return "&" + paramName + "=" + paramValue;
 }
}
/*open and close the login */
function open_login() {
	$("login-button").onclick =  function() {
		close_login();
		$('login-button').className='fake-button';
		return false;
	}
	count=10;
	if (count<=100) {
setTimeout("fadeup("+count+")",10);
	}
}
function close_login() {
	$("login-button").onclick =  function() {
	open_login();
	$('login-button').className='fake-button on';
	return false
	}
	count=100;
	if (count>0) {
		setTimeout("fadedown("+count+")",10);
	}
	setTimeout("replace_login()",1000);
}
function replace_login(){
	$('login').innerHTML = old_login;
	addEvent($('forgot'), "click", function() { forgot();return false; });
}
function init_login() {
	$('form1').onsubmit = function() {
		ajax_login(this,'in');
		return false
	};
}
/*get ajaxy*/
function ajax_login(the_obj,method) {
	var remember = "N"
	if ($('remember') && $('remember').checked==true){
		remember="Y"
	}
	if (method=="in"){
		the_link=""+root_path+"/api/auth/signin?username="+$('username').value+"&password="+$('pass').value+"&remember="+remember+"";
		response_function= "process_login()"
	}
	if (method=="forgot"){
		the_link=""+root_path+"/api/auth/forgot?username="+$('forgot-username').value+"";
		response_function= "process_forgot()"
	}
 	else if (method=="out"){
		the_link=""+root_path+"/api/auth/signout";
		response_function= "process_logout()"
	}
	if((http.readyState==0)||(http.readyState==4)){
		try
   			{
			    http.open("GET", the_link, true);
			    http.onreadystatechange = function()
    	   		{
  				    if ((http.readyState == 4)&&(http.status==200)&&(http.responseXML!=null))
        	        {
						xml_response = http.responseXML
						eval(response_function);
					}
				}
    	       http.send(null);
    		}
		catch(e)
    	{
		}
	}
}
/*process the login response */
function process_login(){
	login_status = xml_response.getElementsByTagName("status")[0].childNodes[0].nodeValue;

	if ((login_status==200)||(login_status==201)){
		trackLoginEvent();
		var userUpdateProfileReqired = xml_response.getElementsByTagName("userUpdateProfileReqired")[0].childNodes[0].nodeValue;
		if (userUpdateProfileReqired == "true"){
			location.replace(root_path + "/member/reg/profile.jsf");
		}
		else
			location.reload(true);
		}
	else {
		login_bubble($('username'));
		$('login-messaging').innerHTML=$('login-error').innerHTML
	}
}
/*process the logout response */
function process_logout(){
	login_status = xml_response.getElementsByTagName("status")[0].childNodes[0].nodeValue
	if (login_status==200){
		var cookie = new Cookie("login");
		cookie.remove("login");
		cookie.store("Tue, 28 Apr 1970 15:18:29 GMT","/");
		location.href=root_path+"/index.jsf";
	}
}
/*process the forgot response */
function process_forgot(){
	login_status = xml_response.getElementsByTagName("status")[0].childNodes[0].nodeValue
	if (login_status==200)
	{
		$('login').innerHTML=$('forgot-password-success').innerHTML;
		$('form2').onsubmit= function() { ajax_login(this,'in');return false };
	}
	else
	{
		login_bubble($('forgot-username'));
		$('login-messaging').innerHTML=$('forgot-password-unknown-username').innerHTML
	}
}

function forgot(){
	$('login').innerHTML=$('forgot-password-form').innerHTML;
	$('forgot-form').onsubmit=function() { ajax_login(this,'forgot');return false } ;
}
function set_buttons() {
	if ($('continue-button'))
	{
		$("continue-button").onmouseover=function() { this.className='hovered' };
		$("continue-button").onmouseout=function() { this.className='focused'};
	}
	if ($('cancel-button'))
	{
		$("cancel-button").onfocus=function() { this.className='focused' }
		$("cancel-button").onblur=function() { this.className=''}
		$("cancel-button").onmouseover=function() { this.className='hovered'};
		$("cancel-button").onmouseout=function() { this.className=''};
	}
}

/*
// function hide_bubble(obj)
//   Used to hide the login bubble.
// Params-
//   obj: Object of bubble to collapse
//     Used to hide bubble popup
*/
function hide_bubble(obj)
{
	obj.style.visibility ='hidden';
	
	return false;
}

function build_bubbles()
{
	new_div = document.createElement("DIV");
	new_div.setAttribute("id","bubble");
	body_ref.appendChild(new_div);
	$("bubble").innerHTML='<div class="bubble-top"><div id="bubble-content">filler</div></div><div class="bubble-bottom"></div><a class="close-button" href="#" onclick="hide_bubble(this.parentNode)"></a><a id="view-webevent" href=""></a>'
		
	tt_divs=getElementsByClass('description');
	/*for (var i in tt_divs)
	{
		tt_divs[i].style.display='none';
	}*/
	dts = document.getElementsByTagName('dt');
	for (i=0; i<dts.length; i++)
	{
		the_link=dts[i].getElementsByTagName("a")[0].href;
		next_node = dts[i].nextSibling;
		if (next_node.tagName=="DD")
		{
			the_desc = escape(next_node.getElementsByTagName("DIV")[0].innerHTML);
		}
		else
		{
			while (next_node.tagName != "DD")
			{
				next_node=next_node.nextSibling;
			}
			the_desc = escape(next_node.getElementsByTagName("DIV")[0].innerHTML);

		}
	if (dts[i].getElementsByTagName("a")[0].rel=="trackWebeventRegistrationInitiatedEvent") {
	setFunction(dts[i].getElementsByTagName("a")[0],"onmouseover","the_obj=this;timer=setTimeout(\"bubble(the_obj,'"+the_link+"','"+the_desc+"',true)\",500)")
	}
	else {	setFunction(dts[i].getElementsByTagName("a")[0],"onmouseover","the_obj=this;timer=setTimeout(\"bubble(the_obj,'"+the_link+"','"+the_desc+"')\",500)")
	}
	}
}

function bubble(the_obj,the_link,the_desc, extra) {
	$("bubble").style.visibility="visible";
	$("bubble-content").innerHTML=unescape(the_desc);
	var posx=findPosTop(the_obj)-100;
	var posy=findPosLeft(the_obj)+320;
	$("bubble").style.top=posx+"px";
	$("bubble").style.left=posy+"px";
	$("view-webevent").href=the_link;
	/*eventually we will make this anonymous, grabbing the onclick event handler on the webevent link. For now? Hard coding it. */
if (extra==true){
	// looks like a scoping issue with "the_link" not being available in the function below.  Reassinging into "onClickLink" seems to fix it.
	onClickLink = the_link;
setFunction($("view-webevent"), "click","setTimeout('trackViewWebeventInitiatedEvent()', 100); setTimeout('trackWebeventRegistrationInitiatedEvent()', 650); setTimeout('document.location.href=\"' + onClickLink + '\"', 1200); return false;")
} else {
	setFunction($("view-webevent"), "click","trackViewWebeventInitiatedEvent();");
}
}

function login_bubble(the_obj)
{
	if ($('login-bubble')) {
		$('login-bubble').style.visibility="visible"
	} else {
		new_div = document.createElement("DIV");
		new_div.setAttribute("id","login-bubble");
		body_ref.appendChild(new_div);
		$("login-bubble").innerHTML='<div  id="login-messaging"></div><a class="close-button" href="#" onclick="this.parentNode.style.visibility=\'hidden\';return false"></a>'
	}
	var posx=findPosTop(the_obj);
	var posy=findPosLeft(the_obj);
	$("login-bubble").style.top=posx+30+"px";
	$("login-bubble").style.left=posy-75+"px";
}
function fadeup(count){
	pixel_offset=count/2
	body_ref.style.backgroundPosition="0 "+pixel_offset+"px";
	$("login").style.marginTop="-"+(50-pixel_offset)+"px"
	/*@cc_on @*/
	/*@if (@_win32)
	$("login").style.filter="alpha(opacity="+(count)+")";
	if ($("login-submit")){
		$("login-submit").style.filter="alpha(opacity="+(count)+")";
	}
	/*@end @*/
	if (count<100) {
		$("login").style.opacity="."+count
		if ($("login-submit")){
			$("login-submit").style.opacity="."+count
		}
	}
	else if (count==100){
		$("login").style.opacity="1";
		if ($("login-submit")){
			$("login-submit").style.opacity="1"
		}
	}
	count=count+10;
	if (count<=100) {
		setTimeout("fadeup("+count+")",10);
	}
}
function fadedown(count){
	count=(count-10);
	margin_offset=50-(count/2)
	if ($('login-bubble'))
		hide_bubble($('login-bubble') );
	
	body_ref.style.backgroundPosition="0 "+count/2+"px";
	$("login").style.marginTop="-"+margin_offset+"px";
	/*@cc_on @*/
	/*@if (@_win32)
		$("login").style.filter="alpha(opacity="+count+")";
		if ($("login-submit")){
			$("login-submit").style.filter="alpha(opacity="+count+")";
		}
	/*@end @*/
	$("login").style.opacity="."+count
	if ($("login-submit")){
		$("login-submit").style.opacity="."+count
	}
	if (count>0) {
		setTimeout("fadedown("+count+")",10);
	}
	else {
		/*@cc_on @*/
		/*@if (@_win32)
				$("login").style.filter="alpha(opacity=0)";
				if ($("login-submit")){
					$("login-submit").style.filter="alpha(opacity=0)";
				}
		/*@end @*/
		$("login").style.opacity=".00"
	}
}

// Test a string to see if it matches an email address //
function test_email(the_string)
{
	email_pattern = new RegExp("/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/");
	return(email_pattern.test(the_string));
}

function font_size()
{
var size=arguments[0]
	if (size==1)
	{
				$("font-styles").href=root_path+"/_assets/styles/normal.css"
		font_cookie(1);
		$('font-size-1').className="on";
		$('font-size-2').className="";
		$('font-size-3').className="";

	}
	else if (size==2)
	{
		$("font-styles").href=root_path+"/_assets/styles/bigger.css"
		font_cookie(2);
		$('font-size-1').className="";
		$('font-size-2').className="on";
		$('font-size-3').className="";
	}
	else if (size==3)
	{
		$("font-styles").href=root_path+"/_assets/styles/biggest.css"
		font_cookie(3);
		$('font-size-1').className="";
		$('font-size-2').className="";
		$('font-size-3').className="on";
	}
}

function font_cookie()
{
//	var allcookies=document.cookie;
	//if (allcookies.indexOf("font-preference") !=-1) alert("woot")

	var cookie = new Cookie("font-preference");
	cookie.remove("font-preference")
	if (!cookie.fontSize){
		cookie.fontSize = arguments[0];
	}
	cookie.store(10000,"/")
}

function check_cookie()
{
var allcookies=document.cookie;
var pos = allcookies.indexOf("fontSize:")
	if (pos!=-1)
	{
		var start= pos + 9
		var end = allcookies.indexOf(";",start);
		if (end ==-1) end = allcookies.length;
		var value = allcookies.substring(start,end);
		value = decodeURIComponent(value)
		if (value==2)
		{
			font_size(2)
			$('font-size-1').className="";
			$('font-size-2').className="on";
			$('font-size-3').className="";
		}
		else if (value==3) {
			font_size(3)
			$('font-size-1').className="";
			$('font-size-2').className="";
			$('font-size-3').className="on";
		}
	}
}




function get_http_object()
{
	var xmlhttp;
	try
	{
	//generic
		xmlhttp = new XMLHttpRequest();
	}
	catch(er)
	{
	//Internet Explorer active x equivalent
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xmlhttp;
}

function show(obj) {
  	$(obj).style.display = 'block';
	}

function hide(obj) {
	$(obj).style.display = 'none';
}

function getEnd(mainStr,searchStr) {
   foundOffset = mainStr.indexOf(searchStr);
   if (foundOffset == -1) {
      return null;
   }
   return mainStr.substring(foundOffset+searchStr.length,mainStr.length);
}

function searchAndReplace(holder, searchfor, replacement)
{
    temparray = holder.split(searchfor);
    holder = temparray.join(replacement);
    return (holder);
}
// cancel form submission handler
function confirmCancel(m, cancelRequest)
{
	var msg = m;
	if(msg == null) msg = "Are you sure?\nTo leave the form without saving your changes, click OK\nTo go back to the form and continue working, click CANCEL";
	if(window.confirm(msg))
	{
		window.location = cancelRequest; return;
	}
	else
	{
		return;
	}
}

function spanishVidPopup(page) {
	newWin = window.open(page,'playerPopup','width=285,height=600,scrollbars=no');
	newWin.focus();
}

function setDescriptions() {
	var controls =getElementsByClass("description-control");
	for (var i=0; i<controls.length; i++) {
			controls[i].onclick=openDescription;
		}
	};

function openDescription(){
		var desc = getNextSibling(this.parentNode);
		addClass(desc,"open");
		this.onclick=closeDescription;
		this.innerHTML="Hide Description";
		return false;

	}
function closeDescription(){
		var desc = getNextSibling(this.parentNode);
		removeClass(desc,"open");
		this.onclick=openDescription;
		this.innerHTML="View Description";
		return false;

	}

function manageChecks(authorizeCheck){
	var theCheckboxes = getElementsByClass("check");

	if(authorizeCheck.checked == true){
		for (var i = 0; i < theCheckboxes.length; i++) {
			theCheckboxes[i].disabled = false;
		}
	}

	else{
		for (var i = 0; i < theCheckboxes.length; i++) {
			theCheckboxes[i].disabled = true;
			theCheckboxes[i].checked = false;
		}
	}
}

function validateZip (zipcode){

	var zip = zipcode.value;
	var regexp = new RegExp("^[0-9]{5}");
	if (zip == ""){ return false; }
	if (regexp.test(zip)){
		removeClass(zipcode,"error");
		$("zipcode-error").style.display = "none";
	}
	else{
		/*@cc_on @*/
	/*@if (@_jscript_version <= 5.6)

	zipcode.parentNode.parentNode.style.height= zipcode.parentNode.parentNode.offsetHeight + 20 +"px";
		/*@end @*/

		addClass(zipcode,"error");
		$("zipcode-error").style.display = "block";
	}
}

function validateEmail(emailAddress){
	var email = emailAddress.value;
	if (email == ""){ return false; }
	var regexp1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var regexp2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	if (!regexp1.test(email) && regexp2.test(email)){
			removeClass(emailAddress,"error");
			$("email-error").style.display = "none";
			/*@cc_on @*/
	/*@if (@_jscript_version <= 5.6)
		if (emailAddress.parentNode.parentNode.style.height != ""){
			emailAddress.parentNode.parentNode.style.height=parseInt(emailAddress.parentNode.parentNode.style.height)-20+"px";
		}
		/*@end @*/
	}
	else{
		addClass(emailAddress,"error");
					/*@cc_on @*/
	/*@if (@_jscript_version <= 5.6)
		if (emailAddress.parentNode.parentNode.style.height == ""){
			emailAddress.parentNode.parentNode.style.height=emailAddress.parentNode.parentNode.offsetHeight+20+"px";
		}
		/*@end @*/
		$("email-error").style.display = "block";
	}
}

function validateEmailMatch(emailAddress){
	var email = getElementsByClass("email");
	if (email[0].value != "" && email[1].value != "") {

		if (email[0].value.toLowerCase() == email[1].value.toLowerCase()){

			removeClass(email[1],"error");
			$("email-match-error").style.display = "none";
						/*@cc_on @*/
		/*@if (@_jscript_version <= 5.6)
			if($("email-match-error").parentNode.parentNode.style.height != "") {
					$("email-match-error").parentNode.parentNode.style.height = parseInt($("email-match-error").parentNode.parentNode.style.height) -20 +"px"
				};
					/*@end @*/
			return true;
		}
		else{
			addClass(email[1],"error");
			$("email-match-error").style.display = "block";

		}
	}
}

function validatePassword(password){
	var thePassword = password.value;
	if (thePassword == ""){ return false; }
	var regexp = /^.*(?=.{4,10})(?=.*\d)(?=.*[a-zA-Z]).*$/
	if (regexp.test(thePassword)){
		removeClass(password,"error");
		$("password-error").style.display = "none";
	}
	else{
		addClass(password,"error");
		$("password-error").style.display = "block";
	}
}

function validatePasswordMatch(){
	var passwords = getElementsByClass("password");
	if (passwords[0].value != "" && passwords[1].value !="" ) {
		if (passwords[0].value == passwords[1].value){
			removeClass(passwords[1],"error");
			$("passwords-match-error").style.display = "none";
			return true;
		}
		else{
			addClass(passwords[1],"error");
			$("passwords-match-error").style.display = "block";
		}
	}
}

function working(){

	document.body.innerHTML+='<div id="working-spinner"><img src="'+ root_path +'/_assets/images/ajax-loader.gif"/><span>Working...</span></div>';
	$("working-spinner").style.left=findPosLeft($("form-wrapper"))+$("form-wrapper").offsetWidth-$("working-spinner").offsetWidth+"px";
	/*a couple of IE hacks*/
	/*@cc_on @*/
	/*@if (@_jscript_version <= 5.6)
	$("working-spinner").style.top=document.documentElement.scrollTop+"px";
	addEvent(window, "resize", function(){
										$("working-spinner").style.top=document.documentElement.scrollTop+"px";	$("working-spinner").style.left=findPosLeft($("form-wrapper"))+$("form-wrapper").offsetWidth-$("working-spinner").offsetWidth+"px";
																																																				   });

	addEvent(window, "scroll", function(){ $("working-spinner").style.top=document.documentElement.scrollTop+"px";	});
	/*@end @*/

};

function updatePage(wishId){
var question = CramerMessaging.messaging[wishId].question;
	var stopWishing = CramerMessaging.messaging[wishId].stopWishing;
	var startLearning = CramerMessaging.messaging[wishId].startLearning;
	var askYourDoctor = CramerMessaging.messaging[wishId].askYourDoctor;
	var fileName = "url(_assets/styles/images/ambassador-"+ wishId +".jpg) no-repeat top right";

	jQuery('#question').html(question);
	jQuery('#stop-wishing').html(stopWishing);
	jQuery('#start-learning').html(startLearning);
	jQuery('#ask-your-doctor').html(askYourDoctor);
	jQuery('#messaging-copy').css("background",fileName);
	jQuery('#messaging-copy').fadeIn(2000, function(){
		jQuery('#messaging').css("background",fileName);
	});

	var updater = function() {
		jQuery('#messaging-copy').fadeOut(500, function() {
			updatePage(wishId);
		})

		if (wishId == 2){
			wishId = 0;
		}
		else{
			wishId = wishId + 1;
		};
	};
	var FadeTimeout = setTimeout(updater ,10000);
}

var checkNoneFlag = 0;
function checkNone(e, formName, noneVal) {
if(checkNoneFlag!=0) {
	return;
}
	checkNoneFlag=1;
	var elements = document.forms[formName];
	for(i=0; i<elements.length; i++) {
		if(elements[i].type == 'checkbox') {
			if(e.value == noneVal && e.checked && elements[i].value != noneVal) {
				if(elements[i].checked) {
					elements[i].click();
				}
			} else if(e.value != noneVal && e.checked && elements[i].value == noneVal) {
				if(elements[i].checked) {
					elements[i].click();
				}
			}
		}
	}
checkNoneFlag=0;
}

function disableIt(e, formName) {
	var elements = document.forms[formName];
	for(i=0; i<elements.length; i++) {
		if(elements[i].type != 'checkbox' && elements[i].type != 'submit') {
			elements[i].disabled = e.checked;
		}
	}
}