function cauta() {
	
	var oras=document.getElementById('localitate');
	
	var tip=document.getElementById('tip_imobil');
	
	var doresc=document.getElementById('doresc_sa');
	
	var minim=document.getElementById('minim');
	
	var maxim=document.getElementById('maxim');
	
	var cuvinte=document.getElementById('cuvinte');
	
	var poze=document.getElementById('poze');
	
	var agentii=document.getElementById('agentii');
	
	
	if (oras.value.length==0) oras1="oricare";
				else oras1=oras.value;
	
	if (tip.value.length==0) tip1="oricare";
				else tip1=tip.value;
				
	if (doresc.value.length==0) doresc1="oricare";
				else doresc1=doresc.value;	

	if (minim.value.length==0) minim1="oricare";
				else minim1=minim.value;
	
	if (maxim.value.length==0) maxim1="oricare";
				else maxim1=maxim.value;
	
	if (cuvinte.value.length==0) cuvinte1="oricare";
				else cuvinte1=cuvinte.value;
	
	if (poze.value.length==0) poze1="oricare";
				else poze1=poze.value;
	
	if (agentii.value.length==0) agentii1="oricare";
				else agentii1=agentii.value;
	
//	var locatie="cautare.html?localitate="+oras.value+"&minim="+minim.value+"&maxim="+maxim.value+"&tip="+tip.value+"&doresc_sa="+doresc.value+"&cuvinte="+URLEncode(cuvinte.value);
	
	
	var locatie="/anunturi/"+oras1+"/"+minim1+"/"+maxim1+"/"+tip1+"/"+doresc1+"/"+URLEncode(cuvinte1)+"/"+poze1+"/"+agentii1+".html";
	
	this.location.href=locatie;
	
	
	
}



function encode(string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	}
	
	
	function URLEncode(sir)
{
	
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = sir;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	 
	return encoded;
};



function URLDecode(sir )
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = sir
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
;
   return plaintext;
};

function ia_vezi() {
	var p1=document.getElementById('at1');
	var p2=document.getElementById('at2');
	var p3=document.getElementById('at3');
	var p4=document.getElementById('at4');
	var p5=document.getElementById('at5');
	var p6=document.getElementById('at6');
	var p=document.getElementById('doresc');
	
	
	
	if ((p.value==2) || (p.value==3)) {
		p1.disabled=false;
		p2.disabled=false;
		p3.disabled=false;
		p4.disabled=false;
		p5.disabled=false;
		p6.disabled=false;
		
			}
			else 
			{
		p1.disabled=true;
		p2.disabled=true;
		p3.disabled=true;
		p4.disabled=true;
		p5.disabled=true;
		p6.disabled=true;
			}
}

function cere_oferta()  {
	var op=document.getElementById('doresc_sa2');
	var tip=document.getElementById('tip_imobil2');
	var pret=document.getElementById('pret_maxim2');
	var contact=document.getElementById('contact');
	var oras=document.getElementById('localitate2');
	
	var er="";
	
	if (contact.value.length<6) er="Datele de contact trebuie sa contina cel putin 6 caractere!";
	if (pret.value.length<2) er="Pretul trebuie sa contina cel putin 2 caractere!";
	
	if (er.length>0) {alert(er);}
		else{document.fr.submit();}
	
	
}

function sortare(linc)
{
	var dupa=document.getElementById('dupa');
		this.location.href=linc+"/sortare_"+dupa.value+".html";
	
}

function newsletter()
{
	
	var mail=document.getElementById('mail');
		ajaxpage("/module/newsletter_add.php?email="+URLEncode(mail.value),"news");
	alert("E-mail adaugat cu succes in lista!\n Va multumim,");	
	
}

function calculeaza()
{
	
var	v=document.getElementById('valoarea');
var	d=document.getElementById('dobanda');
var	n=document.getElementById('perioada');
var	r=document.getElementById('rate');
var	m=document.getElementById('moneda');
ajaxpage("/module/rezultat.php?v="+v.value+"&d="+d.value+"&n="+n.value+"&r="+r.value+"&m="+m.value,"rezultat");
	
	
}

function dimlogin()
{ 
	var login2=document.getElementById('login2');
	var ics=document.getElementById('ics');
	
	if (ics.innerHTML=='+')  {login2.style.display="block";
						 ics.innerHTML="-";	
								}
							else
	{login2.style.display="none";
						 ics.innerHTML="+";	
							}		
	
							
}