﻿function getContent(id)
{
	var url = window.location.href;
	url = addParamToURL(url, "print", "true");
	
    printWindow = window.open(url , "HSE",
    "location=1,status=1,scrollbars=1,width=700,height=1500");
    
	return false;
}

function removeContent()
{
	var print = gup("print");
	if (print == "true")
	{
		var contentPH = document.getElementById("mainContentScript");
		var appendContent = contentPH.cloneNode(true);   

		window.document.getElementsByTagName("body")[0].innerHTML = "";
		window.document.getElementsByTagName("body")[0].removeAttribute("style");
		
		var table = document.createElement("table");
		table.setAttribute("width", "532");
		table.setAttribute("style", "width: 532px;");
		var tableB = document.createElement("tbody");
		
		var logo = document.createElement("img");
		logo.setAttribute("src", "images/logo.gif");
		logo.setAttribute("alt", "hse");
		var logoTD = document.createElement("td");
		logoTD.appendChild(logo);
		var logoTR = document.createElement("tr");
		logoTR.appendChild(logoTD);
		tableB.appendChild(logoTR);	
		
		var tr = document.createElement("tr");
		tr.appendChild(appendContent);
		tableB.appendChild(tr);	
		table.appendChild(tableB);	
		window.document.getElementsByTagName("body")[0].appendChild(table);
	    
		var printDiv = document.getElementById("getMainContentTop");
		printDiv.removeAttribute("onclick");
		printDiv.setAttribute("onclick", "printBody()");
		
		printDiv = document.getElementById("getMainContentBottom");
		printDiv.removeAttribute("onclick");
		printDiv.setAttribute("onclick", "printBody()");
		return false;
	}
	else return false;
}

function gup( name )
{  
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
	var regexS = "[\\?&]"+name+"=([^&#]*)";  
	var regex = new RegExp( regexS );  
	var results = regex.exec( window.location.href );  
	if( results == null )    
		return "";  
	else    
	return results[1];
}

function addParamToURL(URL,param,value)
{
	URL = removeParamFromURL(URL,param);
	URL = URL + '&' + param + '=' + value
	if (!(/\?/.test(URL))) URL = URL.replace(/&/,'?');
	return URL;
}

function removeParamFromURL(URL,param)
{
	URL = String(URL);
	var regex = new RegExp( "\\?" + param + "=[^&]*&?", "gi");
	URL = URL.replace(regex,'?');
	regex = new RegExp( "\\&" + param + "=[^&]*&?", "gi");
	URL = URL.replace(regex,'&');
	URL = URL.replace(/(\?|&)$/,'');
	regex = null;
	return URL;
}

function printBody()
{
	window.print();
}