$(document).ready(function() {	
// reduce image flicker in IE6
 if (ie) {
   try {
     document.execCommand('BackgroundImageCache', false, true);
   } 
   catch(e) {}; // ignore it
 }

	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		padding: 30, /* padding for each side of the picture */
		opacity: 0.35, /* Value betwee 0 and 1 */
		showTitle: true, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
		callback: function(){}
	});
});

function captcha() {
	$.post('/index/captcha', null,
	function(data) {
			$("#recaptcha").hide();
        	$("#recaptcha").html(data);
        	$("#recaptcha").show();
    	}
	);
}


$(document).ready(function() { 
    $('#request').click(function() { 
        $.blockUI({ message: $('#requestform'), css: { width: '400px', top: '100px' } }); 
    });
    $('#go_request').click(function() { 
        $.blockUI({ message: '<h1 style="margin:10px;padding:0;font-size:16px;">Подождите...</h1>' }); 
        
        var err=0;
        $('#rq_name').css("border","#d1d1d1 solid 1px");
        if (trimStr($('#rq_name').val()) == '') {
        	$('#rq_name').css("border","red solid 1px");
			err ++;
        }
        $('#rq_email').css("border","#d1d1d1 solid 1px");
        if ($('#rq_email').val() == '' || !checkmail($('#rq_email').val())) {
        	$('#rq_email').css("border","red solid 1px");
			err ++;
        }
        $('#rq_phone').css("border","#d1d1d1 solid 1px");
        if (trimStr($('#rq_phone').val()) == '') {
        	$('#rq_phone').css("border","red solid 1px");
			err ++;
        }
        $('#rq_message').css("border","#d1d1d1 solid 1px");
        if (trimStr($('#rq_message').val()) == '') {
        	$('#rq_message').css("border","red solid 1px");
			err ++;
        }

        if (err<1)
        {
         var qString = $("#go_log").formSerialize(); //alert(qString);
		 $.post('/request/send?form='+qString, null,
		 function(data) { 
		 	if (data=='ok') {
		 		alert('Ваш запрос успешно отправлен. Спасибо!');
		 		$.unblockUI(); //location.href='http://joinery.bu/';	
		 	}	else	{
		 		alert('Ошибка.. Повторите еще раз, пожалуйста. ');
		 		$.blockUI({ message: $('#requestform'), css: { width: '400px', top: '100px' } }); 
		 	}
		 });
        }
        else {
        	$.unblockUI(); 
        	$.blockUI({ message: $('#requestform'), css: { width: '400px', top: '100px' } }); 	
        	return false;
        }
    }); 

    $('#no').click(function() { 
        $.unblockUI(); 
        return false; 
    }); 
    $('#no_request').click(function() { 
        $.unblockUI(); 
        return false; 
    }); 
}); 

function checkmail(email) {
	var reg = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,4}$/
	return (reg.exec(email)!=null)
} 

