$(document).ready(function(){

	comment_id = 0;
	current_big_photo = 1;


	$('body').ajaxStart(function(){
		$.fancybox.showActivity();

	});
	$('body').ajaxStop(function(){
		$.fancybox.hideActivity();

	});

	$("a#authLink").fancybox({
		'showCloseButton' : true,
		'enableEscapeButton' : true,
		'autoDimensions' : false,
		'width' : 550,
		'height' : 90,
		'titleShow' : false
	});

	$("a#registerLink").fancybox({
		'showCloseButton' : true,
		'enableEscapeButton' : true,
		'autoDimensions' : false,
		'width' : 450,
		'height' : 230,
		'titleShow' : false
	});
	$("a#act_fade").fancybox({
		'showCloseButton' : true,
		'enableEscapeButton' : true,
		'autoDimensions' : false,
		'width' : 450,
		'height' : 630,
		'titleShow' : false
	});

	$('#authLink').bind('click',function(){
		$('#auth_email').val('');
		$('#auth_password').val('');
		$('#auth_email').focus();
	});

	$('#act_fade').bind('click',function(){

	});

	$('#registerLink').bind('click',function(){
		$('#reg_email').val('');
		$('#reg_password').val('');
		$('#reg_password2').val('');
		$('#reg_name').val('');
		$('#reg_num').val('');
		$('#reg_email').focus();
	});

	$('#logoutLink').bind('click',function(){
		$.fancybox.showActivity();

	});

	$("a#mod_ad").fancybox({
		'showCloseButton' : true,
		'enableEscapeButton' : true,
		'autoDimensions' : false,
		'width' : 320,
		'height' : 110,
		'titleShow' : false
	});
	$("a#send_mail").fancybox({
		'showCloseButton' : true,
		'enableEscapeButton' : true,
		'autoDimensions' : false,
		'width' : 270,
		'height' : 120,
		'titleShow' : false
	});

	$('a.fnc').fancybox({
						'titlePosition'  : 'inside',
						'showComments' : 'yes',
						'noWheel' : 'yes'
					});

});

function chkEmailValid(email)
{
	myRe=/([\w.-]+)@([\w.-]+){1,}\.([\w-]+)/g;
    if(myRe.test(email)) return true;
    else return false;
}

function get_models(mark_id,element_id)
{
	element_id.load('/remote/get-model.php?mark_id='+mark_id);
}
/*
????????? ??? ????
*/
function get_models_2(mark_id,heavy_id,element_id)
{
	element_id.load('/remote/get-model.php?mark_id='+mark_id+'&amp;heavy_id='+heavy_id);
}

function get_named_models(mark,element_id,vehicle_type)
{
	var param=0;
	if(document.getElementById('check_ad') && document.getElementById('check_ad').checked) param+=1;
	if(document.getElementById('check_automarket') && document.getElementById('check_automarket').checked) param+=2;
	if(document.getElementById('check_tradein') && document.getElementById('check_tradein').checked) param+=4;

	element_id.load('/remote/get-named-model.php?mark='+mark+'&vehicle_type='+vehicle_type+'&car_type='+param);
}

function comment_it(id)
{
	$('#general-comment-p').show();
	$('#comment'+id).after($('#comment-block'));
	comment_id = id;
	document.getElementById('comm_text').focus();
}
function general_comment()
{
	$('#general-comment-p').before($('#comment-block'));
	$('#general-comment-p').hide();
	comment_id =0;
}
function insert_comment(data)
{
	var result = eval('(' + data + ')');
	if (result.resultCode!=undefined && result.resultCode==0)
    {
        if(comment_id==0)
	        $('#general-comment-p').before('<div class="feedback" id="comment'+result.lastID+'" rel="0"><div class="feedback_date">'+result.date+'</div><div class="feedback_author"><strong>Автор:</strong> '+result.userNick+'</div><div class="feedback_text">'+document.getElementById('comm_text').value+'</div><p style="margin:0;padding:0;font-size:11px;text-align:right;"><a href="#" onclick="comment_it('+result.lastID+');return false;">ответить</a></p></div>');
	     else
	     {
	  		new_rel=parseInt($('#comment'+comment_id).attr('rel'))+20;
	        $('#comment'+comment_id).after('<div class="feedback" id="comment'+result.lastID+'" style="padding-left:'+new_rel+'px" rel="'+new_rel+'"><div class="feedback_date">'+result.date+'</div><div class="feedback_author"><strong>Автор:</strong> '+result.userNick+'</div><div class="feedback_text">'+document.getElementById('comm_text').value+'</div><p style="margin:0;padding:0;font-size:11px;text-align:right;"><a href="#" onclick="comment_it('+result.lastID+');return false;">ответить</a></p></div>');
	     }

		document.getElementById('comm_text').value='';
    }
}

function set_action(path,type,page)
{
	if(type==1)
	{
		if(path!=0)
			document.getElementById('search_b_u_forma').action='/'+page+'/'+path+'/';
		else
			document.getElementById('search_b_u_forma').action='/'+page+'/';
	}
	if(type==2)
	{
		if(path!=0)
			document.getElementById('search_b_u_forma').action='/'+page+'/'+document.getElementById('mark').value+'/'+path+'/';
		else
			document.getElementById('search_b_u_forma').action='/'+page+'/'+document.getElementById('mark').value+'/';
	}
}
