
function displayPrintPage() {
	var strUrl;
	strUrl = document.URL;
	window.open(strUrl + "?mode=print");
}

function checkPrintMode() {
	var strUrl;
	strUrl = document.URL;
	if (strUrl.indexOf("?mode=print") != -1) {
		if (strUrl.indexOf("pretest") != -1) {
			document.write("<link href=\"/pretest/common/css/print_top.css\" rel=\"stylesheet\" type=\"text/css\" title=\"printmode\" />");
		}else {
			document.write("<link href=\"/common/css/print_top.css\" rel=\"stylesheet\" type=\"text/css\" title=\"printmode\" />");
		}
		setActiveStyleSheet("printmode");
	}else {
		setDisabledStyleSheet("printmode");
	}
}

function setActiveStyleSheet(title) {
  if(document.getElementById && document.createTextNode) {
		var i, a, main;
	  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
	    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
		  if(a.getAttribute("title") == title) a.disabled = false;
	    }
	  }
	}
}

function setDisabledStyleSheet(title) {
  if(document.getElementById && document.createTextNode) {
		var i, a, main;
	  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
	    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
		  if(a.getAttribute("title") == title) a.disabled = true;
	    }
	  }
	}
}

checkPrintMode();

function openPrintView() {
	var printjs = document.getElementById('print_js');
	
	//alert(printjs.getAttribute('src'));
	printWin = window.open("", "printView", "");
	//printWin.document.open("text/html");
	//alert(document.documentElement.childNodes['HEAD'].innerHTML);
	printWin.document.open("text/html");
	//printWin.document.write("<html><head></head><body></body></html>");
	printWin.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>');
	printWin.document.write('<head>');
	//printWin.document.write(document.documentElement.childNodes[0].innerHTML);
	printWin.document.write('<script type="text/javascript">');
	printWin.document.write('function openPrintView2() {');
	printWin.document.write('document.documentElement.childNodes[0].innerHTML = window.opener.document.documentElement.childNodes[0].innerHTML;');
	printWin.document.write('document.body.innerHTML = window.opener.document.body.innerHTML;');
	printWin.document.write('}');
	printWin.document.write('</script>');
	printWin.document.write('</head>');
	printWin.document.write('<body onload="openPrintView2();">');
	//printWin.document.write(document.body.innerHTML);
	//printWin.document.write("<head>");
	//printWin.document.write(document.documentElement.childNodes[0].innerHTML);
	//printWin.document.write("</head>");
	printWin.document.write("</body>");
	//printWin.document.write(document.body.innerHTML);
	//printWin.document.write("</body>");
	//printWin.document.write(document.documentElement.innerHTML);
	printWin.document.write("</html>");
	printWin.document.close();
	//printWin.document.title = document.title;
	//printWin.document.getElementById("print_view").removeAttribute('media');
	//printWin.document.documentElement.appendChild(document.getElementsByTagName("head").item(0));
	//printWin.document.documentElement.appendChild(document.getElementsByTagName("body").item(0));
	//printWin.document.documentElement.childNodes[1].innerHTML = document.documentElement.childNodes[1].innerHTML;
	//printWin.document.getElementsByTagName("head").item(0) = document.getElementsByTagName("head").item(0);
	//printWin.document.body.innerHTML = document.body.innerHTML;

	/*
	var aObj = printWin.document.getElementsByTagName('A');
	for (i = 0;i < aObj.length;i++) {
		aObj[i].removeAttribute('href');
	}
	*/
}

function test() {

	//alert(window.opener.document.title);
	document.body.innerHTML = window.opener.document.body.innerHTML;
	/*
	var aObj = printWin.document.getElementsByTagName('A');
	for (i = 0;i < aObj.length;i++) {
		aObj[i].removeAttribute('href');
	}
	*/
}
