	function ajaxFileUpload(check_comment, object, id_object, id_user, source_div, resume, contact)
	{
		$("#loading")
		.ajaxStart(function(){
			$(this).show();
		})
		.ajaxComplete(function(){
			$(this).hide();
		});

		$.ajaxFileUpload
		(
			{
				url:'/js/doajaxfileupload.php',
				secureuri: false,
				fileElementId:'fileToUpload',
				dataType: 'json',
				success: function (data, status)
				{
					if(typeof(data.error) != 'undefined')
					{
						/*
						if(data.error != '')
						{
							alert(data.error);
				  			alert(check_comment);
							alert(data.result);
						}
						else
						{
							if(data.msg)alert(data.msg);
				  			alert(check_comment);
							alert(data.result);
						}
						*/
                        if(!data.result) data.result='';
						//if(data.error) alert(data.error);

						$.post("/js/complaint.php", { mode: "add_check", object: object, id_object: id_object, id_user: id_user, rec_file: data.result, comment: check_comment, resume: resume , contact: contact } );
                        if(check_comment) add_complaint_mc (object,id_object, 'КОММЕНТАРИЙ ПРОЗВОНЩИКА: '+ check_comment,'', 1);
						$('#'+source_div).remove();

					}
				},
				error: function (data, status, e)
				{
					alert(e);
				}
			}
		)

		return false;

	}

function call_details(table,column,id_object,id_user,td_id, contact)
{
   var objHTML = document.createElement('DIV');
   objHTML.align = 'left';
   objHTML.style.background = '#C0C0C0';
   objHTML.style.padding = '10px';
   objHTML.style.width = '530px';
   objHTML.style.border = '1px solid black';
   objHTML.style.cursor = 'hand';
   objHTML.style.display = 'none';

   var position  = set_position();
   objHTML.style.position = position;
   objHTML.style.zIndex  = 100;

   objHTML.id='ds2m_' + id_object + '_' + column;
   var div_id = objHTML.id;

   if(position == 'fixed')
   var ds2m_str = 'doc';
   else
   var ds2m_str = objHTML.id;

  document.getElementById('doc').insertBefore(objHTML, document.getElementById('doc').firstChild);
  var resume_select = "результат: <select size=\"1\" name=\"resume\" id=\"resume\"><option value=\"0\">&nbsp;</option><option value=\"1\">попался</option><option value=\"2\">все чисто</option><option value=\"3\">мутный...</option></select> ";
  $('#'+div_id).append('<table><tr><td><img style=\"padding: 0px 5px 0px 0px;\" src=\"/img/call.png\"></td><td><b style=\"color:black\"></b></td><td><img id=\"loading\" src=\"/images/progress.gif\" style=\"display:none;\"></td><td align=\"right\"><input id=\"fileToUpload\" style=\"background-color:#C0C0C0;\" size=\"2\" type=\"file\" name=\"fileToUpload\">' + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + resume_select + '<input value=\"ОК\" onclick=\"return ajaxFileUpload($(\'#check_comment_' + table + '_' + id_object+'\').val(),\'' + table + '\',' + id_object + ',' + id_user + ',\'' + div_id + '\',$(\'#resume option:selected\').val(),\'' + contact + '\');\" type=\"button\"> <input onclick=\"$(\'#' + div_id +'\').remove();\" value=\"Отмена\" type=\"button\">'+'</td></tr></table>');

 $('#'+div_id).append("<textarea style=width:100% id=\"check_comment_" + table + "_" + id_object + "\" name=comment rows=3></textarea>");
 $('#'+div_id).centerInClient();
 $('#'+div_id).show();
}


	function set_position() {
		var positon = 'fixed';
		if (navigator.userAgent.indexOf ("MSIE 5") != -1) postion='absolute';
		else if (navigator.userAgent.indexOf("MSIE 4") != -1) postion='absolute';
		else if (navigator.userAgent.indexOf ("MSIE 4.5") != -1) postion='absolute';
		else if (navigator.userAgent.indexOf ("MSIE 6") != -1) postion='absolute';
		return positon;
	}

function getBodyScrollTop() // координата верхнего левого угла (Y) видимой части с учетом скроллинга
{
   return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

function getBodyScrollLeft()  // координата верхнего левого угла (X) видимой части с учетом скроллинга
{
   return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}

function getClientWidth() // ширина видимой части экрана
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight()  // высота видимой части экрана
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}


function show_center_block(b_id) // функция отображает блок
{
var block = document.getElementById(b_id);
}


function create_complaint(table,column,id_object,id_user,td_id)
{

   var objHTML = document.createElement('DIV');
   objHTML.align = 'left';
   objHTML.style.background = '#D3CD81';
   objHTML.style.padding = '10px';
   objHTML.style.width = '530px';
   objHTML.style.border = '3px solid #C0C0C0';
   objHTML.style.cursor = 'hand';
   objHTML.style.display = 'none';

   var position  = set_position();
   objHTML.style.position = position;
   objHTML.style.zIndex  = 100;

   objHTML.id='ds2m_' + id_object + '_' + column;
   var div_id = objHTML.id;

   if(position == 'fixed')
   var ds2m_str = 'doc';
   else
   var ds2m_str = objHTML.id;

   document.getElementById('doc').insertBefore(objHTML, document.getElementById('doc').firstChild);

 if(column=='action') $('#'+div_id).append('<table><tr><td><img style=\"padding: 0px 5px 0px 0px;\" src=\"/images/alarm_big.png\"></td><td><b style=\"color:blue\"><font color=red><big>АКЦИЯ:</big></font><br>Выявляем и удаляем с сайта ЦИАН агентов занижающих цену</b></td></tr></table><br>');
 if(column=='action2') $('#'+div_id).append('<table><tr><td><img style=\"padding: 0px 5px 0px 0px;\" src=\"/images/alarm_big.png\"></td><td><b style=\"color:blue\"><font color=red><big>АКЦИЯ:</big></font> Выявляем и удаляем с сайта ЦИАН агентов выставляющих несуществующие объекты</b></td></tr></table><br>');

 if(column !='action2' && column !='action')
 {

   var objHTML = document.createElement("LEGEND");
   var b_element = document.createElement("B");
   var text = document.createTextNode("Некорректные данные? Отправьте сообщение модератору:");
   b_element.appendChild(text);
   objHTML.appendChild(b_element);
   document.getElementById(div_id).appendChild(objHTML);


   var objHTML = document.createElement("BR");
   document.getElementById(div_id).appendChild(objHTML);


   var objHTML = document.createElement("HR");
   document.getElementById(div_id).appendChild(objHTML);

     var objHTML = document.createElement('INPUT');
   objHTML.type='hidden';
   var hidden_id = 'cause2m_' + id_object + '_' + column + '_h';
   objHTML.id = hidden_id;
   document.getElementById(div_id).appendChild(objHTML);

var causes_array = eval(causes);

for(var i = 0; i<causes_array.length; i++)
{
	var table_array=eval(causes_array[i].table);
	var table_ok=0;
	for(var ii = 0; ii<table_array.length; ii++) {if(table_array[ii].t==table) var table_ok=1;}

  if(causes_array[i].column==column && table_ok)
  {
   var objHTML = document.createElement('BR');
   document.getElementById(div_id).appendChild(objHTML);
   var objHTML = document.createElement('INPUT');
   objHTML.type='checkbox';
   objHTML.value=causes_array[i].id;
   eventAdder(objHTML,"onclick","set_value(this,'" + hidden_id + "');");
   document.getElementById(div_id).appendChild(objHTML);
   var objHTML = document.createTextNode(causes_array[i].text);
   document.getElementById(div_id).appendChild(objHTML);
  }
}

  }

 if(column=='action')
 {
  $('#'+div_id).append('<h4>НАСТОЯЩАЯ ЦЕНА ЭТОГО ОБЪЕКТА: <input id=\"uc_action_price_' + table + "_" + id_object + '\" name=\"realprice\" type=\"text\" size=\"10\"><select id=\"uc_action_currency_' + table + "_" + id_object + '\" size=\"1\" name=\"currency\"><option value=\"руб.\">р.</option><option value=\"дол.\">$</option><option value=\"евро\">&euro;</option></select></h4>');
  var action_cells ='$(\'#uc_action_price_' + table + '_' + id_object +'\').val()+$(\'#uc_action_currency_' + table + '_' + id_object +' option:selected\').val()';
 }

 if(column=='action2')
 {
  $('#'+div_id).append('<b>Подробно опишите что и как...</b><br>');
  $('#'+div_id).append("<textarea style=width:100% id=\"uc_textarea_action_" + table + "_" + id_object + "\" name=comment rows=5></textarea>");
  hidden_id = "uc_textarea_action_" + table + "_" + id_object;
 }

   var objHTML = document.createElement('BR');
   document.getElementById(div_id).appendChild(objHTML);

   var objHTML = document.createElement("BR");
   document.getElementById(div_id).appendChild(objHTML);

 if(column !='action2' && column !='action')
 {

   var objHTML = document.createElement("INPUT");
   objHTML.type="button";
   objHTML.setAttribute("value", "Отправить");
   eventAdder(objHTML,"onclick","add_complaint('" + table + "'," + id_object + ",document.getElementById('" + hidden_id + "').value" + "," + id_user + ");document.getElementById('" + ds2m_str + "').removeChild(document.getElementById('" + div_id + "'));document.getElementById('" + td_id + "').style.background='#CCCCFF';");
   document.getElementById(div_id).appendChild(objHTML);

   var objHTML = document.createElement ("INPUT");
   objHTML.setAttribute("type", "button");
   objHTML.setAttribute("value", "Отмена");
   eventAdder(objHTML,"onclick", "document.getElementById('" + ds2m_str + "').removeChild(document.getElementById('" + div_id + "'));");
   document.getElementById(div_id).appendChild(objHTML);

 }

 if(column=='action2') $('#'+div_id).append('<input value=\"Отправить сообщение\" onclick=\"add_complaint(\'' + table + '\',' + id_object + ',\'##Жалоба по акции: \'+ $(\'#' + hidden_id +'\').val(),' + id_user + ');$(this).parent().remove();\" type=\"button\"> <input onclick=\"document.getElementById(\'' + ds2m_str + '\').removeChild(document.getElementById(\'' + div_id + '\'));\" value=\"Отмена\" type=\"button\">&nbsp;&nbsp;&nbsp;<input id=\"uc_append_' + table + "_" + id_object + '\" type=\"checkbox\" checked>продублировать в Личный комментарий');
 if(column=='action') $('#'+div_id).append('<input value=\"Отправить сообщение\" onclick=\"add_complaint(\'' + table + '\',' + id_object + ',\'##Жалоба по акции, цена: \'+ ' + action_cells +',' + id_user + ');$(this).parent().remove();\" type=\"button\"> <input onclick=\"document.getElementById(\'' + ds2m_str + '\').removeChild(document.getElementById(\'' + div_id + '\'));\" value=\"Отмена\" type=\"button\">&nbsp;&nbsp;&nbsp;<input id=\"uc_append_' + table + "_" + id_object + '\" type=\"checkbox\" checked>продублировать в Личный комментарий');

   $('#'+div_id).centerInClient();
   $('#'+div_id).show();
}



function eventAdder(objAttrib,handler,addFunction){

   if ((!document.all)&&(document.getElementById)){
       objAttrib.setAttribute(handler,addFunction);
   }
   if ((document.all)&&(document.getElementById)){
       objAttrib[handler]=new Function(addFunction);
   }
}

function set_value(object,hidden_id)
{
var current_str = document.getElementById(hidden_id).value;

if(object.checked)
	{
   if(!current_str)
   		{
   			var replace_str = escape(object.value) + '=' + escape(object.value) + ';';
   			document.getElementById(hidden_id).value = replace_str;
   		}
    else
   		{
   			var current_str = document.getElementById(hidden_id).value;
   			var replace_str = escape(object.value) + '=' + escape(object.value) + ';';
   			document.getElementById(hidden_id).value = current_str + replace_str;
   		}
	}
else
	{
   	   if(!current_str)
   		{
   			var replace_str = escape(object.value) + '=' + escape(object.value) + ';';
   			document.getElementById(hidden_id).value = replace_str;
		}
    else
		{
   			var current_str = document.getElementById(hidden_id).value;
   			var replace_str = escape(object.value) + '=' + escape(object.value) + ';';
   			document.getElementById(hidden_id).value = current_str.replace(replace_str,'');
   		 }
	}
}


function add_complaint(object,id_object,cause,id_user,ds_id) {
  var url = "/js/complaint.php";
  request.open("POST", url, true);
  request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  request.send("mode=add&object=" + escape(object) +
               "&id_object=" + escape(id_object) +
               "&id_user=" + escape(id_user) +
               "&cause=" + escape(encodeURIComponent(cause)));

        if($('#uc_append_' + object + "_" + id_object).attr('checked'))
      {
         add_complaint_mc(object,id_object,cause,'',1);
      }
}



function ucompl_creeate(object,id_object,id_user) {
var admin_note;
if(object=='flat')admin_note='Если вы жалуетесь на занижение цены, то обязательно сообщайте реальную цену!';
else admin_note='Максимально полно описывайте нарушение!';

if($("#compl_free_form_" + object + "_" + id_object).text()) { $("#compl_free_form_" + object + "_" + id_object).toggle(); $('#tr_{$id_object}').find('.complaint').toggle();}
else  $("#ucompl_link_" + object + "_" + id_object).after("<br><div style=\"background:#D3CD81;border:1px solid #C0C0C0;padding:20px;\" id=\"compl_free_form_" + object + "_" + id_object + "\" align=\"left\"><font color=blue><img style=\"padding: 5px 5px 0px 0px;\" src=\"/images/alarm.png\">Сообщение Модератору в свободной форме:</font><br><textarea style=width:100% onfocus=\"ucompl_clear(this.id);\" id=\"uc_textarea_" + object + "_" + id_object + "\" name=comment rows=5>" + admin_note + "</textarea><br><input type=button value=\"Отправить сообщение\" onclick='if($(\"#uc_textarea_" + object + "_" + id_object + "\").css(\"background\")) add_complaint(\""+ object + "\"," + id_object + ",\"##\"+$(\"#uc_textarea_" + object + "_" + id_object + "\").val()," + id_user + ");$(this).parent().remove();'><input type=\"button\" onclick='$(this).parent().remove();$(\"#ucompl_link_" + object + "_" + id_object + "\").show();$(\"#tr_" + id_object + "\").find(\".complaint\").toggle();' value=\"Отмена\">&nbsp;&nbsp;&nbsp;<input id=\"uc_append_" + object + "_" + id_object + "\" type=\"checkbox\" checked>продублировать в Личный комментарий</div>");
$("#ucompl_link_" + object + "_" + id_object).hide();
}


function ucompl_clear(textarea)
{
	if(!$('#'+textarea).css('background'))
    { $('#'+textarea).text(''); $('#'+textarea).css({ 'background':'#EFF3C5'}); }
}

var appned_uc;

function add_complaint_mc(object,id_object,cause,id_compl,appned_uc) {
 if(!appned_uc)appned_uc=0;
 else appned_uc=1;

  var url = "/js/complaint.php";
  cause = cause.replace(/[a-z<>]/gi, '');
  $("#uc_" + object + "_" + id_object).html("<span style='background:#D2DBDA;'><b>ваш комментарий:</b></span> <span id='uc_span_" + object + "_" + id_object + "'>" + cause + "</span>");
  $("#uc_" + object + "_" + id_object).show();
  $("#uc_a_" + object + "_" + id_object).show();
  $("#uc_text_" + object + "_" + id_object).hide();

  $('#dl2m_' + id_object + "_comment").css({ 'background':'#CCCCFF'});

  request.open("POST", url, true);
  request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  request.send("mode=add_mc&object=" + escape(object) +
               "&id_object=" + escape(id_object) +
               "&append=" + escape(appned_uc) +
               "&id_compl=" + escape(id_compl) +
               "&cause=" + escape(encodeURIComponent(cause)));
}

function accept_complaint(object,id_object,id_complaint,ds_id) {
  var url = "/js/complaint.php";
//  document.getElementById("tr_" + id_object).style.background="#CCCCFF";
  document.getElementById("dl2m_" + id_object + "_comment").style.background="#CCCCFF";
  request.open("POST", url, true);
  request.setRequestHeader("Content-Type",
                           "application/x-www-form-urlencoded");
  request.send("mode=accept&object=" + escape(object) +
               "&id_object=" + escape(id_object) +
               "&id_complaint=" + escape(id_complaint));
  document.getElementById(ds_id).style.display='none';
}


function bad_complaint(object,id_object,id_complaint,ds_id) {
  var url = "/js/complaint.php";
  request.open("POST", url, true);
  request.setRequestHeader("Content-Type",
                           "application/x-www-form-urlencoded");
  request.send("mode=bad&object=" + escape(object) +
               "&id_object=" + escape(id_object) +
               "&id_complaint=" + escape(id_complaint));
  document.getElementById(ds_id).style.display='none';
}

function del_complaint(object,id_object,id_complaint,ds_id) {
  var url = "/js/complaint.php";
  request.open("POST", url, true);
  request.setRequestHeader("Content-Type",
                           "application/x-www-form-urlencoded");
  request.send("mode=del&object=" + escape(object) +
               "&id_object=" + escape(id_object) +
               "&id_complaint=" + escape(id_complaint));
  document.getElementById(ds_id).style.display='none';
}
