function openRequest(link) {
	window.open(link,'_blank', '');
}

function reqSubmitRad(name_rad) {
	if ($("input[@name='radio_name']:checked").val() == 0) return false;
	return true;
}

function stNewRedirect(sw_id, type) {

	if ($("#workFlag"+sw_id+":checked").val() > 0 && type == 3) {
		$("#newStep").show("fast");
		//if ($("#isProblemFinish").attr("checked") == false) $("#closeDate").attr("disabled","yes");
		$("#whatDo").attr("disabled","yes");
	} else if(type == 1) {
		//$("#closeDate").removeAttr("disabled");
		$("#isProblemFinish").removeAttr("checked");
		$("#newStep").hide("fast");
		$("#whatDo").removeAttr("disabled");
	}
	else {
		$("#isProblemFinish").removeAttr("checked");
		//if ($("#isProblemFinish").attr("checked") == false) $("#closeDate").attr("disabled","yes");
		$("#newStep").hide("fast");
		$("#whatDo").attr("disabled","yes");
	}
}

function isclose_edit() {
	if ($("#isClose").attr("checked") == false) {
		$("#whatDo").attr("disabled","yes");
		//$("#closeDate").attr("disabled","yes");
	}
	else {
		$("#whatDo").removeAttr("disabled");
		//$("#closeDate").removeAttr("disabled");
	}
}

function orderEditSubmit() {
	if ($("#isClose").attr("checked") == true) {
		if($("#whatDo").val() == '')   {
			alert('Не заполнено поле: "Что сделано"');
			return false;
		}
	}
}

function leftBar() {

}

function requestNewSubmit() {

	if ($("#workFlag3:checked").val() > 0) {
		if($("input[name='rdToUserName']").val() == "") { alert("Не заполнено поле: Кому передано"); return false; }
		if($("input[name='rdMethod']").val() == "") { alert("Не заполнено поле: Как передано"); return false; }
		if($("textarea[name='st_note']").val() == "") { alert("Не заполнено поле: Примечание"); return false; }
		if($("#isProblemFinish:checked").val() > 0 && $("textarea[name='ansfWorkReport']").val() == "") { 
			alert("Не заполнено поле: Проведенные работы"); return false; 
		}
	}
	return true;
}
     function filtersubmit(ftype) {

    if (ftype == 1) {
        var date1 = document.getElementById("dtDate1")
        if (date1.value == "") { alert("Не задано начало периода"); date1.focus();  return false; }
        var date2 = document.getElementById("dtDate2")
        if (date2.value == "") { alert("Не задан конец периода"); date2.focus();  return false; }
    }
    if (ftype == 2) { }
    if (ftype == 3) {
        var date1 = document.getElementById("dtDate1")
        if (date1.value == "") { alert("Выберите дату"); date1.focus();  return false; }
    }
}

function myDialogShow(id) {
  var md = document.getElementById(id);
  if(md) {
    md.style="display: block";
  }
}

function myDialogHide(id) {
  var md = document.getElementById(id);
  if(md) {
    md.style="display: none";
  }
}

/***********************************************************************************/
/*
* Глобальный массив для хранения временных скрытых данных
*/
var listVars = new Object();
listVars = {
  0: { id:0, pref:'', val:'' }
};

/*******************************************************************************/
function lineOver(id, pref) {
  var d = document.getElementById(pref+id);
  var aSEL = d.getAttribute("sel");
    if (d &&( aSEL == null ||aSEL == "" || aSEL == "undefined")) {
        d.setAttribute("lastClass", d.className);
        d.className = 'over';
    }
}

function lineOut(id, pref) {
    var d = document.getElementById(pref+id);
    var aSEL = d.getAttribute("sel");
    if (d && ( aSEL == null ||aSEL == "" || aSEL == "undefined")) {
        var a = d.getAttribute("lastClass");
        if (a) {
            d.className = a;
        }
    }
}


function setLastVars(VarNum, VarVal) {

}
/**
 *   id - ID из таблици добавляемый к pref
 *   pref - препикс иуникальной сторки TR
 *   TDNum - номер TD содержащего значение
 *   VarNum - в какую из глобальных переменных запомнить последние значение
 *   viewID - куда показать выбранное значение
 *   fiomInputID - input у скрытой формы в которую запомнить значение
 *   callbackFunc - callback без параметров
 */
function lineClick(id, pref, TDNum, VarNum, viewID, formInputID, callbackFunc) {
    /* Удаляем старого, но сперва его проверим */
    lastView = undefined;
    lastInput = undefined;

    if (isNaN(VarNum) || VarNum < 0 || VarNum == undefined) {
      alert('Номер непеменной не известен');
      return;
    }

    if(viewID != '') viewID = document.getElementById(viewID);
    if(!viewID) viewID = '';
    if(formInputID != '') formInputID = document.getElementById(formInputID);
    if(!formInputID) formInputID = '';

    if(listVars[VarNum] == undefined)  listVars[VarNum] = { id:0, pref:'', val:'' };

    last = document.getElementById(listVars[VarNum].pref+listVars[VarNum].id);
    if (last) {
      last.setAttribute("sel", "");
      if(formInputID != '') formInputID.value = '';
      var a = last.getAttribute("lastClass");
      if (a) {
           last.className =  a;
      }
    } else {  }

    /* Устанавливаем нового */
    curr = document.getElementById(pref+id);
    if (curr) {
        curr.setAttribute("sel", "sel");
        curr.className = "active";
        listVars[VarNum].id = id;
        listVars[VarNum].pref = pref;

        if(formInputID != '') formInputID.value = id;
        var td_Coll = curr.getElementsByTagName("td");
         val = '';
         if(TDNum >= 0) {
           val = td_Coll[TDNum].innerHTML;
         }
         else {
           val = '';
         }
         listVars[VarNum].val = val;

        if(viewID != '') viewID.innerHTML = listVars[VarNum].val;
    }
    if (callbackFunc != undefined) {
      eval(callbackFunc);
    }
}
/*
url - ссылка
ParamName - имя параметра который должен быть передан как POST
VarNum - индекс массива в listVars
toID - куда вставить контент
FCallback - функция
*/
function SendByGlobalVar(url, ParamName, VarNum, toID, FCallback) {
    if(listVars[VarNum] == undefined) { return; }
    LoadingDisplay(1);
    str = ParamName+"="+listVars[VarNum].id+"&ajax=1";
    $.ajax({
	   type: "POST",
	   url: url,
	   data: str,
	   success: function(data){
	     $('#'+toID).html(data);
	        LoadingDisplay(2);
            if (FCallback != undefined) {
              eval(FCallback);
            }
	   }
	 });
}
/*******************************************************************************/

function loadToDiv(url, toID) {
	//var div = document.getElementById(toID);
	var div = $("#"+toID);
	if (div) {
		div.html( "<h2>Загрузка</h2>");

	     $.ajax({
	  	   type: "POST",
	  	   url: url + "ajax-1/",
	  	   data: "",
	  	   success: function(data){
	  	     $('#'+toID).html(data);
	  	   }
	  	 });

	} else {
		alert('Error');
	}
}

function buttonSend(url, dialog_id) {
	script = undefined;
	if(script == undefined) {
		script = 'html';
	}
  //  $('#ajaxdata').html("");
    $.post(url + "ajax-1/" , {},  function(data) {
        $('#ajaxdata').html(data);
        openDefDialog();
    }, script);
}

function buttonSend2(sender, url) {

  dialog1 = $("#"+sender);

  if(dialog1) {
    dialog1.dialog('close');
    dialog1.dialog('destroy');
  }

  // buttonsUnbind();
 //   buttonsUpdate();

    $.post(url + "ajax-1/" , {},  function(data) {
        $('#ajaxdata').html(data);
        openDefDialog();
    });
}
/**
  host - хост,
  action - действие,
  varNum - индекс глобальной переменной listVars
  isOpenDialog - выполнить Ajax и открыть диалог или перезагрузить стр. (false | true)
*/
function buttonSendClick(host, action, varNum, isOpenDialog) {
    if(!isNaN(varNum)) {
      if(listVars[varNum].id > 0) {
        url = host + action + '-' +  listVars[varNum].id+'/';
        if(isOpenDialog) {
          url = url + "ajax-1/";
          $.post(url, {},  function(data) {
                $('#ajaxdata').html(data);
                openDefDialog();
          });
        } else {
          location.replace(url);
        }
        }
    }
}

function enableButtonSet(setNum) {
  if(setNum > 0) {
    set = document.getElementById("buttonSet"+setNum);
    if (set) {
      set.setAttribute("style","display: block;");
      set.className = "buttonSetTable";
    }
  }
}


function openDefDialog(dialog_id) {
//	buttonsUpdate();

	if(dialog_id == undefined) {
		dialog_id = 'ajaxdata';
	}
	dialog_id = 'ajaxdata';
	var oDialog = '#'+dialog_id;
//	if (document.getElementById(dialog_id)) oDialog = $('#'+dialog_id);

	
		// if (!oDialog) oDialog = $('#'+dialog_id);
		$(oDialog).dialog({
			height:    'auto',
			width: 'auto',
			modal: true,
			buttons: {
			'Ok': function () {
				
		},
			   'cansel': function () {
                 $(this).dialog('close');
               }
			}
		});
		$(oDialog).dialog('open');
		$(oDialog).css("z-index",1100);

	
}

var FilterWait = false;
var FilterTimer = undefined;

var Filter_host = undefined;
var Filter_fromId = undefined;
var Filter_backID = undefined;
var FilterKey = 0;

function FilterKeyUP() {
	// FilterTimer = setTimeout('');
	FilterKey++;
	FilterTimer = setTimeout('FilterSendByTimer('+FilterKey+')', 200);
}

function FilterSendByTimer(_FilterKey) {
	if(FilterKey == _FilterKey) {
		FilterSend();
	}
}

function sendFilter(_host, _fromId, _backID) {
	Filter_host = _host;
	Filter_fromId = _fromId;
	Filter_backID = _backID;

	FilterKeyUP();
}

function FilterSend() {
	host = Filter_host;
	fromId = Filter_fromId;
	backID = Filter_backID;

	var str = $("#"+fromId).serialize();
	next = false;
	i = 0;
	$(":text").each(function (i) {
	        if($(this).val().length > 2) {
	            next = true;
	            i++;
	        }
	  });

	if(!next && i > 0) return false;

	 var loading = document.getElementById("loading");
	 loading.className="load_vis";

	LoadingDisplay(1);
	//alert(str);
	//return false;
	 $.ajax({
	   type: "POST",
	   url: host,
	   data: str,
	   success: function(data){
	     $('#'+backID).html(data);
	        //f_fio.disabled = "";
	        loading.className="load_hide";
	        LoadingDisplay(2);
	   }
	 });

     Filter_host = undefined;
	 Filter_fromId = undefined;
	 Filter_backID = undefined;
	    /*
	    var f_fio = document.getElementById("f_fio");
	    var f_block = document.getElementById("f_block");
	    var f_cell = document.getElementById("f_cell");

	    // var backID = document.getElementById(backID);
	    var url = "";

	    if (f_fio && f_block && f_cell) {
	      // f_fio.disabled = "yes";
	      loading.className="load_vis";
	    }
	   */
	  //  data = { 'f_fio':f_fio.value, 'f_block':f_block.value, 'f_cell':f_cell.value, 'ajax':1 };

	  /*  $.post(host + url  , data,  function(data) {
	        $('#'+backID).html(data);
	        //f_fio.disabled = "";
	        loading.className="load_hide";
	    });
	    */

}

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 getBodyScrollTop()
{
	return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

function getBodyScrollLeft()
{
	return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}

//Размер документа по вертикали
function getDocumentHeight()
{
	return (document.body.scrollHeight > document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight;
}

//Размер документа по горизонтали
function getDocumentWidth()
{
	return (document.body.scrollWidth > document.body.offsetWidth)?document.body.scrollWidth:document.body.offsetWidth;
}

function getClientCenterX()
{
	return parseInt(getClientWidth()/2)+getBodyScrollLeft();
}

function getClientCenterY()
{
	return parseInt(getClientHeight()/2)+getBodyScrollTop();
}



function LoadingDisplay(type) {
    ld = document.getElementById("LoadingDisplay");
    ldgif = document.getElementById("LoadingDisplayGIF");
    if(ld) {
        if(type == 1) {
          /* показать */
          ld.className = "ui-widget-overlay";
          ld.setAttribute("style","position:absolute;display: block;z-index: 1001;top:0;left:0;width:"+getDocumentWidth()+"px;height:"+getDocumentHeight()+"px;");
          ldgif.setAttribute("style","position:absolute;top:"+(getClientCenterY()-117)+"px;left:"+(getClientCenterX()-117)+"px;");
          ldgif.focus();
        }
        if (type == 2) {
                 //return;
          /* скрыть */
          ld.top = 0;
          ld.left = 0;
          ld.width =  getDocumentWidth() ;
          ld.height =  getDocumentHeight() ;
          ld.setAttribute("style","display: none;z-index: 0;");
        }
    }
}
/********************************************************************************************/

function DialogButtonClick1(dialog_id, input_name) {
	var cXML = ''; 
	var cHide = ''; 
	var a = ''; 
	var i = 0;

	 dlg = document.getElementById(dialog_id);
	 boxes = dlg.getElementsByTagName('input');
	for(i=0;i<boxes.length;i++) {
		ch = i;
if(boxes[ch].type != 'checkbox') continue;
		if (boxes[ch].checked) {

			var chV = document.getElementById('l_'+boxes[ch].id);
			if(chV) {
				cXML+= a+ chV.title; 
				cHide+= a + boxes[ch].value;
			
			a=';';
			}
			//i++;
		}
	}

	$('#'+input_name+'xml').val(cXML);  
	$('#'+input_name).val(cHide);

}

function DialogButtonClickByPOLT(dialog_id, input_name) {
	var cXML = ''; 
	var cHide = ''; 
	var a = ''; 
	var i = 0;

	dlg = document.getElementById(dialog_id);
	boxes = dlg.getElementsByTagName('input');
	//boxes = dlg.getElementsByTagNameNS(namespaceURI, localName)('input');
	var ch = -1;
	for(i=0;i<boxes.length;i++) {	
		ch++;
		if(boxes[ch].type != 'checkbox') continue;
		if (boxes[ch].checked) {

			var chV = document.getElementById('l_'+boxes[ch].id);
			//alert('l_'+boxes[ch].id);
			if(chV) {
				// var atr = chV.title;
				cXML+= a+ chV.title; 
				cHide+= a + boxes[ch].value;

				a=';';
			}
			//i++;
		}
		
	}

	$('#'+input_name+'xml').val(cXML);
	$('#'+input_name).val(cHide);
// alert('#Dialog'+'ajaxdata'+'_'+input_name);
	$('#Dialogajaxdata_'+input_name).hide();
	$('#dialogBgWrap').hide();
}

function buttonSend_K(url, _dialog_id, _input_name) {
    $('#ajaxdata').html("");
    $.post(url + "ajax-1/" , {},  function(data) {
        $('#ajaxdata').html(data);
        openDefDialog_K(_dialog_id, _input_name);
    });
    dialog_id = undefined;
    input_name = undefined;
}

/* Инициализация диалогов */
function dialogINIT() {

	var rootElement = document.getElementById("dialogs");
	var main_bar = document.getElementById("dialogWrap");
	var main_bg = document.getElementById("dialogBgWrap");	
	var adElement = document.createElement('div');

	if(!main_bar) {
		adElement.setAttribute("id", "dialogWrap");				
		rootElement.appendChild(adElement);			
		main_bar = document.getElementById("dialogWrap");				

		var adElement = document.createElement('div');
		adElement.setAttribute("id", "dialogBgWrap");
		rootElement.appendChild(adElement);
		main_bg = document.getElementById("dialogBgWrap");	
	}

	main_bg.style.display = "none";
	main_bg.style.zIndex = "0";

	main_bg.style.position = "absolute";
	main_bg.style.top = "0";
	main_bg.style.left = "0";
	main_bg.style.width = (getDocumentWidth()) + "px";
	main_bg.style.height = (getDocumentHeight()) + "px";          
	main_bg.style.backgroundColor = "#bdbdbd";
	main_bg.style.display = "block";
	main_bg.style.zIndex = "990";
	main_bg.style.opacity= 0.5;
	if(window.navigator.appName == 'Microsoft Internet Explorer') {
		main_bg.style.filter = 'alpha(opacity=' + 30 + ')';
		//main_bg.filters.alpha.opacity = 0.5;
		//main_bg.filter = "alpha(opacity=" + 0.5 + ")";
	}	
}

function showDialogBG() {
	var main_bg = document.getElementById("dialogBgWrap");
	
	main_bg.style.position = "absolute";
	main_bg.style.top = "0";
	main_bg.style.left = "0";
	main_bg.style.width = (getDocumentWidth()) + "px";
	main_bg.style.height = (getDocumentHeight()) + "px";          
	main_bg.style.backgroundColor = "#bdbdbd";
	main_bg.style.display = "block";
	main_bg.style.zIndex = "990";
	main_bg.style.opacity= 0.5;
	if(window.navigator.appName == 'Microsoft Internet Explorer') {
		main_bg.style.filter = 'alpha(opacity=' + 30 + ')';
	}	
}

function showDialog(id) {
	
}

function openDialogByPOLT(_url,_dialog_id, _input_name, _title) {		
	/* Инициализация */
	dialogINIT();
	showDialogBG();
	
	/* Поиск контейнера диалогового окна */
	var main_bar = document.getElementById("dialogWrap");		
	var Dialog = document.getElementById("Dialog"+_dialog_id+'_'+_input_name);
	var dialogContent = document.getElementById("dialogContent"+_dialog_id+'_'+_input_name);
	
	var isExists = false;		
	
	if(Dialog == undefined) {		               
		var adElement = document.createElement('div');
		adElement.setAttribute("id", "Dialog"+_dialog_id+'_'+_input_name);				
		main_bar.appendChild(adElement);			
		Dialog = document.getElementById("Dialog"+_dialog_id+'_'+_input_name);

		/* Добавление Строки заголовка */
		var adElement = document.createElement('p');
		adElement.setAttribute("id", "dialogWrapClose_"+_input_name);      
		adElement.style.padding = "5px";
		//adElement.style.width = "16px";
		adElement.style.height = "16px";
		//adElement.style.background = "transparent url(/images/close.png) no-repeat scroll 0 0";
		adElement.style.backgroundColor = '#8375B0';
		adElement.style.color = '#FFFFFF';
		adElement.style.fontWeight = 'bold';
		adElement.style.zIndex = "999";
		adElement.style.display = "block";    
		adElement.innerHTML = 'Заголовок';
		
		//adElement.setAttribute("onclick", "closeDialogByP('"+"Dialog"+_dialog_id+'_'+_input_name+"')");
		//adElement.onClick =  "closeDialogByP('Dialog"+_dialog_id+"_"+_input_name+")";
		// adElement.
		CloseNode = Dialog.appendChild(adElement);
//		CloseNode.onClick =  "closeDialogByP('Dialog"+_dialog_id+"_"+_input_name+")";
		
		var adElement2 = document.createElement('div');
		adElement2.setAttribute("id", "dialogContent"+_dialog_id+'_'+_input_name);				
		Dialog.appendChild(adElement2);			
		dialogContent = document.getElementById("dialogContent"+_dialog_id+'_'+_input_name);				
	  // alert(Dialog.innerHTML);
		Dialog.style.display = "none";
		
		Dialog.style.zIndex = "0";
		dialogContent.className = 'dialogContent';		
		dialogContent.innerHTML = "";		

		       

	} else {
		isExists = true;
	}
	    
	 
	
	if(!isExists) {	
		$.post(_url + "ajax-1/mode-filter/" , {},  function(data) {
			$('#ajaxdata').html(data);

			
			var ajaxData = document.getElementById("ajaxdata");
			var dialog_title = document.getElementById('dialog_title');						
			
			dialogContent.innerHTML = ajaxData.innerHTML;			
			ajaxData.innerHTML = '';
			if(dialog_title != undefined) adElement.innerHTML = dialog_title.innerHTML ; else alert('dialog_title :(');			
			
			$("#btns_"+_input_name).click(function(){											   	
				$(".tb_"+_input_name+" INPUT").each(	function(){ 	$(this).attr("checked", "checked");	})	});
			$("#btnc_"+_input_name).click(function(){											   	
				$(".tb_"+_input_name+" INPUT").each(	function(){ 	$(this).removeAttr("checked", "checked");	})	});
			
						   		
			showDialogBG();
			/*
			if(window.navigator.appName == 'Microsoft Internet Explorer') {
				var clNode = ajaxData.cloneNode(true);
				x=clNode.childNodes;
				for (i=0;i<x.length;i++)
				{
					if (x.item(i).nodeType==1)
					{
						alert(i+' : '+x.item(i).innerHTML);
						main_bar.appendChild(x.item(i));
					}
				} 								
			} else {
				main_bar.innerHTML = ajaxData.innerHTML;
			}
			*/
			// ajaxData.innerHTML = "";

			Dialog.className = 'Dialog';
			Dialog.style.position = "absolute";
			Dialog.style.top = "10%";
			Dialog.style.left = (getClientCenterX() - 100) + "px";
			// main_bar.style.maeginLeft = "-100px";
			Dialog.style.width = "250px";
			// main_bar.style.height = (getClientCenterX() - 100) + "px";;
			//Dialog.style.backgroundColor = "#bdbdbd";
			//Dialog.style.padding = "3px";
			//Dialog.style.border = "1px solid #FAFAFA";		
			Dialog.style.display = "block";
			Dialog.style.zIndex = "991";			

			DialogAccept(_input_name);
		});

		
		
	} else {		
		showDialogBG();
		
		Dialog.style.position = "absolute";
		Dialog.style.top = "10%";
		Dialog.style.left = (getClientCenterX() - 100) + "px";
		// main_bar.style.maeginLeft = "-100px";
		Dialog.style.width = "250px";
		// main_bar.style.height = (getClientCenterX() - 100) + "px";;
		//Dialog.style.backgroundColor = "#bdbdbd";
		//Dialog.style.padding = "3px";
		//Dialog.style.border = "1px solid #FAFAFA";		
		//Dialog.style.display = "block";
		Dialog.style.zIndex = "991";
		Dialog.style.display = "block";
		// alert(isExists);
		
	}	
    
}

function closeDialogByP(_dialog) {	
	var Dialog = document.getElementById(_dialog);
	var main_bg = document.getElementById("dialogBgWrap");
	// alert(_dialog);
	if(Dialog != undefined) {
		
		Dialog.style.display = "none";
		//Dialog.style.zIndex = "0";
		//  main_bar.innerHTML = "";
		
		main_bg.style.display = "none";
		//main_bg.style.zIndex = "0";
		// main_bg.innerHTML = "";
	}
	
}

function openDefDialog_K(_dialog_id, _input_name) {
	// buttonsUpdate();
	var o = false;
	

	$(function() {
	  o = $("#ajaxdata");
			$(o).dialog({
				height:    'auto',
	            width: 'auto',
				modal: true,
	           // top: 10
				buttons: {
					'Ok': function() {
				DialogButtonClick1(_dialog_id, _input_name);
				
						$(this).dialog('close');
						$(this).dialog('destroy');
					},
					'Отмена': function() {
						$(this).dialog('close');
						$(this).dialog('destroy');
					}
				}  
			});
	        $(o).dialog('open');
	        $(o).css("z-index",1100);

		});
	}

function hormenuClick(link) {
	  $("div.content").hide();
	  target = $("div.content");

		var image;
		image="/images/zoomloader.gif";

	  if(!document.getElementById('zoomloader')) {
		//alert(1);
				var jNode=$('<div id="zoomloader" style="-moz-opacity:0.8;opacity:0.8;filter:alpha(opacity=80);color:#333;font-size:12px;font-family:Tahoma;'
					+'text-align:center;background-image:url('+image+');position:absolute;background-color:#FFFFFF;border: 1px solid;'
					+'background-repeat:no-repeat;background-position:43px 30px;width:100px;height:55px;z-index:999;'
					+'">Загрузка...</div>').appendTo("body");
	  } else {
		//  alert(2);
		  var jNode = $("#zoomloader");
		  $(jNode).show();
	  }
				var t='50%'/*parseInt(this.target.offset().top+(this.target.height()-jNode.height())/2);*/
			   	//var l=parseInt(this.target.offset().left+(this.target.width()-jNode.width())/2);
	            var l = "40%"
				jNode.css({top:t,left:l,display:'block'})

	  if (link != "") {
//	    alert(link);
	    window.location = link;
	  }
	}

    function hormenuClick2(id) {
	  $("div.content").hide();
	  target = $("div.content");

		var image;
		image="/images/zoomloader.gif";

	  if(!document.getElementById('zoomloader')) {
		//alert(1);
				var jNode=$('<div id="zoomloader" style="-moz-opacity:0.8;opacity:0.8;filter:alpha(opacity=80);color:#333;font-size:12px;font-family:Tahoma;'
					+'text-align:center;background-image:url('+image+');position:absolute;background-color:#FFFFFF;border: 1px solid;'
					+'background-repeat:no-repeat;background-position:43px 30px;width:100px;height:55px;z-index:999;'
					+'">Загрузка...</div>').appendTo("body");
	  } else {
		//  alert(2);
		  var jNode = $("#zoomloader");
		  $(jNode).show();
	  }
				var t='50%'/*parseInt(this.target.offset().top+(this.target.height()-jNode.height())/2);*/
			   	//var l=parseInt(this.target.offset().left+(this.target.width()-jNode.width())/2);
	            var l = "40%"
				jNode.css({top:t,left:l,display:'block'})

document.getElementById(id).submit();

	}

function DocLoad() {
  /*	var contentWrap = document.getElementById('contentWrap');
	
	if(contentWrap) {
		// alert(contentWrap.style.height);
		var dx = 47;
		if(window.navigator.appName == 'Microsoft Internet Explorer') { dx = 85; }
		contentWrap.style.height = (getClientHeight() - (112 + 32 +   dx )) + "px";
		

		
		// alert(contentWrap.style.height);
		// contentWrap.style.
		// alert(getDocumentHeight() - (112 + 32 + 80 + 50));
	}     */
}

function filterByCheckBox () {
	
}



function DialogAccept(prefix) {			
	
	
	
	$(function() {
		 var theTable = $('table.tb_'+prefix);
		 
		if(!document.getElementById("filter"+prefix)) alert("filter"+prefix+' :(');
		if(!document.getElementById('filter-form'+prefix)) alert('filter-form'+prefix+' :(');
		if(!theTable) alert('theTable :(');
		
		 
		  

		  theTable.find("tbody > tr").find("td:eq(1)").mousedown(function(){
		    $(this).prev().find(":checkbox").click();
		    
		  });

		  $("#filter"+prefix).keyup(function() {
			  // alert('ok');
		    $.uiTableFilter( theTable, this.value );
		    
		  })

		  $('#filter-form'+prefix).submit(function(){
		    theTable.find("tbody > tr:visible > td:eq(1)").mousedown();
		    return false;
		  }).focus(); //Give focus to input field
		});
}
/******************************************************************************************************************/

function newElement(tag, _id, _class, _style, _text) {
	var nElement = document.createElement(tag);
	if(_id != '') nElement.setAttribute("id", _id);
	if(_style != '') nElement.setAttribute("style", _style);
	if(_text != '') {
		var nText = document.createTextNode(_text);
		nElement.appendChild(nText);
	}
	return nElement;
}

function newInputText(_id, _name, _value) {
	var Input = newElement('input', _id, '', '', '');
	Input.setAttribute("name", _name);
	if(_value != '') Input.setAttribute("value", _value);
	return Input;
}

function newInputSelect(SelectData, DefVal, AttrId, AttrName) {
	var sel = newElement('select', AttrId, '', '', '');
	sel.setAttribute("name", AttrName);
	for(op in SelectData) {
		var sop = newElement('option', AttrId, '', '', op.caption);
		sop.setAttribute("value", op.value);
		sel.appendChild(sop);
	}
	return sel;
}

function newTDInputText(_id, _name, _value) {
	var TD = newElement('td',  '', '', '', '');
	var Inp = newInputText(_id, _name, _value);
	TD.appendChild(Inp);
	return TD;
}

function newTDInputSelect(_id, _name, _value, SelectData) {
	var TD = newElement('td',  '', '', '', '');
	var Inp = newInputSelect(SelectData, 0,_id, _name);
	TD.appendChild(Inp);
	return TD;
}



function addServices(table_id,prefix) {
	var tb = document.getElementById(table_id);
	if (tb) {
		var TR = newElement('tr', '', '', '', '');
		TR.appendChild(newTDInputSelect(prefix+'_type_id_'+RefBook_INDEX[table_id], prefix+'['+RefBook_INDEX[table_id]+'][type_id]', '', RefBookData[table_id]));
		TR.appendChild(newTDInputText(prefix+'_cost_'+RefBook_INDEX[table_id], prefix+'['+RefBook_INDEX[table_id]+'][cost]', ''));
		TR.appendChild(newTDInputText(prefix+'_isFree_'+RefBook_INDEX[table_id], prefix+'['+RefBook_INDEX[table_id]+'][isFree]', ''));
	}
}

var TURIST_INDEX = 2;

function addTurist2() {
	var turists = document.getElementById('turists');
	if (turists) {
		var TR = newElement('tr', '', '', '', '');
		TR.appendChild(newTDInputText('turist_name_'+TURIST_INDEX, 'turist['+TURIST_INDEX+'][fio]', ''));		
		TR.appendChild(newTDInputText('turist_bday_'+TURIST_INDEX, 'turist['+TURIST_INDEX+'][bday]', ''));
		TR.appendChild(newTDInputText('turist_pasport_'+TURIST_INDEX, 'turist['+TURIST_INDEX+'][passport]', ''));
		TR.appendChild(newTDInputText('turist_pday_'+TURIST_INDEX, 'turist['+TURIST_INDEX+'][passport_end]', ''));
		turists.appendChild(TR);
		TURIST_INDEX++;
	}
}

var ROOM_INDEX = 2;

function addRooms() {
	var rooms = document.getElementById('rooms');
	if (rooms) {
		var TR = newElement('tr', '', '', '', '');
		TR.appendChild(newTDInputText('room_type_'+ROOM_INDEX, 'room['+ROOM_INDEX+'][room_name]', ''));
		rooms.appendChild(TR);
		ROOM_INDEX++;
	}
}

function newdoc(id, pref, to_id) {
	var EFrom = document.getElementById(pref+id);
	var ETo = document.getElementById(to_id);
	if(EFrom && ETo) {
		var tds = EFrom.getElementsByTagName('td');
		var tdsTo = ETo.getElementsByTagName('td');		
		// удаляем страрые TD
		/*
		len = tdsTo.length;
		for(i=0;i<len;i++) {		
			ETo.removeChild(tdsTo[i]);
		}	
		*/
		ETo.innerHTML='';
		// добавляем новые TD
		for(i=0;i<tds.length;i++) {
			var nd = tds[i].cloneNode(true);
			ETo.appendChild(nd);
		}
	}
	return true; 
}
/******************************************************************************************************************/
