/*
	common js library
	©2006-2007 gbible.org | Grace Bible Church | Robert McLaughlin Bible Ministries
	All Rights Reserved.
	Contact:
	Marc Pomeroy
	marc@soulfuric.com
	m.pomeroy@traxsource.com
*/

// Search validate
function doSearch() {
	if(document.searchf.scrit.value=="" || document.searchf.scrit.value.length<3) {
		alert("Please enter something larger to search.");
		document.searchf.scrit.focus();
		return false;
	}
}

// Read text size toggle
function toggleReadSize() {
	var obj  = document.getElementById("read");
	var obj2 = document.getElementById("textsize");
	
	if (obj.className == "readSm") {
		obj.className = "readLG";
		obj2.value = "Reduce Text";
	} else {
		obj.className = "readSm";
		obj2.value = "Enlarge Text";
	}
}


// create a window:
function WindowCreate(script, win_name, width, height)
{
  wFeatures = 'width='+width+',height='+height+',copyhistory=0,directories=0,location=0,menubar=0,resizable=-1,scrollbars=-1,status=0,toolbar=0';
	temp_win = open(script, win_name, wFeatures);
	temp_win.focus();
}


// create a CENTERED window:
function WindowCreateCenter(script, win_name, width, height, resize, scrolls)
{
	var left = (screen.width/2) - width/2; 
	var top  = (screen.height/2) - (height/2)-50; 
	wFeatures = 'width='+width+',height='+height+',copyhistory=0,directories=0,location=0,menubar=0,resizable='+resize+',scrollbars='+scrolls;
	wFeatures += ',status=-1,toolbar=0,left='+left+',top='+top+',screenX='+left+',screenY='+top;
	temp_win = open(script, win_name, wFeatures);
	temp_win.focus();
}


// goto a location after a confirmation:
function ConfirmAction(URL, Question)
	{
	  self.status='';
		if (confirm(Question))
			location.href=URL;
	}


// auto submit a form after a confirmation:
function confirmSubmit(formName, Prompt)
	{
			self.status='';
			if (confirm(Prompt))
				document.forms[formName].submit();	
	}


// validate email (Thanks Rolly!):
function ValidateEmail(email)
{
  var fEmailOK = true;
  var num = 0;

  for (var i = 0; i < email.length; ++i) {
    var ch = email.charAt(i);
    if (ch == "@") {
      num = num + 1;
    }
  }
  if (num != "1")
    return false;

  var num2 = 0;
  for (var i = 0; i<email.length; ++i) {
    var ch = email.substring(i,i+2);
    if ((ch == "..")||(ch == ".@")||(ch == "@.")) {
      return false;
    }
  }
  if (email.length < 4)
    return false;
  else if (email.lastIndexOf(' ') != -1)
    return false;
  else if ((email.substring(0,1) == ".")||(email.substring(0,1) == "@")) {
    return false;
  }
  else if (email.lastIndexOf('\'') != -1)
    return false;
  else if ((i = email.lastIndexOf('@')) == -1)
    return false;
  else { // Get substring
    var tail = email.substring(i+1, email.length);
    if (tail.length < 3)
      return false;
    else if ((i = tail.lastIndexOf('.')) == -1)
      return false;
    else {
      var tailend = tail.substring(i+1, tail.length);
      if (tailend.length == 0)
        return false;
    }
  }
  return true;
}
