top_pop_enable_hide = true;
dn18413 = "Розница:<br>вт, ср, чт, пт, сб - круглосуточно<br>пн - с 10:00<br>вс - до 22:00<br>";

dn18414 = "Розница:<br>вт, ср, чт, пт - круглосуточно<br>пн - с 10:00<br>сб - до 22:00<br>вс - 10:00 – 19:00";

dn2_18413 = 'Розница:<br>вт, ср, чт, пт, сб - круглосуточно<br>пн - с 10:00<br>вс - до 20:00<br>';
dn2_18414 = 'Розница:<br>вт, ср, чт, пт - круглосуточно<br>пн - с 10:00<br>сб - до 22:00<br>вс - 10:00 – 19:00';



function showHideTopPop(id, show)
{
	if (show == undefined || show == null)
	{
		show = 1;
	}

	p = document.getElementById(id);
	partner = document.getElementById('partner_li');
	pn = p.parentNode;
	w = pn.offsetWidth;

	p.style.width = w+8+'px';
	pos = getAbsolutePos(pn);
	
	if (show)
	{
		top_pop_enable_hide = false;
	}
	
	if (show && p.style.display == 'none')
	{
		p.style.display = '';
		p.style.left = pos.x+'px';
		partner.className = 'popOn';
		
		if ($is.IE6)
		{
		
//	document.getElementById('search_category').style.display = 'none';
		}
	}
	else if (!show)
	{
		top_pop_enable_hide = true;
		setTimeout('showHideTopPop_call(p,partner);',500);
		
		/*
		p.style.display = 'none';
		partner.className = '';
		
		if ($is.IE6)
		{
			//document.getElementById('search_category').style.display = '';
		}
		*/
	}
}
function showHideTopPop_call(p,partner)
{
	if (!top_pop_enable_hide)
	{
		return false;
	}
	p.style.display = 'none';
	partner.className = '';
	
	if ($is.IE6)
	{
		//document.getElementById('search_category').style.display = '';
	}
}

change_city_fixed_pos = false;
function showChangeCity(eThis,isnew)
{
	cs = document.getElementById('city_select');
	
	if (isnew)
	{
		showChangeCityNew(eThis);
		return;
	}
	
	if (eThis == null || eThis == undefined)
	{
		eThis = 0;
	}
	
	if (!cs)
	{
		return false;
	}
	
	if (!eThis)
	{
		change_city_fixed_pos = true;
		cs.style.display = '';
		cs.style.left = Math.round( (screen.width/2) - (cs.offsetWidth/2))+"px";
		cs.style.top = '120px';
	}
	else
	{
		change_city_fixed_pos = false;
		pos = getAbsolutePos(eThis);
		cs.style.display = '';
		cs.style.left = pos.x+eThis.offsetWidth+10+'px';
		cs.style.top = pos.y+'px';
	}
}
function showChangeCityNew(eThis)
{
	cs = document.getElementById('city_select');
	
	if (eThis == null || eThis == undefined)
	{
		eThis = 0;
	}
	
	if (!eThis)
	{
		change_city_fixed_pos = true;
		cs.style.display = '';
		cs.style.left = Math.round( (screen.width/2) - (cs.offsetWidth/2))+"px";
		cs.style.top = '120px';
	}
	else
	{
		change_city_fixed_pos = false;
		pos = getAbsolutePos(eThis);
		cs.style.display = '';
		cs.style.left = pos.x+eThis.offsetWidth+30+'px';
		cs.style.top = pos.y+20+'px';
	}
}
function fixedChangeCity()
{
	if (!change_city_fixed_pos) return false;
	
	cs = document.getElementById('city_select');
	if (cs.style.display != 'none')
	{
		cs.style.top = document.body.scrollTop+120+'px';
		setTimeout('fixedChangeCity()',200);
	}
}
function hideChangeCity()
{
	cs = document.getElementById('city_select');
	cs.style.display = 'none';
}


function changeCity(city_id)
{
	/*if (document.getElementById('cart_updater1')) {document.getElementById('cart_updater1').src='/chcity.php?setprice='+city_id;}
	else {document.getElementById('cart_updater').src='/cat2.php?setprice='+city_id;}*/
	location = '/chcity.php?setprice='+city_id;
	hideChangeCity();
}

function valign_menu_buttons()
{
	els = document.getElementById('header_menu').getElementsByTagName('A');
	for (i=0; i<els.length; i++)
	{
		el = els[i];
		if (el.className == 'hmLink')
		{
			ph = el.parentNode.offsetHeight;
			h = el.offsetHeight;
			el.style.height = ph+'px';
			im = el.getElementsByTagName('IMG')[0];
			pad = (((ph-h)/2)+1);
			im.style.marginTop = pad+'px';
			//alert(pad);
		}
	}
}



function dojoInit()
{
	/*
	var node = document.createElement('div');
	node.innerHTML = dojo.byId('addGoodsFromCatalogPane').innerHTML;
	dojo.byId('addGoodsFromCatalogDock').appendChild(node);
	var tmp = new dojox.layout.FloatingPane({
		title: "Редактирование резерва",
		dockable: false,
		maxable: false,
		closable: true,
		resizable: false
	},node);
	tmp.startup();

	// Close event
	dojo.connect(tmp, 'close',
		function()
		{
			var xhrArgs =
			{
				url: "/services/gateway.php",
				handleAs: "text",
				load: function(data, ioargs)
				{
					//targetNode.innerHTML = "XHR returned HTTP status: " + ioargs.xhr.status;
				},
				error: function(error, ioargs)
				{
					//targetNode.innerHTML = "An unexpected error occurred: " + error;
				},
				content:
				{
					t: new Date().getTime(),
					method: "system.params.remove",
					params: "name:addGoodsFromCatalog;"
				}
			}
				
			dojo.xhrGet(xhrArgs);
			return false;
		}
	);
	*/
}







var s_text="Найти"
function searchFieldFocus(eThis)
{
	if (eThis.value == s_text)
	{
		eThis.value = '';
	}
	
	eThis.className = 'sFieldActive';
}
function searchFieldBlur(eThis)
{
	if (eThis.value == '' || eThis.value == s_text)
	{
		eThis.value = s_text;
		eThis.className = 'sField';
	}
}

function searchFieldOnChange(eThis)
{
	if (eThis.value == '' || eThis.value == s_text)
	{
		eThis.value = s_text;
		eThis.className = 'sField';
	}
	else
	{
		eThis.className = 'sFieldActive';
	}
}

function categoryFieldFocus(eThis)
{
	eThis.className = 'sCategoryActive';
return true;
}

function categoryFieldBlur(eThis)
{
	if (eThis.value == 0)
	{
		eThis.className = 'sCategory';
	}
	else
	{
		
	}
}


function submit_login(e)
{ 		
	if (e.keyCode == 13)
	{
		if (document.getElementById('login_form1'))
		{
			document.getElementById('login_form1').submit();
		}
		else
		{
		document.getElementById('login_form').submit();
		}
	}
}
function submit_search(e)
{
	if (e.keyCode == 13)
	{
		location = '/search.php?r='+document.getElementById('search_category').value+'&q='+document.getElementById('search_input').value;
		
		//document.getElementById('header_searcH_form').submit();
		return false;
	}
}

function show_hidden_filter_rows(filter_id, eThis, row_prefix)
{
	fil = document.getElementById(filter_id);
	elements = fil.getElementsByTagName('DIV');
	eval("var expr = /"+row_prefix+"/;");
	for(i=0; i<elements.length; i++)
	{
		el = elements[i];
		if (el.id.match(expr))
		{
			el.style.display = '';
		}
	}
	eThis.parentNode.style.display = 'none';
}


////////////////////////////

function get_search_tips(eThis)
{
	w = eThis.value;
	if (w.length<3)
	{
		hide_search_tips(1);
		return false;
	}
	
	$.get('/search_tips.php',
		{ w: w},
		function(data)
		{
			if (data.length>5) // вменяемый контент пришел
			{
				document.getElementById('search_tips').style.display = '';
				document.getElementById('search_tips_cont').innerHTML = data;
				
				//alert(navigator.userAgent);
				if (navigator.userAgent.indexOf('MSIE') + 1)
				{
					document.getElementById('search_tips').style.width = '265px';
					document.getElementById('search_tips_cont').style.width = '262px';
					document.getElementById('search_tips').style.height = '135px';
					
					/*
					document.getElementById('search_tips').style.width = (document.getElementById('search_tips').offsetWidth+1)+'px';
					document.getElementById('search_tips_cont').style.width = (document.getElementById('search_tips').offsetWidth+0)+'px';
					*/
				}
				else
				{
					/*
					document.getElementById('search_tips').style.width = document.getElementById('search_input').offsetWidth+'px';
					document.getElementById('search_tips_cont').style.width = document.getElementById('search_input').offsetWidth+'px';
					*/
				}
			}
			else
			{
				hide_search_tips(1);
			}
			//alert('Load was performed.');
		});
}

enable_hide_search_tips = false;
st_timer = null;
function hide_search_tips(t)
{
	if (t==undefined || t==null)
	{
		t = 1500;
	}
	enable_hide_search_tips = true;
	st_timer = setTimeout(hide_search_tips_call, t);
}
function hide_search_tips_call()
{
	if (enable_hide_search_tips)
	{
		document.getElementById('search_tips').style.display='none';
	}
}
function show_search_tips()
{
	clearTimeout(st_timer);
	enable_hide_search_tips = false;
}

function headerSearchSubmit()
{
	document.getElementById('header_searcH_form').submit();
}

//////////////////////
// Высота документа
var ua = navigator.userAgent.toLowerCase();
var isOpera = (ua.indexOf('opera')  > -1);
var isIE = (!isOpera && ua.indexOf('msie') > -1);
	 
function getDocumentHeight() {
  return Math.max(document.compatMode != 'CSS1Compat' ? document.body.scrollHeight : document.documentElement.scrollHeight, getViewportHeight());
}
 
function getViewportHeight() {
  return ((document.compatMode || isIE) && !isOpera) ? (document.compatMode == 'CSS1Compat') ? document.documentElement.clientHeight : document.body.clientHeight : (document.parentWindow || document.defaultView).innerHeight;
}
function setTerminalBar() // ставит высоту терминального инфо бара
{
	h = getDocumentHeight();
	document.getElementById('terminal_bar').style.height = h+'px';
}
///////////

function dump(arr,level) {
    var dumped_text = "";
    if(!level) level = 0;
    //The padding given at the beginning of the line.
    var level_padding = "";
    for(var j=0;j<level+1;j++) level_padding += "    ";
    if(typeof(arr) == 'object') { //Array/Hashes/Objects
        for(var item in arr) {
            var value = arr[item];
            if(typeof(value) == 'object') { //If it is an array,
                dumped_text += level_padding + "’" + item + "’ …\n";
                dumped_text += dump(value,level+1);
            } else {
                dumped_text += level_padding + "’" + item + "’ => \"" + value + "\"\n";
            }
        }
    } else { //Stings/Chars/Numbers etc.
        dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
    }
    return dumped_text;
}
function print_r(a)
{
	alert(dump(a));
}
///////////

images_preload = new Array();
function image_preload(src)
{
	found = false;
	for (i=0; i<images_preload.length; i++)
	{
		ind = images_preload[i].src.indexOf(src);
		
		if (ind >= 0)
		{
			found = true;
		}
	}
	
	if (!found)
	{
		pi = new Image();
		pi.src = src;
		images_preload.push(pi);
	}
}


////////////////


// новинки
function nl_list(offset)
{
	if (offset == undefined)
	{
		offset = nl_offset;
	}
	else
	{
		nl_offset = offset;
	}

	ci = 0;
	count = 0;
	for(var k in new_goods_list)
	{
		count++;
		//alert(k+','+offset);
		if (k > offset)
		{
			ci++;
			if (ci <= 3)
			{
				nl_item = new_goods_list[k];
				txt = 
					'<div class="borcaseL"><div class="borcaseT"><div class="borcaseR"><div class="borcaseB">'+
					'<div class="borcaseLT"><div class="borcaseRT"><div class="borcaseRB"><div class="borcaseLB">'+
					'<div class="borcaseC" style="padding: 0px;">'+
						'<table cellpadding="0" cellspacing="0" class="newGoods" id="nl_tb_'+ci+'">'+
							'<tr>'+
								'<td rowspan="2" class="ngImg">'+
									'<img src="http://fast.fenixcomp.ru/good_small_pics2/'+nl_item['id']+'s.jpg">'+
								'</td>'+
								'<td class="ngCell1">'+
									'<div class="ngCat"><a href="'+nl_item['soft_link']+'">'+nl_item['soft_name']+'</a></div>'+
									'<div class="ngName color2">'+nl_item['strip_name']+'</div>'+
									'<div class="ngLink"><a href="/goods/'+nl_item['id']+'" onClick="if (w = window.open(\'/goods/'+nl_item['id']+'/\',\''+nl_item['id']+'\' ,\'scrollbars=1,resizable=1,toolbar=yes,menubar=yes,location=1,width='+winWidth+',height='+winHeight+',left=10,top=10,status=yes\')) { return false; }">подробнее о товаре</a> <img src="/i/design4/arrow2.png"></div>'+
								'</td>'+
							'</tr>'+
							'<tr>'+
								'<td class="ngCell2">'+
									'<div class="ngPrice"><span class="color7">'+nl_item['price_format']+'</span> <span class="ngRub color8">руб.</span></div>'+
								'</td>'+
							'</tr>'+
						'</table>'+
					'</div>'+
					'</div></div></div></div>'+
					'</div></div></div></div>'
				;

				document.getElementById('nl'+ci).innerHTML = txt;
			}
		}
	}
	
	tb_h = 0;
	for (i=1; i<=3; i++)
	{
		if (tb_h < document.getElementById('nl_tb_'+i).offsetHeight)
		{
			tb_h = document.getElementById('nl_tb_'+i).offsetHeight;
		}
	}
	for (i=1; i<=3; i++)
	{
		document.getElementById('nl_tb_'+i).style.height = tb_h;
	}
	
	if (count - offset > 5)
	{
		document.getElementById('nl_right').innerHTML = 
			'<a href="#" onClick="nl_right(); return false;" style="padding: 50px 0px;"><img src="/i/design4/arrow3_right.png" style="cursor: pointer;"></a>';
	}
	else
	{
		document.getElementById('nl_right').innerHTML = 
			'<img src="/i/design4/arrow3_right.png">';
	}
	
	if (offset > 0)
	{
		document.getElementById('nl_left').innerHTML = 
			'<a href="#" onClick="nl_left(); return false;" style="padding: 50px 0px;"><img src="/i/design4/arrow3_left.png" style="cursor: pointer;"></a>';
	}
	else
	{
		document.getElementById('nl_left').innerHTML = 
			'<img src="/i/design4/arrow3_left.png">';
	}
}
function nl_left()
{
	if (nl_offset>0)
	{
		nl_offset = nl_offset-1;
	}
	nl_list();
}
function nl_right()
{
	nl_offset = nl_offset+1;
	nl_list();
}



function frontgroud_make()
{
	fr = document.getElementById('frontgroud');
	if (fr)
	{
		fr.style.display = '';
	}
	else
	{
		bgd=document.createElement('DIV');
		var D = document;
		bgd.style.height= Math.max(
			Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
			Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
			Math.max(D.body.clientHeight, D.documentElement.clientHeight)
		)+"px";
		bgd.style.width="100%";
		bgd.style.top="0";
		bgd.style.position="absolute";
		bgd.style.left="0";
		bgd.id = 'frontgroud';
		bgd.className="bgFader";
		bgd.innerHTML='&nbsp';
		
		document.getElementsByTagName('body')[0].appendChild(bgd);
	}
}
function frontgroud_clear()
{
	fr = document.getElementById('frontgroud');
	if (fr)
	{
		document.getElementById('frontgroud').style.display = 'none';
	}
}

$(window).scroll(function (){
	if ($("#frontgroud").length > 0)
	{
		pa = document.getElementById('frontgroud');
		
		y = $(document).scrollTop();
	
		pa.style.top = y+'px';
	}
	
});


/////// popup area  (модальное окно) ///////

/*
example:
	frontgroud_make();
	pa_id = popup_area_make({'width':'700'});
	
	$.get('/common/price_compl.php?mini=1&good_id='+good_id+'&site_id=43', function(data) {
	  $('#'+pa_id).html(data);
	});
	
	---------
	
	frontgroud_clear();
	popup_area_hide();

*/

pa_struc_template = 
	'<div class="popupArea" id="popup_area" style="display: none;">\
	</div>';

pa_content_id = '';

function popup_area_make(params)
{
	if ($("#popup_area").length > 0)
	{
		
	}
	else
	{
		$("body").append(pa_struc_template);
	}
	
	if (params == undefined || params == null)
	{
		params = new Object();
	}
	
	popup_area_content_back();
	
	if (params['width'] == 'auto')
	{
		$("#popup_area").css('width','auto');
	}
	else if (params['width'])
	{
		$("#popup_area").css('width',params['width']+'px');
	}
	else
	{
		$("#popup_area").css('width','500px');
	}
	
	
	$("#popup_area").css('display','');
	popup_area_pos('popup_area');
	
	return 'popup_area';
}
function popup_area_pos(id)
{
	pa = document.getElementById(id);
	
	x = Math.round( ($(window).width() - pa.offsetWidth) / 2);
	y = $(document).scrollTop() + Math.round($(window).height()/2) - Math.round(pa.offsetWidth/2);

	pa.style.left = x+'px';
	pa.style.top = y+'px';
}
function popup_area_hide()
{
	$("#popup_area").css('display','none');
	
	popup_area_content_back();
}
function popup_area_content(pa_id, content_id) // берем контент из блока и попап, удаляя контент в том блоке. По закрытию возвращается
{
	pa_content_id = content_id;
	
	$('#'+pa_id).html($('#'+content_id).html());
	$('#'+content_id).html('');
}
function popup_area_content_back() // возврат контанта
{
	if (pa_content_id.length > 0) // если брали контент через popup_area_content, то вернем обратно
	{
		$('#'+pa_content_id).html($('#popup_area').html());
		pa_content_id = '';
	}
}

$(window).scroll(function (){
	if ($('#popup_area').length > 0 && $('#popup_area').css('display') != 'none')
	{
		popup_area_pos('popup_area');
	}
	
});

///////////////////////////////



function price_complaint_open(good_id)
{
	frontgroud_make();
	pcc = document.getElementById('price_complaint_cont');
	pcc.style.display = '';
	
	x = Math.round( ($(window).width() - pcc.offsetWidth) / 2);
	y = $(document).scrollTop() + Math.round($(window).height()/2) - Math.round(pcc.offsetWidth/2);
	
	pcc.style.left = x+'px';
	pcc.style.top = y+'px';

	
	$.get('/common/price_compl.php?mini=1&good_id='+good_id+'&site_id=43', function(data) {
	  $('#pccTd').html(data);
	});

}
function price_complaint_close()
{
	frontgroud_clear();
	document.getElementById('price_complaint_cont').style.display = 'none';
}

function price_complaint_send(step)
{
	if (!step)
	{
		step = 1;
	}

	if (step == 1)
	{
		check = price_complaint_checkurl($('[name|="link"]').val());
	}
	else if (step == 2)
	{
		params = { 
			do_compl: $('[name|="do_compl"]').val(),
			change_agent_phone: $('[name|="change_agent_phone"]').val() ,
			change_agent_email: $('[name|="change_agent_email"]').val(), 
			link: $('[name|="link"]').val(), 
			price: $('[name|="price"]').val(), 
			quant: $('[name|="quant"]').val(), 
			phone: $('[name|="phone"]').val(), 
			email: $('[name|="email"]').val(), 
			phone1: $('[name|="phone1"]').val(), 
			phone2: $('[name|="phone2"]').val(), 
			comment: $('[name|="comment"]').val(), 
			good_id: $('[name|="good_id"]').val() 
		};
		
		//print_r(params);
		
		$.post("/common/price_compl.php?mini=1&site_id=43", 
			params,
			function(data){
				$('#pccTd').html(data);
		   });
	}
}
function price_complaint_checkurl(str)
{
	$.get("/common/price_compl.php?checkurl=1&url="+str, function(data) {
		if (data.indexOf('CHECK OK') != -1)
		{
			price_complaint_send(2);
			return true;
		}
		else
		{
			alert(data);
			return false;
		}
	  //$('#pccTd').html(data);
	});
}




function forgot_pass_open()
{
	frontgroud_make();
	pcc = document.getElementById('forgot_pass_cont');
	pcc.style.display = '';
}
function forgot_pass_close()
{
	frontgroud_clear();
	document.getElementById('forgot_pass_cont').style.display = 'none';
}
function forgot_pass_send()
{
		params = { 
			login: $('#passbymail_login').val(),
			mini: '1',
			step: '2'
		};
		
		//print_r(params);
		
		$.post("/passbymail.php", 
			params,
			function(data){
				$('#fpsTd2').html(data);
		   });
}


function logon_send()
{
		
	params = { 
		login: $('#logon_login').val(),
		pass: $('#logon_pass').val(),
		mini: '1'
	};
	
	$.post("/login.php", 
		params,
		function(data){
			logon_open();
			$('#lcTd').html(data);
	   });
}
function logon_open()
{
	frontgroud_make();
	pcc = document.getElementById('logon_cont');
	pcc.style.display = '';
}
function logon_close()
{
	frontgroud_clear();
	document.getElementById('logon_cont').style.display = 'none';
}


function blank_url_open(url)
{
	frontgroud_make();
	pcc = document.getElementById('blank_url_cont');
	pcc.style.display = '';
	
	x = Math.round( ($(window).width() - pcc.offsetWidth) / 2);
	y = $(document).scrollTop() + Math.round($(window).height()/2) - Math.round(pcc.offsetWidth/2);
	
	pcc.style.left = x+'px';
	pcc.style.top = y+'px';
	
	data = 
		'<p>Вы покидаете fenixcomp.ru и переходите на сторонний сайт.<br>'+		'Мы не несём ответственности за контент посещаемого сайта,<br>'+		'работоспособность и безопасность указанной ссылки.</p>'+
		'<div><img src="/i/design4/arrow2.png" style="margin-right: 10px;"> перейти по сылке:  <a href="'+url+'" target="_blank">'+url+'</a></div>'+
		'<div><img src="/i/design4/arrow2.png" style="margin-right: 10px;"> вернуться на <a href="#" onClick="blank_url_close(); return false;">fenixcomp.ru</a></div>'+
		'<div><img src="/i/design4/arrow2.png" style="margin-right: 10px;"> <a href="#">сообщить нам</a>, если ссылка носит рекламный характер или является спамом</div>'+
		'<p><input type="checkbox" name="hide_blank_url" id="blank_url_switcher" style="border: 0px;" onChange="blank_url_switch();"> <label for="blank_url_switcher">Больше не показывать это окно</label></p>'
	;
	
	$('#bucTd2').html(data);
}
function blank_url_close()
{
	frontgroud_clear();
	document.getElementById('blank_url_cont').style.display = 'none';
}
function blank_url_switch()
{
	params = { 
		blank_url_switch: '1',
		blank_url_switch_value: $('#blank_url_switcher').attr('checked') ? 1 : 0
	};

	$.post("/index.php", 
		params,
		function(data){
			// do nothing
			//alert(data);
	   });
}



$(document).ready(function(){
	handleValueTip();
});
function handleValueTip()
{
	$('[valueTip]').each(function(indx, element){
			if ($(element).attr('value').length<1)
			{
				$(element).attr('value', $(element).attr('valueTip'));
			}
		
	});

    $('[valueTip]').focus(function()
		{
			if ($(this).attr('value') == $(this).attr('valueTip'))
			{
				$(this).attr('value', '');
			}
		}
    );
    
    $('[valueTip]').blur(function()
		{
			if ($(this).attr('value').length<1)
			{
				$(this).attr('value', $(this).attr('valueTip'));
			}
		}
    );  
}
