

function dhtmlLoadScript(url)
{
   var e = document.createElement("script");
   e.src = url;
   e.type="text/javascript";
   document.getElementsByTagName("head")[0].appendChild(e);
}

var twit_coughlin_var = "";
function toggle_coughlin(boink)
{
    if(boink)
        twit_coughlin_var = "&fc=1";
    else
        twit_coughlin_var = "";
}
function twit_coughlin()
{ return twit_coughlin_var; }
// GOOGLE STUFF:

var wasran=false;
function load_google_search()
{
if(wasran) return false; 
wasran =true;
var search_input = document.getElementById('google_search_field');
search_input.className="google_search_field_loading";
    search_input.onfocus=function(){};
    //document.getElementById('google_search_field_loading').style.display="block";
  dhtmlLoadScript('http://www.google.com/jsapi?callback=goog_callback');
  
}
function goog_callback()
{
      google.load('search', '1',{'callback':goog_searchbox_callback}); //,
      //  google.setOnLoadCallback(goog_searchbox_callback,true);
  
}
function goog_searchbox_callback()
{
    var search_control = new google.search.CustomSearchControl("017376552807249423718:a4qsmjt7q2u");
    
    
    var search_input = document.getElementById('google_search_field');
    
    var drawOptions = new google.search.DrawOptions();
    drawOptions.setInput(search_input);
    
    search_control.draw('cse',drawOptions); //
    
    //document.getElementById('google_search_field_loading').style.display="none";
    search_input.disabled=false;
    search_input.value="";
    search_input.className="google_search_field";
}

// from news.html:
	function sections_edit_display(div_id,topic_id,collection,select_array)
	{
		var new_node=document.getElementById("collection_selection_main").cloneNode(true);
		new_node.id = "cx@"+topic_id;
		var key_offset = 0;
		for (key in new_node.elements)
		{
			if(new_node.elements[key].type == "checkbox")
				new_node.elements[key].checked = select_array[key-key_offset];
			else 
			{
				key_offset++;
				if(new_node.elements[key].type =="radio")
				{  
					new_node.elements[key].name=topic_id+"_form_radio";
					if(new_node.elements[key].id == collection)
						new_node.elements[key].checked = true;
				
				}
			}
		
		}
			
		var destination_div=document.getElementById(div_id);
		destination_div.appendChild(new_node);
		new_node.style.display="block";
		destination_div.style.display="block";
		

	}
    function inject_article_to_twatbox(anchor_id)
    {
        var a = document.getElementById(anchor_id);
        var twatbox = document.getElementById('twitter_input');
        if(a && twatbox)
        {
            twatbox.value = a.innerHTML + " " + a.href;
            twatbox.scrollIntoView(true);
        }
        else
            alert("node not found");
    }
    
    function addquote_qr(post_id, username)
{
	var message_name = 'message_' + post_id;
	var theSelection = '';
	var divarea = false;

	if (document.all)
	{
		divarea = document.all[message_name];
	}
	else
	{
		divarea = document.getElementById(message_name);
	}

	// Get text selection - not only the post content :(
	if (window.getSelection)
	{
		theSelection = window.getSelection().toString();
	}
	else if (document.getSelection)
	{
		theSelection = document.getSelection();
	}
	else if (document.selection)
	{
		theSelection = document.selection.createRange().text;
	}

	if (theSelection == '' || typeof theSelection == 'undefined' || theSelection == null)
	{
		if (divarea.innerHTML)
		{
			theSelection = divarea.innerHTML.replace(/<br>/ig, '\n');
			theSelection = theSelection.replace(/<br\/>/ig, '\n');
			theSelection = theSelection.replace(/&lt\;/ig, '<');
			theSelection = theSelection.replace(/&gt\;/ig, '>');
			theSelection = theSelection.replace(/&amp\;/ig, '&');
		}
		else if (document.all)
		{
			theSelection = divarea.innerText;
		}
		else if (divarea.textContent)
		{
			theSelection = divarea.textContent;
		}
		else if (divarea.firstChild.nodeValue)
		{
			theSelection = divarea.firstChild.nodeValue;
		}
	}
	if (theSelection)
	{
    
		document.getElementById('qr_textarea').value = document.getElementById('qr_textarea').value + ('[quote="' + username + '"]' + theSelection + '[/quote]');
        document.getElementById('qr_textarea').scrollIntoView(true);
	}

	return;
}

function inject_image_upload_box(div_id)
{
var div = document.getElementById(div_id);

ifrm = document.createElement("iframe");
ifrm.setAttribute("name", "image_upload_frame");
ifrm.setAttribute("id", "image_upload_frame");
ifrm.setAttribute("src", "http://latewire.com/images/fekken_random/?in_iframe=1");
ifrm.setAttribute("width", 800);
ifrm.setAttribute("height", 250);
ifrm.style.width.value = 800+"px";
ifrm.style.height.value = 250+"px";
div.appendChild(ifrm);

}