
function fbs_click() {
u=location.href;
t=document.title;
window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
return false;
}

function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external") 
     anchor.target = "_blank"; 
 } 
} 

function deleteMe(uri,action,id,value) {
	var text = "Are you sure you want to delete this "+id+"?";
	var question = confirm(text);
	if (question){
		alert("Alrighty then!");
		window.location = "/"+uri+"?action="+action+"&"+id+"_id=" + value;
	}
	else {
		alert("Phew, close call!");
	}
}


function toggleThis(whichOne) {
	if (document.getElementById(whichOne).style.display == 'none')
		document.getElementById(whichOne).style.display = '';
	else
		document.getElementById(whichOne).style.display = 'none';
}

function hideThis(whichOne) {
	if (document.getElementById(whichOne).style.display == 'none')
		document.getElementById(whichOne).style.display = 'none';
	else
		document.getElementById(whichOne).style.display = 'none';
}


function jumpTo(targ,selObj){
	var loc=selObj.options[selObj.selectedIndex].value;
	if (loc){
		eval(targ+".location='"+loc+"'");
 	}
 	else{
		selObj.selectedIndex=0;
	}
}


function setfocus(id){
	document.getElementById(id).focus();
}



/*
function showThis(whichOne) {
	if (document.getElementById(whichOne).style.display == 'none')
		document.getElementById(whichOne).style.display = '';
}

function hideThis(whichOne) {
	if (document.getElementById(whichOne).style.display == '')
		document.getElementById(whichOne).style.display = 'none';
}
*/

function loadThis(div){
	var urlHash = unescape(self.document.location.hash.substring(1));
	var anchor = (urlHash != '') ? 'v' + urlHash : div;
	showThis(anchor);
}

function styleThis(whichOne){
	if (document.getElementById(whichOne).style.textDecoration == '')
		document.getElementById(whichOne).style.textDecoration = 'underline';
}

function unstyleThis(whichOne){
	if (document.getElementById(whichOne).style.textDecoration == 'underline')
		document.getElementById(whichOne).style.textDecoration = '';
}

function copy(inElement) {
  if (inElement.createTextRange) {
    var range = inElement.createTextRange();
    if (range && BodyLoaded==1)
     range.execCommand('Copy');
  } else {
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="http://rewrit.es/_clipboard.swf" flashvars="clipboard='+escape(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
  }
}




function insertMediaLink(dd,ta){
    ta = document.getElementById(ta);
    dd = document.getElementById(dd);
    var un = '';
    var uid = 0;
    if(dd.selectedIndex != 0){
      un = dd.options[dd.selectedIndex].text;
      uid = dd.options[dd.selectedIndex].value;
      insTexte = ""+un+"";
      startTag = '';
	  endTag = '';
	  
	  
	       if (ta.createTextRange)
	       {
	        var text;
	        ta.focus(ta.caretPos);
	        ta.caretPos = document.selection.createRange().duplicate();
	        if(ta.caretPos.text.length>0)
	        {
	         ta.caretPos.text = startTag + ta.caretPos.text + endTag;
	        }
	        else
	        {
	         ta.caretPos.text = startTag + " " + insTexte + " " + endTag;
	        }
	       }
	       else ta.value += startTag + insTexte + endTag;

    }
  
  }
  
/*
var autoPopulate = {
sInputClass:'medium', // Class name for the input elements to autopopulate
sHiddenClass:'structural', // Class name that gets assigned to hidden label elements
bHideLabels:true, // If true, labels are hidden
init:function() {
// Check for DOM support
if (!document.getElementById || !document.createTextNode) {return;}
// Find all input elements with the given className
var arrInputs = autoPopulate.getElementsByClassName(document, 'input', autoPopulate.sInputClass);
var iInputs = arrInputs.length;
var oInput;
// Loop through the found input elements
for (var i=0; i<iInputs; i++) {
oInput = arrInputs[i];
// Make sure it's a text input. If not, skip to the next input.
if (oInput.type != 'text') { continue; }
// Hide the input's label
if (autoPopulate.bHideLabels) { autoPopulate.hideLabel(oInput.id); }
// If value is empty and title is not, assign title to value
if ((oInput.value == '') && (oInput.title != '')) { oInput.value = oInput.title; }
// Add event handlers for focus and blur
autoPopulate.addEvent(oInput, 'focus', function() {
// If value and title are equal on focus, clear value
if (this.value == this.title) {
this.value = '';
// Make input caret visible in IE
this.select();
}
});
autoPopulate.addEvent(oInput, 'blur', function() {
// If the field is empty on blur, assign title to value
if (!this.value.length) { this.value = this.title; }
});
}
},
hideLabel:function(sId) {
// Find all label elements
var arrLabels = document.getElementsByTagName('label');
var iLabels = arrLabels.length;
var oLabel;
// Loop through the found label elements
for (var i=0; i<iLabels; i++) {
oLabel = arrLabels[i];
// If the value of the label's for attribute equals the input element's id, hide the label
if (oLabel.htmlFor == sId) {
oLabel.className = oLabel.className + ' ' + autoPopulate.sHiddenClass;
}
}
}
};
*/

function sendText(e, text) 
{ 
  e.value = text 
} 

function refreshWin(url){
	document.location.href = url;
}


/**************************************** new ***************************************************/



function f4a_bind(fn, scope) {
		var scope = scope || window;
		var args = [];
		for (var i=2, len = arguments.length; i < len; ++i) {
			args.push(arguments[i]);
		};
		return function() {
			fn.apply(scope, args);
		};
	  }

function f4a_js_flash(props) {
  this.f4a_js_id = props['id'];
  this.id = this.f4a_js_id+'f4a_js_flash';
  this.flashobj_id = this.id+'_f4a';
  this.swfname = props['swfname'];
  this.swfuri = props['swfuri'];
  this.height = 1;
  this.width = 1;
  this.mostRecentResponse = '';

  if (window.log==undefined) log = function(txt) {
	try{console.log(txt)} catch (e) {}
  }
  
  this.getFlash = function() {
      return document.getElementById(this.flashobj_id);
  }
  
  this.checkFlash = function() {  // confirm that the Flash Storage is running
      try {
          return (this.getFlash().ping() == "pong");
      } catch (e) { log(e);return false; }
  }


  this.createSwfObject = function() {
 	var so = new SWFObject(this.swfuri, this.flashobj_id, "1", "1", "8", "#ffffff");  
 	//var so = new SWFObject(this.swfuri, this.flashobj_id, "800", "600", "8", "#0000ff");  
	so.addParam('allowScriptAccess', 'always');
	so.addParam('swliveconnect', 'true');
	so.write(this.f4a_js_id+'flashcontent');
  }
  
  this.open = function(args) {
    var meth = args['meth'];
    var url = args['url'];
    var async = args['async'];
    var user = args['user'];
    var password = args['password'];  
    var headers = args['headers'] ? args['headers'] : [];
    var contenttype = args['contenttype'] ? args['contenttype'] : null;
    var data = args['data'];
    var onready = args['onready'];
  
    var fs = this.getFlash();
    
	var cb = CallbackManager.registerCallback(this.id,onready);
    fs.xmlhttp(url, cb, meth, data, headers);
  }
}

/**************************************** CallbackManager ***************************************************/


var CallbackManager = new Object();
CallbackManager.callbacks = {};
CallbackManager.callbackIndexes = {};

// assigns and returns a unique callback name for the input callback
CallbackManager.registerCallback = function(id, callback) {

  if (!this.callbacks[id]) {
    this.callbacks[id] = [];
    this.callbackIndexes[id] = 0;
  } 

    // todo: could be improved (look for the first available spot in the callbacks table, if necessary, expand it)
    var length = this.callbacks[id].push(function(rsp) {f4a_bind(selfDeleteCallback,this,id,callback,rsp)()});

    this.callbackIndexes[id] = length - 1;
    return 'CallbackManager.callbacks[\''+id+'\']['+this.callbackIndexes[id]+']';
    
    function selfDeleteCallback(id,callback,rsp) {
        //delete CallbackManager.callbacks[id][this.callbackIndexes[id]];
       	setTimeout(function() { callback(rsp); }, 0);
        return;
    } 
}