var ie = (/MSIE\s((5\.5)|[6789])/.test(navigator.userAgent)) && (navigator.platform == "Win32");
var ie5 = /MSIE 5\.0/.test(navigator.userAgent) && navigator.platform == "Win32";
var flash = false;
var plugin;
var version = 6;
var body_w = document.body.clientWidth;

if (navigator.plugins) {
	if (navigator.plugins["Shockwave Flash"]) {
		plugin = navigator.plugins["Shockwave Flash"].description;
                flash = parseInt(plugin.match(/\d+/)[0]) >= version;
	} else {
		if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1))
		{
			var vb = '<script language="vbscript">\n'
				+ '  on error resume next\n'
				+ '  flash = IsObject(CreateObject('
				+ '     "ShockwaveFlash.ShockwaveFlash.' + version + '"))\n'
				+ '<' + '/script>';
			document.write(vb);
		}
	}
}

function escape2(s) {
  return escape(s).replace(/%/g, '!');
}

function putMessage(flash_file, img, txt, w, h, preset, reply){
 if(flash){
  document.write('\
   <div style="float: left;">\
    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+w+'" height="'+h+'" align="left">\n\
    <param name="allowScriptAccess" value="sameDomain" />\n\
    <param name="movie" value="'+flash_file+'.swf" />\n\
    <param name="FlashVars" value="img='+img+'&txt='+escape2(txt)+'&w='+w+'&h='+h+'&preset='+(preset||0)+(reply ? '&reply='+escape2(reply) : '')+'" />\n\
    <param name="menu" value="false" />\n\
    <param name="wmode" value="transparent" />\n\
    <param name="salign" value="l" />\n\
    <param name="scale" value="noscale" />\n\
    <param name="quality" value="high" />\n\
    <param name="bgcolor" value="#204651" />\n\
    <embed src="'+flash_file+'.swf" FlashVars="img='+img+'&txt='+escape2(txt)+'&w='+w+'&h='+h+'&preset='+(preset||0)+(reply ? '&reply='+escape2(reply) : '')+'" menu="false" scale="noscale" salign="l" quality="high" wmode="transparent" bgcolor="#204651" width="'+w+'" height="'+h+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n\
    </object>\n\
   </div>\
');

 }else{

  document.write('<p>'+txt+'</p>');

 }
}


function putFlash(flash_file, img_file, w, h, bgcolor){
 if(flash){
  document.write('\
   <table width="'+w+'" height="'+h+'" border="0" cellspacing="0" cellpadding="0"><tr><td>\
    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+w+'" height="'+h+'" align="left">\
    <param name="allowScriptAccess" value="sameDomain" />\
    <param name="movie" value="'+flash_file+'.swf" />\
    <param name="FlashVars" value="lang='+lang+'" />\n\
    <param name="menu" value="false" />\
    <param name="wmode" value="transparent" />\
    <param name="salign" value="l" />\
    <param name="quality" value="high" />\
    <param name="bgcolor" value="#'+bgcolor+'" />\
    <embed src="'+flash_file+'.swf" FlashVars="lang='+lang+'" menu="false" salign="l" quality="high" wmode="transparent" bgcolor="#'+bgcolor+'" width="'+w+'" height="'+h+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\
    </object>\
   </td></tr></table>\
');

 }else{

  document.write('<img src="'+img_file+'" width="'+w+'" height="'+h+'">');

 }
}

function png(id, src_png, src_gif){  
	image = document.getElementById(id);
	if (ie5) {image.src = src_gif;}
	else {
		if(!ie){image.src = src_png;}
		else {
			image.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" +  src_png + "',sizingMethod='image')"
		}
	}
	return 1;
}


function flickElement() {
 if(!elementToFlick) return;
 var t, e = elementToFlick;
 if (e.inFlick) {
  if (e.flTime > 0) {
   e.isOn = !e.isOn;
   t = Math.round(e.flSwitchTime*Math.random());
   e.flTime -= t }
  else {
   e.inFlick = false;
   e.isOn = true;
   t = Math.round(e.onMaxTime*1000*Math.random());
  } }
 else {
  e.inFlick = true;
  e.flTime = Math.round(e.flMaxTime*1000*Math.random());
  e.isOn = true;
  t = 0;
 }
 e.style.visibility = (e.isOn ? 'visible' : 'hidden');
 setTimeout('flickElement()', t);
}

function invertDisplay(id){
 var current = document.getElementById(id);
 current.style.display = current.style.display != "block" ? "block" : "none";
}

function fade(id, kuda, firstDelay, step, delay) {
 var element = document.getElementById(id);
 if (!element) return;
 if (element.style.display == 'none'){element.style.display = ''};
 if (element.timeoutId) clearTimeout(element.timeoutId);
 element.fadeValue = (kuda == 'in' ? 0 : 1);
 if (typeof(element.style.filter) != 'undefined')
  element.style.filter = 'alpha(opacity='+(element.fadeValue*100)+')'
 else if (typeof(element.style.opacity) != 'undefined')
  element.style.opacity = element.fadeValue
 else {
  element.style.visibility = (kuda == 'in' ? 'visible' : 'hidden');
  return;
 }
 element.fadeStep = (kuda == 'in' ? 1 : -1) * (step || 0.25);
 element.fadeDelay = (delay || 50);
 element.style.visibility = 'visible';
 element.timeoutId = setTimeout('stepFade("'+id+'")', firstDelay*1000);
}

function stepFade(id) {
 var element = document.getElementById(id);
 if (!element) return;
 element.fadeValue += element.fadeStep;
 if (element.fadeValue > 1) element.fadeValue = 1
 else if (element.fadeValue < 0) element.fadeValue = 0;

 if (typeof(element.style.filter) != 'undefined') 
  element.style.filter = 'alpha(opacity='+(element.fadeValue*100)+')'
 else 
  element.style.opacity = element.fadeValue;

 if (0 < element.fadeValue && element.fadeValue < 1){
  element.timeoutId = setTimeout('stepFade("'+id+'")', element.fadeDelay);
// }else{
//  if(element.fadeStep<0 && element.fadeValue == 0){alert(element.fadeStep);element.style.display = 'none';};
 }
}


function inputText (input, dft_value, cssFilled, cssEmpty){
	var thisCopy = this;
	this.Input = input;
	this.dft_Value = dft_value;
	this.CssFilled = cssFilled;
	this.CssEmpty = cssEmpty;

	this.setupEvent (this.Input, 'focus', function() {return thisCopy.onFocus()});
	this.setupEvent (this.Input, 'blur',  function() {return thisCopy.onBlur()});
	this.setupEvent (this.Input, 'keydown', function() {return thisCopy.onKeyDown()});

    if (input.value == dft_value) this.onBlur()
    return this
}

inputText.prototype.setupEvent = function (elem, eventType, handler) {
	if (elem.attachEvent){elem.attachEvent ('on' + eventType, handler)} //IE
	if (elem.addEventListener){elem.addEventListener (eventType, handler, false)} //DOM
}

inputText.prototype.onFocus = function() {
	if (this.Input.value == this.dft_Value) {this.Input.value = ''}
	else {this.Input.className = 'full'}
}

inputText.prototype.onKeyDown = function() {this.Input.className = 'full'}

inputText.prototype.onBlur = function() {
	if (this.Input.value == '' || this.Input.value == this.dft_Value)
	{
		this.Input.value = this.dft_Value;
		this.Input.className = this.CssEmpty
	}
	else {this.Input.className = ''}
}

function resize(){
 body_w = document.body.clientWidth;
 setDelimiter();
}


//---------------------------------------------------
//Lipka, v. 1.1
function hint(){
 var obj = this;

 var elem = document.createElement("DIV");
 document.body.appendChild(elem);
 var attr = document.createAttribute('id'); attr.value = 'hint'; elem.setAttributeNode(attr);
 obj.hint_container = elem;

 this.show = function(message) {

  obj.hint_container.innerHTML='<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td><b></b><div>'+message+'</div><b></b></td></tr></table>';

  document.onmousemove = function (e){

   var ie = document.all ? true : false;
   var x = ie ? document.body.scrollLeft + window.event.clientX : e.pageX;
   var y = ie ? document.body.scrollTop + window.event.clientY : e.pageY;

   obj.hint_container.style.left = document.body.clientWidth - x >= obj.hint_container.clientWidth ? x : x-obj.hint_container.clientWidth + 16 ;
   obj.hint_container.style.top = y+20; //document.body.clientHeight - y >= obj.hint_container.clientHeight ? y+20 : y-obj.hint_container.clientHeight - 16;
  }
  fade('hint', 'in');
//  obj.hint_container.style.display='block';
 }

 this.hide = function() {
//  fade('hint', 'out');
//  setTimeout('document.getElementById("hint").style.display="none"', 100);
  obj.hint_container.style.display='none';
 }

};

var hint = new hint();
