var browserName = navigator.appName;
var browserVer = parseInt(navigator.appVersion);
var version = "";
var msie4 = (browserName == "Microsoft Internet Explorer" && browserVer >= 4);
if ((browserName == "Netscape" && browserVer >= 3) || msie4 || browserName=="Konqueror" || browserName=="Opera" || navigator.userAgent.indexOf('Firefox')>=0) {version = "n3";} else {version = "n2";}
	// Blurring links:
function blurLink(theObject)	{	//
	if (msie4 || navigator.userAgent.indexOf('Firefox')>=0)	{theObject.blur();}
}
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
//////////////////////////////////////////

function toggle(id)
{
	$('#CElement' + id).toggle();
}
function hideOvr()
{
	$('#homeDivMainOvr2').hide();
}

var OKclientData = false;

var LL = new Array();
var URLcache = new Object();
$.fn.previous = function(expr) {
   var match = [];

   // We need to figure out which elements to push onto the array
   this.each(function(){
       // Traverse through the sibling nodes
       for( var i = this.previousSibling; i; i = i.previousSibling ) {
           // Make sure that we're only dealing with elements
           if ( i.nodeType != 1 ) continue;

           // Otherwise, add it on to the stack
           match.push( i );
       }
   });
   return this.pushStack( match, arguments );
};
function dnListShortcut(o,l)
{
	i = o.selectedIndex;
	o.selectedIndex = l;
	to = $('#dnListCategory' + o.options[i].value).offset();
	
	blurLink(o);
	window.scrollTo(0,parseInt(to['top'] - 10)); 	
}
function dnListCategorySwitch(o)
{
	i = o.selectedIndex;
	$('.dnListCategory').css('display','none');
	$('#dnListCategory' + o.options[i].value).css('display','block');
	blurLink(o);
}
function dnPageSwitch(o,uid)
{
	i = o.selectedIndex;
	blurLink(o);
	dnPageSwitchLoad(o.options[i].value,uid);
}
function dnPageSwitchLoadTime(url,uid,time)
{
	setTimeout("dnPageSwitchLoad('"+url+"',"+uid+")",time);
}
function dnPageSwitchLoad(url,uid)
{
	$('#dnPagesData' + uid).html('<div class="trwaLadowanie">' + LL['trwa_ladowanie'] + '</div>');
	if(!URLcache[escape(url)])
	{
		$.get(url, function(data){
			$('#dnPagesData' + uid).html(data);
//			$('#dnPagesData' + uid).append(data);
			URLcache[escape(url)] = data;
		} );
	} else {
		$('#dnPagesData' + uid).html(URLcache[escape(url)]);
	}
}
function dnListHeader(i) 
{
	$('#dnListCategory' + i).toggleClass('collapsed');
	$('#dnListCategory' + i + ' .dnListItems').slideToggle('fast');
}

var originalImages = new Array;
function dnListItemOver(d)
{
	$(d).addClass('dnListItemHover');
	if ($(d).get(0).className.indexOf('dnListItemShort') >= 0) {
		p = $(d).previous().filter('.dnListItemLong');
		if (p.length) {
			id = p.get(0).id;
			originalImages[parseInt(id.substring(10,20))] = $('.thumbnail > img',p.get(0)).attr("src");
			$('.thumbnail > img',p.get(0)).attr("src", $('.thumbnail > img',d).attr("src") );
		}
	}
}
function dnListItemOut(d)
{
	$(d).removeClass('dnListItemHover');
	if ($(d).get(0).className.indexOf('dnListItemShort') >= 0) {
		p = $(d).previous().filter('.dnListItemLong');
		if (p.length) {
			id = p.get(0).id;
			$('.thumbnail > img',p.get(0)).attr("src", originalImages[parseInt(id.substring(10,20))]);
		}
	}
}

function dnListItemZoom(list)
{
//	alert(list);
	list=list.split('|');
	z = '<div id="zoomBG"></div><div id="zoomIMG"><div class="close"></div><center><img src="' + list[0] + '" /></center></div>';
	$('body').append(z);
	$('#zoomBG').click( function() {dnListItemUnZoom();});
	$('#zoomBG').css('height',$(document).height());
	x = $(window).width()/2 - 245;
	y = $(document).scrollTop() + $(window).height()/2 - 240;
	$('#zoomIMG').css('left',x + 'px');
	$('#zoomIMG').css('top',y + 'px');
	$('#zoomBG').css('height',Math.max($(document).height(),$(window).height()));
	$('.close','#zoomIMG').click( function() {dnListItemUnZoom();});
	$('select').css('display','none');
}
function dnListItemZoomBig(list)
{
//	alert(list);
	list=list.split('|');
	z = '<div id="zoomBG"></div><div id="zoomIMG" class="zoomBig"><div class="close"></div><center><img src="' + list[0] + '" /></center></div>';
	$('body').append(z);
	$('#zoomBG').click( function() {dnListItemUnZoom();});
	$('#zoomBG').css('height',$(document).height());
	x = $(window).width()/2 - 420;
	y = $(document).scrollTop() + $(window).height()/2 - 310;
	$('#zoomIMG').css('left',x + 'px');
	$('#zoomIMG').css('top',y + 'px');
	$('#zoomBG').css('height',Math.max($(document).height(),$(window).height()));
	$('.close','#zoomIMG').click( function() {dnListItemUnZoom();});
	$('select').css('display','none');
}
function dnZoomFlash(url,w,h)
{
	z = '<div id="zoomBG"></div><div id="zoomIMG" class="zoomBig" style=" width: '+(w+60)+'px; height: '+(h+60)+'px;"><div class="close" style="position: static; margin-left:'+(w+34)+'px;"></div><div id="zoomSWF" style="margin: 0 30px 30px 30px;"></div></div>';
	$('body').append(z);
	$('#zoomBG').click( function() {dnListItemUnZoom();});
	$('#zoomBG').css('height',$(document).height());
	x = $(window).width()/2 - w/2;
	y = $(document).scrollTop() + $(window).height()/2 - h/2;
	$('#zoomIMG').css('left',x + 'px');
	$('#zoomIMG').css('top',y + 'px');
	$('#zoomBG').css('height',Math.max($(document).height(),$(window).height()));
	$('.close','#zoomIMG').click( function() {dnListItemUnZoom();});
	var so = new SWFObject(url, "zoomSWFo", w, h, "8", "#ffffff");
	so.write("zoomSWF");
}
function dnListItemUnZoom()
{
	$('select').css('display','inline');
	$('#zoomBG').remove();
	$('#zoomIMG').remove();
}
function showAlert_old(h,t)
{
	z = '<div id="alertBG"></div><div id="alertPopup"><div class="close"></div><h3>'+h+'</h3><p>'+t+'</p><input type="button" class="button" value="OK" onClick="hideAlert();" /></div>';
	$('body').append(z);
	$('#alertBG').click( function() {});
	//maximizeHeight($('#alertBG').get(0));
	$('#alertBG').css('height',Math.max($(document).height(),$(window).height()));
	$('.close','#alertPopup').click( function() {hideAlert();});
}
function showAlert(h,t)
{
	z = '<div id="alertBG"></div><div id="alertPopup"><div class="close"></div><h3>'+h+'</h3><p>'+t+'</p><input type="button" class="button" value="OK" onClick="hideAlert();" /></div>';
	$('body').append(z);
	$('#alertBG').click( function() {});
	$('.close','#alertPopup').click( function() {hideAlert();});
	x = $(window).width()/2 - 245;
	y = $(document).scrollTop() + $(window).height()/2 - 80;
	$('#alertPopup').css('left',x + 'px');
	$('#alertPopup').css('top',y + 'px');
	$('#alertBG').css('height',$(document).height());
	
}
function hideAlert()
{
	$('#alertBG').remove();
	$('#alertPopup').remove();
}

function dnListPriceSwitch(o)
{
	$('body').css('cursor','progress');
	$('input').css('cursor','progress');
	listDiv = $('.dnList').not('.' + o.value);
	for (i=0;i<listDiv.length;++i) {
		$('.priceSwitchable .p1', $(listDiv).get(i) ).each(
			function (i)
			{
				t = $(this).html();
				$(this).html($(this).siblings('.p2').html());
				$(this).siblings('.p2').html(t);			
			}
		);
	}
	$(listDiv).toggleClass('brutto');
	$(listDiv).toggleClass('netto');
	$('.priceSwitchable .price', listDiv).toggleClass('brutto');
	$('.priceSwitchable .price', listDiv).toggleClass('netto');
	$('.total', '#dnShortOrder').toggleClass('brutto');
	$('.total', '#dnShortOrder').toggleClass('netto');
	$(listDiv).toggleClass('netto');
	blurLink(o);
	$.get("/order_update.php", { c: o.value}, function(data){
		$('body').css('cursor','default');
		$('input').css('cursor','default');
	} );
	
}


function dnListZamawiam(id,g)
{	
	f = $('form[@name=dnListItemForm' + id + ']').get(0);
	l = f['quantity'].value;
	toomuch = false;
	f2 = document.forms['shortOrderForm'];
	if (f2) {
		max = f2[g + '_maxitems'].value;
		num = $('.item','#dnShortOrder .items-' + g).length;
		toomuch = (parseInt(num) >= parseInt(max));
	}
	if (toomuch) {
		declensions = LL['declesions_pozycja'].split('|');	
		n = computeDeclesion(num);
		txt = LL['alert_za_duzo'].split('|').join(max+' '+declensions[n]);
		showAlert(LL['uwaga'],txt);
	} else {
		$('body').css('cursor','progress');
		$('a').css('cursor','progress');
		disp = '';
		if (typeof f['dispenser'] == 'object')
			disp = f['dispenser'].options[f['dispenser'].selectedIndex].value;
		if (f['instant_jump'].value.length >0 && f['jumpbeforeorder'].value==1) {
			document.location.href = f['instant_jump'].value;
			return false;
		}
		$.getJSON("/order_update.php", { c: 'add', id: id, q: f['quantity'].value, d: disp}, function(json){
			dnListZamawiamOK(json);
		} );
	}
	return false;
}

function  dnListZamawiamOK(json)
{
	id = json['data']['uid'];
	o = $('.quantityTable', '#dnListItem' + id);
	showPtaszek(id);
	
	dnShortOrderAdd(json);
	$('body').css('cursor','default');
	$('a').css('cursor','default');
	
	f = $('form[@name=dnListItemForm' + id + ']').get(0);
	if (f['instant_jump'].value.length >0)
		document.location.href = f['instant_jump'].value;
}

var ptaszekTimeout;
function showPtaszek(o)
{
	o = $('.quantityTable', '#dnListItem' + id);
	$(o).after('<div class="ptaszek" onClick="hidePtaszek('+ id +');"></div>');
	ptaszekTimeout = window.setTimeout('hidePtaszek('+ id +')',4000);
}
function hidePtaszek(id)
{
	//alert(id);
	o = $('#dnListItem' + id);
	$('.ptaszek',o).fadeOut('normal',function(){
		$(this).remove();
	});
}
var tempQuantity;
function dnListQuantityFocus(f)
{
	tempQuantity = f['quantity'].value;
	f['quantity'].select();
}
function dnListQuantityBlur(f)
{

}
function dnListQuantityChange(f)
{

	declensions = f['declensions'].value.split('|');	
	price_ranges = f['price_ranges'].value.split('|');	
//	alert(price_ranges.length);
	q = parseInt(f['quantity'].value);
	if ( q < parseInt(f['minquantity'].value) || isNaN(q) ) {
		f['quantity'].value = f['minquantity'].value;
		q = parseInt(f['minquantity'].value);
//		alert ("Minimalna ilość wynosi " + q + ".");
	}
	n = computeDeclesion(q);
	$('.declension', $(f)).html(declensions[n]);
	price = f['price'].value;
	price_flat = 0;
	if (price_ranges.length > 1) {
		for (i=0;i<price_ranges.length;i+=3)
			if (price_ranges[i]<=q) {
				price = price_ranges[i+1];
				price_flat = price_ranges[i+2];
			}
	}
//	$('.priceranges .netto', $(f)).html(formatPrice(price) + ' ' + f['netto'].value)
//	$('.priceranges .brutto', $(f)).html(formatPrice(price*(1+parseFloat(f['vat'].value))) + ' ' + f['brutto'].value)

//        $netto = $current_price_flat + $current_price * $q + $row['flat_price'];
//        $brutto =  ($current_price_flat + $current_price * $q) * (1+$row['vat']) + $row['flat_price'] * (1+$row['flat_vat']);

	netto = parseFloat(price_flat) + q * parseFloat(price);
	brutto = (parseFloat(price_flat) + q * parseFloat(price)) * (1 + parseFloat(f['vat'].value));
	$('.priceVariable .netto', $(f)).html(formatPrice(netto) + ' ' + f['netto'].value)
	$('.priceVariable .brutto', $(f)).html(formatPrice(brutto) + ' ' + f['brutto'].value)
	netto += parseFloat(f['flat_price'].value);
	brutto += parseFloat(f['flat_price'].value) * (1 + parseFloat(f['flat_vat'].value));
	$('.priceComputable .netto', $(f)).html(formatPrice(netto) + ' ' + f['netto'].value)
	$('.priceComputable .brutto', $(f)).html(formatPrice(brutto) + ' ' + f['brutto'].value)
	
	return false;
}


function dnListQuantityRecalc(n)
{
	f = $('form[@name="dnListItemForm' + n + '"]').get(0);
	return dnListQuantityChange( f );
}

function dnListQuantityMinus(f) {
	q = parseInt(f['quantity'].value);
	q = q - 1;
	if (q < parseInt(f['minquantity'].value)) {
		f['quantity'].value = f['minquantity'].value;
	} else {
		f['quantity'].value = q;
	}
	return dnListQuantityChange(f);
}
function dnListQuantityPlus(f) {
	q = parseInt(f['quantity'].value);
	q = q + 1;
	if (q < parseInt(f['minquantity'].value)) {
		f['quantity'].value = f['minquantity'].value;
	} else {
		f['quantity'].value = q;
	}
	return dnListQuantityChange(f);
}



function dnShortOrderItemErase(id,k)
{
	$('body').css('cursor','progress');
	$('div','#dnShortOrderItem'+id + '-' + k).css('cursor','progress');
	$.getJSON("/order_update.php", { c: 'remove', id: id, k: k }, function(json){
		dnShortOrderRecalc(json['netto'] , json['brutto']);
		par = $('#dnShortOrderItem' + id + '-' + k).parent();
		$('#dnShortOrderItem' + id + '-' + k).remove();
//		if ($(parent).html() == '') {
//			$(parent).html('&nbsp;');
//		}
		dnShortOrderUpdateMarks(json);
		$('body').css('cursor','default');
		$('div','#dnShortOrderItem'+id + '-' + k).css('cursor','default');
		dnShortOrderUpdateHint();
	} );
	return false
}


function dnShortOrderAdd(json)
{
	q = json['q'];
	k = json['k'];
	d = json['d'];
//	alert(d);
	id = json['data']['uid'];
	g = json['data']['group_id'];
	n =  computeDeclesion(q);
	el = $('#dnShortOrderItem' + id + '-' + k).get(0);
	pack = json['data']['packaging'] + '_' + n;
	if (el) {
		$('.quantity',el).html(q + ' ' + declesions[pack]);
	} else {
		o = '<div class="item" id="dnShortOrderItem' +id+ '-' +k+ '">';
		o += '<div class="title">' + json['data']['title_' + language] + '</div>';
		o += '<div class="erase" onclick="dnShortOrderItemErase(' +id+ ',' +k+ ');"></div>';
		if (d.length > 1)
			o += '<div class="quantity">' +q+ ' ' + declesions[pack] + ', ' + d + '</div>';
		else
			o += '<div class="quantity">' +q+ ' ' + declesions[pack] + '</div>';
		o += '</div>';
		if ($('.items-'+g, '#dnShortOrder').html() == '&nbsp;') {
			$('.items-'+g, '#dnShortOrder').html('');
		}
		$('.items-'+g, '#dnShortOrder').append(o);
	}
	dnShortOrderRecalc(json['netto'] , json['brutto']);
	dnShortOrderUpdateMarks(json);
	dnShortOrderUpdateHint();
}

function dnShortOrderRecalc(netto,brutto)
{
	$('.totalNetto b','#dnShortOrder').html(formatPrice(netto));
	$('.totalBrutto b','#dnShortOrder').html(formatPrice(brutto));
}

function dnShortOrderUpdateMarks(json)
{
	g = json['data']['group_id'];
	f = document.forms['shortOrderForm'];
	min = f[g + '_minitems'].value;
	num = $('.item','#dnShortOrder .items-' + g).length;
//	alert(num);
	if (parseInt(num) < parseInt(min))
		$('.marker','#dnShortOrder .header_' + g).removeClass('markerChecked');
	else 
		$('.marker','#dnShortOrder .header_' + g).addClass('markerChecked');
	dnShortOrderUpdateStatus();
}

function dnShortOrderUpdateStatus()
{
	var f = document.forms['shortOrderForm'];
	orderStatus = 'complete';
	for (i=0;i<orderCheckSections.length;++i) {
		section = orderCheckSections[i];
		min = f[section + '_minitems'].value;
		max = f[section + '_maxitems'].value;
		num = $('.item','#dnShortOrder .items-' + section).length;
		if (orderStatus == 'complete') {
			if (num > max)
				orderStatus = 'too_much';
			if (num < min)
				orderStatus = 'not_complete';
		}
	}
//	alert(orderStatus + ' ' + dnuserdatacomplete);
	if ((orderStatus == 'complete') && (!dnuserdatacomplete))
		orderStatus = 'enter_user';
	$('.headerStatus','#dnShortOrder').attr('class','headerStatus');
	$('.headerStatus','#dnShortOrder').addClass('headerStatus_' + orderStatus);
	if (dnuserdatacomplete) {
		$('.marker','#dnShortOrder .header_dane').addClass('markerChecked');
		$('.items-dane','#dnShortOrder').addClass('items-dane-ok');
		$('.items-dane','#dnShortOrder').removeClass('items-dane-notok');
	} else {
		$('.marker','.header_dane').removeClass('markerChecked');
		$('.items-dane','#dnShortOrder').addClass('items-dane-notok');
		$('.items-dane','#dnShortOrder').removeClass('items-dane-ok');
	}
}
function dnShortOrderUpdateHint()
{
	o = $('.hint','#dnShortOrder').get(0);
	if ($('.items-pnaq').length > 0) {	
		// pakiet naq
		if (dnShortOrderCheckSectionStatus('pnaq') != 'complete')
			o.className = 'hint hintPakiet';
		else if (dnShortOrderCheckSectionStatus('dane') != 'complete')
			o.className = 'hint hintDane';
		else
			o.className = 'hint hintZamow';
	} else if ($('.items-pdn').length > 0) {	
		// pakiet naq
		if (dnShortOrderCheckSectionStatus('pdn') != 'complete')
			o.className = 'hint hintPakiet';
		else if (dnShortOrderCheckSectionStatus('dane') != 'complete')
			o.className = 'hint hintDane';
		else
			o.className = 'hint hintZamow';
	} else {

		if (dnShortOrderCheckSectionStatus('w') != 'complete')
			o.className = 'hint hintWoda';
		else if (dnShortOrderCheckSectionStatus('ud') != 'complete')
			o.className = 'hint hintDystrybutor';
		else if (dnShortOrderCheckSectionStatus('dane') != 'complete')
			o.className = 'hint hintDane';
		else
			o.className = 'hint hintZamow';

	}
	//alert (o.className);
}

function dnShortOrderCheckSectionStatus(sections)
{
	f = document.forms['shortOrderForm'];
	s = 'complete';
	sections = sections.split(',');
	for (i=0;i<sections.length;++i) {
		section = sections[i];
		//console.log(section);
		if (section == 'dane') {
			if (!dnuserdatacomplete)
				s = 'enter_user';
		} else {
			min = f[section + '_minitems'].value;
			max = f[section + '_maxitems'].value;
			num = $('.item','#dnShortOrder .items-' + section).length;
			if (s == 'complete') {
				if (num > max)
					s = 'too_much';
				if (num < min)
					s = 'not_complete';
			}
		}
	}
	return s;
}



function dnStepsCheckSections(sections,go,e) 
{
	s = dnShortOrderCheckSectionStatus(sections);
//	alert (s);
	if (s == 'complete')
		location.href = go;
	else
		showAlert (LL['uwaga'],e[s]);
}

function dnStepsBack(go)
{
	location.href = go;
}




function formatPrice(p) {
	p=Math.round(parseFloat(p)*100);
    p=p+'';
    zero = '000';
    p=zero.substring(0,3-p.length) + p;
    dec = p.substring(0,p.length-2);
    if (dec.length > 6)
    	dec = dec.substring(0,dec.length-6) + ' ' + dec.substring(dec.length-6,dec.length-3) + ' ' + dec.substring(dec.length-3,dec.length);
    else if (dec.length > 3)
    	dec = dec.substring(0,dec.length-3) + ' ' + dec.substring(dec.length-3,dec.length);
    p=dec+','+p.substring(p.length-2,p.length);
	return p;
}

function computeDeclesion(q)
{
	n =  parseInt(q) % 100;
	if (n>=10 && n<20) {
		n = 2;
	} else if (q==1) {
		n=0;
	} else {
		n =  q % 10;
		n = (n<=1 || n>=5 ? 2 : 1);
	}
	return n
}

function dnClientTextChange(field)
{

}
function dnClientTextFocus(field)
{
	$('#fieldSet-' + field.name ).addClass('fieldSetActive');
}
function dnClientTextBlur(field)
{
	dnClientFieldUpdate(field);
}

function dnClientRadioClick(field)
{
	$('#fieldSet-' + field.name ).addClass('fieldSetActive');
	dnClientFieldUpdate(field);
	if (field.name == 'typklienta') {
		firma = document.forms['clientDataForm']['firma'];
		if (field.value == 'i') {
			firma.value = '';
			firma.disabled=true;
			dnClientFieldUpdate(firma);
			$('#fieldSet-firma').addClass('fieldSetDisabled');
		} else {
			$('#fieldSet-firma').removeClass('fieldSetDisabled');
			firma.disabled=false;
		}
	}
	field.blur();
}
function dnClientCheckboxClick(field)
{
	$('#fieldSet-' + field.name ).addClass('fieldSetActive');
	$.getJSON("/client_update.php", { f: field.name, v: (field.checked?field.value:'') }, function(json){
		JSONupdateField(json);
	} );
	field.blur();
}


function dnClientFieldUpdate(field)
{
	$.getJSON("/client_update.php", { f: field.name, v: field.value }, function(json){
		JSONupdateField(json);
	} );
}

function JSONupdateField(json)
{
	if (json['ok']) {
		form = document.forms['clientDataForm'];
		field = form[json['f']];
		if (field.type == 'text') {
			field.value = json['v'];
		}
		fset = $('#fieldSet-' + json['f'] ).get(0);
		$('.ptaszek',fset).removeClass('ptaszekOk');
		if (json['r'])
			$('.ptaszek',fset).addClass('ptaszekOk');
		dnClientFormComplete(json['allok']);
	}
	$('#fieldSet-' + json['f'] ).removeClass('fieldSetActive');
	dnShortOrderUpdateHint();
}

function dnClientFormComplete(complete)
{
	OKclientData = complete;
	dnuserdatacomplete = complete;
	dnShortOrderUpdateStatus();
	if (complete)
		$('.comments', document.forms['clientDataForm']).addClass('commentsOk');
	else
		$('.comments', document.forms['clientDataForm']).removeClass('commentsOk');
}
function dnClientDestroy()
{
	$.get("/client_update.php", { c: 'destroy' }, function(data){
		location.reload();
	} );
}


function dnClientConfirm()
{
	if (OKclientData) {
	
	} else {
		showAlert (LL['uwaga'],LL['alert_nie_kompletny']);
	}
}


function dnContactTextChange(field)
{
	
}
function dnContactTextFocus(field)
{
	$('#fieldSet-' + field.name ).addClass('fieldSetActive');
}
function dnContactTextBlur(field)
{
	$('#fieldSet-' + field.name ).removeClass('fieldSetActive');
	dnContactFieldUpdate(field);
}
function dnContactFieldUpdate(field)
{
	fset = $('#fieldSet-' + field.name, field.form ).get(0);
	field.value = field.value.trim();
	$('.ptaszek',fset).removeClass('ptaszekOk');
	var fieldOK = true;
	if (field.attributes['alternative'] != undefined) {
		field2 = $('input[@name=' + field.attributes['alternative'].value + ']',field.form).get(0);
		fset2 = $('#fieldSet-' + field2.name, field.form ).get(0);
		field2.value = field2.value.trim();
		$('.ptaszek',fset2).removeClass('ptaszekOk');
		var field2OK = true;
		if (field2.type == 'text' || field2.type == 'textarea') {
			if ((fset2.className.indexOf('fieldSetRequired') >0) && (field2.value.length == 0 ))
				field2OK = false;
			if ((field2.attributes['validate'] != undefined) && (field2.value.length > 0)) {
				fRegexp = new RegExp(field2.attributes['validate'].value);
				if (!fRegexp.test(field2.value))
					field2OK = false;
			}
		}
	}
	if (field.type == 'text' || field.type == 'textarea') {
		if ((fset.className.indexOf('fieldSetRequired') >0) && (field.value.length == 0 ))
			fieldOK = false;
		if ((field.attributes['validate'] != undefined) && (field.value.length > 0)) {
			fRegexp = new RegExp(field.attributes['validate'].value);
			if (!fRegexp.test(field.value))
				fieldOK = false;
		}
		if (field.attributes['alternative'] != undefined) {
			if (fieldOK || field2OK) {
				$('.ptaszek',fset2).addClass('ptaszekOk');
				$('.ptaszek',fset).addClass('ptaszekOk');
			}
		} else {
			if (fieldOK)		
				$('.ptaszek',fset).addClass('ptaszekOk');
		}
	}
}
function dnContactCheckboxClick(field)
{
	fset = $('#fieldSet-' + field.name ).get(0);
	$('.ptaszek',fset).removeClass('ptaszekOk');
	if (field.type == 'checkbox' && fset.className.indexOf('fieldSetRequired') >0) {
		if (field.checked) {
			$('.ptaszek',fset).addClass('ptaszekOk');
		}			
	}
	if (field.name == 'jestem_klientem') {
		numer = field.form['numer_klienta'];
		if (!field.checked) {
			numer.value = '';
			numer.disabled=true;
			$('#fieldSet-numer_klienta').addClass('fieldSetDisabled');
		} else {
			$('#fieldSet-numer_klienta').removeClass('fieldSetDisabled');
			numer.disabled=false;
		}
	}
	field.blur();
}

function dnContactRadioClick(field)
{
	fset = $('#fieldSet-' + field.name ).get(0);
	if (fset.className.indexOf('fieldSetRequired') >0) {
		if (field.checked) {
			$('.ptaszek',fset).addClass('ptaszekOk');
		}			
	}
	if (field.name == 'rodzajoferty') {
		pracownicy = field.form['pracownicy'];
		if (field.value == 'dom') {
			pracownicy.value = '';
			pracownicy.disabled=true;
			$('#fieldSet-pracownicy').addClass('fieldSetDisabled');
		} else {
			$('#fieldSet-pracownicy').removeClass('fieldSetDisabled');
			pracownicy.disabled=false;
		}
	}
	field.blur();
}
function dnContactSelectChange(field)
{
	fset = $('#fieldSet-' + field.name ).get(0);
	$('.ptaszek',fset).removeClass('ptaszekOk');
	if (fset.className.indexOf('fieldSetRequired') >0) {
		if (field.options[field.selectedIndex].value > '') {
			$('.ptaszek',fset).addClass('ptaszekOk');
		}			
	}
}

function dnChangeDispenser(o)
{
	f = o.form;
	//pic = o.options[o.selectedIndex].value;
	a = eval('dispenserPictures'+f.uid.value);
	$('.thumbnail > img',f).attr("src", a[o.selectedIndex] );
	$('.thumbnail > img',f).one( 'load', function() {
		oo = $(this).get(0);
		$(this).parent().css('height',oo.height + 'px');
	} );
	p = eval('dispenserPDF'+f.uid.value);
	if (p[o.selectedIndex].length>0) {
		$('.pdf',f).attr("href", '/download.php?f=' + p[o.selectedIndex] );
		$('.pdf',f).css("visibility", "visible");
	} else {
		$('.pdf',f).css("visibility", "hidden");
	}
//	$('.thumbnail',f).css("height", "auto" );
}
var contactOK;
function dnContactConfirm(f) 
{
	contactOK = true;
	$('.fieldSet',f).each(function(t) {
		if(this.className.indexOf('fieldSetRequired')>0 && this.className.indexOf('fieldSetDisabled')<0) {
			//alert($('.ptaszek',this).get(0).className.indexOf('ptaszekOk') >0);
			if($('.ptaszek',this).get(0).className.indexOf('ptaszekOk')<0)
				contactOK = false;
		}
	});
	if (contactOK)
		f.submit();
	else 
		showAlert (LL['uwaga'],LL['alert_nie_kompletny']);
	
}
var newwindow;
function dnContactPrint(f) 
{
	h = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
	h = h + '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
	h = h + '<base href="http://darnatury.pl/" />';
	h = h + '<title>Dar Natury: ' + f.formtitle.value + '</title>';
	h = h + '<link rel="stylesheet" type="text/css" href="fileadmin/template/css/formprint.css" media="screen, projection, print" />'
	h = h + '</head><body class="subpage">';
	//h = h + '<div style="float: right; height: 122px;"><img id="imgLogoNAQ" height="128" width="122" alt="" src="/fileadmin/template/images/logo_dn_naq.png"/></div>'
	h = h + '<img id="imgLogoDN" height="40" width="106" alt="Nestle Waters Direct" src="/fileadmin/template/images/logo_nwd.gif"/>';
	h = h + '<table cellspacing="1" cellpadding="0" border="0">';
	$('form > div',f.parent).each(function(t) {
		if (i = $('input',this).get(0)) {
			h = h + '<tr class="fieldSet" valign="top">'
			switch (i.type) {
				case 'text':
					h = h + '<td class="label">' + $('.label',this).text() + '</td>';
					h = h + '<td class="value">&nbsp;' + i.value + '</td>';
					break;
				case 'checkbox':
					h = h + '<td class="checkbox"><input type="checkbox" value="1"' + (i.checked?' checked="checked"':'') + ' name="11"/></td>';
					h = h + '<td class="checkboxlabel">' + $('.checkboxLabel',this).text() + '</td>';
					break;
			}
			h = h + '</tr>';
		} else if (i = $('select',this).get(0)) {
			h = h + '<tr class="fieldSet" valign="top">'
			h = h + '<td class="label">' + $('.label',this).text() + '</td>';
			h = h + '<td class="value">' + (i.options[i.selectedIndex].value !=""?i.options[i.selectedIndex].text:'') + '</td>';
			h = h + '</tr>';
		} else if (i = $('.dnListHeaderCollapse',this).get(0)) {
			h = h + '<tr class="header">'
			h = h + '<td colspan="2"><div>' + $(this).text() + '</div></td>';
			h = h + '</tr>';			
		} else {
			h = h + '<tr class="fieldSet" valign="top">'
			h = h + '<td class="label">' + $('.label',this).text() + '</td>';
			h = h + '<td class="value">' + $('.field',this).text() + '</td>';
			h = h + '</tr>';
		}
	}); 
	h = h + '<tr class="">'
	h = h + '<td colspan="2"></td>';
	h = h + '</tr>';			
	h = h + '</table>';
	h = h + '<img id="imgLogoNAQ" height="61" width="208" alt="" src="/fileadmin/template/images/logo_dn_naq.png"/>';
	h = h + '<script type="text/javascript">function p() {window.print();} setTimeout("p()",500);</script>';
	h = h + '</body></html>';
	h = h + '';
	newwindow=window.open('','newwindow','height=600,width=500');
	if (newwindow) {
		newwindow.document.write(h);
		newwindow.document.close();
		if (window.focus) {newwindow.focus()}
	} else {
		alert("Funkcja niedostępna: Nowe okienko zostało zablokowane przez przeglądarkę.");
	}
}
function maximizeHeight(o){ 
	alert(o);
	var htmlheight = document.body.parentNode.clientheight; 
	var windowheight = window.screen.height; 
	var frame = document.getElementById("frame1"); 
	if ( htmlheight < windowheight ) 
		{ o.style.height = windowheight + "px"; } 
} 

