// JavaScript Document
function doNav(theUrl) {
	document.location.href = theUrl;
}
function changeCursor(tableRow, highLight) {
	if (highLight) {
		tableRow.style.cursor="pointer";
	}
}
var loader = new Image();
loader.src = 'images/red_loader.gif';
function pleaseWait(table,row,cell) {
	//var button = document.getElementById('submitbutton');
	var x=document.getElementById(table).rows[row].cells;
	x[cell].innerHTML='<img src="images/red_loader.gif" align="absbottom"> Please Wait...';
	//button.style.color="#999999";
	//button.disabled=true;
}
function printPage() {
	window.print();
}
function deleteUser(id) {
	if(confirm('Are you sure you want to delete this user?')) {
		doNav('admin_users.php?action=process&section=delete&id='+id);
	}
}
function deleteParagraph(id,page) {
	if(confirm('Are you sure you want to delete this paragraph?')) {
		doNav('page_info.php?action=process&section=delete&id='+id+'&return='+page);
	}
}
//rotating images
function start_slideshow(start_frame, end_frame, delay) {
	setTimeout(switch_slides(start_frame,start_frame,end_frame, delay), delay);
}
						
function switch_slides(frame, start_frame, end_frame, delay) {
	return (function() {
		Effect.Fade('slideshow' + frame);
		if (frame == end_frame) { frame = start_frame; } else { frame = frame + 1; }
		setTimeout("Effect.Appear('slideshow" + frame + "', {duration:1.5});", 150);
		setTimeout(switch_slides(frame, start_frame, end_frame, delay), delay + 850);
	})
}

img1 = new Image();
img1.src = 'images/loader_gray.gif';

function deleteRotatingImage(id) {
	if(confirm('Are you sure you want to delete this image?')) {
		doNav('rotating_images.php?action=process&section=delete&id='+id);
	}
}
function deleteAbout(id) {
	if(confirm('Are you sure you want to delete this section?')) {
		doNav('admin_about.php?action=process&section=delete&id='+id);
	}
}
function deleteLifeAtImmanuel(id) {
	if(confirm('Are you sure you want to delete this section?')) {
		doNav('admin_lifeatimmanuel.php?action=process&section=delete&id='+id);
	}
}
function deleteEducation(id) {
	if(confirm('Are you sure you want to delete this section?')) {
		doNav('admin_education.php?action=process&section=delete&id='+id);
	}
}
function showSubMenu(id,parent) {
	$(id).show();
	$(parent).className = 'menulinkhover';
}
function hideSubMenu(id,parent) {
	$(id).hide();
	$(parent).className = 'menulink';
}
function showSubSubMenu(id,parent,mainparent) {
	$(id).show();
	$(parent).className = 'submenuhover';
	$(mainparent).className = 'menulinkhover';
}
function hideSubSubMenu(id,parent,mainparent) {
	$(id).hide();
	$(parent).className = 'submenu';
	$(mainparent).className = 'menulink';
}
function updateDate() {
	var month = document.getElementById("top_month").value;
	var year = document.getElementById("top_year").value;
	document.location.href = "calendar.php?month="+month+"&year="+year;
}
function updateAdminDate() {
	var month = document.getElementById("top_month").value;
	var year = document.getElementById("top_year").value;
	document.location.href = "admin_calendar.php?month="+month+"&year="+year;
}
function getDDCal(id,month,year) {
	if(document.getElementById('cal'+id).style.display == 'none') {
		new Effect.Appear('cal'+id,{duration:.2});
	}
	document.getElementById('cal'+id).innerHTML = '<div id="contentLoading" style="display:none;" align="center"><br>Loading...<br /><br /><img src="images/gray_loader.gif" width="24" height="24" /></div>';
	new Effect.Appear('contentLoading',{duration:.1});
	new Ajax.Request('dd_cal.php?month='+month+'&year='+year+'&id='+id,
		 {
			method:'get',
			onComplete: function(transport){
				new Effect.Fade('contentLoading',{duration:.1});
				var response = transport.responseText || "no response text";
				document.getElementById('cal'+id).innerHTML = response;
				$('innercal'+id).hide();
			  	new Effect.Appear('innercal'+id, { duration:.3, queue: 'end' });
			},
			onFailure: function(){ alert('Something went wrong...Please select a date again.') }
		  });
}
function getDDCal2(id,month,year) {
	new Ajax.Request('dd_cal.php?month='+month+'&year='+year+'&id='+id,
		 {
			method:'get',
			onComplete: function(transport){
				var response = transport.responseText || "no response text";
				document.getElementById('cal'+id).innerHTML = response;
			},
			onFailure: function(){ alert('Something went wrong...Please select a date again.') }
		  });
}
function closeDDCal(id) {
	new Effect.Fade('cal'+id,{duration:.2});
}
function selectDay(id,month,day,year) {
	
	new Effect.Fade('cal'+id,{duration:.2});
	document.getElementById('caldate'+id).value = month+'/'+day+'/'+year;
}
function repeatsEveryWeek() {
	var repeatEvery=document.getElementById("repeatEveryWeek");
	if (repeatEvery.options[repeatEvery.selectedIndex].text != '1') {
		var x=document.getElementById("repeatsEvery").rows["0"].cells;
		x["1"].innerHTML='weeks';
	} else {
		var x=document.getElementById("repeatsEvery").rows["0"].cells;
		x["1"].innerHTML='week&nbsp;';
	}
}
function repeatsEveryMonth() {
	var repeatEvery=document.getElementById("repeatEveryMonth");
	if (repeatEvery.options[repeatEvery.selectedIndex].text != '1') {
		var x=document.getElementById("repeatsEvery").rows["0"].cells;
		x["1"].innerHTML='months';
	} else {
		var x=document.getElementById("repeatsEvery").rows["0"].cells;
		x["1"].innerHTML='month&nbsp;';
	}
}
function repeatConfig() {
	var repeat=document.getElementById("repeatDropDown");
	if (repeat.options[repeat.selectedIndex].text == 'Weekly') {
		var x=document.getElementById("repeats001").rows["0"].cells;
		x["0"].innerHTML='<table id="repeatsEvery" cellpadding="2" cellspacing="2" style="border:solid; border-width:1px; border-color:#CCCCCC; border-collapse:collapse;"><tr><td align="left" valign="top" class="pagetext" width="140">Repeats every: <select name="repeatsevery" id="repeatEveryWeek" onchange="repeatsEveryWeek()"><option>1</option><option>2</option><option>3</option><option>4</option></select></td><td align="left" class="pagetext" valign="top" width="260">week&nbsp;</td></tr><tr><td align="left" class="pagetext" colspan="2" valign="top">Repeat On: <input type="checkbox" name="sunday" value="0">S&nbsp;&nbsp;<input type="checkbox" name="monday" value="1">M&nbsp;&nbsp;<input type="checkbox" name="tuesday" value="2">T&nbsp;&nbsp;<input type="checkbox" name="wednesday" value="3">W&nbsp;&nbsp;<input type="checkbox" name="thursday" value="4">T&nbsp;&nbsp;<input type="checkbox" name="friday" value="5">F&nbsp;&nbsp;<input type="checkbox" name="saturday" value="6">S&nbsp;&nbsp;</td></tr></table><img src="images/spacer.gif" width="100%" height="5">';
	} else if (repeat.options[repeat.selectedIndex].text == 'Monthly') {
		var x=document.getElementById("repeats001").rows["0"].cells;
		x["0"].innerHTML='<table id="repeatsEvery" cellpadding="2" cellspacing="2" style="border:solid; border-width:1px; border-color:#CCCCCC; border-collapse:collapse;"><tr><td align="left" valign="top" class="pagetext" width="140">Repeats every: <select name="repeatsevery" id="repeatEveryMonth" onchange="repeatsEveryMonth()"><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option><option>11</option><option>12</option></select></td><td align="left" class="pagetext" valign="top" width="250">month&nbsp;</td></tr><tr><td align="left" class="pagetext" colspan="2" valign="top">Repeat By: <input type="radio" name="repeatby" value="month"> day of the month&nbsp;&nbsp;<input type="radio" name="repeatby" value="week"> day of the week&nbsp;&nbsp;</td></tr></table><img src="images/spacer.gif" width="100%" height="5">';
	} else {
		var x=document.getElementById("repeats001").rows["0"].cells;
		x["0"].innerHTML='<img src="images/spacer.gif" width="100%" height="5">';
	}
}
function fullDay(element) {
	if (element.checked) {
		var x=document.getElementById("when").rows["0"].cells;
		x["1"].innerHTML="&nbsp;to&nbsp;";
	} else {
		var x=document.getElementById("when").rows["0"].cells;
		x["1"].innerHTML='<input type="text" name="start_time" value="8:00am" size="8">&nbsp;to&nbsp;<input type="text" name="end_time" value="9:00am" size="8">';
	}
}
function toggleAppear(id) {
	var divs = $$('div.editdiv');
	for(i=0;i<divs.length;i++) {
		if(divs[i]['id'] == 'edit'+id) {
			new Effect.toggle(divs[i]['id'],'appear',{duration:.2});		
		} else {
			new Effect.Fade(divs[i]['id'],{duration:.2});
		}
	}
}
function deleteEvent(id,m,y) {
	if(confirm('Are you sure you want to delete this event?')) {
		doNav('admin_calendar.php?action=process&section=delete&id='+id+'&month='+m+'&year='+y);	
	}
}
function deleteEventSeries(id,m,y) {
	if(confirm('Are you sure you want to delete this series of events?')) {
		doNav('admin_calendar.php?action=process&section=deleteseries&seriesid='+id+'&month='+m+'&year='+y);	
	}
}
function togglePopUp(id,flip) {
	var divs = $$('div.eventPopUp');
	for(i=0;i<divs.length;i++) {
		if(divs[i]['id'] == id) {
			if(flip == 'yes') {
				var pos = $('a-'+id).positionedOffset();
				new Effect.Move(divs[i]['id'],{x:pos['left']-187,y:pos['top']+13,mode:'absolute',duration:0});
			} else {
				var pos = $('a-'+id).positionedOffset();
				new Effect.Move(divs[i]['id'],{x:pos['left']-3,y:pos['top']+13,mode:'absolute',duration:0});
			}
			new Effect.toggle(divs[i]['id'],'appear',{duration:.1});
		} else {
			if(flip == 'yes') {
				var pos = $('a-'+divs[i]['id']).positionedOffset();
				new Effect.Move(divs[i]['id'],{x:pos['left']-187,y:pos['top']+13,mode:'absolute',duration:0});
			} else {
				var pos = $('a-'+divs[i]['id']).positionedOffset();
				new Effect.Move(divs[i]['id'],{x:pos['left']-3,y:pos['top']+13,mode:'absolute',duration:0});
			}
			new Effect.Fade(divs[i]['id'],{duration:.1});
		}
	}
}
function startScrollingEvents(count) {
	for(var i=2;i<=count;i++) {
		if($('scrollingEvent'+i)) {
			new Effect.Move('scrollingEvent'+i,{x:0,y:90,mode:'relative',duration:0});
		} else {
			alert('This event could not be found.');
		}
		if(i == count) {
			setTimeout("scrollEvent('2',"+count+")", 5000);
		}
	}
}
function scrollEvent(num,count) {
	if(num != 1) {
		new Effect.Move('scrollingEvent'+((num*1)-1),{x:0,y:-90,mode:'relative',duration:1});
	} else if(num == 1) {
		new Effect.Move('scrollingEvent'+count,{x:0,y:-90,mode:'relative',duration:1});
	}
	new Effect.Move('scrollingEvent'+num,{x:0,y:-90,mode:'relative',duration:1});
	if(num != 1) {
		new Effect.Move('scrollingEvent'+((num*1)-1),{x:0,y:180,mode:'relative',duration:0,queue:'end'});
	} else if(num == 1) {
		new Effect.Move('scrollingEvent'+count,{x:0,y:180,mode:'relative',duration:0,queue:'end'});
	}
	if(num	 != count) {
		setTimeout("scrollEvent("+((num*1)+1)+","+count+")", 5000);
	} else {
		setTimeout("scrollEvent('1',"+count+")", 5000);
	}
}