/* arsagera */
jQuery(document).ready(function(){
	if (jQuery.browser.msie && jQuery.browser.version == '6.0') {
			//alert(document.title)
		}	
})
jQuery.noConflict();
(function($){
    $(function(){
				if (jQuery.browser.msie && jQuery.browser.version == '6.0') {
            $(".ie6hov").hover(function(){
                //alert('oki');
                $(this).addClass('hover');
            }, function(){
                $(this).removeClass('hover');
            });
       }
        $('#hider').removeClass('autoscroll').addClass('hider');
        $('.opener').attr('href', 'javascript:void(0)');
        $('.opener').click(function(){
            var vis = $('#authorization .form').css('visibility');
            //alert(vis);
            vis = (vis == 'hidden') ? 'visible' : 'hidden';
            $('#authorization .form').css({
                'visibility': vis
            });
        });
        $('.ico_closer').click(function(){
            $('#authorization .form').css({
                'visibility': 'hidden'
            });
        })
        if (document.getElementById('arsagera_carousel')) {
            $('#arsagera_carousel').addClass('pos_abs');
            jQuery('#arsagera_carousel').jcarousel({
                vertical: true,
                scroll: 5,
                //auto:1,
                visible: 5,
                wrap: 'both'
                //buttonNextHTML: '<span><b class="icons ico_down_jq ie6hov"><!-- !!! --></b></span>',
                //buttonPrevHTML: '<span><b class="icons ico_up_jq ie6hov"><!-- !!! --></b></span>'
            }); 
        } 
        var marginLeft = -$('#b').width() / 2;
        $('#b').css({
            'marginLeft': marginLeft + 'px'
        });
        /*$('input[type="text"]').each(function(){
            var defVal = $(this).val();
            $(this).focus(function(){
                if ($(this).val() && $(this).val() == defVal) {
                    $(this).val('');
                    if (jQuery.browser.msie) {
                        $(this).addClass('focus');
                    };
                                    };
                            })
            $(this).blur(function(){
                if (!$(this).val()) {
                    $(this).val(defVal);
                    if (jQuery.browser.msie) {
                        $(this).removeClass('focus');
                    };
                                    };
                            });*/
        //})
// orders
				var select_field = document.getElementById('q2');
				var input_field = document.getElementById('q33');
				if (input_field && select_field) {
					
					/*input_field.disabled = true;
					input_field.className += ' disabled';
					input_field.value = 0;*/
					
					if (select_field.options[select_field.selectedIndex].getAttribute('pif') == 'disabled' || select_field.options[select_field.selectedIndex].getAttribute('value') == '') {
						input_field.disabled = true;
						input_field.value = 0;
						if (!input_field.className.match('disabled')) {
							input_field.className += ' disabled';
						}
					}
					else {
						input_field.disabled = false;
						input_field.className = input_field.className.replace(' disabled', '');
					}
					
					select_field.onchange = function(){
					input_field.disabled = true;
					if (!input_field.className.match('disabled')) {
						input_field.className += ' disabled';
					}
					input_field.value = 0;
					
					if (this.options[this.selectedIndex].getAttribute('value') != '') {
							if (this.options[this.selectedIndex].getAttribute('pif') == 'disabled') {
								input_field.disabled = true;
								input_field.value = 0;
								
								$('#q33').attr('required', '');
								$('#q33').attr('sum', '');
								
								if (!input_field.className.match('disabled')) {
									input_field.className += ' disabled';
								}
							}
							else {
								input_field.disabled = false;
								input_field.className = input_field.className.replace(' disabled', '');
								
								$('#q33').attr('required', 'Заполните поле Сумма');
								$('#q33').attr('sum', 'Сумма должна быть числом с точностью до 2-х знаков после запятой');
							}
						}
					}
				}
				
// load personal accounts numbers
				$('#q2').change(function(){
					if (this.options[this.selectedIndex].getAttribute('value') != '') {
						$('#q22').load('/fundorder/userAccounts/?fund=' + $(this).attr('value'));
						//alert($(this).attr('value'));
					}
				});
				
				$('#q21').change(function(){
					if (this.options[this.selectedIndex].getAttribute('value') != '') {
						$('#q23').load('/fundorder/userAccounts/?fund=' + $(this).attr('value'));
						//alert($(this).attr('value'));
					}
				});
// END load personal accounts numbers

// select region
				var select_field = document.getElementById('r');
				if (select_field) {
					select_field.onchange = function(){
						//alert(this.options[this.selectedIndex].getAttribute('cut'));
						document.location.href = "?region=" + $(this).attr('value') + "&cut=" + this.options[this.selectedIndex].getAttribute('cut');
						
					}
				}
// END select region
				
// select city
				var select_field = document.getElementById('c');
				if (select_field) {
					select_field.onchange = function(){
						document.location.href = "?city=" + $(this).attr('value') + "&cut=" + this.options[this.selectedIndex].getAttribute('cut');
						
					}
				}
// END select city
						
						//if (!(jQuery.browser.msie && jQuery.browser.version == '6.0')) {
						//}
				$('a:not(.print_version, .more)','.work_area').each(function(){
					if($(this).attr('href') && $(this).attr('href').match('/investor_dictionary/')){
						
						$(this).wrap('<dfn></dfn>');
						var thisPos = $(this).offset();
						var thisH = $(this).height();
						var bodyWidth = $('#obertka').outerWidth();
						$(this).hover(function(event){
							$.post('/dictionary/showTitle/?link=' + $(this).attr('href'), function(data){
								jQuery('<div id="vocabulary"></div').appendTo('body').text('');
								$('#vocabulary').text($('anons',data).text());
								var vocabW = $('#vocabulary').outerWidth();
								var vocabH = $('#vocabulary').outerHeight();
								var correctLeft;
								var correctW = vocabW;
								if((event.pageX + vocabW) < bodyWidth){
									correctLeft = 0;
								} else {
									correctLeft = (event.pageX + vocabW) - bodyWidth;
								};
								$('#vocabulary').css({
									left:event.pageX - correctLeft + 'px',
									top:event.pageY + thisH + 'px'
								});
							});
						},function(){
							$('#vocabulary').text('').remove();
						})
					}
				});
				//}
        });
    })(jQuery);

function addBookmark(url, title) {
	if (!url) url = location.href;
	if (!title) title = document.title;

//Gecko
	if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel (title, url, "");

//IE4+
	else if (typeof window.external == "object") window.external.AddFavorite(url, title);

//Opera7+
	else if (window.opera && document.createElement) {
		var a = document.createElement('A');

		if (!a) return false; //IF Opera 6
		a.setAttribute('rel','sidebar');
		a.setAttribute('href',url);
		a.setAttribute('title',title);
		a.click();
	}

	else return false;

	return true;
}