function start_editor(edt){
	var oFCKeditor = new FCKeditor(edt);
	oFCKeditor.BasePath = "/editor/" ;
	oFCKeditor.ToolbarSet = "More";
	oFCKeditor.Height	= 300 ;
	oFCKeditor.ReplaceTextarea();
}

function start_full_editor(edt){
	var oFCKeditor = new FCKeditor(edt);
	oFCKeditor.BasePath = "/editor/" ;
	oFCKeditor.ToolbarSet = "Default";
	oFCKeditor.Height	= 400 ;
	oFCKeditor.ReplaceTextarea();
}

function start_basic_editor(edt){
	var oFCKeditor = new FCKeditor(edt);
	oFCKeditor.BasePath = "/editor/" ;
	oFCKeditor.ToolbarSet = "Basic";
	oFCKeditor.Height	= 400 ;
	oFCKeditor.ReplaceTextarea();
}

function refresh_new_content(frame_div, content_div, editor_div){

	c = document.getElementById(content_div);
	f = document.getElementById(frame_div).contentWindow.document;
	
	if(f.location.href!="about:blank"){
		new_content = f.body.innerHTML;
		if(new_content!=""){
			c.innerHTML = new_content;
			showdiv(content_div);
			hidediv(editor_div);
		}
	}
}



//-- not used --//

var iView;
var this_wysiwyg_div;

var arr_contents = new Array();

function init_editor(wysiwyg_div, text_div){
	
	make_editor(wysiwyg_div);

	document.getElementById(wysiwyg_div).contentWindow.document.body.innerHTML = document.getElementById(text_div).innerHTML;
	
	//document.getElementById(wysiwyg_div).focus();
}

function make_editor(wysiwyg_div){

	this_wysiwyg_div = wysiwyg_div;
	
	if(document.all){
		iView = document.getElementById(wysiwyg_div).contentWindow.document;
		if(iView)
			iView.body.contentEditable = true;

	} else {
		
		iView = document.getElementById(wysiwyg_div).contentDocument;
		if(iView)
			iView.designMode="on";
	}
}

function close_editor(id){
	
	document.getElementById('wysiwyg_content_'+id).contentWindow.document.body.innerHTML = document.getElementById('wysiwyg_area_'+id).innerHTML;
	
	hidediv('wysiwyg_editor_'+id); 
	showdiv('wysiwyg_content_'+id); 
}	
	
function doCenter(){
	iView.execCommand('justifycenter', false, null);
}
function doLeft(){
	iView.execCommand('justifyleft', false, null);
}
function doRight(){
	iView.execCommand('justifyright', false, null);
}
function doBold(){
	iView.execCommand('bold', false, null);
}
function doItalic(){
	iView.execCommand('italic', false, null);
}
function doBulList(){
	iView.execCommand('insertunorderedlist', false, null);
}
function doForeCol(){
	var fCol = prompt('Enter foreground color', '');

	if(fCol != null)
		iView.execCommand('forecolor', false, fCol);
} 
function doRule(){
	iView.execCommand('inserthorizontalrule', false, null);
}
function doFont(fName){
	if(fName != '')
		iView.execCommand('fontname', false, fName);
} 
function doSize(fSize){
	if(fSize != '')
		iView.execCommand('fontsize', false, fSize);
}
function doLink(){
}
function doLink2(){
		
	//window.open('/js/insert_hyperlink.html?wysiwyg=6', 'popup', 'location=0,status=0,scrollbars=0,resizable=0,width=350,height=160,top=100,left=100');
	
	//iView = document.getElementById(wysiwyg_div).contentWindow.document;

	//iView.execCommand('createlink');
	//editor.contentWindow.document.selection.createRange().pasteHTML(hyperlink.outerHTML);

	str1=prompt("Please insert  URL ","");
	if(str1 != null){
		if(document.all){

			range = iView.selection.createRange();  
			link_text = iView.selection.createRange().text ;      
			str = "<a href=' " +str1+ " ' target='_blank' ><U>" +   link_text + "</U></a>";
			range.pasteHTML(str);

		} else {
			
			//var selectedRange = editor.contentWindow.document.selection.createRange().text;
			
			//iView = document.getElementById(this_wysiwyg_div);

			//iView = document.getElementById(this_wysiwyg_div).contentWindow.document;

			selectedRange  =   document.getElementById(this_wysiwyg_div).contentWindow.document.selection.createRange().text;
			
			if (selectedRange != null && selectedRange != ''){
			
				insertLink = prompt('', selectedRange);
			
				document.getElementById(this_wysiwyg_div).document.execCommand('CreateLink', false, insertLink);
				//iView.execCommand('CreateLink', false, insertLink);

			}
		}
	} else{
		alert("you didn't insert URL ");
	}


}
function doHead(hType){
	if(hType != ''){
		iView.execCommand('formatblock', false, hType);
		//doFont(selFont.options[selFont.selectedIndex].value);
	}
} 

var htmlOn = false;

function switch_html(buttons_div){

	if (htmlOn == true){	

		if(document.all){
			var text = iView.body.innerText;

		} else {
			var text = iView.body.textContent;

		}

		iView.body.innerHTML = text;

		//iView.body.innerHTML = iView.body.innerHTML.replace("&nbsp;", "");

		if(document.getElementById(buttons_div)!=null) document.getElementById(buttons_div).style.display = "block";
		
		htmlOn = false;
	}else{	

		var html = iView.body.innerHTML;

		if(document.all){
			iView.body.innerText = html;
		} else {
			iView.body.textContent = html;
		}

		document.getElementById(buttons_div).style.display = "none";
		
		//selFont.style.display = 'none';
		//selSize.style.display = 'none';
		//selHeading.style.display = 'none';

		htmlOn = true;
	}
}

function wysiwyg_save(text_div, wysiwyg_div, form_div){
	
	if (htmlOn == true){
		switch_html(buttons_div);
	}
	
	var content = iView.body.innerHTML;

	//get content from editor frame, pass to form and submit
	//var content = document.getElementById(wysiwyg_div).contentWindow.document.body.innerHTML;
	
	var this_form = document.getElementById(form_div);
	
	this_form.content.value = content;
	
	this_form.submit();

	//send_xml("/cp/content/save.php?task=Content&content_id="+content_id+"&body="+content, 1);
	//document.getElementById(text_div).innerHTML = content;

}

function preview_photo(id){
	o = document.getElementById('wysiwyg_content_'+id);
	f = document.getElementById('wysiwyg_photoframe_'+id).contentWindow.document;
	
	if(f.location.href!="about:blank"){
		new_img = f.body.innerHTML;			
		if(new_img!=""){
			o.innerHTML = new_img;
			showdiv('wysiwyg_content_'+id);
		}
	}
}



function del_content(id, content_id){
	if(confirm("Are you sure you want to delete?")){
		send_xml('/cp/content/save.php?task=Del&content_id='+content_id, 0);
		hidediv(id);
	}
}

function edit_text(text_id, editor_id){
	hidediv(text_id);
	showdiv(editor_id);
}

function save_text(url, new_value, text_id, editor_id){
	
	//update
	send_xml(url, 0);
	
	hidediv(editor_id);
	showdiv(text_id);

	document.getElementById(text_id).innerHTML = new_value;
}

