/***************************************************
Met à jour un champ hidden avec les valeurs du Tree
dhtmlgoodies, puis soumet le formulaire
****************************************************/
function saveMyTree()
{
	saveString = treeObj.getNodeOrders();
	$('#saveString').val(saveString);
	document.forms['myForm'].submit();
}

function pop(element)
{
	element.show();
}

var isIE = document.all;
var mouseX = 0;
var mouseY = 0;



	$().mousemove(function(e){
		mouseX = e.pageX;
		mouseY = e.pageY;
	});




function tooltipShow()
{	
	document.getElementById("user_informations").style.left = mouseX +"px";
 	document.getElementById("user_informations").style.top = mouseY +"px";
 	$('#user_informations').show();
}





/* UPLOAD GMAIL STYLE */


/* standard small functions */
function $m(quem){
 return document.getElementById(quem)
}
function remove(quem){
  if (quem)
  {
    quem.parentNode.removeChild(quem);
  }
}
function addEvent(obj, evType, fn){
 // elcio.com.br/crossbrowser
    if (obj.addEventListener)
        obj.addEventListener(evType, fn, true)
    if (obj.attachEvent)
        obj.attachEvent("on"+evType, fn)
}
function removeEvent( obj, type, fn ) {
  if ( obj.detachEvent ) {
    obj.detachEvent( 'on'+type, fn );
  } else {
    obj.removeEventListener( type, fn, false ); }
} 
/* THE UPLOAD FUNCTION */
function micoxUpload(form, url_action, id_element, html_show_loading, html_error_http, update_url, update_element){
/******
* micoxUpload - Submit a form to hidden iframe. Can be used to upload
* Use but dont remove my name. Creative Commons.
* Versão: 1.0 - 03/03/2007 - Tested no FF2.0 IE6.0 e OP9.1
* Author: Micox - Náiron JCG - elmicoxcodes.blogspot.com - micoxjcg@yahoo.com.br
* Parametros:
* form - the form to submit or the ID
* url_action - url to submit the form. like action parameter of forms.
* id_element - element that will receive return of upload.
* html_show_loading - Text (or image) that will be show while loading
* html_error_http - Text (or image) that will be show if HTTP error.
*******/

 //testing if 'form' is a html object or a id string
 form = typeof(form)=="string"?$m(form):form;
 
 var erro="";
 if(form==null || typeof(form)=="undefined"){ erro += "The form of 1st parameter does not exists.\n";}
 else if(form.nodeName.toLowerCase()!="form"){ erro += "The form of 1st parameter its not a form.\n";}
 if($m(id_element)==null){ erro += "The element of 3rd parameter does not exists.\n";}
 if(erro.length>0) {
  alert("Error in call micoxUpload:\n" + erro);
  return;
 }

 //creating the iframe
 var iframe = document.createElement("iframe");
 iframe.setAttribute("id","micox-temp");
 iframe.setAttribute("name","micox-temp");
 iframe.setAttribute("width","0");
 iframe.setAttribute("height","0");
 iframe.setAttribute("border","0");
 iframe.setAttribute("style","width: 0; height: 0; border: none;");
 
 //add to document
 form.parentNode.appendChild(iframe);
 window.frames['micox-temp'].name="micox-temp"; //ie sucks
 
 //add event
 var carregou = function() { 
   removeEvent( $m('micox-temp'),"load", carregou);
   var cross = "javascript: ";
   cross += "window.parent.$m('" + id_element + "').innerHTML = document.body.innerHTML;";
   cross += "window.parent.jQuery('#" + update_element + "').load('" + update_url + "');";
   cross += "void(0);"
   
   $m(id_element).innerHTML = html_error_http;
   $m('micox-temp').src = cross;
   //del the iframe
   setTimeout(function(){ remove($m('micox-temp'))}, 250);
  }
 addEvent( $m('micox-temp'),"load", carregou)
 
 //properties of form
 form.setAttribute("target","micox-temp");
 form.setAttribute("action",url_action);
 form.setAttribute("method","post");
 form.setAttribute("enctype","multipart/form-data");
 form.setAttribute("encoding","multipart/form-data");
 //submit
 form.submit();
 
 //while loading
 if(html_show_loading.length > 0){
  $m(id_element).innerHTML = html_show_loading;
 }
 
}


/* SWFOBJECT */


function preparePlayer(filename)
{
var so = new SWFObject("/forums/js/swfobject/mediaplayer.swf", "901", "400", "70", "7", "#FFFFFF");
    so.addVariable("file", "/forums/uploads/"+filename);
  	so.addVariable("showeq", "true");
  	so.addVariable("overstretch", "true");
  	so.addVariable("showdigits", "true");
  	so.addVariable("showfsbutton", "true");
  	so.addVariable("backcolor", "0x000000");
  	so.addVariable("frontcolor", "0xFFFFFF");
  	so.addVariable("lightcolor", "0xFFFFFF");
  	so.addVariable("volume", "80");
  	so.addVariable("bufferlength", "3");
  	so.addVariable("width", "400");
  	so.addVariable("height", "70");
  	so.write(filename);
}


/* INSERT MEDIA */

function sendImgToPost(filename)
{
	
	if(filename != undefined)
	{
	 var src = $('#'+filename).attr('src');
	 src = src.replace("/thumbs", ""); 
	}
	else
	{
		var src = $('#uploaded_file').attr('src');
	}
	tinyMCE.execCommand('mceInsertContent',false,' <img src="'+src+'"/> ');
}

function sendSongToPost(filename)
{
	tinyMCE.execCommand('mceInsertContent',false,'[insertMedia]'+filename+'[/insertMedia]');
}

function setVisibility(id, visibility) {
   document.getElementById(id).style.display = visibility;
   return false;
}

