
/* JS: mod_login_main*/
function mod_login_on_submit() {
	var form;
	if (form = document.getElementById('form_id_login')) {
		var inputs = form.elements;	var err = '';
		for (var i = 0; i < inputs.length; i++) {
			if ((inputs[i].name == 'ed_login') && (inputs[i].value == '')) {
				err = err + "Zadejte uživatelské jméno.";
			}
			if ((inputs[i].name == 'ed_password') && (inputs[i].value == '')) {
				err = err + "Zadejte heslo.";
			}
		}
		if (err != '') {alert(err);	return false;} else {return true;}
	}
}

/* JS: new_window*/

function openwin(elm, isImage) {

    if (!isImage) {
      window.open(elm.getAttribute("href"), "_blank");
      return true;
    }


    var msgWindow = window.open(elm.getAttribute("href"), "_blank", "toolbar=no");
    msgWindow.document.write("<?xml version='1.0' encoding='UTF-8' standalone='yes'?>");
    msgWindow.document.write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>");
    msgWindow.document.write("<html>");
    msgWindow.document.write("<meta http-equiv='content-type' content='text/html; charset=utf-8'>");
    msgWindow.document.write("<head>");
    msgWindow.document.write("<title>Obrázek</title>");
    msgWindow.document.write("<style media='screen,tv,projection' type='text/css'> html, body {margin:0;padding:0} a, img {border: 0px solid #fff}</style>");
    msgWindow.document.write("<script type='text/javascript'>");
    msgWindow.document.writeln("    function getInnerHeight() { ");
    msgWindow.document.writeln("           if (window.innerHeight) {");
    msgWindow.document.writeln("             return window.innerHeight;");
    msgWindow.document.writeln("           } else {");
    msgWindow.document.writeln("             return document.documentElement.offsetHeight;"); // document.body.clientHeight;
    msgWindow.document.writeln("           }");
    msgWindow.document.writeln("    }");
    msgWindow.document.writeln("    function getInnerWidth() { ");
    msgWindow.document.writeln("           if (window.innerWidth) {");
    msgWindow.document.writeln("             return window.innerWidth;");
    msgWindow.document.writeln("           } else {");
    msgWindow.document.writeln("             return document.documentElement.offsetWidth;"); //document.body.clientWidth;
    msgWindow.document.writeln("           }");
    msgWindow.document.writeln("    }");
    msgWindow.document.writeln("    function imgSize(controlHeight,fotoMargin) {");
    msgWindow.document.writeln("      image=document.getElementById('image_elm');");
    msgWindow.document.writeln("      if (screen.height <= (image.height + 31)) {");
    msgWindow.document.writeln("        window.resizeTo(image.width + 12,screen.height - 100);");
    msgWindow.document.writeln("      } else {");
    msgWindow.document.writeln("        window.resizeTo(image.width+2*fotoMargin,image.height+controlHeight+fotoMargin);");
    msgWindow.document.writeln("        controlx = image.width+2*fotoMargin - getInnerWidth();");
    msgWindow.document.writeln("        controly = image.height+controlHeight+fotoMargin - getInnerHeight();");
    msgWindow.document.writeln("        window.resizeTo(image.width + controlx+2*fotoMargin, image.height + controly+controlHeight+fotoMargin);");
    msgWindow.document.writeln("      }");
    msgWindow.document.writeln("    }");
    msgWindow.document.write("</script>");
    msgWindow.document.write("</head>");
    msgWindow.document.write("<body style='margin:0;padding:0;background:#fff' onload='imgSize(0,0);'>");
    msgWindow.document.write("<a style='border:0px solid #fff;' href='#' onclick='window.close();'><img src='"+elm.getAttribute("href")+"' style='border:0px solid #fff;' id='image_elm' alt=''></a>");
    msgWindow.document.write("</body>");
    msgWindow.document.write("</html>");
    msgWindow.document.close();
    msgWindow.focus();
    return true;
}

function open_win_external(elm) {
    window.open(elm.getAttribute("href"), "_blank");
    return true;
}

/* JS: superfish*/

/*
 * Superfish v1.4.8 - jQuery menu widget
 * Copyright (c) 2008 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 *
 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
 */

;(function($){
	$.fn.superfish = function(op){

		var sf = $.fn.superfish,
			c = sf.c,
			$arrow = $(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),
			over = function(){
				var $$ = $(this), menu = getMenu($$);
				clearTimeout(menu.sfTimer);
				$$.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function(){
				var $$ = $(this), menu = getMenu($$), o = sf.op;
				clearTimeout(menu.sfTimer);
				menu.sfTimer=setTimeout(function(){
					o.retainPath=($.inArray($$[0],o.$path)>-1);
					$$.hideSuperfishUl();
					if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}
				},o.delay);	
			},
			getMenu = function($menu){
				var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0];
				sf.op = sf.o[menu.serial];
				return menu;
			},
			addArrow = function($a){ $a.addClass(c.anchorClass).append($arrow.clone()); };
			
		return this.each(function() {
			var s = this.serial = sf.o.length;
			var o = $.extend({},sf.defaults,op);
			o.$path = $('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){
				$(this).addClass([o.hoverClass,c.bcClass].join(' '))
					.filter('li:has(ul)').removeClass(o.pathClass);
			});
			sf.o[s] = sf.op = o;
			
			$('li:has(ul)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {
				if (o.autoArrows) addArrow( $('>a:first-child',this) );
			})
			.not('.'+c.bcClass)
				.hideSuperfishUl();
			
			var $a = $('a',this);
			$a.each(function(i){
				var $li = $a.eq(i).parents('li');
				$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
			});
			o.onInit.call(this);
			
		}).each(function() {
			var menuClasses = [c.menuClass];
			if (sf.op.dropShadows  && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
			$(this).addClass(menuClasses.join(' '));
		});
	};

	var sf = $.fn.superfish;
	sf.o = [];
	sf.op = {};
	sf.IE7fix = function(){
		var o = sf.op;
		if ($.browser.msie && $.browser.version > 6 && o.dropShadows && o.animation.opacity!=undefined)
			this.toggleClass(sf.c.shadowClass+'-off');
		};
	sf.c = {
		bcClass     : 'sf-breadcrumb',
		menuClass   : 'sf-js-enabled',
		anchorClass : 'sf-with-ul',
		arrowClass  : 'sf-sub-indicator',
		shadowClass : 'sf-shadow'
	};
	sf.defaults = {
		hoverClass	: 'sfHover',
		pathClass	: 'overideThisToUse',
		pathLevels	: 1,
		delay		: 800,
		animation	: {opacity:'show'},
		speed		: 'normal',
		autoArrows	: true,
		dropShadows : true,
		disableHI	: false,		// true disables hoverIntent detection
		onInit		: function(){}, // callback functions
		onBeforeShow: function(){},
		onShow		: function(){},
		onHide		: function(){}
	};
	$.fn.extend({
		hideSuperfishUl : function(){
			var o = sf.op,
				not = (o.retainPath===true) ? o.$path : '';
			o.retainPath = false;
			var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
					.find('>ul').hide().css('visibility','hidden');
			o.onHide.call($ul);
			return this;
		},
		showSuperfishUl : function(){
			var o = sf.op,
				sh = sf.c.shadowClass+'-off',
				$ul = this.addClass(o.hoverClass)
					.find('>ul:hidden').css('visibility','visible');
			sf.IE7fix.call($ul);
			o.onBeforeShow.call($ul);
			$ul.animate(o.animation,o.speed,function(){ sf.IE7fix.call($ul); o.onShow.call($ul); });
			return this;
		}
	});

})(jQuery);

/* JS: init*/
jQuery().ready(function(){


if($(".mod_form_errs").length > 0 && $("#contact_form").length > 0){
	$("#contact_form").fadeIn("slow");
}
		
		$('ul.sf-menu').superfish({ 
			delay:       100,                            // one second delay on mouseout 
			speed:       'normal',                          // faster animation speed 
			autoArrows:  false,                           // disable generation of arrow mark-up 
			dropShadows: false                            // disable drop shadows 
		}); 
		
$(".sf-menu li").mouseenter(function(){
	$(this).addClass("sfHover");
}).mouseleave(function(){
	$(this).removeClass("sfHover");
});

		// $(".content_class5").each(function(){$(this).addClass('lightBox')});
		
		$("img.content_class35").parent().lightBox();
		
		$("#ed_predmet").val('');
		
		$("a.order").click(function(){
			
			$("#contact_form").fadeIn("slow");
			
			var subjDefault = $("#ed_predmet").val();
			var subj = $(this).parent().parent().children("td.type").text();
			
			subjDefault == '' ? $("#ed_predmet").val(subj) : $("#ed_predmet").val(subjDefault + ", " + subj);
			return false;
		});

$(".list-of-documents th").css({background: "#ffcc00 url(/img/yellow-bg.gif) repeat-x top"});
$(".list-of-documents tr:nth-child(2) th").css({background: "#ffcc00"});

$("body.ac-dc-standard .list-of-documents th").css({background: "#ffcc00 url(/img/yellow-bg.gif) repeat-x top"});
$("body.ac-dc-standard .list-of-documents tr:nth-child(2) th").css({background: "#ffcc00"});

$("body.ac-dc-din .list-of-documents th").css({background: "#CC6633 url(/img/brown-bg.gif) repeat-x top", color: "#fff"});
$("body.ac-dc-din .list-of-documents tr:nth-child(2) th").css({background: "#CC6633", color: "#fff"});

$("body.ac-dc-nabijece .list-of-documents th, body.ac-dc-chargers .list-of-documents th, , body.ac-dc-ladegerate-zubehor .list-of-documents th").css({background: "#99CC33 url(/img/green-bg.gif) repeat-x top", color:"#fff"});
$("body.ac-dc-nabijece .list-of-documents tr:nth-child(2) th, body.ac-dc-chargers .list-of-documents tr:nth-child(2) th, body.ac-dc-ladegerate-zubehor .list-of-documents tr:nth-child(2) th").css({background: "#99CC33", color:"#fff"});

$("body.dc-dc-din .list-of-documents th").css({background: "#FF6633 url(/img/orange-bg.gif) repeat-x top", color:"#fff"});
$("body.dc-dc-din .list-of-documents tr:nth-child(2) th").css({background: "#FF6633", color:"#fff"});

$("body.menic-dc-dc-din .list-of-documents th").css({background: "#FF6633 url(/img/orange-bg.gif) repeat-x top", color:"#fff"});
$("body.menic-dc-dc-din .list-of-documents tr:nth-child(2) th").css({background: "#FF6633", color:"#fff"});

$("body.napajeci-systemy .list-of-documents th, body.power-system .list-of-documents th, body.netzeil-system .list-of-documents th,body.stromversorgungssysteme .list-of-documents th").css({background: "#339966 url(/img/dark-green-bg.gif) repeat-x top", color: "#fff"});
$("body.napajeci-systemy .list-of-documents tr:nth-child(2) th, body.power-system .list-of-documents tr:nth-child(2) th, body.netzeil-system .list-of-documents tr:nth-child(2) th,body.stromversorgungssysteme .list-of-documents tr:nth-child(2) th").css({background: "#339966", color: "#fff"});



$("body.vestavne-ac-dc .list-of-documents th, body.built-in-ac-dc .list-of-documents th, body.einbau-ac-dc .list-of-documents th").css({background: "#656598 url(/img/violet-bg.gif) repeat-x top", color: "#fff"});
$("body.vestavne-ac-dc .list-of-documents tr:nth-child(2) th, body.built-in-ac-dc .list-of-documents tr:nth-child(2) th, body.einbau-ac-dc .list-of-documents tr:nth-child(2) th").css({background: "#656598", color: "#fff"});

$("body.specialni-zdroje .list-of-documents th, body.special-sps .list-of-documents th, body.speciale-schaltnetzteile .list-of-documents th").css({background: "#00CCFF url(/img/azure-bg.gif) repeat-x top", color: "#fff"});
$("body.specialni-zdroje .list-of-documents tr:nth-child(2) th, body.special-sps .list-of-documents tr:nth-child(2) th, body.speciale-schaltnetzteile .list-of-documents tr:nth-child(2) th").css({background: "#00CCFF", color: "#fff"});

$("body.speziale-schaltnetzteile .list-of-documents th, body.special-sps .list-of-documents th, body.speciale-schaltnetzteile .list-of-documents th").css({background: "#00CCFF url(/img/azure-bg.gif) repeat-x top"});
$("body.speziale-schaltnetzteile .list-of-documents tr:nth-child(2) th, body.special-sps .list-of-documents tr:nth-child(2) th, body.speciale-schaltnetzteile .list-of-documents tr:nth-child(2) th").css({background: "#00CCFF"});


$("body.invertory .list-of-documents th, body.invertors .list-of-documents th, body.speciale-invertors .list-of-documents th").css({background: "#BD0775 url(/img/magenta-bg.gif) repeat-x top"});
$("body.invertory .list-of-documents tr:nth-child(2) th, body.invertors .list-of-documents tr:nth-child(2) th, body.invertors .list-of-documents tr:nth-child(2) th").css({background: "#BD0775"});



$(".list-of-documents th span").each(function(){
   var label = $(this).text();

if($(this).text().match(/EN - /)){
	$(this).text(label.replace(/EN - /, ""))
}

if($(this).text().match(/CS - /)){
	$(this).text(label.replace(/CS - /, ""))
}

if($(this).text().match(/DE - /)){
	$(this).text(label.replace(/DE - /, ""))
}

   //$(this).empty().text(label.replace(/DE - /, "")).text(label.replace(/CS - /, ""));

});

})
/* JS: mod_form_main*/
function validate_form(formular) {
  try {
    // kvuli captcha je zde skip_validation
	  if (skip_validation) {
		  return true;
	  }
	} catch(e) {
	
	var inputs = formular.elements;
    var error = -1; //-1 = OK, jinak index prvniho chybneho inputu
    var tp,val,errorMsg = "";
    for (var i = 0; i < inputs.length; i++) {
		if (inputs[i].nodeName.toLowerCase() == 'textarea') {
			tp = 'text';
		} else if (inputs[i].nodeName.toLowerCase() == 'select') {
			tp = 'select';
		} else {
			tp = inputs[i].type;
		}
		//nesmi se pouzit 2,n protoze zasrany zkurveny svine
		mailRegExp = new RegExp('^[^@]{2,}@[_a-zA-Z0-9\.\-]{2,}\.[a-zA-Z]{2,4}$');
    	switch (tp) {
			case 'checkbox':
				if (inputs[i].className.match('mandatory') && !inputs[i].checked) {
					if (error == -1) {error = i;}
					errorMsg += "Prosím vyplňte položku "+inputs[i].title+". \n";
				}
			case 'password':
			case 'file':
			case 'text':
				if (inputs[i].nodeName.toLowerCase() == 'textarea') {
				    val = inputs[i].innerHTML;
				} else {
				    val = inputs[i].value;
				}
				if (inputs[i].className.match('mandatory') && (inputs[i].value == '')) {
            		if (error == -1) {error = i;}
					errorMsg += "Prosím vyplňte položku "+inputs[i].title+". \n";
        		}
        		if (inputs[i].className.match('email') && (inputs[i].value != '') && (!inputs[i].value.match(mailRegExp))) {
					if (error == -1) {error = i;}
            		errorMsg += "Prosím vyplňte platný email "+"\n";
        		}
        		if (inputs[i].className.match('number') && (inputs[i].value != '') && (!inputs[i].value.match("^-{0,1}[0-9]*[.,]{0,1}[0-9]+$"))) {
					if (error == -1) {error = i;}
            		errorMsg += "Prosím vyplňte platné číslo "+"\n";
        		}
			case 'select':
			    if (inputs[i].className.match('mandatory') && (inputs[i].selectedIndex == 0)) {
            		if (error == -1) {error = i;}
					errorMsg += "Prosím vyplňte položku "+inputs[i].title+". \n";
				}
        }
    }
    if (error != -1) {
    	alert(errorMsg);
        inputs[error].focus();
        return false;
    } else {
		return true;
	}

	}
}

/* JS: mod_form_fill*/
//http://dean.edwards.name/weblog/2006/06/again/
// Dean Edwards/Matthias Miller/John Resig
function init() {
  // quit if this function has already been called
  if (arguments.callee.done) return;

  // flag this function so we don't do the same thing twice
  arguments.callee.done = true;

  // kill the timer
  if (_timer) clearInterval(_timer);

  // do stuff
  fillForm();
};

/* for Mozilla/Opera9 */
if (document.addEventListener) {
  document.addEventListener("DOMContentLoaded", init, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
  document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
  var script = document.getElementById("__ie_onload");
  script.onreadystatechange = function() {
    if (this.readyState == "complete") {
      init(); // call the onload handler
    }
  };
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
  var _timer = setInterval(function() {
    if (/loaded|complete/.test(document.readyState)) {
      init(); // call the onload handler
    }
  }, 10);
}

/* for other browsers */
window.onload = init;

// vycisti formular - zrusi vyber u checkboxu, radiobuttonu a optionu
function clearForm() {
  var inputs = document.getElementsByTagName('input');
  for(var i=0; i<inputs.length; i++) {
    if (inputs[i].form.id.indexOf('mod_form') != -1 && (inputs[i].type=='checkbox' || inputs[i].type=='radio'))
      inputs[i].checked = false;
  }
  var options = document.getElementsByTagName('option');
  for(var i=0; i<options.length; i++) {
    if (options[i].form.id.indexOf('mod_form') != -1)
      options[i].selected = false;
  }
}

// vyplni formular daty ulozenymi v hiddenech, ktere zacinaji _mod_form_fill_
function fillForm() {
  var inputs = document.getElementsByTagName('input');
  var count = 0;
  for (var i=0; i<inputs.length; i++) {
    // filtr hiddenu
    if (inputs[i].form.id.indexOf('mod_form') == -1 || inputs[i].type != 'hidden' ||
      inputs[i].name.indexOf('_mod_form_fill_') == -1)
      continue;
    
    // pri prvnim vyskytu spravneho hiddenu, promazeme formular
    if (!count++)
      clearForm();
    
    // nyni nam zustali jen potrebne hiddeny
    var elements = document.getElementsByName(inputs[i].name.substr(('_mod_form_fill_').length));
    var element = elements[0];
    switch(element.type) {
      case 'textarea':
        element.innerHTML = inputs[i].value; break;
      case 'text':
        element.value = inputs[i].value; break;
      case 'checkbox':
        element.checked = (inputs[i].value!='0' ? true : false); break;
      case 'radio':
        for (var j=0; j<elements.length; j++) {
          if (elements[j].value == inputs[i].value) {
            elements[j].checked = true;
            break;
          }
        }
        break;
      case 'select-one':
        var options = element.getElementsByTagName('option');
        for (var j=0; j<options.length; j++) {
          if (options[j].value == inputs[i].value) {
            options[j].selected = true;
            break;
          }
        }
        break;
      default:
    }
  }
}

