// Written by Devin McQueeney FEB Design April 2006

// Replace selects with their selected text
function swapSelectsWithText(){
var HTMLelements = document.getElementsByTagName("SELECT");
for (i=0;i<HTMLelements.length;){
if (HTMLelements[i].style.visibility != "hidden" && HTMLelements[i].style.display != "none"){
var HTMLselectText = document.createTextNode(HTMLelements[i].options[HTMLelements[i].selectedIndex].text);
HTMLelements[i].parentNode.replaceChild(HTMLselectText, HTMLelements[i]);
}else{
i++;
}}}

// Replace inputs with their values
function swapInputsWithText(){
var HTMLelements = document.getElementsByTagName("INPUT");
for (i=0;i<HTMLelements.length;){
if (HTMLelements[i].type == "text" && HTMLelements[i].style.visibility != "hidden" && HTMLelements[i].style.display != "none"){
var HTMLselectText = document.createTextNode(HTMLelements[i].value);
HTMLelements[i].parentNode.replaceChild(HTMLselectText, HTMLelements[i]);
}else{
i++;
}}}

// Replace textareas with the innerText
function swapTextareasWithText(){
var HTMLelements = document.getElementsByTagName("TEXTAREA");
for (i=0;i<HTMLelements.length;i++){
if (HTMLelements[i].style.visibility != "hidden" && HTMLelements[i].style.display != "none"){
var HTMLselectText = document.createTextNode(HTMLelements[i].value);
HTMLelements[i].parentNode.replaceChild(HTMLselectText, HTMLelements[i]);
}else{
i++;
}}}

// Remove the href and onclick attributes of any A tags
function removeHREFs(){
var HTMLelements = document.getElementsByTagName("A");
for (i=0;i<HTMLelements.length;i++){
HTMLelements[i].removeAttribute("href",0);
HTMLelements[i].removeAttribute("onclick",0);
}}

// Pop open the print frameset
function printThisPage(landscape){
var myTime = new Date();
var timeNow = myTime.getTime();

if (landscape == "false"){
window.print();
}else{
newwindow=window.open("/static/common/htm/printframe.html?printpage="+ window.location + "&landscape=" + landscape,"printWin"+ timeNow,"toolbar=0,menubar=0,location=0,status=0,directories=0,resizable=1,scrollbars=1,top=0,left=0,width=812,height=560")
if (window.focus){newwindow.focus()}
}

}

// Check to see if the page should be formatted as a print page
function checkPrint(){
var docUrl = window.location + "";
if (docUrl.indexOf("print=yes",0) > 0){
document.title = ""; // Remove the page title so it doesn't print at the top of the page
swapSelectsWithText();
swapInputsWithText();
swapTextareasWithText();
removeHREFs();
}}

var docUrl = window.location + "";
if (docUrl.indexOf("print=yes",0) > 0){
document.write("<link rel='stylesheet' type='text/css' href='/static/common/css/ofprint.css'>"); // Add the print stylesheet
}