﻿function window_open_parametrs(el){
	var r = $(el).attr('rel').split('&');
	var n=window.open (r[0],"podglad","toolbar=no,fullscreen=no,width=" + r[1] + ",height=" + r[2] + "directories=no,status=n,resizable=yes,menubar=no,scrollbars=no");
	n.focus();
	return false;	
}

function image_change(dst, src){
	var dst_img = $(dst).children('img');
	var dst_description = $(dst).children('span');
	$(src).each(function(){
		var el = this;
		$(this).parent().mouseover(function(){
			$(dst_img).attr('src',$(el).attr('rev'));
			$(dst_description).text($(el).attr('title'));
		});
		$(this).parent().mouseout(function(){
			$(dst_img).attr('src', $(dst).attr('rev'));
			$(dst_description).text($(dst).attr('title'));
		});
		$(el).click(function(){
			return window_open_parametrs(el);
		});
	})
	$(dst).click(function(){
		return window_open_parametrs(dst);
	});
}

function set_first_visible(el){
	$(el).hide();
	$($(el)[0]).show();
}
var prj_ver = 'podstawowa';
function block_change(divs, as){
	$(as).click(function(){
		if ($(this).attr('href') == '#') { return; }
        $(divs).hide();
		$($(this).attr('href')).show();
		prj_ver = $(this).attr('href').replace('#','');
		//zmiana rzutow
		var img_wersje = ['rzuty_projekt', 'przekroj_projekt', 'dzialka_img', 'plan_syt'];
		for (x = 0; x < img_wersje.length; x++) {
		    if ($('#' + img_wersje[x]).length > 0){
			$('#' + img_wersje[x]).children().hide();
			$('#' + img_wersje[x] + '_' + prj_ver).show();
		    }
		}
        $('#id_span_symbol_prj_l').html((prj_ver == 'lustrzana') ? lustro_litera : '');
		/*
		if ($('#przekroj_projekt').length > 0){
			$('#przekroj_projekt').children().hide();
			$('#przekroj_projekt_' + ver).show();
		}
		if ($('#dzialka_img').length > 0){
			$('#dzialka_img').children().hide();
			$('#dzialka_img_' + ver).show();
		}
		if ($('#plan_syt').length > 0){
			$('#plan_syt').children().hide();
			$('#plan_syt_' + ver).show();
		}*/
		return false;
	});
}

function content_change(id){
	var buttons = $('a.' + id + '_button');
	var contents = $('.' + id + '_content');
	$(contents).hide();
	$($(contents)[0]).show();
	$(buttons).click(function(){
		$(buttons).attr('class', id + '_button');
		$(contents).hide();
		$(this).attr('class', $(this).attr('class') + ' active');
		$($(this).attr('href')).show();
		return false;
	});
}
var curr_group_prj;
$(document).ready(function(){
	//START zmiana obrazkow na projekt_dom
	image_change('.rzuty #podstawowa .big a', '.rzuty #podstawowa .mini a');
	image_change('.rzuty #lustrzana .big a', '.rzuty #lustrzana .mini a');
	//block_change($('.rzuty').children(), $('.rzuty a.more'));
	block_change2($('.rzuty').children(), $('.rzuty span.SPANPTR.more'));
	set_first_visible($('.rzuty').children());
	//KONIEC zmiana obrazkow na projekt_dom
	
	//START zmiana cen brutto na projekt_dom
	var is_kosztorys = $('.kosztorys_btt a').length > 0;
	if (is_kosztorys){
		$('.kosztorys_btt a').hide();
		$($('.kosztorys_btt a')[0]).show();
	}
	$('#cena_brutto_select').change(function(){
		var v = $(this).val().split(',');
		var price = v[0];
		var id_cennika = v[1];
		var wariant = v[2];
		$('#cena_brutto_projekt').text(price + ' ');
		$('#zamow_projekt').attr('href','/koszyk?act=add&amp;id_cennika=' + id_cennika +'&amp;typ=dom');
		if (is_kosztorys){
			$('.kosztorys_btt a').hide();
			$('#kosztorys_' + wariant).show();
		}
	});
	//END zmiana cen brutto na projekt_dom
	
	//START zmiana contentow projektu
	$('#_projekt .group_projekt').hide();
	$($('#_projekt .group_projekt')[0]).show();
    curr_group_prj = $('#_projekt .group_projekt')[0].id;
    curr_group_prj = curr_group_prj.substring(0, curr_group_prj.length-8);
	$('.menu_projektu a').click(function(){
		$('#_projekt .group_projekt').hide();
		curr_group_prj = $(this).attr('href').substring(1);
        $($(this).attr('href') + '_projekt').show();
		return false;
	});
	//END zmiana contentow projektu
		
	//START zmiana dodatkowych informacji - zakres zmian i zawartosc pakietu
	content_change('menu_dodatkowe');
	//END zmiana dodatkowych informacji - zakres zmian i zawartosc pakietu
	
	$(window).scroll(function () { $('.submenu').hide(); $('#sm_2_li').attr('class', ''); $('#sm_1_li').attr('class', '') } );
});

function open_big(sym) {
	var key = sym+wariant_lustro+"D";
	var sz = size_map[key];
	if (_msie) {dx=24;dy=4;} else {dx=18;dy=16;}
	open_window('/pliki/'+img_map[key], sz[0]+dx, sz[1]+dx, "no");
	return false;
}

function hideById(id) { e=document.getElementById(id); if (e) e.style.display='none'; }
function showByIdBlk(id) { e=document.getElementById(id); if(e) e.style.display='block'; }

function switchPanel(s) { hideById('panel_'+current_panel);showByIdBlk('panel_'+s);current_panel=s; }
function showTip(s) {showByIdBlk('tip_'+s);}
function hideTip(s) {hideById('tip_'+s);}

function open_window(url, w, h, s) {
	var n=window.open (url,"podglad","toolbar=no,fullscreen=no,width=" + w + ",height="+h+",directories=no,status=n,resizable=yes,menubar=no,scrollbars="+s);
	n.focus();
	return false;
}

function show_img(id1,id2,txt) {
	var e=document.getElementById('mainview');
	var ident = id1+wariant_lustro+id2;
	old_src = e.src;
	e.src='/pliki/'+img_map[ident];
	document.getElementById('text_widok').innerHTML= txt + text_widok_suffix();
}

function reload_imgs() {
	var e=document.getElementById('mainview');
	e.src='/pliki/'+img_map['F'+wariant_lustro+'N'];
	e=document.getElementById('smallview1');
	if (e) e.src='/pliki/'+img_map['O'+wariant_lustro+'M'];
	e=document.getElementById('smallview2');
	if (e) e.src='/pliki/'+img_map['B'+wariant_lustro+'M'];
}

_el = function (id) {
    return document.getElementById(id);
}

function hide_element(id, hide)
{
    var el = _el(id);
    if (!el) { return; }
    el.style.display = (hide) ? 'none' : 'block';
}

function print_full()
{
	for (i=0; i<idy_panele.length; i++) {
		elt = document.getElementById(idy_panele[i]);
		if (elt) elt.className = "show_print";
	}

	window.print();
}

function print_view(id_prj, show_details)
{
    var group_prj = (show_details) ? curr_group_prj : '';
    window.open('/print_project.htm?grupa=1&IdProjektu=' + id_prj + '&curr_group='+group_prj+'&ver=' + prj_ver,'_blank','width=640,height=800,resizable=no,scrollbars=yes,status=no');
    return false;
}

function print_view_old()
{
	//$('.group_projekt').show();
	//window.print();
var win3=window.open('informacje.html','','width=640,height=800,scrollbars');

win3.document.write('<html><head>');
win3.document.write($('head').html());
win3.document.write('</head><body><div id="main_center" class="projectpage"><div style="text-align: center;" class="print_ico"><a href="#" title="drukuj" onclick="window.print(); return false;"><img src="/images/printer_48.png" alt="drukuj" /><br />drukuj</a></div><br />');
//content = $('#id_print_header').html();
clss = ['nazwa_projektu', 'clear', 'szczegoly_projektu', 'clear', 'big_buttons', 'clear'];
for (x = 0; x < clss.length; x++) {
content = '<div class="' + clss[x] + '">' + $('.' + clss[x]).html() + '</div>';
content = content.replace(/<script[^>]*>.*?<\/script>/igm, '');
win3.document.write(content);
}
content = '<div id="_projekt">' + $('#_projekt').html() + '</div>';
content = content.replace(/<script[^>]*>.*?<\/script>/igm, '');
win3.document.write(content);

win3.document.write('</div></body></html>');
win3.document.close();

}

function preload_images()
{
	tmp = new Image();
	imgs = document.getElementsByTagName('img');
	for (i=0; i<imgs.length; i++) {
		e = imgs[i];
		if (e.className.indexOf("ppreload")!=-1) tmp.src = e.src;
	}
	for (k in img_map) tmp.src = '/pliki/'+img_map[k];
}
var handlerFunc = function(t) {		
    $('bloczek_kredyty').innerHTML = t.responseText;
}
var errFunc = function(t) {
    alert('Error ' + t.status + ' - ' + t.statusText);
}
function remoteGET(url) {
    url = url.replace(/&amp;/ig, '&');
    new Ajax.Request(url , {method:'get', asynchronous:true, evalScripts:true, onSuccess:handlerFunc, onFailure:errFunc});
}

function koszyk_aktywny(element, czy_aktywny)
{
    element.src = (czy_aktywny) ? '/images/pg_koszyk.gif' : '/images/pg_koszyk_off.gif';
}

function crtNwWindow(src, lang, w, h)
{
    var wnd = window.open('podglad','','width=' + w + ',height=' + h);
    wnd.document.write('<' + '?xml version="1.0" encoding="UTF-8"?' + '>\n<' + '!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"' + '>\n<' + 'html xmlns="http://www.w3.org/1999/xhtml" lang="pl"' + '><' + 'head' + '><' + 'meta http-equiv="content-type" content="text/html; charset=utf-8" /' + '><' + 'link rel="StyleSheet" href="http://projekty.muratordom.pl/styles/styles.css" type="text/css" /' + '><' + 'title' + '>' + lang['podglad'] + '<' + '/title' + '><' + '/head' + '><' + 'body' + '>');
    wnd.document.write('<' + 'span class="LNK"' + '><' + 'img id="image" alt="" src="' + src + '" onclick="window.close();" /' + '><' + '/span' + '>');
    wnd.document.write('<' + '/body' + '><' + '/html' + '>');
    wnd.document.close();
}

function show_image_window(src, lang)
{
    img = new Image()
    img.onload=function() { crtNwWindow(src, lang, this.width,this.height); }
    img.src = src;
}

function block_change2(divs, as){
	$(as).click(function(){
		var for_id = $(this).attr('id');
        if (for_id.substr(0, 10) != 'for_rzuty_') { return; }
        prj_ver = for_id.substr(10);
        $(divs).hide();
		$('#' + prj_ver).show();
		//zmiana rzutow
		var img_wersje = ['rzuty_projekt', 'przekroj_projekt', 'dzialka_img', 'plan_syt'];
		for (x = 0; x < img_wersje.length; x++) {
		    if ($('#' + img_wersje[x]).length > 0){
			$('#' + img_wersje[x]).children().hide();
			$('#' + img_wersje[x] + '_' + prj_ver).show();
		    }
		}
        $('#id_span_symbol_prj_l').html((prj_ver == 'lustrzana') ? lustro_litera : '');
		return false;
	});
}

