// JavaScript Document
function doNav(theUrl) {
	document.location.href = theUrl;
}
var loader = new Image();
loader.src = 'images/loader_red.gif';
function pleaseWait(table,row,cell) {
	var x=document.getElementById(table).rows[row].cells;
	x[cell].innerHTML='<img src="images/loader_red.gif" align="absbottom"> Please Wait...';
}
function deleteNews(id) {
	if(confirm('Are you sure you want to delete this news?')) {
		doNav('admin_newsevents.php?action=process&section=delete&id='+id);
	}
	return false;
}
function transferStartDate() {
	var start = $('start').value;
	var end = $('end').value;
	if(end == '') {
		$('end').value = start;
	} else if(end == 'mm/dd/yyyy') {
		$('end').value = start;
	} else if(end < start) {
		$('end').value = start;
	}
}
function transferEndDate() {
	var start = $('start').value;
	var end = $('end').value;
	if(start == '') {
		$('start').value = end;
	} else if(start == 'mm/dd/yyyy') {
		$('start').value = end;
	} else if(end < start) {
		$('start').value = end;
	}
}
function deleteArticleCat(id) {
	if(confirm('Are you sure you want to delete this category and all articles within?')) {
		doNav('admin_articles.php?action=process&section=deletecat&catid='+id);
	}
	return false;
}
function deleteQuestion(id) {
	if(confirm('Are you sure you want to delete this unanswered question?')) {
		doNav('admin_articles.php?action=process&section=deletequestion&id='+id);
	}
	return false;
}
function deleteArticle(id,catid) {
	if(confirm('Are you sure you want to delete this article?')) {
		doNav('admin_articles.php?action=process&section=delete&id='+id+'&catid='+catid);
	}
	return false;
}
function addParagraph(iteration) {
	$('paragraphContainer').insert('<div id="paragraph'+iteration+'" style="margin:0 0 5px 0;"><div style="float:left; text-align:left;padding:0 5px 0 0;width:300px;"><textarea name="paragraphs[]" id="paragraph'+iteration+'" style="width:300px;height:150px;"></textarea></div><div style="float:left; text-align:left;"><br /><a href="javascript:removeParagraph(\''+iteration+'\');" class="adminLink">Remove Paragraph</a></div><div style="clear:both;"></div><div style="margin:5px 0 0 0;">Image Upload&nbsp;&nbsp;<input type="file" name="images[]" id="image'+iteration+'" /></div><div style="clear:both;"></div></div>');
	iteration++;
	$('addParagraphLink').href='javascript:addParagraph(\''+(iteration)+'\');';
}
function removeParagraph(id) {
	$('paragraph'+id).remove();
}
function openArticleImage(img) {
	window.scrollTo(0,200);
	var w = document.viewport.getWidth();
	var start = w/2;
	var left = start - 350;
	new Effect.Move('loadingFrame',{x:left,y:200,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:200,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');
	return false;
}
function showPopup(id) {
	$(id).show();
}
function hidePopup(id) {
	$(id).hide();
}
function removeCurrentImage(key) {
	$('currentImage'+key).hide();
	$('imageUpload'+key).show();
	$('current_image'+key).value = '';	
}