function big_foto(w,h,win_name,left)
{
	var url='';
	var win_name;
	if (!win_name) win_name='big';
	if (!left) left=100;
	var features='menubar=no,scrollbars=yes,status=no,resizable=yes,top=8,left='+left+',width='+w+',height='+h;
	window.open(url,win_name,features);
}


function getParam(sParamName)
{
    var Params = location.search.substring(1).split("&"); // отсекаем «?» и вносим переменные и их значения в массив
    var variable = "";
    for (var i = 0; i < Params.length; i++)
	{ // пробегаем весь массив
        if (Params[i].split("=")[0] == sParamName)
		{ // если это искомая переменная — бинго!
            if (Params[i].split("=").length > 1)
			{
				variable = Params[i].split("=")[1]; // если значение параметра задано, то возвращаем его
				return variable;
			}
        }
    }
    return "";
}


$(document).ready(function() {

	/*
	if ($.cookie('message')=='confirm_ok')
	{
		$.cookie('message','');
		alert('Регистрация подтверждена');
		document.location='/';
	}
	*/
	
	$("h1, div.h1").each(function(){if(!$(this).hasClass("h1prodToMain"))$(this).html('<span><font>'+$(this).text()+'</font></span>')});
	
	
	
	//$("#typeWork option").click(function(){
		//$("#tr_type_work_nalog").remove();
		//var type_work_val = $('select#typeWork option:selected').val();
		//if (type_work_val == 1 || type_work_val == 2){
			//alert(type_work_val);
			//appe = "<tr id='tr_type_work_nalog'><td>Статус платника податку:*</td><td><select name='nalog'><option value='zagal'>на загальних підставах</option><option  value='fixed'>на єдиному, або фіксованому</option></select></td></tr>";
			//$("#tr_type_work").after(appe);
		//}
	//});
	
	var type_work =  $('select[name=typeWork] option:selected').val();
	if (type_work == 1 || type_work == 2){
		$("#tr_type_work_nalog").css("display","");
	}
	
	$("#typeWork option").click(function(){
		var type_work_val = $('select#typeWork option:selected').val();
		if (type_work_val == 1 || type_work_val == 2){
			$("#tr_type_work_nalog").css("display","");
		}
		if (type_work_val == 3){
			$("#tr_type_work_nalog").css("display","none");
		}
	});
	
	
	$("input, textarea").focus(function(){
		if ($(this).attr('type')=="text"||$(this).attr('type')=="password"||$(this).attr('type')=="textarea")
		{
			//if (!/str/.test($(this).attr('name')) && ($(this).attr('value')=="Логин" || $(this).attr('value')=="*****")) $(this).attr('value','');
			//if ($(this).attr('value')=='поиск') $(this).val('');
			$(this).addClass('over');
		}
	});

 	$("input, textarea").blur(function(){
		if ($(this).attr('type')=="text"||$(this).attr('type')=="password"||$(this).attr('type')=="textarea")
		{
			//if ($(this).attr('name')=='q' && $(this).attr('value')=="") $(this).val('поиск');
			$(this).removeClass('over');
		}
	});
	
	$("input[type='text'].prodCount").click(function(){
		$(this).select();
	});

	$('ins.prod_dop').hover(
		function(){
			$("div.prod_dop[rel='"+$(this).attr('rel')+"']").css({'display':'block'});
		},
		function(){
			var rel=$(this).attr('rel');
			setTimeout(function(){$("div.prod_dop[rel='"+rel+"']").css({'display':'none'})}, 1000);
		}
	);
	
	$('.v_karzinu').live('click',function(){
		if (loading_start(ids_=$(this),'v_karzinu'))
		{
			var params={};
			params.good=$(this).attr('rel');
			var count=parseInt($("input[type='text'][rel='"+params.good+"']").val());
			params.count=((count>0)?count:1);
			//alert(params.good+' '+params.count);
			JsHttpRequest.query(
				'/zina.php',
				params,
				function(result, errors)
				{
					loading_end(ids_,'v_karzinu');
					if (errors) alert(errors);
					//$('#div_errors').html(errors);
					if (result)
					{
						alert('Товар добавлен в корзину');
						$('#goods').html(result['goods_prev']);
						$('#summa').html(result['price_prev']);
						
					}
				},
				true
			);
		}
	});
	
	$('.prodCount').live('keypress',function(e){
		if (e.which==13) $("input[type='button'][rel='"+$(this).attr('rel')+"']").trigger('click');
	});
	
	
	//$('#login2').focus(function(){$(this).attr('value','');});
	
	/* $('#rememberme').click(function(){
		$('#remem').slideToggle(100);
		return false;
	});
	
	$('#remem1').click(function(){
		if (login2=$.trim($('#login2').val()))
		{
			JsHttpRequest.query(
				'/rememberme.php',
				{
					'email': login2
				},
				function(result, errors)
				{
					$('#div_errors').html(errors);
					if (result)
					{
						if (result['res']==1)
						{
							alert('Пароль выслан на ваш e-mail');
							$('#rememberme').trigger('click');
						}
						if (result['res']==2)
						{
							alert('Нет такого пользователя или пользователь не активен');
						}
						
					}
				},
				true
			);
		}
	});
	
	 */
	
	$('#go_').click(function(){go_away();});
	
	$("a[target='info']").click(function(){
		var ll;
		if (screen.width>1000) ll=(screen.width-1000)/2;
		else ll=1000;
		var url=$(this).attr("href");
		var win_name="info";
		var features='menubar=yes,scrollbars=yes,status=no,resizable=yes,top=100,left='+ll+',width=1000,height=500';
		window.open(url,win_name,features);
		return false;
	});
	
	$(".chainSelect select").change(function(){
		$(document).attr('location', $(this).val());
	});
	
	// $.browser.(safari, opera, msie, mozilla)
	if ($.browser.msie)
	{
		$("table.prod-tbl > tbody > tr ").hover(
			function(){
				var bg=$(this).css('background');
				if (typeof(bg)=='undefined') bg='';
				$(this).data("bg",bg);
				$(this).css({'background':'#F1F1F1'});
			},
			function(){
				$(this).css({'background':$(this).data("bg")});
			}
		);
	}

});

 
function go_away()
{
	if (loading_start(ids_='#go_'))
	JsHttpRequest.query(
		'/guest.php',
		{
			'fio': $('#fio').val(),
			'email': $('#email').val(),
			'message': $('#message').val(),
			'code': $('#code').val()
		},
		function(result, errors)
		{
			if (errors) alert(errors);
			//$('#div_errors').html(errors);
			loading_end(ids_);
			if (result)
			{
				if (result['res']==1)
				{
					alert('Сообщение успешно отправленно');
					$('#fio').val('');
					$('#email').val('');
					$('#message').val('');
					$('#code').val('');
					$('.sec').text(result['rnd']); //
				}
				if (result['res']==2)
				{
					alert('Не все поля заполнены или заполнены неверно');
				}
				if (result['res']==3)
				{
					alert('Неверный защитный код');
				}
            }
		},
		true
	);
}

//$(document).attr('location','?print')" target="print"
function _print()
{
	var url='?print';
	var win_name="print";
	var features='menubar=yes,scrollbars=yes,status=no,resizable=yes,top=200,left=200,width=800,height=600';
	window.open(url,win_name,features);
	return false;
}

function check_w()
{
	//if(window.opener){if(!/tvd/.test(window.opener.document.location.host))document.location=document.location.toString().split("?")[0];}else document.location=document.location.toString().split("?")[0];
}

function preload_image(imgs)
{
	var i3=1;
	var n=imgs.length;
	var img = document.createElement('img');
	$(img).bind('load', function(){
		if (imgs[0])
		{
			this.src = imgs.shift();
			i3++;
			if (i3==n)
			{
				alert('готово');
			}
		}
	}).trigger('load');
}


var loading_start_ids=[], a_interval=[];
function loading_start(obj,ids)
{
	var ids;
	if (ids==undefined) ids=obj;
	loading_start_ids[ids];
	if (loading_start_ids[ids]==undefined||loading_start_ids[ids]==false)
	{
		loading_start_ids[ids]=true;
		$(obj).attr('disabled',true);
		$(obj).after("<div class='loading' rel='"+ids+"'>&nbsp;</div>"); // loading...
		a_interval[ids]=setTimeout(function(){alert('Повторите попытку :) ');loading_end(obj,ids);}, 30000);
		return true;
	}
	return false;
}
function loading_end(obj,ids)
{
	var ids;
	if (ids==undefined) ids=obj;
	if (loading_start_ids[ids]==true)
	{
		clearTimeout(a_interval[ids]);
		$(obj).attr('disabled',false);
		loading_start_ids[ids]=false;
		$("div.loading[rel='"+ids+"']").css({display:'none'});
	}
}


//var ss1=decodeURIComponent(location.search.substring(1)).toString();
//if (ss1!='') ss2=$("body").html().toString().replace(/Радіатор/, "<search>"+ss1+" 1 </search>");
//$("body").html(ss2);
//alert(ss2);