function SexChange(theSex) {
	if (theSex != "0") {
		buildD.style.visibility = 'hidden'
		buildF.style.visibility = 'visible'
		buildM.style.visibility = 'hidden'
		}
	else {
		buildD.style.visibility = 'hidden'
		buildM.style.visibility = 'visible'
		buildF.style.visibility = 'hidden'
		}
//there's also a strBuildParam needs setting (prolly)
}

// Two functions for the emailer:
function selectAll(formObj) 
{
   for (var i=0;i < formObj.length;i++) 
   {
      fldObj = formObj.elements[i];
      if (fldObj.type == 'checkbox') fldObj.checked = true; 
   }
}
function selectNone(formObj) 
{
   for (var i=0;i < formObj.length;i++) 
   {
      fldObj = formObj.elements[i];
      if (fldObj.type == 'checkbox') fldObj.checked = false; 
   }
}

function MemToChange(intMID)
{
// Used by emailer address change function:
// sets the hidden id field to the id of the member to change before calling processemail.asp
	var oEach = document.getElementById("hidMID" + intMID);
	var oSingle = document.getElementById("hidChangeMID");
	oSingle.value = oEach.value;
}

function fnLeaving(strTarget) {
	if (!(confirm("You're about to leave the Southend Shakespeare Company website - use your BACK button to come back here.")))
	{return false}
	else
	{open(strTarget,"_self")}
}

function drawCurtains()
{
	setTimeout("",5000);
	doDraw();
}

function doDraw()
{
	var oLeft = document.getElementById("leftCurtain");
	var oRight = document.getElementById("rightCurtain");
	var intLeft = oLeft.style.width.substring(0,oLeft.style.width.indexOf('px'));
	var intRight = oRight.style.width.substring(0,oRight.style.width.indexOf('px'));
	intLeft = intLeft - 2;
	oLeft.style.width = intLeft;
	oRight.style.width = intLeft;
	oRight.style.posRight = 0;
	if (intLeft > 20) setTimeout("doDraw()",5);
}

function fnToggleForumMsgDisplay(sMsgId,sLinkId)
{
// Used in the Forum index page to unhide (or hide) a message

var oMsg = document.getElementById("msg" + sMsgId); //get the id of the block to be displayed
if (oMsg.className == 'forumMsgOpen') 
{
	oMsg.className = 'forumMsg';
	oMsg.style.display = 'none';
}	 // the braces apparently make all the difference. Javascript!

else // manage the read/unread status of the message that's to be displayed
	{ 
	var dCookie = getCookie("read"); // get the existing cookie (doesn't exlude expiry date)
	var iPos = 0; // integer for substring manipulation, initialised
// Check that the cookie length is <= 4000, and if not strip out some of the earlier ids
/*	I tested this, but I'm not entirely confident in it. Fortunately I'm one of the heaviest
users so I should be one of the first to fall foul of it if it fails
I think if it does the only symptom will be an error on loading the page, because the sLinkId may not exist
 = which suggests that we need to deal with deleted messages too
 = just trap and strip out if the onload routine fails
*/

	if (dCookie.length > 4000)
		{
		iPos = dCookie.substr(3000).indexOf("&"); // find start of first msgid after 3000th byte
		dCookie = dCookie.substring(3000 + iPos);
		}
	dCookie = dCookie+"&"; // terminator - so we can find duplicates
	// if the one they're looking at's already recognised, replace it at the end:
	//	to avoid duplicates, and if it's been read recently avoid it being an early candidate for removal
	//		when the string exceeds 4000
	iPos = dCookie.indexOf("&" + sLinkId + "&"); 
	// If it's been found, strip it out
	if (iPos != -1)
		{
		dCookie = dCookie.substr(0,iPos) + dCookie.substr(iPos + sLinkId.length + 1);
		} // prob only need braces when there's an else, but here's a belt and.
		
	dCookie = dCookie + sLinkId;

	setCookie("read", dCookie, 30); // set the cookie, to expire in 30 days

	document.getElementById(sLinkId).className = "ForumRead"; //Set the link to mauve for the current session
	oMsg.className = 'forumMsgOpen';
	oMsg.style.display = 'block';
	}
}

function markUnRead(sLinkId)
{
var dCookie = getCookie("read"); // get the "read" cookie
var iPos = dCookie.indexOf("&" + sLinkId); 

// It should be found, but an 'if' will avoid embarrassing error messages in the unlikely event
if (iPos != -1)
	{
	dCookie = dCookie.substr(0,iPos) + dCookie.substr(iPos + ("&" + sLinkId).length);
	setCookie("read", dCookie, 30); // write the updated cookie, to expire in 30 days
	}
document.getElementById(sLinkId).className = "ForumNew"; //Change the link colour
document.getElementById("msg" + sLinkId).style.display = "none"; // Close the message so they don't click it again) 
}

function fnSetReadStatus()
{
var dCookie = getCookie("read");
var iPos = dCookie.indexOf("&");
var iNextPos = dCookie.substr(iPos+1).indexOf("&");
var sAnchorId;
var oMessage;
if (iPos != -1)
	{
	dCookie= dCookie + "&"; // terminator
	while (dCookie.substr(iPos+1).indexOf("&") != -1)
		{
		sAnchorId = dCookie.substr(iPos+1,iNextPos);
		oMessage = document.getElementById(sAnchorId)
		if (oMessage != null) oMessage.className= "ForumRead";
		iPos = iPos + iNextPos+1;
		iNextPos = dCookie.substr(iPos+1).indexOf("&");
		}
	}
dCookie = getCookie("hideall");
if (dCookie == "true") ToggleReadHeadsDisplay();
}

function fnHideAll()
{
var oBody;
var x = 0;
//for (var x = 0;
oBody = document.getElementsByTagName("form")[0];
while (!(oBody == undefined))
	{
	var sId = oBody.id;
	if (sId.indexOf("msg")>=0)
		{
		if (oBody.className=='forumMsgOpen')
			{
			oBody.className='forumMsg';
			oBody.style.display = 'none';
			}
		}
	x++;
	oBody = document.getElementsByTagName("form")[x];
	}
}

function fnHideForumMsg(msgId)
// Used in the Forum index page to hide a message
{
var oMsg = document.getElementById("msg" + msgId);
oMsg.className = 'forumMsg';
oMsg.style.display = 'none';
}

function TextFieldBlank(sField, sFieldName)
{
if (sField=='')
	{alert("You must enter something in the " + sFieldName + " area. (Or press List Messages to abandon)");
	return false;
	}
else
	return true
}

function showBlocks(sState, dDate, bThread)
// When clicked, set the form's action attribute and submit, to show or hide the author's blocked messages
{
var sPage = "conversation"
if (bThread) sPage = "convthread"
document.getElementById("frmMonthTop").action = sPage + ".asp?showblocks=" + sState + "&date=" + dDate;
// IMPORTANT!! This routine fails locally but WORKS ON BRINKSTER! Go figure - one day I will.
document.getElementById("frmMonthTop").submit();
}

function setMessageMonth(sWhich)
// When one of the month select dropdowns changes, turn it back into a vb date, create a querystring, and submit
{
	var oForm = document.getElementById("frmMonthTop");
	if (sWhich=="top") // whichever control is used we can store in the one variable
		var oSel = document.getElementById("selMonthTop")
	else
		var oSel = document.getElementById("selMonthBot");
	
	var selIndex = oSel.selectedIndex;
	var sSelection = oSel.options[selIndex].value;
	
	var sMonth	= sSelection.substr(0,3); // extract the month
	switch (sMonth) // and its number
		{
		 case "Jan" :
			iMonth = 1
		      break
		 case "Feb" :
			iMonth = 2
		      break
		 case "Mar" :
			iMonth = 3
		      break
		 case "Apr" :
			iMonth = 4
		      break
		 case "May" :
			iMonth = 5
		      break
		 case "Jun" :
			iMonth = 6
		      break
		 case "Jul" :
			iMonth = 7
		      break
		 case "Aug" :
			iMonth = 8
		      break
		 case "Sep" :
			iMonth = 9
		      break
		 case "Oct" :
			iMonth = 10
		      break
		 case "Nov" :
			iMonth = 11
		      break
		 case "Dec" :
			iMonth = 12
		      break
		}
	// Build the date
	var sDate = "01/" + iMonth + "/" + sSelection.substr(4,7);
	// Set the Action attribute ...
	oForm.action = "conversation.asp?date=" + sDate; //note never convthread.asp: setting the month defeas threading
	// .. and Go!
	oForm.submit();
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}

function getCookie(c_name)
{
if (document.cookie.length > 0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start != -1)
    { 
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end == -1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return ""
}

function showThread(sMsgId, sParentId)
/*
Change action for form msgnnn, and submit
Returns to convThread.asp (instead of processforum), with messageid & thread=true
*/
{
var oForm = document.getElementById("msg" + sMsgId); 
oForm.action = "convthread.asp?msg=" + sMsgId;
oForm.submit();
}

function ToggleReadHeadsDisplay()
// Hide or show all purple headed messages
{
var oMsg;
var x = 0;
var bHidden = false;

oMsg = document.getElementsByTagName("div")[0];
while (!(oMsg == undefined))
	{
	if (oMsg.className == "ForumMsgHead") // only hide the message divs, nothing else!
		{
// get first <td> within the div
		var oCell = oMsg.getElementsByTagName("td")[0];
		if (oCell.className=="ForumRead")
// If its className is ForumNew then don't change it, but if it's ForumRead then ...
			{
			if (oMsg.style.display=='none')
				{
				oMsg.style.display='block'
				}
			else
				{
				oMsg.style.display='none';
				bHidden = true;
				}
			}
		}
	x++;
	oMsg = document.getElementsByTagName("div")[x];
	}

// Change the button's legend and tooltip
var oButton = document.getElementsByTagName("input")[0];
x = 0;
while (!(oButton == undefined)) // Change both top and bottom buttons
	{
	if (oButton.value=="Hide Read Topics")
		{
		oButton.value = "Show Read Topics";
		oButton.title = "Reveal the headers of hidden messages that I've already read";
		}
	else if (oButton.value == "Show Read Topics")
		{
		oButton.value = "Hide Read Topics";
		oButton.title = "Hide all trace of messages that I've already read";
		}
	x++;
	oButton = document.getElementsByTagName("input")[x];
	}
//set a cookie hideall=true/false; to expire in 30 days
setCookie("hideall", bHidden, 30);
}
// end of conversation functions
