// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function show_edit_about_toggle(t_id, edt) {
	if (edt == "edit") {
		Element.hide($('show_about_'+t_id));
		Element.show($('edit_about_'+t_id));
	} else {
		Element.show($('show_about_'+t_id));
		Element.hide($('edit_about_'+t_id));
	}
}

function sel_toggle(t_id, edt) {
	if (edt == "edit") {
		Element.hide($('show_link_'+t_id));
		Element.show($('edit_link_'+t_id));
	} else {
		Element.show($('show_link_'+t_id));
		Element.hide($('edit_link_'+t_id));
	}
}

function sec_toggle(t_id, edt) {
	if (edt == "edit") {
		Element.hide($('show_cat_'+t_id));
		Element.show($('edit_cat_'+t_id));
	} else {
		Element.show($('show_cat_'+t_id));
		Element.hide($('edit_cat_'+t_id));
	}
}

function se_toggle(t_id, edt) {
	if (edt == "edit") {
		Element.hide($('show_'+t_id));
		Element.show($('edit_'+t_id));
	} else {
		Element.show($('show_'+t_id));
		Element.hide($('edit_'+t_id));
	}
}

function post_toggle(t_id, edt) {
	if (edt == "open") {
		Element.hide($('show_post_'+t_id));
		Element.show($('show_open_'+t_id));
	} else {
		Element.show($('show_post_'+t_id));
		Element.hide($('show_open_'+t_id));
	}
}

function source_toggle(t_id, edt) {
	if (edt == "edit") {
		Element.hide($('post_open_show_'+t_id));
		Element.show($('post_open_edit_'+t_id));
	} else {
		Element.show($('post_open_show_'+t_id));
		Element.hide($('post_open_edit_'+t_id));
	}
}

function login_box(to_do) {
	if (to_do == "close") {
		Element.hide($('login'));
	} else {
		Element.show($('login'));
	}
}

function search_found_on(t_id, edt) {
	if (edt == "open") {
		Element.show($('found_on_'+t_id));
	} else {
		Element.hide($('found_on_'+t_id));
	}
}

function DetectNEnter(e)
{
	var KeyID = (window.event) ? event.keyCode : e.keyCode;
	if (KeyID == 13) {
	    document.forms[0].submit();
	}
}

function postcountdown(){
	len = $("post_body").value.length;
	string = " characters left";
    remaining = 750 - len;
	if (remaining < 0) {
		Element.addClassName("countdown", "red");
	}
	else {
		Element.removeClassName	("countdown", "red");
	}
	
    $("countdown").innerHTML = remaining+string;
}

function ajaxsearch(v){
	updatesearch(v);
}

function updatesearch(v){
	new Ajax.Updater('containerBg','/search?q='+v+'&ajax=true',{method:'get'});
}

if (!HTMLAnchorElement.prototype.click) {
  HTMLAnchorElement.prototype.click = function() {
    var ev = document.createEvent('MouseEvents');
    ev.initEvent('click',true,true);
    if (this.dispatchEvent(ev) !== false) {
      //safari will have already done this, but I'm not sniffing safari
      //just in case they might in the future fix it; I figure it's better
      //to trigger the action twice than risk not triggering it at all
      document.location.href = this.href;
    }
  }
}

var expand_collapse = '';
function expand_all() {
	$$('li[id*="show_post"]').each(function(xx){Element.hide(xx);});
	$$('li[id*="show_open"]').each(function(xx){Element.show(xx);});
     expand_collapse = 'expand';
}
function collapse_all() {
	$$('li[id*="show_post"]').each(function(xx){Element.show(xx);});
	$$('li[id*="show_open"]').each(function(xx){Element.hide(xx);});
     expand_collapse = '';
}
function check_expand() {
	if (expand_collapse == 'expand') {
     	expand_all();
     }
}
