// dunnschapel.org javascript functions
/*
var quotes = new Array();
quotes[0] = new quotation("The grass withers and the flowers fall, but the word of our God stands forever.", 'Isaiah&nbsp;40:8');
quotes[1] = new quotation("For God so loved the world that He gave His only begotten Son, that whoever believes in Him should not perish but have everlasting life.", 'John&nbsp;3:16');
quotes[2] = new quotation("My sheep listen to my voice; I know them, and they follow me. I give them eternal life, and they shall never perish; no one can snatch them out of my hand. My Father, who has given them to me, is greater than all; no one can snatch them out of my Father's hand. I and the Father are one.", 'John 10:27-30');

function quotation(quote, ref)
{
	this.quote = quote;
	this.ref = ref;
}

function random_quote()
{
	var quoteframe = document.getElementById('verse');
	if(quoteframe)
	{
		var i = Math.round(Math.random() * (quotes.length-1));
		quoteframe.innerHTML = "<p class=\"versetext\">"+quotes[i].quote+"</p><p class=\"verseref\">"+quotes[i].ref+"</p>";
	}
}
*/

function toggleLayer(layername, toggle)
{
 	var ele = document.getElementById(layername);
 	
 	if(ele) ele.style.display = toggle;
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function checkEmail(inputvalue)
{
	var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
	var chararray = [',', ';', ' ', '/'];
	var retval = false;
    		
	inputvalue = inputvalue.trim();
	retval = pattern.test(inputvalue);
	if(retval)
	{
		for (var i=0; i<chararray.length; i++)
		{
			if (inputvalue.indexOf(chararray[i]) != -1)
			{
				retval = false;
				break;
			}
		}
    }

	return retval;
}

function check_changes(form1, applyelement, statusmessageelement)
{
	if (form1.sendername.value == '')
	{
		statusmessageelement.innerHTML = 'Enter your name';
		applyelement.disabled = true;
		return false;
	}

/*	if (form1.address.value == '')
	{
		statusmessageelement.innerHTML = 'Enter your address<br><br>';
		applyelement.disabled = true;
		return false;
	}

	if (form1.pobox.value == '')
	{
		statusmessageelement.innerHTML = 'Enter your last name<br><br>';
		applyelement.disabled = true;
		return false;
	}

	if (form1.city.value == '')
	{
		statusmessageelement.innerHTML = 'Enter your city<br><br>';
		applyelement.disabled = true;
		return false;
	}

	if ((form1.state.value == '') || (form1.STATE.value.length != 2))
	{
		statusmessageelement.innerHTML = 'Enter your 2-character state abbreviation<br><br>';
		applyelement.disabled = true;
		return false;
	}

	if (form1.zip.value == '')
	{
		statusmessageelement.innerHTML = 'Enter your zip-code<br><br>';
		applyelement.disabled = true;
		return false;
	}
*/
	if ((form1.email.value == '') || (!checkEmail(form1.email.value)))
	{
		statusmessageelement.innerHTML = 'Enter your valid email address';
		applyelement.disabled = true;
		return false;
	}

	if (form1.comment.value == '')
	{
		statusmessageelement.innerHTML = 'Enter your comment/question';
		applyelement.disabled = true;
		return false;
	}

	if ((form1.captcha_code.value == '') || (form1.captcha_code.value.length != 5))
	{
		statusmessageelement.innerHTML = 'Enter the text from the image';
		applyelement.disabled = true;
		return false;
	}
			
	statusmessageelement.innerHTML = 'Click the Submit button to send the message';
	applyelement.disabled = false;
	return true;
}

function resetform(emailform)
{
	var el = document.getElementById('statusmessage');
	if(el)
	{
		el.innerHTML = 'Enter your name';
		emailform.sendername.focus();
		emailform.sendbutton.disabled = true;
	}
}

var onkeyuphandler = function(){ check_changes(document.emailform, document.emailform.sendbutton, document.getElementById('statusmessage'));}
function init()
{
	var emailform = document.emailform;
	if(emailform)
	{
		var ele = null;
		for (var i=0; i < emailform.elements.length; i++)
		{
			ele = emailform.elements[i];
			if(ele.type == 'text' || ele.type == 'textarea')
			{
				ele.onkeyup = function () { onkeyuphandler(); }
			}
			else if(ele.type == 'reset')
			{
				ele.onmouseup = function () { onkeyuphandler(); resetform(emailform); }
			}
		}
	}
}

window.onload = init;

if(typeof slideshow=="function")
{
	window.onload = function (){ slideshow(); init();}
}


