
/* */

var activeTemplate = '';
var divAt = 1;
var doCycle = true;

/* */

function scrollDiv(div,a){
	try{
		var height = document.getElementById(div).offsetHeight;
		a--;if(a<-height)a=250;
		document.getElementById(div).style.marginTop = a+'px';
	}
	catch(err){}
	window.setTimeout('scrollDiv(\''+div+'\','+(a-1)+')',300);
}


function setCycle(x){
	divAt = x;
}
function cycleOneDiv(div){
  if(doCycle){
	hide(div+divAt);
	if(document.getElementById(div+(divAt+1))==null) {
		divAt = 1;
	}
	else {
		divAt++;
	}
	show(div+divAt);
	//initFade(div+divAt,'in');
  }
}

function cycleDivs(div,a){
	initFade(div+a,'in');
	if(document.getElementById(div+(a+1))==null) {
		window.setTimeout('hide(\''+div+a+'\');cycleDivs(\''+div+'\',1)',8000);
	}
	else {
		window.setTimeout('hide(\''+div+a+'\');cycleDivs(\''+div+'\','+(a+1)+')',8000);
	}
}

// JavaScript Document
function initFade(imageId,direction) {
    var initial = 100;
    if(direction=="in") initial = 0;
    image = document.getElementById(imageId);
   
    if ((direction=="in") || (direction=="out")) {
        setOpacity(image, initial);
        image.style.display = "";
        fade(imageId,initial,direction);
    }
}
function fade(objId,opacity,direction) {
    if (document.getElementById) {
        obj = document.getElementById(objId);
        if ((direction=="out" && opacity < 1)) {obj.style.display = "none";}
		if ((direction=="in" && opacity > 100)){setOpacity(obj, 100);}
        if ((direction=="in" && opacity <= 100) || (direction=="out" && opacity > 0)) {
            setOpacity(obj, opacity);
            if(direction=="in") opacity += 5;
            else  opacity -= 5;
            window.setTimeout("fade('"+objId+"',"+opacity+",'"+direction+"')", 50);
        }
    }
}
function setOpacity(obj, opacity) {
    opacity = (opacity == 100)?99.999:opacity;
    // IE/Win
    obj.style.filter = "alpha(opacity:"+opacity+")";
    // Safari<1.2, Konqueror
    obj.style.KHTMLOpacity = opacity/100;
    // Older Mozilla and Firefox
    obj.style.MozOpacity = opacity/100;
    // Safari 1.2, newer Firefox and Mozilla, CSS3
    obj.style.opacity = opacity/100;
} 



function show2(a){
document.getElementById(a).style.visibility='visible';

}
function hide2(a){
document.getElementById(a).style.visibility='hidden';

}

function show(a){
document.getElementById(a).style.display='';
}
function hide(a){
document.getElementById(a).style.display='none';
}
var maxl = 300;
var countr = 300;
function tc(field) {
if (field.value.length > maxl) {field.value = field.value.substring(0, maxl);}
else {countr = maxl - field.value.length;}
document.getElementById('counterview').innerHTML=countr + ' characters left';

}

function showpreviewcard(){
document.getElementById('previewcardcontent').innerHTML = '<div class="p_request">'+document.prayerform.prayer_text.value + '<br><div class="p_sub">submitted by  '+ document.prayerform.author_name.value + ' on '+ document.prayerform.datetime.value + '</div>';
show('previewcard');
}

function hidepreviewcard(){
hide('previewcard');
}

function processPrayerRequest(){
	if(document.prayerform.author_email.value != ""){
		document.emailform.from.value = document.prayerform.author_email.value;
		document.emailform.submit();
	}
	if(document.prayerform.prayer_text.value=="") {
		alert('Please enter your request before submitting the form. Thanks!!');
		return false;
	}
	else {
		hide('sendreq');
		show('sendreq_loading');
		return true;
	}
}
function showThankYou(){
hide('sendreq_loading');
show('sendreq_thankyou');
}


/* s_d__ */
var s_d__ajaxObjects = new Array();

function ajaxLoad(url,windowId){
	document.getElementById(windowId).innerHTML = "<div class='loading'>Loading...</div>";
	
	if(windowId == 'rightContent' || windowId == 'leftContent' ){
		location.href = '#top';
	}
	
	var ajaxIndex = s_d__ajaxObjects.length;	
	s_d__ajaxObjects[ajaxIndex] = new sack();
	s_d__ajaxObjects[ajaxIndex].requestFile = url;	// Specifying which file to get
	s_d__ajaxObjects[ajaxIndex].onCompletion = function(){ 
		// Specify function that will be executed after file has been found
		document.getElementById(windowId).innerHTML = s_d__ajaxObjects[ajaxIndex].response;	
		try{onAjaxFinish();}catch(err){}
		ajaxTemplateCheck();			
	};	
	s_d__ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function	

	
}

function ajaxTemplateCheck(){
	var ajaxIndex = s_d__ajaxObjects.length;	
	s_d__ajaxObjects[ajaxIndex] = new sack();
	s_d__ajaxObjects[ajaxIndex].requestFile = 'inc/activetemplate.cfm';	// Specifying which file to get
	s_d__ajaxObjects[ajaxIndex].onCompletion = function(){ 
		// Specify function that will be executed after file has been found
		var tempTemplate = s_d__ajaxObjects[ajaxIndex].response;
		if (tempTemplate != activeTemplate){
			activeTemplate = tempTemplate;
			//alert(activeTemplate);
			changeStyle(activeTemplate);
		}	
	};	
	s_d__ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function	
}

//The script below is courtesy of http://www.howtocreate.co.uk/tutorials/javascript/domcss
function getAllSheets() {
  if( !window.ScriptEngine && navigator.__ice_version ) { return document.styleSheets; }
  if( document.getElementsByTagName ) { var Lt = document.getElementsByTagName('link'), St = document.getElementsByTagName('style');
  } else if( document.styleSheets && document.all ) { var Lt = document.all.tags('LINK'), St = document.all.tags('STYLE');
  } else { return []; } for( var x = 0, os = []; Lt[x]; x++ ) {
    var rel = Lt[x].rel ? Lt[x].rel : Lt[x].getAttribute ? Lt[x].getAttribute('rel') : '';
    if( typeof( rel ) == 'string' && rel.toLowerCase().indexOf('style') + 1 ) { os[os.length] = Lt[x]; }
  } for( var x = 0; St[x]; x++ ) { os[os.length] = St[x]; } return os;
}
function changeStyle() {
  for( var x = 0, ss = getAllSheets(); ss[x]; x++ ) {
    if( ss[x].title ) { ss[x].disabled = true; }
    for( var y = 0; y < arguments.length; y++ ) {
     if( ss[x].title == arguments[y] ) { ss[x].disabled = false; }
} } }

/* Simple AJAX Code-Kit (SACK) */
/* ©2005 Gregory Wild-Smith */
/* www.twilightuniverse.com */
/* Software licenced under a modified X11 licence, see documentation or authors website for more details */

function sack(file){
	this.AjaxFailedAlert = "Your browser does not support the enhanced functionality of this website, and therefore you will have an experience that differs from the intended one.\n";
	this.requestFile = file;
	this.method = "POST";
	this.URLString = "";
	this.encodeURIString = true;
	this.execute = false;

	this.onLoading = function() { };
	this.onLoaded = function() { };
	this.onInteractive = function() { };
	this.onCompletion = function() { };

	this.createAJAX = function() {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (err) {
				this.xmlhttp = null;
			}
		}
		if(!this.xmlhttp && typeof XMLHttpRequest != "undefined")
			this.xmlhttp = new XMLHttpRequest();
		if (!this.xmlhttp){
			this.failed = true; 
		}
	};
	
	this.setVar = function(name, value){
		if (this.URLString.length < 3){
			this.URLString = name + "=" + value;
		} else {
			this.URLString += "&" + name + "=" + value;
		}
	}
	
	this.encVar = function(name, value){
		var varString = encodeURIComponent(name) + "=" + encodeURIComponent(value);
	return varString;
	}
	
	this.encodeURLString = function(string){
		varArray = string.split('&');
		for (i = 0; i < varArray.length; i++){
			urlVars = varArray[i].split('=');
			if (urlVars[0].indexOf('amp;') != -1){
				urlVars[0] = urlVars[0].substring(4);
			}
			varArray[i] = this.encVar(urlVars[0],urlVars[1]);
		}
	return varArray.join('&');
	}
	
	this.runResponse = function(){
		eval(this.response);
	}
	
	this.runAJAX = function(urlstring){
		this.responseStatus = new Array(2);
		if(this.failed && this.AjaxFailedAlert){ 
			alert(this.AjaxFailedAlert); 
		} else {
			if (urlstring){ 
				if (this.URLString.length){
					this.URLString = this.URLString + "&" + urlstring; 
				} else {
					this.URLString = urlstring; 
				}
			}
			if (this.encodeURIString){
				var timeval = new Date().getTime(); 
				this.URLString = this.encodeURLString(this.URLString);
				this.setVar("rndval", timeval);
			}
			if (this.element) { this.elementObj = document.getElementById(this.element); }
			if (this.xmlhttp) {
				var self = this;
				if (this.method == "GET") {
					var totalurlstring = this.requestFile + "?" + this.URLString;
					this.xmlhttp.open(this.method, totalurlstring, true);
				} else {
					this.xmlhttp.open(this.method, this.requestFile, true);
				}
				if (this.method == "POST"){
  					try {
						this.xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded')  
					} catch (e) {}
				}

				this.xmlhttp.send(this.URLString);
				this.xmlhttp.onreadystatechange = function() {
					switch (self.xmlhttp.readyState){
						case 1:
							self.onLoading();
						break;
						case 2:
							self.onLoaded();
						break;
						case 3:
							self.onInteractive();
						break;
						case 4:
							self.response = self.xmlhttp.responseText;
							self.responseXML = self.xmlhttp.responseXML;
							self.responseStatus[0] = self.xmlhttp.status;
							self.responseStatus[1] = self.xmlhttp.statusText;
							self.onCompletion();
							if(self.execute){ self.runResponse(); }
							if (self.elementObj) {
								var elemNodeName = self.elementObj.nodeName;
								elemNodeName.toLowerCase();
								if (elemNodeName == "input" || elemNodeName == "select" || elemNodeName == "option" || elemNodeName == "textarea"){
									self.elementObj.value = self.response;
								} else {
									self.elementObj.innerHTML = self.response;
								}
							}
							self.URLString = "";
						break;
					}
				};
			}
		}
	};
this.createAJAX();
}