//if(!__AJAX_request_counter_set){
	var __AJAX_request_counter = 0;
//	__AJAX_request_counter_set = true;
//}
	var __LookupTimeout;
	var __LookupShown;

function domFilterShow(obj){
	var i = __LookupShown++%2+1;
	obj.className='row'+i;
	if(BrowserDetect.browser == 'Explorer' && BrowserDetect.version < 8)
		obj.style.display='inline';
	else
		obj.style.display='table-row';
}

function changeVisible(id){
   element = document.getElementById(id);
   if(element.style.display=='')
      element.style.display='none';
   else
      element.style.display='';
}

function GetYof(obj) {
   var y = 0;
   while ( obj.offsetParent != null) {
      y += obj.offsetTop;
      obj = obj.offsetParent;
   }
   y += obj.offsetTop;

   return y;
}

function GetXof(obj) {
   var x = 0;
   while ( obj.offsetParent != null) {
      x += obj.offsetLeft;
      obj = obj.offsetParent;
   }
   x += obj.offsetLeft;

   return x;
}

function domFilterIter(list,iter,count,val){
    clearTimeout(__LookupTimeout);
    var oRow = list.item(iter);
    if(val != ''){
        eval('var p = /'+val+'/i');
        if(!p.test(oRow.id)) {
			if(oRow.style)oRow.style.display='none';
		}
        else domFilterShow(oRow);//.style.display='inline';
    }else domFilterShow(oRow);//oRow.style.display='inline';

    if(iter<count-1)
        __LookupTimeout = setTimeout(function(){domFilterIter(list,iter+1,count,val)}, 10);
}

function domFilter(filterobj,listtable){
    clearTimeout(__LookupTimeout);
    __LookupShown = 0;
    var oTable = document.getElementById(listtable);
    var oSrc = document.getElementById(filterobj);
    __LookupTimeout = setTimeout(function(){domFilterIter(oTable.rows,0,oTable.rows.length,oSrc.value)}, 10);
}

function ajaxDo(url,targetObj,meth,_append,beSilent){
    var cLocal = 'ajax_req'+(++__AJAX_request_counter);
    var silent = beSilent==true?'true':'false';
    var callBackFunc = "function(){AJAXAlter('"+targetObj+"','"+cLocal+"',"+_append+","+silent+");}";
    if (window.XMLHttpRequest){
    	eval("window."+cLocal+" = new XMLHttpRequest();");
		eval("window."+cLocal + ".onreadystatechange = "+callBackFunc+";");
		eval("window."+cLocal + ".open('"+meth+"', \""+url+"\", true);");
		eval("window."+cLocal +".send(null);");
	}else if (window.ActiveXObject){
		eval("window."+cLocal+" = new ActiveXObject(\"Microsoft.XMLHTTP\");");
		eval("if(window."+cLocal+"){"+
				"window."+cLocal+".onreadystatechange = "+callBackFunc+"; "+
				"window."+cLocal+".open('"+meth+"', \""+url+"\", true); "+cLocal+".send(); "+
			"}");
	}
}

function ajaxDoExecProgress(url,meth,targetObj){
    var cLocal = 'ajax_req'+(++__AJAX_request_counter);
    //var silent = beSilent==true?'true':'false';
    var callBackFunc = "function(){AJAXExecProgress('"+cLocal+"','"+targetObj+"');}";
    if (window.XMLHttpRequest){
    	eval("window."+cLocal+" = new XMLHttpRequest();");
		eval("window."+cLocal + ".onreadystatechange = "+callBackFunc+";");
		eval("window."+cLocal + ".open('"+meth+"', \""+url+"\", true);");
		eval("window."+cLocal +".send(null);");
	}else if (window.ActiveXObject){
		eval("var window."+cLocal+" = new ActiveXObject(\"Microsoft.XMLHTTP\"); ");
		
		eval("if(window."+cLocal+"){ "+
				"window."+cLocal+".onreadystatechange = "+callBackFunc+"; "+
				"window."+cLocal+".open('"+meth+"', \""+url+"\", true); "+cLocal+".send(); "+
			"}");
	}
}

function AJAXExecProgress(Areq,Atarget){
	eval("if($_(Atarget)) $_(Atarget).innerHTML = statA(window."+Areq+".readyState);");
/*	if($_(Atarget)) $_(Atarget).innerHTML = statA($_(Areq).readyState);
	
	if ($_(Areq).readyState == 4){
		if ($_(Areq).status == 200){ 
			if($_(Atarget)) $_(Atarget).innerHTML = '';
			eval($_(Areq).responseText);
		}else{ 
			if($_(Atarget)) $_(Atarget).innerHTML = '';
			alert('Не удалось выполнить запрос. Ошибка '+$_(Areq).status); 
		}
	}
		 */
    eval("if (window."+Areq+".readyState == 4){"+
    		"if (window."+Areq+".status == 200){ "+
				"if(document.getElementById('"+Atarget+"')) document.getElementById('"+Atarget+"').innerHTML = '';"+
    			"eval(window."+Areq+".responseText); "+
    		"}else{ "+
				"if(document.getElementById('"+Atarget+"')) document.getElementById('"+Atarget+"').innerHTML = '';"+
    			"alert('Не удалось выполнить запрос'); "+
    		"}"+
    	 "}");
}



function AJAXAlter(Atarget,Areq,doAppend,beSilent){
   var appendStr = doAppend!=false?"document.getElementById('"+Atarget+"').innerHTML +":'';
   if(!beSilent)
	eval("if(document.getElementById('"+Atarget+"')) document.getElementById('"+Atarget+"').innerHTML = "+appendStr+" statA("+Areq+".readyState);");

    eval("if (window."+Areq+".readyState == 4){"+
    		"if (window."+Areq+".status == 200){ "+
    			"document.getElementById('"+Atarget+"').innerHTML = "+appendStr+" window."+Areq+".responseText; "+
    		"}else{ "+
    			"document.getElementById('"+Atarget+"').innerHTML = "+appendStr+" '<b>Не удалось загрузить текст</b>'; "+
    		"}"+
    	 "}");
}

  function statA(n){
 	switch (n){
 		case 0:return "ОШИБКА: AJAX недоступен. Для работы Вам необходимо включить JavaScript";break;
        case 1:
        case 2:
        case 3:
        case 4://return "Загрузка данных: 100%";
			return '<center><img border=0 src="/images/wait16trans.gif"></center>';break;
        default:return "неизвестное состояние. Обратитесь в службу поддержки";break;
    }
 }

function AJAXAction(url, Ftarget, meth, req){
	loadXMLDocA(req, url,Ftarget,meth);
}

function ajaxDoExec(url,meth){
    var cLocal = 'ajaxreq'+(++__AJAX_request_counter);
    //var silent = beSilent==true?'true':'false';
    var callBackFunc = "function(){AJAXExec('"+cLocal+"');}";
    if (window.XMLHttpRequest){
    	eval(" window."+cLocal+" = new XMLHttpRequest();");
		eval(cLocal + ".onreadystatechange = "+callBackFunc+";");
		eval(cLocal + ".open('"+meth+"', \""+url+"\", true);");
		eval(cLocal +".send(null);");
	}else if (window.ActiveXObject){
		eval("window."+cLocal+" = new ActiveXObject(\"Microsoft.XMLHTTP\");");
		eval("if(window."+cLocal+"){"+
				"window."+cLocal+".onreadystatechange = "+callBackFunc+"; "+
				"window."+cLocal+".open('"+meth+"', \""+url+"\", true); "+cLocal+".send(); "+
			"}");
	}
}



function AJAXExec(Areq){
    eval("if (window."+Areq+".readyState == 4){"+
    		"if (window."+Areq+".status == 200){ "+
				"try{"+
					"eval(window."+Areq+".responseText); "+
				//	"alert(window."+Areq+".responseText); "+
				"}catch(e){"+
					"alert('Ошибка в ответе сервера: '+window."+Areq+".responseText);"+
				"}"+
    		"}else{ "+
    			"alert('Не удалось выполнить запрос'+window."+Areq+".status); "+
    		"}"+
    	 "}");
}

function $_(id){ return document.getElementById(id); }
function removeElement(id){	if(!$_(id)) return; var p = $_(id).parentNode; if(p) p.removeChild($_(id));}
function removeElementA(obj){	if(!obj)return; var p = obj.parentNode;p.removeChild(obj);}
function atoi(str) {var out = str+''; out=out.replace(/px/g,'');out.toInt;return out;}

var PW = function(){
	return{
		numbers: "1234567890",
		punctuation: "`~!@#$%^&*()_+=-,.<>/?[]{}\\|'\";:",
		lowercase: "abcdefghijklmnopqrstuvwxyz",
		uppercase: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
		contains: function (password, validChars) {
			var count = 0;
			for (i = 0; i < password.length; i++) {
				var char = password.charAt(i);
				if (validChars.indexOf(char) > -1) count++;
			}
			return count;
		},
		cap: function (number, max) {
			if (number > max) {
				return max;
			} else {
				return number;
			}
		},
		check: function (password) {
			var combinations = 0;
			if (this.contains(password, this.numbers) > 0) combinations += 10;
			if (this.contains(password, this.lowercase) > 0) combinations += 26;
			if (this.contains(password, this.uppercase) > 0) combinations += 26;
			if (this.contains(password, this.punctuation) > 0) combinations += this.punctuation.length;

			// work out the total combinations
			var totalCombinations = Math.pow(combinations, password.length);

			// work out how long it would take to crack this
			var timeInSeconds = (totalCombinations / 200) / 2;

			// this is how many days? (there are 86,400 seconds in a day.
			var timeInDays = timeInSeconds / 86400;

			// how long we want it to last
			var lifetime = 365;

			// how close is the time to the projected time?
			var percentage = timeInDays / lifetime;

			var friendlyPercentage = this.cap(Math.round(percentage * 100), 100);
			if ( friendlyPercentage < (password.length * 5)) {
				friendlyPercentage += password.length * 5;
			}
			var chcount = $_('pwcheck').children.length;
			
			for(var x = 0; x<chcount; x++){
				if(friendlyPercentage <= (x/chcount*100))
					$_('pwcheck').children[x].className = '';
				else
					$_('pwcheck').children[x].className = 'good';
			}
		}
	}
}();

function WFTime(sec) {
	var TMAMOUNT = [{k:'дн.',v:86400},{k:'ч',v:3600},{k:'м',v:60},{k:'с',v:1}];
	var ret = '';
	for(i in TMAMOUNT){
		if(sec < TMAMOUNT[i].v) continue;
		ret += Math.floor(sec / TMAMOUNT[i].v)+' '+TMAMOUNT[i].k+' ';
		sec %= TMAMOUNT[i].v;
	}
	return ret;
}

var UPn = function() {
	var startTime = null; 
	var interval;
	var curuplID = ''; var action = '';	var ifrSrc = '/progress'; var oStatus = 'status'; var oComment = ''; var oPercent = '';
	var oFileForm = ''; var oFileCont = ''; var debug = false;
	var ifr2 = null;
	var writeStatus = function(since,percent,est) {
		var comment;
		if(percent && percent < 99){
			comment = "Загрузка длится: "+WFTime(since)+". До конца осталось: "+WFTime(est);
		}else{
			if(!est && infoUpdated>0 || percent > 99){
				comment = "Загрузка закончена. Идёт обработка изображений. Пожалуйста, ждите...";
				percent = 100;
			}else
				comment = "Начинаем загрузку. Пожалуйста, подождите...";
		}
		$_(oComment).innerHTML = comment;
		if(!percent) percent = 1;		
		$_(oPercent).style.width = ''+percent+'%';
	}
	return {
		update: function(o){
			return o;
		},
		fetch: function() {
			var req;
			if (window.XMLHttpRequest){
				req = new XMLHttpRequest();
			}else if (window.ActiveXObject){
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			
			req.open("GET", ifrSrc, 1);
			req.setRequestHeader("X-Progress-ID", curuplID);
			req.onreadystatechange = function () {
				if (this.readyState == 4) {
					if (this.status == 200) {
						var upload = eval(this.responseText);
						if (upload.state == 'starting') {
							writeStatus(0,0,0);
						}
						if (upload.state == 'uploading') {
							UPn.updateInfo(upload);
						}
						if (upload.state == 'done') {
							window.clearTimeout(interval);
							writeStatus(0,0,0);
						}
					}
				}
			}
			req.send(null);
		},
		set: function(vals){
			if(vals){
				if(vals.action) action = vals.action;
				if(vals.source) ifrSrc = vals.source;
				if(vals.ostatus) oStatus = vals.ostatus;
				if(vals.ocomment) oComment = vals.ocomment;
				if(vals.opercent) oPercent = vals.opercent;
				if(vals.ofilecont) oFileCont = vals.ofilecont;
				if(vals.ofileform) oFileForm = vals.ofileform;
				if(vals.debug) {
					debug = vals.debug;
					if(ifr2 != null) ifr2.style.display = debug? 'block' : 'none';
				}
			}
		},
		init: function(){
			var ourDate = new Date( );
			curuplID = 'upl'+ourDate.getTime()+'_'+ourDate.getMilliseconds();

			if(ifr2 == null){
				ifr2 = document.createElement('iframe');
				ifr2.src = '';
				ifr2.id = 'ifr2';
				ifr2.name = 'ifr2';
				if(!debug) ifr2.style.display = 'none';
				$_(oFileForm).appendChild(ifr2);
				$_(oFileForm).target = 'ifr2';
			}
			
			UPn.start();
			$_(oFileForm).action = action+'&X-Progress-ID='+curuplID; 
			$_(oFileForm).submit(); 
			$(oFileCont).css('display','none');
		},
		start: function() {
			$_(oStatus).style.display='block';startTime = new Date();infoUpdated = 0;
			interval = window.setInterval( UPn.fetch , 1000 );
			writeStatus(0,0,0);
		},
		stop: function() {
			startTime = null;
			
			$_(oComment).innerHTML='Начинаем загрузку. Пожалуйста, подождите...';
			$_(oPercent).style.width='1px';
			$_(oStatus).style.display='none';
			$(oFileCont).css('display','block');
			$(oFileCont+' input[type=file]').attr('value','');
			//$(oFileCont+' input[type=text]').attr('value','');
		},
		updateInfo: function(upload) {
			var percent = upload.size?Math.round(upload.received / upload.size * 100):0;
			var secpast = Math.round((new Date() - startTime)/1000);
			if (startTime) {
				if (percent) {
					infoUpdated++;
					var estimatedSeconds = upload.received?Math.abs(Math.round(upload.size / upload.received * secpast)-secpast):0;
					writeStatus(secpast, percent , estimatedSeconds );
				} else {
					writeStatus(secpast, percent , 0 );
				}
			}
		}
	}
}();
var IUpload = UPn;

var UPurl = function() {
	var startTime = null; 
	var interval;
	var curuplID = ''; var action = '';	var ifrSrc = '/progress'; var oStatus = 'status'; var oComment = ''; var oPercent = '';
	var oFileForm = ''; var oFileCont = ''; var debug = false;
	var ifr2 = null;
	var writeStatus = function(since,percent,est) {
		var comment;
		if(percent && percent < 99){
			comment = "Загрузка длится: "+WFTime(since)+". До конца осталось: "+WFTime(est);
		}else{
			if(!est && infoUpdated>0 || percent > 99){
				comment = "Загрузка закончена. Идёт обработка изображений. Пожалуйста, ждите...";
				percent = 100;
			}else
				comment = "Начинаем загрузку. Пожалуйста, подождите...";
		}
		$_(oComment).innerHTML = comment;
		if(!percent) percent = 1;		
		$_(oPercent).style.width = ''+percent+'%';
	}
	return {
		fetch: function() {
			var req;
			if (window.XMLHttpRequest){
				req = new XMLHttpRequest();
			}else if (window.ActiveXObject){
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			
			req.open("GET", ifrSrc, 1);
			req.setRequestHeader("X-Progress-ID", curuplID);
			req.onreadystatechange = function () {
				if (this.readyState == 4) {
					if (this.status == 200) {
						var upload = eval(this.responseText);
						if (upload.state == 'starting') {
							writeStatus(0,0,0);
						}
						if (upload.state == 'uploading') {
							UPurl.updateInfo(upload);
						}
						if (upload.state == 'done') {
							window.clearTimeout(interval);
							writeStatus(0,0,0);
						}
					}
				}
			}
			req.send(null);
		},
		set: function(vals){
			if(vals){
				if(vals.action) action = vals.action;
				if(vals.source) ifrSrc = vals.source;
				if(vals.ostatus) oStatus = vals.ostatus;
				if(vals.ocomment) oComment = vals.ocomment;
				if(vals.opercent) oPercent = vals.opercent;
				if(vals.ofilecont) oFileCont = vals.ofilecont;
				if(vals.ofileform) oFileForm = vals.ofileform;
				if(vals.debug) {
					debug = vals.debug;
					if(ifr2 != null) ifr2.style.display = debug? 'block' : 'none';
				}
			}
		},
		init: function(){
			var ourDate = new Date( );
			curuplID = 'upl'+ourDate.getTime()+'_'+ourDate.getMilliseconds();

			if(ifr2 == null){
				ifr2 = document.createElement('iframe');
				ifr2.src = '';
				ifr2.id = 'ifr2';
				ifr2.name = 'ifr2';
				if(!debug) ifr2.style.display = 'none';
				$_(oFileForm).appendChild(ifr2);
				$_(oFileForm).target = 'ifr2';
			}
			
			UPurl.start();
			$_(oFileForm).action = action+'&X-Progress-ID='+curuplID; 
			$_(oFileForm).submit(); 
			$(oFileCont).css('display','none');
		},
		start: function() {
			$_(oStatus).style.display='block';startTime = new Date();infoUpdated = 0;
			interval = window.setInterval( UPurl.fetch , 1000 );
			writeStatus(0,0,0);
		},
		stop: function() {
			startTime = null;
			
			$_(oComment).innerHTML='Начинаем загрузку. Пожалуйста, подождите...';
			$_(oPercent).style.width='1px';
			$_(oStatus).style.display='none';
			$(oFileCont).css('display','block');
			$(oFileCont+' input[type=file]').attr('value','');
			//$(oFileCont+' input[type=text]').attr('value','');
		},
		updateInfo: function(upload) {
			var percent = upload.size?Math.round(upload.received / upload.size * 100):0;
			var secpast = Math.round((new Date() - startTime)/1000);
			if (startTime) {
				if (percent) {
					infoUpdated++;
					var estimatedSeconds = upload.received?Math.abs(Math.round(upload.size / upload.received * secpast)-secpast):0;
					writeStatus(secpast, percent , estimatedSeconds );
				} else {
					writeStatus(secpast, percent , 0 );
				}
			}
		}
	}
}();

function UP() {
	var startTime = null; 
	var interval;
	var curuplID = ''; var action = '';	var ifrSrc = '/progress'; var oStatus = 'status'; var oComment = ''; var oPercent = '';
	var oFileForm = ''; var oFileCont = ''; var debug = false;
	var ifr2 = null;
	var writeStatus = function(since,percent,est) {
		var comment;
		if(percent && percent < 99){
			comment = "Загрузка длится: "+WFTime(since)+". До конца осталось: "+WFTime(est);
		}else{
			if(!est && infoUpdated>0 || percent > 99){
				comment = "Загрузка закончена. Идёт обработка изображений. Пожалуйста, ждите...";
				percent = 100;
			}else
				comment = "Начинаем загрузку. Пожалуйста, подождите...";
		}
		$_(oComment).innerHTML = comment;
		if(!percent) percent = 1;		
		$_(oPercent).style.width = ''+percent+'%';
	}
	return {
		fetch: function() {
			var inst = this;
			var req;
			if (window.XMLHttpRequest){
				req = new XMLHttpRequest();
			}else if (window.ActiveXObject){
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			
			req.open("GET", ifrSrc, 1);
			req.setRequestHeader("X-Progress-ID", curuplID);
			req.onreadystatechange = function () {
				if (this.readyState == 4) {
					if (this.status == 200) {
						var upload = eval(this.responseText);
						if (upload.state == 'starting') {
							writeStatus(0,0,0);
						}
						if (upload.state == 'uploading') {
							inst.updateInfo(upload);
						}
						if (upload.state == 'done') {
							window.clearTimeout(interval);
							writeStatus(0,0,0);
						}
					}
				}
			}
			req.send(null);
		},
		set: function(vals){
			if(vals){
				if(vals.action) action = vals.action;
				if(vals.source) ifrSrc = vals.source;
				if(vals.ostatus) oStatus = vals.ostatus;
				if(vals.ocomment) oComment = vals.ocomment;
				if(vals.opercent) oPercent = vals.opercent;
				if(vals.ofilecont) oFileCont = vals.ofilecont;
				if(vals.ofileform) oFileForm = vals.ofileform;
				if(vals.debug) {
					debug = vals.debug;
					if(ifr2 != null) ifr2.style.display = debug? 'block' : 'none';
				}
			}
		},
		init: function(){
			var ourDate = new Date( );
			curuplID = 'upl'+ourDate.getTime()+'_'+ourDate.getMilliseconds();

			if(ifr2 == null){
				ifr2 = document.createElement('iframe');
				ifr2.src = '';
				ifr2.id = 'ifr2';
				ifr2.name = 'ifr2';
				if(!debug) ifr2.style.display = 'none';
				$_(oFileForm).appendChild(ifr2);
				$_(oFileForm).target = 'ifr2';
			}
			
			this.start();
			$_(oFileForm).action = action+'&X-Progress-ID='+curuplID; 
			$_(oFileForm).submit(); 
			$(oFileCont).css('display','none');
		},
		start: function() {
			$_(oStatus).style.display='block';startTime = new Date();infoUpdated = 0;
			interval = window.setInterval( this.fetch , 1000 );
			writeStatus(0,0,0);
		},
		stop: function() {
			startTime = null;
			
			$_(oComment).innerHTML='Начинаем загрузку. Пожалуйста, подождите...';
			$_(oPercent).style.width='1px';
			$_(oStatus).style.display='none';
			$(oFileCont).css('display','block');
			$(oFileCont+' input[type=file]').attr('value','');
			$(oFileCont+' input[type=text]').attr('value','');
		},
		updateInfo: function(upload) {
			var percent = upload.size?Math.round(upload.received / upload.size * 100):0;
			var secpast = Math.round((new Date() - startTime)/1000);
			if (startTime) {
				if (percent) {
					infoUpdated++;
					var estimatedSeconds = upload.received?Math.abs(Math.round(upload.size / upload.received * secpast)-secpast):0;
					writeStatus(secpast, percent , estimatedSeconds );
				} else {
					writeStatus(secpast, percent , 0 );
				}
			}
		}
	}
}
