var targetDiv = "";

function printURL()
{
	var header = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Printable version</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
	header += '<link rel="stylesheet" href="/css/default.css" type="text/css"><style>body {background-color: #ffffff; margin: 0px; padding: 0px;}</style></head>';
	header += '<body onLoad="window.print();">';
	header += '<table align="center"><tr><td width="100%" bgcolor="#ffffff">';
	var footer = '</td></tr></table></body></html>';

	var strInner = document.body.innerHTML;
	var startPos = strInner.lastIndexOf("<!-- print_start -->");	
	var endPos = strInner.lastIndexOf("<!-- print_end -->");
	strInner = strInner.substring(startPos+20, endPos);
		
	if (strInner.lastIndexOf("<!-- print_pause_on -->") > -1)
	{
		var str1 = "<!-- print_pause_on -->";
		var str2 = "<!-- print_pause_off -->";
		startPos = strInner.lastIndexOf(str1);	
		endPos = strInner.lastIndexOf(str2);

		if (endPos > startPos)
		{
			leftStr = strInner.substring(0, startPos);
			rightStr = strInner.substring(endPos + str2.length, strInner.length);
			strInner =	 leftStr + rightStr;
		}
	}

	var xwin = window.open("/code/printable.php", "PrintVersion", "menubar=yes, scrollbars=yes, resizable=yes, width=625, toolbar=yes, statubar=no");
	xwin.document.write(header+strInner+footer);
}

function isPPC()
{
	if (navigator.appVersion.indexOf("PPC") != -1) return true;
	else return false;
}

function sendPage(mailHeadline)
{
	if(!isPPC())
	{
		window.location="mailto:\?subject\=" + mailHeadline + "&body=" + mailHeadline + ": " + window.location;
	}
	else
	{
		window.location="mailto:\?body=" + mailHeadline + ": " + window.location;
	}
}

function ajaxPoll(questionId, multiAnswer, answers, resultDiv)
{
	targetDiv = resultDiv;
	xmlHttp = GetXmlHttpObject();

	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}

	url = "/php/polls/updatePoll.php?questionId="+questionId+"&multiAnswer="+multiAnswer+"&answers="+answers;

	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function ajaxAllPolls(resultDiv)
{
	targetDiv = resultDiv;
	xmlHttp = GetXmlHttpObject();

	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}

	url = "/php/polls/allPolls.php";

	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function ajaxPollResults(questionId, resultDiv)
{
	targetDiv = resultDiv;
	xmlHttp = GetXmlHttpObject();

	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}

	url = "/php/polls/pollResults.php?questionId="+questionId;

	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged() 
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		document.getElementById(targetDiv).innerHTML = xmlHttp.responseText;
	}
}

function GetXmlHttpObject()
{
	var xmlHttp = null;

	try
	{
		xmlHttp = new XMLHttpRequest();
	}
		catch (e)
	{
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}

	return xmlHttp;
}
