function trim12 (str) {
	var	str = str.replace(/^\s\s*/, ''),
	ws = /\s/,
	i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}

	function sendArticle(){
		
		var sender = $('#sender').val();
		var receiver = $('#receiver').val();
		var message = $('#message').val();
		var signature = $('#signature').val();
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

		if(trim12(sender) == ''){
			alert('Please input sender email.');
			return false;
		}
		if(reg.test(sender) == false){
			alert('Please input correct sender email.');
			return false;
		}

		if(trim12(receiver) == ''){
			alert('Please input receiver email.');
			return false;
		}
		if(reg.test(receiver) == false){
			alert('Please input correct receiver email.');
			return false;
		}
		
		if(trim12(message) == ''){
			alert('Please input message.');
			return false;
		}else{
			
			$('#sendArticleForm').css('display', 'none');
			$('#sendArticleLoader').css('display', 'block');
			var send = $.ajax
			({	
				type: "post",
				url: '/ajax/',
				data: {action:'send_article', sender:sender, receiver:receiver, message:message, signature:signature},
				dataType: "json",
				success: onSuccessSendArticle
			});
		}
	}
	
	function onSuccessSendArticle(oReq){
		var json = oReq;
		if (json.status=='ok'){
			$('#sendArticleLoader').css('display', 'none');
			$('#sendArticleMessage').html('Your message has been sent.');
		}else{
			$('#sendArticleLoader').css('display', 'none');
			$('#sendArticleMessage').html('Your message has NOT been sent.');			
		}
		$('#sender').val('');
		$('#receiver').val('');
		$('#message').val('');		
		$('#signature').val('');		
		
		$('#sendArticleMessage').append('<span onclick="closeThickBox();"> <a href="javascript://">'+'Close'+'</a></span>');			
		
	}		
	
	function closeThickBox(){
		$('#sender').val('');
		$('#receiver').val('');
		$('#message').val('');		
		$('#signature').val('');		
		$('#sendArticleMessage').html('');			
		$('#sendArticleForm').css('display', 'block');
		$('#sendArticleLoader').css('display', 'none');
		tb_remove();
	}
	
$(document).ready( function(){

	/*
		Internet Explorer PNG transparent fix
	*/
	if($.browser.msie && (parseInt(jQuery.browser.version) == 6)) DD_belatedPNG.fix('#header');
	
	/*
		Height ob block alligment
	*/
	$('.b-same-height').each(function(){
		$(this).find('.layout-box > .b-allign-height').height($(this).height()-15);
		$(this).find('.layout-box > .box').height($(this).height()-15-16-16);	
	});
	
	/*
		Custom corners
	*/
	$('.bc-tlc').append("<span class='tlc'></span>");
	
	//$('.rc17 .rocon-bl, .rc17 .rocon-br').css({'bottom': 'auto', 'top': '100%', 'margin-top': '-16px'});


	/*
		Tabs on homepage
	*/

	$('.b-tabs dt').click(function(){
        $(this)
            .siblings().removeClass('active').end()
            .next('dd').andSelf().addClass('active');
    });


	$('#send1').click(function(){
		$('#stab1').removeClass('active');
		$('#stab1c').removeClass('active');
		$('#stab2').addClass('active');
		$('#stab2c').addClass('active');
		$('#stab3').removeClass('active');
		$('#stab3c').removeClass('active');
	});

	$('#send2').click(function(){
		$('#stab1').removeClass('active');
		$('#stab1c').removeClass('active');
		$('#stab2').removeClass('active');
		$('#stab2c').removeClass('active');
		$('#stab3').addClass('active');
		$('#stab3c').addClass('active');
	});


	$('.switcher .i-radio').each(function(){
		b_id = $(this).attr('id');
		b_container = $(this).parent().parent().parent().parent();
		
		b_container.find('.swithcher-block').hide();
		b_container.find('.'+b_id).show();
	});

	/* checkbox 4 market indices*/
	$('.b-tabs dt').each(function(){
		$(this).click(function(){
			//$('#f-events').attr('checked', 'checked');
			//$('#f-events').parent().addClass('checked');
		});
	});
	$('.switcher .l-radio').each(function(){
		$(this).click(function(){
			//$('#f-events').attr('checked', 'checked');
			//$('#f-events').parent().addClass('checked');
		});
	});
	
	$('.switcher .i-radio').change(function(){
		b_id = $(this).attr('id');
		b_container = $(this).parent().parent().parent().parent();

		b_container.find('.swithcher-block').hide();
		b_container.find('.'+b_id).show();
	});


	$('.b-tabs-market dt').click(function(){
        $(this)
            .siblings().removeClass('active').end()
            .next('dd').andSelf().addClass('active');
    });


	/*
		Date picker
	*/
	
	if(typeof $.fn.datepick == 'function') {
		$('.i-date').datepick({
			showOn: 'both', 
			buttonImage: '/img/icons/icon-calendar.gif',
			changeMonth: false,
			changeYear: false,
			dateFormat: 'dd.mm.yy'

		});
	}

	/*
		Form element replacement
	*/
	
	if(typeof $.fn.formstyle == 'function') {
		$('input.i-checkbox').checkboxstyle();
		$('input.i-radio').radiostyle();
		$('select.i-select').selectstyle();
		$('input[type=file]').filestyle();

		$('body').click(function(){
			$('a.expander').removeClass('open');
			$('ul.options').hide();
		});
		
		zIndex = 99999;
		$('.select').each(function(){
			$(this).css('z-index', zIndex--);
		});
	}
	
	/*
		Country Selector
	*/
	$('#header-country-selector ul li a').click(function(){
		currentSelectedRel = $(this).parent().parent().find('a.selected').attr('rel');
		$(this).parent().parent().attr('class', 'options bgCountry-'+$(this).attr('rel'));
	}).mouseover(function(){
		currentSelectedRel = $(this).parent().parent().find('a.selected').attr('rel');
		$(this).parent().parent().attr('class', 'options bgCountry-'+$(this).attr('rel'));
	});
	
	$('#header-country-selector a.expander').click(function(){
		$(this).next().find('a.selected').parent().parent().addClass('bgCountry-'+$(this).next().find('a.selected').attr('rel'));
	});
	$('#header-country-selector a.selector').click(function(){
		$(this).next().next().find('a.selected').parent().parent().addClass('bgCountry-'+$(this).next().next().find('a.selected').attr('rel'));
	});
	
});




function reset_form(id) {
    document.forms[id].reset();
    var selects = document.forms[id].getElementsByTagName("SELECT");
    for (var i=0; i<selects.length; i++){
	selects.item(i).selectedIndex = 0;
    }
}

function reset_form2(id) {
    document.forms[id].reset();
}


