var p = getQueryVariable("print");

if ( (typeof host == "undefined") || host == "" ) {  host = "http://htmldev.scholastic.net"; }

if(p == 1) {
	document.write('<link rel="stylesheet" type="text/css" href="' + host + '/content/presentation/www/pr-print.css" />');
	addLoadEvent(printIt);
}
else if(p == 2) {
	document.write('<link rel="stylesheet" type="text/css" href="' + host + '/content/presentation/www/pr-printimg.css" />');
	addLoadEvent(printIt);
}

var openCallout = "";

function printPage(hostName) {
	if( !document.getElementById || !document.getElementsByTagName ) return;
	if(openCallout != "" && openCallout != "printCallout") {
		document.getElementById(openCallout).style.display = "none";
	}
	if ( !hostName ) hostName = host; 
	
	if(!document.getElementById("printCallout")) {
		var body = document.getElementsByTagName("body")[0];
		var d = document.createElement('div');	
		body.appendChild(d);
		d.setAttribute("id", "printCallout");
	}
	
	
	var topImg = "callout_top.gif";
	obj = document.getElementById("printCallout");
	obj2 = document.getElementById("print");
	temp = getposOffset(obj2, "top") + 16;
	temp2 = getposOffset(obj2, "left");
	temp2 = temp2 - 55;
	if( temp2 < 0 ) {
		temp2 += (-temp2) + 10;
		topImg = "callout_topA.gif";
	}
	
	cContent = '<img src="' + hostName + '/content/presentation/www/images/' + topImg +'" width="370" height="27" class="dBlock" />';
	cContent += '<div id="printCalloutContent">';
	cContent += '<div style="float: right;"><a href="#" onclick="hide(\'printCallout\'); return false;"><img src="' + hostName + '/content/presentation/www/images/cart_close.gif" width="20" height="18" border="0" /></a></div>';
	cContent += '<a href="http://www.scholastic.com/custsupport/">Help with printing?</a><br /><strong>PRINT THIS PAGE</strong>';
	cContent += '<p><form action="" method="post" onsubmit="return printable(this);">';
	cContent += '<table border="0" cellpadding="0" cellspacing="0" width=""><tr valign="top">';
	cContent += '<td width="25"><input type="radio" name="pImages" value="no" checked="checked" /></td>';
	cContent += '<td width="562"><strong>Printer-friendly format, no images</strong><br />Removes all graphics, other content, and advertising. Use this if you just want the body text!</td></tr>';
	cContent += '<tr><td>&nbsp;</td><td>&nbsp;</td></tr><tr valign="top">';
	cContent += '<td><input type="radio" name="pImages" value="yes" /></td>';
	cContent += '<td><strong>Printer-friendly format, with images</strong><br />Removes other content, and advertising, but images remain. Use this if you want to print out pictures alongside the body text!</td></tr>';
	cContent += '<tr valign="top"><td>&nbsp;</td><td>&nbsp;</td></tr>';
	cContent += '<tr valign="top"><td colspan="2"><input type="image" src="' + hostName + '/content/presentation/www/images/btnPrint.gif" alt="Print" width="47" height="15" border="0" /></td></tr>';
	cContent += '</table></form></div>';
	cContent += '<div><img src="' + hostName + '/content/presentation/www/images/callout_btm.gif" width="370" height="14" class="dBlock" /></div>';
	
	obj.style.top = temp + "px";
	obj.style.left = temp2 + "px";
	obj.style.display = "block";
	
	obj.innerHTML = cContent;
	
	openCallout = "printCallout";
}


var emailText;

function emailPage(which) {
	if(openCallout != "" && openCallout != "emailCallout") {		
		document.getElementById(openCallout).style.display = "none";
	}	

	obj = document.getElementById('emailCallout');
	if ( !obj ) return;
	obj2 = document.getElementById("email");
	if ( !obj2 ) return;
	temp = getposOffset(obj2, "top") + 16;
	temp2 = getposOffset(obj2, "left") - 55;
		
	obj.style.top = temp + "px";
	obj.style.left = temp2 + "px";
	obj.style.display = "block";
	
	openCallout = 'emailCallout';
}



function hide(which) {
	document.getElementById(which).style.display = "none";
	openCallout = "";
}

function printable(form) {	
	hide('printCallout');			
	var choice;
	for (var counter = 0; counter < form.pImages.length; counter++) {
		if (form.pImages[counter].checked) choice = counter; 
	}
	var url = location.href;
	var print;
	if(url.indexOf('?') != -1) print = '&print=';
	else print = '?print=';
	if (form.pImages[choice].value == "no")	window.open(location.href + print + '1');
	else if (form.pImages[choice].value == "yes") window.open(location.href + print + '2');	

	return false;
}

function printIt() {
	window.print();
}
