/*))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))
)))))))))))))   ))))  )))  )))))))))))
)))))))))))  )))  ))  )))  )))))))))))
)))))))))))))     ))  )))  )))))))))))
)))))))))))  )))  ))  )))  )))))))))))
)))))))))))  )))  ))  )    )))))))))))
)))))))))))))     ))))  )  )))))))))))
))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))

Slevarna.cz support JavaScript

© 2008 Petr Vostrel / www.pisi.cz

*/


function make_loadable(loading){
  Element.addMethods({
    ajaxUpdate: function(element, url, options){
      element=$(element);
      element.update(loading);
      $$('.Body').first().className="Body Loading";
      options.onComplete=function(){ $$('.Body').first().className="Body"; }
      new Ajax.Updater(element, url, options);
      return element;
    }
  });
}

function support_corner(){
  Event.observe(document,'mousemove',function(e){
    var x=Event.pointerX(e);
    var y=Event.pointerY(e);
    var t=corner.size+10;
    if (x<t&&y<t){
      corner.object.className='Highlight';
      scale_corner(54,true);
    }else if (x>t||y>t){
      corner.object.className='';
      scale_corner(36,false);
    }
  });
  Event.observe('Corner','click',function(e){ leave(); });
  scale_corner(36,false);
}

function large_image(o){
  $('LargeImage').src='GUI/Images/void.gif';
  $('LargeImage').setStyle({display: 'none'}).onload=function(){ this.appear(); }
  $('LargeImage').src=o.src.gsub('Thumb/','');
  $('LargeImageOverlay').appear({duration:0.3,fps:12});
}

function loading(){
  $$('.Body').first().className="Body Loading";
}
function idle(){
  $$('.Body').first().className="Body";
}

function key_press(e){
//  document.title=('char '+e.charCode+' || key '+e.keyCode+' | C:'+e.ctrlKey+' S:'+e.shiftKey+' A:'+e.altKey); // Left for future key stroke identification purposes
  if (e.ctrlKey&&(e.charCode==96||e.keyCode==96||e.keyCode==92||e.charCode==92||e.keyCode==28||e.charCode==28)){ setup(); e.stopPropagation(); } // Ctrl+\ and somewhere Ctrl+~
  if (e.keyCode==Event.KEY_ESC){ setup_ui(); e.stopPropagation(); } // Esc
  if (e.ctrlKey&&(e.keyCode==10||e.keyCode==13)){ setup_submit(); e.stopPropagation(); } // Ctrl+ENTER
  if (e.ctrlKey&&(e.keyCode==40)){ setup_maximize_trigger(); e.stopPropagation(); } // Ctrl+ArrowDOWN
}

var record_to_save=false;

function setup_submit(){
  if (record_to_save){ loading(); $('SetupForm').submit(); }
}

function setup_ui(){
  if ($('Setup').className==''){ return setup_hide(); }else{ if (question_abandon_changes()){ return setup_hide(); }} return false;
}

function setup_hide(){
  $('Setup').update('<div class="Nothing"></div>'); return true;
}

function setup_maximize_trigger(){
  $$('.SetupUI').first().toggleClassName('Maximized');
}

function setup_tool(url,tool){
  $('SetupTools').className=tool;
  $('SetupTool').ajaxUpdate(url,{evalScripts: true});
}
function setup_change_password(){
  $('SetupTools').className='MyProfile';
}
function setup_focus(e){
  var proc=Event.element(e).morph({ borderColor: '#00c6ff' },{ duration: 0.2 });
  if (proc.previous()) proc.previous().morph({ borderColor: '#00c6ff' },{ duration: 0.2 });
}
function setup_blur(e){
  var proc=Event.element(e).morph({ borderColor: '#000000' },{ duration: 0.2 });
  if (proc.previous()) proc.previous().morph({ borderColor: '#000000' },{ duration: 0.2 });
}
function setup_tool_cancel(e){
  $('SetupTools').className='';
  $('SetupTool').update();
}

function hide_setup_message(){
  $('SetupMessage').fade({ duration: 0.4 });
}

function question_abandon_changes(){
  return confirm("Tequki:\n„Neuložil(a) jsi provedené změny.“\n\nZahodit je?\n\nStiskni OK [Enter] pro ztracení změn nebo Zrušit [Esc] pro návrat");
}
function question_increase_version(version){
  return confirm('Tequki:\n„Stávající verze (v.'+version+') textu bude archivována a bude vytvořena nová verze (v.'+(version+1)+').\n\nOpravdu zvýšit verzi?\n\nStiskni OK [Enter] pro zvýšení nebo Zrušit [Esc] pro návrat');
}
function question_leave(){
  return confirm('Tequki:\n„Chcete se odhlásit. Tím ochráníte svůj účet před zneužitím.“\n\nPokračovat a odhlásit?\n\nStiskni OK [Enter] pro odhlášení nebo Zrušit [Esc] pro návrat');
}
function question_create_page(page){
  return confirm('Tequki:\n„Stránka '+page+' zatím neexistuje.“\n\nVytvořit?\n\nStiskni OK [Enter] pro vytvoření nebo Zrušit [Esc] pro návrat');
}

function finish_start(){
  $$('.LanguageSelector, .OtherManufacture, .Company .MenuItem .ItemLabel, h1, #Tower, .Footer, .PageContent').each(function(it){it.onmouseover=function(){ if (typeof(highlight)!='undefined') highlight(); }});
  $$('#LinkCasting > p, #LinkCasting > .ItemLabel').each(function(it){ it.onmouseover=function(){ if (typeof(highlight)!='undefined') highlight('Odlitky'); }});
  $$('#LinkCasting > p').each(function(it){ it.onclick=function(){ go('casting'); }});
  $$('#LinkFerro > p, #LinkFerro > .ItemLabel').each(function(it){ it.onmouseover=function(){ if (typeof(highlight)!='undefined') highlight('Zelezo'); }});
  $$('#LinkFerro > p').each(function(it){ it.onclick=function(){ go('casting/ferro'); }});
  $$('#LinkAluminium > p, #LinkAluminium > .ItemLabel').each(function(it){ it.onmouseover=function(){ if (typeof(highlight)!='undefined') highlight('Hlinik'); }});
  $$('#LinkAluminium > p').each(function(it){ it.onclick=function(){ go('casting/aluminium'); }});
  $$('#LinkCopper > p, #LinkCopper > .ItemLabel').each(function(it){ it.onmouseover=function(){ if (typeof(highlight)!='undefined') highlight('Med'); }});
  $$('#LinkCopper > p').each(function(it){ it.onclick=function(){ go('casting/copper'); }});
  $$('#LinkMachining > p, #LinkMachining > .ItemLabel').each(function(it){ it.onmouseover=function(){ if (typeof(highlight)!='undefined') highlight('Obroba'); }});
  $$('#LinkMachining > p').each(function(it){ it.onclick=function(){ go('machining'); }});
  $$('#LinkPatternshop > p, #LinkPatternshop > .ItemLabel').each(function(it){ it.onmouseover=function(){ if (typeof(highlight)!='undefined') highlight('Drevo'); }});
  $$('#LinkPatternshop > p').each(function(it){ it.onclick=function(){ go('patternshop'); }});
  $$('.Certification p, .Certification .Cert').each(function(it){ it.onmouseover=function(){ if (typeof(highlight)!='undefined') highlight('Cert'); }});
  $$('.ShortContact .Address').each(function(it){ it.onmouseover=function(){ if (typeof(highlight)!='undefined') highlight('Kontakt'); }; it.onclick=function(){ go('contact'); }});
  $$('.Certification p').each(function(it){ it.onclick=function(){ go('certification'); }});
  Event.observe(document,'keypress',key_press);
  $$('#SetupMessage').each(function(it){ it.appear({ duration: 0.5 }); });
  if (typeof(start_page)!='undefined') start_page();
  if (typeof(setup_auto_start)!='undefined') setup();
}


/*
==== funkce insertTagsTo_ ====
; Author: phpBB Team, WikiMedia, Maciej Jaros [[:pl:User:Nux]]
; Licence: [http://opensource.org/licenses/gpl-license.php GNU General Public License v2]
; Description: Apply tagOpen/tagClose to selection in given textarea/input, use sampleText instead of
 selection if there is none. Copied and adapted from phpBB
; Reused from cs.wikipedia.org
*/

function insertTagsTo_(tagOpen, tagClose, sampleText, outputid){
	var txtarea = document.getElementById(outputid);
	if (!txtarea)
		return;

	// IE
	if (document.selection  && !is_gecko) {
		var theSelection = document.selection.createRange().text;
		if (!theSelection)
			theSelection=sampleText;
		txtarea.focus();
		if (theSelection.charAt(theSelection.length - 1) == " ") { // exclude ending space char, if any
			theSelection = theSelection.substring(0, theSelection.length - 1);
			document.selection.createRange().text = tagOpen + theSelection + tagClose + " ";
		} else {
			document.selection.createRange().text = tagOpen + theSelection + tagClose;
		}

	// Mozilla
	} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
		var replaced = false;
		var startPos = txtarea.selectionStart;
		var endPos = txtarea.selectionEnd;
		if (endPos-startPos)
			replaced = true;
		var scrollTop = txtarea.scrollTop;
		var myText = (txtarea.value).substring(startPos, endPos);
		if (!myText)
			myText=sampleText;
		if (myText.charAt(myText.length - 1) == " ") { // exclude ending space char, if any
			subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
		} else {
			subst = tagOpen + myText + tagClose;
		}
		txtarea.value = txtarea.value.substring(0, startPos) + subst + txtarea.value.substring(endPos, txtarea.value.length);
		txtarea.focus();

		//set new selection
		if (replaced) {
			var cPos = startPos+(tagOpen.length+myText.length+tagClose.length);
			txtarea.selectionStart = cPos;
			txtarea.selectionEnd = cPos;
		} else {
			txtarea.selectionStart = startPos+tagOpen.length;
			txtarea.selectionEnd = startPos+tagOpen.length+myText.length;
		}
		txtarea.scrollTop = scrollTop;
	}

	// reposition cursor if possible
	if (txtarea.createTextRange)
		txtarea.caretPos = document.selection.createRange().duplicate();
}
