/*window.onfocus = function () {
	new Ajax.Updater('cart0', '/index.php', {
		method: 'post',
		parameters: 'p=cart&show=1'
	});
}*/
kosardarab = 0

function Collapse(c)	{
	if (c == 1)	{
		$('kerulet').style.display = "block"
		//$('megye').style.display = "none"
	} else	{
		$('kerulet').style.display = "none"
		//$('megye').style.display = "block"
	}
}

function Search()	{
	//alert($('f').serialize(false)); return
	if ($('list'))	{
		new Ajax.Updater('list', '/index.php', {
			parameters: $('f').serialize(true)
		});
	} else {
		fc = $('f').serialize(false).replace(/p=list/, 'p=main')
		top.location = 'index.php?' + fc
	}
}

function EK(ek)	{
	if (ek == 1)	{
		$('iarel').style.display = "block";
		$('iarki').style.display = "none";
	}
	else if (ek == 2)	{
		$('iarel').style.display = "none";
		$('iarki').style.display = "block";
	}
}

function BP()	{
	$('kerulet').style.display = "block";
	//$('megye').style.display = "none";
}

function Videk()	{
	$('kerulet').style.display = "none";
	//$('megye').style.display = "block";
}

function CartIn(i)	{
/*	new Ajax.Request('/index.php?p=cart&in=' + i, {
		method: 'post',
		onSuccess: function(transport) {
			CartAdd()
		}
	});*/
	new Ajax.Updater('cart0', '/index.php', {
		insertion: 'top',
		parameters: "p=cart&in=" + i
	});
	kosardarab++
}

function CartOut(i)	{
	new Ajax.Updater('cart0', '/index.php', {
		parameters: "p=cart&out=" + i
	});
	kosardarab--
}


//////// http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/
// usage:
// var value = $RF('radio_btn_id');
// var value = $RF('form_id', 'radio_grp_name');
function $RF(el, radioGroup) {
    if($(el).type && $(el).type.toLowerCase() == 'radio') {
        var radioGroup = $(el).name;
        var el = $(el).form;
    } else if ($(el).tagName.toLowerCase() != 'form') {
        return false;
    }

    var checked = $(el).getInputs('radio', radioGroup).find(
        function(re) {return re.checked;}
    );
    return (checked) ? $F(checked) : null;
}

function Contact(iid)	{
	$('tovabbitas').style.display = "none"
	if ($('ingatlanfigyelo')) $('ingatlanfigyelo').style.display = "none"
	$('kapcsolat').style.display = "block"
	//$F('iid').setValue(iid)
	document.kapcsf.iid.value = iid
	$('kapcsref').update("(Ref.: " + iid + ")")
	new Ajax.Request('/index.php', {
		parameters: 'stat=contact'
	})
}

function ContactClose()	{
	$('kapcsolat').style.display = "none"
	$('kapcsolatline').update()
}

function ContactSend()	{
	new Ajax.Request('/index.php', {
		parameters: $('kapcsf').serialize(true),
		onSuccess: function (transport) {
			if (parseInt(transport.responseText) > 0) ContactError()
			else ContactClosing()
		}
	});
}

function ContactClosing()	{
	$('kapcsolatline').update("A levelet elküldtük")
	var closing = 0;
	new PeriodicalExecuter(function(pe) {
		$('kapcsolatline').insert(".")
  		if (++closing > 3)	{
	  		pe.stop();
	  		ContactClose();
  		}
	}, 0.5);
}

function ContactError()	{
	$('kapcsolatline').update("Kérjük, adjon meg valós emailcímet!")
}

function Forward(iid)	{
	$('kapcsolat').style.display = "none"
	if ($('ingatlanfigyelo')) $('ingatlanfigyelo').style.display = "none"
	if (!iid && kosardarab <= 0) { alert("A kedvencek lista üres"); return }
	$('tovabbitas').style.display = "block"
	//$F('iid').setValue(iid)
	if (iid)	{
		document.tovf.iid.value = iid
		$('kapcsref').update("(Ref.: " + iid + ")")
	}
	new Ajax.Request('/index.php', {
		parameters: 'stat=forward'
	})
}

function ForwardClose()	{
	$('tovabbitas').style.display = "none"
	$('tovabbitasline').update()
}

function ForwardSend()	{
	new Ajax.Request('/index.php', {
		parameters: $('tovf').serialize(true),
		onSuccess: function (transport) {
			if (parseInt(transport.responseText) > 0) ForwardError()
			else ForwardClosing()
		}
	});
}

function ForwardClosing()	{
	$('tovabbitasline').update("A levelet elküldtük")
	var closing = 0;
	new PeriodicalExecuter(function(pe) {
		$('tovabbitasline').insert(".")
  		if (++closing > 3)	{
	  		pe.stop();
	  		ForwardClose();
  		}
	}, 0.5);
}

function ForwardError()	{
	$('tovabbitasline').update("Kérjük, adjon meg valós emailcímet!")
}

function IngFigy()	{
	if ($('kapcsolat')) $('kapcsolat').style.display = "none"
	if ($('tovabbitas')) $('tovabbitas').style.display = "none"
	$('eladom').style.display = "none"
	$('ingatlanfigyelo').style.display = "block"
	new Ajax.Request('/index.php', {
		parameters: 'stat=ingfigy'
	})

}

function IngFigyClose()	{
	$('ingatlanfigyelo').style.display = "none"
	$('ifline').update()
}

function IFSend()	{
	document.iff.ingfigy.value = $('f').serialize(false)
	new Ajax.Request('/index.php', {
		parameters: $('iff').serialize(true),
		onSuccess: function (transport) {
			if (parseInt(transport.responseText) > 0) IFError()
			else IFClosing()
		}
	});
}

function IFClosing()	{
	$('ifline').update("A levelet elküldtük")
	var closing = 0;
	new PeriodicalExecuter(function(pe) {
		$('ifline').insert(".")
  		if (++closing > 3)	{
	  		pe.stop();
	  		IngFigyClose();
  		}
	}, 0.5);
}

function IFError()	{
	$('ifline').update("Kérjük, adjon meg valós emailcímet!")
}

function Eladom()	{
	if ($('kapcsolat')) $('kapcsolat').style.display = "none"
	if ($('tovabbitas')) $('tovabbitas').style.display = "none"
	$('ingatlanfigyelo').style.display = "none"
	$('eladom').style.display = "block"
	new Ajax.Request('/index.php', {
		parameters: 'stat=eladom'
	})

}

function EladomClose()	{
	$('eladom').style.display = "none"
	$('elvline').update()
}

function EladomSend()	{
	new Ajax.Request('/index.php', {
		parameters: $('elvf').serialize(true),
		onSuccess: function (transport) {
			if (parseInt(transport.responseText) > 0) EladomError()
			else EladomClosing()
		}
	});
}

function EladomClosing()	{
	$('elvline').update("A levelet elküldtük")
	var closing = 0;
	new PeriodicalExecuter(function(pe) {
		$('elvline').insert(".")
  		if (++closing > 3)	{
	  		pe.stop();
	  		EladomClose();
  		}
	}, 0.5);
}

function EladomError()	{
	$('elvline').update("Kérjük, adjon meg valós emailcímet!")
}

function CreateBookmarkLink(ref) {
 	title = "Codeside Ingatlan" + ref;
  // Blogger - Replace with <$BlogItemTitle$>
  // MovableType - Replace with <$MTEntryTitle$>

 	//url = "http://www.codeside.hu";
 	url = top.location.href;
  // Blogger - Replace with <$BlogItemPermalinkURL$>
  // MovableType - Replace with <$MTEntryPermalink$>
  // WordPress - <?php bloginfo('url'); ?>

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url, "");
	} else if ( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if (window.opera && window.print) { // Opera Hotlist
		return true
	}
	new Ajax.Request('/index.php', {
		parameters: 'stat=bookmark'
	})
}

function WriteBookmarkLink(ref)	{
	if (window.external) {
		document.write('<a href = \'javascript:CreateBookmarkLink("' + ref + '")\'>Könyvjelzők közé</a>');
	} else  if (window.sidebar) {
		document.write('<a href = \'javascript:CreateBookmarkLink("' + ref + '")\'>Könyvjelzők közé</a>');
	} else if (window.opera && window.print) {
		document.write('<a href = \'javascript:CreateBookmarkLink("' + ref + '")\'>Könyvjelzők közé</a>');
	}
}

function ArstatTov()	{
	$('arstattov').style.display = "block"
	new Ajax.Request('/index.php', {
		parameters: 'stat=arstat'
	})
}

function ArstatTovClose()	{
	$('arstattov').style.display = "none"
	$('tovabbitasline').update()
}

function ArstatTovSend()	{
	new Ajax.Request('/index.php', {
		parameters: $('astovf').serialize(true),
		onSuccess: function (transport) {
			if (parseInt(transport.responseText) > 0) ForwardError()
			else ArstatTovClosing()
		}
	});
}

function ArstatTovClosing()	{
	$('tovabbitasline').update("A levelet elküldtük")
	var closing = 0;
	new PeriodicalExecuter(function(pe) {
		$('tovabbitasline').insert(".")
  		if (++closing > 3)	{
	  		pe.stop();
	  		ArstatTovClose();
  		}
	}, 0.5);
}

function ArstatTovError()	{
	$('tovabbitasline').update("Kérjük, adjon meg valós emailcímet!")
}

