/************************************************************************************/
//zmienne globalne do slideshow
slideShow_pokaz    = true;
slideShow_czas     = 5000;
slideShow_aktualny = 0;
slideShow_timer = null;

/************************************************************************************/
function slideShow(typ, link_od, link_do, ilosc) {

      if (slideShow_pokaz) {
            slideShow_aktualny++;

            if (slideShow_aktualny > link_do || slideShow_aktualny < link_od) {
                     slideShow_aktualny = link_od;
            }

		if (typ == 'news')  {
            	pokazNews(slideShow_aktualny, ilosc);
            } else if (typ == 'produkt') {
//            	pokazProdukt(slideShow_aktualny, ilosc);
            }
      }

      slideShow_timer = window.setTimeout("slideShow('" + typ + "', '" + link_od + "', '" + link_do + "', '" + ilosc + "')", slideShow_czas);
}
/************************************************************************************/
function slideShowPause(pauza) {

     slideShow_pokaz = !pauza;
     slideShow_aktualny = 0;
}
/************************************************************************************/
function updateForm(){
	var obj = document.getElementById('section');
	if (obj != null)	{
		document.getElementById('section').value = 'update';
	}
}
/************************************************************************************/
function checkEmail (email) {
      invalid = " /:,;";
      if (email=="") { return false }
      for (i=0; i<invalid.length; i++) {
        bad = invalid.charAt(i);
        if (email.indexOf (bad, 0) != -1) { return false }
      }
      at = email.indexOf ("@", 0);
      if ((at == -1) || (at == 0)) { return false }
      if (email.indexOf ("@", at+1) != -1) { return false }
      period = email.indexOf (".", at);
      if ((period == -1) || (period == at+1)) { return false }
	  znak = email.charAt(email.length - 1);
      if (znak ==  ".") { return false }
      at = email.indexOf (".",email.length - 4);
      if (at == -1) { return false };
      return true;
}
/************************************************************************************/
function zapisz(form,msg) {
	if (!(checkEmail(form.email.value))) {
		alert(msg);
		form.email.focus();
		form.email.select();
		return false;
	}
	else {
		return true;
	}
}
/************************************************************************************/
function zapiszCustomer(form,msg) {
	var ifNewsletter = form.newsletter.checked;

	if (ifNewsletter) {
		if (!(checkEmail(form.email.value))) {
			alert(msg);
			form.email.focus();
			form.email.select();
			return false;
		} else {
			return true;
		}
	} else {
		if (!(checkCustomerEmail(form.email.value))) {
			alert(msg);
			form.email.focus();
			form.email.select();
			return false;
		} else {
			return true;
		}
	}
}
/************************************************************************************/
function checkCustomerEmail (email) {
      invalid = " /:,;";
      if (email=="") { return true }
      for (i=0; i<invalid.length; i++) {
        bad = invalid.charAt(i);
        if (email.indexOf (bad, 0) != -1) { return false }
      }
      at = email.indexOf ("@", 0);
      if ((at == -1) || (at == 0)) { return false }
      if (email.indexOf ("@", at+1) != -1) { return false }
      period = email.indexOf (".", at);
      if ((period == -1) || (period == at+1)) { return false }
	  znak = email.charAt(email.length - 1);
      if (znak ==  ".") { return false }
      at = email.indexOf (".",email.length - 4);
      if (at == -1) { return false };
      return true;
}
/************************************************************************************/
function sendOpinion(nazwa,msg) {
	//czy zaznaczono odpowiedz w sondzie

	// czy po nazwie czy po wskazniku
	if (document.forms[nazwa]) {
		form = document.forms[nazwa];
	} else {
		form = nazwa;
	}

	var key = 0;
	for (var i = 0; i < form.my_opinion.length; i++){
		if (form.my_opinion[i].checked){
			key = form.my_opinion[i].value;
			break;
		}
	}

	if (key == 0) {
		alert(msg);
		return false;
	} else {
		if (key == form.klucz.value) {
//			form.action.value = "form";
		} else {
//			form.set.value = "tak";
		}
	}

	return true;
}
/************************************************************************************/
function submitForm(name){
	if (document.forms[name])   {
		document.forms[name].submit();
	}
}
/************************************************************************************/
function submitSelectForm(name, sel){
	if (document.forms[name])   {
		document.forms[name].selection.value = sel;
		document.forms[name].submit();
	}
}
/************************************************************************************/
function maillist(setmail){
	var obj = document.getElementById('newsmail');
	if(obj != null)	{
		document.getElementById('newsmail').value = setmail;
	}
}
/************************************************************************************/
function displayDivList(name,id, maxid) {

	for (var i = 0; i <= maxid; i++){
		div = document.getElementById(name + i);
		if(div != null)	{
			div.style.display = (i == id) ? "block" : "none";
		}
	}
}
/************************************************************************************/
function changeStyle(name,id, maxid) {
return;  
	for (var i = 0; i <= maxid; i++){
		link = document.getElementById(name + i);
		if(link != null)	{
			link.className = (i == id) ? "path_actual" : "path";
		}
	}
}
/************************************************************************************/
function displayMenuBox(id, maxid) {
	var browser = navigator.userAgent.toLowerCase();
	var isIE = ((browser.indexOf("msie") != -1) && (browser .indexOf( "opera" ) == -1) && (browser .indexOf( "webtv" ) == -1));
	if (!isIE) {return;}
	div = document.getElementById("menu" + id);
	if(div != null && div.style.display == "block") {
		return;
	}
	for (var i = 1; i <= maxid; i++){
		div = document.getElementById("menu" + i);
		if(div != null)	{
			div.style.display = (i == id) ? "block" : "none";
		}
	}
}
/************************************************************************************/
function hideMenuBox(id) {
	var browser = navigator.userAgent.toLowerCase();
	var isIE = ((browser.indexOf("msie") != -1) && (browser .indexOf( "opera" ) == -1) && (browser .indexOf( "webtv" ) == -1));
	if (!isIE) {return;}
	div = document.getElementById("menu" + id);
	if (div != null)	{
		div.style.display = "none";
	}
}
/************************************************************************************/
function checkSelect(maxid) {
	list = document.getElementById('sections');

	for (var i = 0; i < list.length; i++) {
		if (list.options[i].selected == true && i != list.selectedIndex) {
			list.options[i].selected = false;
		}
	}
	id = list.options[list.selectedIndex].value;

	displayDivList('productdesc',id, maxid);

}
/************************************************************************************/
function newsSelect(maxid, section, gr) {

	linker = "index.php?action=news&section=" + section;

	if (gr != '') {
		linker = linker + "&gr" + gr;
	}

	list = document.getElementById('sections');
	id = list.options[list.selectedIndex].value;

	linker = linker + "&news_id=" + id;

	window.location = linker;
}
/************************************************************************************/
function odswiezObject() {
	objects = document.getElementsByTagName("object");
	for (var i = 0; i < objects.length; i++)
	{
		objects[i].outerHTML = objects[i].outerHTML;
	}
}
/************************************************************************************/
function clearInput(name, text) {
	input = document.getElementById(name);
	if (input != null)	{
		if (input.value == text) {
			input.value = '';
		}
	}
}
/************************************************************************************/
//nowe funkcje
/************************************************************************************/
function showF(frag)
{

	var d;
	for(i = 1 ; i <= 5; i++) {

//		if ((d = document.getElementById('fragment-'+i))
//		 &&  (x = document.getElementById('div'+i))	)	{
		if (d = document.getElementById('fragment-'+i)) {
			if(i == frag) {
				d.className = 'showRF';
//				x.className = 'm_over';
			}
			else
			{
				d.className = 'hideRF';
//				x.className = 'm_out';
			}
		
		}
	}
}
/************************************************************************************/
function UpdateTimer() {
   if(timerID) {
      clearTimeout(timerID);
      clockID  = 0;
   }

   if(timer % timeout == 0)
   {
   	showF(active%realmod + 1);
   	active++;
   }
   
   timer++;

	timerID  = setTimeout("UpdateTimer()", 1000);
}
/************************************************************************************/
function UpdateTimer_old() {
   if(timerID) {
      clearTimeout(timerID);
      clockID  = 0;
   }

   if (!tStart) {
      tStart   = new Date();
   } else {
   }

   var   tDate = new Date();
   var   tDiff = tDate.getTime() - tStart.getTime();

   tDate.setTime(tDiff);

   if(tDate.getSeconds() % timeout == 0)
   {
   	showF(active%realmod + 1);
   	active++;
   }
   
   timerID = setTimeout("UpdateTimer()", 1000);
}
/************************************************************************************/
function Start() {
   tStart   = new Date();
   timerID  = setTimeout("UpdateTimer()", 1000);
}
/************************************************************************************/
function Stop() {
   if(timerID) {
      clearTimeout(timerID);
      timerID  = 0;
   }

   tStart = null;
   active = 0;

}
/************************************************************************************/
function Reset() {
   tStart = null;
}
/************************************************************************************/
function pokazNews(nr,ilosc) {

	for(i = 1 ; i <= ilosc; i++) {
	      div = document.getElementById("newsdesc_" + i);
	      if (div != null) {
		div.className = (i == nr) ? "news_on" : "news_off";
              }

	      div = document.getElementById("newstitle_" + i);
	      if (div != null) {
		div.className = (i == nr) ? "news_on2" : "news_off2";
              }

	      a = document.getElementById("newsheader_" + i);
	      if (a != null) {
		a.className = (i == nr) ? "news_on" : "news_off";
              }
        }
}
/************************************************************************************/
function pokazProdukt(nr,ilosc) {

	for(i = 1 ; i <= ilosc; i++) {
	      div = document.getElementById("productdesc_" + i);
	      if (div != null) {
		div.className = (i == nr) ? "product_on" : "product_off";
              }

	      div = document.getElementById("producttitle_" + i);
	      if (div != null) {
		div.className = (i == nr) ? "news_on2" : "news_off2";
              }

	      a = document.getElementById("productheader_" + i);
	      if (a != null) {
		a.className = (i == nr) ? "news_on" : "news_off";
              }
        }
}
/************************************************************************************/
function nawigacjaNews(link_od,link_do,ilosc) {
	for(i = 1 ; i <= ilosc; i++) {
	      div = document.getElementById("newsnavigator_" + i);
	      if (div != null) {
		div.style.display = (i == link_od) ? "block" : "none";
              }
	      div = document.getElementById("newsgroup_" + i);
	      if (div != null) {
		div.style.display = (i == link_od) ? "block" : "none";
              }
        }
//        pokazNews(link_od, ilosc);
          slideShowPause(false);
          if(slideShow_timer != null) {
              clearTimeout(slideShow_timer);
          }
          slideShow(link_od, link_do, ilosc);
}
/************************************************************************************/
function zmianaSelect(nazwa, podnazwa) {
	select	= document.getElementById(nazwa + "_id");
	if (select ==  null) {return;}
	id	= select.options[select.selectedIndex].value;

	ile = select.length;
	for (i = 0; i < ile; i++) {
		val	= select.options[i].value;
		pokazDiv(nazwa + "div_" + val, val == id);
	}

        if (podnazwa != '') {
           zmianaSelect(podnazwa + "_" + id,'');
        }
}
/************************************************************************************/
function pokazDiv(nazwa, warunek) {
	div	= document.getElementById(nazwa);
	if (div != null) {
		div.style.display = (warunek) ? "block" : "none";
	}
}
/************************************************************************************/
function ustawKontakt(adres) {

	email	= document.getElementById("office");
	email.value = adres;

	select	= document.getElementById("department_id");
	if (select ==  null) {return;}
	id = select.options[select.selectedIndex].value;

	select	= document.getElementById("employee_" + id + "_id");
	if (select ==  null) {return;}
//	adres = select.options[select.selectedIndex].value;
        adres = '';
	employee = select.options[select.selectedIndex].value;
        separator = employee.indexOf ("_", 0);
        if (separator != -1) {
           adres = employee.substring(separator + 1);
        }

        if (adres != '' && checkEmail(adres)) {
	   email.value = adres;
        }
}
/************************************************************************************/
function wyslijPytanie(form,msg) {
	if (form.c_email.value == '' || !(checkEmail(form.c_email.value))) {
		alert(msg);
		form.c_email.focus();
		form.c_email.select();
		return false;
	}
	else {
		return true;
	}
}
/************************************************************************************/
function flashMovie(nr, movie, width, height, version, quality, menu, bgcolor, transparent, flashvars) {

src = "movie/tece.swf?flv=" + movie + ".flv&id=" + nr;
	document.write("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="+version+",0,0,0' width='" +width+ "' height='" +height+ "' id='" + nr + "'>");
	document.write("<param name='movie' value='" +src+ "' />");
	document.write("<param name='FlashVars' value='" +flashvars+ "'>");
	document.write("<param name='quality' value='" +quality+ "' />");
	document.write("<param name='wmode' value='" +transparent+ "' />");
	document.write("<param name='menu' value='" +menu+ "' />");
	document.write("<param name='bgcolor' value='" +bgcolor+ "' />");
	document.write("<embed src='" +src+ "' wmode='" +transparent +"' swLiveConnect='true' menu='" +menu+ "' FlashVars='" +flashvars+ "' quality='" +quality+ "' bgcolor='" +bgcolor+ "' width='" +width+ "' height='" +height+ "' name='" +movie+ "' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />");
	document.write("</object>");
}
/************************************************************************************/
function showMovie(movie) {
	show = document.getElementById(movie);
	if (show == null) {return;}

	show.style.display = "inline";
	show.style.visibility = "visible";
}
/************************************************************************************/
function hideMovie(movie) {
	//chwilowo nieuzywana
	return;
	show = document.getElementById(movie);
	if (show == null) {return;}

	show.style.display = "none";
	show.style.visibility = "hidden";
}
/************************************************************************************/
	// Globals
	// Major version of Flash required
	var requiredMajorVersion = 8;
	// Minor version of Flash required
	var requiredMinorVersion = 0;
	// Minor version of Flash required
	var requiredRevision = 0;
/************************************************************************************/
function banerReload(init) {
	if (!init) {
		var baner1 = document.getElementById('start_baner1');
		var baner2 = document.getElementById('start_baner2');
		var baner3 = document.getElementById('start_baner3');
		if (baner1 && baner2 && baner3) {
			if (baner1.style.display == "block"){
				baner1.style.display = "none";
				baner2.style.display = "block";
				baner3.style.display = "none";
                  } else if (baner2.style.display == "block"){
				baner1.style.display = "none";
				baner2.style.display = "none";
				baner3.style.display = "block";
                  } else {
				baner1.style.display = "block";
				baner2.style.display = "none";
				baner3.style.display = "none";
                  }
            }
      }

	window.setTimeout("banerReload(0)", 8000);
}
/************************************************************************************/

