// fixPNG(); http://www.tigir.com/js/fixpng.js (author Tigirlas Igor)
function fixPNG(element)
{
	if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
	{
		var src;
		
		if (element.tagName=='IMG')
		{
			if (/\.png$/.test(element.src))
			{
				src = element.src;
				element.src = "/images/blank.gif";
			}
		}
		else
		{
			src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i)
			if (src)
			{
				src = src[1];
				element.runtimeStyle.backgroundImage="none";
			}
		}
		
		if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='noscale')";
	}
}

function showMessages(mess,closetext)
{	
	$('#outher_text').html(mess).focus();
	if (closetext=='')
	{
		$('#container_outher_text').find("a[rel='close']").hide();
	}
	else
	{
		$('#container_outher_text').find("a[rel='close']").show().html(closetext).click(function(){
			$('#container_outher_text').hide();
			$('#formsend_block').hide();
			if ($.browser.msie && parseInt($.browser.version)<=6) $('#formsend').find('select').attr('disabled','');
			return false
		});
	}
	$('#container_outher_text').show();
	$('#formsend_block').show();
	if ($.browser.msie && parseInt($.browser.version)<=6) $('#formsend').find('select').attr('disabled','disabled');
}

function real_width(obj){
	obj = $(obj);
	return parseInt(obj.width()) + parseInt(obj.css('paddingLeft')) + parseInt(obj.css('paddingRight'));
}
function real_height(obj){
	obj = $(obj);
	return parseInt(obj.height()) + parseInt(obj.css('paddingTop')) + parseInt(obj.css('paddingBottom'));
}
function setFormAjax(text, fields)
{
	insert_html = '<div id="container_outher_text" style="display:none;"><div id="outher_text"></div><br /><br /><center><a href="javascript:void(0)" rel="close">закрыть</a></center></div><div id="formsend_block" style="display:none;">&nbsp;</div>';
 	var options = {
		url: "/common/send_mail.php?javascript=y",// change
		success: function(responseText){
			if (responseText=='ok')
			{
				showMessages(text,'закрыть');
				$("#formsend").resetForm();
			}
			else
			{
				error_text = typeof(responseText)=="string"?responseText.replace(/error\:/i,''):'';
				showMessages('<span style="color:red">Произошла ошибка отправки сообщения. <br /> '+error_text+'</span>', 'закрыть');
			}
		},
		beforeSubmit:function(formArray, jqForm){
			
			for(var i=0;i<formArray.length;i++)
			{
				if (formArray[i]['value']=='' && fields && fields.indexOf('|'+formArray[i]['name']+'|')>=0)
					{
						showMessages('Не все поля заполнены. <br />Пожалуйста заполните их.<br />','Заполнить');// change
						return false; 
					}
			}
			showMessages('<img src="/images/wait.gif" align="absmiddle" /> Подождите, идет отправка сообщения...','');// change
			return true;
		} 
	};
	$("#formsend").ajaxForm(options).before(insert_html); // change
	//document.title = '#container_formsend = width:'+real_width("#container_formsend")+'px'+'; height:'+real_height("#container_formsend")+'px';
	$('#formsend_block').css({width:real_width("#container_formsend")+'px', height:real_height("#container_formsend")+'px'});
	$('#container_outher_text').css({left:parseInt((real_width("#container_formsend") - real_width("#container_outher_text"))/2)+'px',top:parseInt((real_height("#container_formsend") - real_height("#container_outher_text"))/4) +'px'});
}

