

function writeFaqBoxStart(width)
{
	if (width == "" || width == null) {
		width = 0;
	}

	document.write("<table class='message' cellspacing='0' cellpadding='0'  width='"+width+"'>");
	document.write("<tr>");
	document.write("<td background='./images/FaqBoxTLCorner.png' width='9' height='14'></td>");
	document.write("<td background='./images/FaqBoxTEdge.png' height='14'></td>");
	document.write("<td background='./images/FaqBoxTRCorner.png' width='9' height='14'></td>");
	document.write("</tr>");
	document.write("<tr>");
	document.write("<td background='./images/FaqBoxLEdge.png' width='9'></td>");
	document.write("<td bgcolor='#3b8ccb'><div class='faqBoxText'>");
}

function writeFaqBoxEnd()
{
	document.write("</div></td>");
	document.write("<td background='./images/FaqBoxREdge.png' width='9'></td>");
	document.write("</tr>");
	document.write("<tr>");
	document.write("<td background='./images/FaqBoxBLCorner.png' width='9' height='13'></td>");
	document.write("<td background='./images/FaqBoxBEdge.png' height='13'></td>");
	document.write("<td background='./images/FaqBoxBRCorner.png' width='9' height='13'></td>");
	document.write("</tr>");
	document.write("</table>");
}




function writeMsgBoxStart(width)
{
	// <table cellspacing='0' cellpadding='0'>
	// <tr>
	// <td background='./images/messageBoxTLCorner.png' width='10' height='14'></td>
	// <td background='./images/messageBoxTEdge.png' height='14'></td>
	// <td background='./images/messageBoxTRCorner.png' width='9' height='14'></td>
	// </tr>
	// <tr>
	// <td background='./images/messageBoxLEdge.png' width='10'></td>
	// <td bgcolor='#deefff'>testing</td>
	// <td background='./images/messageBoxREdge.png' width='9'></td>
	// </tr>
	// <tr>
	// <td background='./images/messageBoxBLCorner.png' width='10' height='12'></td>
	// <td background='./images/messageBoxBEdge.png' height='12'></td>
	// <td background='./images/messageBoxBRCorner.png' width='9' height='12'></td>
	// </tr>
	// </table>

	if (width == "" || width == null) {
		width = 0;
	}

	document.write("<table class='message' cellspacing='0' cellpadding='0'  width='"+width+"'>");
	document.write("<tr>");
	document.write("<td background='./images/messageBoxTLCorner.png' width='10' height='14'></td>");
	document.write("<td background='./images/messageBoxTEdge.png' height='14'></td>");
	document.write("<td background='./images/messageBoxTRCorner.png' width='9' height='14'></td>");
	document.write("</tr>");
	document.write("<tr>");
	document.write("<td background='./images/messageBoxLEdge.png' width='10'></td>");
	document.write("<td bgcolor='#deefff'><div class='msgBoxText'>");
}

function writeMsgBoxEnd()
{
	document.write("</div></td>");
	document.write("<td background='./images/messageBoxREdge.png' width='9'></td>");
	document.write("</tr>");
	document.write("<tr>");
	document.write("<td background='./images/messageBoxBLCorner.png' width='10' height='12'></td>");
	document.write("<td background='./images/messageBoxBEdge.png' height='12'></td>");
	document.write("<td background='./images/messageBoxBRCorner.png' width='9' height='12'></td>");
	document.write("</tr>");
	document.write("</table>");
}


function writeTxtBoxStart()
{
	// <table cellspacing='0' cellpadding='0'>
	// <tr>
	// <td background='./images/txtBoxTLCorner.png' width='5' height='5'></td>
	// <td background='./images/txtBoxTEdge.png' height='5'></td>
	// <td background='./images/txtBoxTRCorner.png' width='4' height='5'></td>
	// </tr>
	// <tr>
	// <td background='./images/txtBoxLEdge.png' width='5'></td>
	// <td bgcolor='#f3f9fe'><input class='stylizedInput' id='inName' name='inName'/></td>
	// <td background='./images/txtBoxREdge.png' width='4'></td>
	// </tr>
	// <tr>
	// <td background='./images/txtBoxBLCorner.png' width='5' height='4'></td>
	// <td background='./images/txtBoxBEdge.png' height='4'></td>
	// <td background='./images/txtBoxBRCorner.png' width='4' height='4'></td>
	// </tr>
	// </table>
	document.write("<table cellspacing='0' cellpadding='0'>");
	document.write("<tr>");
	document.write("<td background='./images/txtBoxTLCorner.png' width='5' height='5'></td>");
	document.write("<td background='./images/txtBoxTEdge.png' height='5'></td>");
	document.write("<td background='./images/txtBoxTRCorner.png' width='4' height='5'></td>");
	document.write("</tr>");
	document.write("<tr>");
	document.write("<td background='./images/txtBoxLEdge.png' width='5'></td>");
	document.write("<td bgcolor='#f3f9fe'>");
}

function writeTxtBoxEnd()
{
	document.write("</td>");
	document.write("<td background='./images/txtBoxREdge.png' width='4'></td>");
	document.write("</tr>");
	document.write("<tr>");
	document.write("<td background='./images/txtBoxBLCorner.png' width='5' height='4'></td>");
	document.write("<td background='./images/txtBoxBEdge.png' height='4'></td>");
	document.write("<td background='./images/txtBoxBRCorner.png' width='4' height='4'></td>");
	document.write("</tr>");
	document.write("</table>");
}


function replyTo(num)
{
	topDoc = self.document;
	topDoc.getElementById('inReplyID').value = num;
	topDoc.getElementById('dReplyID').innerHTML = "Replying to message no. " + num;
	topDoc.getElementById('dReplyIDContainer').style.display = 'block';
	//alert("reply to " + document.getElementById('inReplyID').value);

	foc = topDoc.getElementById('formFocus');
	//alert(foc.id);
	foc.focus();
	foc.blur();
}

// function hyperlinkText(id)
// {
// 	text = document.getElementById(id).innerHTML;
// 
// 	withProtocolRegexp = new RegExp("[a-zA-Z]+://([.]?[a-zA-Z0-9_/-])*");
// 	text.replace(withProtocolRegexp, "<a href=\"\\0\">\\0</a>");
// 
// 	withProtocolRegexp = new RegExp("(^| |.)(www([.]?[a-zA-Z0-9_/-])*)");
// 	text.replace(withProtocolRegexp, "<a href=\"\\0\">\\0</a>");
// 
// 	alert(text);
// }


// Get the height of the entire document
// --------------------------------------------------------------------
// screen.getDocumentHeight = function() {
// 	var body = screen.getBody();
// 	var innerHeight = (defined(self.innerHeight)&&!isNaN(self.innerHeight))?self.innerHeight:0;
// 
// 	if (!document.compatMode || document.compatMode=="CSS1Compat") {
// 
// 		var topMargin = parseInt(CSS.get(body,'marginTop'),10) || 0;
// 		var bottomMargin = parseInt(CSS.get(body,'marginBottom'), 10) || 0;
// 	
// 		return Math.max(
// 			body.offsetHeight + topMargin + bottomMargin,
// 			document.documentElement.clientHeight,
// 			document.documentElement.scrollHeight, screen.zero(self.innerHeight)
// 		);
// 	}
// 	return Math.max(
// 		body.scrollHeight,
// 		body.clientHeight,
// 		screen.zero(self.innerHeight)
// 	);
// };


function showParent(ctrId, replyToID)
{
	//alert("showParent(" + ctrId + ", " + replyToID);
	topDoc = top.document;
	//alert(self.location);

	parentReply = topDoc.getElementById("parent"+replyToID);
	if (parentReply == null) { parentReply = topDoc.getElementById("msg"+replyToID); }

	if (parentReply == null) {
		ctr = topDoc.getElementById("msg" + ctrId);
		//alert(ctr);
		if (ctr == null) {
			ctr = topDoc.getElementById("parent" + ctrId);
			//alert(ctr);
		}
		//alert(ctr);
		newCode = "<div id='parent"+replyToID+"' name='parent"+replyToID+"'><iframe src='./previewSiteMessage.php?m="+replyToID+"&it="+ctrId+"' scrolling='no' frameborder='0'></iframe> <div style='position:relative;left:20px;'>" + ctr.outerHTML + "</div></div>"
		ctr.innerHTML = "";
		ctr.outerHTML = "";
		alert(ctr.outerHTML);
		ctr.outerHTML = newCode;
		alert(ctr.outerHTML);
		alert(ctr.innerHTML);

		alert(document.getElementById("parent"+replyToID).outerHTML);

	} else {

		ctr = topDoc.getElementById("msg" + ctrId);
		//alert(ctr);
		if (ctr == null) {
			ctr = topDoc.getElementById("parent" + ctrId);
			//alert(ctr);
		}

		// attach parentReply to the top of ctr
		// then set the focus on the parentReply

		ctr.outerHTML = parentReply.outerHTML + "<div style='position:relative;left:+20px;'>" + ctr.outerHTML + "</div>";
		parentReply.outerHTML = "";
		//alert(parentReply);
		//alert(parentReply.outerHTML);
		//alert(document.documentElement.outerHTML);
	}
}



function trim(sString)
{
	while (sString.substring(0,1) == ' ') {
		sString = sString.substring(1, sString.length);
	}

	while (sString.substring(sString.length-1, sString.length) == ' ') {
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function trimInput(name)
{
	var val = document.getElementById(name).value;
	//alert('trimInput for ' + name + ': "' + val + '"');

	var obj = document.getElementById(name);

	obj.value = trim(val);

	//alert('..after trimInput');
}

function validateMsgBoard()
{
	trimInput('inName');
	trimInput('inMsg');

	nameCheck = document.getElementById('inName').value.length > 0;
	msgCheck = document.getElementById('inMsg').value.length > 0;

	msg = '';
	if (!nameCheck) {
		msg += "Name should not be empty.\n"
	}
	if (!msgCheck) {
		msg += "Your message should not be empty.\n"
	}
	if (msg != '') {
		alert(msg);
	}
	//alert (document.getElementById('inReplyID').value);
	return (msg == '');
}
