// JavaScript Document
function getBody(elId,el)
{
	ShowLoader($("#jrightcol"), true)
	$("#jrightcol").load("rightcolDiv.cfm?p="+elId);
	$(".liSelect").removeClass("liSelect");
	
	$(el).addClass("liSelect");
}


function ShowLoader(DomEl, show)
	{
		if(show)
		{	
			
			$(DomEl).empty();
			
			var image = document.createElement("img");
			image.id = 'ajaxLoaderImg';
			image.src="/images/load.gif";
			$(image).attr('align','center'); 
			
			var loadingDiv =  document.createElement("div");
			loadingDiv.id = 'preloadDiv';
			$('#preloadDiv').attr('align','center'); 
			$('#preloadDiv').attr('clear','both'); 
			$(loadingDiv).append(image);
			$(DomEl).prepend(loadingDiv);
			 
		}
		else
		{
			$(DomEl).find("#ajaxLoaderImg").remove();	
		}
	}
	
function findPos(obj){
var posY = obj.offsetTop;

	while(obj.offsetParent)
	{
		posY=posY+obj.offsetParent.offsetTop;
		if(obj==document.getElementsByTagName('body')[0]){break}
		else{obj=obj.offsetParent;}
	}
	return [posY]
}

function CatPosts(elId,el){
	ShowLoader($("#jrightcol"), true)
	$("#jrightcol").load("rightcolDiv.cfm?cat="+elId);
	$(".liSelect").removeClass("liSelect");
	
	$(el).addClass("liSelect");
}

function close_window(val){
	ColdFusion.Window.getWindowObject(val).destroy(true);	
	ColdFusion.objectCache[val] = null;
}

function edit_post(val){
	var id = val.replace(/[^\d\s]+/g, "");
	ColdFusion.Window.create('Edit', id,'wysiwyg.cfm?ID='+id,
		{x:100,y:100,height:550,width:700,modal:false,closable:true,
		draggable:true,resizable:false,center:true,initshow:true})

}


function edit_date(){
	ColdFusion.Window.create('Edit', id,'wysiwyg.cfm?ID='+id,
		{x:100,y:100,height:550,width:700,modal:false,closable:true,
		draggable:true,resizable:false,center:true,initshow:true})
}

function edit_title(val){
	var title = $("#h_"+val).html();
	$("#edit_"+val).hide();
	
	var Inpt =  document.createElement("input");
	Inpt.setAttribute("id","title");
	Inpt.setAttribute("type","text");
	Inpt.setAttribute("value",title);
	Inpt.setAttribute("name","title");
	
	var btn =  document.createElement("input");
	btn.setAttribute("id","btn_"+val);
	btn.setAttribute("type","button");
	btn.setAttribute("value",'Done');
	btn.onclick = function(){ChangeToH(this.id)};
	$("#h_"+val).empty();
	$("#h_"+val).append(Inpt);
	$("#h_"+val).append(btn);
}

function ChangeToH(val){
	var id = val.replace(/[^\d\s]+/g, "");
	var title = $("#jtitle").val();
	$("#h_"+id).empty();
	$("#h_"+id).html(title);
	$("#title_"+id).html(title);
	$("#edit_"+id).show();
	send_values(id);
	
}

function DescriptionSend(val){
		var editdesc = ColdFusion.getElementValue('description','wysiwyg');
		$("#post_"+val).html(editdesc);
		close_window('Edit');
		send_values(val);
}

function send_values(val){

	var desc = $("#post_"+val).html();
	
	var title = $("#h_"+val).html();

	var z = new PostContent();
	z.setHTTPMethod("post");
	var CatRet = z.update_post(val,'',title,desc);
	
}
