var _CLOSED_ELEMENTS = new Array ();

function isString() {
	if (typeof arguments[0] == 'string') return true;
	if (typeof arguments[0] == 'object') {
		var criterion = arguments[0].constructor.toString().match(/string/i);
		return (criterion != null);  
	}
	
	return false;
}

function hasClass ( _object , _className ) {
	if ( isString( _object.className ) )
		if ( _object.className.search(_className) != -1 ) return true;

	return false;
}

function addClass ( _object , _className ) {
	_object.className += ' '+_className;
}

function removeClass ( _object , _className ) {
	_rexp = new RegExp ("\s?"+_className+"" , "i" );
	_object.className = _object.className.replace( _rexp , "" );
}

function getParentByClassName ( _object , _className ) {
	_parentModule = _object;
	while ( _parentModule.className.search (_className) == -1 ) {
		_parentModule = _parentModule.parentNode;
	}

	return _parentModule;
}

function getFirstChildByClassName ( _object , _className ) {
	_bodyId = 0;
	_continue = -1;
	do {
		_bodyId++;
		_target = _object.childNodes[ _bodyId ];
		if ( isString(_target.className) ) _continue = _target.className.search(_className);
	} while ( _continue == -1 );

	return _target;
}


function minimize ( _object ) {
	_parentModule = getParentByClassName ( _object , 'module' );
	_targetBody = getFirstChildByClassName ( _parentModule , 'body' );

	if( _targetBody.style.display != 'none' ) {
		_targetBody.style.display = 'none';
		
		//zvalek
			var Eid = _targetBody.id;
			if (Eid) {
				//nastavi hodnotu promenne menuboxu
				create_menubox_cookie(Eid, _targetBody.style.display);
			}
		//zvalek
	}
	else {
		_targetBody.style.display = '';
		
		//zvalek
			var Eid = _targetBody.id;
			if (Eid) {
				//nastavi hodnotu promenne menuboxu
				create_menubox_cookie(Eid, '');
			}
		//zvalek
	}		
}

function hide ( _object ) {
	_target = getParentByClassName( _object , 'productSmall' );
	_target.style.display = 'none';

	_CLOSED_ELEMENTS.push( _target );
}

function unHideLast () {
	if ( _CLOSED_ELEMENTS.length != 0 ) {
		_target = _CLOSED_ELEMENTS.pop();
		_target.style.display = '';
	}
	else {
		alert( 'Nemackej kam nemas woe..' );
	}
}

function showTab ( _object ) {
	_parent = getParentByClassName ( _object , 'info' );
	_target = document.getElementById ( _object.id + 'Tab' );
	_test=0;

	for ( i = 0 ; i < _parent.childNodes.length ; i++ ) {
		_this = _parent.childNodes[i];
		_test += _parent.childNodes[i].className+' ';
		if ( _this.tagName == 'BUTTON' ) {
			document.getElementById( _this.id + 'Tab' ).style.display = 'none';
			_this.className = 'inactive';
		}
	}

	_object.className = 'active';
	_target.style.display = 'inline';
}

function hover ( _object , _classNameArg ) {
	_className = _classNameArg || "active";
	if ( hasClass ( _object , _className ) ) {
		removeClass ( _object , _className );
	} else
		addClass ( _object , _className );
}

function inputFocus ( _object ) {
	if ( ( _object.value == _object.defaultValue ) ) {
		_object.value = '';
	}
	else { if ( _object.value == '' ) {
			_object.value = _object.defaultValue;
		}
	}
}

function checkInputDefaults ( _object ) {
	length = _object.elements.length;

	for ( x = 0 ; x < length ; x++ ) {
		_subj = _object.elements[x];
		if ( ( _subj.type.value == 'text' ) || ( _subj.type.value == 'password' ) ) {
			if ( _subj.value == _subj.defaultValue ) {
				alert ( '!!!' );
				return 1;
			}
		}
	}

	return 0;
}
