<!--//hidden

////////////////////////////////////////////////////////
// Coded by Jesse Knowles | http://www.jesseknowles.com
// description: Common functions used in most websites
// Author: jesse@jesseknowles.com
// Last Modified: 07-09-03
////////////////////////////////////////////////////////


////////////
// Platform
////////////

var agt=navigator.userAgent.toLowerCase();
var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
var is_mac= (agt.indexOf("mac")!=-1);

///////////////////////////////////
// Common function initializations
///////////////////////////////////

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//////////////////////
// Get URL
//////////////////////

function getPage(address) {
	location.href = address;
}

//////////////////////
// Preload Images
//////////////////////

// imagePreload( '01.gif', '02.gif' ); 
function imagePreload()
{ 
  var args = imagePreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}

//////////////////////
// Status Bar Message
//////////////////////

window.defaultStatus="New Tribes Bible Institute";

function statusBar(msg) {
	self.status=msg;
}


//////////////////////
// Bookmark this page
//////////////////////
function bookmark() {
	var txt = "Bookmark Us!";
	var url = document.location;
	var who = document.title;

	var ver = navigator.appName;
	var num = parseInt(navigator.appVersion);
	if ((ver == "Microsoft Internet Explorer")&&(num >= 4)) {
		window.external.AddFavorite(url,who);
	}else{
	   txt += "  (Ctrl+D)";
	   document.write(txt);
	}
}

////////////////////////////////////
// Popup window in center of screen
////////////////////////////////////

function popupWin(theURL,popWidth,popHeight){
	var winleft = (screen.width - popWidth) / 2;
	var winUp = (screen.height - popHeight) / 2;
	window.open(theURL, 'popup','toolbar=no, scrollbars=no,width='+popWidth+',height='+popHeight+',left='+winleft+',top='+winUp);
}
function popupWin_scroll(theURL,popWidth,popHeight){
	var winleft = (screen.width - popWidth) / 2;
	var winUp = (screen.height - popHeight) / 2;
	window.open(theURL, 'popup','toolbar=no, scrollbars=yes,width='+popWidth+',height='+popHeight+',left='+winleft+',top='+winUp);
}

////////////////////////////////////
// Map popup window - explore section
////////////////////////////////////

function popupMap(image, country, popWidth, popHeight){
	var winleft = (screen.width - popWidth) / 2;
	var winUp = (screen.height - popHeight) / 2;
	window.open("../explore/map.php?map=" + image + "&country=" + country, 'popup','toolbar=no, scrollbars=no,width='+popWidth+',height='+popHeight+',left='+winleft+',top='+winUp);
}

////////////////////////////////////
// News image popup window - news section
////////////////////////////////////

function popupPhoto(image, imgname, popWidth, popHeight){
	var winleft = (screen.width - popWidth) / 2;
	var winUp = (screen.height - popHeight) / 2;
	window.open("image.php?image=" + image + "&imgname=" + imgname, 'popup','toolbar=no, scrollbars=no,width='+popWidth+',height='+popHeight+',left='+winleft+',top='+winUp);
}

//////////////////////
// Disable Right Click
//////////////////////

function disableRightClick()
{
  var message = "Right click disabled";
  
  if(!document.rightClickDisabled) // initialize
  {
    if(document.layers) 
    {
      document.captureEvents(Event.MOUSEDOWN);
      document.onmousedown = disableRightClick;
    }
    else document.oncontextmenu = disableRightClick;
    return document.rightClickDisabled = true;
  }
  if(document.layers || (document.getElementById && !document.all))
  {
    if (e.which==2||e.which==3)
    {
      return false;
    }
  }
  else
  {
    return false;
  }
}
// disableRightClick();

//////////////////////
// Status Bar Message
//////////////////////

function statusBar(msg) {
	self.status=msg;
}
window.defaultStatus="NTM";


///////////////
// blur anchors
///////////////

function blurAnchors(){
  if(document.getElementsByTagName){
    var a = document.getElementsByTagName("a");
    for(var i = 0; i < a.length; i++){
      a[i].onfocus = function(){this.blur()};
    }
  }
}
window.onload = blurAnchors;

//////////////////
// hyper cells
//////////////////

function hyperCell_over(object, color){
	object.style.backgroundColor = color; 
	object.style.cursor = "hand";
}

function hyperCell_out(object){
	object.style.backgroundColor = "";
}

function hyperCell_click(url){
	window.location.href = url;
}

///////////////////////////////
// show or hide table elements
///////////////////////////////
// value 1 - name of select field 
// value 2 - comma separated string of select options which are the same as your id's
// value 3 - comma separated string of how many form fields corespond to value 2
function showHide(formSelect, idArray, fieldsArray){
	// initialize form elements
	form = document.forms[0];
	formSelect = form.elements[formSelect];
	// get value of form element
	idArray = idArray.split(","); 
	fieldsArray = fieldsArray.split(","); 
	formElements = document.forms[0].elements.length;
	// find element key so we can clear old element value
	for(i=0; i<form.length; i++){ if(form.elements[i].value == formSelect.value){ key = i; } }		
	// decide what to display and what not to display
	fieldsArraySum = 1;
	for(i=0; i<idArray.length; i++){ 
		if(formSelect.value == idArray[i]){ displayValue = ''; }
		else{ displayValue = 'none'; }
		// remove all value's given for input fields
		for(z=0; z<fieldsArray[i]; z++){ 		
			form.elements[fieldsArraySum + key + z].value = ''; 
		}
		fieldsArraySum = eval(fieldsArraySum + eval(fieldsArray[i]));
		// to display or not to display - that is the question		
		document.getElementById(idArray[i]).style.display = displayValue; 
	}
}

///////////////////////////////
// control flash via javascript
///////////////////////////////

function mediaPlay(type, file, name, length){
	flashObj = 'flashHeader';
   	if (navigator.appName.indexOf("Microsoft Internet")!=-1){ flashObj =  eval("window." + flashObj); }
   	else { flashObj = eval("window.document." + flashObj); }
	flashObj.SetVariable('type', type); 
	flashObj.SetVariable('file', file); 
	flashObj.SetVariable('itemName', name);
	flashObj.SetVariable('itemLength', length);
	flashObj.TCallLabel('/media_player', type); 
}
// -->

///////////////////////////////
// Automatic format phone numbers.
///////////////////////////////
function formatPhoneNum(e) {
	var isIE4=false;
	if (parseInt(navigator.appVersion.charAt(0))>=4){
		isIE4=(navigator.appName.indexOf("Microsoft"!=-1)) ? true:false
	}
	var charCode
	if (isIE4){
		var charCode = e.keyCode;
		var obj_name = window.event.srcElement.name
		var strPhone = eval("document.forms[0]."+obj_name+".value");
		if (strPhone.length<14){
			if (!(charCode >= 48 && charCode <= 57)) return false;
		}
		else return false;
		if (strPhone.length==0) eval("document.forms[0]."+obj_name+".value=('(')");
		else if (strPhone.length==4) eval("document.forms[0]."+obj_name+".value=(strPhone+') ')");
		else if (strPhone.length==9) eval("document.forms[0]."+obj_name+".value=(strPhone+'-')");
		return true;
	}
	else return true;
}

///////////////////////////////
// Email validation.
///////////////////////////////
function isvalid_email(oEmail){
	if (document.layers||document.getElementById||document.all) {
		var str=oEmail.value;
		if (str!=''){
			var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
			if (!filter.test(str)) {
				alert("Please input a valid email address!");
				oEmail.select();
				oEmail.focus();
			}
		}
	}
}