// JavaScript Document

function publish_phrase(phrase_id) {

	new Ajax.Request('/admin/phrase/publish/' + phrase_id,  {
		method: 'post',
		parameters: 'phrase_id=' + phrase_id,		
		onComplete: 
			function(response) { 
				if(document.getElementById('phrase_list')){
					new Effect.Highlight('phrase_list');
					id_text = phrase_id.toString();
					id_text = 'phrase_link' + id_text;
					new_link = 'javascript:unpublish_phrase(' + phrase_id + ')';
				    document.getElementById(id_text).innerHTML='Un-Publish';
				    document.getElementById(id_text).href=new_link;
					}
			}
	});
			
}

function unpublish_phrase(phrase_id) {

	new Ajax.Request('/admin/phrase/unpublish/' + phrase_id,  {
		method: 'post',
		parameters: 'phrase_id=' + phrase_id,		
		onComplete: 
			function(response) { 
				if(document.getElementById('phrase_list')){
					new Effect.Highlight('phrase_list');
					id_text = phrase_id.toString();
					id_text = 'phrase_link' + id_text;
					new_link = 'javascript:publish_phrase(' + phrase_id + ')';
					document.getElementById(id_text).innerHTML='Publish';
				    document.getElementById(id_text).href=new_link;
					}
			}
	});
			
}

function add_phrase(slogan_input) {

	new Ajax.Request('/admin/phrase/add/',  {
		method: 'post',
		parameters: 'slogan_input=' + slogan_input,		
		onComplete: 
			function(response) {
					document.getElementById('slogan_input').value='Well?';
				    document.getElementById('phrase_submit').style.display = 'block';					
			}
		
	});
			
}

function add_comment() {
	
	author = document.getElementById('comment_author').value;
	comment = document.getElementById('comment_text').value;
	id = document.getElementById('project_id').value;

	if(author == "" || comment == "")
		{
		alert("Please populate all values for your comment entry");
		return;
		}
			
	new Ajax.Updater('visible_comments', '/admin/comment/add/' + id,  {
		method: 'post',
		parameters: 'author=' + author + '&comment=' + comment,		
		onComplete: 
			function(response) { 
			
				new_object = '<p><i>' + author + '</i><br/>' + commment + '</p>';
				var newI = new Element( 'i' );
			  	newI.update(new_object);
				
				new Effect.Highlight('visible_comments');
				 $('visible_comments').insert ({'top'  :  newI } );

				document.getElementById('comment_form').style.display = 'none';
				document.getElementById('comment_author').value = '';				
				document.getElementById('comment_text').value = '';								
				
				//window.location.reload( true );
			}
		
	});
			
}

function add_guestbook() {
	
	// Pull both current values for insertion. 
	author = document.getElementById('guest_author').value;
	entry = document.getElementById('guest_entry').value;
	
	if(author == "" || entry == "")
		{
		alert("Please populate all values for your guestbook entry");
		return;
		}
  
	new Ajax.Updater('guest_list', '/admin/guestbook/add/',  {
		method: 'post',
		parameters: 'author=' + author + '&entry=' + entry,				
		onComplete: 
			function(response) { 
								
				new_object = '<li><p>'+entry+'</p><p class="author">'+author+'</li>';
				var newI = new Element( 'i' );
			  	newI.update(new_object);
				
				new Effect.Highlight('guest_list');
				 $('guest_list').insert ({'top'  :  newI } );
  
				document.getElementById('guest_author').value='';
				document.getElementById('guest_entry').value='';
			}
		
	});
			
}

function publish_showing(showing_id) {

	new Ajax.Request('/admin/showing/publish/' + showing_id,  {
		method: 'post',
		parameters: 'showing_id=' + showing_id,		
		onComplete: 
			function(response) { 
				if(document.getElementById('showing_list')){
					new Effect.Highlight('showing_list');
					id_text = showing_id.toString();
					id_text = 'showing_link' + id_text;
					new_link = 'javascript:unpublish_showing(' + showing_id + ')';
				    document.getElementById(id_text).innerHTML='Un-Publish';
				    document.getElementById(id_text).href=new_link;
					}
			}
	});
			
}

function unpublish_showing(showing_id) {

	new Ajax.Request('/admin/showing/unpublish/' + showing_id,  {
		method: 'post',
		parameters: 'showing_id=' + showing_id,		
		onComplete: 
			function(response) { 
				if(document.getElementById('showing_list')){
					new Effect.Highlight('showing_list');
					id_text = showing_id.toString();
					id_text = 'showing_link' + id_text;
					new_link = 'javascript:publish_showing(' + showing_id + ')';
				    document.getElementById(id_text).innerHTML='Publish';
				    document.getElementById(id_text).href=new_link;
					}
			}
	});
			
}

var myarray_phrase = new Array();

function update_phrase_rating(phrase_id, phrase_rating) {

	if(myarray_phrase.indexOf(phrase_id) > -1)
         { return; }
	else {
		myarray_phrase[myarray_phrase.length] = phrase_id; 
		new Ajax.Request('/admin/phrase/update_rating/' + phrase_id,  {
			method: 'post',
			parameters: 'phrase_id=' + phrase_id,		
			onComplete: 
				function(response) { 
					if(document.getElementById('current_rating')){
						new_rating = phrase_rating + 1;
						rating = new_rating.toString();
						document.getElementById('current_rating').innerHTML=rating;	
						}
				}
		});
	}
			
}

var myarray = new Array();

function update_project_rating(project_id, project_rating, num) {
	text = "current_rating" + num.toString();
	
	if(myarray.indexOf(num) > -1)
         { return; }
	else {	
		myarray[myarray.length] = num; 
		new Ajax.Request('/admin/project/update_rating/' + project_id,  {
			method: 'post',
			parameters: 'project_id=' + project_id,		
			onComplete: 
				function(response) { 
					if(document.getElementById(text)){
						new_rating = project_rating + 1;
						rating = new_rating.toString();
						
						var id = '#'+text;
						jQuery(id).html(rating);
						var bar = jQuery(id).parent().find('.pinkBar');
						var w = bar.css('min-width');
						w = parseInt(w);
						w = Math.round(Number(w));
						w = w + 10;
						//bar.animate({minWidth:w, maxWidth:w, width:w}, 800);
						//bar.css('display', 'inline !important');
						bar.css('min-width', w);
						bar.css('max-width', w);
						bar.css('width', w);
						}
				}
		});
	} // end of else
			
}

function delete_phrase(phrase_id) {
	
	new Ajax.Request('/admin/phrase/delete', {
		method: 'post',
		parameters: 'phrase_id=' + phrase_id,
		onComplete: 
			function(response) { 
				if (document.getElementById('phrase_' + phrase_id)) {
					new Element.remove('phrase_' + phrase_id);
					new Effect.Highlight('phrase_list');
				}
			}
	});			
}

function delete_guestbook(guest_id) {
	
	new Ajax.Request('/admin/guestbook/delete', {
		method: 'post',
		parameters: 'guest_id=' + guest_id,
		onComplete: 
			function(response) { 
				if (document.getElementById('guest_' + guest_id)) {
					new Element.remove('guest_' + guest_id);
					new Effect.Highlight('guestbook_list');
				}
			}
	});			
}

function delete_user(user_id) {
	
	new Ajax.Request('/admin/user/delete', {
		method: 'post',
		parameters: 'user_id=' + user_id,
		onComplete: 
			function(response) { 
				if (document.getElementById('user_' + user_id)) {
					new Element.remove('user_' + user_id);
					new Effect.Highlight('user_list');
				}
			}
	});			
}

function delete_employee(employee_id) {
	
	new Ajax.Request('/admin/employee/delete', {
		method: 'post',
		parameters: 'employee_id=' + employee_id,
		onComplete: 
			function(response) { 
				if (document.getElementById('employee_' + employee_id)) {
					new Element.remove('employee_' + employee_id);
					new Effect.Highlight('employee_list');
				}
			}
	});			
}

function delete_comment(comment_id) {
	
	new Ajax.Request('/admin/comment/delete', {
		method: 'post',
		parameters: 'comment_id=' + comment_id,
		onComplete: 
			function(response) { 
				if (document.getElementById('comment_' + comment_id)) {
					new Element.remove('comment_' + comment_id);
					new Effect.Highlight('comment_list');
				}
			}
	});			
}

function delete_credit(credit_id) {
	
	new Ajax.Request('/admin/credit/delete', {
		method: 'post',
		parameters: 'credit_id=' + credit_id,
		onComplete: 
			function(response) { 
				if (document.getElementById('credit_' + credit_id)) {
					new Element.remove('credit_' + credit_id);
					new Effect.Highlight('credit_list');
				}
			}
	});			
}

function delete_award(award_id) {
	
	new Ajax.Request('/admin/award/delete', {
		method: 'post',
		parameters: 'award_id=' + award_id,
		onComplete: 
			function(response) { 
				if (document.getElementById('award_' + award_id)) {
					new Element.remove('award_' + award_id);
					new Effect.Highlight('award_list');
				}
			}
	});			
}

function delete_project_link(link_id) {
	
	new Ajax.Request('/admin/project_link/delete', {
		method: 'post',
		parameters: 'link_id=' + link_id,
		onComplete: 
			function(response) { 
				if (document.getElementById('link_' + link_id)) {
					new Element.remove('link_' + link_id);
					new Effect.Highlight('link_list');
				}
			}
	});			
}

function delete_press(press_id) {
	
	new Ajax.Request('/admin/press/delete', {
		method: 'post',
		parameters: 'press_id=' + press_id,
		onComplete: 
			function(response) { 
				if (document.getElementById('press_' + press_id)) {
					new Element.remove('press_' + press_id);
					new Effect.Highlight('press_list');
				}
			}
	});		
}

function delete_showing(showing_id) {
	
	new Ajax.Request('/admin/showing/delete', {
		method: 'post',
		parameters: 'showing_id=' + showing_id,
		onComplete: 
			function(response) { 
				if (document.getElementById('showing_' + showing_id)) {
					new Element.remove('showing_' + showing_id);
					new Effect.Highlight('showing_list');
				}
			}
	});		
}

function delete_video(video_id) {
	
	new Ajax.Request('/admin/video/delete', {
		method: 'post',
		parameters: 'video_id=' + video_id,
		onComplete: 
			function(response) { 
				if (document.getElementById('video_' + video_id)) {
					new Element.remove('video_' + video_id);
					new Effect.Highlight('video_list');
				}
			}
	});		
}

function delete_image(image_id) {
	
	new Ajax.Request('/admin/image/delete', {
		method: 'post',
		parameters: 'image_id=' + image_id,
		onComplete: 
			function(response) { 
				if (document.getElementById('image_' + image_id)) {
					new Element.remove('image_' + image_id);
					new Effect.Highlight('image_list');
				}
			}
	});		
}

function delete_download(download_id) {
	
	new Ajax.Request('/admin/download/delete', {
		method: 'post',
		parameters: 'download_id=' + download_id,
		onComplete: 
			function(response) { 
				if (document.getElementById('download_' + download_id)) {
					new Element.remove('download_' + download_id);
					new Effect.Highlight('download_list');
				}
			}
	});		
}

function validate_news_item(i) {
	
	any_checked=false;
	
	for (j = 1; j <= 5; j++) {
		// alert('channel_' + i + '_' + j);
		if (document.getElementById('channel_' + i + '_' + j).checked) any_checked=true;
	}
	
	if (any_checked) {
		new Effect.Highlight('item_' + i);
		return true;
	} else {
		alert('Please select at least one channel.');
		return false;
	}
		
}