$(document).ready(function()
{
	/**
	 * Lightbox
	 */
	$('a.lightbox').lightBox();

	/**
	 * Show Hints, <a href='...' title='hint text'>
	 */
	$('a[title]').each(function(){
		title = $(this).attr('title');
		if (title.length > 0)
		{
			$(this).attr('tooltip',  title );
			$(this).attr('title','');
		}
	});
	$('a[tooltip]').mouseover(function(){
		offset=$(this).offset();
		if ( !$('#tooltip').get(0) )
		{
			$('body').append("<div id='tooltip'>"+$(this).attr('tooltip')+"</div>");
			$('#tooltip').css('top',offset.top+$(this).height()+15+'px');
			$('#tooltip').css('left',offset.left-30+'px');
		}
	}).mousemove(function(e){
		$('#tooltip').css('top',e.pageY+15+'px');
		$('#tooltip').css('left',e.pageX-30+'px');
	}).mouseout(function(){
		$('#tooltip').remove();
	});


	$('#site_left .menu a').mouseover(function()
	{
		$(this).parent().addClass('over');
	});
	$('#site_left .menu a').mouseout(function()
	{
		$(this).parent().removeClass('over');
	});
	
	$('.req_form').submit(function()
	{
		email_re=/^[a-z][a-z0-9\._]+@[a-z0-9\.\-]+?\.[a-z]{2,5}$/i;
		er=new Array();
		if ($('input[@name=fio]',$(this)).val()=='')
		{
			er.push('Необходимо ввести имя');
		}
		if ($('input[@name=phone]',$(this)).val()=='' && $('input[@name=email]',$(this)).val()=='')
		{
			er.push('Необходимо ввести контактный телефон или e-mail');
		}
		else if ( $('input[@name=email]',$(this)).val() && ! email_re.test( $('input[@name=email]',$(this)).val() ) )
		{
			er.push('E-mail введён не верно');
		}
		
		if (er.length==0)
		{
			current_form=$(this);
			data_for_send={
				'fid':$('input[@name=fid]',$(this)).val(),
				'fio':$('input[@name=fio]',$(this)).val(),
				'company':$('input[@name=company]',$(this)).val(),
				'email':$('input[@name=email]',$(this)).val(),
				'phone':$('input[@name=phone]',$(this)).val(),
				'experience':$('textarea[@name=experience]',$(this)).val()
			}
			$.ajax({
				type: "POST",
				data:data_for_send,
  				url: "/req_form.php",
  				dataType: "html",
  				success:function(response)
  				{
  					$('div.notice',current_form).html('Ваша заявка принята, наши менеджеры свяжутся с Вами в ближайшее время');
  					$('div.notice',current_form).removeClass('error');
					$('div.notice',current_form).show();
					$('input[@name=fio]',current_form).val('');
					$('input[@name=company]',current_form).val('');
					$('input[@name=email]',current_form).val('');
					$('input[@name=phone]',current_form).val('');
					$('textarea[@name=experience]',current_form).val('');
  				}
			});
		}
		else
		{
			t='';
			for (i in er)
			{
				t+=er[i]+"<br/>";
			}
			$('div.notice',$(this)).html(t);
			$('div.notice',$(this)).addClass('error');
			$('div.notice',$(this)).show();
		}
		return false;
	});
});