function sendInfo(form){	
	
	var error = new Array;

	if ($('#fRequestForm [name=name]').val() == '')
		error[0] = 'name';

	if ($('#fRequestForm [name=contact]').val() == '')
		error[2] = 'contact';

	if (error.length) {
		$('#rErrorMessage').show();
		setTimeout(function() {
			$('#rErrorMessage').hide();
		}, 3000);
		return false;
	}
	
	$.ajax({
		url: '?submit',
		type: 'post',
		dataType:	'json',
		data: $('#fRequestForm').serialize(),
		success: function(msg) {
			if (msg.status) {
				$('#rSuccessMessage').show();
				$('#rFormBlock').hide();
				setTimeout(function() {
					CloseForm();
					location.reload();
				}, 3000);				
			}
			else {
				$('#rErrorMessage').show();
				$('#captcha').html(msg.captcha);
				Recaptcha.reload();
				setTimeout(function() {
					$('#rErrorMessage').hide();
				}, 3000);
			}
		}
	});	
};

$(document).ready(function() {
	
	Cufon.replace('#logo');
	Cufon.replace('#topMenu li a');
	Cufon.replace('#thirdLevelMenu li a');
	Cufon.replace('#footerLeft');
	Cufon.replace('#footerRight');
	Cufon.replace('.promoText p');
	Cufon.replace('.promoLink');
	Cufon.replace('#page td');
	Cufon.replace('#page h1');
	Cufon.replace('#page h2');
	Cufon.replace('#page h3');
	Cufon.replace('#button');
	Cufon.replace('#pageTitle');
	Cufon.replace('#producePageTitle');
	Cufon.replace('#producePageComment');
	Cufon.replace('#similar h2');
	Cufon.replace('.r_text');
	Cufon.replace('.r_title');
	Cufon.replace('.r_request');
	Cufon.replace('.r_title2');
	Cufon.replace('.r_submit');
	Cufon.replace('.anti');
	Cufon.replace('.page_txt p');
	Cufon.replace('.produceListLink');
	Cufon.replace('#anotherCaptcha');
	$('#slideshow').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		speed:  2500,
		timeout:4500
	});
	$('#pageslide').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		speed:  2500,
		timeout:4500
	});
	$("a.zoom").fancybox({
		'speedIn'		:	400, 
		'speedOut'		:	200, 
		'overlayShow'	:	false,
		'titlePosition' :	'inside',
		'cyclic'		:	true
	});
	 $(window).scroll(function () {  
		// code will go here  
	});
});

$('#requestForm').find('.r_close').click(function() {
		CloseForm();
		return false;
	});

$('#rLayout').click(function() {
	CloseForm();
	return false;
});

$.fn.centerInClient = function(options) {
    var opt = { forceAbsolute: false,
                container: window,    // selector of element to center in
                completeHandler: null
              };
    $.extend(opt, options);
   
    return this.each(function(i) {
        var el = $(this);
        var jWin = $(opt.container);
        var isWin = opt.container == window;

        if (opt.forceAbsolute) {
            if (isWin)
                el.remove().appendTo("body");
            else
                el.remove().appendTo(jWin.get(0));
        }

        el.css("position", "absolute");

        var heightFudge = isWin ? 2.0 : 1.8;

        var x = (isWin ? jWin.width() : jWin.outerWidth()) / 2 - el.outerWidth() / 2;
        var y = (isWin ? jWin.height() : jWin.outerHeight()) / heightFudge - el.outerHeight() / 2;

        el.css("left", x + jWin.scrollLeft());
        //if (y + jWin.scrollTop() > 0)
			el.css("top", y + jWin.scrollTop());

        if (opt.completeHandler)
            opt.completeHandler(this);
    });
}

function PreparePromoLink(forma, chk) {
	
	ClearForm();

	$('#rLayout').show();
	$('#requestForm .r_title').show();
	$('#requestForm .r_submit').bind('click', function(){
		sendInfo(forma);
	});
	$('#intInput').val(forma);
	
	if (chk == 'all') {
		$('#requestForm .opt input').attr('checked','checked');
	}
	else {
		if (chk > 0)
			$('#requestForm #r_ch'+chk).attr('checked','checked');
		else if(chk < 0)
			$('#requestForm .opt').hide();

	}

}

function ClearForm() {
	
	$('#requestForm').centerInClient().show()
		.find(':input')
		.not(':button, :submit, :reset, :hidden')
		.val('')
		.removeAttr('checked')
		.removeAttr('selected');
	
	$('#requestForm .r_title').hide();
	$('#requestForm .opt').show();
	$('#requestForm .r_submit').unbind('click');
	
}

function CloseForm() {
	
	$('#rLayout').hide();
	$('#requestForm').hide();

}
