var reg_mail = new RegExp("^([A-Za-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}$");
function open_gallery(Code,T_Code) {
	myWin = open ("","displayWindow","width=1000,height=650,top=100,toolbar=no,menubar=no,resizable=yes");
	myWin.document.open();
	myWin.document.write('<html><head><title>Хамелеон</title></head><body>');
	myWin.document.write('<img src="/Pages/images/B/'+Code+'_'+T_Code+'.jpg"/>');
	myWin.document.write('</body></html>');
	myWin.document.close();
	}

function on() {
	$('#tools > .quantity').removeAttr('disabled');
}
function price(id) {
	ids = id-1;
	quantity = $('#Products_'+ids).next().val();
	cost = $('#Products_'+ids).val();
	$('#Products_'+ids).next().next().html(quantity*cost);
	$('#Products_'+ids).next().removeAttr('onchange');
	$('#Products_'+ids).next().change(
		function () {
			price(id);
		}
	);
}
function add_Products(id) {
	$.ajax({
		type: "GET",
		url: "/ajax.php",
		cache: false,
		data: "mode=order&id="+id,
		success: function(response) {
			price(id);
			$('#tools').append(response);
		}
 });
}
function empty(val) {
	if (val=='') return true;
	else return false;
}
function my_mail() {
	if (!empty($('#fio').val()) && !empty($('#email').val()) && reg_mail.test($('#email').val())) {
		i = 0;
		//str = '<table><tr><td>оборудование</td><td>количество</td><td>цена</td></tr>';
		while (i < ($('#order select').length-1)) {
			//str += '<tr><td>'+$('#Products_'+i+' option[@selected]').text()+'</td><td>'+$('#Products_'+i).next().val()+'</td><td>'+$('#Products_'+i).next().next().text()+'</td></tr>';
			str += ' '+$('#Products_'+i+' option[@selected]').text()+' '+$('#Products_'+i).next().val()+' '+$('#Products_'+i).next().next().text()+'<br/>';
			i++;
		}
		//str += '</table>';
		$.ajax({
			type: "POST",
			url: "/send/query.php",
			cache: false,
			data: "mode=order&fio="+$('#fio').val()+"&email="+$('#email').val()+"&note="+str,
			success: function(response) {
				$('#if_error').html(response);
			}
		});
	}
	else {
		$('#if_error').html('Неправильно введеные данные');
	}
}
function contact() {
	if (!empty($('#fio').val()) && !empty($('#email').val()) && reg_mail.test($('#email').val())) {
		$.ajax({
			type: "POST",
			url: "/send/query.php",
			cache: false,
			data: "fio="+$('#fio').val()+"&email="+$('#email').val()+"&note="+$('#note').val(),
			success: function(response) {
				$('#if_error').html(response);
			}
		});
	}
	else {
		$('#if_error').html('Неправильно введеные данные');
	}
}