// JavaScript Document
function doNav(theUrl) {
	document.location.href = theUrl;
}
function changeCursor(tableRow, highLight) {
	if (highLight) {
		tableRow.style.cursor="pointer";
	}
}
function accountHover(tableRow, highLight) {
	if (highLight) {
		tableRow.className = "accounthover";
		tableRow.style.cursor="pointer";
	} else {
		tableRow.className = "account";
	}
}
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);
	}
}
var loader = new Image();
loader.src = 'images/loader_red.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/loader_red.gif" align="absbottom"> Please Wait...';
	//button.style.color="#999999";
	//button.disabled=true;
}
function deleteNews(id) {
	if(confirm('Are you sure you want to delete this piece of news?')) {
		doNav('news.php?action=process&section=delete&id='+id);	
	}
}
function deleteGallery(id) {
	var remove = confirm('This will delete this gallery as well as all photos and categories within this gallery.  This action is unrecoverable. Are you sure you want to delete this gallery?');
	if(remove == true) {
		doNav('admin_pictures.php?action=process&section=deletecat&catid='+id);	
	}
}
function deletePhoto(catid,id) {
	var remove = confirm('You are about to delete this photo from the database.  This action is unrecoverable. Are you sure you want to delete this photo?');
	if(remove == true) {
		doNav('admin_pictures.php?action=process&section=deletephoto&catid='+catid+'&id='+id);	
	}
}
function deleteRotatingImage(id) {
	if(confirm('Are you sure you want to delete this rotating image?')) {
		doNav('rotating_images.php?action=process&section=delete&id='+id);	
	}
}
function openPhoto(img) {
	var w = document.viewport.getWidth();
	var start = w/2;
	var left = start - 350;
	new Effect.Move('loadingFrame',{x:left,y:0,mode:'absolute',duration:0});
	new Effect.SlideDown('loadingFrame',{duration:.5});
	new Ajax.Request('ajax_largeimage.php?img='+img,
		 {
			method:'get',
			onSuccess: function(text){
			  var response = text.responseText || "no response text";
			  document.getElementById('content').innerHTML = response;
				var w = document.viewport.getWidth();
				var start = w/2;
				var left = start - 350;
				new Effect.Move('largePhotoFrame',{x:left,y:0,mode:'absolute',duration:0});
			  document.getElementById('img'+img).onload = function() {
			    new Effect.SlideUp('loadingFrame',{duration:.5});
				new Effect.SlideDown('largePhotoFrame',{queue:'end'});  
			  }
			},
			onFailure: function(){ 
				alert('Something went wrong...')
				new Effect.SlideUp('loadingFrame');
			}
		  });
	return false;
}
function closePhoto() {
	new Effect.SlideUp('largePhotoFrame');
}
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 deleteGame(gameid,teamid) {
	if(confirm('Are you sure you want to delete this game?')) {
		doNav('admin_standings.php?action=process&section=deletegame&gameid='+gameid+'&teamid='+teamid);
	}
}
function deleteTeam(id,groupid) {
	if(confirm('Are you sure you want to delete this team?')) {
		doNav('admin_standings.php?action=process&section=deleteteam&groupid='+groupid+'&teamid='+id);	
	}
}
function deleteGroup(id) {
	if(confirm('Are you sure you want to delete this group?')) {
		doNav('admin_standings.php?action=process&section=deletegroup&groupid='+id);	
	}
}
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);
    })
}

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