	var CORRECT_EXIT=0;
	var allwins='ALLOPENWINDOWS';

	var isIE = window.navigator.userAgent.indexOf("MSIE")>-1;
	var GlassWindow=false;
	var WaitWindow=false;

	function convertTrueTo1(isTrue){
		if(isTrue){return 1;}
		else{return 0;}
	}


	function loadJSDataPOST(URL,FORMID,postfunction) {
		//ShowGlassWindow(true);
		new Ajax.Request( URL, 
				{ method: 'post',
				  parameters: $(FORMID).serialize(true),
				  onComplete: function(transport) {
					 	var response = transport.responseText;		
						eval(response);
						eval(postfunction);
						//ShowGlassWindow(false);
				},
				  onFailure: function(resp){
				  		alert('Failure in getting data');
						//ShowGlassWindow(false);
				}
		});
	}

	function loadJSData(URL,postfunction) {
		//ShowGlassWindow(true);
		new Ajax.Request( URL, 
				{ method: 'get',
				  onComplete: function(transport) {
					 	var response = transport.responseText;		
						eval(response);
						eval(postfunction);
						//ShowGlassWindow(false);
				},
				  onFailure: function(resp){
				  		alert('Failure in getting data');
						//ShowGlassWindow(false);
				}
		});
	}

	function ShowWaitWindow(show){
		if(!WaitWindow){
			// на первом проходе создаем элемент - "полупрозрачный экран"
			WaitWindow=document.createElement('DIV');
			with(WaitWindow.style){
				display='none';
				position='absolute';
				height=0;	
				width=0;	
				zIndex=9999;
				if(isIE){
					backgroundColor = 'red';
					filter="progid:DXImageTransform.Microsoft.Alpha(Opacity=40, Style=0)";
				}
				else{
					backgroundImage = 'url(/gifs/alfa40-fon.png)';
				}
				//WaitWindow.innerHTML='<div align=center><br><br><br><img src=/gifs/crocodile.gif align=center><br><br><br>Wait please, the page is loading...</div>';
			}
			document.body.appendChild(WaitWindow);
		}

		if(show){
			with(WaitWindow.style){
				left = 0;
				top = document.body.scrollTop;
				width = document.body.clientWidth;
				height = document.body.clientHeight;
			}
		}
		WaitWindow.style.display=show?'block':'none';
	}


	function ShowGlassWindow(show){
		if(!GlassWindow){
			// на первом проходе создаем элемент - "полупрозрачный экран"
			GlassWindow=document.createElement('DIV');
			with(GlassWindow.style){
				display='none';
				position='absolute';
				height=0;	
				width=0;	
				zIndex=9998;
				if(isIE){
					backgroundColor = '#FFFFFF';
					filter="progid:DXImageTransform.Microsoft.Alpha(Opacity=40, Style=0)";
				}
				else
					backgroundImage = 'url(/gifs/alfa40-fon.png)';
			}
			document.body.appendChild(GlassWindow);
		}

		if(show){
			with(GlassWindow.style){
				left = 0;
				top = document.body.scrollTop;
				width = document.body.clientWidth;
				height = document.body.clientHeight;
			}
		}
		GlassWindow.style.display=show?'block':'none';
	}



	function show_lnk_txt_field(formname,field,edit_disabled,nname,postfunction,fonchangefunction){
		script='/ctools/show_lnk_txt_field.phtml?formname='+formname+'&field='+field+'&edit_disabled='+edit_disabled+'&nname='+nname+'&postfunction='+postfunction+'&fonchangefunction='+fonchangefunction;
		txt_field=openwin(script,'txt_field'+field,440,240);
	}


	function preview_field(formname,field,phpfunction){
		script='/ctools/preview_field.phtml?formname='+formname+'&field='+field+'&phpfunction='+phpfunction;
		txt_field=openwin(script,'preview_field'+field,640,440,1);
	}


	function preview_PHP_function(phpfunctionwithargs){
		script='/ctools/preview_PHP_function.phtml?phpfunctionwithargs='+phpfunctionwithargs;
		txt_field=openwin(script,'preview_PHP'+getRanName(),640,440,1);
	}


	function thisClose(win){
		var argv = thisClose.arguments;
		var argc = thisClose.arguments.length;
		var ifClose = (argc > 1) ? argv[1] : false;
		if(ifClose && ifClose==1){win.close();}
	}


	function getRanName(){
		DD=new Date();
		str=DD.getTime();
		return(str);
	}

	function openwin(href,name,w,h){
		var argv = openwin.arguments;
		var argc = openwin.arguments.length;
		var scrollview=(argc > 4) ? ',scrollbars='+argv[4] : '';
		var menuview=(argc > 5) ? ','+argv[5] : '0';
		//name=window.open(href,name,'width='+w+',height='+h);
		name=window.open(href,name,'width='+w+',height='+h+',menubar='+menuview+',resizable=1,status=0,toolbar=0,location=0'+scrollview);
		name.focus();
		//currentwins=getCookie(allwins);
		//currentwins=currentwins+' '+name.name;
		//setCookie(allwins,currentwins);
		return name;
	}


	function openmodalwin(href,name,fValues,w,h){
		name=window.showModalDialog(href,fValues,'dialogHeight: '+h+'px; dialogWidth: '+w+'px; edge: Raised; border=thin; center: Yes; help: No; resizable: Yes; status: No;');
		return name;
	}

        function fmodalclose(cProp){ 
	        window.returnValue=cProp;
	        event.returnValue=false;
	        window.close();
        }

	function wailtpls(frame){
		doc=frame.document;
		doc.open();		
		doc.write(
		'<link href=/css/search.css type=text/css rel=stylesheet>'+
		'<body class=FRAME1>'+
		'<br>'+
		'<center>'+
		'<img src=/gifs/crocodile.gif>'+
		'<br><br>'+
		'Пожалуйста, подождите ...'+
		'</body>'
		);
		doc.close();
	}

	function wait_pls(win,windetails){
		doc=win.document;
		doc.open();
		doc.write('<link href=/css/card.css type=text/css rel=stylesheet>'+
			 '<body class=MAIN><center><br><br>Минуточку ...');
		doc.close();

		
		if(doc=windetails.document){
			doc.open();
			doc.write('<body bgcolor=lightyellow>');
			doc.close();
		}
	}

	function ShowHelp(page){
	help=window.open('','help','width=700,height=500,scrollbars=auto,resizable=1');
	help.location.href='/help/help.phtml?page='+page;
	help.focus();
	}

	function setCorrectExit(){
		CORRECT_EXIT=1;
	}

	function getCorrectExit(){
		if(CORRECT_EXIT==1){return true;}
		else{return false;}
	}

	

	function fBeforeClose(EDIT_VALUE){
	if(EDIT_VALUE=='save' && CORRECT_EXIT==0){
		event.cancelBubble = true;
		event.returnValue = 'Вы не сохранили последние изменения, внесенные в карточку.\\nНажмите Сохранить или Отмена, в противном случае карточка будет заблокирована.';
		return false;
	}
	}


	function fClose(EDIT_VALUE,id,CardType,JrnID,ifnew){
	if(EDIT_VALUE=='Save' && CORRECT_EXIT==0){
		script='../tools/incorrect_exit.phtml?CardType='+CardType+'&id='+id;
		if(CardType=='paper'){
		script=script+'&JrnID='+JrnID+'&ifnew='+ifnew;
		}
		opener.parent.frames['_invisible'].location=script;
	}
	}


	function nocontextmenu(){
	if(DOM && IE){
		//event.cancelBubble = true;
		//event.returnValue = false;
	}
	return false;
	}


	//document.oncontextmenu = nocontextmenu; 	// Zapret na vivod standartnogo menu IE 



	function ViewAsDisabled(formname){
		ElementsLength=formname.elements.length;
		for(el=0;el<ElementsLength;el++){
			elem=formname.elements[el];
			if(elem.disabled==1){elem.style.color='gray';}
		}
	}


	function DisableButtons(formname){
	ElementsLength=formname.elements.length;
		for(el=0;el<ElementsLength;el++){
		ElType=myform.elements[el].type;
			if(ElType=='button' || ElType=='submit' || ElType=='reset'){
				myform.elements[el].disabled=1;
			}
		}
	}




	function KeyPressEvent(e){	
		e = e || window.Event || window.event;
		key=e.which || e.keyCode;
		switch(key){
			case 13:
				fsubmit();
				break;
		}

	}


	function getCookieVal(offset){
		var endstr=document.cookie.indexOf(';',offset);
		if (endstr == -1)
		endstr=document.cookie.length;
		return unescape(document.cookie.substring(offset,endstr));
	}
          
	function getCookie(name){
		var arg=name+'=';
		var alen=arg.length;
		var clen=document.cookie.length;
		var i=0;
		while(i < clen){
			var j=i+alen;
			if(document.cookie.substring(i,j)==arg){return getCookieVal(j);}
			i=document.cookie.indexOf(' ',i)+1;
			if(i==0) break;
		}
		return '';
	}

	function setCookie(name,value){
		var argv = setCookie.arguments;
		var argc = setCookie.arguments.length;
		var expires = (argc > 2) ? argv[2] : null;
		var path = (argc > 3) ? argv[3] : null;
		var domain = (argc > 4) ? argv[4] : null;
		var secure = (argc > 5) ? argv[5] : false;
		document.cookie = name + '=' + escape (value) +
		((expires == null) ? '' : ('; expires=' + expires.toGMTString())) +
		((path == null) ? '' : ('; path=' + path)) +
		((domain == null) ? '' : ('; domain=' + domain)) +
		((secure == true) ? '; secure' : '');
	}
                              

	function changeDisplayMode(eItem){
		if(document.getElementById(eItem).style.display=='none'){
			document.getElementById(eItem).style.display='';
		}
		else{
			document.getElementById(eItem).style.display='none';
		}

	}



	function getBodySize() {
	  var w = 0, h = 0;
	  if (typeof(window.innerWidth) == 'number' ) {
	    //Non-IE
	    w = window.innerWidth;
	    h = window.innerHeight;
	  }
	  else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
	    //IE 6+ in 'standards compliant mode'
	    w = document.documentElement.clientWidth;
	    h = document.documentElement.clientHeight;
	  }
	  else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
	    //IE 4 compatible
	    w = document.body.clientWidth;
	    h = document.body.clientHeight;
	  }
	  return {width: w, height: h};
	}

 
	function getBodyScroll(){
	  var t = 0, l = 0;
	  t = self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
	  l = self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
	  return {top: t, left: l};
	}
 



