	/*
	 * $Id: szybkomieszkanie.js 12947 2011-08-02 14:53:41Z twardowski $
	 */

  
function changeStatus(value) {	
	if(value=="firma") selectedFirma();
	if(value=="osoba") selectedOsoba();
}

function selectedFirma() {
	document.getElementById('c_name').disabled=false;
	document.getElementById('c_address').disabled=false;
	document.getElementById('c_city').disabled=false;
	document.getElementById('c_RegionId').disabled=false;
	document.getElementById('c_nip').disabled=false;
	document.getElementById('c_nip').style.backgroundColor='#ffffff';
	document.getElementById('c_nip').value='';
	document.getElementById('c_regon').disabled=false;
	document.getElementById('c_regon').style.backgroundColor='#ffffff';
	document.getElementById('c_regon').value='';
	document.getElementById('c_code').disabled=false;
}

function selectedOsoba() {
	document.getElementById('c_name').disabled=false;
	document.getElementById('c_address').disabled=false;
	document.getElementById('c_city').disabled=false;
	document.getElementById('c_RegionId').disabled=false;
	document.getElementById('c_nip').disabled=true;
	document.getElementById('c_nip').style.backgroundColor='#dddddd';
	document.getElementById('c_regon').disabled=true;
	document.getElementById('c_regon').style.backgroundColor='#dddddd';
	document.getElementById('c_regon').value='';
	document.getElementById('c_code').disabled=false;
}

function nonSelected() {
	document.getElementById('c_name').disabled=true;
	document.getElementById('c_address').disabled=true;
	document.getElementById('c_city').disabled=true;
	document.getElementById('c_RegionId').disabled=true;
	document.getElementById('c_nip').disabled=true;
	document.getElementById('c_regon').disabled=true;
	document.getElementById('c_code').disabled=true;
}

function dodajDoUlubionych(url, opis) {
    window.external.AddFavorite(url, opis);
}


function popUp(URL, params) {
//	params='toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=820,height=650';
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', params);");
}


function template_popup(TemplateId) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('popup/template.php?TemplateId="+TemplateId+"', '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=300');");
}

//really not important (the first two should be small for Opera's sake)
PositionX = 10;
PositionY = 10;
defaultWidth  = 600;
defaultHeight = 400;

//kinda important
var AutoClose = false;

//don't touch
function popImage(imageURL,imageTitle){
	var imgWin = window.open('','_blank','scrollbars=no,resizable=1,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY);
	if( !imgWin ) { return true; } //popup blockers should not cause errors
	imgWin.document.write('<html><head><title>'+imageTitle+'<\/title><script type="text\/javascript">\n'+
		'function resizeWinTo() {\n'+
		'if( !document.images.length ) { document.images[0] = document.layers[0].images[0]; }'+
		'var oH = document.images[0].height, oW = document.images[0].width;\n'+
		'if( !oH || window.doneAlready ) { return; }\n'+ //in case images are disabled
		'window.doneAlready = true;\n'+ //for Safari and Opera
		'var x = window; x.resizeTo( oW + 200, oH + 200 );\n'+
		'var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;\n'+
		'if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight; }\n'+
		'else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }\n'+
		'else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }\n'+
		'if( window.opera && !document.childNodes ) { myW += 16; }\n'+
		'x.resizeTo( oW = oW + ( ( oW + 200 ) - myW ), oH = oH + ( (oH + 200 ) - myH ) );\n'+
		'var scW = screen.availWidth ? screen.availWidth : screen.width;\n'+
		'var scH = screen.availHeight ? screen.availHeight : screen.height;\n'+
		'if( !window.opera ) { x.moveTo(Math.round((scW-oW)/2),Math.round((scH-oH)/2)); }\n'+
		'}\n'+
		'<\/script>'+
		'<\/head><body onload="resizeWinTo();"'+(AutoClose?' onblur="self.close();"':'')+'>'+
		(document.layers?('<layer left="0" top="0">'):('<div style="position:absolute;left:0px;top:0px;display:table;">'))+
		'<img src='+imageURL+' alt="Loading image ..." title="" onload="resizeWinTo();">'+
		(document.layers?'<\/layer>':'<\/div>')+'<\/body><\/html>');
	imgWin.document.close();
	if( imgWin.focus ) { imgWin.focus(); }
	return false;
}

function scroller(AdId) {
			obiekt = document.getElementById(AdId);
			if(obiekt){
				how = obiekt.offsetTop+obiekt.offsetParent.offsetTop+obiekt.offsetParent.offsetParent.offsetTop;
				window.scrollBy(0,how); 
			}	
}

//////////////////////////////////////////////

this.imagePreview = function(){    
	jQuery("a.preview").hover(function(e){
  
        this.t = this.title;
        this.title = "";    
    
    var x = jQuery(this).offset().left;
    var y = jQuery(this).offset().top;
    
    
    //sprawdzam zeby zawsze na ekranie sie wyswietlalo
    var docViewTop = jQuery(window).scrollTop();
    var docViewBottom = docViewTop + jQuery(window).height();

    pos_y = y - 150;
    if (pos_y < docViewTop) pos_y = docViewTop + 10;
    if (docViewBottom < pos_y + 570) pos_y = docViewBottom - 570;
    
    
        var c = (this.t != "") ? "<br/>" + this.t : "";
        jQuery("body").append("<p id='preview'><img id='pwksz' src='"+ this.href +"' alt='Powi&#281;kszenie zdj&#281;cia' />"+ c +"</p>");                                 
        jQuery("#preview")
            .css("top",  pos_y + "px")
            .css("left", (x+100) + "px")
            .fadeIn("fast");    
            
        jQuery('img#pwksz').zoom('500px', '600px');                    
    },
    function(){
        this.title = this.t;    
        jQuery("#preview").remove();
    });    
        
};
jQuery(document).ready(function(){
    imagePreview();
});  
jQuery.fn.zoom = function(height, width) {
  if (!width && height) {
    width = height;
  } else if (!width && !height) {
    width = height = '100%';
  }
  
  function toem(px) {
    px = parseFloat(px);
    return (px * 0.0626).toString() + 'em';
  }
  
  function getLen(elm, side, target) {
    var l = 1;
    if (target.indexOf('%') === -1) {
      l = toem(target);
    } else {
      l = toem(elm[side] * (parseFloat(target)/100));
    }
    
    return l;
  }
  
  return this.each(function() {
    var hem = getLen(this, 'height', height);
    var wem = getLen(this, 'width', width);
    
    jQuery(this).css({ height: hem, width: wem });
  });
  
};


function toggleEditor(id) {
	if (!tinyMCE.get(id)){
		//alert(id+'!tinyMCE.get(id)');
		tinyMCE.execCommand('mceAddControl', false, id);
	} else {
		//alert(id);
		tinyMCE.execCommand('mceRemoveControl', false, id);
	}
}
function setDescription(id,text){
	document.getElementById(id).value=text;
	if(tinyMCE.get(id)){
		var editor=tinyMCE.get(id);
		editor.setContent(text);
	}
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

this.imagePreview1 = function(){	
	var tm;
	var mouseover = false;	
	jQuery('a.preview1').hover(
			function(){ mouseover = true;},
			function(){	mouseover = false;}
		);
	
	jQuery("a.preview1").hover(function(e){
		

			
		
		
		
		clearTimeout(tm);
		jQuery('#preview').remove();
		
		this.t = this.title;
		this.title = "";	
    
		var x = jQuery(this).offset().left;
		var y = jQuery(this).offset().top;    
    
		//sprawdzam zeby zawsze na ekranie sie wyswietlalo
		var docViewTop = jQuery(window).scrollTop();
		var docViewBottom = docViewTop + jQuery(window).height();

		pos_y = y - 150;
		if (pos_y < docViewTop) pos_y = docViewTop + 10;
		if (docViewBottom < pos_y + 420) pos_y = docViewBottom - 420;
    
		var pics = this.rel.split(",");
		//alert(pics[0]);
    
		var c = (this.t != "") ? "<br/>" + this.t : "";
		jQuery("body").append("<div id='preview'><table border=\"0\"><tr><td><a href=\""+this.href+"\"><img border=\"0\" src='"+ pics[0] +"' alt='Image preview' id='previmg' style=\"width:400px;height:auto;padding-bottom:13px;border-bottom:dotted 1px #666;margin-bottom:10px\" /></a>"+ c +"</td><td valign=\"top\" style=\"width:80px;vertical-align:top;\">"+ (pics[0]!=''?'<a href="'+this.href+'"><img class=\"smallpc\" src="'+pics[0]+'" /></a>'+"<br />":'') +""+ (pics[1]!=''?'<a href="'+this.href+'"><img src="'+pics[1]+'" class=\"smallpc\" /></a>'+"<br />":'') +""+ (pics[2]!=''?'<a href="'+this.href+'"><img src="'+pics[2]+'" class=\"smallpc\" /></a>'+"<br />":'') +""+ (pics[3]!=''?'<a href="'+this.href+'"><img src="'+pics[3]+'" class=\"smallpc\" /></a>'+"<br />":'') +"</td></tr></table></div>");

		jQuery(".smallpc").hover(function(){ jQuery('#previmg').attr("src", jQuery(this).attr("src"));  },function(){});

		
		
		setTimeout( function(){ if(mouseover!=false){    
	
		jQuery("#preview")
			.css("top",  pos_y + "px")
			.css("left", (x+160) + "px")
			.fadeIn("fast");	
		}}, 200 );
		
		jQuery("#preview").hover(function(e){
			clearTimeout(tm);	
		},
		function(){
			tm = setTimeout("jQuery('#preview').remove();", 1000);
	    });	
    },
	function(){
    	if(this.t!='' && this.t!=null && this.t!='undefined')
		this.title = this.t;			
		tm = setTimeout("jQuery('#preview').remove();", 1000);
    });			
};

this.mapPreview = function(){	
	var tm;
	jQuery("a.mapp").hover(function(e){
    
		clearTimeout(tm);
		jQuery('#preview').remove();
		    
		var x = jQuery(this).offset().left;
		var y = jQuery(this).offset().top;    
    
		//sprawdzam zeby zawsze na ekranie sie wyswietlalo
		var docViewTop = jQuery(window).scrollTop();
		var docViewBottom = docViewTop + jQuery(window).height();

		pos_y = y - 150;
		if (pos_y < docViewTop) pos_y = docViewTop + 10;
		if (docViewBottom < pos_y + 400) pos_y = docViewBottom - 440;
		       
		jQuery("body").append("<div id='preview'><iframe width=\"480\" height=\"450\" src="+this.rel+">map</iframe></div>");
		
		jQuery("#preview")
			.css("top",  pos_y + "px")
			.css("left", (x-490) + "px")
			.fadeIn("fast");	
		
		jQuery("#preview").hover(function(e){
			clearTimeout(tm);			
		},
		function(){
			tm = setTimeout("jQuery('#preview').remove();", 1000);
	    });	
    },
	function(){
		this.title = this.t;			
		tm = setTimeout("jQuery('#preview').remove();", 1000);
    });			
};


jQuery(document).ready(function(){
	mapPreview();
	imagePreview1();
	jQuery('input[rel="autoFixInt"]').change(function(){
		var tekst = new String(jQuery(this).val());
		var wzor = /[^\d]*([\d]+)(?:[\.\,]([\d]+))?.*/;
		var zamieniony = tekst.replace(wzor, "$1.$2");
		//alert(zamieniony);
		jQuery(this).val(Math.ceil(parseFloat(zamieniony)));
	});
});





