function faq(id,base) {
	if (document.getElementById("plus"+id).src==base+'i/plus.gif') {
		document.getElementById("plus"+id).src=base+'i/minus.gif';
		if (document.getElementById("flag"+id).value!=0) {
			$("#answer"+id).fadeIn(300);
		} else {
        	document.getElementById("answer"+id).style.display='block';
   			$.ajax({
				type:"POST",
				url:base+'answer',
				dataType:'html',
				cache:'false',
				data:{id:id},
				success: function onAjaxSuccess(html){
					$("#answer"+id).empty();
					document.getElementById("answer"+id).innerHTML=html;
				}
   			})
		}
	} else {		document.getElementById("plus"+id).src=base+'i/plus.gif';
		document.getElementById("answer"+id).style.display='none';
	}
}
function ltrim(s){return s.replace(/^\s+/, '');}// Урезание левых пробелов в строке
function rtrim(s){return s.replace(/\s+$/, '');}// Урезание правых пробелов в строке
function trim(s){return rtrim(ltrim(s));}// Урезание пробелов в строке
function setheightwidth(height,width) {
	document.getElementById('height').value=height;
	document.getElementById('width').value=width;
}
function setcheckboxes(id) {
	document.getElementById('radio'+id).checked=true;
}
function mathcalc(base) {
	var height = trim(document.getElementById('height').value);
	var width = trim(document.getElementById('width').value);
	if ((height=='')||(isNaN(height))) {
		alert('Некорректно введена высота!');
	} else {
		if ((width=='')||(isNaN(width))) {
			alert('Некорректно введена ширина!');
		} else {
			$('#gogogo').empty();
			$('#gogogo').append('<img src="'+base+'i/loading.gif" alt="подождите..."/>');
   			var type = $('input[name=type]:checked').val();
			var material = document.getElementById('material').value;
			var amount = document.getElementById('amount').value;
   			$.ajax({
				type: "POST",
				url: '/math',
				dataType: 'html',
				cache: 'false',
				data: {type: type, height: height, width: width, material: material, amount:amount},
				success: function onAjaxSuccess(html) {
					$("#load").css({display: "none"});
					$("#load").empty();
					$("#load").append(html);
					$("#load").fadeIn(300);
					$('#gogogo').empty();
					$('#gogogo').append('<img src="'+base+'i/button1.gif" onclick="mathcalc(\''+base+'\')" alt="Посчитать" width="107" height="36" />');

				}
   			})
		}
	}
}
function mathorder(base) {
	var type = document.getElementById('temp_type').value;
	var height = document.getElementById('temp_height').value;
	var width = document.getElementById('temp_width').value;
	var full_name = document.getElementById('temp_full_name').value;
	var material = document.getElementById('temp_material').value;
	var amount = document.getElementById('temp_amount').value;
	var BW = document.getElementById('temp_BW').value;
	var BY = document.getElementById('temp_BY').value;
	var area = document.getElementById('temp_area').value;
	var BZ = document.getElementById('temp_BZ').value;
	$('#load').empty();
	$('#gogogo').empty();
	$('#gogogo').append('<img src="'+base+'i/loading.gif" alt="подождите..."/>');
   			$.ajax({
				type: "POST",
				url: '/order',
				dataType: 'html',
				cache: 'false',
				data: {type: type, height: height, width: width, full_name: full_name, material:material, amount:amount, BW: BW, BY: BY, area: area, BZ: BZ},
				success: function onAjaxSuccess(html) {
					$("#order").css({display: "none"});
					$("#order").empty();
					$("#order").append(html);
					$("#order").fadeIn(300);
					$('#gogogo').empty();
					$('#gogogo').append('<img src="'+base+'i/button1.gif" onclick="mathcalc(\''+base+'\')" alt="Посчитать" width="107" height="36" />');
				}
   			})
}

function remove_row(id,base) {
if (confirm('Вы уверены, что хотите удалить строку заказа?')) {
	$('#load').empty();
	$('#gogogo').empty();
	$('#gogogo').append('<img src="'+base+'i/loading.gif" alt="подождите..."/>');
   			$.ajax({
				type: "POST",
				url: '/remove_row',
				dataType: 'html',
				cache: 'false',
				data: {id: id},
				success: function onAjaxSuccess(html) {
					$("#order").css({display: "none"});
					$("#order").empty();
					$("#order").append(html);
					$("#order").fadeIn(300);
					$('#gogogo').empty();
					$('#gogogo').append('<img src="'+base+'i/button1.gif" onclick="mathcalc(\''+base+'\')" alt="Посчитать" width="107" height="36" />');
				}
   			})
}
}

function up_count(id,base,amount) {	$('#load').empty();
	$('#gogogo').empty();
	$('#gogogo').append('<img src="'+base+'i/loading.gif" alt="подождите..."/>');
   			$.ajax({
				type: "POST",
				url: '/up_count',
				dataType: 'html',
				cache: 'false',
				data: {id: id},
				success: function onAjaxSuccess(html) {
					$("#order").css({display: "none"});
					$("#order").empty();
					$("#order").append(html);
					$("#order").fadeIn(300);
					$('#gogogo').empty();
					$('#gogogo').append('<img src="'+base+'i/button1.gif" onclick="mathcalc(\''+base+'\')" alt="Посчитать" width="107" height="36" />');
				}
   			})
}

function down_count(id,base,amount) {
if (amount>1) {
	$('#load').empty();
	$('#gogogo').empty();
	$('#gogogo').append('<img src="'+base+'i/loading.gif" alt="подождите..."/>');
   			$.ajax({
				type: "POST",
				url: '/down_count',
				dataType: 'html',
				cache: 'false',
				data: {id: id},
				success: function onAjaxSuccess(html) {
					$("#order").css({display: "none"});
					$("#order").empty();
					$("#order").append(html);
					$("#order").fadeIn(300);
					$('#gogogo').empty();
					$('#gogogo').append('<img src="'+base+'i/button1.gif" onclick="mathcalc(\''+base+'\')" alt="Посчитать" width="107" height="36" />');
				}
   			})
}
}