
function thTagPaddingUnset(nodeTbody,elIndex)
{
	trTagIndex = 1;
	nodeTbody.get('children').each(function(nodeTR)
	{
		if ( trTagIndex == 1 )
		{
			thTagIndex = 1;
			nodeTR.get('children').each(function(nodeTH)
			{
				if ( thTagIndex == elIndex )
				{
					nodeTH.setStyle('paddingRight','0');
				}
				thTagIndex++;
			});
		}
		trTagIndex++;
	});
}
function thTagPaddingFurImage(nodeTbody,elIndex)
{
	trTagIndex = 1;
	nodeTbody.get('children').each(function(nodeTR)
	{
		if ( trTagIndex == 1 )
		{
			thTagIndex = 1;
			nodeTR.get('children').each(function(nodeTH)
			{
				if ( thTagIndex == elIndex )
				{
					nodeTH.setStyle('paddingLeft','10px');
					nodeTH.setStyle('paddingRight','10px');
				}
				thTagIndex++;
			});
		}
		trTagIndex++;
	});
}
function arrange_table_paddings()
{
	Y.all('table').each(function(nodeTable)
	{
		thTagsEsGibt = false;
		nopaddingIndex = new Array;
		nodeTable.get('children').each(function(nodeTbody)
		{
			nodeTbody.get('children').each(function(nodeTR)
			{
				elIndex = 1;
				nodeTR.get('children').each(function(el)
				{
					if ( el.get('tagName') == 'TH' )
					{
						thTagsEsGibt = true;
						if ( el.hasClass('nopadding') )
						{
						    nopaddingIndex.push(elIndex);
						}
					}
					if ( el.get('tagName') == 'TD' || el.get('tagName') == 'TH' )
					{
						if ( thTagsEsGibt )
						{
							imgTagEsGibt = false;
							el.get('children').each(function(elChildren)
							{
								if ( elChildren.get('tagName') == 'IMG' )
								{
									imgTagEsGibt = true;
									elChildren.setAttribute('align','middle');
								}
								if ( elChildren.get('tagName') == 'A' )
								{
									node = Y.Node.create(elChildren.get('innerHTML'));
									if ( is_object(node) && node.get('tagName') == 'IMG' )
									{
										imgTagEsGibt = true;
										node.destroy();
										// node.setAttribute('align','middle');
										//elChildren.set('innerHTML',node.get('outerHTML'));
									}
								}
							});
							if ( imgTagEsGibt )
							{
								//thTagPaddingUnset(nodeTbody,elIndex);
								thTagPaddingFurImage(nodeTbody,elIndex);
								el.setStyle('textAlign','center');
								if ( parseInt(el.getStyle('paddingLeft')) == nodeTable.getAttribute('cellpadding') || empty(nodeTable.getAttribute('cellpadding')) )
								{
									el.setStyle('paddingLeft','10px');
								}
								if ( parseInt(el.getStyle('paddingRight')) == nodeTable.getAttribute('cellpadding') || empty(nodeTable.getAttribute('cellpadding')) )
								{
									el.setStyle('paddingRight','10px');
								}
							}
							else
							{
								if ( parseInt(el.getStyle('paddingLeft')) == 1 )
								{
								    el.setStyle('paddingLeft','2px');
								}
								if ( !in_array(elIndex,nopaddingIndex) )
								{
									if ( parseInt(el.getStyle('paddingRight')) == nodeTable.getAttribute('cellpadding') || empty(nodeTable.getAttribute('cellpadding')) )
									{
									    el.setStyle('paddingRight','20px');
									}
								}
								else
								{
									el.setAttribute('nowrap','nowrap');
								}
								if ( el.getContent() == parseInt(el.getContent()) )
								{
									el.setStyle('textAlign','right');
								}
							}
						}
					}
					elIndex++;
				});
			});
		});
	});
}

function put_click_handler(className)
{
	Y.Event.purgeElement("A", false, "click");
	Y.all('.'+className).each(function(nodeTR)
	{
		nodeTR.get('children').each(function(nodeTD)
		{
			nodeTD.get('children').each(function(el)
			{
				if ( el.get('tagName') == 'A' )
				{
					nodeTD.setStyle('cursor','pointer');
					nodeTD.on('click',function()
					{
					    countTagsA = 0;
					    this.get('children').each(function(el)
						{
							if ( el.get('tagName') == 'A' )
							{
							    if ( el.getAttribute('href') != '' )
							    {
							        countTagsA++;
							    }
						    }
						});
						if ( countTagsA == 1 )
						{
						    this.get('children').each(function(el)
						    {
							    if ( el.get('tagName') == 'A' )
							    {
								    onclickCode = el.getAttribute('onclick');
								    onclickCode += '; event.cancelBubble=true;';
								    el.setAttribute('onclick',onclickCode);
								    el.simulate('click');
							    }
						    });
						}
					});
				}
			});
		});
	});
}
function put_check_handler()
{
	Y.all('input[type=checkbox], input[type=radio]').each(function(nodeInput)
	{
		if ( elSibling = nodeInput.next(function(el){return el.get('tagName') == 'SPAN' || el.get('tagName') == 'IMG';}) )
		{
			elSibling.on('click',function()
			{
				if ( elSiblingPrev = this.previous(function(el){return el.get('tagName') == 'INPUT' && ( el.getAttribute('type') == 'checkbox' || el.getAttribute('type') == 'radio' );}) )
				{
					if ( elSiblingPrev.getAttribute('type') == 'checkbox' )
					{
						if ( elSiblingPrev.getAttribute('checked') )
						{
							elSiblingPrev.removeAttribute('checked');
						}
						else
						{
							elSiblingPrev.setAttribute('checked','checked');
						}
					}
					else if ( elSiblingPrev.getAttribute('type') == 'radio' )
					{
						elSiblingPrev.setAttribute('checked','checked');
					}
				}
			});
			elSibling.setStyle('cursor','pointer');
		}
	});
}
function assign_ids()
{
	Y.all('input').each(function(el)
	{
		if ( !empty(el.getAttribute('name')) )
		{
			if ( empty(el.getAttribute('id')) )
			{
				el.setAttribute('id','i_'+el.getAttribute('name'));
			}
		}
	});
	Y.all('select').each(function(el)
	{
		if ( !empty(el.getAttribute('name')) )
		{
			if ( empty(el.getAttribute('id')) )
			{
				el.setAttribute('id','sel_'+el.getAttribute('name'));
			}
		}
	});
}

function auswahlRecordOver(id)
{
	nodeDIV = Y.one('#d_auswahlRecord_'+id);
	nodeS = Y.one('#s_auswahlRecord_'+id);
	nodeINPUT = Y.one('#i_auswahlRecordId');
	nodeDIV.setStyle('cursor','pointer');
	if ( nodeINPUT.get('value') != id )
	{
		nodeDIV.addClass('einblendung');
		//nodeS.setStyle('fontWeight','bold')
	}
}
function auswahlRecordOut(id)
{
	nodeDIV = Y.one('#d_auswahlRecord_'+id);
	nodeS = Y.one('#s_auswahlRecord_'+id);
	if ( nodeINPUT.get('value') != id )
	{
		nodeINPUT = Y.one('#i_auswahlRecord');
		nodeDIV.removeClass('einblendung');
		nodeS.setStyle('fontWeight','');
	}
}
function auswahlRecordClick(id)
{
	Y.all('.auswahlRecord').removeClass('einblendungStatisch');
	Y.all('.auswahlRecordTitel').setStyle('color','#676767');
	Y.all('.auswahlRecordTitel').setStyle('fontWeight','');
	nodeDIV = Y.one('#d_auswahlRecord_'+id);
	nodeS = Y.one('#s_auswahlRecord_'+id);
	nodeINPUT = Y.one('#i_auswahlRecordId');
	nodeINPUT.set('value',id);
	nodeDIV.removeClass('einblendung');
	nodeDIV.addClass('einblendungStatisch');
	//nodeS.setStyle('color','#000000');
	nodeS.setStyle('fontWeight','bold');
}

function loadImageToViewer(src,layerId)
{
	YUI().use('node',function(Y)
	{
		nodeDIV = Y.one('#'+layerId);
		nodeIMG = nodeDIV.create('<img />');
		nodeIMG.set('src',src);
		docScrollY = Y.DOM.docScrollY();
		winHeight = Y.DOM.winHeight();
		docScrollmiddle = docScrollY + ( winHeight / 2 );
		divXY = nodeDIV.getXY();
		divY = divXY[1];
		if ( docScrollY > divY || divY > docScrollmiddle )
		{
			if ( docScrollY < 100 )
			{
				marginTop = 140;
			}
			else
			{
				marginTop = 20;
			}
			nodeDIV.setY(docScrollY+marginTop);
		}
		nodeDIV.setContent(nodeIMG);
	});
}

function accordion(pClassName,divClassName)
{
	var textNodeOpen = null;
	YUI().use('node', 'anim', function(Y)
	{
		var anim = new Y.Anim({
			node: '.usluga_text',
			to: { height: 0 },
			easing: Y.Easing.backIn
		});
		if ( zagolovki = Y.all('.'+pClassName) )
		{
			zagolovki.setStyle('cursor','pointer');
			zagolovki.each(function(el)
			{
				anchor = Y.Node.create('<a></a>');
				anchor.setAttribute('name',el._yuid);
				if ( !(Y.UA.ie > 0) )
				{
					el.insertBefore(anchor);
				}
			});
			zagolovki.on('click', function(e)
			{
				zagolovok = Y.one(e.target);
				if ( zagolovok.get('tagName') != 'P' )
				{
					pNode = zagolovok.ancestor(function(el){return el.get('tagName') == 'P';});

				}
				else
				{
					pNode = zagolovok;	
				}
				if ( textNode = pNode.next() )
				{
					var animBack = new Y.Anim({
						node: textNode,
						to: { opacity: 0, height: 0 },
						duration: 0.2,
						easing: Y.Easing.easeNone
					});
					var animUp = new Y.Anim({
						node: textNode,
						from: { opacity: 0, height: function(el){return el.height;}},
						to: { opacity: 1, height: function(el){return el.height;}},
						duration: 0.6,
						easing: Y.Easing.easeNone
					});
					
					if ( textNode.getStyle('display') == 'block' )
					{
						animBack.on('end',function()
						{
							textNode.setStyle('display','none');
							textNodeOpen = null;
						});
						animBack.run();
					}
					else
					{
						textNode.setStyle('display','block');
						if ( !(textNode.height>0) )
						{
							textNode.height = textNode.get('scrollHeight');
						}
						//textNode.setStyle('height',textNode.height);
						
						if ( textNodeOpen == null )
						{
							animUp.on('end',function()
							{
								pNode = textNode.previous();
								document.location.replace('#'+pNode._yuid);
								textNodeOpen = textNode;
							});
							animUp.run();
						}
						else
						{
							animUp.on('end',function()
							{
								textNodeOpen.setStyle('display','none');
								pNode = textNode.previous();
								document.location.replace('#'+pNode._yuid);
								textNodeOpen = textNode;
							});
							animBack.set('node',textNodeOpen);
							animUp.run();
							animBack.run();
						}
					}
				}
			});
			texty = Y.all('.'+divClassName);
			texty.setStyle('display','none').setStyle('marginLeft','10px');
			//textNodeOpen = Y.one('.'+divClassName);
		}
	});
}

