	/*------------------------------------------
		Byxal.com - Scripts
	------------------------------------------*/

//---------------------------------------------------------------------------------------------------

	document._createElement	= document.createElement;

	document.createElement	= function( TagName ) {
		return document._createElement( TagName );
	}

	function Elements( OBJ, TagName ) {
		if( !TagName )
			return document.getElementsByTagName( OBJ );
		else
			return OBJ.getElementsByTagName( TagName );
	}

	function Element( ID ) { return document.getElementById( ID ); }

	function PreventDefault( e ) {
		if( window.event )
			window.event.returnValue = false;
		else if( e )
			e.preventDefault();
	}

//---------------------------------------------------------------------------------------------------

	function SetPosition( OBJ, POS, Top, Right, Bottom, Left, Parent, Flag ) {
		var PositionTypes	= {
			'r' : 'relative',
			's' : 'static',
			'a' : 'absolute',
			'f' : 'fixed'
		};

		OBJ.style.position	= PositionTypes[POS];

		OBJ.style.bottom	= Bottom == null ? null : Bottom + 'px';
		OBJ.style.right		= Right == null ? null : Right + 'px';
		OBJ.style.left		= Left == null ? null : Left + 'px';
		OBJ.style.top		= Top == null ? null : Top + 'px';

		if( Parent )
			Parent.appendChild( OBJ );

		/*@cc_on @if( @_jscript_version < 5.7 )
			if( POS	== 'a' && !Flag ) {
				var Parent	= OBJ.parentNode;

				if( Parent.className.match(/normal/) )
					OBJ.style.bottom = (Parent.offsetHeight % 2 == 1 ? 1*Bottom : 1*Bottom - 1) + 'px';
				else
					OBJ.style.bottom = (Parent.offsetHeight % 2 == 1 ? 1*Bottom : 1*Bottom) + 'px';

				OBJ.style.right = (Parent.offsetWidth % 2 == 1 ? 1*Right - 1 : 1*Right) + 'px';
			}
		@end @*/
	}

	function RoundThingsUp() {
		var	DIVS	= Elements( 'div' ),
			Blue	= null,
			x		= null,
			Angle1	= null,
			Angle2	= null,
			Angle3	= null,
			Angle4	= null
		;

		for( var i = 0; i < DIVS.length; i++ ) {
			if( DIVS[i].className.match(/^box/) ) {
				Angle1	= document.createElement('img');
				Angle2	= document.createElement('img');
				Angle3	= document.createElement('img');
				Angle4	= document.createElement('img');

				Blue	= DIVS[i].className.match(/blue/) ? 'blue-box-c-' : 'box-c-';

				Angle1.setAttribute( 'src', 'images/' + Blue + 't-l.gif' );
				Angle2.setAttribute( 'src', 'images/' + Blue + 'b-l.gif' );
				Angle3.setAttribute( 'src', 'images/' + Blue + 't-r.gif' );
				Angle4.setAttribute( 'src', 'images/' + Blue + 'b-r.gif' );

				$TOP	= DIVS[i].className.match(/normal/) ? -1 : 0;

				SetPosition( Angle1, 'a', $TOP, x, x, -1, DIVS[i] );
				SetPosition( Angle2, 'a', x, x, 0, -1, DIVS[i] );
				SetPosition( Angle3, 'a', $TOP, -1, x, x, DIVS[i] );
				SetPosition( Angle4, 'a', x, -1, 0, x, DIVS[i] );						
			}
		}

		Angle1	= document.createElement('img');
		Angle2	= document.createElement('img');

		Angle1.setAttribute( 'src', 'images/footer-left.gif' );
		Angle2.setAttribute( 'src', 'images/footer-right.gif' );

		Angle1.style.position	= 'absolute';
		Angle2.style.position	= 'absolute';
		Angle1.style.top		= '-1px';
		Angle2.style.top		= '-1px';
		Angle1.style.left		= '-1px';
		Angle2.style.right		= '-1px';

		Element('footer').appendChild( Angle1 );
		Element('footer').appendChild( Angle2 );
	}

	function BeautifyInputs() {
		var INPUTS	= Elements( 'input' ),
			SPAN	= null,
			IMG1	= null,
			IMG2	= null,
			Match	= null
		;

		for( var i = 0; i < INPUTS.length; i++ ) {
			Match	= INPUTS[i].className.match(
				/^entry\/(\d+)\/(\d+)\/(\d+)\/(\d+)\/(\d+)\//
			);

			if( Match ) {
				SPAN	= document.createElement( 'span' );
				IMG1	= document.createElement( 'img' );
				IMG2	= document.createElement( 'img' );

				SPAN.className	= 'button';
				IMG1.className	= 'b-left';
				IMG2.className	= 'b-right';

				IMG1.setAttribute( 'src', 'images/input-left.gif' );
				IMG2.setAttribute( 'src', 'images/input-right.gif' );

				INPUTS[i].parentNode.insertBefore( SPAN, INPUTS[i] );

				SPAN.style.margin		= Match[1] + 'px ' + Match[2] + 'px ' + Match[3] + 'px ' + Match[4] + 'px';
				INPUTS[i].style.width	= (Match[5] - 20) + 'px';
				INPUTS[i].style.margin	= 0;

				INPUTS[i].onfocus	= function() {
					this.className	+= ' active';

					if( this.value == this.defaultValue && !this.className.match(/ edit/) )
						this.value		= '';
				}

				INPUTS[i].onblur	= function() {
					this.className	= this.className.replace( ' active', '' );

					if( this.value == '' && !this.className.match(/ edit/) )
						this.value		= this.defaultValue;
				}

				SPAN.appendChild( INPUTS[i] );
				SPAN.appendChild( IMG1 );
				SPAN.appendChild( IMG2 );
			}
		}
	}

	function SetRollovers() {
		if( !Element('popular') )
			return;

		var ITEMS	= Elements( Element('popular'), 'li' );

		for( var i = 0; i < ITEMS.length; i++ ) {
			ITEMS[i].onmouseover	= function() { this.className	= 'hover'; }
			ITEMS[i].onmouseout		= function() { this.className	= ''; }
		}
	}

	function OperateMenu() {
		var Menu	= Element( 'menu' );
		var List	= Elements( Menu, 'li' );

		for( var i=0; i < List.length; i++ ) {
			List[i].onmouseover	= function() { this.className = 'drop'; }
			List[i].onmouseout	= function() { this.className = ''; }
		}
	}

	function OptionValue( OBJ ) {
		return ( OBJ.value == '' ) ? OBJ.text : OBJ.value;
	}

	function BeautyfySelects() {
		var SELECTS		= Elements( 'select' ),
			SelectBBox	= null,
			SPAN		= null,
			UL			= null,
			Selected	= null,
			OPT			= null,
			LI			= null
		;

		for( var i = 0; i < SELECTS.length; i++ ) {
			Match	= SELECTS[i].parentNode.className.match( /^entry/ );

			if( Match ) {
				SELECTS[i].style.display = 'none';

				SelectBBox	= document.createElement( 'div' );
				SPAN		= document.createElement( 'span' );
				UL			= document.createElement( 'ul' );

				Selected		= document.createTextNode( SELECTS[i].options[SELECTS[i].selectedIndex].text );
				SelectBBox.List	= UL;

				SelectBBox.onmousedown	= function( e ) {
					if( window.Opened ) {
						var flag = ( window.Opened.parentNode == this.parentNode );
		
						window.Opened.parentNode.className	= 'SelectBox';
						window.Opened.style.display 		= 'none';
						window.Opened						= null;
		
						if( flag )
							return;
					}

					this.className				= 'select-box top';
					this.List.style.display		= 'block';

					window.Opened	= this.List;

					document.onmousedown	= function( e ) {
						var ThisElement	= e ? e.target : window.event.srcElement;

						if( !window.Opened || window.Opened.parentNode == ThisElement || window.Opened.parentNode == ThisElement.parentNode )
							return;

						window.Opened.parentNode.className	= 'select-box';
						window.Opened.style.display			= 'none';
						window.Opened						= null;
						document.onmousedown				= null;
					}
				}

				var SelectedIndex	= SELECTS[i].selectedIndex;

				for( var j = 0; j < SELECTS[i].options.length; j++ ) {
					LI			= document.createElement('li');
					OPT			= document.createElement('a');

					OPT.OptionValue	= OptionValue( SELECTS[i].options[j] );
					OPT.OptionText	= SELECTS[i].options[j].text;
					OPT.SelectBox	= SELECTS[i];
					OPT.title		= OPT.OptionText;
					OPT.VAL			= SPAN;
					OPT.List		= UL;

					OPT.appendChild( document.createTextNode( OPT.OptionText ) );

					if( j == SelectedIndex ) {
						OPT.VAL.title		= OPT.OptionText;
						OPT.className		= 'selected';
						OPT.List.selected	= OPT;
					}

					OPT.onmousedown = function( e ) {
						this.SelectBox.value			= this.OptionValue;
						this.VAL.firstChild.data		= this.OptionText;
						this.VAL.title					= this.OptionText;
						this.List.selected.className	= '';

						this.List.selected				= this;
						this.className					= 'selected';

						PreventDefault( e );
					}

					LI.appendChild( OPT );
					UL.appendChild( LI );
				}

				SelectBBox.className	= 'select-box';

				SPAN.appendChild( Selected );
				SelectBBox.appendChild( SPAN );
				SelectBBox.appendChild( UL );

				SELECTS[i].parentNode.parentNode.insertBefore( SelectBBox, SELECTS[i].parentNode );
			}
		}
	}

	function CreateResetButton() {
		var INPUTS	= Elements( 'input' );

		for( var i = 0; i < INPUTS.length; i++ ) {
			if( INPUTS[i].type == 'reset' ) {
				var Match	= INPUTS[i].className.match( /^(\d+)\/(\d+)\/(\d+)\/(\d+)/ );
				var IMG		= document.createElement( 'img' );
				var A		= document.createElement( 'a' );

				IMG.setAttribute( 'src', 'images/reset-button.gif' );
				IMG.setAttribute( 'alt', INPUTS[i].value );
				A.setAttribute( 'href', 'javascript://' );

				if( Match ) A.style.margin	= Match[1] + 'px ' + Match[2] + 'px ' + Match[3] + 'px ' + Match[4] + 'px';

				A.form		= INPUTS[i].form;
				A.appendChild( IMG );

				A.onclick	= function() { this.form.reset(); }

				INPUTS[i].parentNode.insertBefore( A, INPUTS[i] );
				INPUTS[i].parentNode.removeChild( INPUTS[i] );
			}
		}
	}

	function BeautyfyTextareas() {
		var TEXTAREAS	= Elements( 'textarea' );

		for( var i = 0; i < TEXTAREAS.length; i++ ) {
			Match	= TEXTAREAS[i].className.match(
				/^entry\/(\d+)\/(\d+)\/(\d+)\/(\d+)\/(\d+)\/(\d+)\//
			);

			if( Match ) {
				TEXTAREAS[i].style.margin	= Match[1] + 'px ' + Match[2] + 'px ' + Match[3] + 'px ' + Match[4] + 'px';
				TEXTAREAS[i].style.width	= Match[5] + 'px';
				TEXTAREAS[i].style.height	= Match[6] + 'px';

				TEXTAREAS[i].onfocus	= function() {
					this.className	+= ' active';

					if( this.value == this.defaultValue && !this.className.match(/ edit/) )
						this.value		= '';
				}

				TEXTAREAS[i].onblur	= function() {
					this.className	= this.className.replace( ' active', '' );

					if( this.value == '' && !this.className.match(/ edit/) )
						this.value		= this.defaultValue;
				}
			}
		}
	}

	function ClearIfDefault( OBJ ) {
		return OBJ.value == OBJ.defaultValue ? '' : OBJ.value;
	}

	function Send( FORM, TYPE ) {
		var URI		= 'ajax.php?action=feedback&type=' + TYPE;
		var ajax	= new Ajax();

		var Name	= ClearIfDefault( FORM['name'] );
		var Email	= ClearIfDefault( FORM['email'] );
		var Subject	= ClearIfDefault( FORM['subject'] );
		var Message	= ClearIfDefault( FORM['message'] );

		Params	 = 'name='		+ escape( Name );
		Params	+= '&email='	+ escape( Email );
		Params	+= '&subject='	+ escape( Subject );
		Params	+= '&message='	+ escape( Message );

		ajax.sendRq( 'POST', URI, Feedback, Params, FORM );
	}

	function Feedback( response, FORM ) {
		var Parent	= response.documentElement;

		var item	= Parent.tagName == 'errors' ? 'error' : 'ok';

		var Count	= Elements( Parent, 'count' )[0].getAttribute( 'value' );
		var Errors	= Elements( Parent, item );
		var row		= '';

		Element('system_message').className	= item;
		Element('system_message').innerHTML = '';

		Element('system_message').style.display = 'block';

		if( Parent.tagName == 'errors' ) {
			Element('system_message').innerHTML	= 'Формулярът отчете <strong>' + Count + ' грешк' + ( Count == 1 ? 'а' : 'и' ) + '</strong>';

			row	= "<br />&nbsp;&nbsp;&nbsp;- ";
		}

		for( var i = 0; i < Errors.length; i++ )
			Element('system_message').innerHTML += row + Errors[i].firstChild.data;

		if( Parent.tagName != 'errors' )
			FORM.reset();

		// Stinkin' IE...
		Element('footer').style.clear = 'both';
	}

	var myCart	= {
		error	: false,

		// Добавяне към количката
		add		: function( ID ) {
			var ajax	= new Ajax();

			ajax.sendRq( 'POST', 'ajax.php?action=add-to-cart', this.update, 'id=' + ID );
		},

		// Премахване от количката
		remove : function( OBJ, ID, PRICE ) {
			OBJ.parentNode.parentNode.removeChild( OBJ.parentNode );

			var ajax	= new Ajax();

			ajax.sendRq( 'POST', 'ajax.php?action=remove-from-cart', function() {}, 'id=' + ID );

			Element( 'price' ).innerHTML	= parseFloat(Element( 'price' ).innerHTML) - parseFloat(PRICE);
			Element( 'artnum' ).innerHTML	= parseInt( Element( 'artnum' ).innerHTML ) - 1;
		},

		// Добавяне към количката, Статус
		update	: function( response ) {
			var DocumentElement	= response.documentElement;

			// Добавен материал - Process
			if( Elements( DocumentElement, 'added' ).length == 1 ) {
				Element( 'artnum' ).innerHTML			= Element( 'artnum' ).innerHTML * 1 + 1;
				Element( 'artnum' ).parentNode.title	= 'Моята количка: ' + Element( 'artnum' ).innerHTML + ' артикул(а)';

				window.location.href	= '#';

				window.alert( 'Материалът е добавен към вашата количка!' );
			}
			this.error	= false;

			// Грешка
			if( Elements( DocumentElement, 'error' ).length == 1 ) {
				this.error	= true;

				if(
					Elements( DocumentElement, 'error' )[0].getAttribute( 'name' ) == 'login' &&
					window.confirm(
						Elements( DocumentElement, 'error' )[0].getAttribute( 'value' ).replace('\\n',"\n")
					)
				)
					window.location.href	= 'login.html';
				else
					window.alert( Elements( DocumentElement, 'error' )[0].getAttribute( 'value' ) );
			}
		}
	};

	function preventDefault( event ) {
		event.returnValue = false;

		if (event.preventDefault)
			event.preventDefault();
	}

	function searched( ID, A, event ) {
		if(
			(event.button && event.button == 1) ||
			(event.which && event.which == 1)
		) {
			var URI	= A.href;

			( new Ajax() ).sendRq(
				'GET', 'ajax.php?action=searched&searched=' + ID,
				function( response, URI ) { window.location = URI; },
				null, URI
			);

			preventDefault( event );
		}
	}

	function Rating() {
		var
			Links	= Elements( 'a' ),
			ID		= null,
			Ranks	= null,
			j = 0, i = 0,
			ok		= ''
		;

		for( i; i < Links.length; i++ ) {
			if( Links[i].rel.match(/rank\[\d+\]/) ) {
				ID	= Links[i].rel.match(/rank\[(\d+)\]/)[1];

				if( Links[i].parentNode.className.indexOf('rated') >= 0 )
					continue;

				Links[i].parentNode.defaultClassName	= Links[i].parentNode.className;
				Links[i].parentNode.onmouseout	= function() {
					this.className = this.defaultClassName;
				}

				Ranks	= Elements( Links[i].parentNode, 'a' );

				for( j = 0; j < Ranks.length; j++ ) {
					ok				= j == 0 ? 'а' : 'и';
					Ranks[j].num	= j + 1;

					Ranks[j].title	= 'Оцени този материал с ' + (j + 1) + ' точк' + ok;

					Ranks[j].onmouseover = function() {
						this.parentNode.className	= "ranker marked" + this.num;
					}

					Ranks[j].onmouseout = function() {
						this.parentNode.className	= 'ranker';
					}

					Ranks[j].onclick	= function() {
						var ajax	= new Ajax;

						ajax.sendRq( 'GET', 'ajax.php?action=rate&id=' + ID + '&rate=' + this.num, Rate, null, this.parentNode );

						this.parentNode.style.height		= '23px';
						this.parentNode.style.background	= "url('images/ajax-loader.gif') center center no-repeat";

						var Vals	= Elements( this.parentNode, 'a' );

						for( var k = 0; k < Vals.length; k++ ) {
							Vals[k].onmouseover = Vals[k].onmouseout = null;
							Vals[k].style.display = 'none';
						}

						this.parentNode.onmouseout	= null;
					}
				}
			}
		}
	}

	function Rate( Response, Rater ) {
		var Stars	= Elements( Response, 'rater' )[0].firstChild.data;
		var Marked	= Elements( Response, 'marked' )[0].getAttribute( 'value' );

		Rater.className	= 'rater ' + Marked + ' rated';
		Rater.innerHTML	= Stars;

		Rater.style.background		= '';
		Rater.style.height			= '14px';

		Rater.parentNode.style.color = '#b30004';

		Rater.parentNode.appendChild( document.createElement( 'br' ) );
		Rater.parentNode.appendChild( document.createTextNode( 'Гласът Ви е отчетен. Благодарим, че гласувахте!' ) );
		Rater.parentNode.appendChild( document.createElement( 'br' ) );
	}

	function centerAlert() {
		var ALERT	= Element( 'alert' );

		var scrollTop		= document.documentElement.scrollTop;
		var screenCenter	= Math.floor( document.documentElement.clientHeight / 2 ) - 91;

		ALERT.style.top		= (scrollTop + screenCenter) + 'px';

		return centerAlert;
	}

	function download( ID, FORMAT, BANK, SMS, PREVOD, FREE, LOGGED ) {
		if( FREE ) {
			window.location	= 'download.php?id=' + ID + '&format=' + FORMAT;
			return;
		}

		if( !LOGGED ) {
			if(
				window.confirm(
					'За да закупите материал трябва да имате регистриран акаунт.\n' +
					'Продължете към ВХОД?'
				)
			)
				window.location	= 'login.html#bestview';

			return;
		}

		var SHADE	= Element( 'shade' );
		var ALERT	= Element( 'alert' );

		SHADE.style.height	= document.documentElement.scrollHeight + 'px';
		SHADE.style.filter	= 'alpha(opacity=50)';
		SHADE.style.opacity	= '.5';
		SHADE.style.left	= '0px';
		SHADE.style.width	= document.body.offsetWidth + 'px';

		window.onscroll	= window.onresize = centerAlert();

		SHADE.style.display	= 'block';
		ALERT.style.display	= 'block';

		if( !PREVOD )
			Element( 'prevodb' ).style.display	= 'none';
		if( !BANK ) {
			Element( 'epayb' ).style.display	= 'none';
			Element( 'cartb' ).style.display	= 'none';
		}

		if( SMS && !BANK && !PREVOD && !FREE ) {
			Element( 'activation' ).style.display	= 'block';
			Element( 'options' ).style.display		= 'none';
		}
		else if( !SMS && (BANK || PREVOD) && !FREE ) {
			Element( 'smsb' ).style.display	= 'none';
		}
	}

	function ActivateSMS( FORM, SMS2 ) {
		var num	= FORM.elements['activnum'].value;

		if( !num.match( /^[a-zA-Z0-9]{6}$/ ) ) {
			window.alert( 'Невалиден код. Моля, опитайте отново' );
			return;
		}

		var URI		= 'ajax.php?action=activation&num=' + escape(num);
		if( SMS2 ) URI += '&sms2=sms2';
		var ajax	= new Ajax();

		Element( 'activation' ).style.display	= 'none';
		Element( 'loader' ).style.display		= 'block';

		ajax.sendRq( 'GET', URI, ActivateResult, null, null );
	}

	function ActivateResult( response ) {
		var Result	= Elements( response, 'result' )[0].getAttribute( 'value' );
		var Status	= Elements( response, 'result' )[0].getAttribute( 'status' );

		Element( 'activation' ).style.display	= 'block';
		Element( 'loader' ).style.display		= 'none';

		alert( Result );

		if( Status == 'yes' )
			window.location.reload();
	}

	var myAlert, Status;

	function Start( ID ) {
		Element('logo').onclick	= function() { window.location.href = './'; }

		if( Element( 'status' ) ) {
			Status	= {
				active : 'bought',

				getBought	: function() {
					Element( 'table' ).innerHTML	= '';

					var URI		= 'ajax.php?action=getstatus&type=bought';
					var ajax	= new Ajax();

					ajax.sendRq( 'GET', URI, Status.processQuery, null, null );
					Element('status').innerHTML	= '<p class="center">Моля изчакайте<br /><img src="images/loader.gif" alt="" /><br /><br /></p>';
				},

				getUploaded	: function(page) {
					Element( 'table' ).innerHTML	= '';

					var URI		= 'ajax.php?action=getstatus&type=uploaded&page=' + page;
					var ajax	= new Ajax();

					ajax.sendRq( 'POST', URI, Status.processQuery, 'a=5', null, true );
					Element('status').innerHTML	= '<p class="center">Моля изчакайте<br /><img src="images/loader.gif" alt="" /><br /><br /></p>';
				},

				getSales	: function( M, Y ) {
					Element( 'table' ).innerHTML	= '';

					M	= M ? '&month=' + M : '';
					Y	= Y ? '&year=' + Y : '';

					var URI		= 'ajax.php?action=getstatus&type=sales' + M + Y;
					var ajax	= new Ajax();

					ajax.sendRq( 'GET', URI, Status.processQueryStat, null, null );
					Element('status').innerHTML	= '<p class="center">Моля изчакайте<br /><img src="images/loader.gif" alt="" /><br /><br /></p>';
				},

				setActive	: function( LINK ) {
					Element(this.active).className		= '';
					LINK.className						= 'active';
					this.active							= LINK.id;
				},

				processQuery	: function( response ) {
					if( typeof response.documentElement != 'undefined' ) {
						var Parent	= response.documentElement;
						var result	= '';
	
						if( Elements( Parent, 'data' ).length > 0 && Elements( Parent, 'data' )[0].firstChild )
							result	= Elements( Parent, 'data' )[0].firstChild.data;
						else
							result	= 'Папката е празна';
	
						Element('status').innerHTML = result;
					}
					else {
						//var Parent	= response.documentElement;
						var result	= response;//'';
	
						if( result.length > 0 )//Elements( Parent, 'data' ).length > 0 && Elements( Parent, 'data' )[0].firstChild )
							{ var sda=5; }//result	= Elements( Parent, 'data' )[0].firstChild.data;
						else
							result	= 'Папката е празна';
	
						Element('status').innerHTML = result;
					}
				},

				processQueryStat	: function( response ) {
					var Parent	= response.documentElement;

					var days_count	= Elements( Parent, 'days_count' )[0].getAttribute('value');
					var m			= Elements( Parent, 'month' )[0].firstChild.data;
					var y			= Elements( Parent, 'year' )[0].firstChild.data;

					var DIAGRAM		= document.createElement( 'img' );
					var DIV			= document.createElement( 'div' );
					var DAYS		= Elements( Parent, 'day' );
					var A			= null;

					var PREV		= document.createElement( 'A' );
					var NEXT		= document.createElement( 'A' );

					PREV.appendChild(
						document.createTextNode(
							'< ' +
							Elements( Parent, 'prevm' )[0].getAttribute('full') + ' ' +
							Elements( Parent, 'prevy' )[0].firstChild.data
						)
					);
					NEXT.appendChild(
						document.createTextNode(
							Elements( Parent, 'nextm' )[0].getAttribute('full') + ' ' +
							Elements( Parent, 'nexty' )[0].firstChild.data +
							'>'
						)
					);

					PREV.className	= 'prevm';
					NEXT.className	= 'nextm';

					PREV.setAttribute(
						'href', 'javascript:Status.getSales(' +
							Elements( Parent, 'prevm' )[0].firstChild.data + ',' +
							Elements( Parent, 'prevy' )[0].firstChild.data +
						');'
					);

					NEXT.setAttribute(
						'href', 'javascript:Status.getSales(' +
							Elements( Parent, 'nextm' )[0].firstChild.data + ',' +
							Elements( Parent, 'nexty' )[0].firstChild.data +
						');'
					);

					DIV.className	= 'diagram-container';

					DIAGRAM.setAttribute( 'src', 'diagram-' + m + '-' + y + '.png' );

					for( var i = 0; i < DAYS.length; i++ ) {
						A	= document.createElement( 'a' );
						A.setAttribute( 'href', 'javascript://' );
						A.style.left	= (i * 14 + 36) + 'px';

						A.payments		= new Array();
						var Payments	= Elements( DAYS[i], 'payment' );

						for( var j = 0; j < Payments.length; j++ ) {
							A.payments[A.payments.length]	= {
								'id'	: Payments[j].getAttribute( 'id' ),
								'title'	: Payments[j].getAttribute( 'title' ),
								'money'	: Payments[j].getAttribute( 'money' ),
								'buyer'	: Payments[j].getAttribute( 'buyer' ),
								'date'	: Payments[j].getAttribute( 'date' ),
								'paid'	: Payments[j].getAttribute( 'paid' )
							};
						}

						A.onclick	= function() {
							var table	= '';

							if( this.payments.length > 0 ) {
								table	+= '<table class="status-table" cellspacing="0" cellpadding="0">';
								table	+= '<tr>' +
									'<th style="width: 60px;">Номер</th>' +
									'<th>Материал</th>' +
									'<th style="width: 70px;">Потребител</th>' +
									'<th style="width: 100px;">Дата</th>' +
									'<th style="width: 55px;">Печалби</th>' +
									'<th style="width: 65px;">Изплатени</th>' +
								'</tr>';

									for( var i = 0; i < this.payments.length; i++ ) {
										table	+= '<tr>';
											table	+= "<td>" + this.payments[i].id + "</td>";
											table	+= "<td><a href='view-" + this.payments[i].id + ".html' target='_blank'>" + this.payments[i].title + "</a></td>";
											table	+= "<td>" + this.payments[i].buyer + "</td>";
											table	+= "<td>" + this.payments[i].date + "</td>";
											table	+= "<td>" + this.payments[i].money + "лв.</td>";
											table	+= "<td>" + this.payments[i].paid + "лв.</td>";
										table	+= '</tr>';
									}

								table	+=	'</table>';
							}

							Element( 'table' ).innerHTML	= table;
						}

						A.sales			= DAYS[i].getAttribute( 'sales' );
						A.date			= DAYS[i].getAttribute( 'date' );

						A.onmouseover	= function() { Status.setPrimaryStatus( this ); }
						A.onmouseout	= function() { Element( 'stats' ).innerHTML = ''; }
						A.innerHTML		= '&nbsp;';

						DIV.appendChild( A );
					}

					DIV.appendChild( DIAGRAM );

					Element('status').innerHTML	= '';
					Element('status').appendChild( DIV );
					Element('status').appendChild( PREV );
					Element('status').appendChild( NEXT );
				},

				setPrimaryStatus : function( OBJ ) {
					var ok	= OBJ.sales == 1 ? 'а' : 'и';

					Element( 'stats' ).style.color	= OBJ.sales > 0 ? '#95c52a' : '';
					Element( 'stats' ).style.fontSize	= OBJ.sales > 0 ? '12px' : '';

					Element( 'stats' ).innerHTML	= '<strong>' + OBJ.date + '</strong><br />' + OBJ.sales + ' продажб' + ok +
					'<br /><br />Кликни на стълбчето за подробна информация';
				}
			};
		}

		if( Element('shade') ) {
			myAlert	= {
				ALERT		: Element( 'alert' ),
				SHADE		: Element( 'shade' ),
				BANK		: Element( 'pay-by-bank' ),
				ACTIV		: Element( 'activation' ),
				OPTIONS		: Element( 'options' ),
				EPAYT		: Element( 'epay-thingy' ),
				EPM			: Element( 'easypay-message' ),

				close		: function() {
					window.onscroll	= window.onresize = null;

					this.ALERT.style.display	= 'none';
					this.SHADE.style.display	= 'none';
					this.ACTIV.style.display	= 'none';
					this.BANK.style.display		= 'none';
					this.EPM.style.display		= 'none';
					if( this.EPAYT )
						this.EPAYT.style.display	= 'none';
					this.OPTIONS.style.display	= 'block';
				},

				addToCart	: function() {
					myCart.add( ID );
					this.close();
				},

				payByEPay	: function() {
					this.OPTIONS.style.display	= 'none';
					this.ACTIV.style.display	= 'none';
					this.EPAYT.style.display	= 'block';
					// document.forms['ePayForm'].submit();
					// this.close();
				},

				payByEPay_go	: function() {
					document.forms['ePayForm'].submit();
					this.close();
				},

				payByEasyPay	: function() {
					Element( 'easybuttons' ).style.display	= 'none';
					Element( 'loader' ).style.display		= 'block';

					var ajax = new Ajax();

					ajax.sendRq( 'GET', 'ajax.php?action=easypay&materials=' + document.forms['ePayForm'].elements['materials'].value, function( response ) {
						Element( 'loader' ).style.display			= 'none';
						Element( 'easypay-message' ).style.display	= 'block';

						if( response.getElementsByTagName('error').length > 0 )
							Element( 'easypay-message' ).innerHTML	= response.getElementsByTagName('error')[0].firstChild.data;
						else {
							var IDN	= response.getElementsByTagName('IDN')[0].firstChild.data;
							Element( 'easypay-message' ).innerHTML	= '<div style="height: 110px; margin-right: 10px; overflow: auto;"><b>Инструкции за плащане на банкомат:</b><br />' +
							'1. Поставете картата в банкомата и изберете меню "Други услуги". След това изберете меню "B-pay".<br />' +
							'2. Въведете код на търговеца: <b>60000</b><br />' +
							'3. Въведете 10-цифрен код за плащане ( <b>' + IDN + '</b> )<br />' +
							'<br />' +
							'<b>Инструкции за плащане в офис на Easypay:</b><br />' +
							'1. Изберете офис от <a href="http://easypay.bg/?p=off" class="hovered" target="_blank">този адрес</a>.<br />' +
							'2. В офиса съобщете на кой търговец искате да заплатите и ' +
							'10-цифрения код за плащане (<b>' + IDN + '</b>).</div>';
						}
					}, null, null );
				},

				payBySMS	: function() {
					this.OPTIONS.style.display	= 'none';
					this.ACTIV.style.display	= 'block';
				},

				payByPrevod	: function( ID ) {
					this.CLOSED	= false;

					var ajax	= new Ajax();

					ajax.sendRq( 'POST', 'ajax.php?action=pay-by-bank', myAlert.payByPrevodFeedback, 'id=' + ID );

					Element('options').style.display	= 'none';
					Element('loader').style.display		= 'block';
				},

				payByPrevodFeedback	: function( response ) {
					Element('loader').style.display			= 'none';
					Element('pay-by-bank').style.display	= 'block';
				}
			};
		}

		BeautyfyTextareas();		// Стилизиране на Textarea полетата
		CreateResetButton();		// Стилизиране на Reset бутоните
		BeautyfySelects();			// Стилизиране на Select менютата
		BeautifyInputs();			// Стилизиране на Input полетата
		RoundThingsUp();			// Обли форми div.box
		SetRollovers();				// Rollover ефект popular-list
		OperateMenu();				// Drop-down за менюто
		IE_7_Sucks();				// IE7 hash bug - мразя IE
		Rating();					// Рейтинг на материалите
	}

	function IE_7_Sucks() {
		FuckIE( window.location );

		var LINKS	= document.links;

		for( var i = 0; i < LINKS.length; i++ ) {
			if( LINKS[i].hash ) {
				LINKS[i].onclick	= function() {
					FuckIE( this );
				}
			}
		}
	}

	function FuckIE( URI ) {
		var ANCHOR	= URI.hash.substring(1);

		if( Element( '_' + ANCHOR ) )
			document.documentElement.scrollTop	= Element( '_' + ANCHOR ).offsetTop;
	}

	function vid( obj, vs, vid, dims ) {
		switch( vs ) {
			case 'youtube':
				var asd = document.createElement( 'DIV' );
				asd.innerHTML = '<object width="' + dims.w  + '" height="' + dims.h  + '"><param name="movie" value="http://www.youtube.com/v/' + vid + '&fs=1&autoplay=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + vid + '&fs=1&autoplay=1" type="application/x-shockwave-flash" width="' + dims.w + '" height="' + dims.h + '" allowscriptaccess="always" allowfullscreen="true"></embed></object>';
				obj.parentNode.insertBefore(asd, obj);
				obj.parentNode.removeChild(obj);
			break;
			case 'vbox':
				var asd = document.createElement( 'DIV' );
				asd.innerHTML = '<object width="' + dims.w  + '" height="' + dims.h  + '"><param name="movie" value="http://i47.vbox7.com/player/vBoxPlayerSV22.swf?vid=' + vid + '"></param><embed src="http://i47.vbox7.com/player/vBoxPlayerSV22.swf?vid=' + vid + '" type="application/x-shockwave-flash" width="' + dims.w + '" height="' + dims.h + '" allowscriptaccess="always" allowfullscreen="true"></embed></object><br /><a href="http://www.vbox7.com/play:'+vid+'" style="color: #737373;font-size: 9px;" target="_blank">http://www.vbox7.com/play:'+vid+'</a><br />';
				obj.parentNode.insertBefore(asd, obj);
				obj.parentNode.removeChild(obj);
			break;
		}
	}

