var pay_link ='';
function OpenWindow(url,width,height, name, scrlls) {
	x = (640 - width)/2, y = (480 - height)/2;
	
	if (screen) {
		y = (screen.availHeight - height)/2;
		x = (screen.availWidth - width)/2;
	}
	var window_name = (name) ? name : 'mb_' + get_random();
	var scrlls = scrlls || "yes";

	window.open (url,name, 'width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x+ ', scrollbars = '+scroll+ ',resizable=0,status=no,toolbar=no,directories=no,menubar=no');
}

function min_height(_element, _height) {
	if(_element.clientHeight < _height) {
		_element.style.height = _height + 'px';
	}
}

function product_blocks(_string) {
	$('.content_block').hide();
	$('.block_link').show();
	$('#' + _string).show();
	$('#' + _string + '_link').hide();
	
	return false;
}

function switch_display(_id) {
	if($('#' + _id).css('display') == 'block') {
		$('#' + _id).slideUp('slow');
	} else {
		$('#' + _id).slideDown('slow');
	}
}

function switch_display_by_class(_class) {
	if($('.' + _class).css('display') == 'block') { 
		$('.' + _class).slideUp('slow');
	} else {
		$('.' + _class).slideDown('slow');
	}
}

function ChangeOption(_ele) {
	value = _ele.options[document.getElementById("products_list").selectedIndex].value;
	var type = document.getElementById('t1').checked ? 1 : (document.getElementById('t2').checked ? 2: 0); 
	if (value == 1 || value == 2 || value == 4) {
		if(type == 1)
			$('#download').attr('href', '/f/support/pay/bank_form.pdf');
		else $('#download').attr('href', '/f/support/pay/post_form.pdf');
	} else if (value == 3) {
		if(type == 1)
			$('#download').attr('href', '/f/support/pay/bank_form.pdf');
		else $('#download').attr('href', '/f/support/pay/post_form.pdf');
	} else if (value == 5 || value == 6) {
		if(type == 1)
			$('#download').attr('href', '/f/support/pay/bank_form_cc.pdf');
		else $('#download').attr('href', '/f/support/pay/post_form_cc.pdf');
	}
}

$(document).ready(function()
{
	$('.bslink').bstip();
	
	$("h2.faqhead").click(function () { 
		if ($(this).next().css('display') == 'none')
		{
			$(this).siblings('dl.faq').css('display','none');
			$(this).next().css('display','block');
		}
		else
		{
			$(this).next().css('display','none');
		}
	});
	
	$("dl.faq dd a.title").click(function () { 
		
		if ($(this).next().css('display') == 'none')
		{
			$("dl.faq dd").find("div").css('display','none');
	    	$(this).next().css('display','block');
	    	return false;
		}
		else
		{
			$(this).siblings("div").css('display','none');
	    	return false;
		}
	});
	
	$("a.showmoar").toggle(
		function () { 
			var d = $(this).attr('rel');
			$("#"+d).css('display','block');
			return false;
		},
		function () { 
			var d = $(this).attr('rel');
			$("#"+d).css('display','none');
			return false;
		}
	);

	$("#sortTable").tablesorter({sortList: [[0,0]], headers: { 2: { sorter: false}}});

	$(".inquiry-close").click(function () { 
		close_inquiry();
	});
	$(".pay").click(function () { 
		if (in_array("pay", is_inquiry)) {
			
			pay_link = $(this).attr("href");

			$('#inquiry-overlay').css({'height':$('#main').height()});
            $('#inquiry-overlay').show();
            $('#inquiry-popup').show();
			$('#inquiry-block').load('/ajax/inquiry/', {
				folder: 'pay',
				num: 'first'
			}, function(data, textStatus) {

			});
		
			return false;
		}	

	});

	$('#movie-overlay').css({'height':$('#main').height()});
    $("#movie_lnk").click(function () { 
          $('#movie-overlay').show();
          $('#movie-popup').show();
          return false;
	});
    $(".movie-close").click(function () { 
		$('#movie-overlay').hide();
        $('#movie-popup').hide();
        return false;
	});
	

});

 	function show_question(_folder, _num, _q_id) {
		var keys = new Array();

		$("input").each(function(){
			if ($(this).attr("checked")==true) { 
				keys.push($(this).val());    
			} 
		});     
		if (_num!=0 && !keys.length){
			$('#error').show();
			$('#error').html('Ошибка. Не все поля заполнены.');
		} else {
			$('#inquiry-block').load('/ajax/inquiry/', {
				folder: _folder,
				num: _num,
				qid: _q_id,
				answer: keys
			}, function() {
				$(".inquiry-table input").click(function () { 
					$("input").not($("input:checked")).parents("tr").removeClass("checked");
				if ($(this).attr("checked")==true) { 
					$(this).parents("tr").addClass('checked');
				} else
				{
					$(this).parents("tr").removeClass('checked');
				}
				});
			});
	 	}
	}

	function close_inquiry() {
		$('#inquiry-overlay').hide();
        $('#inquiry-popup').hide();
		window.location = pay_link;
	}                                                                                                             

	function in_array(needle, haystack, strict) {
	   var found = false, key, strict = !!strict;
	   for (key in haystack) {
	      if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
	         found = true;
	         break;
	      }
	   }
	   return found;
	}

