function popup_window(url, name) {
	
	win_param = 1/2;
	
	/* var cx=screen.width * win_param; */
	var cx=785;
	var cy=screen.height * win_param;
	
	window.open(url,name,"toolbar=no,location=yes,status=no,directories=no,menubar=no,resizable=yes,width="+cx+",height="+cy+",scrollbars=yes,top=50px,left=50px");
	
}

radio_elem_id = new Array();
function radio_button(r_name, r_id) {
	var obj = document.getElementById(r_name + r_id);
	var input_hidden = document.getElementById(r_name); 

	if(radio_elem_id[r_name] != ''){
		var obj_last = document.getElementById(radio_elem_id[r_name]); 
	}
	
	regExpStr = 'default_radio_btn_checked';
	if(obj_last){
		obj_last.className = obj_last.className.replace(new RegExp(regExpStr), '');
	}
	
	if(obj){
		if (!obj.className.match(/\default_radio_btn_checked\b/)){ 
			obj.className += ' default_radio_btn_checked';
		} else {
			obj.className = obj.className.replace(new RegExp(regExpStr), '');
		}
	}	
	
	if(input_hidden){
		input_hidden.value = r_id;
		radio_elem_id[r_name] = r_name + r_id;
	}
	
	
}



var fickt_inputs = true;
function auth_clear(obj,v,action) {
	if (obj.value == v && fickt_inputs) {
		obj.value = ''
	} else if (obj.value == '') {
		obj.value = v
	}
	if (action == 'ch') {
		fickt_inputs = false
	}
}

function input_focus(id, text)
{
	qs_input = document.getElementById(id);
	if(qs_input){
		if (qs_input.value == text)  {
			qs_input.value = '';
		}
	}	
}

function input_onblur(id, text)
{
	qs_input = document.getElementById(id);
	if(qs_input){
		if (qs_input.value == ''){
			qs_input.value = text; 
		}
	}	
}

function EldShowNote (popup_left, popup_top, popup_html){
	$j("#filter-helper").css({"left":popup_left,"top":popup_top})
	$j("#filter-helper-content").html(popup_html)
	
	$j("#filter-helper-content").css("width",$j("#filter-helper").width()- 35 +'px');
	
	popup_left_shadow = $j("#filter-helper").offset().left + 3;
	popup_top_shadow = $j("#filter-helper").offset().top + 2;
	
	//alert('popup_left_shadow='+popup_left_shadow+' popup_top_shadow='+popup_top_shadow);
	
	$j("#filter-helper-shadow").css({"left":popup_left_shadow,"top":popup_top_shadow})
	$j("#filter-helper-shadow").css("width",$j("#filter-helper").width());
	var timer = setTimeout(function(){
		$j("#filter-helper-shadow-inner").css("height",$j("#filter-helper").height()-11);
		$j("#filter-helper-shadow").css("display","block");
	}, 5);
	
	
	/* if ($j("#filter-helper-content").width() > 360) {
		$j("#filter-helper-content").css("width","360px")
		$j("#filter-helper-content .title").css({"width":"290px","white-space":"normal"})
	} else { */
		/* if ($j("#filter-helper-content").width() < 330) {
			$j("#filter-helper-content").css("width","330px")
			$j("#filter-helper-content .title").css({"width":"160px","white-space":"normal"})
		} else {
			$j("#filter-helper-content").css("width",$j("#filter-helper-content").width())
			$j("#filter-helper-content .title").css({"width":($j("#filter-helper-content").width() - 62),"white-space":"normal"})
		} */
	//}
	/* $j("#filter-helper .filter-helper-top").children(1).css("width",($j("#filter-helper-content").width() - (0 - 24) + 'px'))
	$j("#filter-helper .filter-helper-bottom").children(2).css("width",($j("#filter-helper-content").width() - (0 - 24) + 'px')) */
	//$j("#filter-helper .filter-helper-bottom-shadow_inr").children(1).css("width",($j("#filter-helper-content").width() - (0 - 24) + 'px'))
}

function EldShowNotePickup (popup_left, popup_top, popup_html){
	$j("#filter-helper").css({"left":popup_left,"top":popup_top, "width":600, "height":"auto"})
	$j("#filter-helper-content").html(popup_html)
	
	$j("#filter-helper-content").css("width",$j("#filter-helper").width()- 35 +'px');
	
	popup_left_shadow = $j("#filter-helper").offset().left + 3;
	popup_top_shadow = $j("#filter-helper").offset().top + 2;
	
	//alert('popup_left_shadow='+popup_left_shadow+' popup_top_shadow='+popup_top_shadow);
	
	$j("#filter-helper-shadow").css({"left":popup_left_shadow,"top":popup_top_shadow})
	$j("#filter-helper-shadow").css("width",$j("#filter-helper").width());
	var timer = setTimeout(function(){
		$j("#filter-helper-shadow-inner").css("height",$j("#filter-helper").height()-11);
		$j("#filter-helper-shadow").css("display","block");
	}, 5);
}

//функция для подсчета итоговой суммы покупки при добавлении ПДС
function change_total(price_pds, r_name, r_id, years)
{
	var obj = document.getElementById(r_name + r_id);
	var input_hidden = document.getElementById(r_name);
	
	if(radio_elem_id[r_name] != ''){
		var obj_last = document.getElementById(radio_elem_id[r_name]); 
	}
	
	if (!obj.className.match(/\default_radio_btn_checked\b/)){
		document.getElementById("total_price_id_hidden").value = parseInt(document.getElementById("total_price_id_hidden").value) + parseInt(price_pds);
		if(obj_last){
			document.getElementById("total_price_id_hidden").value = parseInt(document.getElementById("total_price_id_hidden").value) - parseInt($j(obj_last).attr('name'));
		}
	}
}

//функция для подсчета итоговой суммы покупки при добавлении карты призовая территория
function addSberCardPrice(price)
{
	var input_hidden = document.getElementById("addSberCard");
	
	if (input_hidden.value == "") {
		document.getElementById("total_price_id_hidden").value = parseInt(document.getElementById("total_price_id_hidden").value) + parseInt(price);
		input_hidden.value = price;
	} else {
		document.getElementById("total_price_id_hidden").value = parseInt(document.getElementById("total_price_id_hidden").value) - input_hidden.value;
		input_hidden.value = "";
	}
}


//функция для форматирования числа разделяя пробелами
function numFormat(n, d, s) {
	if (arguments.length == 2) { s = " "; }
	if (arguments.length == 1) { s = " "; d = "."; }
	n = n.toString();
	a = n.split(d);
	x = a[0];
	y = a[1];
	z = "";
	if (typeof(x) != "undefined") {
	for (i=x.length-1;i>=0;i--)
		z += x.charAt(i);
	z = z.replace(/(\d{3})/g, "$1" + s);
	if (z.slice(-s.length) == s)
		z = z.slice(0, -s.length);
	x = "";
	for (i=z.length-1;i>=0;i--)
		x += z.charAt(i);
	if (typeof(y) != "undefined" && y.length > 0)
		x += d + y;
	}
	return x;
}


function format_total()
{
	format = document.getElementById("total_price_id_hidden").value;
	format = numFormat(format);
	document.getElementById("total_price_id").innerHTML = format;
}



//Показываем всплывающий див подсказки
$j(document).ready(function(){
	$j("#filter-helper-close").click(function(){
		$j("#filter-helper").removeClass("filter-helper-active");
		//$j("#filter-helper-shadow").css("displayheight","none");
		$j("#filter-helper-shadow").css("display","none");
		$j("#filter-helper-shadow-inner").css("","10");
	})
	
	$j("#sort").find("li img").click(function(){
		var help_left = $j(this).offset().left + 25 + 'px'
		var help_top = $j(this).offset().top - 30 + 'px'
		if (!$j("#filter-helper").hasClass("filter-helper-active")) {
			$j("#filter-helper").toggleClass("filter-helper-active")
		}
		popup_html = $j(this).next().html()
		
		EldShowNote(help_left, help_top, popup_html);
	})
	
	
	$j(".cat_lot2").find("input.show_cat_popup").click(function(){
		var help_left = $j(this).offset().left - 190 + 'px'
		var help_top = $j(this).offset().top + 'px'
		if (!$j("#filter-helper").hasClass("filter-helper-active")) {
			$j("#filter-helper").toggleClass("filter-helper-active")
		}
		popup_html = $j(this).parent().next().html()
		EldShowNote(help_left, help_top, popup_html);
	})
})
