//Add blog category functions//////////////////////////////////////////////////////
function toggle_add_blog_category(blog_id){
	
	if ($("cancel_blog_category_" + blog_id).style.display == "none"){
		$("cancel_blog_category_" + blog_id).style.display = "inline";
		$("add_blog_category_" + blog_id).style.display = "none";
	}else{
		$("cancel_blog_category_" + blog_id).style.display = "none";
		$("add_blog_category_" + blog_id).style.display = "inline";
		
		
		comment_block.style.display="none";
	}
}

//Comment Functions///////////////////////////////////////////////////////////////
function toggle_comments(article_id){
	var comment_block = $("comment_block_" + article_id);
	
	if (comment_block.style.display == "none"){
		$("hide_comments_" + article_id).style.display = "inline";
		$("show_comments_" + article_id).style.display = "none";
		comment_block.style.display = "inline";
	}else{
		$("hide_comments_" + article_id).style.display = "none";
		$("show_comments_" + article_id).style.display = "inline";
		
		
		comment_block.style.display="none";
	}
}


//Article Tool Functions/////////////////////////////////////////////////////////////
function toggle_article_tools(article_id, tool_type){
	var tool_box = $("article_" + tool_type + "_" + article_id);
	
	if (tool_box.style.display == "none"){
		$("article_tools_" + article_id).style.display = "none";
		$("article_multimedia_" + article_id).style.display = "none";
		//tool_box.style.display = "inline";
		new Effect.BlindDown(tool_box);
	}else{
		$("article_tools_" + article_id).style.display = "none";
		$("article_multimedia_" + article_id).style.display = "none";
	}
}


//Voting Functions///////////////////////////////////////////////////////////////
function rate_loading(rating_type, action, id){
	loading_box = $(rating_type + "_" + action + "_" + "loading_" + id);
	box = $(rating_type + "_" + action + "_" + id);
	loading_box.innerHTML = "<img src=\"/images/indicator.gif\" />";
	Element.hide(box);
	Element.show(loading_box);
}

function rate_complete(rating_type, action, id, response){
	loading_box = $(rating_type + "_" + action + "_" + "loading_" + id);
	box = $(rating_type + "_" + action + "_" + id);
	vote_count = $(rating_type + "_" + action + "_" + "count_" + id);
	loading_box.innerHTML = "";
	Element.hide(loading_box);
	Element.show(box);
	
	if(isNaN(response)){
		make_alert(response, "popup_error", rating_type + "_" + action + "_" + id);
	}
	else{
		vote_count.innerHTML = "<strong>" + response + "</strong>";
		//make_alert("Your vote has been successfully counted", "popup_alert", rating_type + "_" + action + "_" + id);
	}
	//alert("made it");
}

//Alert Functions /////////////////////////////////////////////////////////////////////////////

function make_alert(message, alert_type, link_id){
	
	var alert_message = $('lp_alert_message');
	var alert_popup = $('lp_alert_message_popup');
	if(!alert_type){ alert_type = "common_error"; }
	var link_obj = $(link_id);
	//a low level error
	if(alert_type == "common_error"){
		//alert("oo");
		alert_message.style.display = "none";
		alert_message.className = "common_error";
		alert_message.innerHTML = message;
		new Effect.BlindDown(alert_message);
		
		window.setTimeout("new Effect.BlindUp($('lp_alert_message'))", 5000);
		
	}
	
	//a low level error that will remain visible until the visitor navigates to another page
	if(alert_type == "common_error_pinned"){
		//alert("oo");
		alert_message.style.display = "none";
		alert_message.className = "common_error";
		alert_message.innerHTML = message;
		new Effect.BlindDown(alert_message);
		
	}
	
	//A low level nice notice
	if(alert_type == "common_alert"){
		//alert("oo");
		alert_message.style.display = "none";
		alert_message.className = "common_alert";
		alert_message.innerHTML = message;
		new Effect.BlindDown(alert_message);
		window.setTimeout("new Effect.BlindUp($('lp_alert_message'))", 5000);
		
	}
	
	//A low level nice notice that will remain until the visitor navigates to another page
	if(alert_type == "common_alert_pinned"){
		//alert("oo");
		alert_message.style.display = "none";
		alert_message.className = "common_alert";
		alert_message.innerHTML = message;
		new Effect.BlindDown(alert_message);
		
	}
	
	//A low level popup error
	if(alert_type == "popup_error"){
		//alert("oo");
		alert_popup.style.display = "none";
		alert_popup.className = "popup_error";
		alert_popup.innerHTML = message;
		
		var y_pos = findPosY(link_obj) + (link_obj.offsetHeight + 5);
		var x_pos = findPosX(link_obj) + 5;
		
		alert_popup.style.top = y_pos + 'px';
		alert_popup.style.left = x_pos + 'px';
		
		new Effect.Appear(alert_popup);
		window.setTimeout("new Effect.DropOut($('lp_alert_message_popup'))", 3000);
		
	}
	
	//A low level popup nice notice
	if(alert_type == "popup_alert"){
		alert_popup.style.display = "none";
		alert_popup.className = "popup_alert";
		alert_popup.innerHTML = message;
		
		var y_pos = findPosY(link_obj) + (link_obj.offsetHeight + 5);
		var x_pos = findPosX(link_obj) + 5;
		
		alert_popup.style.top = y_pos + 'px';
		alert_popup.style.left = x_pos + 'px';
		
		new Effect.Appear(alert_popup);
		window.setTimeout("new Effect.DropOut($('lp_alert_message_popup'))", 3000);
		
	}
	
	
}




//Login Functions///////////////////////////////////////////////////////////////////////////
function login_complete(outcome){
	Element.show('login_submit'); 
	Element.hide('login_loading'); 
	$('login_loading').innerHTML = '';
	
	//If the log in was successful, then make all of the authorized elements visible
	if(outcome == "1"){
		member_content_update();
	}
	else{
		make_alert(outcome, "popup_error", "template_login_box");
		//$('login_message_box').innerHTML = outcome;
		//new Effect.Highlight($('login_message_box'));
	}
	
	
	//$('personal_nav_bar').style.visibility="visible";
	//$('login_box').style.display="none";
	//new Effect.Highlight($('personal_nav'));
	
}

function login_loading(){
	Element.show('login_loading'); 
	Element.hide('login_submit'); 
	$('login_loading').innerHTML = '<img src=\"/images/indicator.gif\" />';
}


function member_content_update(){
	
	var visitor_elements = getElementsByClassName("visitor_content");
	for(var i=0; i < visitor_elements.length; i++){
		visitor_elements[i].style.visibility = "hidden";
		visitor_elements[i].style.display = "none";
	}
	
	var member_elements = getElementsByClassName("member_content");
	for(var x=0; x < member_elements.length; x++){
		member_elements[x].style.visibility="visible";
		
		//member_elements[x].style.display = "none";
		member_elements[x].style.display = "inline";
		member_elements[x].style.display="block";
		//new Effect.Appear(member_elements[x]);
		new Effect.Highlight(member_elements[x]);
	}
	
}

//Logout Functions///////////////////////////////////////////////////////////////////////
function logout_complete(outcome){
	$('logout_loading').innerHTML = '';
	Element.show('logout_submit'); 
	Element.hide('logout_loading'); 
	
	
	//If the log in was successful, then make all of the authorized elements visible
	if(outcome == "1"){
		visitor_content_update();
		make_alert("Successfully Logged Out", "popup_alert", "login_box");
		//$('login_message_box').innerHTML = "Successfully Logged Out";
		//new Effect.Highlight($('login_message_box'));
	}
	else{
		
	}
	
	
	//$('personal_nav_bar').style.visibility="visible";
	//$('login_box').style.display="none";
	//new Effect.Highlight($('personal_nav'));
	
}

function logout_loading(){
	Element.hide('logout_submit'); 
	Element.show('logout_loading'); 
	$('logout_loading').innerHTML = 'Logout';
}


function visitor_content_update(){
	
	var member_elements = getElementsByClassName("member_content");
	for(var x=0; x < member_elements.length; x++){
		member_elements[x].style.visibility="hidden";
		member_elements[x].style.display = "none";
		//member_elements[x].style.display="block";
		
	}
	
	var visitor_elements = getElementsByClassName("visitor_content");
	for(var i=0; i < visitor_elements.length; i++){
		visitor_elements[i].style.visibility = "visible";
		//visitor_elements[x].style.display = "none";
		visitor_elements[i].style.display = "inline";
		visitor_elements[i].style.display = "block";
		//new Effect.Appear(visitor_elements[i]);
		new Effect.Highlight(visitor_elements[i]);
	}
	
}


//Info Box Functions ////////////////////////////////////////////////////////////////////
//Global Variables
var current_menu = "";
//vertical can be either top or bottom, horizontal can be either left or right
function toggle_info_box(link_id, vertical, horizontal, width, height, shadow_offset){
 	
	var info_box = $('info_box_wrapper');
	var info_box_control = $('info_box_control');
	var info_box_shadow = $('info_box_shadow');
	var info_box_content = $('info_box_content');
	
	if(info_box.style.display == "none"){
		
		var link_obj = $(link_id);
		//alert(info_box_control.offsetHeight);
		if(width > 15){
			info_box.style.width = width + 'px';
		}else{
			info_box.style.width = '200px';
			width = 200;
		}
		if(height > 15){
			info_box.style.height = height + 'px';
			info_box_content.style.height = (height) + 'px';
		}else{
			info_box.style.height = '200px';
			info_box_content.style.height = (200) + 'px';
			height = 200;
		}
		
		if(vertical == "top"){
			var y_pos = findPosY(link_obj) - (link_obj.offsetHeight + 5) - height;
		}else{
			var y_pos = findPosY(link_obj) + (link_obj.offsetHeight + 5);
		}
		
		if(horizontal == "right"){
			var x_pos = findPosX(link_obj) + (link_obj.offsetWidth) + 5;
		}else{
			var x_pos = findPosX(link_obj) - 235;
		}
		
		
		if(shadow_offset > 0){
			shadow_offset = shadow_offset + 10;
			info_box_shadow.style.top = shadow_offset + 'px';
			info_box_shadow.style.left = shadow_offset + 3 + 'px';
		}else{
			info_box_shadow.style.top = '7px';
			info_box_shadow.style.left = '7px';
		}
		//var x_pos = findPosX(link_obj) - (menu_width - link_obj.offsetWidth);
		//var y_pos = findPosY(link_obj) + (link_obj.offsetHeight + 5);
		
		info_box_content.innerHTML = "<img src=\"/images/indicator.gif\" />";
		
		info_box.style.top = y_pos + 'px';
		info_box.style.left = x_pos + 'px';
		
		new Effect.Appear(info_box);
		ajaxEngine.sendRequest( button_id.id );
		
		
		return link_obj.id;
		
	}
	else{
		info_box.style.display = "none";
		info_box_content.innerHTML = "<img src=\"/images/indicator.gif\" />";
		if(current_menu != link_obj.id){
			info_box.style.top = y_pos + 'px';
			info_box.style.left = x_pos + 'px';
			//alert("");
			new Effect.Appear(info_box);
			ajaxEngine.sendRequest( link_obj.id );
			
			return link_obj.id;
		
		}else{
			return 0;
		}
		
	}

	
}


function load_info_box(content){
	var info_box_content = $('info_box_content');
	info_box_content.innerHTML = content;
}


//helper functions
function getElementsByClassName(xx){
	var rl=new Array();
	var ael=document.all?document.all:document.getElementsByTagName('*')
	for(i=0,j=0;i<ael.length;i++){
		if((ael[i].className==xx)){
			rl[j]=ael[i];
			j++;
		}
	}
	return rl;
}



function menu_toggle(menu_obj, button_id, nav_menu_obj){
 	var button_obj = $(button_id);
	//alert(button_id.id);
	var x_pos = findPosX(button_obj) - (menu_width - button_obj.offsetWidth);
	var y_pos = findPosY(button_obj) + (button_obj.offsetHeight + 5);
	
	if(menu_obj.style.display == "none"){
		
		nav_menu_obj.innerHTML = "<img src=\"/images/indicator.gif\" />";
		
		menu_obj.style.top = y_pos + 'px';
		menu_obj.style.left = x_pos + 'px';
		
		new Effect.Appear(menu_obj);
		ajaxEngine.sendRequest( button_id.id );
		
		
		return button_id.id;
		
	}
	else{
		menu_obj.style.display = "none";
		nav_menu_obj.innerHTML = "<img src=\"/images/indicator.gif\" />";
		if(current_menu != button_id.id){
			menu_obj.style.top = y_pos + 'px';
			menu_obj.style.left = x_pos + 'px';
			//alert("");
			new Effect.Appear(menu_obj);
			ajaxEngine.sendRequest( button_id.id );
			
			return button_id.id;
		
		}else{
			return 0;
		}
		
	}
	//Element.toggle( element );
	//alert(element.offsetLeft);
	
	
	
	
}

//Library function to find the x,y coordinates of an element

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


