// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
bTextareaWasTinyfied = false; //this should be global, could be stored in a cookie...

function setTextareaToTinyMCE(sEditorID) {
	var oEditor = document.getElementById(sEditorID);
	if(oEditor && !bTextareaWasTinyfied) {
		tinyMCE.execCommand('mceAddControl', true, sEditorID);
		bTextareaWasTinyfied = true;
	}
	return;
}

function unsetTextareaToTinyMCE(sEditorID) {
	var oEditor = document.getElementById(sEditorID);
	if(oEditor && bTextareaWasTinyfied) {
		tinyMCE.execCommand('mceRemoveControl', true, sEditorID);
		bTextareaWasTinyfied = false;
	}
	return;
}
function createLinkPlain(){
	var str = prompt('Enter link location (e.g. http://www.dallasbirthdays.com):','http:\/\/');
	if (str) {
		var str1 = prompt('Enter link title:','');
		if (str1) {
			str = '<a href=\'' + str + '\'>' + str1 + '</a>';
			prompt('Copy (Ctrl+C) and paste (Ctrl+V) this HTML into your Entry:', str);
		} 
	}
	return false;
}
function toggleSub(myid){
	var firstid = document.getElementById('cat-'+myid);
	var secondid = document.getElementById('browseon-'+myid);
	var thirdid = document.getElementById('browseoff-'+myid);
	Element.toggle(firstid);
	Element.toggle(secondid);
	Element.toggle(thirdid);
}
function toggleBrowse(mytype){
	var cat = document.getElementById('cat');
	var mkt = document.getElementById('mkt');
	if(mytype=='category'){
		cat.style.background='#138205';
		mkt.style.background='#13CE21';
		Element.show(document.getElementById('browse-cat'));
		Element.hide(document.getElementById('browse-market'));

	}else{
		cat.style.background='#13CE21';
		mkt.style.background='#138205';
		Element.hide(document.getElementById('browse-cat'));
		Element.show(document.getElementById('browse-market'));


	}
}
function popOut(div, val){
	var k = document.getElementById('test');
	var myid = document.getElementById(div);
	var mylinks = document.getElementById('test').getElementsByTagName('a');

	if(val){
		k.style.filter = 'alpha(opacity=30)';
		k.style.opacity = '.3';
		//
		myid.style.display='block';
		//
		for(var i in mylinks){
			mylinks[i].onclick = function() {return false;}
		}
	} else{
		k.style.filter = 'alpha(opacity=100)';
		k.style.opacity = '1.0';
		//
		myid.style.display='none';
		//
		for(var i in mylinks){
			mylinks[i].onclick = null;
		}
	}
	//
}