var fade_event;
function page_listing(search_id,page,sort_ord){
	new Ajax.Updater('cnt_left','http://www.imopedia.ro/listing-' + search_id + '-' + page + '-' + sort_ord+'.html',{
		method:'get',
		onCreate: function (){
			fade_event  = new Effect.Opacity('cnt_left',{ from: 1, to: 0.3, duration: 1.0 });
		},
		onSuccess:function (t){
			var r = 1;
			document.title = t.getHeader('Title');
			document.location.hash = page+'-'+sort_ord;
		//	('cnt_left').appear({duration:3});
			fade_event.cancel();
			new Effect.Opacity('cnt_left',{ from: 0.3, to: 1, duration: 1.0,queue:'end'  });
			Effect.ScrollTo('cnt_left');
//			Effect.Pulsate('cnt_left', { pulses: 2, duration: 1, queue:'end' })
//			Effect.Appear('cnt_left', {  })
		}.bind(this)
	});
	
	
	return false;
}

function validate_telefon(telefon_text){
	var reg = /^([\+0-9]{4,14})$/;
	if(reg.test(telefon_text) == false) {
      return false;
   }
   return true;
}
function validate_email(email_text)
{
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email_text) == false) {
      return false;
   }
   return true;
}
function search_agentie(val,filtru)
{
	if(val.length<3) return;
	url = "/index.php?section=ajax&screen=select_agentii";
	aj=new Ajax.Request(
		url, 
		{
			onSuccess:function(ob){
				resp = ob.responseText;
				if(resp.length>2) //am ales 2 fara un motiv anume. poate exista niste spatii in plus... puteam sa pun si 3 sau 4
				{
					$(filtru+'_agentia_cnt').style.display = '';
					$(filtru+'_agentia_cnt').innerHTML = resp;
				}
				else
					$(filtru+'_agentia_cnt').style.display = 'none';
			},
			method:"post",
			parameters:"t="+val+"&filtru="+filtru
		}
	   );	
}
function verify_email() {
		url = "/index.php?section=users&screen=verify_email";
		aj=new Ajax.Request(
							url, 
							{
								onCreate: function() {
									//$('verifica_email').update("Verificare adresa de e-mail ...");
								},
								onSuccess:function(ob){
									//$('verifica_email').update("Verificare realizata");
									if(ob.responseText==1)
									{
										$('login_main_cnt').style.display='';
										$('parola').focus();
									}
									else
									{
										$('login_main_cnt').style.display='none';
									}
									
								},
								method:"post",
								parameters:"email="+$('email').value
							}
						   );	
}

function mesaj_rezervare(id)
{
	error = "";
	if($("rezervare_mesaj").value=="")
	{
		error += "Nu ati introdus mesajul";
	}
	if(error!="") alert(error);
	else
	{
		url = "/index.php?section=users&screen=rezervare_mesaj";
		aj=new Ajax.Request(
							url, 
							{
								onSuccess:function(ob){alert(ob.responseText);},
								method:"post",
								parameters:"id="+id+"&mesaj="+$("rezervare_mesaj").value
							}
						   );
	}
}
function show_full_stars(i,total,object_type,img1_name,img2_name)
{
	for(j=1;j<=i;j++)
	{
		$(object_type+"_"+j).src="/images/"+img1_name+".gif";
	}
	for(j=i+1;j<=total;j++)
	{
		$(object_type+"_"+j).src="/images/"+img2_name+".gif";
	}
}
function hide_full_stars(total,object_type,img2_name)
{
	for(j=1;j<=total;j++)
	{
		$(object_type+"_"+j).src="/images/"+img2_name+".gif";
	}
}
function vote_object(object_id,nota){
	var url="/index.php?section=users&screen=vot_mesaj";
	new Ajax.Request (
		url,
		{
			onCreate: function() {$('votare').update("Se incarca ...");},
			onSuccess: function(resp) {$('votare').update(resp.responseText);},
			method:"post",
			parameters:"object_id="+object_id+"&nota="+nota
		}
	);				
}
function google_track(a,b,c,d)
{
	if(pageTracker) pageTracker._trackEvent(a,b,c,d); //_trackEvent(category, action, optional_label, optional_value)
//	pageTracker._trackPageview("/"+a+"/"+b+"/"+c+"/"+d);
}
function make_self_clearing(el)
{
		el.original_value = el.value
		Event.observe(el, 'focus', function()
		{
				if(el.value == el.original_value)
						el.value = '';
		});
		Event.observe(el, 'blur', function(ev)
		{
				if(el.value == ''){
						if(el.id.indexOf('MIN')>0)
							el.value = 'min';
						if(el.id.indexOf('MAX')>0)
							el.value = 'max';
				}
		});
}
function number_format(el) {
	Event.observe(el,'keyup',function(ev){
		my_orig_val = el.value.replace(/[^0-9]/g,"");
		my_orig_val_length = my_orig_val.length;
		
		if(my_orig_val=='') el.value = '';
		
		number_of_points = Math.floor((my_orig_val_length-1)/3);
		if(number_of_points>0)
		{
			my_new_number = "";
			for(i=1;i<=number_of_points;i++)
			{
				if(i==1)
					my_new_number = "." + my_orig_val.slice(-3);
				else
					my_new_number = "." + my_orig_val.slice(0-(i*3),0-((i-1)*3)) + my_new_number;
			}
			my_new_number = my_orig_val.substr(0,my_orig_val_length-(number_of_points*3)) + my_new_number;
			if(el.value != my_new_number)
				el.value = my_new_number;
			else return true;
		}
		else if(el.value.length!=my_orig_val_length) el.value = my_orig_val;
	})
}
var Cookies = {
  	init: function () {
  		var allCookies = document.cookie.split('; ');
  		for (var i=0;i<allCookies.length;i++) {
  			var cookiePair = allCookies[i].split('=');
  			this[cookiePair[0]] = cookiePair[1];
  		}
  	},
  	set: function (name,value,days) {
  		if (days) {
  			var date = new Date();
  			date.setTime(date.getTime()+(days*24*60*60*1000));
  			var expires = "; expires="+date.toGMTString();
  		}
  		else var expires = "";
  		document.cookie = name+"="+value+expires+"; path=/";
  		this[name] = value;
  	},
  	clear: function (name) {
  		this.set(name,'',-1);
  		this[name] = undefined;
  	}
}
function search_menu_2(a,b,c)
{
	part_1 = '<span onClick="google_track(\'formular cautare listing\', \'altele\', \'schimbare tip imobil\',1);search_menu_2(1,5,\'Apartamente\')">Apartamente</span>';
	part_2 = '<span onClick="google_track(\'formular cautare listing\', \'altele\', \'schimbare tip imobil\',34);search_menu_2(2,5,\'Case/Vile\')">Case/Vile</span>';
	part_3 = '<span onClick="google_track(\'formular cautare listing\', \'altele\', \'schimbare tip imobil\',56);search_menu_2(3,5,\'Spatii\')">Spatii</span>';
	part_4 = '<span onClick="google_track(\'formular cautare listing\', \'altele\', \'schimbare tip imobil\',2);search_menu_2(4,5,\'Birouri\')">Birouri</span>';
	part_5 = '<span onClick="google_track(\'formular cautare listing\', \'altele\', \'schimbare tip imobil\',7);search_menu_2(5,5,\'Terenuri\')">Terenuri</span>';
	glue = '&nbsp;|&nbsp;';
	$('search_2_top').innerHTML = '';
	//draw_filters(a,b);
	for(i=1;i<=b;i++)
	{
		$('searchbox_cnt_'+i).style.display="none";
		if(i!=1 && i!=(a+1) && !(i==b && a==b)) $('search_2_top').innerHTML += glue;
		if(i!=a) $('search_2_top').innerHTML += eval("part_"+i);
	}
	$('searchbox_cnt_'+a).style.display="";
	$('search_2_title').innerHTML = c;
}
function schimba_video_oferta(id,nume)
{
	if (id!=este_slectata)
	{
		$('img_video_'+este_slectata).className='';
		$('img_video_'+id).className='act';
		$('pic_title_video').innerHTML=nume;
		new Ajax.Updater('container_video_flash','/index.php?section=all&screen=video_oferta_inner&ajax=1&id='+id,{evalScripts:true,method:"get"});
		este_slectata=id;
	}
}

function arata_tip(id)
{
	$('tip_'+id).style.display='block';
}
function ascunde_tip(id)
{
	$('tip_'+id).style.display='none';
}
function trimite_cos()
{
	error = "";
	if($("cos_nume").value=="") error += "\n\t- Numele";
	if($("cos_email").value=="") error += "\n\t- Adresa Email";
	if($("cos_telefon").value=="") error += "\n\t- Telefonul";
	if($("cos_text").value=="") error += "\n\t- Mesajul";
	if(error!="") alert("Urmatoarele campuri sunt obligatorii:"+error);
	else
	{
		url = "/index.php?section=cart&screen=trimite_cos";
		send_all=true;

		params  = "what=cos_oferte&nume="+$("cos_nume").value;
		params += "&email="+$("cos_email").value;
		params += "&telefon="+$("cos_telefon").value;
		params += "&mesaj="+$("cos_text").value;
		ids=document.getElementsByName('anunt[]');
		for(i=0;i<ids.length;i++)
		{
			if(ids[i].checked) params += "&ids[]="+ids[i].value;
		}
		
		count = 0;
		aj=new Ajax.Request(url, {
							onSuccess:function(ob){
								$('trimite_cos_cnt').style.display='none';
								alert(ob.responseText)
							},
							method:"post", 
							parameters:params});
		
	}
	return false;
}

function contact_agents_whois(id)
{
	error = "";
	if($("contact_nume").value=="") error += "\n\t- Numele";
	if($("contact_oras").value=="") error += "\n\t- Orasul";
	if($("contact_telefon").value=="") error += "\n\t- Telefonul"; else
		if(!validate_telefon($("contact_telefon").value)) error += "\n\t- Telefonul nu este corect";
	if($("contact_email").value=="") error += "\n\t- Adresa email"; else
		if(!validate_email($("contact_email").value)) error += "\n\t- Adresa de email nu are formatul corect";
	if($("contact_mesaj").value=="") error += "\n\t- Mesajul";
	if(error!="") alert("Urmatoarele campuri sunt obligatorii:"+error);
	else
	{
		url = "/index.php?section=agent&screen=contact";
		aj=new Ajax.Request(url, {onSuccess:function(ob){$("contact_right_part").innerHTML = ob.responseText},method:"post", parameters:"what=oferta&id="+id+"&nume="+$("contact_nume").value+"&oras="+$("contact_oras").value+"&telefon="+$("contact_telefon").value+"&email="+$("contact_email").value+"&mesaj="+$("contact_mesaj").value});
	}
	return false;
}

function contact_oferta(id)
{
	error = "";
	if($("contact_nume").value=="") error += "\n\t- Numele";
	//if($("contact_oras").value=="") error += "\n\t- Orasul";
	if($("contact_telefon").value=="") error += "\n\t- Telefonul"; else
		if(!validate_telefon($("contact_telefon").value)) error += "\n\t- Telefonul nu este corect";
	if($("contact_email").value=="") error += "\n\t- Adresa email"; else
		if(!validate_email($("contact_email").value)) error += "\n\t- Adresa de email nu are formatul corect";
	if($("contact_mesaj").value=="") error += "\n\t- Mesajul";
	if(error!="") alert("Urmatoarele campuri sunt obligatorii:"+error);
	else
	{
		url = "/index.php?section=oferte&screen=contact";
		aj=new Ajax.Request(
			url, 
			{
				onLoading:function(){$("contact_right_part").innerHTML = 'Va rugam asteptati. Cererea a fost trimisa.'},
				onSuccess:function(ob){$("contact_right_part").innerHTML = ob.responseText},
				method:"post", 
				parameters:"what=oferta&id="+id+"&nume="+$("contact_nume").value+"&telefon="+$("contact_telefon").value+"&email="+$("contact_email").value+"&mesaj="+$("contact_mesaj").value});
	}
	return false;
}
function mesaj_rezervare(id)
{
	error = "";
	if($("rezervare_mesaj").value=="")
	{
		error += "Nu ati introdus mesajul";
	}
	if(error!="") alert(error);
	else
	{
		url = "/index.php?section=users&screen=rezervare_mesaj";
		aj=new Ajax.Request(url, {onSuccess:function(ob){alert(ob.responseText);},method:"post", parameters:"id="+id+"&mesaj="+$("rezervare_mesaj").value});
	}
}
function contact_proiect(id)
{
	error = "";
	if($("contact_nume").value=="") error += "\n\t- Numele";
	if($("contact_oras").value=="") error += "\n\t- Orasul";
	if($("contact_telefon").value=="") error += "\n\t- Telefonul"; else
		if(!validate_telefon($("contact_telefon").value)) error += "\n\t- Telefonul nu este corect";
	if($("contact_email").value=="") error += "\n\t- Adresa email"; else
		if(!validate_email($("contact_email").value)) error += "\n\t- Adresa de email nu are formatul corect";
	if($("contact_mesaj").value=="") error += "\n\t- Mesajul";
	if(error!="") alert("Urmatoarele campuri sunt obligatorii:"+error);
	else
	{
		url = "/index.php?section=proiecte&screen=contact";
		aj=new Ajax.Request(url, {onSuccess:function(ob){$("contact_cnt").innerHTML = ob.responseText},method:"post", parameters:"what=proiect&id="+id+"&nume="+$("contact_nume").value+"&oras="+$("contact_oras").value+"&telefon="+$("contact_telefon").value+"&email="+$("contact_email").value+"&mesaj="+$("contact_mesaj").value});
	}
	return false;
}
function sesizeaza_oferta(id)
{
	error = "";
	if($("sesizeaza_nume").value=="") error += "\n\t- Numele";
	if($("sesizeaza_email").value=="") error += "\n\t- Adresa Email";
	if($("sesizeaza_text").value=="") error += "\n\t- Mesajul";
	if($("sesizeaza_telefon").value=="") error += "\n\t- Telefonul";
	if(error!="") alert("Urmatoarele campuri sunt obligatorii:"+error);
	else
	{
		url = "/index.php?section=oferte&screen=sesizeaza";
		aj=new Ajax.Request(url, {onSuccess:function(ob){$('sesizeaza_neregula_cnt').style.display='none';alert(ob.responseText)},method:"post", parameters:"what=oferta&id="+id+"&nume="+$("sesizeaza_nume").value+"&email="+$("sesizeaza_email").value+"&telefon="+$("sesizeaza_telefon").value+"&mesaj="+$("sesizeaza_text").value});
	}
	return false;
}
function feedback()
{
	error = "";
	if($("feedback_nume").value=="") error += "\n\t- Numele";
	if($("feedback_email").value=="") error += "\n\t- Adresa Email";
	if($("feedback_text").value=="") error += "\n\t- Mesajul";
	if(error!="") alert("Urmatoarele campuri sunt obligatorii:"+error);
	else
	{
		url = "/index.php?section=oferte&screen=feedback";
		aj=new Ajax.Request(url, {onSuccess:function(ob){$('feedback_cnt').style.display='none';alert(ob.responseText)},method:"post", parameters:"nume="+$("feedback_nume").value+"&email="+$("feedback_email").value+"&mesaj="+$("feedback_text").value});
	}
	return false;
}
function email_oferta(id)
{
	error = "";
	if($("email_nume_1").value=="") error += "\n\t- Numele tau";
	if($("email_email_1").value=="") error += "\n\t- Adresa ta de email";
	if($("email_nume_2").value=="") error += "\n\t- Numele destinatarului";
	if($("email_email_2").value=="") error += "\n\t- Adresa de email a destinatarului";
	if(error!="") alert("Urmatoarele campuri sunt obligatorii:"+error);
	else
	{
		url = "/index.php?section=oferte&screen=email";
		aj=new Ajax.Request(url, {onSuccess:function(ob){$('trimite_email_cnt').style.display='none';alert(ob.responseText)},method:"post", parameters:"what=oferta&id="+id+"&nume_1="+$("email_nume_1").value+"&email_1="+$("email_email_1").value+"&nume_2="+$("email_nume_2").value+"&email_2="+$("email_email_2").value});
	}
	return false;
}
function sesizeaza_agent(id)
{
	error = "";
	if($("sesizeaza_nume").value=="") error += "\n\t- Numele";
	if($("sesizeaza_email").value=="") error += "\n\t- Adresa Email";
	if($("sesizeaza_text").value=="") error += "\n\t- Mesajul";
	if(error!="") alert("Urmatoarele campuri sunt obligatorii:"+error);
	else
	{
		url = "/index.php?section=agent&screen=sesizeaza";
		aj=new Ajax.Request(url, {onSuccess:function(ob){$('sesizeaza_neregula_cnt').style.display='none';alert(ob.responseText)},method:"post", parameters:"what=agent&id="+id+"&nume="+$("sesizeaza_nume").value+"&email="+$("sesizeaza_email").value+"&mesaj="+$("sesizeaza_text").value});
	}
	return false;
}
function email_agent(id)
{
	error = "";
	if($("email_nume_1").value=="") error += "\n\t- Numele tau";
	if($("email_email_1").value=="") error += "\n\t- Adresa ta de email";
	if($("email_nume_2").value=="") error += "\n\t- Numele destinatarului";
	if($("email_email_2").value=="") error += "\n\t- Adresa de email a destinatarului";
	if(error!="") alert("Urmatoarele campuri sunt obligatorii:"+error);
	else
	{
		url = "/index.php?section=agent&screen=email";
		aj=new Ajax.Request(url, {onSuccess:function(ob){$('trimite_email_cnt').style.display='none';alert(ob.responseText)},method:"post", parameters:"what=agent&id="+id+"&nume_1="+$("email_nume_1").value+"&email_1="+$("email_email_1").value+"&nume_2="+$("email_nume_2").value+"&email_2="+$("email_email_2").value});
	}
	return false;
}
function email_proiect(id)
{
	error = "";
	if($("email_nume_1").value=="") error += "\n\t- Numele tau";
	if($("email_email_1").value=="") error += "\n\t- Adresa ta de email";
	if($("email_nume_2").value=="") error += "\n\t- Numele destinatarului";
	if($("email_email_2").value=="") error += "\n\t- Adresa de email a destinatarului";
	if(error!="") alert("Urmatoarele campuri sunt obligatorii:"+error);
	else
	{
		url = "/index.php?section=proiecte&screen=email";
		aj=new Ajax.Request(url, {onSuccess:function(ob){$('trimite_email_cnt').style.display='none';alert(ob.responseText)},method:"post", parameters:"what=proiect&id="+id+"&nume_1="+$("email_nume_1").value+"&email_1="+$("email_email_1").value+"&nume_2="+$("email_nume_2").value+"&email_2="+$("email_email_2").value});
	}
	return false;
}
function showSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

function hideSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}

function imob_oferta(a)
{
	if(a<4)
	{
		if($("info_links")) $("info_links").style.display = "";	
		$("actualizat").style.display = "";	
		$("top_side").style.display = "";	
	}
	for(i=1;i<=3;i++)
	{
		$("imob_menu_"+i).className="item";
	}
	if(a<4)
	{
		$("imob_menu_"+a).className="item item_act";
	}
	if(a==1)
	{
		$("poze_oferta").style.display = "none";
		$("info_oferta").style.display = "";
		$("other_pics").style.display = "";
		$("finance").style.display = "";
		$("informatii").style.display = "";
		$("video_oferta").style.display = "none";
		if($('validata_de_proprietar')) $('validata_de_proprietar').style.display = "";
	}
	else if (a==2)
	{
		$("info_oferta").style.display = "none";
		$("poze_oferta").style.display = "";
		$("video_oferta").style.display = "none";
		if($('validata_de_proprietar')) $('validata_de_proprietar').style.display = "none";
	}
	else if (a==3)
	{
		$("info_oferta").style.display = "none";
		$("poze_oferta").style.display = "none";
		$("video_oferta").style.display = "";
		if($('validata_de_proprietar')) $('validata_de_proprietar').style.display = "none";
	}
	$('info_oferta').innerHTML=$('info_oferta').innerHTML;
}
var sto;
function nav_pics(a)
{
	div_pics = $("nav_pics");
	if(a==0) return;
	else if(a<0)
	{
		if(div_pics.scrollLeft<=0) return;
	}
	else if(a>0)
	{
		if(div_pics.scrollLeft>=(div_pics.scrollWidth-221)) return;
	}
	div_pics.scrollLeft = div_pics.scrollLeft+a;
	sto=setTimeout('nav_pics('+a+')',30);
}
function stop_nav_pics()
{
	clearTimeout(sto);
}
function nav_alte_oferte(a)
{
	div_pics = document.getElementById("top_alte_oferte_items");
	if($('nav_alte_oferte_prev').src.indexOf('inact')!=-1) $('nav_alte_oferte_prev').src = '/images/blue_arr_left.gif';
	if($('nav_alte_oferte_next').src.indexOf('inact')!=-1) $('nav_alte_oferte_next').src = '/images/blue_arr_right.gif';
	if(a==0) return;
	else if(a<0)
	{
		if(div_pics.scrollLeft<=0)
		{
			$('nav_alte_oferte_prev').src = '/images/blue_arr_left_inact.gif';
			return;
		}
	}
	else if(a>0)
	{
		if(div_pics.scrollLeft>=(div_pics.scrollWidth-885))
		{
			$('nav_alte_oferte_next').src = '/images/blue_arr_right_inact.gif';
			return;
		}
	}
	div_pics.scrollLeft = div_pics.scrollLeft+a;
	sto=setTimeout('nav_alte_oferte('+a+')',30);
}
function stop_nav_alte_oferte()
{
	clearTimeout(sto);
}
function change_clapeta(curent,total,id)
{
	for(i=1;i<=total;i++)
	{
		if($(id+'_clp_'+i).className=="item item_first item_act" || $(id+'_clp_'+i).className=="item item_act") //for up and down
			curent_now = i;
		if(i==1)
			$(id+'_clp_'+i).className="item item_first";
		else
			$(id+'_clp_'+i).className="item";
		$(id+'_cnt_'+i).style.display="none";
	}
	if(curent=='up' && curent_now<total) curent = curent_now+1;
	else if(curent=='up' && curent_now==total) curent=total;
	else if(curent=='down' && curent_now>1) curent = curent_now-1;
	else if(curent=='down' && curent_now==1) curent = 1;
	if(curent==1)
		$(id+'_clp_'+curent).className="item item_first item_act";
	else
		$(id+'_clp_'+curent).className="item item_act";
	$(id+'_cnt_'+curent).style.display="";
}
var ChangeClapetaEv = Class.create();
ChangeClapetaEv.prototype = {
	initialize: function(total,id,curent,evt) {
		this.total = total;
		this.id = id;
		this.curent = curent;
		this.evt = evt;
		if(this.evt=='mouseover')
			this.create_mouseover();
		else if(this.evt=='click')
			this.create_click();
	},
	create_mouseover: function() {
		Event.observe($(this.id+'_clp_'+this.curent),'mouseover',function() {
			this.to = setTimeout('change_clapeta('+this.curent+','+this.total+',"'+this.id+'")',250);
		}.bind(this));
		Event.observe($(this.id+'_clp_'+this.curent),'mouseout',function() {
			clearTimeout(this.to);
		}.bind(this));
	},
	create_click: function() {
		Event.observe($(this.id+'_clp_'+this.curent),'click',function() {
			change_clapeta(this.curent,this.total,this.id);
			var a = 1;
		}.bind(this));
	}
}
function change_clapeta_ev(curent,total,id,evt)
{
	if(curent!=0) change_clapeta(curent,total,id);
	for(i=1;i<=total;i++)
	{
		new ChangeClapetaEv(total,id,i,evt);
	}
	if($(id+'_clp_down')) new ChangeClapetaEv(total,id,'down',evt);
	if($(id+'_clp_up')) new ChangeClapetaEv(total,id,'up',evt);
}
function change_pic(a,b,c,d)
{
	$("pic_big").src = a;
	if($("pic_title").firstChild)
		$("pic_title").firstChild.nodeValue=b;
	else
		$("pic_title").appendChild(document.createTextNode(b));
	for(i=1;i<=d;i++)
	{
		if(i!=c)
		{
			$("mini_pic_"+i).className="mini_pic";
			$("mini_pic_"+i).onmouseover = function(e) {this.className="mini_pic activ";};
			$("mini_pic_"+i).onmouseout = function(e) {this.className="mini_pic";};
		}
	}
	$("mini_pic_"+c).className="mini_pic activ";
	$("mini_pic_"+c).onmouseover = null;
	$("mini_pic_"+c).onmouseout = null;
	if(c!=d) $('poze_nav_right').style.display = "inline";
	else $('poze_nav_right').style.display = "none";
	if(c!=1) $('poze_nav_left').style.display = "inline";
	else $('poze_nav_left').style.display = "none";
}
function nav_pic(a)
{
	var command = "";
	my_pics = $$('#poze_oferta .mini_pic');
	for(i=0;i<my_pics.length;i++)
	{
		if(my_pics[i].nodeName!="IMG" || my_pics[i].className!="mini_pic activ") continue;
		if(a=='left' && my_pics[i-1])
		{
			command = my_pics[i-1].getAttribute('onclick');
			break;
		}
		else if (a=='right' && my_pics[i+1])
		{
			command = my_pics[i+1].getAttribute('onclick');
			break;
		}
	}
	if(command=="") return false;
	if(window.execScript)
	{
		command=command.toString();
		if(command.indexOf('{')>0)
			command = command.substring(command.indexOf('{')+1,command.indexOf('}'));
		window.execScript(command);
		return false;
	}
	eval(command);
}

var mouseX, mouseY;
function getMousePos(e){
	if (!e)
	var e = window.event||window.Event;
	
	if("undefined"!=typeof e.pageX){
		mouseX = e.pageX;
		mouseY = e.pageY;
	} else {
		mouseX = e.clientX;
		mouseY = e.clientY;
	}
}
if(window.Event && document.captureEvents)
	document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMousePos;

function show_tt(div,top,left)
{
	hideSelectBoxes();
	if(top==undefined)
	{
		if(window.pageYOffset!=undefined)
			top=mouseY;
		else
			top=mouseY+(document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop);
	}
	if(left==undefined)
	{
		if(window.pageXOffset!=undefined)
			left=mouseX+10;
		else
			left=mouseX+10+(document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft);
	}
	div.style.display='inline';
	div.style.top = top+"px";
	div.style.left = left+"px";
	new Draggable(div,{handle:'top_side'});

}
Position.getWindowSize = function(w) {
	var width, height;
	w = w ? w : window;
	width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
	height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
	
	return { width: width, height: height };
}
Position.Center = function(element, parent) {
        var w, h, pw, ph;
        var d = Element.getDimensions(element);
        w = d.width;
        h = d.height;
        Position.prepare();
        if (!parent) {
                var ws = Position.GetWindowSize();
                pw = ws[0];
                ph = ws[1];
        } else {
                pw = parent.offsetWidth;
                ph = parent.offsetHeight;
        }
        element.style.top = (ph/2) - (h/2) -  Position.deltaY + "px";
        element.style.left = (pw/2) - (w/2) -  Position.deltaX + "px";
}
Position.CenterPage = function(element) {
        var w, h, pw, ph;
        var d = Element.getDimensions(element);
        w = d.width;
        h = d.height;

		y = (window.innerHeight?window.innerHeight:(document.documentElement.clientHeight?document.documentElement.clientHeight:document.body.clientHeight))/2+(document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop);
		x = (window.innerWidth?window.innerWidth:(document.documentElement.clientWidth?document.documentElement.clientWidth:document.body.clientWidth))/2+(document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft);
        element.style.top = y - (h/2) + "px";
        element.style.left = x - (w/2) + "px";
}
function show_tt_centred(div)
{
	hideSelectBoxes();
	div.style.display = 'inline';
	Position.CenterPage(div);
	new Draggable(div,{handle:'top_side'});

}
function unshow_tt(div)
{
	div.style.display='none';
	showSelectBoxes();
}
function load_tt(url,top,left)
{
	var right;
	hideSelectBoxes();
	if($('tt_div_cnt')==undefined)
	{
		tt_div = document.createElement("div");
		tt_div.setAttribute('id','tt_div_cnt');
		document.body.insertBefore(tt_div,document.body.firstChild)
	}
	else
	{
		$('tt_div_cnt').innerHTML = '';
	}
	if(top==undefined)
	{
		if(window.pageYOffset!=undefined)
			top=mouseY;
		else
			top=mouseY+(document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop);
	}
	if(left==undefined)
	{
		if(window.pageXOffset!=undefined)
			left=mouseX+10;
		else
			left=mouseX+10+(document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft);
	}
	$('tt_div_cnt').style.top = top+"px";
	
	new Ajax.Request(
		url, 
		{onSuccess:function(ob){
			valuta1=valuta1_reset;
			valuta2=1;
			$('tt_div_cnt').innerHTML = ob.responseText;
			if($('taxe_imobiliare')) new Draggable('taxe_imobiliare',{handle:'top_side'});
			else if ($('convertor_valutar')) new Draggable('convertor_valutar',{handle:'top_side'});
			else if ($('dex_tooltip')) new Draggable('dex_tooltip',{handle:'top_side'});
			else if ($('popup_login')) new Draggable('popup_login',{handle:'top_side'});			
			else new Draggable('tt_div_cnt',{handle:'top_side'});
			if($('dex_tooltip') && (left-278)<0)
			{
				left=278;
			}
			else if ($('convertor_valutar') && (left-278)<0)
			{
				left=278;
			}
			else if ($('taxe_imobiliare') && (left-375)<0)
			{
				left=375;
			}
			else if ($('popup_login') && (left-278)<0)
			{
				left=278;
			}
			else if ($('popup_login') && (left+52)>1000)
			{
				//alert(left);
				left=left-40;
			}			
			$('tt_div_cnt').style.left = left+"px";

		},
		evalJS: false,
		onException:function(t,ob){
				
				//po++;
				//alert(t);
		}
		}
	);
}
function hide_tt()
{
	$('tt_div_cnt').innerHTML = '';
	showSelectBoxes();
}
function list_check_all(ck)
{
	$$('.de_selectat').each(
		function (el){
			el.checked=ck.checked;
	});
		$('check_all_header').checked=ck.checked;
		$('check_all_footer').checked=ck.checked;
}
function list_add()
{
	$$('.de_selectat').each(
		function (el){
			if(el.checked) mycart.add_item(el.value)
	});
}

/*functia care seteaza un coockie*/
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 on_loaded()
{
	placeElements();
	Event.observe($('close_top_casete'),'click', function(){
		if($('top_casete').style.display=='none') {
			Effect.BlindDown('top_casete',{duration: 0.5,afterFinish:function(){
																		$('comanda_utilitare').innerHTML='Inchide sectiunea utilitara'; 
																		$('comanda_utilitare').style.borderBottom='' ; 
																		$('img_utilitare_1').src='/images/sep_left_close.gif'; 
																		$('img_utilitare_2').src='/images/sep_left_close.gif'
																		$('slider_blog').style.display='block';
																		$('slider_stire').style.display='block';
																		Set_Cookie('inchis','0');
																	}});
			
		} else { 
			$('slider_blog').style.display='none';
			$('slider_stire').style.display='none';
			Effect.BlindUp('top_casete',{duration: 0.5, afterFinish:function(){
																		$('comanda_utilitare').innerHTML='Deschide sectiunea utilitara';
																		$('comanda_utilitare').style.borderBottom='1px dashed #ff9000'; 
																		$('img_utilitare_1').src='/images/sep_left_open.gif'; 
																		$('img_utilitare_2').src='/images/sep_left_open.gif' 
																		Set_Cookie('inchis','1');
																	}});
		}
	});
}

var ImoCart= Class.create(); 

ImoCart.prototype={

    initialize: function(options) { 
        this.url = "/index.php?section=cart&screen=receiver"; 
    },
	
	add_item: function(id_run){
		var a=new Ajax.Request(this.url, {   
			method: 'post',   
			parameters:'action=add_item&idrun='+id_run,
			onSuccess: function(transport) {
				$('favorite_'+id_run).immediateDescendants().each(function (el){el.remove()});
				if($('imobiliare_oferta'))
					new_element_link = Builder.node('a',{href:'javascript:void(0)',onclick:'pageTracker._trackEvent(\'oferte\', \'sterge_din_cos\', \''+id_run+'\');mycart.delete_item(\''+id_run+'\')'},["Sterge din cos"]);
				else new_element_link = Builder.node('a',{href:'javascript:void(0)',onclick:'mycart.delete_item(\''+id_run+'\')'},["Sterge"]);
				$('favorite_'+id_run).appendChild(new_element_link);
				$('imgfavorite_'+id_run).className = 'icon_normal icon_cos3';

				resp = transport.responseText;
				oferte = resp.evalJSON();
				
				$$('.numar_oferte_cos').each(function(el){el.innerHTML=oferte['total']});
				$$('.oferte_netrimise_cos').each(function(el){el.innerHTML=oferte['netrimise']});
				$$('.oferte_trimise_cos').each(function(el){el.innerHTML=oferte['trimise']});
			} 
		});
	},
	delete_item: function(id_run){
		var a=new Ajax.Request(this.url, {   
			method: 'post',   
			parameters:'action=delete_item&idrun='+id_run,
			onSuccess: function(transport) {     
				$('favorite_'+id_run).immediateDescendants().each(function (el){el.remove()});
				new_element_link = Builder.node('a',{href:'javascript:void(0)',onclick:'pageTracker._trackEvent(\'oferte\', \'adauga_in_cos\', \''+id_run+'\');mycart.add_item(\''+id_run+'\')'},["Adauga in cos"]);
				$('favorite_'+id_run).appendChild(new_element_link);
				$('imgfavorite_'+id_run).className = 'icon_normal icon_cos3 icon_gray';
				if($('cos_item_'+id_run)) $('cos_item_'+id_run).fade();
				resp = transport.responseText;
				oferte = resp.evalJSON();
				
				$$('.numar_oferte_cos').each(function(el){el.innerHTML=oferte['total']});
				$$('.oferte_netrimise_cos').each(function(el){el.innerHTML=oferte['netrimise']});
				$$('.oferte_trimise_cos').each(function(el){el.innerHTML=oferte['trimise']});
			} 
		});
	},
	add_item_new: function(id_run){
		var a=new Ajax.Request(this.url, {   
			method: 'post',   
			parameters:'action=add_item&idrun='+id_run,
			onSuccess: function(transport) {
				google_track('oferte', 'adauga_in_cos', id_run);
				$('favorite_'+id_run).immediateDescendants().each(function (el){el.remove()});
				if($('imobiliare_oferta'))
					new_element_link = Builder.node('a',{href:'javascript:void(0)',onclick:'pageTracker._trackEvent(\'oferte\', \'sterge_din_cos\', \''+id_run+'\');mycart.delete_item_new(\''+id_run+'\')'},["Sterge"]);
				else new_element_link = Builder.node('a',{href:'javascript:void(0)',onclick:'mycart.delete_item_new(\''+id_run+'\')'},["Sterge"]);

				position_1 = Position.cumulativeOffset($('favorite_'+id_run).parentNode);
				position_2 = Position.cumulativeOffset($('cos_ear'));
				div_style_string = 'display:none;position:absolute;width:117px;height:27px;top:'+position_1[1]+'px;left:'+position_1[0]+'px;';
				div_attributes = {id:'anim_cart_'+id_run,'class':'anim_add_cart',style:div_style_string};
//				new_anim = Builder.node('div',{id:'anim_cart_'+id_run,class:'anim_add_cart',style:style_string},[" "]);
				new_anim = Builder.node('div',div_attributes);
				$('favorite_'+id_run).appendChild(new_element_link);
				$('favorite_'+id_run).parentNode.parentNode.parentNode.appendChild(new_anim);

				yScroll =  document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop;				
				xScroll =  document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft;				
				
				new Effect.Appear('anim_cart_'+id_run,{ from:0.3, to:0.7,duration: 0.2,queue: { position: 'end', scope: 'my_effect' }});
				
				ver = getInternetExplorerVersion();
				if(ver<7 && ver>0) position_2[1] = position_2[1] - document.documentElement.scrollTop;

				new Effect.Parallel([
					new Effect.Move('anim_cart_'+id_run,{sync: true, x: (position_2[0]+xScroll), y: (position_2[1]+yScroll), mode: 'absolute',duration:1}),
					new Effect.Morph('anim_cart_'+id_run,{sync: true, duration: 1, style: 'width:50px;height:51px;' }),
					new Effect.Fade('anim_cart_'+id_run,{sync: true, duration: 1, from:0.7, to:0.4 })
				], { 
					duration: 1,queue: { position: 'end', scope: 'my_effect'}
				});
				new Effect.Fade('anim_cart_'+id_run,{duration: 0.3, from:0.4, to:0.0,queue: { position: 'end', scope: 'my_effect'},afterFinish:function(){$('anim_cart_'+id_run).remove()}})
				
				resp = transport.responseText;
				oferte = resp.evalJSON();
				
				$$('.numar_oferte_cos').each(function(el){el.innerHTML=oferte['total']});
				$$('.oferte_netrimise_cos').each(function(el){el.innerHTML=oferte['netrimise']});
				$$('.oferte_trimise_cos').each(function(el){el.innerHTML=oferte['trimise']});
				
			} 
		});
	},
	delete_item_new: function(id_run){
		var a=new Ajax.Request(this.url, {   
			method: 'post',   
			parameters:'action=delete_item&idrun='+id_run,
			onSuccess: function(transport) {     
				google_track('oferte', 'sterge_din_cos', id_run);
				$('favorite_'+id_run).immediateDescendants().each(function (el){el.remove()});
				new_element_link = Builder.node('a',{href:'javascript:void(0)',onclick:'pageTracker._trackEvent(\'oferte\', \'adauga_in_cos\', \''+id_run+'\');mycart.add_item_new(\''+id_run+'\')'},["Salveaza"]);
				$('favorite_'+id_run).appendChild(new_element_link);
				if($('cos_item_'+id_run)) $('cos_item_'+id_run).fade();
				resp = transport.responseText;
				oferte = resp.evalJSON();
				
				$$('.numar_oferte_cos').each(function(el){el.innerHTML=oferte['total']});
				$$('.oferte_netrimise_cos').each(function(el){el.innerHTML=oferte['netrimise']});
				$$('.oferte_trimise_cos').each(function(el){el.innerHTML=oferte['trimise']});
			} 
		});
	},
	
	set_callback:function(functor){
		this.callback_action=functor;
	},
	
	fill_cart_count:function(text_total){
		$$('.numar_oferte_cos').each(function(el){el.innerHTML=text_total;});
	}
}

mycart=new ImoCart();


Event.observe(window,'load',function(){
	on_loaded();
})


function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

function reset_filtre()
{
	for(i=0;i<document.getElementsByName('zona[]').length;i++)
	{
		document.getElementsByName('zona[]')[i].value = "";
	}
	$('filterMIN_NRCAM').value = 'min';
	$('filterMAX_NRCAM').value = 'max';
	$('filterMIN_SUPR_UTILA').value = 'min';
	$('filterMAX_SUPR_UTILA').value = 'max';
	$('filterMIN_SUPR_TEREN').value = 'min';
	$('filterMAX_SUPR_TEREN').value = 'max';
	$('filterCls_PRET_MIN').value = 'min';
	$('filterCls_PRET_MAX').value = 'max';
	$('filterCls_PRETMP_MIN').value = 'min';
	$('filterCls_PRETMP_MAX').value = 'max';
	$$('.numar_zone_selectate').each(function(el){el.innerHTML="nicio zona selectata";});
	div_manager.next_reload();
}

function show_form()
{
	Effect.BlindDown('formular');
}
function hide_form()
{
	var disp = $('formular').style.display;
	
	if (disp == 'none')
	{
		alert('alert');
	}
	else
	{
		Effect.Fade('formular');
	}
	
}
function trimite_definitie()
{
	alert('definitie trimisa');
}

// number formatting function
// copyright Stephen Chapman 24th March 2006, 22nd August 2008
// permission to use this function is granted provided
// that this copyright notice is retained intact

function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) {
	var x = Math.round(num * Math.pow(10,dec));
	if (x >= 0) n1=n2='';
	var y = (''+Math.abs(x)).split('');
	var z = y.length - dec; 
	if (z<0) z--; for(var i = z; i < 0; i++) y.unshift('0'); 
	if (z<0) z = 1; y.splice(z, 0, pnt); 
	if(y[0] == pnt) y.unshift('0'); 
	while (z > 3) {
		z-=3; y.splice(z,0,thou);
	}
	var r = curr1+n1+y.join('')+n2+curr2;
	return r;
}


/* functii pentru convertor valutar*/
/* autor Tudor */

var valuta2=1;
function schimba (id)
{
	if (id==1)
		valuta1=document.getElementById("valuta1").value;
	else if (id==2)
		valuta2=document.getElementById("valuta2").value;
	calculeaza();
}

function checknumber()
{
	var x=document.getElementById('valoare').value;
	var anum=/(^\d+$)|(^\d+\.\d+$)/
	if (anum.test(x))
		testresult=true
	else{
		testresult=false
	}
	return (testresult)
}

function calculeaza()
{
	if (checknumber())
	{
		var suma=$F('valoare');
		var rezultat=Math.round(10000*suma*valuta1/valuta2)/10000;
		$('txt_rezultat').value=formatNumber(rezultat,2,'.',',','','','','');
	}
}

/* functii pentru caseta popup*/
/* inchide un popup cu id dat*/
/* autor Tudor */

function close_box(id){
	$(id).style.display="none";
}

/* afiseaza taxe detaliat*/
function show_taxes_details(){
	url = "/?section=calc&screen=taxe_detaliat";
	url +="&tranzactie="+$F('tranzactie');
	url +="&pret="+$F('pret');
	url +="&termen="+$F('termen');
	url +="&valuta="+$F('valuta');

	new Ajax.Request(
		url, 
		{
		onCreate: function() {$('taxes_details').update("<div style='width:320px; font-size:12px; font-weight:bold'>Se incarca ...</div>");},
		onSuccess: function(resp) {$('taxes_details').update(resp.responseText);}
		}
	);
}

/*pentru editare users*/
function arata_div_edit_ag()
{
	var arata=$('agent_imobiliar').checked;
	if (arata) $('patru_oferte').style.display="block";
	else $('patru_oferte').style.display="none";
}

function arata_div_schimba_parola()
{
	var arata=$('chk_parola').checked;
	if (arata) $('schimba_parola').style.display="block";
	else $('schimba_parola').style.display="none";
}

//pentru popup login

function try_login(from_alerte){
	var url = "/?section=users&screen=login&ajax=1";
	new Ajax.Request(url,
	{
		method:'post',
		parameters: {username: $F('pl_email'), parola: $F('pl_parola'), popup: "1", tine_logat: ($('popup_tine_logat').checked==true)?"1":""},
		onSuccess: function(transport)
		{
			var response = transport.responseText || "no response text";
			//alert("Success! \n\n" + response);
			if (response == "-1")
			{
				alert('Userul sau parola gresita!');
			} else{
				if(from_alerte==1){
					show_alerta();
					hide_tt();
				} else{
					window.location="/cont/index.html";
				}
			}
		}
	});		
}

//pentru creare alerte

function creaza_alerta(){
	var url = "/?section=users&screen=alerte_salveaza&ajax=1";
	new Ajax.Request(url,
	{
		method:'post',
		parameters: {titlu: $F('al_nume'), perioada: $F('al_perioada'), search_id: $F('alerte_search_id')},
		onSuccess: function(transport)
		{
			var response = transport.responseText || "no response text";
			//alert("Success! \n\n" + response);
			if (response == "-1")
			{
				load_tt('/index.php?section=users&screen=popup_login');
			} else{
				succes_alerta($F('al_nume'));	
			}
		}
	});		
}

function show_alerta(){
	var url = "/?section=users&screen=alerte_salveaza&ajax=1";
	var update_alerta = new Ajax.Updater('alerta', url, {parameters: {search_id: $F('alerte_search_id')},method:'get'});	
}

function succes_alerta(mesaj){
	var url = "/?section=users&screen=alerte_succes&titlu="+mesaj+"&ajax=1";
	var update_alerta = new Ajax.Updater('alerta', url, {method:'get'});	
}



//sectiunea de alerte 
function change_status(id){
	var url = "/?section=users&screen=alerte_change_status&ajax=1&id="+id;
	new Ajax.Request(url,
	{
		onSuccess: function(transport)
		{
			var response = transport.responseText || "no response text";
			//alert("Success! \n\n" + response);
			if (response == 2)
			{
				$('header_'+id).className = "header";
				$('actiune_'+id).className = "actiune";
				$('actiune_name_'+id).innerHTML = "Dezactiveaza";
				//alert(parseInt($('count_active').innerHTML)-1);
				//alert('Alerta a fost activata!');
				$('count_active').innerHTML = parseInt($('count_active').innerHTML)+1;
				$('count_inactive').innerHTML = parseInt($('count_inactive').innerHTML)-1;				
			}
			else if (response == 1)
			{
				$('header_'+id).className = "header bkg_act";
				$('actiune_'+id).className = "actiune color_act";
				$('actiune_name_'+id).innerHTML = "Activeaza";
				//alert('Alerta a fost dezactivata!');
				$('count_active').innerHTML = parseInt($('count_active').innerHTML)-1;
				$('count_inactive').innerHTML = parseInt($('count_inactive').innerHTML)+1;				
			}
		}
	});	
}

function change_alert_time(id){
	var url = "/?section=users&screen=alerte_change_alert_time&ajax=1&id="+id;
	new Ajax.Request(url,
	{
		method:'post',
		parameters: {alert_time: $F('alert_time_'+id)},
		onSuccess: function(transport)
		{
			var response = transport.responseText || "no response text";
			//alert("Success! \n\n" + response);
			if (response != "-1")
			{
				alert('Perioada alertei a fost schimbata!');
			}
		}
	});	
}
var t_pulsate_cart;
function pulsate_cart()
{
	if(parseInt($$('.oferte_netrimise_cos')[0].innerHTML)>2)
	{
		$('cos_ear').pulsate();
	}
	t_pulsate_cart = setTimeout('pulsate_cart()',10000);
}
