//========================================================================================
//===
//===	toggleDescriptions - show/hide descriptions
//===		fUseForm -  false [in]
//===           sPrefix - WebPart Prefix
//===
//========================================================================================
function toggleDescriptions( fUseForm, sPrefix, bReload )
{
	var strShowDescription = GetCookie(sPrefix + g_strShowDescriptionCookieId);

	if ("false" == strShowDescription)
	{
		document.cookie = sPrefix + g_strShowDescriptionCookieId + "=true";
	}
	else 
	{
		document.cookie = sPrefix + g_strShowDescriptionCookieId + "=false";
	}
	if (bReload == null) {var bReload = true;}
	if (bReload)
	{
		reloadPage( fUseForm, false );
	}
}

//========================================================================================
//===
//===	setCookie - set cookie value
//===		fUseForm -  false [in]
//===           strCookieName - cookie name [in]
//===           strCookieValue - cookie value [in]
//===
//========================================================================================
function setCookie( fUseForm, strCookieName, strCookieValue, bReload )
{
	document.cookie = strCookieName + "=" + strCookieValue;
	if (bReload == null) {var bReload = true;}
	if (bReload)
	{
		reloadPage( fUseForm, false );
	}
}


//========================================================================================
//===
//===	setLocationSearchParameter - create or replace document.location search parameter
//===		strParameterName -  parameter name [in]
//===           strParameterValue - parameter value [in]
//===
//========================================================================================
function setLocationSearchParameter(strParameterName, strParameterValue)
{
//alert("strParameterValue");
	var strSearch = document.location.search;
	if (strSearch.length == 0)
	{
		strSearch = strParameterName + "=" + strParameterValue;
	}
	else
	{
		if (strSearch.indexOf(strParameterName + "=") == -1)
		{
			strSearch = strSearch + "&" + strParameterName + "=" + strParameterValue;
		}
		else
		{
			var aParameters = strSearch.split("&");
			for (var i = 0; i <= aParameters.length - 1; i++)
			{
				if (aParameters[i].indexOf(strParameterName) != -1)
				{
					aParameters[i] = strParameterName + "=" + strParameterValue;
					break;
				}
			}
			strSearch = "?";
			for (i = 0; i <= aParameters.length - 1; i++)
			{
				strSearch = strSearch + aParameters[i] + "&";
			}
			strSearch = strSearch.substr(0, strSearch.length - 1);
		}
		
	}

	document.location.search = strSearch;
//	alert("strSearch=" + strSearch);
//	document.location.reload();
}

//========================================================================================
//===
//===	printNewsItem - get news item HTML for printing
//===		strItemTableName -  news item <table> name [in]
//===           strTitle - title string [in]
//===
//========================================================================================
function printNewsItem(strItemTableName, strTitle)
{
//alert(document.layers["ItemTable"].innerHTML);
	if (window.navigator.appName == 'Netscape')
	{
		var strInnerText = eval('document.' + strItemTableName + '.innerHTML');
		var oNewWindow = window.open("", "PrintWindow");
//alert(strInnerText);
	}
	else
	{
		var strInnerText = document.all.item(strItemTableName).innerHTML;
		var oNewWindow = window.open("", "PrintWindow", "channelmode=0,directories=0,fullscreen=0,height=400,left=100,location=1,menubar=1,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=1,top=100,width=600");
	}

	var sBaseRef = document.location.search.substring(document.location.search.indexOf("DetailUrl=")+10);
	sBaseRef = sBaseRef.substring(0, sBaseRef.indexOf("&"));
	sBaseRef = sBaseRef.substring(0, sBaseRef.lastIndexOf("/")+1);

	var oNewDoc = oNewWindow.document;
	oNewDoc.open();
	oNewDoc.writeln("<HTML>");
	oNewDoc.writeln("<HEAD>");
	oNewDoc.writeln('<BASE id="bseHref" href="' + sBaseRef + '"/>');
	oNewDoc.writeln('<TITLE>' + strTitle + '</TITLE>');
	oNewDoc.writeln("</HEAD>");
	oNewDoc.writeln("<BODY>");

	oNewDoc.writeln("<i>To print this page select <b>Print</b> from menu <b>File</b></i>");
	oNewDoc.writeln('<hr noshade color="black" size="1">');
	oNewDoc.writeln("<TABLE border=0 width=700>" + strInnerText + "</TABLE>");

	if (window.navigator.appName == 'Netscape')
	{
		if (document.FooterSection != null) {
			strInnerText = document.FooterSection.innerHTML;
			oNewDoc.writeln("<TABLE border=0 width=700>" + strInnerText + "</TABLE>");
		}
	}
	else
	{
		if (document.all.item("FooterSection") != null) {
			strInnerText = document.all.item("FooterSection").innerHTML;
			oNewDoc.writeln("<TABLE border=0 width=700>" + strInnerText + "</TABLE>");
		}
	}
	oNewDoc.writeln("</BODY>");
	oNewDoc.writeln("</HTML>");

	oNewDoc.close();
}

//========================================================================================
//===
//===	sendNewsItemFromWindow - mailing form (in window) for sending news item by E-Mail
//===           strASPUrl - form action url [in]
//===		strItemTableName -  news item <table> name [in]
//===           strTitle - title string [in]
//===
//========================================================================================
function sendNewsItemFromWindow(strASPUrl, strItemTableName, strTitle) // for NetscapeNavigator
{
	var strInnerText = "<TABLE border=0 width=700>" + document.all.item(strItemTableName).innerHTML + "</TABLE>";
//	var strInnerText = document.all.item(strItemTableName).innerText + "</TABLE>";

	var sScript = "";

	sScript = sScript + "function checkInput()";
	sScript = sScript + "{";
	sScript = sScript + '	var strTo = document.all.item("smmTo").value;';
	sScript = sScript + '	if ( strTo == "" )';
	sScript = sScript + "	{";
	sScript = sScript + '		alert("Field \\"Recipient address:\\" is empty !" + String.fromCharCode(10,13) + "Please, enter a valid E-mail address.");';
	sScript = sScript + "		return false;";
	sScript = sScript + "	}";
	sScript = sScript + "	else";
	sScript = sScript + "	{";
	sScript = sScript + "		if (( strTo.indexOf('@') < 1 ) || (strTo.indexOf('@') == strTo.length - 1))";
	sScript = sScript + "		{";
	sScript = sScript + '			alert("Field \\"Recipient address:\\" is not a valid E-mail !" + String.fromCharCode(10,13) + "Please, enter a valid E-mail address.");';
	sScript = sScript + "			return false;";
	sScript = sScript + "		}";
	sScript = sScript + "		else";
	sScript = sScript + "		{";
	sScript = sScript + "			if (( strTo.indexOf('.') < 1 ) || (strTo.indexOf('.') == strTo.length - 1))";
	sScript = sScript + "			{";
	sScript = sScript + '				alert("Field \\"Recipient address:\\" is not a valid E-mail !" + String.fromCharCode(10,13) + "Please, enter a valid E-mail address.");';
	sScript = sScript + "				return false;";
	sScript = sScript + "			}";
	sScript = sScript + "		}";
	sScript = sScript + "		if ((strTo.indexOf('.@') > -1) || (strTo.indexOf('@.') > -1)) ";
	sScript = sScript + "		{";
	sScript = sScript + '			alert("Field \\"Recipient address:\\" is not a valid E-mail !" + String.fromCharCode(10,13) + "Please, enter a valid E-mail address.");';
	sScript = sScript + "			return false;";
	sScript = sScript + "		}";
	sScript = sScript + "	}";
	sScript = sScript + '	strTo = document.all.item("smmFrom").value;';
	sScript = sScript + '	if ( strTo == "")';
	sScript = sScript + "	{";
	sScript = sScript + '		alert("Field \\"Your address:\\" is empty !" + String.fromCharCode(10,13) + "Please, enter your valid E-mail address or name.");';
	sScript = sScript + "		return false;";
	sScript = sScript + "	}else{";
	sScript = sScript + "		return true;";
	sScript = sScript + "	}";
	sScript = sScript + "}";
	sScript = sScript + "function SubmitMailForm(strContainerType, strFormName, strSpanName)";
	sScript = sScript + "{";
	sScript = sScript + "	document.forms(0).style.cursor='wait';";
	sScript = sScript + "	if (strContainerType == 'span')";
	sScript = sScript + "	{";
	sScript = sScript + "		if (checkInput())";
	sScript = sScript + "		{";
	sScript = sScript + "			document.forms(strFormName).submit();";
	sScript = sScript + "			document.all(strSpanName).innerHTML='';";
	sScript = sScript + "		}";
	sScript = sScript + "	}";
	sScript = sScript + "	if (strContainerType == 'window')";
	sScript = sScript + "	{";
	sScript = sScript + "		if (checkInput())";
	sScript = sScript + "		{";
	sScript = sScript + "			document.forms(strFormName).submit();";
//	sScript = sScript + "			window.close();";
	sScript = sScript + "		}";
	sScript = sScript + "	}";
	sScript = sScript + "}";
	sScript = sScript + "function CancelMailForm(strContainerType, strSpanName)";
	sScript = sScript + "{";
	sScript = sScript + "	if (strContainerType == 'span')";
	sScript = sScript + "	{";
	sScript = sScript + "		document.all(strSpanName).style.visibility='hidden';";
	sScript = sScript + "		document.all(strSpanName).innerHTML='';";
	sScript = sScript + "	}";
	sScript = sScript + "	if (strContainerType == 'window')";
	sScript = sScript + "	{";
	sScript = sScript + "		window.close();";
	sScript = sScript + "	}";
	sScript = sScript + "}";

	if (document.all.item("FooterSection") != null) {
		strInnerText = strInnerText + "<TABLE border=0 width=700>" + document.all.item("FooterSection").innerHTML + "</TABLE>";

//		strInnerText = strInnerText + document.all.item("FooterSection").innerText;

	}

//	var sBaseRef = document.location.search.substring(document.location.search.indexOf("DetailUrl=")+10);
//	sBaseRef = sBaseRef.substring(0, sBaseRef.indexOf("&"));
//	sBaseRef = sBaseRef.substring(0, sBaseRef.lastIndexOf("/"))

	var sBaseRef = document.location.href.substring(0,document.location.href.indexOf("main.asp"));

	var iTop = (window.screen.height - 160) / 2;
	var iLeft = (window.screen.width - 510) / 2;
	var oNewWindow = window.open("", "sendWindow", "directories=no, fullscreen=no, menubar=no, scrollbars=no, resizable=no, toolbar=no, left=" + iLeft + "px, top=" + iTop + "px, height=160px, width=510px");

	var oNewDoc = oNewWindow.document;
	oNewDoc.open();

	oNewDoc.writeln("<html>");
	oNewDoc.writeln("<head>");
	oNewDoc.writeln("<title>" + strTitle + "</title>");
	oNewDoc.writeln('<meta http-equiv="Content-Type" content="text/html">');
//	oNewDoc.writeln('<base href="' + sBaseRef + '"/>');

	for (var i=0; i < document.styleSheets.length; i++)
	{
		oNewDoc.writeln('<link rel="stylesheet" href="' + document.styleSheets[i].href + '">');
	}

//	oNewDoc.writeln('<!--<script language="javascript" src="' + sBaseRef + 'Components/News/NewsMiscFunctions.js"></script>-->');
	oNewDoc.writeln('<script language="javascript">' + sScript + '</script>');
	oNewDoc.writeln("</head>");

	oNewDoc.writeln('<body class="UserConfiguration">');
	oNewDoc.writeln(getMailFormBody('window', '', strASPUrl));

	oNewDoc.writeln("</body>");
	oNewDoc.writeln("</html>");

	oNewDoc.close();

//	oNewDoc.all('SendForm').action = strASPUrl;
	oNewDoc.all('smmTo').focus();
	oNewDoc.all('smmSubject').value = strTitle;
	oNewDoc.all('smmHTML').value = strInnerText;
	
//	oNewDoc.all.item('body').value = strInnerText;
}

//========================================================================================
//===
//===	sendNewsItemFromSpan - mailing form (in span) for sending news item by E-Mail
//===           strASPUrl - form action url [in]
//===		strItemTableName -  news item <table> name [in]
//===           strTitle - title string [in]
//===
//========================================================================================
function sendNewsItemFromSpan(strASPUrl, strItemTableName, strTitle)
{
	var strInnerText = "<TABLE border=0 width=700>" + document.all.item(strItemTableName).innerHTML + "</TABLE>";

//	var strInnerText = document.all.item(strItemTableName).innerText;

	if (document.all.item("FooterSection") != null) {
		strInnerText = strInnerText + "<TABLE border=0 width=700>" + document.all.item("FooterSection").innerHTML + "</TABLE>";

//		strInnerText = strInnerText + document.all.item("FooterSection").innerText;

	}

	var spanAddr = document.all.item("MailSpan");
	if (spanAddr == null)
	{
		spanAddr = document.createElement("DIV"); //'<span id="MailSpan" class="UserConfiguration" style="border:'1px solid black'; position:absolute; cursor:default; visibility=hidden; overflow:hidden;"></span>';
		if (spanAddr == null)
		{
			alert("Failed to initiate container for mailing panel");
			return;
		}
		spanAddr.id = 'MailSpan';
		document.body.appendChild(spanAddr);
		spanAddr.className = 'UserConfiguration';
		spanAddr.style.border = '1px solid black';
		spanAddr.style.position = 'absolute';
		spanAddr.style.cursor = 'default';
		spanAddr.style.visibility = 'hidden';
		spanAddr.style.overflow = 'hidden';
	}
	spanAddr.style.height='140px';
	spanAddr.style.width='510px';
	spanAddr.style.top='0px';
	spanAddr.style.left='0px';
  
	spanAddr.innerHTML = getMailFormBody('span', 'MailSpan', strASPUrl);

	var iWinHeight = document.body.offsetHeight; //window.screen.height;
	var iWinWidth = document.body.offsetWidth; //window.screen.width;
	var iSpanTop = 0;
	var iSpanLeft = 0;

	iSpanTop = Math.round((100 - (spanAddr.style.pixelHeight * 100/iWinHeight)) / 2);
	iSpanLeft = Math.round((100 - (spanAddr.style.pixelWidth * 100/iWinWidth)) / 2);

	spanAddr.style.top = iSpanTop + '%';
	spanAddr.style.left = iSpanLeft + '%';

//	document.all('SendForm').action = strASPUrl;
	document.all('smmSubject').value = strTitle;
	document.all('smmHTML').value = strInnerText;

//	document.all('body').value = strInnerText;

//alert(strInnerText);
	spanAddr.style.visibility='visible';
	document.all('smmTo').focus();
}

//========================================================================================
//===
//===	checkInput - mailing form input checking
//===
//========================================================================================
function checkInput()
{
	var strTo = document.all.item("smmTo").value;
	if ( strTo == "" )
	{
		alert("Field \"Recipient address:\" is empty !" + String.fromCharCode(10,13) + "Please, enter a valid E-mail address.");
		return false;
	}
	else
	{
		if (( strTo.indexOf('@') < 1 ) || (strTo.indexOf('@') == strTo.length - 1))
		{
			alert("Field \"Recipient address:\" is not a valid E-mail !" + String.fromCharCode(10,13) + "Please, enter a valid E-mail address.");
			return false;
		}
		else
		{
			if (( strTo.indexOf('.') < 1 ) || (strTo.indexOf('.') == strTo.length - 1))
			{
				alert("Field \"Recipient address:\" is not a valid E-mail !" + String.fromCharCode(10,13) + "Please, enter a valid E-mail address.");
				return false;
			}
		}
		if ((strTo.indexOf('.@') > -1) || (strTo.indexOf('@.') > -1)) 
		{
			alert("Field \"Recipient address:\" is not a valid E-mail !" + String.fromCharCode(10,13) + "Please, enter a valid E-mail address.");
			return false;
		}
	}
	strTo = document.all.item("smmFrom").value;
	if ( strTo == "")
	{
		alert("Field \"Your address:\" is empty !" + String.fromCharCode(10,13) + "Please, enter your valid E-mail address or name.");
		return false;
	}else{
		return true;
	}
}

//========================================================================================
//===
//===	getMailFormBody - get mailing form HTML
//===           strContainerType - form container type ('span' or 'window') [in]
//===		strSpanName -  if strContainerType = 'span' then <span> name, else empty string ('') [in]
//===
//========================================================================================
function getMailFormBody(strContainerType, strSpanName, strASPUrl)
{
	var spanHTML = "";

	spanHTML = spanHTML + '<form id="SendForm" name="SendForm" method="post" enctype="application/x-www-form-urlencoded" action="' + strASPUrl + '">';

//	spanHTML = spanHTML + '<form id="SendForm" name="SendForm" method="post" enctype="text/html" action="mailto:ovs@crimescape.org?subject=Hello">';

	spanHTML = spanHTML + '  <table align="center" width="100%" border="0">';
	spanHTML = spanHTML + "    <tr>";
	spanHTML = spanHTML + "    </tr>";
	spanHTML = spanHTML + '      <td colspan="2">';
	spanHTML = spanHTML + '        <div class="UserSectionTitle" align="center">Send this item by E-mail</div>';
	spanHTML = spanHTML + "      </td>";
	spanHTML = spanHTML + "    <tr>";
	spanHTML = spanHTML + '      <td width="27%">';
	spanHTML = spanHTML + '        <div class="UserSectionHead" align="right">Recipient address<font color="red">&nbsp;*</font></div>';
	spanHTML = spanHTML + "      </td>";
	spanHTML = spanHTML + '      <td width="73%">';
	spanHTML = spanHTML + '		<div class="UserSectionBody">';
	spanHTML = spanHTML + ' 		<span class="UserControlGroup">';
	spanHTML = spanHTML + '        			<input type="text" name="smmTo" size="50">';
	spanHTML = spanHTML + '        		</span>';
	spanHTML = spanHTML + '		</div>';
	spanHTML = spanHTML + "      </td>";
	spanHTML = spanHTML + "    </tr>";
//	spanHTML = spanHTML + "    <tr>";
//	spanHTML = spanHTML + '      <td width="30%">';
//	spanHTML = spanHTML + '        <div class="UserSectionHead" align="right">Your name/address<font color="red">&nbsp;*</font></div>';
//	spanHTML = spanHTML + "      </td>";
//	spanHTML = spanHTML + '      <td width="70%">';
//	spanHTML = spanHTML + '		<div class="UserSectionBody">';
//	spanHTML = spanHTML + ' 		<span class="UserControlGroup">';
//	spanHTML = spanHTML + '        			<input type="text" name="smmFrom" size="50">';
//	spanHTML = spanHTML + '        		</span>';
//	spanHTML = spanHTML + '		</div>';
//	spanHTML = spanHTML + "      </td>";
//	spanHTML = spanHTML + "    </tr>";
	spanHTML = spanHTML + "    <tr>";
	spanHTML = spanHTML + '      <td width="25%">';
	spanHTML = spanHTML + '        <div class="UserSectionHead" align="right">Subject</div>';
	spanHTML = spanHTML + "      </td>";
	spanHTML = spanHTML + '      <td width="75%">';
	spanHTML = spanHTML + '		<div class="UserSectionBody">';
	spanHTML = spanHTML + ' 		<span class="UserControlGroup">';
	spanHTML = spanHTML + '			        <input type="text" name="smmSubject" size="50">';
	spanHTML = spanHTML + '        		</span>';
	spanHTML = spanHTML + '		</div>';
	spanHTML = spanHTML + "      </td>";
	spanHTML = spanHTML + "    </tr>";
	spanHTML = spanHTML + '    <tr><td colspan="2" width="100%" class="UserDottedline"></td></tr>';
	spanHTML = spanHTML + '    <tr>';
	spanHTML = spanHTML + '    	<td colspan="2">';
	spanHTML = spanHTML + '    		<span style="PADDING-RIGHT:3px; width:60%; wrap:none">';
	spanHTML = spanHTML + '    			<nobr><font color="red">*&nbsp;</font></nobr><String>Indicates a required field.</String>';
	spanHTML = spanHTML + '    		</span>';
	spanHTML = spanHTML + '    	</td>';
	spanHTML = spanHTML + '    </tr>';
	spanHTML = spanHTML + '    <tr align="center">';
	spanHTML = spanHTML + '      <td colspan="2">';
	spanHTML = spanHTML + '        <input type="button" class="UserButton" name="SendBtn" value="Send" onclick="SubmitMailForm(\'' + strContainerType + '\',\'SendForm\',\'' + strSpanName +'\')">';
	spanHTML = spanHTML + '        <input type="button" class="UserButton" name="CancelBtn" value="Cancel" onclick="CancelMailForm(\'' + strContainerType + '\',\'' + strSpanName +'\')">';
	spanHTML = spanHTML + "      </td>";
	spanHTML = spanHTML + "    </tr>";
	spanHTML = spanHTML + "    <tr>";
	spanHTML = spanHTML + '      <td colspan="2">';
	spanHTML = spanHTML + '		<div class="UserSectionBody">';
	spanHTML = spanHTML + ' 		<span class="UserControlGroup">';
	spanHTML = spanHTML + '	        		<textarea style="visibility:hidden" name="smmHTML" cols=50 rows=10></textarea>';

//	spanHTML = spanHTML + '	        		<textarea style="visibility:visble" name="smmHTML" cols=50 rows=10></textarea>';

	spanHTML = spanHTML + '        		</span>';
	spanHTML = spanHTML + '		</div>';

	spanHTML = spanHTML + '		<div class="UserSectionBody">';
	spanHTML = spanHTML + ' 		<span class="UserControlGroup">';
	spanHTML = spanHTML + '        			<input type="hidden" name="smmFrom" value="news@crimescape.org" size="50">';
	spanHTML = spanHTML + '        		</span>';
	spanHTML = spanHTML + '		</div>';

	spanHTML = spanHTML + "      </td>";
	spanHTML = spanHTML + "    </tr>";
	spanHTML = spanHTML + "  </table>";
	spanHTML = spanHTML + "</form>";

	return spanHTML;
}

//========================================================================================
//===
//===	SubmitMailForm - submit and close mailing form
//===           strContainerType - form container type ('span' or 'window') [in]
//===		strFormName - form name [in]
//===		strSpanName -  if strContainerType = 'span' then <span> name, else empty string ('') [in]
//===
//========================================================================================
function SubmitMailForm(strContainerType, strFormName, strSpanName)
{
	if (strContainerType == 'span')
	{
		if (checkInput())
		{
			document.forms(strFormName).submit();
			document.all(strSpanName).innerHTML='';
		}
	}
	if (strContainerType == 'window')
	{
		if (checkInput())
		{
			document.forms(strFormName).submit();
			window.close();
		}
	}
}

//========================================================================================
//===
//===	CancelMailForm - cancel and close mailing form
//===           strContainerType - form container type ('span' or 'window') [in]
//===		strSpanName -  if strContainerType = 'span' then <span> name, else empty string ('') [in]
//===
//========================================================================================
function CancelMailForm(strContainerType, strSpanName)
{
	if (strContainerType == 'span')
	{
		document.all(strSpanName).style.visibility='hidden';
		document.all(strSpanName).innerHTML='';
	}
	if (strContainerType == 'window')
	{
		window.close();
	}
}

function NewsTranslateItem(sWPPrefix)
{
	var sProtocol = document.location.protocol + "//";
	var sHost = document.location.host;
	var sPathName = document.location.pathname;
//	var iPortalPos = sPathName.indexOf("/Portal/");
	var iPortalPos = sPathName.lastIndexOf("/");
	if (iPortalPos < 0) { iPortalPos = sPathName.length - 1}

	sPathName = sPathName.substr(0, iPortalPos) + "/Components/FolderViewer/MiscModules/NewsChooseLanguage.asp";
	window.open(sProtocol + sHost + sPathName + '?WP=' + sWPPrefix, 
		    null, 
		    'top=170,left=250,height=100,width=250,menubar=no,status=no,resizable=no,scrollbars=yes,toolbar=no,location=no,channelmode=no,directories=no,fullscreen=no');
}

function ShowCalendar(sASPUrl, scrX, scrY)
{
	if (sASPUrl.indexOf("http") == -1)
	{
		sASPUrl = document.location.protocol + "//" + document.location.hostname + document.location.pathname.substring(0, document.location.pathname.lastIndexOf("/")+1) + sASPUrl;
	}

	window.open(sASPUrl, "", "channelmode=0,directories=0,fullscreen=0,height=200," + "left=" + scrX + ",location=0,menubar=0,resizable=1,scrollbars=1,status=1,titlebar=0,toolbar=0,top=" + scrY +",width=200");
	return true;
}

function f_News_RefreshLanguagePair(oForm,oWindow,oParent)
{
	if (oWindow==null || oForm==null) return;

	if (oParent.navigator.appName == 'Netscape')
	{
		var arr = oForm.langID;
		var sWPPrefix = oForm.WP.value;
	}
	else
	{
		var arr = oForm.all("langID");
		var sWPPrefix = oForm.all("WP").value;
	}
	var strPair = "";
	var i1=0, i2;

	while (i1 != arr.length)
	{
		if (arr[i1].checked){strPair=arr[i1].value;break;}
		i1++;
	}
	var sDocSearch = oParent.document.URL;
	if (sDocSearch.indexOf('?') != -1)
	{
		var sHref = sDocSearch.substring(0, sDocSearch.indexOf('?'));
		sDocSearch = sDocSearch.substr(sDocSearch.indexOf('?'));
		
		var sSearch = sDocSearch;	//document.location.search;
		var iKeyPos = sSearch.indexOf(sWPPrefix + "Tr=");

		if ( iKeyPos >= 0){
			var iAmpPos = sSearch.indexOf("&", iKeyPos)
			if (iAmpPos < 0) {iAmpPos = sSearch.length - 1}
			if ( iKeyPos >= 0){
				sSearch = sSearch.substr(0, iKeyPos) + sSearch.substr(iAmpPos + 1);
			}
		}
		iKeyPos = sSearch.indexOf(sWPPrefix + "TrDir=");
		if (iKeyPos >= 0){
			var iAmpPos = sSearch.indexOf("&", iKeyPos)
			if (iAmpPos < 0) {iAmpPos = sSearch.length - 1}
			sSearch = sSearch.substr(0, iKeyPos) + sSearch.substr(iAmpPos + 1);
		}
		if (sSearch.substr(sSearch.length - 1) == "&") {sSearch = sSearch.substr(0, sSearch.length - 1)}
		oParent.document.URL = sHref + sSearch + "&" + sWPPrefix + "Tr=1&" + sWPPrefix + "TrDir=" + strPair;
//		document.location.search = sSearch + "&" + sWPPrefix + "Tr=1&" + sWPPrefix + "TrDir=" + strPair;
	}
	oWindow.close();																
}

function NewsDeleteItems(oDoc, sForm, sWPPrefix)
{
	if (oDoc == null) {return;}

	if (GetCookie(sWPPrefix + "CheckedItems") == "undefined") {alert("There are no checked items !"); return;}

	var arrCheckedCB = GetCookie(sWPPrefix + "CheckedItems").split(",");

	if (arrCheckedCB == null) {alert("There are no checked items !"); return;}

	if (!confirm('Do you want to delete selected items ?')) {return;}
	
	var oF = oDoc.forms(sForm);
	if (oF.elements(sWPPrefix + "_List_for_Deleting").length == 0) {alert("Error: field \"" + sWPPrefix + "_List_for_Deleting\" not found !"); return;}

	oF.elements(sWPPrefix + "_List_for_Deleting").value = GetCookie(sWPPrefix + "_List_for_Deleting").split(",");
	oF.action = document.URL;
	oF.submit();

/*	for (var iCBNum = 0; iCBNum < arrCheckedCB.length; iCBNum++)
	{
		if (arrCheckedCB[iCBNum].length > 0)
		{
			setCookie(false, sWPPrefix + "DigestPartTitle" + arrCheckedCB[iCBNum], "", false);
			setCookie(false, sWPPrefix + "DigestPartHref" + arrCheckedCB[iCBNum], "", false);
		}
	}*/
	setCookie(false, sWPPrefix + "CheckedItems", "", false);
	setCookie(false, sWPPrefix + "_List_for_Deleting", "", false);
	setCookie(false, sWPPrefix + "DigestPartTitle", "", false);
	setCookie(false, sWPPrefix + "DigestPartHref", "", false);
}

function NewsCreateDigest(oDoc, sForm, sWPPrefix, sDocType)
{
	if (sDocType == null) {sDocType = "";}
	if (oDoc == null) {return;}

	if (GetCookie(sWPPrefix + "CheckedItems") == "undefined") {alert("There are no checked items !"); return;}

	var ss = GetCookie(sWPPrefix + "CheckedItems");
	if (ss.substr(ss.length - 1) == ',')
	{
		setCookie(false, sWPPrefix + "CheckedItems", ss.substr(0, ss.length - 1), false);
	}
	var arrCheckedCB = GetCookie(sWPPrefix + "CheckedItems").split(",");
	
	if (arrCheckedCB == null) {alert("There are no checked items !"); return;}
	
	if (oDoc.all("NewsDate") != null)
	{
		var sDate = oDoc.all("NewsDate").innerText;
	}
	else
	{
		var News_MonthName = new Array();
		News_MonthName[1] = "January";
		News_MonthName[2] = "February";
		News_MonthName[3] = "March";
		News_MonthName[4] = "April";
		News_MonthName[5] = "May";
		News_MonthName[6] = "June";
		News_MonthName[7] = "July";
		News_MonthName[8] = "August";
		News_MonthName[9] = "September";
		News_MonthName[10] = "October";
		News_MonthName[11] = "November";
		News_MonthName[12] = "December";

		var sDate = "" + News_MonthName[(new Date()).getMonth() + 1] + " " + (new Date()).getDate() + ", " + (new Date()).getFullYear();
		News_MonthName = null;
	}
	
	var sBR = "<BR>";
	var strDigest = "This is your WJIN daily " + sDocType + " update for " + sDate + "." + sBR + sBR;
	
	var arrTitles = GetCookie(sWPPrefix + "DigestPartTitle").split("-,-");
	var arrHrefs = GetCookie(sWPPrefix + "DigestPartHref").split("-,-");
//alert(GetCookie(sWPPrefix + "DigestPartHref"));
	var iNumber = 0;
	for (var iCBNum = 0; iCBNum < arrCheckedCB.length; iCBNum++)
	{
		if (arrCheckedCB[iCBNum].length > 0)
		{
			var sTitle = arrTitles[iCBNum];
			var sHref = arrHrefs[iCBNum];
			var sTemp = "" + (++iNumber) + ". " + sTitle + sBR;
			sTemp += "<a href=\"" + sHref + "\">" + sHref + "</a>" + sBR;
//			sTemp += "<a style=\"word-wrap : normal;\" href=\"" + sHref + "&IN=" + (iCBNum + 1) + "\">" + sHref + "&IN=" + (iCBNum + 1) + "</a>" + sBR;
			if (sTemp.length > 0) {	strDigest += sTemp + sBR; }
		}
	}
	setCookie(false, sWPPrefix + "DigestPartTitle", "", false);
	setCookie(false, sWPPrefix + "DigestPartHref", "", false);

	strDigest += "This message is brought to you by the World Justice" + sBR;
	strDigest += "Information Network, <a href=\"http://www.wjin.net\">http://www.wjin.net</a>, administered" + sBR;
	strDigest += "by the Rule of Law Foundation, <a href=\"http://www.rol.org\">http://www.rol.org</a>, with" + sBR;
	strDigest += "support from the National Institute of Justice of the" + sBR;
	strDigest += "United States Department of Justice, and the Bureau for" + sBR;
	strDigest += "International Narcotics and Law Enforcement Affairs of the" + sBR;
	strDigest += "United States Department of State. Some links are to" + sBR;
	strDigest += "external web sites which are not affiliated with WJIN or" + sBR;
	strDigest += "its sponsors." + sBR;
	strDigest += "" + sBR;
//	strDigest += "-------------------------------------------------------------" + sBR;
//	strDigest += "This message was sent to you because you are subscribed to" + sBR;
//	strDigest += "  the mailing list <<a href=\"mailto:justnews@list.crimescape.org\">justnews@list.crimescape.org</a>>." + sBR;
//	strDigest += "To UNSUBSCRIBE, E-mail to: <<a href=\"mailto:justnews-off@list.crimescape.org\">justnews-off@list.crimescape.org</a>>" + sBR;
//	strDigest += "Send administrative queries to: <<a href=\"mailto:greg@rol.org\">greg@rol.org</a>>" + sBR;

	if (!confirm('Do you want to create digest from selected items ?')) {return;}
	
	var sHref = "Components/HTMLEditor/HTMLEditor.htm";

	var oParams = new Function();
	//................................
	//...parameters for modal dialog window
	//................................
	oParams.htmlstr	= strDigest;						//...text to edit
	oParams.url		= "" ; //null;							//...url to load html from
	oParams.mode	= "html";								//...mode of initiating html - pass through parameters ('html') or load from web-page ('url')
	var returnValue = window.showModalDialog(
					sHref, 
					oParams, 
					'dialogHeight:500px;dialogWidth:600px;resizable:yes;status:no;help:no;');
	
	if (returnValue)
	{
		var str = oParams.htmlstr;

		var oF = oDoc.forms(sForm);
		if (oF.elements(sWPPrefix + "_Digest_HTML").length == 0) {alert("Error: field \"" + sWPPrefix + "_Digest_HTML\" not found !"); return;}

		oF.elements(sWPPrefix + "_Digest_HTML").value = str;
		oF.action = document.URL;
		setCookie(false, sWPPrefix + "_Digest_Date", escape(sDate), false);
		oF.submit();
	}
	for (var iCBNum = 0; iCBNum < arrCheckedCB.length; iCBNum++)
	{
		if (arrCheckedCB[iCBNum].length > 0)
		{
			setCookie(false, sWPPrefix + "DigestPartTitle" + arrCheckedCB[iCBNum], "", false);
			setCookie(false, sWPPrefix + "DigestPartHref" + arrCheckedCB[iCBNum], "", false);
		}
	}
	setCookie(false, sWPPrefix + "CheckedItems", "", false);
	setCookie(false, sWPPrefix + "_List_for_Deleting", "", false);

	if (!returnValue) {	reloadPage( false, false ); }
}

function NewsItemAnchorClick(oDoc, sForm, sWPPrefix, oCheckBox, sItemNo)
{
	if (oCheckBox.checked)
	{
		var sCookie = GetCookie(sWPPrefix + "_List_for_Deleting");
		if (sCookie == "undefined") {sCookie = "";}

		setCookie(false, sWPPrefix + "_List_for_Deleting", sCookie + oCheckBox.parentElement.parentElement.all("id_real_doc_url").value + ",", false);

		sCookie = GetCookie(sWPPrefix + "CheckedItems");
		if (sCookie == "undefined") {sCookie = "";}
		setCookie(false, sWPPrefix + "CheckedItems", sCookie + sItemNo + ",", false);

		sCookie = "";
		sCookie = oCheckBox.parentElement.parentElement.all("id_RecordTitle").innerText;
		if (oCheckBox.parentElement.parentElement.all("id_RecordSource") != null)
		{
			sCookie += " " + oCheckBox.parentElement.parentElement.all("id_RecordSource").innerText;
		}

		var sTmp = GetCookie(sWPPrefix + "DigestPartTitle");
		if (sTmp == "undefined") {sTmp = "";}
		setCookie(false, sWPPrefix + "DigestPartTitle", sTmp + sCookie + "-,-", false);

		sCookie = oCheckBox.parentElement.parentElement.all("id_real_doc_url").innerText;

		var sTmp = GetCookie(sWPPrefix + "DigestPartHref");
		if (sTmp == "undefined") {sTmp = "";}
		setCookie(false, sWPPrefix + "DigestPartHref", escape(sTmp + sCookie) + "-,-", false);
	}
	else
	{
		var sValue = oCheckBox.parentElement.parentElement.all("id_real_doc_url").value;
		var sCookie = GetCookie(sWPPrefix + "_List_for_Deleting");
		if (sCookie != "undefined")
		{
			var arr = sCookie.split(",");
			for (var iarr = 0; iarr < arr.length - 1; iarr++)
			{
				if (arr[iarr] == sValue) {break;}
			}
			if (iarr < arr.length) {arr.splice(iarr, 1);}
			
			sCookie = arr.join(",");
			setCookie(false, sWPPrefix + "_List_for_Deleting", sCookie, false);
		}
		
		sValue = sItemNo;
		sCookie = GetCookie(sWPPrefix + "CheckedItems");
		if (sCookie != "undefined")
		{
			arr = sCookie.split(",");
			for (iarr = 0; iarr < arr.length - 1; iarr++)
			{
				if (arr[iarr] == sValue) {break;}
			}
			if (iarr < arr.length) {arr.splice(iarr, 1);}
			
			sCookie = arr.join(",");
			setCookie(false, sWPPrefix + "CheckedItems", sCookie, false);
		}

		sValue = "";
		sValue = oCheckBox.parentElement.parentElement.all("id_RecordTitle").innerText;
		if (oCheckBox.parentElement.parentElement.all("id_RecordSource") != null)
		{
			sValue += " " + oCheckBox.parentElement.parentElement.all("id_RecordSource").innerText;
		}
		sCookie = GetCookie(sWPPrefix + "DigestPartTitle");
		if (sCookie != "undefined")
		{
			arr = sCookie.split("-,-");
			for (iarr = 0; iarr < arr.length - 1; iarr++)
			{
				if (arr[iarr] == sValue) {break;}
			}
			if (iarr < arr.length) {arr.splice(iarr, 1);}
			
			sCookie = arr.join("-,-");
			setCookie(false, sWPPrefix + "DigestPartTitle", sCookie, false);
		}

		sValue = oCheckBox.parentElement.parentElement.all("id_real_doc_url").innerText;
		sCookie = GetCookie(sWPPrefix + "DigestPartHref");
		if (sCookie != "undefined")
		{
			arr = sCookie.split("-,-");
			for (iarr = 0; iarr < arr.length - 1; iarr++)
			{
				if (arr[iarr] == sValue) {break;}
			}
			if (iarr < arr.length) {arr.splice(iarr, 1);}
			
			sCookie = arr.join("-,-");
			setCookie(false, sWPPrefix + "DigestPartHref", escape(sCookie), false);
		}
	}
	sCookie = GetCookie(sWPPrefix + "CheckedItems");
	if (sCookie == "undefined") {sCookie = "";}
	oDoc.forms(sForm).elements(sWPPrefix + "_CheckedItems").value = sCookie;
}
