var IE = document.all?true:false;
var aId = 'EditorMTF';	

function LoadingEditorMt(){		
	V('EditorMTT');
	V('EditorMTF');	
	V('EditorMtTools');
	
	var t = document.getElementById('EditorMTT').value;
	var myIFrame = document.getElementById(aId);
		
	myIFrame.contentWindow.document.write('<html><head><title>internauci.org</title><link href="http://internauci.org/editorMt.css" rel="stylesheet" type="text/css" /></head><body></body></html>');
	myIFrame.contentWindow.document.body.innerHTML = t;
	
	if(IE){ myIFrame.contentWindow.document.body.contentEditable = true;
	}else{ myIFrame.contentDocument.designMode = "on"; }
}

function SaveBlog(){
	var myIFrame = document.getElementById(aId);
	document.getElementById('EditorMTT').value = myIFrame.contentWindow.document.body.innerHTML;	
}

function Pr(title){
	var into = prompt("Podaj adres do "+title+":",'');
	return into;
}

function EditorMT(ins){
	var arg = null; 
	var val = null;
	
	switch(ins){	
		case 'b': 		arg = "Bold"; 					break;
		case 'i': 		arg = "Italic";					break;
		case 'u': 		arg = "Underline";				break;
		case 'ul':		arg = "InsertOrderedList";		break;
		case 'ol':		arg = "InsertUnorderedList";	break;
		case 'h1':		arg = "FontSize";	val="6";	break;
		case 'h2':		arg = "FontSize";	val="5";	break;
		case 'p':		arg = "RemoveFormat";			break;
		case 'center':	arg = "JustifyCenter";			break;
		case 'left':	arg = "JustifyLeft";			break;
		case 'right':	arg = "JustifyRight";			break;
		//case 'full':	arg = "JustifyFull";			break;
		case 'Outdent':	arg = "Outdent";				break;
		case 'Indent':	arg = "Indent";					break;		
		
		case 'emoticon':	arg = "InsertImage";	val="img/emoticons/artykul.jpg";		break;	

		case 'url':			arg = "CreateLink";		val=Pr("strony");						break;
		case 'img':			arg = "InsertImage";	val=Pr("obrazka");						break;
		case 'youtube':		arg = "InsertHTML";		val=Pr("filmu youtube");				break;
		case 'unurl':		arg = "UnLink";	 												break;
		
		
		default:	alert("B��d");
	}
	//alert(val);
	if(IE) { ob =  document.frames[aId].document; } 
	else{ ob = document.getElementById(aId).contentDocument; }
	
	ob.execCommand(arg, false, val);
}

function V(idk){
	var obj = document.getElementById(idk);
	if(obj.style.display=="none"){ obj.style.display="block"; }else{ obj.style.display="none"; }
}

function SelectColor(color){
	document.getElementById('colors').style.background = color;
	if(IE) { ob =  document.frames[aId].document; } 
	else{ ob = document.getElementById(aId).contentDocument; }
	ob.execCommand("ForeColor",false,color);
}

function SelectEmoticon(src){
	if(IE) { ob =  document.frames[aId].document; } 
	else{ ob = document.getElementById(aId).contentDocument; }
	ob.execCommand("InsertImage",false,src);
}


// JavaScript Document
function pos(e) {
	var tempY=0,y=0;
	
		if( typeof( window.pageYOffset ) == 'number' ){
			y = window.pageYOffset;
		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			y = document.body.scrollTop;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			y = document.documentElement.scrollTop;
		}				
				
		if(IE){	tempY = event.clientY + y; 
		}else{ tempY = e.pageY; 	} 		
		
		if (tempY < 0) {tempY = 0} ;		
	
return tempY;
}

function resize(e){
		if(e!="over"){
			var o = document.getElementById(aId);
			var pA = pos(e);		
			var y = o.style.height;
					
			y = (pA-y.replace("px",""));	
		}
		
		document.onmousemove = function(e){
			if(e!="over"){
				var p = pos(e);		
				if((p-y) >= 400){
					o.style.height = (p-y)+"px";
				}
				
				document.onmouseup = function(e) {
					resize('over');
				}
			}
		}	

return 0;
}
