var URL = document.location+"";
var URLSITE = URL;
var estabResize;
var eventResize;
if( URL.lastIndexOf('.br') != -1 )
	URLSITE = URL.substring( 0, URL.lastIndexOf('.br') + 3 );

//URLSITE = 'http://localhost:8080'

function setLogo() {
	url = document.location;
	if( url.toString().indexOf('lbr')>0 )
		document.getElementById('logo').style.background="transparent url(/templates/site/default/logos/logorede.png) no-repeat scroll 0 0";
}

function setFocus(el) {
	setTimeout("document.getElementById('"+el+"').focus();",500);
}

//---------------------------------------------------------------------
//Upload
function uploadFile( recipient, type, name, path, width, height ) {
	var recipient = recipient+"";
	var inputfile = document.getElementById( recipient );
	var fupload = document.getElementById('fupload');
	
	if( document.getElementById('imageBtn') )
		var buttons = 1;

	if( inputfile.value != "" ) {
		fupload.insertBefore( inputfile, null );
		if( buttons == 1 ) 
			document.getElementById("imageBtn").style.display="none";
//		else
//			inputfile.style.display = "none";
		
		var URL = document.location+"";		
		URL = URL.substring(0,URL.lastIndexOf('index.php'));
		
		var url = URL+'index.php?m=upload&filename='+name+'&recipient='+recipient+'&type='+type+'&path='+path+'&width='+width+'&height='+height;
		micoxUpload("fupload",url,recipient+'_load','&nbsp;<img src="image/indicatormini.gif">&nbsp;Carregando...','Erro ao carregar');
	}
}
function uploadImageCrop( recipient, type, name, path, width, height, crop ){
	var recipient = recipient+"";
	var inputfile = document.getElementById( recipient );
	var fupload = document.getElementById('fupload');
	
	if( document.getElementById('imageBtn') )
		var buttons = 1;

	if( inputfile.value != "" ) {
		fupload.insertBefore( inputfile, null );
		if( buttons == 1 ) 
			document.getElementById("imageBtn").style.display="none";
		
		var URL = document.location+"";		
		URL = URL.substring(0,URL.lastIndexOf('index.php'));
		
		if(crop != "undefined")
			crop = "1";
		else
			crop = "0";
			
		var url = URL+'index.php?m=upload&filename='+name+'&recipient='+recipient+'&type='+type+'&path='+path+'&width='+width+'&height='+height+'&crop='+crop;
		micoxUpload("fupload",url,recipient+'_load','&nbsp;<img src="image/indicatormini.gif">&nbsp;Carregando...','Erro ao carregar');
	}
}
//---------------------------------------------------------------------

function fecharRich() {
	richM = findDOM('Rich_Media');
	if( richM )
		richM.parentNode.removeChild(richM);
}

function fecharIntro() {
	richM = findDOM('introDiv');
	sites = findDOM('siteAgito');
	if( richM )
		richM.parentNode.removeChild(richM);
	if( sites )
		sites.style.display = "inline";
	if( richM ) {
		loadCorpo();
		setLoading();
	}
}

function disableselect(e){
      return false;
}

function reEnable(){
      return true;
}

function removeSidebar() {
	document.onselectstart=new Function ("return false");
	if (window.sidebar){
      	document.onmousedown=disableselect;
    	document.onclick=reEnable;
	}
}

function textCounter(field, maxlimit) {
if (field.value.length > maxlimit) 
	field.value = field.value.substring(0, maxlimit);
}

function scrollToBottom() {
	if (document.all)
		topScroll = document.documentElement.clientHeight; 
	else
		topScroll = window.innerHeight; 
	window.scrollTo(0, topScroll);
}

function confirmDelete( question, action ) {
	answer = confirm(question);
	if( answer )
		eval( action );
		
	return answer;
}

/////////////////////////////////////////////
//    Funcoes para o Loading do Ajax       //
/////////////////////////////////////////////

var wait=0;
var countResponse=0;

function showLoading() {

	var page = findDOM("disablePage");
	var loading = findDOM("loadingMessage");
	var isHome = findDOM("chamadasCadernoHome");
	var isLive = findDOM("janelaPerfilPrincipal");
	
	if( wait==0 )
		countResponse=0;

	if( isHome ) {
		page.style.display='none';
		loading.style.display='none';
	}
	else {
		if( document.all ) {
			page.style.height=document.body.offsetHeight;
			topScroll = document.documentElement.scrollTop;
			page.style.width=document.body.offsetWidth;
			leftScroll = document.documentElement.scrollLeft;
			widthTotal = document.body.clientWidth;
		} else {
			page.setAttribute('style','height:'+document.body.offsetHeight+'px;');
			topScroll = window.pageYOffset; 
			page.setAttribute('style','width:'+document.body.offsetWidth+'px;');
			leftScroll = window.pageXOffset; 
			widthTotal = window.innerWidth;
		}
		if( isLive )
			if( topScroll > 300 ) {
				window.scrollTo(0, 0);
				topScroll = 0;
			}
		loading.style.top = ( topScroll + 200 )+"px";
		loading.style.left = ( leftScroll + parseInt((widthTotal/2)-75) )+"px";
		page.style.display='block';	
		loading.style.display='block';
		page.disabled = true;
	}
}

function hideLoading() {

	countResponse++;

	if( wait==0 ) {
		var page = findDOM("disablePage");
		var loading = findDOM("loadingMessage");
		
		page.style.display='none';
		loading.style.display='none';
    	
    	// fotos
    	var fotoCob=findDOM('fotoCobertura');
    	if( fotoCob )
			fotoCob.style.visibility = 'visible';
	}
	
}

function setLoading() {
	xajax.callback.global.onRequest = showLoading;
	xajax.callback.global.onComplete = hideLoading;
	xajax.callback.global.onFailure = hideLoading;
	
/*	xajax.callback.global.onFailure = function(args) {
		alert("In global.onFailure...HTTP status code: " + args.request.status);
	} 
*/	
//	xajax.loadingFunction = showLoading;
//	xajax.doneLoadingFunction = hideLoading;
	try {
  		document.execCommand("BackgroundImageCache", false, true);
	} catch(err) {}	
}

function setLoadingPos( el, waux, haux ) {	
	var loadingWidth = 150;
	var loadingHeight = 30;	
	var w = el.offsetWidth;
	var h = el.offsetHeight;		
	
	pos = findPos(el);
			
	if( !waux )
		waux = 0;
	if( !haux )
		haux = 0;
		
	loading = findDOM("loadingMessage");	
	if( document.all ) {
		loading.style.top = pos[1] + haux + (h/2) - loadingHeight/2;
		loading.style.left = pos[0] + waux + (w/2) - loadingWidth/2;
	}
	else {
		top = pos[1] + haux + (h/2) - loadingHeight/2;
		left = pos[0] + waux + (w/2) - loadingWidth/2;
		loading.setAttribute('style','top:'+top+'px;'+'left:'+left+'px;');
	}
}

function setWait() {
	wait=1;
	foto = findDOM("fotoCobertura");	
	if( foto.offsetHeight > 375 )	
		setLoadingPos( foto, 0, -62 );
	else
		setLoadingPos( foto );
}

function stopWait() {
	wait=0;
	
	if( countResponse > 0 )
		setTimeout("hideLoading();", 500);
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

////////////////////////////////////////////
//    Funcoes de formatacao de foto       //
////////////////////////////////////////////

function findDOM(objectId) {
	if (document.getElementById) {
		return (document.getElementById(objectId));}
		if (document.all) {
			return (document.all[objectId]);}
}

function recarregaPerfil( urlPerfil ) {
	perfilD = findDOM('amigoPerfil_id');
	var perfilExist = false;
	if( perfilD != null ) {
		perfil = perfilD.value;
		if( perfil > 0 ) {
			perfilComp = "&perfil_id="+perfil;
			perfilExist = true;
		}
	}
	if( perfilExist )
		url = urlPerfil+perfilComp;
	else
		url = urlPerfil;
	setTimeout("top.location.href = '"+url+"';",500);
}

function redirecionarUrl( url ) {
	setTimeout("top.location.href = '"+url+"';",500);
}

function limpaThumbsAlbum(sortPic,numeroPagina,proximaFoto,anteriorFoto,largura,altura){
	var e=document.getElementsByTagName("a");
	for(var i=0;i<e.length;i++){
		if(e[i].className=='thumbAlbumMarcado'||e[i].className=='thumbAlbum') 
			e[i].className = 'thumbAlbum';
	}
	var at=findDOM('thumb'+sortPic);
	var prox = findDOM('proxima');
	var ant = findDOM('anterior');
	if (at!=null) {
		at.className = 'thumbAlbumMarcado';	
		if(proximaFoto!=0) {
			var pr=findDOM('thumb'+proximaFoto);
			if (pr!=null) {
				prox.style.display = 'block';
				prox.onclick = function() {
					hideFoto(0);
					xajax_getFoto(proximaFoto,numeroPagina, xajax.getFormValues( 'formFoto' ) );
				}
			}				
			else {
				prox.style.display = 'block';
				prox.onclick = function() {
					hideFoto(0);
					xajax_getPagina((numeroPagina+1),1,xajax.getFormValues( 'formFoto' ));
				}	
			}
		} 
		else {
			prox.style.display = 'none';
			prox.onclick = function() {
				void(null);
			}
		}

		if(anteriorFoto!=0) {
			var an=findDOM('thumb'+anteriorFoto);
			if (an!=null) {
				ant.style.display = 'block';
				ant.onclick = function() {
					hideFoto(0);
					xajax_getFoto(anteriorFoto,numeroPagina,xajax.getFormValues( 'formFoto' ));}				
			} 
			else {
				ant.style.display = 'block';
				ant.onclick = function() {
					hideFoto(0);
					xajax_getPagina((numeroPagina-1),0,xajax.getFormValues( 'formFoto' ));}			
			}
		} 
		else {
			ant.style.display = 'none';
			ant.onclick = function() {
				void(null);
			}	
		}
	}
	var fotoCob=findDOM('fotoCobertura');
	fotoCob.style.width = largura+'px';
	fotoCob.style.height = altura+'px';
	hideLoading();
}

function hideFoto(foto_id) {
	var fotoMarcada = 1;
	var atFoto=findDOM('thumb'+foto_id);
	if( atFoto )
		if( atFoto.className != 'thumbMarcado' || atFoto.className != 'thumbAlbumMarcado' ) 
			fotoMarcada = 0;
	
	fotoCob = findDOM('fotoCobertura');	
	fotoCob.src = "../default/img/transparente.gif";
	if( foto_id==0 && fotoMarcada == 0) {
		fotoCob.style.visibility = 'hidden';
		setWait();
	} else {
		fotoCob.style.visibility = 'visible';
	}	
}

function showDenuncia ( hash ) {
	xajax_getJanelaDenuncia( hash );
}

function hideJanela ( id ) {
	dDOM = findDOM(id);
	if(dDOM) {
		dDOM.style.display = 'none';
		dDOM.innerHTML = "";
	}
}

function ini( conteudo_id, entidade_id, dominio_id ) {
	cont_id=conteudo_id;
	ent_id=entidade_id;
	dom_id=dominio_id;
	checkLoginBox();
	getMidias();
	//xajax_checkMenu();
}

function iniAlbum ( numeroPagina, conteudo_id, entidade_id ) {
	cont_id=conteudo_id;
	ent_id=entidade_id;
	dom_id=0;
	getMidias();
	checkLoginBox();
	xajax_getJanelaPesquisa( xajax.getFormValues( 'formFoto' ), numeroPagina );	
}

function iniPerfil ( usuario_id, acao, album_id, entidade_id ) {
	cont_id=usuario_id;
	ent_id=entidade_id;
	dom_id=0;
	getMidias();
	checkLoginBox();
	xajax_getPaginaPerfil( usuario_id, acao, album_id );
}

function iniComunidade ( comunidade_id, acao, album_id, entidade_id ) {
	cont_id=comunidade_id;
	ent_id=entidade_id;
	dom_id=0;
	getMidias();	
	checkLoginBox();
	xajax_getPaginaComunidade( comunidade_id, acao, album_id );
}

function mostraVideo( video ) {
	vd = findDOM('biografiaVideo');	
	vd.innerHTML = video;
}

function selecaoPesquisa () {
	document.getElementById("filterWord").select();
}

function selecaoCampo ( nomeCampo ) {
	document.getElementById( nomeCampo ).select();
}

function disableEnterKey( e, c )
{
     var key;
     if(window.event)
          key = window.event.keyCode;     	//IE
     else
          key = e.which;     				//firefox

     if(key == 13) {
     	if( c == "pesquisa" )
			resultPesquisa();
		else if ( c == "amigoPesquisa" ) {
			usr = findDOM('amigoUsuario_id');
			xajax_getPaginaAmigos( 1, usr.value, xajax.getFormValues('formPesqAmigo'));	
		}
		else if ( c == "pessoaPesquisa" ) {
			usr = findDOM('amigoUsuario_id');
			xajax_getPesquisaPessoasPagina( 1, usr.value, xajax.getFormValues('formPesqAmigo'), xajax.getFormValues('formPesqPessoa'));
		}		
		else if ( c == "favoritoPesquisa" ) {
			usr = findDOM('favoritoUsuario_id');
			xajax_getPaginaFavoritos( 1, usr.value, xajax.getFormValues('formPesqFavorito'));	
		}
		else if ( c == "metaAlbumTexto" )
			xajax_putNovoMetaFoto( xajax.getFormValues('formTagAlbum'),xajax.getFormValues('formFoto'));
		
		else if ( c == "metaAlbumPesquisa" )
			xajax_putMetaTextoPesquisa( xajax.getFormValues('formPesqAlbum'),xajax.getFormValues('formFoto'));
			
		else if ( c == "login" )
			logarUsuario(''); 
     	
		else if ( c == "perguntaPromocao" )
			xajax_putRespostaPromocao( xajax.getFormValues( 'formCheckPromo' ) );	
			
		else if ( c == "checkRGPromocao" ) 
			xajax_checkRG( xajax.getFormValues( 'formCheckPromo' ) );	

		else if ( c == "checkCPFPromocao" )
			xajax_checkCPF( xajax.getFormValues( 'formCheckPromo' ) );	
			
     	return false;
     }
     else 
     	return true;     
}

function logarUsuario() {

	loginDOM = findDOM('loginInput');
	senhaDOM = findDOM('senhaInput');

	hashDOM = findDOM('hashConteudo');
	if(hashDOM)
		hash = hashDOM.value;

	var nomeUsuario = $("#usuarioRede").val();
	var importarRede = $("#importarRede").val();
	var novoCadastro = $("#tipo_cadastro").val();

	if(importarRede == "true"){
		var emailRede = $("#emailRede").val();
		var passwordRede = $("#passwordRede").val();
		var confirmRede = $("#confirmRede").val();
		var mailling = 0;
		var showProfileImg = null;
		if($("#mailling").attr("checked"))
			mailling = 1;
		if($("#showProfileImg").attr("checked"))
			showProfileImg = $("#profile_image_url").attr("src");
		
		if(novoCadastro == "novo")
			xajax_getAuthUserSocial( emailRede, passwordRede, confirmRede, nomeUsuario, mailling, showProfileImg, hash, "erro" );
		else
			xajax_getAuthUser( emailRede, passwordRede, hash, "erro", showProfileImg );
	} else
		xajax_getAuthUser( loginDOM.value, senhaDOM.value, hash, "loginErro", showProfileImg );
}

function checkLoginBox(){
	loginB = findDOM("loginBox");
	loginB2 = findDOM("loginBox2");
	loginBT = findDOM("loginBoxTexto");
	if(checkCookieLogin()) {
		loginB.style.display = "none";
		loginBT.style.display = "none";
		loginBT.style.display = "block";
		xajax_atualizaLogin();
	} else {
		loginB.style.display = "block";
		loginBT.style.display = "none";
		$("#login_nome").html("Login");
	}
}
function checkCookieLogin(){
	al = getCookieLogin("agitologinInfo");
	if (al!=null&&al!=""){
		//msg('checkCookieTRUE');
		return true;
	}else{
		//msg('checkCookieFALSE');  	
		return false;
	}
}	
function getCookieLogin(c_name){
	if (document.cookie.length>0){
		c_start=document.cookie.indexOf(c_name+"=");
		//msg("c"+document.cookie);
		if (c_start!=-1){ 
			c_start=c_start+c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if(c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}
function checkLoginStatus(){
	if(!checkCookieLogin()){
		xajax_checkLoginStatus();
	}
}

function openPopFacebook(promocao){
	var param = "&promocao=0";
	if(promocao)
		param = "&promocao=1";
	window.open('http://'+location.host+'/index.php?m=homeSite&e=getAuthSessionFacebook'+param,'loginFacebook','width=600,height=500')
}	

function openPopTwitter(){
	window.open('http://'+location.host+'/index.php?m=homeSite&e=getAuthSessionTwitter','loginTwitter','width=600,height=500')
}

function createLogin(){
	// Login logado
	$(".login_nome").mouseover(function(event){
		$("#logado").css("display","block");
	});
	$("#logado").mouseover(function(event){
		$("#logado").css("display","block");
		$("#Super_Banner").css("display","none");
	});
	$("#logado").mouseout(function(event){
		$("#logado").css("display","none");
		$("#Super_Banner").css("display","block");
	});
}

function setSocialNet(logou, imgProfile, nomeProfile){
	if(logou){
		url = new String(window.location);
		if(url.indexOf("login=1")>=0)
			document.location = url;
		if( url.indexOf("?")>=0){
			url = url.replace("&login=1","");
			url+="&login=1";
		} else {
			url+="?login=1";
		}			
		document.location = url;
	} else {
		$("#importarRede").val("true");
		if(imgProfile != null || imgProfile != "undefined")
			$(".avatar img").attr("src", imgProfile);
		else
			$(".avatar img").attr("src", "im/avatar2.jpg");
		if(nomeProfile != null || nomeProfile != "undefined"){
			$(".avatar h2").html(nomeProfile);
			$("#usuarioRede").val(nomeProfile);
		}
		$("#loginBox").css("display","none");
		$("#loginBox2").css("display","block");
	}
}

function pesquisaAmigos( valorPesqAmigos, perfil_id ) {
	campoPesqAmigos = findDOM( 'abrangenciaAmigos' );
	campoPesqAmigos.value = valorPesqAmigos;
			
	todosAmigosAmDOM = findDOM( 'todosAmigosPesquisaAm' );	
	amigosAmDOM = findDOM( 'amigosPesquisaAm' );	
	
	todosAmigosAmDOM.className = "pesquisaAmItem";	
	amigosAmDOM.className = "pesquisaAmItem";	
	
	linkPesqAmDOM = findDOM( valorPesqAmigos+'PesquisaAm' );
	linkPesqAmDOM.className = "pesquisaAmSelecionado";
	
	if( valorPesqAmigos == 'todosAmigos' )
		xajax_getPesquisaPessoasPagina( 1, perfil_id, xajax.getFormValues('formPesqAmigos') );
	else
		xajax_getPaginaAmigos( 1, perfil_id, xajax.getFormValues('formPesqAmigos') );
}


function limpaAbas( el, tag, base ) {
	var e=document.getElementsByTagName(tag);
	for(var i=0;i<e.length;i++){
		if(e[i].className==base+'Marcado'||e[i].className==base+'Fim'||e[i].className==base) {
			if(	e[i].id==base+"7" || e[i].id==base+"14" || e[i].id==base+"21" || e[i].id==base+"28" ||
				e[i].id==base+"6" || e[i].id==base+"13" || e[i].id==base+"20" || e[i].id==base+"27")
				e[i].className = base+'Fim';
			else
				e[i].className = base;
		}
	}
	sp = findDOM(base+el);
	sp.className=base+'Marcado';	
}

function atualizaFormAgenda ( campo, valor ) {
	cp = findDOM(campo);
	cp.value = valor;
}

function marcarSelecionado( base, id, total ) {
	for( var i=0; i<=total; i++ ) {
		elem = findDOM( base+i );
		if( elem )
			elem.className = base;
	}
	el = findDOM( base + id );
	if( el )
		el.className = base + 'Marcado';
}

function cancelarResponderMensagem( usuario_id ) {	
	respMsgSuccess  = findDOM( 'responderMsgSucesso' );
	respMsg 		= findDOM( 'responderMsgUsuario' );
	loginTxt 		= findDOM( 'loginTextoMsgUsuario' );
	msgConteudo_id 	= findDOM( 'mensagemConteudo_id' );
	msgTexto 		= findDOM( 'textoMensagem' );
	msgTitulo 		= findDOM( 'tituloMensagem' );
	msgResponder	= findDOM( 'mensagemResponder' );
	
	respMsgSuccess.style.visibility = "hidden";
	respMsg.style.visibility 	= "hidden";
	loginTxt.style.visibility 	= "visible";
	msgConteudo_id.value 		= usuario_id;
	msgTexto.style.backgroundColor = "#FFFFFF";
	msgTitulo.style.backgroundColor = "#FFFFFF";
	msgResponder.value = 0;
}

function hoverIcones( mensagem ) {
	spanIcon = findDOM( 'mensagemIcones' );
	if( spanIcon ) 
		spanIcon.style.visibility = "visible";
	
	spanIconTxt = findDOM( 'mensagemIconesTexto' );
	if(spanIconTxt)
	spanIconTxt.innerHTML = mensagem;
	
}

function hoverIconesLimpar() {
	spanIcon = findDOM( 'mensagemIcones' );
	spanIcon.style.visibility = "hidden";
	spanIconTxt = findDOM( 'mensagemIconesTexto' );
	spanIconTxt.innerHTML = "";
}

function showPesquisaAv(){
	av = findDOM("buscaAv");
	
	if( av.style.display == "none")
		av.style.display = "block";
	else
		av.style.display = "none";
}

function showInserirMsg(){
	v = findDOM("inserirMsg");
	
	if( v.style.display == "none")
		v.style.display = "block";
	else
		v.style.display = "none";
}

function resultPesquisa() {
	
	noHover=0;
	var filterDomain;
	var allUsers;
	var entidadesStr = "";	
	filterWordDOM = findDOM('filterWord');
	filterDomainDOM = findDOM('filterDomain');
	perPageDOM = findDOM('perPage');
	orderByDOM = findDOM('orderBy');
	usuariosDOM = findDOM('usuarios');

	coberturasDOM = findDOM('coberturasE');
	enquetesDOM = findDOM('enquetesE');
	estabelecimentosDOM = findDOM('estabelecimentosE');
	eventosDOM = findDOM('eventosE');
	materiasDOM = findDOM('materiasE');
	promocoesDOM = findDOM('promocoesE');

	if ( !coberturasDOM.checked )
		entidadesStr = entidadesStr + coberturasDOM.value + ",";
	
	if ( !enquetesDOM.checked )
		entidadesStr = entidadesStr + enquetesDOM.value + ",";
	
	if ( !estabelecimentosDOM.checked )
		entidadesStr = entidadesStr + estabelecimentosDOM.value + ",";
	
	if ( !eventosDOM.checked )
		entidadesStr = entidadesStr + eventosDOM.value + ",";

	if ( !materiasDOM.checked )
		entidadesStr = entidadesStr + materiasDOM.value + ",";

	if ( !promocoesDOM.checked )
		entidadesStr = entidadesStr + promocoesDOM.value + ",";
		
	if ( !usuariosDOM.checked )
		allUsers = 0;
	else
		allUsers = 1;

	if ( !filterDomainDOM.checked )
		filterDomain = 0;
	else
		filterDomain = 1;		
	
	if(_gaq)
		_gaq.push(['_trackEvent', 'Busca', filterWordDOM.value, 'busca pelo header']);
		
	xajax_getSearchResultPage( 1, filterWordDOM.value, orderByDOM.value, entidadesStr, 
									allUsers, perPageDOM.value, filterDomain );
}


// ----------------------------------------------------------------------
// Editor HTML

var validateEditor=0;
var editor_id="";

function initEditor( editor_id, type, height, width ) {
	if( !height ) {
		height = "300";
		width = "98%"
	}
	oFCKeditor = new FCKeditor( editor_id, width, height, type,'' );
	var sBasePath = document.location.pathname.substring(0,document.location.pathname.lastIndexOf('index.php'));
	sBasePath = sBasePath + "lib/fckeditor/"
	oFCKeditor.BasePath	= sBasePath;
	oFCKeditor.ReplaceTextarea();
}

function updateFCK( id ) {
	var fck = FCKeditorAPI.GetInstance( id );
	eval("document.forms[0]."+id+".value = fck.GetXHTML();");
}

function debug( el ) {
	var element = document.getElementById( el );
	alert(element.innerHTML);
}

/*--------  Customized FOR getOption -----------------------------------*/
function addOption(selectId, txt, val) {
    var objOption = new Option( decodeHtml(val), txt);
    document.getElementById(selectId).options.add(objOption);
}

function clearOptions(selectId) {	
	var select = document.getElementById( selectId );	
	while( select.length > 0 ) {
		select.options.remove(0);
	}
}

function decodeHtml(html) {
	html = 	html.replace("&nbsp;"," ");
	html =	html.replace("&iexcl;","¡");
	html =	html.replace("&cent;","¢");
	html =	html.replace("&pound;","£");
	html =	html.replace("&curren;","¤");
	html =	html.replace("&yen;","¥");
	html =	html.replace("&brvbar;","¦");
	html =	html.replace("&sect;","§");
	html =	html.replace("&uml;","¨");
	html =	html.replace("&copy;","©");
	html =	html.replace("&ordf;","ª");
	html =	html.replace("&laquo;","«");
	html =	html.replace("&not;","¬");
	html =	html.replace("&shy;","­");
	html =	html.replace("&reg;","®");
	html =	html.replace("&macr;","¯");
	html =	html.replace("&deg;","°");
	html =	html.replace("&plusmn;","±");
	html =	html.replace("&sup2;","²");
	html =	html.replace("&sup3;","³");
	html =	html.replace("&acute;","´");
	html =	html.replace("&micro;","µ");
	html =	html.replace("&para;","¶");
	html =	html.replace("&middot;","·");
	html =	html.replace("&cedil;","¸");
	html =	html.replace("&sup1;","¹");
	html =	html.replace("&ordm;","º");
	html =	html.replace("&raquo;","»");
	html =	html.replace("&frac14;","¼");
	html =	html.replace("&frac12;","½");
	html =	html.replace("&frac34;","¾");
	html =	html.replace("&iquest;","¿");
	html =	html.replace("&Agrave;","À");
	html =	html.replace("&Aacute;","Á");
	html =	html.replace("&Acirc;","Â");
	html =	html.replace("&Atilde;","Ã");
	html =	html.replace("&Auml;","Ä");
	html =	html.replace("&Aring;","Å");
	html =	html.replace("&AElig;","Æ");
	html =	html.replace("&Ccedil;","Ç");
	html =	html.replace("&Egrave;","È");
	html =	html.replace("&Eacute;","É");
	html =	html.replace("&Ecirc;","Ê");
	html =	html.replace("&Euml;","Ë");
	html =	html.replace("&Igrave;","Ì");
	html =	html.replace("&Iacute;","Í");
	html =	html.replace("&Icirc;","Î");
	html =	html.replace("&Iuml;","Ï");
	html =	html.replace("&ETH;","Ð");
	html =	html.replace("&Ntilde;","Ñ");
	html =	html.replace("&Ograve;","Ò");
	html =	html.replace("&Oacute;","Ó");
	html =	html.replace("&Ocirc;","Ô");
	html =	html.replace("&Otilde;","Õ");
	html =	html.replace("&Ouml;","Ö");
	html =	html.replace("&times;","×");
	html =	html.replace("&Oslash;","Ø");
	html =	html.replace("&Ugrave;","Ù");
	html =	html.replace("&Uacute;","Ú");
	html =	html.replace("&Ucirc;","Û");
	html =	html.replace("&Uuml;","Ü");
	html =	html.replace("&Yacute;","Ý");
	html =	html.replace("&THORN;","Þ");
	html =	html.replace("&szlig;","ß");
	html =	html.replace("&agrave;","à");
	html =	html.replace("&aacute;","á");
	html =	html.replace("&acirc;","â");
	html =	html.replace("&atilde;","ã");
	html =	html.replace("&atilde;","ã");
	html =	html.replace("&atilde;","ã");		
	html =	html.replace("&auml;","ä");
	html =	html.replace("&aring;","å");
	html =	html.replace("&aelig;","æ");
	html =	html.replace("&ccedil;","ç");
	html =	html.replace("&egrave;","è");
	html =	html.replace("&eacute;","é");
	html =	html.replace("&ecirc;","ê");
	html =	html.replace("&euml;","ë");
	html =	html.replace("&igrave;","ì");
	html =	html.replace("&iacute;","í");
	html =	html.replace("&icirc;","î");
	html =	html.replace("&iuml;","ï");
	html =	html.replace("&eth;","ð");
	html =	html.replace("&ntilde;","ñ");
	html =	html.replace("&ograve;","ò");
	html =	html.replace("&oacute;","ó");
	html =	html.replace("&ocirc;","ô");
	html =	html.replace("&otilde;","õ");
	html =	html.replace("&ouml;","ö");
	html =	html.replace("&divide;","÷");
	html =	html.replace("&oslash;","ø");
	html =	html.replace("&ugrave;","ù");
	html =	html.replace("&uacute;","ú");
	html =	html.replace("&ucirc;","û");
	html =	html.replace("&uuml;","ü");
	html =	html.replace("&yacute;","ý");
	html =	html.replace("&thorn;","þ");
	html =	html.replace("&yuml;","ÿ");
	//html =	html.replace("&quot;",""");
	html =	html.replace("&lt;","<");
	html =	html.replace("&gt;",">");
	html =	html.replace("&amp;","&");
	
	return html;
}			   
/*--------  Customized FOR getOption -----------------------------------*/

