
var MietanfrageBubble = {

	Bubble : null,

	show : function( obj, msg )
	{
		if(this.Bubble != null)
		{
			this.Bubble.obj.parentNode.removeChild( this.Bubble.obj );
			this.Bubble = null;
		};

		this.Bubble = new _ptools.Bubble({
			top: -120,
			left: -57
		});
		obj.parentNode.appendChild( this.Bubble.create() );

		if(this.Bubble.SHOW) {
			return;
		};

		this.Bubble.show();
		this.Bubble.setAttribute('content', msg);
	},

	hide : function()
	{
		this.Bubble.hide();
	}

}

function mietanfrage_show_bubble( msg )
{
	new _ptools.Bubble({
		content : msg
	}).show();
}

function mietanfrage_hide_bubble( msg )
{
	new _ptools.Bubble({
		content : msg
	}).show();
}

function mietanfrage_entry_opener( o )
{
	var nextSibling = o.nextSibling;
	var Parent = document.getElementById('moreitems');

	while(nextSibling.nodeType != 1) {
		nextSibling = nextSibling.nextSibling;
	};

	if( o.className == 'opener' )
	{
		o.className = 'opener plus';
		o.parentNode.style.height = '1px';
		nextSibling.style.display = 'none';

		new Fx.Morph(Parent, {
			duration: 500,
			transition: Fx.Transitions.Quad.easeOut
		}).start({
		   height: Parent.offsetHeight-320
		});

		return;
	};

	o.className = 'opener';

	var _height = Parent.offsetHeight + 320;

	new Fx.Morph(Parent, {
		duration: 500,
		transition: Fx.Transitions.Quad.easeOut,
		onComplete: function(){
			o.parentNode.style.height = '320px';
			nextSibling.style.display = '';
		}
	}).start({
	   height: _height
	});

};


function mietanfrage_set_sub(o)
{
	//KATEGORIES
	var oForm = document.forms['mietanfrage'];
	var _n = o.getAttribute('name').replace('[Maschinenkategorie]', '[Maschinentyp]');
	var _kat = o.value;

	var oSubKategories = oForm.elements[_n];
	oSubKategories.innerHTML = '';

	var _kategories = KATEGORIES[_kat];
	var domOption = document.createElement('option');

	for(var i = 0, len = _kategories.length; i < len; i++)
	{
		var o = domOption.cloneNode(true);
		o.value = _kategories[i];
		o.innerHTML = _kategories[i];

		oSubKategories.appendChild(o);
	};
};

function mietanfrage_add_entry()
{
	var oParent = document.getElementById('moreitems');
	var oEntry = document.getElementById('placebo_entry');

	if(!oParent || !oEntry) {
		return;
	};

	// indexes ersetzen
	mietanfrage_entry_index++;
	var entryhtml = oEntry.innerHTML.replace(/was\[1\]/g, 'was['+ mietanfrage_entry_index +']');

	var o = document.createElement('div');
	var o2 = o.cloneNode(true);
	var oDel = o.cloneNode(true);
	var oOpener = o.cloneNode(true);
		oOpener.onclick = function() {
			mietanfrage_entry_opener(this);
		};

	o2.innerHTML = entryhtml;

	o.className = 'entry';
	oOpener.className = 'opener';

	o.appendChild(oOpener);
	o.appendChild(o2);

	oDel.style.position = 'absolute';
	oDel.style.right = '-20px';
	oDel.style.top = '-5px';

	oDel.appendChild( new _ptools.Button({
		name : 'del',
		image : URL_BIN_DIR +'16x16/cancel.png',
		onclick : function(_me) {
			if(window.confirm('Möchten Sie wirklich den Eintrag löschen?')) {
				var Parent = _me.getAttribute('o').parentNode;
				var _height = Parent.offsetHeight - 320;

				Parent.removeChild(_me.getAttribute('o'));
				new Fx.Morph(Parent, {
					duration: 500,
					transition: Fx.Transitions.Quad.easeOut
				}).start({
				   height: _height
				});
			}
		},
		alt : 'Eintrag löschen',
		title : 'Eintrag löschen',
		o : o
	}).create() );

	o2.appendChild(oDel);

	if(Fx && Fx.Morph)
	{
		var _height = oParent.offsetHeight + 320;

		new Fx.Morph(oParent, {
			duration: 500,
			transition: Fx.Transitions.Quad.easeOut,
			onComplete: function(){
				oParent.appendChild(o);
			}
		}).start({
		   height: _height
		});

		return;
	};

	oParent.appendChild(o);
};

function ajax_hkl_Get_MyList(){

	var _MyList = _Ajax.syncPost('ajax_hkl_Get_MyList', {
		Project_name : _Project.name,
		Project_lang : _Project.lang
	});

	var oDiv =document.getElementById('MyListContent');

	if(oDiv) {
		oDiv.innerHTML =_MyList;
	}
	if(typeof ET_Event != 'undefined') {
		ET_Event.eventStart('Kategorie',  'Merkliste',  'Merkliste anzeigen', 'Gebrauchtmaschinen, Kategorie, Merkliste');
	};

	return false;
}

function ajax_hkl_add_MyList(id){

	var _MyList = _Ajax.syncPost('ajax_hkl_add_MyList', {
		maschine : id
	});

	new _ptools.Info({name:'google_info', text:'Infomappe zur Liste hinzugef&uuml;gt!'}).create();
	ajax_hkl_Get_MyList();

	if(typeof ET_Event != 'undefined') {
		ET_Event.eventStart('Kategorie', 'Item', 'Merkliste', 'Gebrauchtmaschinen, Kategorie, Item, Merkliste');
	};


	return false;
}

function ajax_hkl_add_send_now(id,cid){

	var _MyList = _Ajax.syncPost('ajax_hkl_add_MyList', {
		maschine : id
	});

	ajax_hkl_Get_MyList();

	ajax_hkl_MyList_get_form(cid);

	if(typeof ET_Event != 'undefined') {
		ET_Event.eventStart('Kategorie', 'Item', 'Kontakt', 'Gebrauchtmaschinen, Kategorie, Item, Kontakt')
	};

	return false;
}


function ajax_hkl_del_MyList(id){

	var _MyList = _Ajax.syncPost('ajax_hkl_del_MyList', {
		maschine : id
	});

	id= 'tr'+id;
	var parent = document.getElementById(id).parentNode;
	var child = document.getElementById(id);
	parent.removeChild(child);

	return false;

}

function ajax_hkl_MyList_get_form(id){

	var _MyListForm = _Ajax.syncPost('ajax_hkl_MyList_get_form', {
		Project_name : _Project.name,
		Project_lang : _Project.lang
	});

	if(typeof ET_Event != 'undefined') {
		ET_Event.eventStart('Kategorie', 'Merkliste', 'Infomappe anfordern', 'Gebrauchtmaschinen, Kategorie, Infomappe');
	};

	var oDiv =document.getElementById(id);
	oDiv.innerHTML =_MyListForm;

	return false;
}

function ajax_hkl_MyList_send_form(){

	var f = document.forms['hkl_infomappeform'];

	if(f)
	{
		var tmp = new Object();
		for(var i = 0, len = f.elements.length; i < len; i++)
		{
			if(f.elements[i].type == 'checkbox' || f.elements[i].type == 'radio')
			{
				if(f.elements[i].checked)
				{
					tmp[f.elements[i].name] = 1;
				} else
				{
					tmp[f.elements[i].name] = 0;
				};

			} else
			{
				tmp[f.elements[i].name] = f.elements[i].value;
			};
		};

		if(hkl_MyList_check_form(tmp))
		{
			var _MyListForm = _Ajax.syncPost('ajax_hkl_MyList_send_form', {
				Project_name : _Project.name,
				Project_lang : _Project.lang,
				data: JSON.stringify(tmp)
			});

			var oDiv =document.getElementById('GM_Form');
			oDiv.innerHTML =_MyListForm;

			if(typeof ET_Event != 'undefined') {
				ET_Event.eventStart('Kategorie', 'Kontakt', 'Kontakt-infomappe gesendet', 'Gebrauchtmaschinen, Kategorie, Item, Merkliste');
			};

			hkl_intelliad(oDiv);

		};

	};

	return false;


}

function hkl_MyList_check_form(data){

	var _errorFields = "Bitte füllen Sie alle Pflichtfelder aus.\n Please cehck all required Fields!  \n";
	var _error = false;

	if (data['Vorname'] == '') {
		_errorFields = _errorFields+"\n Vorname";
		_error = true;
	};
	if (data['Nachname'] == '') {
		_errorFields = _errorFields+"\n Nachname";
		_error = true;
	};
	if (data['Strasse'] == '') {
		_errorFields = _errorFields+"\n Strasse";
		_error = true;
	};
	if (data['PLZ'] == '') {
		_errorFields = _errorFields+"\n PLZ";
		_error = true;
	};
	if (data['Land'] == '') {
		_errorFields = _errorFields+"\n Land";
		_error = true;
	};
	if (data['EMail'] == '') {
		_errorFields = _errorFields+"\n E-Mail";
		_error = true;
	};

	if (_error) {
		alert(_errorFields);
		return false;
	} else {
		return true;
	};


}

function ajax_hkl_show_details(id){

	var _Details = _Ajax.syncPost('ajax_hkl_show_details', {
		Project_name : _Project.name,
		Project_lang : _Project.lang,
		id: id
	});

	hs.htmlExpand(document.getElementById('gebraucht_details'),{ contentId: 'details' , align: 'center', width: 600 , height: 450, preserveContent:false} );
	document.getElementById('detailsContent').innerHTML = _Details;

	if(typeof ET_Event != 'undefined') {
		ET_Event.eventStart('Kategorie', 'Item', 'Details', 'Gebrauchtmaschinen, Kategorie, Item, Details');
	};


	return false;

}

function ajax_hkl_show_details_send(id){

	hs.htmlExpand(document.getElementById('gebraucht_details'),{ contentId: 'details' , align: 'center', width: 600 , height: 450, preserveContent:false} );
	//document.getElementById('detailsContent').innerHTML = _Details;
	ajax_hkl_add_send_now(id,'detailsContent');

	return false;

}



function show_select_kat(){

	if(document.getElementById('select_kat')){
		document.getElementById('select_kat').style.display = 'block';

	}
}

function hkl_intelliad (id)
{

	id.innerHTML = id.innerHTML+'<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1049655181/?value=200.0&amp;label=uUCuCPnpogEQje_B9AM&amp;guid=ON&amp;script=0"/>';

}



