function getObjectProps(obj, objName)
{
    var result = "";
    for (var i in obj) result += objName + "." + i + " = " + obj[i] + "<BR>\n";
    return result;
}
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.get('checked') )
						{
							elSiblingPrev.set('checked',false);
						}
						else
						{
							elSiblingPrev.set('checked',true);
						}
					}
					else if ( elSiblingPrev.getAttribute('type') == 'radio' )
					{
						elSiblingPrev.set('checked',true);
					}
					elSiblingPrev.simulate('change');
				}
				
			});
			elSibling.setStyle('cursor','pointer');
		}
	});
}
function checkCaptcha(value,formIdToSubmit,fnCompleteNo)
{
	var fnComplete = function ()
	{
		if ( responseText == 'true' )
		{
			Y.one('#'+formIdToSubmit).submit();
		}
		else
		{
			if ( !empty(fnCompleteNo) )
			{
				fnCompleteNo();
			}
		}
	}
	ajaxResponse('checkout','cart','checkCaptcha','captcha='+value,fnComplete);
}
function ajaxResponse(mappe,datei,formname,params,fnComplete)
{
	YUI().use('node', 'io-base', function(Y) {
		var uri =  '/index.php?route=' + mappe + '/' + datei;
		var cfg = {
			method: 'POST',
			data: 'formname='+formname + '&' + params
		}
		
		function complete(id, o, args) {
			if ( !empty(o.responseText) )
			{
				responseText = o.responseText;
			}
			if ( !empty(fnComplete) )
			{
				fnComplete();
			}
		};
		Y.on('io:complete', complete, Y, ['lorem', 'ipsum']);
		
		var request = Y.io(uri,cfg);
	});
}
var prepareFormOk = false;
function prepareForm(thisForm,noempty)
{
	if ( !prepareFormOk )
	{
		prepareFormOk = true;
		Y.one(thisForm).setAttribute('method','post');
		Y.one(thisForm).all('input').each(function(el)
		{
			if ( el.getAttribute('type') == 'text' )
			{
				el.setAttribute('alt',el.get('value'));
				el.setAttribute('title',el.get('value'));
				el.on('focus',function()
				{
					if ( this.hasClass('checked') )
					{
						if ( this.get('value') == this.getAttribute('alt') )
						{
							if ( noempty == undefined )
							{
								if ( this.getAttribute('name') == 'telefon' && this.get('value').length == 2 )
								{
									;
								}
								else
								{
									this.set('value','');
								}
							}
						}
					}
				});
				el.on('blur',function()
				{
					if ( this.hasClass('error') )
					{
						this.removeClass('error');
					}
					if ( this.hasClass('checked') )
					{
						if ( this.get('value') == '' )
						{
							this.set('value',this.getAttribute('alt'));
						}
						if ( noempty == undefined )
						{
							if ( this.get('value') == this.getAttribute('alt') )
							{
								this.addClass('error');
							}
						}
					}
				});
			}
		});
		Y.one(thisForm).all('textarea').each(function(el)
		{
			el.setAttribute('alt',el.get('value'));
			el.setAttribute('title',el.get('value'));
			el.on('focus',function()
			{
				if ( this.hasClass('error') )
				{
					this.removeClass('error');
				}
				if ( el.hasClass('checked') )
				{
					if ( noempty == undefined )
					{
						if ( this.get('value') == this.getAttribute('alt') )
						{
							this.set('value','');
						}
					}
				}
			});
			el.on('blur',function()
			{
				if ( this.hasClass('checked') )
				{
					if ( this.hasClass('error') )
					{
						this.removeClass('error');
					}
					if ( el.hasClass('checked') )
					{
						if ( this.get('value') == '' )
						{
							this.set('value',this.getAttribute('alt'));
						}
						if ( noempty == undefined )
						{
							if ( this.get('value') == this.getAttribute('alt') )
							{
								this.addClass('error');
							}
						}
					}
				}
			});
		});
	}
}
function confirmForm(thisForm,noempty)
{
	if ( !prepareFormOk )
	{
		prepareForm(thisForm);
	}
	erlaubt = true;
	Y.one(thisForm).all('input').each(function(el)
	{
		if ( el.getAttribute('type') == 'text' )
		{
			if ( el.hasClass('checked') )
			{
				if ( this.hasClass('error') )
				{
					this.removeClass('error');
				}
				if ( el.get('value') == '' || ( noempty == undefined && el.get('value') == el.getAttribute('alt') ) )
				{
					erlaubt = false;
					el.addClass('error');
				}
			}
		}
	});
	Y.one(thisForm).all('textarea').each(function(el)
	{
		if ( el.hasClass('checked') )
		{
			if ( this.hasClass('error') )
			{
				this.removeClass('error');
			}
			if ( el.get('value') == '' || ( noempty == undefined && el.get('value') == el.getAttribute('alt') ) )
			{
				erlaubt = false;
				el.addClass('error');
			}
		}
	});
	if ( erlaubt )
	{
		Y.one(thisForm).all('input').each(function(el)
		{
			if ( el.getAttribute('type') == 'text' )
			{
				if ( el.getAttribute('alt') != '' && el.get('value') == el.getAttribute('alt') && noempty == undefined )
				{
					el.set('value','');
				}
			}
		});
		Y.one(thisForm).all('textarea').each(function(el)
		{
			if ( el.getAttribute('alt') != '' && el.get('value') == el.getAttribute('alt') && noempty == undefined )
			{
				el.set('value','');
			}
		});
	}
	return erlaubt;
}
function submitFeedbackForm(tagDIV_id,tagFORM_id,tagINPUTcaptcha_id,tagSPANcaptcha_id,messageLoader)
{
	if ( tagDIV_id == 'infoDostavka' )
	{
		tovars = new Array;
		tovar_kode = new Array();
		tovar_name = new Array();
		tovar_quantity = new Array();
		Y.all('.tovar_kode').each(function(el)
		{
			tovar_kode.push(el.get('value'));
		});
		Y.all('.tovar_name').each(function(el)
		{
			tovar_name.push(el.getContent());
		});
		Y.all('.tovar_quantity').each(function(el)
		{
			tovar_quantity.push(el.get('value'));
		});
		for (i=0; i<tovar_kode.length; i++)
		{
			tovars[i] = tovar_kode[i]+'^'+tovar_name[i]+'^'+tovar_quantity[i];
		}
		Y.one('#i_infoDostavka_tovars_info').setAttribute('value',implode('~',tovars));
	}
	if ( confirmForm(Y.one('#'+tagFORM_id),'noempty') )
	{
		Y.one('#'+tagFORM_id).hide(true);
		width = Y.one('#'+tagDIV_id).get('scrollWidth');
		marginLeft = parseInt(width) - 410;
		insertAjaxLoader(Y.one('#'+tagDIV_id),'<div style=\'margin-left:'+marginLeft+'px;margin-top:50px;width:200px;text-align:center;\'></div>','<br clear=\'all\'><div style=\'color:#00cc00;font-weight:bold;\'>'+messageLoader+'</div>');
		window.setTimeout(function(){
			checkCaptcha(Y.one('#'+tagINPUTcaptcha_id).get('value'),tagFORM_id,function()
			{
				Y.one('#'+tagFORM_id).show(true);
				Y.one('#'+tagINPUTcaptcha_id).select();
				Y.one('#'+tagINPUTcaptcha_id).focus();
				Y.one('#'+tagSPANcaptcha_id).show(true);
				removeAjaxLoader();
			})
		},2000);
	}
	return false;
}

var ajaxLoaderId;
var nodeBeforeAjaxLoaderId;
function insertAjaxLoader(node,containerHtml,contentHtml)
{
	if ( !empty(ajaxLoaderId) )
	{
		Y.one('#'+ajaxLoaderId).remove();
	}
	if ( empty(containerHtml) )
	{
		containerHtml = '<div style="position:relative;float:right;"></div>';
		ajaxLoaderHtml = '<img src="/ajax-loader.gif" style="position:absolute;margin-left:-45px;margin-top:25px;">';
	}
	else
	{
		ajaxLoaderHtml = '<img src="/ajax-loader.gif" align="absmiddle">';
	}
	if ( empty(contentHtml) )
	{
		contentHtml = '';
	}
	nodeAjaxLoader = Y.one('body').create(containerHtml);
	ajaxLoaderId = nodeAjaxLoader.generateID();
	nodeAjaxLoader.setContent(ajaxLoaderHtml+contentHtml);
	node.insert(nodeAjaxLoader,'append');
}
function removeAjaxLoader()
{
	if ( !empty(ajaxLoaderId) )
	{
		if ( Y.one('#'+ajaxLoaderId) != null )
		{
			Y.one('#'+ajaxLoaderId).remove();
		}
		ajaxLoaderId = '';	
	}
}
layersShadowActivated = new Array();
function layerShadow(id,fnStart,fnEnd,grosseK)
{
	node = Y.one('#'+id);
	if ( 1 )
	{
		if ( !in_array(id,layersShadowActivated) )
		{
			node.setStyle('visibility','hidden');
			node.show();
			width = node.get('scrollWidth');
			height = node.get('clientHeight');
			node.hide();
			node.setStyle('visibility','visible');
			halbWidth = Math.ceil(width/2);
			halbHeight = Math.ceil(height/2);
			node.setStyle('position','fixed');
			node.setStyle('width',width);
			node.setStyle('height',height);
			node.setStyle('left','50%');
			node.setStyle('top','50%');
			node.setStyle('marginLeft',-halbWidth);
			node.setStyle('marginTop',-halbHeight);
			node.setStyle('zIndex','40001');
			array_push(layersShadowActivated,id);
		}
		fnClose = function()
		{
			node.hide();
			nodeClose.remove();
			nodeShadow.hide(true);
			window.setTimeout(function(){nodeShadow.remove();},500);
			if ( !empty(fnEnd) )
			{
				fnEnd();
			}
		}
		nodeShadow = Y.Node.create('<div/>');
		nodeShadow.setStyle('backgroundColor','#999');
		nodeShadow.setStyle('position','fixed');
		nodeShadow.setStyle('width','100%');
		nodeShadow.setStyle('height','100%');
		nodeShadow.setStyle('top','0');
		nodeShadow.setStyle('left','0');
		nodeShadow.setStyle('display','none');
		nodeShadow.setStyle('zIndex','40000');
		nodeShadow.setStyle('opacity',0.7);
		nodeShadow.setStyle('display','block');
		nodeShadow.on('click',fnClose);
		node.insertBefore(nodeShadow,node);
		nodeClose = Y.Node.create('<img src="/image/dialog-close.png">');
		nodeClose.setStyle('position','absolute');
		nodeClose.setStyle('top','0px');
		nodeClose.setStyle('right','0px');
		nodeClose.setStyle('width','32px');
		nodeClose.setStyle('cursor','pointer');
		nodeClose.on('click',fnClose);
		node.append(nodeClose,node);
		node.show(true);
		if ( !empty(fnStart) )
		{
			fnStart();
		}
	}
}
function implode( glue, pieces )
{
    return ( ( pieces instanceof Array ) ? pieces.join ( glue ) : pieces );
}
function empty (mixed_var) {
	// !No description available for empty. @php.js developers: Please update the function summary text file.
	// 
	// version: 1103.1210
	// discuss at: http://phpjs.org/functions/empty
	// +   original by: Philippe Baumann
	// +      input by: Onno Marsman
	// +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +      input by: LH
	// +   improved by: Onno Marsman
	// +   improved by: Francesco
	// +   improved by: Marc Jansen
	// +   input by: Stoyan Kyosev (http://www.svest.org/)
	// *     example 1: empty(null);
	// *     returns 1: true
	// *     example 2: empty(undefined);
	// *     returns 2: true
	// *     example 3: empty([]);
	// *     returns 3: true
	// *     example 4: empty({});
	// *     returns 4: true
	// *     example 5: empty({'aFunc' : function () { alert('humpty'); } });
	// *     returns 5: false
	var key;
 
	if (mixed_var === "" || mixed_var === 0 || mixed_var === "0" || mixed_var === null || mixed_var === false || typeof mixed_var === 'undefined') {
		return true;
	}
 
	if (typeof mixed_var == 'object') {
		for (key in mixed_var) {
			return false;
		}
		return true;
	}
 
	return false;
}
function in_array (needle, haystack, argStrict) {
    // Checks if the given value exists in the array  
    // 
    // version: 1107.2516
    // discuss at: http://phpjs.org/functions/in_array
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: vlado houba
    // +   input by: Billy
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: true
    // *     example 2: in_array('vlado', {0: 'Kevin', vlado: 'van', 1: 'Zonneveld'});
    // *     returns 2: false
    // *     example 3: in_array(1, ['1', '2', '3']);
    // *     returns 3: true
    // *     example 3: in_array(1, ['1', '2', '3'], false);
    // *     returns 3: true
    // *     example 4: in_array(1, ['1', '2', '3'], true);
    // *     returns 4: false
    var key = '',
        strict = !! argStrict;
 
    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;
            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {
                return true;
            }
        }
    }
 
    return false;
}
function array_push (inputArr) {
    // Pushes elements onto the end of the array  
    // 
    // version: 1107.2516
    // discuss at: http://phpjs.org/functions/array_push
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // %        note 1: Note also that IE retains information about property position even
    // %        note 1: after being supposedly deleted, so if you delete properties and then
    // %        note 1: add back properties with the same keys (including numeric) that had
    // %        note 1: been deleted, the order will be as before; thus, this function is not
    // %        note 1: really recommended with associative arrays (objects) in IE environments
    // *     example 1: array_push(['kevin','van'], 'zonneveld');
    // *     returns 1: 3
    var i = 0,
        pr = '',
        argv = arguments,
        argc = argv.length,
        allDigits = /^\d$/,
        size = 0,
        highestIdx = 0,
        len = 0;
    if (inputArr.hasOwnProperty('length')) {
        for (i = 1; i < argc; i++) {
            inputArr[inputArr.length] = argv[i];
        }
        return inputArr.length;
    }
 
    // Associative (object)
    for (pr in inputArr) {
        if (inputArr.hasOwnProperty(pr)) {
            ++len;
            if (pr.search(allDigits) !== -1) {
                size = parseInt(pr, 10);
                highestIdx = size > highestIdx ? size : highestIdx;
            }
        }
    }
    for (i = 1; i < argc; i++) {
        inputArr[++highestIdx] = argv[i];
    }
    return len + i - 1;
}
