function checkit(id1,id2)
{

var nodeObj1 = document.getElementById(id1);
var nodeObj2 = document.getElementById(id2);
var tx = nodeObj1.value;
if (tx.length != 0)
{
var agree = confirm('You have given your email address as ' + '\n\n' + tx + '\n\n' + 'Are you sure this is correct?');
if (agree)
{
nodeObj2.focus();
return true;
}
else
{
nodeObj1.focus();
return false;
}
}
}

var error = false;

//Preventing hitting enter submitting form **************

function noenter()
{
 return !(window.event && window.event.keyCode == 13);
}

//Preventing all capitals **************

// Original:  jgw (jgwang@csua.berkeley.edu ) 
// Web Site:  http://www.csua.berkeley.edu/~jgwang/ 

function checkCapsLock( e ) {
	var myKeyCode=0;
	var myShiftKey=false;
	var myMsg='Caps Lock is On.\n\nPlease press Caps Lock to turn it Off.\n\nWe request you do not type in all capital letters\njust capital letters where capital letters are needed.';

	// Works for Internet Explorer 4+ but has no effect in Netscape
	if ( document.all ) {
		myKeyCode=e.keyCode;
		myShiftKey=e.shiftKey;
	} 

	// Upper case letters are seen without depressing the Shift key, therefore Caps Lock is on
	if ( ( myKeyCode >= 65 && myKeyCode <= 90 ) && !myShiftKey ) {
		alert( myMsg );
            e.returnValue = false;
	// Lower case letters are seen while depressing the Shift key, therefore Caps Lock is on
	} else if ( ( myKeyCode >= 97 && myKeyCode <= 122 ) && myShiftKey ) {
		alert( myMsg );
            e.returnValue = false;
	}
}

function lengthCountdown(field, maxlength)
{
 if (field.value.length == maxlength)
 {
  field.value = field.value.substring(0, maxlength);
  alert('Please keep your posting short!\n\nIf you go beyond this point the comments box will reset!');
 }
 if (field.value.length > maxlength)
 {
  field.value = field.value.substring(0, maxlength);
  alert('You appeared to have attempted to paste in a large block of text.\n\nThis isn\'t allowed and the box will reset.');
  document.theform.message.value = "";
 }
 else eval('field.form.' + field.name+ 'Length.value = maxlength - field.value.length');
}

function validateForm(form)
{
 var nameStatus = validateName(form.name);
 var locationStatus = validateLocation(form.residence);
 var emailStatus = validateEmail(form.email);
 var commentsStatus = validateComments(form.message);

 if (nameStatus&&locationStatus&&emailStatus&&commentsStatus)
 {
  if (warnComments(form.message)) return confirm('Your submission is ready to send.\n\nClick CANCEL if you want to first follow a link\n or change your submission. \n\nClick OK to submit your message \n\t and then WAIT for details!');
  else return false;
 }
 else
 {
  error = false;
  if (!nameStatus&&!error) erroresidence(form.name);
  if (!locationStatus&&!error) errorLocation(form.residence);
  if (!emailStatus&&!error) errorEmail(form.email);
  if (!commentsStatus&&!error) errorComments(form.message);
  return false;
 }
}

function validateName(field)
{
 if (field.value.length == 0)
 {
  return false;
 }
 else
 {
  var re = /[^ .,\-a-zA-Z]/;
  return !re.test(field.value);
 }
}

function validateLocation(field)
{
 if (field.value.length == 0)
 {
  return false;
 }
 else
 {
  var re = /[^ .,\-a-zA-Z0-9]/;
  return !re.test(field.value);
 }
}

function validateEmail(field)
{
 if (field.value.length == 0)
 {
  return false;
 }
 else
 {
  var re = /^[a-zA-Z_0-9\-.]+@[a-zA-Z_0-9\-.]+\.[a-zA-Z_0-9\-.]+$/;
  return re.test(field.value);
 }
}

function validateComments(field)
{
 if (field.value.length == 0)
 {
  return false;
 }
 else
{
 //  Two regexp checks now. First one checks for bad words and second checks if
 // there are any lowercase characters and negates the result (Hence equivalent
 // to checking if all the characters are uppercase). Notice no 'i' flag in the
 // second. Also the regexps can now match strings such as 'o - r - a - l' - try
 // it, pretty cool, eh?
 var re = /f(\W){0,3}u(\W){0,3}c(\W){0,3}k|s(\W){0,3}u(\W){0,3}c(\W){0,3}k|c(\W){0,3}o(\W){0,3}c(\W){0,3}k|s(\W){0,3}h(\W){0,3}i(\W){0,3}t|c(\W){0,3}u(\W){0,3}n(\W){0,3}t|b(\W){0,3}a(\W){0,3}s(\W){0,3}t(\W){0,3}a(\W){0,3}r(\W){0,3}d|a(\W){0,3}n(\W){0,3}a(\W){0,3}l|o(\W){0,3}r(\W){0,3}a(\W){0,3}l|>|<font|http:|www\.|\.org|\.com|\.co\.uk|\.net|please pray|pray for|tithe|tithing/i;
 var re2 = /[a-z]/;
 return !((re.test(field.value))||(!re2.test(field.value)));
 }
}

function erroresidence(field)
{
 if (field.value.length == 0)
 {
  alert("Please enter your name.");
 }
 else
 {
  var re = /[^ .,\-a-zA-Z]/;
  alert('Your name cannot contain a '+ re.exec(field.value)[0]+ ' character!');
 }
 field.focus();
 error = true;
}

function errorLocation(field)
{
 if (field.value.length == 0)
 {
  alert("Please enter your location.");
 }
 else
 {
  var re = /[^ .,\-a-zA-Z0-9]/;
  alert('Your location cannot contain a '+ re.exec(field.value)[0]+ ' character!');
 }
 field.focus();
 error = true;
}

function errorEmail(field)
{
 if (field.value.length == 0)
 {
  alert('Please enter your email address.');
 }
 else
 {
  var re = /[^a-zA-Z_0-9\-.@]/;
  reResult = re.exec(field.value);
  if (reResult == null)
  {
   if (!/@/.exec(field.value)) alert('Your email address must contain\n\t an @ character!');
   else if (!/@.*\./.exec(field.value)) alert('Your email address must contain\n\t  a . character after the @!');
   else if (!/.+@/.exec(field.value)) alert('Your email address must contain\n\t  a useresidence before the @ character!');
   else if (!/@[^@]+\..+/.exec(field.value)) alert('Your email address must contain\n\t  a valid domain name after the @ character!');
  }
  else
  {
   alert('Your email address cannot contain a '+ reResult[0]+ ' character!');
  }
 }
 field.focus();
 error = true;
}

function errorComments(field)
{
 if (field.value.length == 0)
 {
  alert('Please say something - even if just \"Hello\".');
 }
 else
 {
  //  Four regexps now, grouped for readability. First checks for bad words,
  // second for inappropriate topics, third for formatting, and last for
  // uppercase evil. They have been separated for friendlier user-feedback.
  var re = /f(\W){0,3}u(\W){0,3}c(\W){0,3}k|s(\W){0,3}u(\W){0,3}c(\W){0,3}k|c(\W){0,3}o(\W){0,3}c(\W){0,3}k|s(\W){0,3}h(\W){0,3}i(\W){0,3}t|c(\W){0,3}u(\W){0,3}n(\W){0,3}t|b(\W){0,3}a(\W){0,3}s(\W){0,3}t(\W){0,3}a(\W){0,3}r(\W){0,3}d/i;
  var re2 = /a(\W){0,3}n(\W){0,3}a(\W){0,3}l|o(\W){0,3}r(\W){0,3}a(\W){0,3}l/i;
  var re3 = />|<font/i;
  var re4 = /[a-z]/;
  var re5 = /http:|www\.|\.org|\.com|\.co\.uk|\.net/i;
  var re6 = /please pray|pray for/i;
  var re7 = /tithe|tithing/i;

  if (re.test(field.value))
  {
   alert('This communication cannot be posted! It appears to contain abuse or swear words.');
  }
  else if (re2.test(field.value))
  {
   alert('This communication cannot be posted! Your TOPIC is unsuitable for this site.');
  }
  else if (re3.test(field.value))
  {
   alert('We aren\'t able to accept your submission like this! You appear to be using formatting - e.g. the symbol \>. Please enter plain text.');
  }
  else if (!re4.test(field.value))
  {
   alert('Sorry! We don\'t accept submissions in all capitals!\n\nPlease re-type your message with Caps Lock off and save our eyes. Thanks!');
  }
  else if (re5.test(field.value))
  {
   alert('Sorry! You can\'t put web addresses or email addresses in the message box.\n\nDo you have another message or simply a greeting?');
  }
  else if (re6.test(field.value))
  {
   alert('Instead of leaving a prayer request\nplease leave a short prayer.\n\nI will then stand in agreement\nwith you over your prayer.');
  }
  else if (re7.test(field.value))
  {
   window.location.href = "../minilesson/titheclosure.html";
  }
 }
 field.focus();
 error = true;
}

function transfertattoo()
{
window.location = "../minilesson/tattoo.html"
}

function warnComments(field)
{
  if (/divorce/i.exec(field.value)) return confirm('Have you read my page \"Divorce Recovery\"?\n\n No? Click CANCEL to check this out\n\t - use my site\'s TOPIC DIRECTORY.\n\n Yes? Click OK to continue with the submission.');

 if (/marriage/i.exec(field.value)) return confirm('Have you read my page \"Love and Marriage\"?\n\n No? Click CANCEL to check this out\n\t - use my site\'s TOPIC DIRECTORY.\n\n Yes? Click OK to continue with the submission.');

 if (/tattoo|tattoos/i.exec(field.value)) return confirm('Have you read my page \"Tattoos and the Christian\"?\n\n No? Click CANCEL to check this out\n\t - use my site\'s TOPIC DIRECTORY.\n\n Yes? Click OK to continue with the submission.');

 return true;
 
}

