window.onload = function() {
	addTB();
	addTNlinks();
	initNav();
	eolas();
}

// CSS (if JavaScript is enabled)
function writeJSstyle(){
	document.write('<link rel="stylesheet" type="text/css" media="screen" href="css/azplastik-js.css" />');
}

function addTNlinks() {
	if(getEl('map-trade-network')) {
		var mapLinks = getEl('map-trade-network').getElementsByTagName('area');
		for(var i=0;i<mapLinks.length;i++) {
			mapLinks[i].onmouseover=function() {
				var layerName=this.id+'-layer';
				setVV(layerName);
				getEl(layerName).onmouseover=function() {
					setVV(layerName);
					cancelBublle=true;
				}
				getEl(layerName).onmouseout=function() {
					setVH(layerName);
				}
			}
			mapLinks[i].onmouseout=function() {
				var layerName=this.id+'-layer';
				setVH(layerName);
			}
		}
	}
}

var timers=new Array();
var menuFall=20;
function initNav() {
	if(browser.isIE) {
		var menuElements=getEl('mnu').getElementsByTagName("ul");
		for(var i=0;i<menuElements.length;i++) {
			menuElements[i].parentNode.parentNode.onmouseover=function() {
				if(timers[this.lastChild.id]) clearTimeout(timers[this.lastChild.id]);
				setVVObj(this.lastChild);
				this.firstChild.lastChild.style.backgroundPosition="0px -46px";
			}

			menuElements[i].parentNode.parentNode.onmouseout=function() {
				timers[this.lastChild.id]=setTimeout('setVH("'+this.lastChild.id+'");var liEl=getEl("'+this.id+'");liEl.firstChild.lastChild.style.backgroundPosition="0px 0px"',menuFall);
			}
		}
	}
}

function isMail(mail){
  var mailre=/^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$/;
  return mailre.test(mail);
}

function reVal(el){
  if(trim(el.value)!="")el.style.backgroundImage="url('images/layout/backgrounds/bg-input.gif')";
}

function checkFrm(f){

	 var emptys=new Array();
	 var invalids=new Array();

	 if(f.id=="form_order") {

		if(trim(f.f_name.value)=="")emptys[emptys.length]=new Array(f.f_name,"Jméno, příjmení");
		if(trim(f.f_email.value)=="") {
			emptys[emptys.length]=new Array(f.f_email,"Email");
		} else {
			if(!isMail(trim(f.f_email.value)))invalids[invalids.length]=new Array(f.f_email,"Email");
		}
		if(trim(f.f_phone.value)=="")emptys[emptys.length]=new Array(f.f_phone,"Telefon");
		if(trim(f.f_street.value)=="")emptys[emptys.length]=new Array(f.f_street,"Adresa");
		if(trim(f.f_city.value)=="")emptys[emptys.length]=new Array(f.f_city,"Město");
		if(trim(f.f_zipcode.value)=="")emptys[emptys.length]=new Array(f.f_zipcode,"PSČ");
		if(!f.f_agree.checked)emptys[emptys.length]=new Array(f.f_agree,"Souhlas s obchodními podmínkami");

	 }

	 if(f.id=="form_contacts") {

		if(trim(f.f_name.value)=="")emptys[emptys.length]=new Array(f.f_name,"Jméno, příjmení");
		if(trim(f.f_phone.value)=="")emptys[emptys.length]=new Array(f.f_phone,"Telefon");
		if(trim(f.f_email.value)=="") {
			emptys[emptys.length]=new Array(f.f_email,"Email");
		} else {
			if(!isMail(trim(f.f_email.value)))invalids[invalids.length]=new Array(f.f_email,"Email");
		}
		if(trim(f.f_text.value)=="")emptys[emptys.length]=new Array(f.f_text,"Text");

	}


	if(emptys.length>0 || invalids.length>0){
		var alrt="";
		if(emptys.length>0){
			alrt+="Následující položky nebyly vyplněny:\n\n";
			for(var i=0;i<emptys.length;i++){
				alrt+=emptys[i][1]+"\n";
				if(emptys[i][0].id!="f_agree")emptys[i][0].style.backgroundImage="url('images/layout/crumbs/exclamation-mark.gif')";
			}
		}

		if(invalids.length>0){
			alrt+=(emptys.length>0?"\n\n":"")+"Nasledujici položky nebyly správně vyplněny:\n\n";
			for(var i=0;i<invalids.length;i++){
				alrt+=invalids[i][1]+"\n";
				invalids[i][0].style.backgroundImage="url('images/layout/crumbs/exclamation-mark.gif')";
			}
		}

		alert(alrt);
		return false;
	} else {
		return true;
	}
}

function setWinSize() {
	var padVer=86;
	var padHor=86;
	var wi=getEl('detail').width;
	var he=getEl('detail').height;
	var wL = (screen.width-wi) / 2;
	var wT = (screen.height-he) / 2;
	//window.resizeTo(wi+padVer,he);
	window.resizeBy((wi+padVer)-winW(),(he+padHor)-winH());
	window.moveTo(wL,wT);
}

var eolas=function(){
if(getEl("intro")) {
	getEl("intro").innerHTML='<object type="application/x-shockwave-flash" data="swf/intro.swf" width="499" height="157"><param name="movie" value="swf/intro.swf" /><param name="wmode" value="opaque" /></object>';
	setDBObj(getEl("intro").firstChild);
}
}

