var d=document;

function searchFormCheck(id_prefix) {

    this.skipinvcheck = false;
		this.p = id_prefix;
		this.check_kind = function(f) {
					var kinds = f.rodzaj_nieruchomosci;
					for (var i=0; i<kinds.length; i++) 
						if (kinds[i].checked) {
							var unused = document.getElementById((kinds[i].value == 1) ? this.p+'cena_wynajem':this.p+'cena_sprzedaz');
							var used = document.getElementById((kinds[i].value == 2) ? this.p+'cena_wynajem':this.p+'cena_sprzedaz');
							unused.style.display = 'none';
							used.style.display = 'block';
							unused.disabled = 'disabled';
							used.disabled = false;
							
						}
			}
		this.show= function (a){
					for (i=0; i<arguments.length; i++){
						if (elm = document.getElementById(this.p+arguments[i])) {
							elm.style.display='';
							this.toggleVisibility(elm,0);
						}
	
					}
				}
		this.hide= function (a){
					for (i=0; i<arguments.length; i++){
						if (elm = document.getElementById(this.p+arguments[i])) {
							elm.style.display='none';
							this.toggleVisibility(elm,1);
						}
					}
				}
		this.check_investment = function(f) {
		  
		  if (f.invest.checked && f.typ_nieruchomosci.value == 1) {
		    this.show('buildyear','area','invlist','market_type','pricem2');
		    this.hide('floors','groundtop','rooms','forjustmarried','forfamily','forinvest','plotarea','houseplotarea','usetypeid');
		    this.toggleVisibility(document.getElementById('invlist'),0,'all');
              // checkbox invlist disabled separately	
		    this.skipinvcheck = false;
	      } else {
	        this.check_type(f);
	      }
	    }
		
		this.check_market_type= function (f){
			if(f.market_type.value==1) f.invest.checked=true;
		}
		
		this.check_rkind = function (f) {
		  
    }
		
		this.check_type= function (f){

					type = f.typ_nieruchomosci.value;
				
        	// rkind check
        	/* valid for radio only*/
        	/*
					for (i=0;i<f.rodzaj_nieruchomosci.length;i++) {
            if (f.rodzaj_nieruchomosci[i].checked) {
                rkind = f.rodzaj_nieruchomosci[i].value;
            }
          } 
          */
          /* valid for selects */
          rkind = f.rodzaj_nieruchomosci.value;
	
					switch (type) {
						case '1':
						  if (!this.skipinvcheck && rkind == 1) {
						    this.skipinvcheck = true;
						    this.check_investment(f);
						    return;
						  }
						  this.skipinvcheck = false;
							this.show('floors','groundtop','buildyear','rooms','area','forsingle','forjustmarried','forfamily','forinvest','market_type','invlist');	
							this.hide('plotarea','houseplotarea','usetypeid','pricem2','devlocal');
							this.toggleVisibility(document.getElementById('invlist'),0,'all');
              // checkbox invlist disabled separately		
						break;
						case '2':
							this.show('houseplotarea','buildyear','rooms','area','market_type');
							this.hide('floors','groundtop','forsingle','forjustmarried','forfamily','forinvest','plotarea','usetypeid','invlist','pricem2','devlocal');
							this.toggleVisibility(document.getElementById('invlist'),1,'all');
              // checkbox invlist disabled separately				
						break;
						case '3':
							this.show('plotarea','usetypeid');
							this.hide('floors','groundtop','buildyear','rooms','area','forsingle','forjustmarried','forfamily','forinvest','houseplotarea','market_type','invlist','pricem2','devlocal');
							this.toggleVisibility(document.getElementById('invlist'),1,'all');
              // checkbox invlist disabled separately					
						break;
						case '4':
							this.show('plotarea','usetypeid','price','area','buildyear','devlocal');
							this.hide('usetypeid','plotarea','floors','groundtop','rooms','forsingle','forjustmarried','forfamily','forinvest','houseplotarea','market_type','invlist','pricem2');
						break;
						case '5':
						case '6':
							// hala/magazyn
							this.show('plotarea','usetypeid','price','buildyear','area');
							this.hide('usetypeid','plotarea','floors','groundtop','rooms','forsingle','forjustmarried','forfamily','forinvest','houseplotarea','market_type','invlist','pricem2','devlocal');
							this.toggleVisibility(document.getElementById('invlist'),1,'all');
						break;
					}
				
					
  		
  		  switch (rkind) {
    		  case '1':
            this.hide('rentincl');
    		    break;
    		  case '2':
    		    
            this.show('rentincl','price');
    		    this.hide('pricem2','market_type','invlist','forjustmarried','forfamily','forinvest','usetypeid');
    		    f.invest.checked=false;
    		    f.market_type.value = '';
    		    break;
  		  }
					
					
			}
		this.clearExtended= function (){
		
					var elem = document.getElementById(this.p+'ext_form');
					if (elem.style.display != 'none') return;
					// extended search is hidden so we can clear the data
					this.toggleVisibility(elem,1,'all');
					
					
				}
		this.toggleVisibility= function(el,dis,what){
		      var i=0;
					var els = el.getElementsByTagName('input');

					for (i=0; i<els.length;i++){
					  if (what != 'all' && els[i].name == 'invest')
              continue;  
					    // don't change disabled property for the 'list investment' checkbox. this is controlled separately
					 	     els[i].disabled = (dis) ? true : false;
						
					}
					var els = el.getElementsByTagName('select');
					for (i=0; i<els.length;i++){
						els[i].disabled = (dis) ? true : false;
					}
					
				}
		this.showRelevantCities = function(pr) {
					cit = document.getElementById(this.p+"cities");
					cit.innerHTML = '';
					opt = document.createElement("option");
					opt.value = '';
					opt.text = '- wybierz -';
					cit.options.add(opt);
					for (i=0; i<this.cities.length; i++) {
						if (this.cities[i]["province"] == pr || !pr) {
							opt = document.createElement("option");
							opt.value = this.cities[i]["city"];
							opt.text = this.cities[i]["city"];
							cit.options.add(opt);
						}
					}
					//alert(cit.options);
				}
}

function goTo (l) {
	location.href=l;
}
function changeBg (el) {
	el.style.backgroundColor = '#ffecec';
}
function changeBgTr (el) {
	el.style.backgroundColor = 'white';
}
function addbookmark(bookmarkurl, bookmarktitle, title, path) {
	if (document.all) {
		
		document.write('<a href="javascript:window.external.AddFavorite(\''+bookmarkurl+'\',\''+bookmarktitle+'\');');
		document.write('">'+ title +'');
		document.write('<br>');
		document.write('<img src="'+ path +'/i/ico/bookmark.png" width="24" height="18" alt="" border="0"></a>');
	
	}
		
}
function startWithUs(s_url, s_mouseo, s_text, path) {

	if (document.all) {
			document.write('<a href="javascript:void(0);" ');
			document.write('onclick="this.style.behavior=');
			document.write("'url(#default#homepage)'");
			document.write("; this.setHomePage('"+s_url+"');");
			document.write('">'+ s_text +''); 
			document.write('<br>');
			document.write('<img src="'+ path +'/i/ico/start.png" width="19" height="16" alt="" border="0"></a>');

		}
		
}

function okienkoImg(urlImg, title, width, height) {   
	var width = parseInt(width);
	var height = parseInt(height);
	var width = (isNaN(width) ? 420 : width+20);
	var height = (isNaN(height) ? 420 : height+20);
 
	var Win = window.open('',"",'width=' + width + ',height=' + height + ',resizable=0,scrollbars=no, menubar=no, left=350, top=100' );
	Win.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>'+title+'</title></head><body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">');
	
	Win.document.write('<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align=center><table style="padding:4px;border:silver 1px solid"><tr><td><a href="javascript:self.close();"><img src="'+urlImg+'" alt="" border="0"></a></td></tr></table></td></tr></table>');
	Win.document.write('</body></html>');
	
};

function addComment (par, user, ident, identId) {
	if(!user) {
		referer = '';
		if(ident == 'OFFER')
			referer="?referer=offer.php%3FidCnt%3D"+identId;
		if(ident == 'GUESTBOOK')
			referer="?referer=guestbook.php";

		location.href="login.php" + referer;
	} else {
		//window.open(
		location.href='forumPopUp.php'+par;//,'forum','align=center,toolbar=0,status=1,location=0,directories=0,resizable=yes,scrollbars=yes,width=420,height=320,menubar=no';
		
	}
}


function printWindow(url){ 
	 w = window.open(url,'printWin','align=center,toolbar=0,status=1,location=0,directories=0,resizable=yes,scrollbars=yes,width=700,height=500,menubar=yes')
	 w.focus();
} 

function okienko_img(urlImg, title, width, height) {    
	var Win = window.open('',"displayWindow",'width=' + width + ',height=' + height + ',resizable=0,scrollbars=no, menubar=no, left=350, top=100' );
	Win.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>'+title+'</title></head><body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">');
	
	Win.document.write('<a href="javascript:self.close();"><img src="'+urlImg+'" alt="" border="0"></a>');
	Win.document.write('</body></html>');
	Win.document.close();
	
};

function checkFloat (field) {
	field.value = field.value.replace(",",".");
	if(isNaN(field.value)) {
		alert('Wrong digit: ' + field.value)
		field.value = '';
	}
}

function checkSendTo (f, calert, emailalert) {
	if(
		f.RecipientName.value != ''
		&& f.FirstName.value != ''
		&& f.LastName.value != ''
		&& checkEmailAddress(f.RecipientEmail)
		&& checkEmailAddress(f.Mail)
	) {
		f.submit();
	} else {
		if(!checkEmailAddress(f.RecipientEmail) || !checkEmailAddress(f.Mail)) {
			alert(emailalert);
		} else {
			alert(calert);
		}
	}
}


function checkQuestion (f, calert, emailalert) {
	if(
		f.FirstName.value != ''
		&& f.LastName.value != ''
		&& f.Question.value != ''
		&& checkEmailAddress(f.Mail)
	) {
		f.submit();
	} else {
		if(!checkEmailAddress(f.Mail)) {
			alert(emailalert);
		} else {
			alert(calert);
		}
	}
}d

function checkBrochure(f, calert, emailalert) {
	if(
		f.txtLast.value != ''
		&& f.txtFirst.value != ''
		&& f.txtCompany.value != ''
		&& checkEmailAddress(f.txtEmail)
	) {
		f.submit();
	} else {
		if(!checkEmailAddress(f.txtEmail)) {
			alert(emailalert);
		} else {
			alert(calert);
		}
	}
}

function checkNewslleter(f, calert, emailalert) {
	if(
		f.adtFirst.value != ''
		&& f.adtLast.value != ''
		&& f.adtCompany.value != ''
		&& checkEmailAddress(f.email)
	) {
		f.submit();
	} else {
		if(!checkEmailAddress(f.email)) {
			alert(emailalert);
		} else {
			alert(calert);
		}
	}
}

function checkJoinUsForm(f, calert, emailalert) {
	if(
		f.nazwa.value != ''
		&& f.imie.value != ''
		&& f.addr.value != ''
		&& f.kodm.value != ''
		&& checkEmailAddress(f.email)
	) {
		f.submit();
	} else {
		if(!checkEmailAddress(f.email)) {
			alert(emailalert);
		} else {
			alert(calert);
		}
	}
}

function checkEmailAddress(field) {
	var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
	
	if (goodEmail){
	  return true
	} else {
    field.focus()
    field.select()
    return false
  }
}
function OverButton(obj,img){
	obj.childNodes[0].src='data/l/'+img;
}
function OutButton(obj,img){
	obj.childNodes[0].src='data/l/'+img;
}
function ClickButton(objimg){
	obj.childNodes[0].src='data/l/'+img;
}





function hideElement(id) {
	var o = document.getElementById(id);
	if(o.style) {
		o.style.display = 'none';
	}
}
function showElement(id) {
	var o = document.getElementById(id);
	if(o.style) {
		o.style.display = '';
	}
}

function selectCountry (idC) {
	var f = document.searchForm;
	if(f) {
		var box = f.ctgRootId;
		for(i=0;i<box.options.length;i++) {
			if(box.options[i].value == idC) {
				box.selectedIndex = i;
			}
		}
	} else {
		location.href='index.php?ctgRootId='+idC + '&ustaw_mape='+idC;
	}
}


function javascript_to_flash(id, xx, yy) {
	var id = (id == null) ? document.searchForm.ctgRootId.value : id;
	var xx = (xx == null) ? false : xx;
    var yy = (yy == null) ? false : yy;
//if(navigator.appName.toLowerCase() == "microsoft internet explorer") alert("Microsoft Internet Explorer");
	//var id = document.searchForm.ctgRootId.value;
	//alert(thisMovie("logo"));
	if(xx & yy){
		thisMovie("logo").asFunc(id,xx,yy);
	} else {
		thisMovie("logo").asFunc(id);
	}
	//
	flash=document.logo;
	flash.SetVariable("region_id", id);
	//alert(id);
}

function thisMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	//alert(isIE);
	return (isIE) ? window[movieName] : document[movieName];
}

function set_cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

function get_cookie( name ) {
	
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}
/*
function toggleRecommended(){
	r = document.getElementById("recommended");
	if (!r) return false;
	divs = r.getElementsByTagName("div");
	ros = [];
	
	for (i=0; i<divs.length; i++) {
		if (divs[i].className=='relements') ros.push(divs[i]);
	}
	for (i=0; i<ros.length; i++) 
		if (ros[i].style.display == 'block') {
			ros[i].style.display = 'none';
				if (ros[i+1]) {
					ros[i+1].style.display = 'block';
					set_cookie('rindex',i+1, '', '/', '', '');
				}
				else {
					ros[0].style.display = 'block';
					set_cookie('rindex',0, '', '/', '', '');
				}
			break;
		}
	
}
*/
function fillRecommended(d){
	if (d == 'no_data') {
		_rindex = -1;
		toggleRecommended();
	} else {
		r = document.getElementById("rcontents");	
		r.innerHTML = d;
		set_cookie('rindex',_rindex,'','/');
	}
}
function toggleRecommended(){
	
	_rindex++;
	ajax.get(_path+'offer_recommended_get_data.php?rindex='+_rindex,fillRecommended);
	
}

function showReplyForm(id){
	var p = document.getElementById('reply'+id);
	var b = document.getElementById('replybutton'+id);
	p.style.display='block';
	b.style.display='none';
}
function hideReplyForm(id){
	var p = document.getElementById('reply'+id);
	var b = document.getElementById('replybutton'+id);
	p.style.display = 'none';
	b.style.display = 'block';
}

// ajax aktowka
	var ObiektXMLHttp = false;
	if (window.XMLHttpRequest) {
		ObiektXMLHttp = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		ObiektXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	function getMsg(src, content)
		{
		if(ObiektXMLHttp) {
		ObiektXMLHttp.open("GET", src);
		ObiektXMLHttp.onreadystatechange = function()
		{
		if (ObiektXMLHttp.readyState == 4) {

		document.getElementById(content).innerHTML = ObiektXMLHttp.responseText;
//		document.getElementById('total_223').innerHTML = ObiektXMLHttp.responseText;
//		document.getElementById('total1').innerHTML = ObiektXMLHttp.responseText;
		}
		}
		ObiektXMLHttp.send(null);
		}
		}