// JavaScript Document defining functions for daveespionage.com
// primarily written by David Cox-Espenlaub
// If you're reading this, congratulations on pulling this page down.  You win... umm..
// ... code...

//function to repeat strText numRepeat times
	function repeatText(strText,numRepeat){
		theString = new String();		// string to hold the repeated characters
		//theString = '\"' + strText + '\" , ' + numRepeat + '\n';  //debug code to determine what 
																	//has been passed to the func
		if (strText != '' && numRepeat > 0) {		// check to make sure nothing
													// is null or 0
			for (x = numRepeat;x>0;x--) {			// count down to zero from iteration
			 	theString = theString + strText;	// append strText to theString each time
													// the loop goes round
			}
			return(theString);						// dump the string in response
		}
	}

//function to write html to an element
	function writeElement(strElementID, strContents){
		if (strElementID != '' && strContents != '') {
			document.getElementById(strElementID).innerHTML = strContents;
		}
	}
	
//function to show or hide an element
	function changeVisible(strElementID){
		if (strElementID != '') {
			switch(document.getElementById(strElementID).style.display){
 				case 'inline' :
					document.getElementById(strElementID).style.display = 'none';			
				    break;
				case 'none' :
					document.getElementById(strElementID).style.display = 'inline';			
					break;
			}
		}
	}

//function to show or hide an element, ver2
	function changeVisibleSw(strElementID, strDisplay){
		if (strElementID != '' && strDisplay != '') {
				document.getElementById(strElementID).style.display = strDisplay;			
		}
	}

//function to act as lightswitch in a standardized naming convention of 
//spans, changing the conditions of strElementID, strElementID + 'closed' and strElementID + 'open'
	function changeAllVisible(strElementID){
		if (strElementID != '') {
			strElementIDc = strElementID + 'closed';
			strElementIDo = strElementID + 'open';
			changeVisible(strElementID);
			changeVisible(strElementIDc);
			changeVisible(strElementIDo);
		}
	}

	//function to make loading span dissapear on page load
		function showContent(){
			document.getElementById('spnContent').style.display = "inline";
		}
		function hideLoadingMessage(){
//				spans do not necessarily exist on all pages
//				so we need a func call that is customizable
//				from the page level. 
//			document.getElementById('spnQuote').style.display = "none";
			document.getElementById('spnLoading').style.display = "none";
			document.getElementById('spnContinue').style.display = "none";
			showContent();
		}
		function showCompleteMessage(){
			document.getElementById('spnContinue').style.display = "inline";
		}

function ShowMenu(numMenu){
	// function that changes the table visibility depending on which of a series of menu items
	// are selected
	// menuItems = number of items in the menu
	// numMenu = menu item number, also number of tblMenu id, I.E. tblMenu1, tblMenu0, tblMenu5000
	if (numMenu > -1) {
		var menuItems = 3;
		for (menuLoop = 0; menuLoop <= menuItems; menuLoop++){
			var eleName = 'tblMenu' + menuLoop;
//			alert('loop number ' + menuLoop + '\n' + 
//				'element called is ' + eleName);
			var objElement = document.getElementById(eleName);
			if (menuLoop != numMenu) {
				objElement.style.display = 'none';
			} else {
				objElement.style.display = 'inline';
			}
		}
	}
//	alert ('ShowMenu Called, ' + menuItems + ' menu items, menu item selected is ' + numMenu);
	return true;
}


//image preloaders
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_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_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];}
}

// woohoo, prints a page, doesn't work on macs.
function printpage() {
window.print();  
}

// makes a new window, abbreviated specs for easy function calls, 
// mypage = url
// myname = document.name or target reference for page
// w = width of window in px, h = height of window in px
// scroll = scrollbars?  "yes" or "no"
function NewWindow(mypage, myname, w, h, scroll) {
var browser = navigator.userAgent.toLowerCase();
this.win = browser.indexOf("win")!=-1;
this.mac = browser.indexOf("mac")!=-1;
if (this.win)
{
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
}
if (this.mac)
{
var winl = (screen.width) / 1.5;
var wint = (screen.height) / 1.5;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
}
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

// call this function to generate a random quote from the stored arrays.
// its, like, funny, and stuff.
function RandomQuote() {
//Random Quote Script
//original code by Christopher Schmitt
//store the quotations in arrays

quotes = new Array(68);
authors = new Array(68);
theQuote = new String();

quotes[0] = "Ok, first, we get an ark...";
authors[0] = "D.e.";
quotes[1] = "So if you want massive play, lose a teste right away.";
authors[1] = "Nice Guy Eddie: <U>Johnny One-Nut</U>";
quotes[2] = "Where are my pants?";
authors[2] = "Joy";
quotes[3] = "(in a Sean Connery impression) I am the last sock monkey.";
authors[3] = "Shane";
quotes[4] = "reninja";
authors[4] = "SuperZac";
quotes[5] = "Nessie lives.";
authors[5] = "SuperZac";
quotes[6] = "destrongers UNTIE!!!...oops...";
authors[6] = "SuperZac";
quotes[7] = "Watching the zebrazzizzies playin the xylophonizzizzies, and if you make that shyme's next single, i'll marry you.  We'll have kizzizzies";
authors[7] = "Steven Chenault";
quotes[8] = "word to the mothizzy.";
authors[8] = "Andy";
quotes[9] = "...Do not sleep on the mentioning of dimmer switches, because that, above all else, is exceptionally key, and exceptionally poorly lit.";
authors[9] = "SuperZac";
quotes[10] = "Why is the keyboard sticky?";
authors[10] = "Sarah";
quotes[11] = "Y'all smokin mad izm.";
authors[11] = "Steven Chenault";
quotes[12] = "It didn't make you look 'street', it made you look 'autistic'. seriously.";
authors[12] = "Andy";
quotes[13] = "Six million dollars and fourteen virgins.";
authors[13] = "Steve C.";
quotes[14] = "Good, Bad, I'm the one with the Gun.";
authors[14] = "Ash, in <U>Army of Darkness</U>";
quotes[15] = "Give me some sugar, baby.";
authors[15] = "Ash, in <U>Army of Darkness</U>";
quotes[16] = "Groovy.";
authors[16] = "Ash, in <U>Army of Darkness</U>";
quotes[17] = "Its a trick, get an axe.";
authors[17] = "Ash, in <U>Army of Darkness</U>";
quotes[18] = "but enough of that, back to the seafood sampler plate";
authors[18] = "Andy";
quotes[19] = "you're trying to give me cooties?";
authors[19] = "Steven Chenault";
quotes[20] = "I think Sarah's just upset that I can summon her into an orgy using the words 'bling bling'.";
authors[20] = "SuperZac";
quotes[21] = "Damn baby, you got some fine upholstry.";
authors[21] = "Monkey Lover";
quotes[22] = "As for the 'point', Chenault, how about the point of my peace pipe shoved up your Louisiana Purchase?";
authors[22] = "SuperZac";
quotes[23] = "I don't, I swear, nobabiesnobabiesnobabiespleasegod don'tlethimimpregnatemeIdon'trememberthefirstreferencesurelyIwasmakingthewholethingup whatarewetalkingaboutwhoareyouwherearemypants DON'TLETTHEMSTICKTHATTHINGINMEEEEEEEEEEEEEEEE!!!!!!";
authors[23] = "Joy!";
quotes[24] = "The shipping is extra cheap since electricity has no mass.";
authors[24] = "Andy";
quotes[25] = "THEY DON'T SELL ELECTRICITY AT RALPH'S!";
authors[25] = "Andy";
quotes[26] = "Hello, I'm looking for an oversized severed human head. i was referred to you by AbraKadavver.";
authors[26] = "Andy, in search of a severed head.";
quotes[27] = "Basically, any movie is in bad straits when everyone in the audience is disappointed that a Wayans brother has died.";
authors[27] = "Review of the <U>Dungeons and Dragons</U> movie.";
quotes[28] = "There was a parade?";
authors[28] = "Dave.";
quotes[29] = "Sign: Bondage ring (Libra, really..... :-P )";
authors[29] = "Sarah, from <a href=\"http://go.to/edbonyx\" target=\"_blank\">The Edbonyx Website</a>";
quotes[30] = "Take her away for regrooving.";
authors[30] = "Firesign Theatre, from <U>Waiting for the Electrician, Or Someone Like Him</U>";
quotes[31] = "When correctly viewed, EVERYTHING is lewd.";
authors[31] = "Tom Lehrer";
quotes[32] = "Occupations: Student, International Pain in the Ass, and the friendliest employee the Coffee Beanery has ever had.  I know it isn't saying much, but I really am a sweetheart at work.";
authors[32] = "Wray, from <a href=\"http://go.to/edbonyx\" target=\"_blank\">The Edbonyx Website</a>";
quotes[33] = "I too would like to see the aformentioned movie about dinosaurs.";
authors[33] = "Sedge, from <a href=\"http://go.to/edbonyx\" target=\"_blank\">The Edbonyx Website</a>";
quotes[34] = "Evolution or creation? A board with a nail in it. That is a little of both";
authors[34] = "Collin, from <a href=\"http://go.to/edbonyx\" target=\"_blank\">The Edbonyx Website</a>";
quotes[35] = "Science or magic? a unique blend of both that i like to call \"Smagic\"";
authors[35] = "Nick, from <a href=\"http://go.to/edbonyx\" target=\"_blank\">The Edbonyx Website</a>";
quotes[36] = "I�ve achieved a state of perfect bliss a good seven or eight times.  But then I forget again.";
authors[36] = "Joy, from <a href=\"http://go.to/edbonyx\" target=\"_blank\">The Edbonyx Website</a>";
quotes[37] = "Boxers or Briefs? No Thanks, I'm driving.";
authors[37] = "Geoff, from <a href=\"http://go.to/edbonyx\" target=\"_blank\">The Edbonyx Website</a>";
quotes[38] = "Favorite Bands: Rubber bands";
authors[38] = "Geoff, from <a href=\"http://go.to/edbonyx\" target=\"_blank\">The Edbonyx Website</a>";
quotes[39] = "Prison Area: Do not pick up hitchikers";
authors[39] = "A sign on I-75 just north of the Michigan-Ohio border";
quotes[40] = "you'll have a pig in my stead? our honeymoon will.... smell... interesting...";
authors[40] = "Steven Chenault";
quotes[41] = "Sleep?  On an Airplane?  That's Hilarious.";
authors[41] = "SuperZac";
quotes[42] = "All right!  Let's really stand around!";
authors[42] = "SuperZac";
quotes[43] = "But I mean, there is good, solid evidence for the Blair Witch being a pig. Let�s examine the facts.";
authors[43] = "SuperZac";
quotes[44] = "Somebody buy me a car... please?";
authors[44] = "D.e.";
quotes[45] = "Working as a slave to the man since time began.";
authors[45] = "D.e.";
quotes[46] = "Marketing: a good reason to ignore the hype.";
authors[46] = "D.e.";
quotes[47] = "You can call me Flower...OF DEATH!";
authors[47] = "D.e.";
quotes[48] = "Wie wird das gerechnet? Pro nacht oder pro stellung?(-How do you charge? By night, or by position?)";
authors[48] = "Blatantly borrowed from <a href=\"http://www.geocities.com/leananesidhe/\" target =\"_blank\">Herself</a>, from a reference in a translation book."; 
quotes[49] = "Don't toss me, I'm full of potato salad!";
authors[49] = "bumper of a catering van.";                               
quotes[50] = "When in doubt, revert to 'Yo Mama's a Ho.'";
authors[50] = "Yo Mama (little Mersmann)";
quotes[51] = "OH... Oh... wow.. that was weird.  I wonder if anyone's in the shower?";
authors[51] = "Jenny, in <i>Bitch-Ass Demons</i>";
quotes[52] = "A breakfast establishment where you can't get martinis?  Who do I cut first?";
authors[52] = "Nick, while brandishing a small slideblade knife.";
quotes[53] = "Automated movie ticket machines, automated parking ticket machines, but you have to butter your own popcorn.";
authors[53] = "Nick, on our way to see <i>How High</i>.";
quotes[54] = "We will rule the world with an iron fist, covered in a sock puppet.";
authors[54] = "D. &quot;DJ Tanner&quot; Goosebey, <BR>&nbsp;&nbsp;&nbsp;&nbsp;in regards to The Tundra, and <a href=\"http://www.soundonsoundoh.com\" target =\"_blank\">Sound On Sound</a>.";
quotes[55] = "TELL THEM THAT I AM JED!";
authors[55] = "<a href=\"http://www.damagehappy.com/jed\" target =\"_blank\">Jed</a>.";
quotes[56] = "I'm a turkey, gobble gobble, shoot me in the face.";
authors[56] = "D. &quot;DJ Tanner&quot; Goosebey";
quotes[57] = "FUCK EVERYTHING, DISCO'S DEAD!";
authors[57] = "<a href=\"http://www.damagehappy.com/jed\" target =\"_blank\">Jed</a>.";
quotes[58] = "FUCK THE DEAD, DISCO'S EVERYTHING!";
authors[58] = "Dave Espionage.";
quotes[59] = "I AM MEGA-SLEEPYTRON!";
authors[59] = "Dave Espionage.";
quotes[60] = "One person's traditionalist is another person's revolutionary.";
authors[60] = "Dave Espionage.";
quotes[61] = "i like my men the way i like my mexican. add some meat, a bit of cheese, some sauce, wrapped in a tortilla";
authors[61] = "<a href=\"http://www.be-persnickety.org/novacaine\" target =\"_blank\">Ashe</a>.";
quotes[62] = "Goat-Demon FACE!  Because the Chupacabra doesn't like it when you do that.";
authors[62] = "Dave Espionage.";
quotes[63] = "Then there was the whole piss-drinking thing.";
authors[63] = "Dave Espionage.";
quotes[64] = "you're not worth shit. go back to bed.";
authors[64] = "Andy 'I'm married and live in California, bitch' Nienaber.";
quotes[65] = "No more chocolate milk for me, I'm drivin.";
authors[65] = "Dave Espionage.";
quotes[66] = "there's an inherent flaw in the idea of 'not sleeping until I get on the plane.'";
authors[66] = "Dave Espionage.";
quotes[67] = "...and no bunny gets laid by the bunny of his or her dreams if they smell like piss...";
authors[67] = "Dave Espionage, in a bedtime story told to Ashe.";
quotes[68] = "I don't want to go through giving birth to kittens again.";
authors[68] = "Dave Espionage, right before going in for the night.";
quotes[69] = "I'm fucking her well!";
authors[69] = "Jason Doctor.";



//calculate a random index
	index = Math.floor(Math.random() * quotes.length);

//display the quotation
//	document.write("<DL>\n");
	theQuote = "<DT>" + "\"" + quotes[index] + "\"\n" + "</DT><DD><SMALL>" + "-- " + authors[index] + "</SMALL></DD>\n";
	return(theQuote);
//	document.write("<DT>" + "\"" + quotes[index] + "\"\n");
//	document.write("<DD><SMALL>" + "-- " + authors[index] + "\n");
//	document.write("</DL>\n");

//end of RandomQuote()
}


// Form Validation Functions for standard form value types
// english only, sadly
// and north american phone numbers/zip codes
function isEmailAddr(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function validRequired(formField,fieldLabel)
{
	var result = true;
	
	if (formField.value == "")
	{
		alert('Please enter a value for the "' + fieldLabel +'" field.');
		formField.focus();
		result = false;
	}
	
	return result;
}

function allDigits(str)
{
	return inValidCharSet(str,"0123456789");
}

function inValidCharSet(str,charset)
{
	var result = true;

	// Note: doesn't use regular expressions to avoid early Mac browser bugs	
	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = false;
			break;
		}
	
	return result;
}

function validEmail(formField,fieldLabel,required)
{
	var result = true;
	
	if (required && !validRequired(formField,fieldLabel))
		result = false;

	if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
	{
		alert("Please enter a complete email address in the form: yourname@yourdomain.com");
		formField.focus();
		result = false;
	}
   
  return result;

}

function validNum(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		if (!allDigits(formField.value))
 		{
 			alert('Please enter a number for the "' + fieldLabel +'" field.');
			formField.focus();		
			result = false;
		}
	} 
	
	return result;
}


function validInt(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		var num = parseInt(formField.value,10);
 		if (isNaN(num))
 		{
 			alert('Please enter a number for the "' + fieldLabel +'" field.');
			formField.focus();		
			result = false;
		}
	} 
	
	return result;
}


function validDate(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		var elems = formField.value.split("/");
 		
 		result = (elems.length == 3); // should be three components
 		
 		if (result)
 		{
 			var month = parseInt(elems[0],10);
  			var day = parseInt(elems[1],10);
 			var year = parseInt(elems[2],10);
			result = allDigits(elems[0]) && (month > 0) && (month < 13) &&
					 allDigits(elems[1]) && (day > 0) && (day < 32) &&
					 allDigits(elems[2]) && ((elems[2].length == 2) || (elems[2].length == 4));
 		}
 		
  		if (!result)
 		{
 			alert('Please enter a date in the format MM/DD/YYYY for the "' + fieldLabel +'" field.');
			formField.focus();		
		}
	} 
	
	return result;
}

// validates an entire form, establish which form elements you want to fix, 
// so it knows which kinds of data to filter for
function validateForm(theForm)
{
	// Customize these calls for your form

	// Start ------->
	if (!validRequired(theForm.name,"Name"))
		return false;

	if (!validEmail(theForm.email,"Email Address",true))
		return false;

	// <--------- End
	
	return true;
}

// begin absolutely positioned scrollable area object scripts 
/*
Extension developed by David G. Miles (www.z3roadster.net/dreamweaver)
Original Scrollable Area code developed by Thomas Brattli 
To add more shock to your site, visit www.DHTML Shock.com
*/

function verifyCompatibleBrowser(){ 
    this.ver=navigator.appVersion 
    this.dom=document.getElementById?1:0 
    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0; 
    this.ie4=(document.all && !this.dom)?1:0; 
    this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
 
    this.ns4=(document.layers && !this.dom)?1:0; 
    this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5) 
    return this 
} 
bw=new verifyCompatibleBrowser() 
 
 
var speed=50 
 
var loop, timer 
 
function ConstructObject(obj,nest){ 
    nest=(!nest) ? '':'document.'+nest+'.' 
    this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0; 
    this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0; 
    this.scrollHeight=bw.ns4?this.css.document.height:this.el.offsetHeight 
    this.clipHeight=bw.ns4?this.css.clip.height:this.el.offsetHeight 
    this.up=MoveAreaUp;this.down=MoveAreaDown; 
    this.MoveArea=MoveArea; this.x; this.y; 
    this.obj = obj + "Object" 
    eval(this.obj + "=this") 
    return this 
} 
function MoveArea(x,y){ 
    this.x=x;this.y=y 
    this.css.left=this.x 
    this.css.top=this.y 
} 
 
function MoveAreaDown(move){ 
	if(this.y>-this.scrollHeight+objContainer.clipHeight){ 
    this.MoveArea(0,this.y-move) 
    if(loop) setTimeout(this.obj+".down("+move+")",speed) 
	} 
} 
function MoveAreaUp(move){ 
	if(this.y<0){ 
    this.MoveArea(0,this.y-move) 
    if(loop) setTimeout(this.obj+".up("+move+")",speed) 
	} 
} 
 
function PerformScroll(speed){ 
	if(initialised){ 
		loop=true; 
		if(speed>0) objScroller.down(speed) 
		else objScroller.up(speed) 
	} 
} 
 
function CeaseScroll(){ 
    loop=false 
    if(timer) clearTimeout(timer) 
} 
var initialised; 
function InitialiseScrollableArea(){ 
    objContainer=new ConstructObject('divContainer') 
    objScroller=new ConstructObject('divContent','divContainer') 
    objScroller.MoveArea(0,0) 
    objContainer.css.visibility='visible' 
    initialised=true; 
} 
// end absolutely positioned scrollable area object scripts 

function form1_validate() {
// validates a form with name fields, email addresses and phone numbers
	var everythingIsOk = true;
	var objForm = document.form1; 		// the form
	var Firstname = objForm.firstname 	// the first name
	var Lastname = objForm.lastname 	// the last name	
	var Email = objForm.email_address;  // the email field
	var Phone = objForm.phone;			// the first phone field
	var Phone2 = objForm.phone2;		// the second phone field
	var Fax = objForm.fax;				// the fax field

  if(Firstname.value == "") {
    alert('Please enter your first name.');
	Firstname.focus();
	everythingIsOk = false;
	return false;
  }
  if(Lastname.value == "") {
    alert('Please enter your last name.');
	Lastname.focus();
	everythingIsOk = false;
	return false;
  }

// check what is selected, store what it is, and see if the corresponding field is filled in
fieldsToCheck = new Array('email_address', 'phone', 'phone2', 'fax');

	for(j=0; j< objForm.radio1.length; j++){
    	if(objForm.radio1[j].checked){
        	selectedRadio = objForm.radio1[j].value;
			switch(selectedRadio) { 
				case 'E': { // Email is checked
//					alert('calling case E');
					if(!isValidEmail(Email.value)) {
				 	   alert('Please check your email address.');
						Email.focus();
						everythingIsOk = false;
						return false;
					}
					break
				}
				case 'T': { // Telephone is Checked
//					alert('calling case T');
					if(!isValidPhone(Phone, 'Phone')) {
						everythingIsOk = false;
						return false;
					}
					break
				}
				case 'F': { // Fax is Checked
//					alert('calling case F');
					if(!isValidPhone(Fax, 'Fax')) {
						everythingIsOk = false;
						return false;
					}
					break
				}
				default: {
					// no default action //
				}
			}// end switch		
        }// end if radio checked
	}// end for
// submit

  if (everythingIsOk == true) {
    objForm.submit('contact.php');
  }
}

function isValidEmail(email) {
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0) {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1)) result = true;
  }
  return result;
}

function titleChange() {
  title = document.register.title.value;
  if((title == "Mr.") || (title == "Rev.") || (title == "Rev. Mr.")) {
	disableHer();
	enableHim();
  }
  if((title == "Mrs.") || (title == "Sister")) {
    disableHim();
	enableHer();
  }
  if((title == "none") || (title == "Mr and Mrs")) {
    enableHim();
	enableHer();
  }
}

function enableHim() {
  his = document.register.hisFirst;
  his.value = "";
  his.className = 'input';
  //his.disabled = false;
}
function disableHim() {
  his = document.register.hisFirst;
  his.value = "none";
  his.className = 'disabledInput';
  //his.disabled = true;
}
function enableHer() {
  her = document.register.herFirst;
  her.value = "";
  her.className = 'input';
  //her.disabled = false;
}
function disableHer() {
  her = document.register.herFirst;
  her.value = "none";
  her.className = 'disabledInput';
  //her.disabled = true;
}

function ShowMenu(numMenu){
// function that changes the table visibility depending on which of a series of menu items
// are selected
// menuItems = number of items in the menu
// numMenu = menu item number, also number of tblMenu id, I.E. tblMenu1, tblMenu0, tblMenu5000
	if (numMenu > -1) {
		var menuItems = 3;
		for (menuLoop = 0; menuLoop <= menuItems; menuLoop++){
			var eleName = 'tblMenu' + menuLoop;
//			alert('loop number ' + menuLoop + '\n' + 
//				'element called is ' + eleName);
			var objElement = document.getElementById(eleName);
			if (menuLoop != numMenu) {
				objElement.style.display = 'none';
			} else {
				objElement.style.display = 'inline';
			}
		}
	}
//alert ('ShowMenu Called, ' + menuItems + ' menu items, menu item selected is ' + numMenu);
clearFields();
return true;
}

function clearFields(){
	// clears all fields affected by radio button selection change
	var objForm = document.form1;
	fieldsToClear = new Array('email_address', 'phone', 'phone2', 'fax');
	for (theField in fieldsToClear) {
		objFormElement = eval('objForm.' + fieldsToClear[theField]);
		objFormElement.value = '';
	}
}

/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function isValidPhone(Phone, strTypeOf) {
	//checks to see if a phone field is blank or invalid
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your " + strTypeOf + " Number")
		Phone.focus()
		everythingIsOk = false;
		return false
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid " + strTypeOf + " Number")
		Phone.value=""
		Phone.focus()
		everythingIsOk = false;
		return false
	}
	return true
}

function launchPlayer(URL){
	// launches mp3 player window
	windowvar = null;
	day = new Date();
	id = day.getTime();
	eval("windowvar = window.open(URL, 'player', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=200');");
}
