function clearTextBox()
{
	if (document.getElementById('secret').value == 'Share your secret here!')
		document.getElementById('secret').value = '';
}
function getCheckedValue(radioObj)
{
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
function buildSample()
{
	var notecolor = document.forms['capform'].elements['notecolor'].value;
	var fontface = document.forms['capform'].elements['fontface'].value;
	document.getElementById('samplenote').src = 'buildsample.php?notecolor='+notecolor+'&fontface='+fontface;
}
function load()
{
	buildSample();
}

function filterSecret(w,s){
	// Count the words
	var txt = w.value;
	var wordcount = 0;
	txt = txt.replace(/[^a-zA-Z @\.\*0-9]+/g,' ');
	txt = txt.replace(/\. /,' ');
	if (txt.lastIndexOf(' ') == txt.length-1 || s == 1)
	{
		txtarr = txt.split(' ');
		for (i=0; i<txtarr.length; i++)
		{
			if (txtarr[i].length > 0)
			{
				wordcount++;
			}
		}
		// Update word count
		document.getElementById('wordcount').innerHTML = wordcount;

//		filterBadWord(txtarr);

		// Bad words filter checking on the fly
		var tempBadWord;
		var alertWord;
		for (var i=0; i<badwordArr.length; i++)
		{
			for(var j=0; j<txtarr.length; j++)
			{
				tempBadWord = '';
				tempBadWord = badwordArr[i];

				// Check form text string for period at end of word
				if (txtarr[j].indexOf('.') == txtarr[j].length-1)
				{
					txtarr[j].substring(0,txtarr[j].length-1);
				}

				// If asterik at beginning
				if (tempBadWord.indexOf('*') == 0)
				{
					tempBadWord = tempBadWord.substring(1);
					// If asterik also at end
					if (tempBadWord.indexOf('*') == tempBadWord.length-1)
					{
						tempBadWord = tempBadWord.substring(0,tempBadWord.length-1);
						if (txtarr[j].indexOf(tempBadWord) > -1)
						{
							alertWord = txtarr[j];
							break;
						}
					}
					else
					{
						if (txtarr[j].indexOf(tempBadWord) > 0)
						{
							alertWord = txtarr[j];
							break;
						}
					}
				}
				else if (tempBadWord.indexOf('*') == tempBadWord.length-1)
				{
					tempBadWord = tempBadWord.substring(0,tempBadWord.length-1);
					if (txtarr[j].indexOf(tempBadWord) == 0)
					{
						alertWord = txtarr[j];
						break;
					}
				}
				else if (tempBadWord == txtarr[j].toLowerCase())
				{
					alertWord = txtarr[j];
						break;
				}
			}
		}
		if (alertWord)
		{
			if (alertWord.indexOf('.') == -1 && alertWord.indexOf('@') == -1)
			{
				var answer = confirm("The word \"" + alertWord + "\" is not permitted on this site.\n\nWould you like to post your secret on our adult site.");
				if (answer){
					window.location = "http://adult.secretswall.com/";
				}
				else
				{
					alert("Please remove the word \"" + alertWord + "\" from your post.")
					document.capform.secret.select();
				}
			}
			else
			{
				alert("The word \"" + alertWord + "\" is not permitted on this site.")
				document.capform.secret.select();
			}
			return true;
		}
	}
	return false;
}

function submitSecret(formObj)
{
	if (formObj.secret.value.length == 0)
	{
		alert("You must tell us your Secret!");
		return false;
	}
	else if (formObj.agreetoterms.checked == false)
	{
		alert("You must agree to the terms for this site.");
		return false;
	}
	else if (filterSecret(document.capform.secret,1))
	{
		return false;
	}
	return true;
}

function filterComment(w,s){
	// Count the words
	var txt = w.value;
	var wordcount = 0;
	txt = txt.replace(/[^a-zA-Z @\.\*0-9]+/g,' ');
	txt = txt.replace(/\. /,' ');
	if (txt.lastIndexOf(' ') == txt.length-1 || s == 1)
	{
		txtarr = txt.split(' ');
		for (i=0; i<txtarr.length; i++)
		{
			if (txtarr[i].length > 0)
			{
				wordcount++;
			}
		}
		if (document.getElementById('wordcount'))
			document.getElementById('wordcount').innerHTML = wordcount;

		// Bad words filter checking on the fly
		var tempBadWord;
		var alertWord;
		for (var i=0; i<badwordArr.length; i++)
		{
			for(var j=0; j<txtarr.length; j++)
			{
				tempBadWord = '';
				tempBadWord = badwordArr[i];

				// Check form text string for period at end of word
				if (txtarr[j].indexOf('.') == txtarr[j].length-1)
				{
					txtarr[j].substring(0,txtarr[j].length-1);
				}

				// If asterik at beginning
				if (tempBadWord.indexOf('*') == 0)
				{
					tempBadWord = tempBadWord.substring(1);
					// If asterik also at end
					if (tempBadWord.indexOf('*') == tempBadWord.length-1)
					{
						tempBadWord = tempBadWord.substring(0,tempBadWord.length-1);
						if (txtarr[j].indexOf(tempBadWord) > -1)
						{
							alertWord = txtarr[j];
							break;
						}
					}
					else
					{
						if (txtarr[j].indexOf(tempBadWord) > 0)
						{
							alertWord = txtarr[j];
							break;
						}
					}
				}
				else if (tempBadWord.indexOf('*') == tempBadWord.length-1)
				{
					tempBadWord = tempBadWord.substring(0,tempBadWord.length-1);
					if (txtarr[j].indexOf(tempBadWord) == 0)
					{
						alertWord = txtarr[j];
						break;
					}
				}
				else if (tempBadWord == txtarr[j].toLowerCase())
				{
					alertWord = txtarr[j];
						break;
				}
			}
		}
		if (alertWord)
		{
			alert("The word \"" + alertWord + "\" is not permitted on this site.")
			document.capform.comment.select();
			return true;
		}
	}
	return false;
}

// When submitting a comment, validate and filter
function submitComment(formObj)
{
	if (formObj.comment.value.length == 0)
	{
		alert("You must leave a comment!");
		return false;
	}
	else if (formObj.agreetoterms.checked == false)
	{
		alert("You must agree to the terms for this site.");
		return false;
	}
	else if (filterComment(document.capform.comment,1))
	{
		return false;
	}
	return true;
}

// Begin clip art functions
var leftright;

function slideExample1(elementId, headerElement, clipartSide)
{

	var element = document.getElementById(elementId);
	if (element.up == null)
		element.up = true;
	if(element.up == null || element.down)
	{
		animate(elementId, 0, 0, 420, 0, 200, null);
		element.up = true;
		element.down = false;
		leftright = null;
	}
	else
	{
		animate(elementId, 0, 0, 320, 420, 200, null);
		element.down = true;
		element.up = false;
		if (clipartSide == 'left')
			leftright = 'l';
		if (clipartSide == 'right')
			leftright = 'r';
	}
}
function animate(elementID, newLeft, newTop, newWidth, newHeight, time, callback)
{
	var el = document.getElementById(elementID);
	if(el == null)
		return;
 
	var cLeft = parseInt(el.style.left);
	var cTop = parseInt(el.style.top);
	var cWidth = parseInt(el.style.width);
	var cHeight = parseInt(el.style.height);
 
	var totalFrames = 1;
	if(time> 0)
		totalFrames = time/40;

	var fLeft = newLeft - cLeft;
	if(fLeft != 0)
		fLeft /= totalFrames;
 
	var fTop = newTop - cTop;
	if(fTop != 0)
		fTop /= totalFrames;
 
	var fWidth = newWidth - cWidth;
	if(fWidth != 0)
		fWidth /= totalFrames;
 
	var fHeight = newHeight - cHeight;
	if(fHeight != 0)
		fHeight /= totalFrames;
   
	doFrame(elementID, cLeft, newLeft, fLeft,
		cTop, newTop, fTop, cWidth, newWidth, fWidth,
		cHeight, newHeight, fHeight, callback);
}

function doFrame(eID, cLeft, nLeft, fLeft, cTop, nTop, fTop, cWidth, nWidth, fWidth, cHeight, nHeight, fHeight, callback)
{
	var el = document.getElementById(eID);
	if(el == null)
		return;

	cLeft = moveSingleVal(cLeft, nLeft, fLeft);
	cTop = moveSingleVal(cTop, nTop, fTop);
	cWidth = moveSingleVal(cWidth, nWidth, fWidth);
	cHeight = moveSingleVal(cHeight, nHeight, fHeight);

	el.style.left = Math.round(cLeft) + 'px';
	el.style.top = Math.round(cTop) + 'px';
	el.style.width = Math.round(cWidth) + 'px';
	el.style.height = Math.round(cHeight) + 'px';
 
	if(cLeft == nLeft && cTop == nTop && cHeight == nHeight && cWidth == nWidth)
	{
		if(callback != null)
			callback();
		return;
	}
   
	setTimeout( 'doFrame("'+eID+'",'+cLeft+','+nLeft+','+fLeft+','
				+cTop+','+nTop+','+fTop+','+cWidth+','+nWidth+','+fWidth+','
				+cHeight+','+nHeight+','+fHeight+','+callback+')', 40);
}

function moveSingleVal(currentVal, finalVal, frameAmt)
{
	if(frameAmt == 0 || currentVal == finalVal)
		return finalVal;
 
	currentVal += frameAmt;
	if((frameAmt> 0 && currentVal>= finalVal) || (frameAmt <0 && currentVal <= finalVal))
	{
		return finalVal;
	}
	return currentVal;
}

function loadClipArt(clipart)
{
	if (leftright == 'l')
	{
		document.capform.clipart1.value = clipart;
		document.getElementById('leftclipart').src='elements/clipart/'+clipart+'.gif';
	}
	if (leftright == 'r')
	{
		document.capform.clipart2.value = clipart;
		document.getElementById('rightclipart').src='elements/clipart/'+clipart+'.gif';
	}
	slideExample1('clipartPanel', this);
}
