function inputTextFocus(el,theText) {
	if(el.value == theText) { el.value = ""; }
}
function inputTextBlur(el,theText) {
	if(el.value == "" || el.value == " ") { el.value = theText; }
}

function listenLivePop() {
	window.open('http://66.225.205.19/MediaPlayer-Spirit/', '_blank', 'width=739,height=449,status=yes,resizable=no,screenx=15,screeny=15'); 
}

function mailpage() {
	mail_str = "mailto:?subject=" + document.title;
	mail_str += "&body=I thought you might be interested in the " + document.title;
	mail_str += ". You can view it at " + location.href;
	location.href = mail_str;
}

// PRAYER PAGE FUNCTIONS ////////////////////
function togglePrayerBox() {
	var thePrayerBox = document.getElementById('prayerBoxContent');
	thePrayerBox.style.display = (thePrayerBox.style.display == 'block') ? 'none': 'block';
}

function validateEventSubmit(theForm) {
	var reason = "";
	reason += validateEmpty(theForm.title,"Event");
	reason += validateEmpty(theForm.content,"Description");
	reason += validateEmpty(theForm.startdate,"Start Date");
	reason += validateEmpty(theForm.time,"Time");
	reason += validateEmpty(theForm.place,"Place");
	reason += validateEmpty(theForm.city,"City");
	reason += validateEmpty(theForm.yourname,"Your Name");
	reason += validateEmpty(theForm.youremail,"Your Email");
	reason += validateEmpty(theForm.yourphone,"Your Phone");
	reason += validateEmpty(theForm.code,"NO-SPAM Validation");
      
	if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }
  return true;
}


function validateFormOnSubmit(theForm) {
	var reason = "";
	reason += validateEmpty(theForm.title,"Title");
	reason += validateEmpty(theForm.content,"Content");
	reason += validateEmpty(theForm.name,"Your Name");
	reason += validateEmpty(theForm.email,"Your Email");

      
	if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }
  return true;
}

function validateEmpty(fld,alerttxt) {
    var error = "";
    if (fld.value.length == 0) {
        fld.style.background = '#fff999'; 
        error = alerttxt+"\n";
    } 
    else { fld.style.background = '#ffffff url(/images/inputbg.gif) top left no-repeat'; }
    return error;  
}
// END PRAYER PAGE FUNCTIONS ////////////////////



// FLASH AUDIO PLAYER FUNCTIONS ////////////////////
function getFlashMovieObject(movieName) {
	if (window.document[movieName]) {
		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet") == -1) {
		if (document.embeds && document.embeds[movieName])
		return document.embeds[movieName]; 
	}
	else {
		return document.getElementById(movieName);
	}
}

function switchSong(player, songFile, songDesc) {
	var flashMovie = getFlashMovieObject(player);
	flashMovie.SetVariable('_root.theSong',songFile);
	flashMovie.SetVariable('_root.theSongDesc',songDesc);
	flashMovie.Play();
}

function playRelatedAudio(player,songFile,songTitle) {
	$('relAudioNowPlaying').innerHTML = "<span>NOW PLAYING <b>&raquo;</b></span> "+songTitle;
	var flashMovie = getFlashMovieObject(player);
	flashMovie.SetVariable('_root.theSong',songFile);
	flashMovie.Play();
}
// END FLASH AUDIO PLAYER FUNCTIONS ////////////////////





// NO FLASH AD ROTATOR STUFF ////////////////////////
var thisAd;
var maxAds;
var runAds;

function changeRotator(way) {
	if(way == 1) {
		thisAd = thisAd+1;
		if(thisAd > maxAds) {
			thisAd = 1;
		}
	}
	else {
		thisAd = thisAd-1;
		if(thisAd < 1) {
			thisAd = maxAds;
		}
	}
	for(var i=1; i<=maxAds; i++) {
		document.getElementById('bannerad'+i).style.display = 'none';
	}
	document.getElementById('bannerad'+thisAd).style.display = 'block';
}

function changeAndRoll(way) {
	window.clearInterval(runAds);
	changeRotator(1);
	rollTheAds();
}

function rollTheAds() {
	runAds = window.setInterval(function () { changeRotator('forward');  }, 6000);
}


// PHOTO GALLERY STUFF ///////////////////////////////////////////

var currentNum = 1;
function scrollThis(theNum) {
	
	var descs = $$('#imageDescriptionBox .imageDescription');
	var currentFade = new Fx.Styles('description'+currentNum, {duration: 200, wait: true}).start({'opacity': 0})
	.chain(function() {
		descs.each(function(element) { element.style.display = "none"; });
		$('description'+theNum).style.display = "block";
		currentNum = theNum;
		var myFx = new Fx.Scroll($('galleryViewer'), {duration:700,transition: Fx.Transitions.Cubic.easeInOut}).toElement('viewer'+theNum).start()
		.chain(function() {
			var currentFade = new Fx.Styles('description'+currentNum, {duration: 200, wait: true}).start({'opacity': 1});
		});
	});
}

function setUpGallery() {
	var viewers = $$('#galleryViewerBox .imageViewer');
	var vCounter = 0;
	
	viewers.each(function(element) { vCounter++; });
	var totalViewers = vCounter*395+20;
	$('galleryViewerBox').style.width = totalViewers+'px';
}

///////////////////////////////////////////////////
// CALENDAR SWITCHING STUFF  //////////////////////
///////////////////////////////////////////////////
function getCalendar(m,y,cal) {
	var formFade = new Fx.Styles('calendarTableInside', {duration: 100, wait: true});
	formFade.start({'opacity': 0})
	.chain(function() {
		new Ajax("graphicCalendar.php", { method: 'get', data: "month="+m+"&year="+y+"&calCat="+cal, update: $('calendarTableInside'), evalScripts:true,
			onComplete: function() {
				formFade.start({'opacity': 1}) 
			},
			onFailure: function() { 
				formFade.start({'opacity': 1}) 
				alert('Sorry! The network was busy. Please try again later.');
			}})
		.request();
	});
}




///////////////////////////////////////////////////
// URL ENCODING FOR AJAX     //////////////////////
///////////////////////////////////////////////////
var Url = {

	encode : function (string) { return escape(this._utf8_encode(string)); },
	decode : function (string) { return this._utf8_decode(unescape(string)); },
	
	_utf8_encode : function (string) {
	  	string = string.replace(/\r\n/g,"\n");
	 	var utftext = "";
	  	for (var n = 0; n < string.length; n++) {
	   		var c = string.charCodeAt(n);
	   		if (c < 128) {
	    			utftext += String.fromCharCode(c);
	 		} 
	 		else if((c > 127) && (c < 2048)) {
	  			utftext += String.fromCharCode((c >> 6) | 192);
	  			utftext += String.fromCharCode((c & 63) | 128);
	 		} 
	 		else {
	  			utftext += String.fromCharCode((c >> 12) | 224);
	  			utftext += String.fromCharCode(((c >> 6) & 63) | 128);
	 	 		utftext += String.fromCharCode((c & 63) | 128);
	 		}
	 	}
		return utftext;
	},
	
	_utf8_decode : function (utftext) {
	 	var string = "";
	 	var i = 0;
	 	var c = c1 = c2 = 0;
	  	while ( i < utftext.length ) {
	  		c = utftext.charCodeAt(i);
	   		if (c < 128) {
	    		string += String.fromCharCode(c);
	    		i++;
	  		} 
	  		else if((c > 191) && (c < 224)) {
	 			c2 = utftext.charCodeAt(i+1);
	    		string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
	    		i += 2;
	  		} 
	  		else {
	 			c2 = utftext.charCodeAt(i+1);
	    		c3 = utftext.charCodeAt(i+2);
	    		string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
	   			i += 3;
	 		}
		}
		return string;
	}
}


