function start() {
	//start
	
	if(jskomShow&&$('komunikat')) {
		jskomAppear();
		$('komunikat').observe('click',jskomFadeOut);
	}
	if ($('banner_home')) myExecuter=new PeriodicalExecuter(nextBanner, 6);

	if($('form_zast_small')) Event.observe($('form_zast_small'), 'submit', zastosowaniaSubmit);
}
window.onload = start;


function checkFormZapytanieProdukt(oForm) {
	if(($F('zpt')==''||$F('zpt')==$('zpt').defaultValue)&&($F('zpe')==''||$F('zpe')==$('zpe').defaultValue)) {
		var kom = (lang=='pl'?'Prosimy podać numer telefonu i/lub email':'Please give telephone number and/or email');
		alert(kom);
		return false;
	}
	if($F('zpz')==''||$F('zpz')==$('zpz').defaultValue) {
		var kom = (lang=='pl'?'Prosimy wpisać treść zapytania':'Please write the message');
		alert(kom);
		return false;
	} 
	return true;
}

function setSubMenu (mAkt,mItem,isSub) {
	if (mAkt!=mItem) {
		$('main_menu_item_'+mItem).setStyle({backgroundImage:'url(images/_b_menu_.png)',marginTop:'0px',height:'76px'}); 
		$('txt1_'+mItem).setStyle({color:'#ffffff',marginTop:'20px'}); 
		$('txt2_'+mItem).setStyle({color:'#ffffff'}); 
		$('menu_hl_'+mItem).setStyle({display:'block'}); 
	}
	if (isSub==1) $('submenu_'+mItem).show();
}
function unsetSubMenu (mAkt,mItem,isSub) {
	if (mAkt!=mItem) {
		$('main_menu_item_'+mItem).setStyle({backgroundImage:'url(images/_b_menu.png)',marginTop:'17px',height:'59px'}); 
		$('txt1_'+mItem).setStyle({color:'#132a34',marginTop:'13px'}); 
		$('txt2_'+mItem).setStyle({color:'#00a8ff'}); 
		$('menu_hl_'+mItem).setStyle({display:'none'}); 
	}
	if (isSub==1) $('submenu_'+mItem).hide();
}



function zastosowaniaSubmit(evt) {
	//alert('http://tuplex.nazwa.pl/'+lang+'/zastosowania,'+$F('zastosowanie_hidden')+','+$F('kat_id_hidden'));
	window.location = 'http://tuplex.nazwa.pl/'+lang+'/zastosowania,'+$F('kat_id_hidden')+','+$F('zastosowanie_hidden');
}
var aktLeft=0;
function galGoLeft(width) {
	if (aktLeft<0) {
		aktLeft+=210;
		$('onpage_gallery_slide').setStyle({left:aktLeft+'px'});
	}
	if (aktLeft>=0) $('galNavLeft').hide();
	if (aktLeft>(-width+610)) $('galNavRight').show();	
	
}
function galGoRight(width) {
	if (aktLeft>(-width+610)) {
		aktLeft-=210;
		$('onpage_gallery_slide').setStyle({left:aktLeft+'px'});
	}
	if (aktLeft<=(-width+610)) $('galNavRight').hide();	
	if (aktLeft<0) $('galNavLeft').show();
}

var myExecuter;
var bannersHome=[];
var aktBanner=0;
function gotoBanner(bid) {
	chgBanner_step1(bid);
/*
	var banId=0;
	for(var i=0;i<bannersHome.length;i++) {
		if (bannersHome[i].id==bid) banId=i;
		$('banner_nav_'+bannersHome[i].id).removeClassName('item_');
		$('banner_nav_'+bannersHome[i].id).addClassName('item');
	}
	$('banner_img').src=bannersHome[banId].img;
	$('banner_apla_title').innerHTML=bannersHome[banId].title;	
	$('banner_apla_desc').innerHTML=bannersHome[banId].desc;	
	$('banner_nav_'+bannersHome[banId].id).removeClassName('item');
	$('banner_nav_'+bannersHome[banId].id).addClassName('item_');
	aktBanner=banId;

	myExecuter.stop();
	myExecuter=new PeriodicalExecuter(nextBanner, 6);
	*/
}
function chgBanner_step1(bid) {
	var banId=0;
	$('banner_img').fade({ duration: 0.5 , afterFinish:chgBanner_step2});
	for(var i=0;i<bannersHome.length;i++) {
		if (bannersHome[i].id==bid) banId=i;
	}
	aktBanner=banId;
}
function chgBanner_step2() {
	banId=aktBanner;
	for(var i=0;i<bannersHome.length;i++) {
		$('banner_nav_'+bannersHome[i].id).removeClassName('item_');
		$('banner_nav_'+bannersHome[i].id).addClassName('item');
	}

	$('banner_apla_title').innerHTML=bannersHome[banId].title;	
	$('banner_apla_desc').innerHTML=bannersHome[banId].desc;	
	$('banner_nav_'+bannersHome[banId].id).removeClassName('item');
	$('banner_nav_'+bannersHome[banId].id).addClassName('item_');
	$('banner_img').src=bannersHome[banId].img;
	$('banner_img').appear({ duration: 0.5 });
	myExecuter.stop();
	myExecuter=new PeriodicalExecuter(nextBanner, 6);
}

function nextBanner() {
	if (aktBanner<(bannersHome.length-1)) gotoBanner(bannersHome[aktBanner+1].id);
	else gotoBanner(bannersHome[0].id);
}

function setText(oTextInput) {
	if(oTextInput.value=='') oTextInput.value = oTextInput.defaultValue;
}
function clearText(oTextInput) {
	if(oTextInput.value==oTextInput.defaultValue) oTextInput.value = '';
}

function isEmail(address) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   return(reg.test(address));
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

function selectedRadioValue(oForm, sRadioName) {
	var retval = '';
	for(var i=0;i<oForm.elements.length;i++) {
		if(oForm.elements[i].type!='radio'||oForm.elements[i].name!=sRadioName) continue;
		if(oForm.elements[i].checked) retval = oForm.elements[i].value;
	}
	return retval;
}

function showKom(kom,kom_status) {
	if(kom_status=='error') {
		$('komunikat').setStyle({backgroundColor:'#E1E6FA', border: '5px solid #183152', color:'#183152'});
		$('kom_img').src = 'images/ico_kom_error.png';
	}
	else if(kom_status=='info') {
		$('komunikat').setStyle({backgroundColor:'#E1E6FA', border: '5px solid #183152', color:'#183152'});
		$('kom_img').src = 'images/ico_kom_info.png';
	}
	else {
		$('komunikat').setStyle({backgroundColor:'#E1E6FA', border: '5px solid #183152', color:'#183152'});
		$('kom_img').src = 'images/ico_kom_ok.png';
	}
	$('kom_text').update(kom);
	jskomAppear();
}
var jskomShow=false;
var jskomZostaw=true;
var peJskom;
function jskomAppear() {
	try{
		//Effect.Appear('jskom');
		$('komunikat').show();
	}
	catch (exc) {
		$('komunikat').show();
	}
	if(!jskomZostaw) peJskom = new PeriodicalExecuter(function(peJskom) {
			jskomFadeOut();
		}, 4);
}
function jskomFadeOut() {
	try{
		Effect.Fade('komunikat');
		}
	catch (exc) {
		$('komunikat').hide();
	}
	//$('komunikat').update('');
	if(peJskom) peJskom.stop();
}


//nowa galeria
/*
var aktGal = new Galeria();
function showGal(el) {
	aktGal.initGal(el);
}
*/

//stara galeria
var img;
var galFotos = [];
var aktFoto = 0;
function setGal(fot,fotos) {
	if(typeof fotos=='object') galFotos = fotos;
	else galFotos = [];
	$('bigFotoContainer').show();
	aktFoto = 0;
	if(galFotos.length>0) {
		for(var i=0;i<galFotos.length;i++) {
			if(galFotos[i]==fot) aktFoto = i;
		}
	}
	pokazFotoGal(fot);
}
function pokazFotoGal(fot) {
	$('bigFotoImg').update('<img src="images/czekaj_pl.gif" border="0" />')
	img = new Element('img');
	img.id = 'theimage';
	img.observe('load', showimg);
	//document.body.appendChild(img);
	img.src = fot;
	//$('bigFotoImg').update('<img src="'+fot+'" border="0" />';
	$('bigFotoImg').show();
	fotoNav();
	//$('main').hide();	
}
function pokazFoto(fot) {
	galFotos = [];
	$('bigFotoImg').update('<img src="images/czekaj_pl.gif" border="0" />')
	img = new Element('img');
	img.id = 'theimage';
	img.observe('load', showimg);
	//document.body.appendChild(img);
	img.src = fot;
	$('bigFotoImg').update('<img src="'+fot+'" border="0" />');
	$('bigFotoImg').show();
	$('bigFotoContainer').show();
	//$('main').hide();
	aktFoto = 0;
	fotoNav();
}
function showimg(evt) {
	$('bigFotoImg').hide();
	$('bigFotoImg').update(img);
	$('bigFotoImg').show();
	var dim = document.viewport.getDimensions();
	if(img.width>dim.width||img.height>dim.height-160) {
		var new_size = image_small_maker(img.width, img.height, dim.width, dim.height-160)
		img.setStyle({'width':new_size[0]+'px','height':new_size[1]+'px'});
	}
}
function wywalFoto() {
	$('bigFotoContainer').hide();
	$('bigFotoImg').hide();
	//$('main').show();
}
function fotoNav() {
	if(aktFoto>0) $('bigFotoPrev').show();
	else $('bigFotoPrev').hide();
	if(aktFoto<galFotos.length-1) $('bigFotoNext').show();
	else $('bigFotoNext').hide();
}
function prevFoto() {
	if(aktFoto<=0) return;
	aktFoto--;
	pokazFotoGal(galFotos[aktFoto]);
}
function nextFoto() {
	if(aktFoto>galFotos.length-1) return;
	aktFoto++;
	pokazFotoGal(galFotos[aktFoto]);
}
function image_small_maker(orig_width, orig_height, max_width, max_height) {
	var xRatio = max_width / orig_width; 
	var yRatio = max_height / orig_height; 
	var new_width = 0;
	var new_height = 0;
	if ( (orig_width <= max_width) && (orig_height <= max_height) ) { 
	 new_width = orig_width; 
	 new_height = orig_height; 
	} 
	else if ((xRatio * orig_height) < max_height) { 
	 new_height = Math.ceil(xRatio * orig_height); 
	 new_width = max_width; 
	} 
	else { 
		new_width = Math.ceil(yRatio * orig_width); 
		new_height = max_height; 
		}
	var output = [];
	output.push(Math.round(new_width));
	output.push(Math.round(new_height));
	return output;
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function basename (path, suffix) {
    var b = path.replace(/^.*[\/\\]/g, '');
    
    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }
    
    return b;
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}
function viewportDims() {
	var viewportwidth;
	var viewportheight;
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerWidth,
		viewportheight = window.innerHeight
	}
 	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined'&& typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0) {
		viewportwidth = document.documentElement.clientWidth,
		viewportheight = document.documentElement.clientHeight
	}
	// older versions of IE
	else {
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}
	return {width:viewportwidth,height:viewportheight};
}

var tabSubKat=[];
var aktSubKat=0;

var tabZast=[];
var aktZast=0;
function toggleZast(i,j) {
	var x=document.getElementById('s_'+j);

	var xv=x.value;
	for(var k=0;k<=tabZast.length;k++) {
		if ($('zast_'+i+'_'+tabZast[k]) && tabZast[k]!=xv) {
			$('zast_'+i+'_'+tabZast[k]).hide();
				
		}
	}
	
	if (xv>0) {
		$('s3_'+i+'_'+xv).selectedIndex=0;
		$('zast_'+i+'_'+xv).show();
		$('form_zast_small').hide();
	}
	aktZast=xv;
}
function toggleZastKat(i) {
	var x=document.getElementById("s_"+i);
	var xv=x.value;
	if (aktSubKat!=xv) {
		for(var k=0;k<=tabSubKat.length;k++) {
			if ($('zkat_sub_'+tabSubKat[k]) && tabSubKat[k]!=xv) {
				$('zkat_sub_'+tabSubKat[k]).hide();
				$('s_'+tabSubKat[k]).selectedIndex=0;
			}
		}
		if ($('zkat_sub_'+xv)) {
			$('zkat_sub_'+xv).show();
			for(var k=0;k<tabZast.length;k++)  $('zast_'+i+'_'+tabZast[k]).hide();
			$('form_zast_small').hide();
		}
		else {
			toggleZast(i,i);
		}
		aktSubKat=xv;
	}
}
function clearKZ() {
	for(var k=0;k<=tabSubKat.length;k++) {
		$('zkat_sub_'+tabSubKat[k]).hide();
		$('s_'+tabSubKat[k]).selectedIndex=0;
	}

	for(var i=1;i<=3;i++) {
		alert($('s_'+i));
		$('s_'+i).selectedIndex=0;
		for(var k=0;k<=tabZast.length;k++) {
			$('zast_'+i+'_'+tabZast[k]).hide();
			
		}
	}
}
function setRightBanner(bid) {
	$('button_right_'+bid).addClassName('active');
	$('img_right_'+bid).show();
}
function unsetRightBanner(bid) {
	$('button_right_'+bid).removeClassName('active');
	$('img_right_'+bid).hide();	
}





// this function is needed to work around 
// a bug in IE related to element attributes
function hasClass(obj) {
	var result = false;
	if (obj.getAttributeNode("class") != null) {
		result = obj.getAttributeNode("class").value;
	}
	return result;
}   

function stripe(id,second) {

	// the flag we'll use to keep track of 
	// whether the current row is odd or even
	var even = false;
	
	// if arguments are provided to specify the colours
	// of the even & odd rows, then use the them;
	// otherwise use the following defaults:
	var evenColor =  "#ffffff";
	var oddColor = "#eeeeee";

	// obtain a reference to the desired table
	// if no such table exists, abort
	var table = document.getElementById(id);
	if (! table) { return; }
	
	
	
	// find all the &lt;tr&gt; elements... 
	var trs = table.getElementsByTagName("tr");
		
	// ... and iterate through them
	for (var i = 0; i < trs.length; i++) {
		// avoid rows that have a class attribute
		// or backgroundColor style
		if (! hasClass(trs[i]) && ! trs[i].style.backgroundColor) {
			// get all the cells in this row...
			var tds = trs[i].getElementsByTagName("td");
			// and iterate through them...
			for (var j = 0; j < tds.length; j++) {
				var mytd = tds[j];
				// avoid cells that have a class attribute
				// or backgroundColor style
		
				if (i==0) mytd.addClassName('first_row');
				if (second==1 && i==1) mytd.addClassName('second_row');				

				else {
						
					if (! hasClass(mytd) &&	! mytd.style.backgroundColor) {
						mytd.style.backgroundColor =even ? evenColor : oddColor;
						
					}
				}
		

			}
		}
	// flip from odd to even, or vice-versa
	even =  ! even;
	}
}






