function formHighlightAndActionUrlSet(obj, actionUrl)
{
	// set actionUrl hidden input field
	var actionUrlHiddenInput = document.getElementById("actionUrl")
	if (!actionUrlHiddenInput) {
		var hiddenInput = document.createElement("input");
		hiddenInput.id = "actionUrl";
		hiddenInput.setAttribute("type", "hidden");
		hiddenInput.setAttribute("name", "actionUrl");
		document.forms[0].appendChild(hiddenInput);
		actionUrlHiddenInput = hiddenInput;
	}
	actionUrlHiddenInput.value = actionUrl;
	
	if (document.getElementsByTagName && obj == 'free')
	{
		var allDivs = document.getElementsByTagName('div');

		for (var i = 0; i < allDivs.length; i++)
		{
			if (allDivs[i].className == 'regFormHighlight')
			{
				highlight = allDivs[i];
				highlight.style.backgroundColor = '#faf6eb';
				setTimeout('setRegistrationFormFocus()',1);
			}
		}
	}
	if (document.getElementsByTagName && obj == 'premium')
	{
		var allDivs = document.getElementsByTagName('div');

		for (var i = 0; i < allDivs.length; i++)
		{
			if (allDivs[i].className == 'regFormHighlight')
			{
				highlight = allDivs[i];
				highlight.style.backgroundColor = '#f9efee';
				setTimeout('setRegistrationFormFocus()',1);
			}
		}
	}
}

function setRegistrationFormFocus() {
	document.getElementById('ctl00_BodyPH_gridContent_callToAction_ctl00_firstName').focus();
}

function openPopUp (u,w,h,options) {
	var popWin = window.open(u,'mqk','width='+w+',height='+h+','+options);
	popWin.focus();
}

function selectAllAlerts (where,sender) {
	for (y=0;y<3;y++) {
		var target = document.getElementById(where + y);
		var inputs = target.getElementsByTagName('input').length;
		for (x=0;x<inputs;x++) {
			if (document.getElementById(sender).checked == true) {
				target.getElementsByTagName('input')[x].checked = true;
			} else {
				target.getElementsByTagName('input')[x].checked = false;
			}	
		}
	}
}

/* get date for global header */

function getDateEN() {
	var d=new Date()
	var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
	var now = (d.getDate() + " " + monthname[d.getMonth()] + " " + d.getFullYear());

	if (document.getElementById('clientDate')) {
		document.getElementById('clientDate').innerHTML = now;
	}
}

function getDateCN (yearSymbol, monthSymbol, dateSymbol) {
    var d=new Date();    
    var now = (d.getFullYear() + yearSymbol + (d.getMonth()+1) + monthSymbol + d.getDate() + dateSymbol);
	
	if (document.getElementById('clientDate')) {
		document.getElementById('clientDate').innerHTML = now;
	}    
}

/* style switching for articles text courtesy of a list apart */

function setTextSize (way) {
	var which = getActiveStyleSheet();
	if (which == null) {
		which = 'sheet1';
	}
	var x = which.substring(5);
	if (way == 'larger') {
		if (x != 3) {
			if (x == '1') document.getElementById('decSize').className = 'decrease';
			var name = 'sheet' + (parseInt(x) + 1);
			if (name == 'sheet3') document.getElementById('incSize').className = 'top increaseDisabled';
			setActiveStyleSheet(name);
		}
	} else if (way == 'smaller') {
		if (x != 1) {
			if (x == '3') document.getElementById('incSize').className = 'top increase';
			var name = 'sheet' + (parseInt(x) - 1);
			if (name == 'sheet1') document.getElementById('decSize').className = 'decreaseDisabled';
			setActiveStyleSheet(name);
		}
	}
	return false;
}

function setTextSize (way, incSize, decSize) {
   	var which = getActiveStyleSheet();
	if (which == null) {
		which = 'sheet1';
	}
	var x = which.substring(5);
	if (way == 'larger') {
		if (x != 3) {
			if (x == '1') document.getElementById(decSize).className = 'decrease';
			var name = 'sheet' + (parseInt(x) + 1);
			if (name == 'sheet3') {
			    document.getElementById(incSize).className = 'top increaseDisabled';
			}
			setActiveStyleSheet(name);
		}
	} else if (way == 'smaller') {
		if (x != 1) {
			if (x == '3') document.getElementById(incSize).className = 'top increase';
			var name = 'sheet' + (parseInt(x) - 1);
			if (name == 'sheet1') document.getElementById(decSize).className = 'decreaseDisabled';
			setActiveStyleSheet(name);
		}
	}
}

function applyArticleToolsStyle( incSize, decSize ) { 
    var which = getActiveStyleSheet();
	if (which == null) {
		which = 'sheet1';
	}
    var x = which.substring(5);
    if( x == '3' ) {
        document.getElementById(incSize).className = 'top increaseDisabled';
        document.getElementById(decSize).className = 'decrease';
    } else if( x == '2' ) {
        document.getElementById(incSize).className = 'top increase';
        document.getElementById(decSize).className = 'decrease';
    }
}

function setActiveStyleSheet(title) {
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
     if(a.getAttribute("rel").indexOf("style") != -1
        && a.getAttribute("title")) {
       a.disabled = true;
       if(a.getAttribute("title") == title) a.disabled = false;
     }
   }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

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 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;
}

if( typeof window.addEvent == "function" ) {
	window.addEvent( 'domready', function(e) {
	  var cookie = readCookie("style");
	  var title = cookie ? cookie : getPreferredStyleSheet();
	  setActiveStyleSheet(title);
	  if (title == 'sheet2' || title == 'sheet3') {
		if (document.getElementById('decSize')) {
			document.getElementById('decSize').className = 'decrease';
		}
	  }
	  if (title == 'sheet3') {
		if (document.getElementById('incSize')) {
			document.getElementById('incSize').className = 'top increaseDisabled';
		}
	  }
	});

	window.addEvent('unload', function(e) {
	  var sheet = getActiveStyleSheet();
	  createCookie("style", sheet, 365);
	});
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

/* exhibit popup code */

function openExhibitPop (url,width,height,articleTitle) {
	var exhibitWindow = window.open("",'exhibit','width=' + width + ',height=' + height + ',resizable=yes');
	exhibitWindow.focus();
	exhibitWindow.document.write("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>");
	exhibitWindow.document.write("<html>");
	exhibitWindow.document.write("<head>");
	exhibitWindow.document.write("<title>McKinsey Exhibit</title>");
	exhibitWindow.document.write("<style type='text/css'>@import url(inc/screen.css);</style>");
	exhibitWindow.document.write("</head>");
	exhibitWindow.document.write("<body class='client'>");
	exhibitWindow.document.write("<div class='popupContainer'>");
	exhibitWindow.document.write("<div class='header'>");
	exhibitWindow.document.write("<h1><span>McKinsey Quarterly</span></h1>");
	exhibitWindow.document.write("</div>");
	exhibitWindow.document.write("<p class='close'><input class='blueButton' type='button' onclick='window.close()' value='close window' /></p>");
	exhibitWindow.document.write("<h2 class='exhibit'>" + articleTitle + "</h2>");
	exhibitWindow.document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='100%' height='64%' id='exhibit' align=''>");
	exhibitWindow.document.write("<param name='movie' value='" + url + "'>");
	exhibitWindow.document.write("<param name='play' value='true'>");
	exhibitWindow.document.write("<param name='loop' value='true'>");
	exhibitWindow.document.write("<param name='quality' value='high'>");
	exhibitWindow.document.write("<param name='menu' value='true'>");
	exhibitWindow.document.write("<param name='bgcolor' value='#ffffff'>");
	exhibitWindow.document.write("<embed src='" + url + "' play='true' loop='true' quality='high' menu='true' bgcolor='#fff' swLiveConnect='false' width='100%' height='68%' name='flashtest' align='center' type='application/x-shockwave-flash'>");
	exhibitWindow.document.write("</embed></object>");
	exhibitWindow.document.write("<p class='resize'>&laquo; resize the window to enlarge the exhibit &raquo;</p>");
	exhibitWindow.document.write("<div class='footer'>");
	exhibitWindow.document.write("<p class='legal'>Copyright &copy; 1992-2009 McKinsey &amp; Company</p>");
	exhibitWindow.document.write("</div>");
	exhibitWindow.document.write("</div>");
	exhibitWindow.document.write("</body>");
	exhibitWindow.document.write("</html>");
}

function execSearchBtn(event, loc) 
{    
    if (event.keyCode == 13 || event.keyCode == 3) 
    {        
		event.cancelBubble = true;
		event.returnValue = false;
		if (loc == 'top')
		    document.getElementById('ctl00_BodyPH_SearchButton1').click();
        else
            document.getElementById('ctl00_BodyPH_SearchButton2').click();
    }
}

function execComplete(event, buttonId) 
{   
    if (event.keyCode == 13 || event.keyCode == 3) {    
        event.cancelBubble = true;
        event.returnValue = false;
	    if( buttonId ){
		    buttonId.click();
	    }
    }
}