/*
* Tento soubor jsem vytahl z miniBB diskuzniho fora a slouzi k javascriptovemu handlovani s citacemi
* komentaru. Nevim, zda to nejde proti licenci miniBB fora, ale je to vyborny nastroj, takze jej zde
* necham. A samozrejme promptne odstranim, pokud dojde na protesty.
*
* http://www.miniBB.net
*
*/




function checkBrowser()
	{
	this.ver=navigator.appVersion;
	this.dom=document.getElementById?1:0;
	this.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom)?1:0;
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ns6=(this.dom && parseInt(this.ver)>= 5)?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;

	this.ff15=(navigator.userAgent.toLowerCase().indexOf("firefox/1.5")!=-1)?1:0;

	this.opr8=(navigator.userAgent.toLowerCase().indexOf("opera 8")!=-1)?1:0;
	if(this.opr8 == 0)
		this.opr8=(navigator.userAgent.toLowerCase().indexOf("opera/8")!=-1)?1:0;
	
	this.opr=(navigator.userAgent.toLowerCase().indexOf("opera")!=-1)?1:0;
	
	
	return this
	}




function orizniKonec(str,jmeno,formular)
	{
	var str = ''+str+'';
	str = str.substring(0,str.length-1);
	paste_strinL(str,jmeno,formular);
	}




function paste_strinL(selection,jmeno,formular)
	{ 
	var strinL = ''+selection+'';
	if(strinL=='')
		alert('Označ prosím myší úsek komentáře, který chceš citovat.\nPrvní ani poslední znak úseku nesmí být mezera!');
	else
		{
		
		/*
		*	Texy syntaxe nezvladne syntaxi, ktera konci mezerou nebo teckou.
		*	Proto jsem to takhle osefoval... mezera nebo tecka se odstrani.
		*/
		var konec = strinL.substring(strinL.length-1,strinL.length);
		if(konec == " " || konec == ".")
			{
			orizniKonec(strinL,jmeno,formular);
			}
		else
			{
			strinL = '**'+jmeno+' napsal/a:** >>' + strinL + '<<' + '\n'; // Texy! syntaxe
			
			var formText, formForm;
			if(formular == 'kf')
				{
				formForm = 'kf';
				formText = 'kt';
				}
			else if(formular == 'forum-form')
				{
				formForm = 'forum-form';
				formText = 'nt_text';
				}
			else if(formular == 'foto-form')
				{
				formForm = 'foto-form';
				formText = 'ktext';
				}
			
			
			var isForm=document.forms[formForm];
			if (isForm)
				{
				var input=document.forms[formForm].elements[formText];
				input.value=input.value+strinL; 
				location.href= '#'+formForm; // tohle zajisti, ze po kliknuti na "citace" odkaz obrazovka preskoci na formular.
				}
			else
				alert('Přístup zamítnut');
			}
		} // if konec
	}



function pasteSel()
	{
	if(window.getSelection) selection=window.getSelection();
	else if(document.getSelection) { selection=document.getSelection(); }
	else if(document.selection) selection=document.selection.createRange().text;
	else selection='';
	return selection;
	}



function getQuotation(jmeno,formular) {
	var bw = new checkBrowser();

	if ((bw.ns6 || bw.ie5 || bw.ie6 || bw.ie7 || bw.ns4 ) && !(bw.opr && !bw.opr8)) {
	
		if(formular == 'forum-form' || formular == 'foto-form') {
			document.write(' - ');
		}
		
		if(bw.ff15) {
			document.write('<a href="javascript://" onMouseDown="pasteSel();paste_strinL(selection,\''+jmeno+'\',\''+formular+'\');" title="Vloží do textového pole označený úsek textu" class="odkaz-cituj">cituj</a>');
		}
		else {
			document.write('<a href="javascript:paste_strinL(selection,\''+jmeno+'\',\''+formular+'\')" onMouseDown="pasteSel()" title="Vloží do textového pole označený úsek textu" class="odkaz-cituj">cituj</a>');
		}
		
	}
}

