var DOM = (typeof(document.getElementById) != 'undefined');

function setCookie(name, value, expires, domain, secure)
	{
	var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "")  + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
	document.cookie = curCookie;
	}

function getCookie(name)
	{
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1)
		{
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
		}else
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)	end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
	}

function fixDate(date)
	{
	var base = new Date(0);
	var skew = base.getTime();
	if (skew > 0)	date.setTime(date.getTime() - skew);
	}

function saveHide(element)
	{
	var now = new Date();
	fixDate(now);
	now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	setCookie(element, 'OFF', now);
	}

function saveShow(element)
	{
	var now = new Date();
	fixDate(now);
	now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	setCookie(element, 'ON', now);
	}

function getShow(element)
	{
	var stat = getCookie(element);
	if (stat=='ON') return true;
	return false;
	}

function show_upload_info()
	{
	document.getElementById('upload_info_tbl').style.display='block';
	document.getElementById('upload_info_hide').style.display='none';
	saveShow('up_info');
	return false;
	}
function hide_upload_info()
	{
	document.getElementById('upload_info_tbl').style.display='none';
	document.getElementById('upload_info_hide').style.display='block';
	saveHide('up_info');
	return false;
	}

function show_full_http_upload()
	{
	document.getElementById('upload_plus').innerHTML="&nbsp;&nbsp;<a href=\"#\" title=\"- Скрыть Referer и комментарии\" onclick=\"javascript: hide_full_http_upload();\" class=\"plus\">-</a>";
	document.getElementById('upload').style.display='block';
	saveShow('up_http');
	return false;
	}
function hide_full_http_upload()
	{
	document.getElementById('upload_plus').innerHTML="&nbsp;<a href=\"#\" title=\"+ Дополнительно Referer и комментарии\" onclick=\"javascript: show_full_http_upload();\" class=\"plus\">+</a>";
	document.getElementById('upload').style.display='none';
	saveHide('up_http');
	return false;
	}



function show_full_btt_upload()
	{
	document.getElementById('upload_plus_btt').innerHTML="&nbsp;<a href=\"#\" onclick=\"javascript: hide_full_btt_upload();\" title=\"- Скрыть выбор типа файлов и комментариев\" class=\"plus\">-</a>";
	document.getElementById('upload_btt').style.display='block';
	saveShow('up_btt');
	return false;
	}
function hide_full_btt_upload()
	{
	document.getElementById('upload_plus_btt').innerHTML="&nbsp;<a href=\"#\" onclick=\"javascript: show_full_btt_upload();\" title=\"+ Дополнительно комментарии и тип файла\" class=\"plus\">+</a>";
	document.getElementById('upload_btt').style.display='none';
	saveHide('up_btt');
	return false;
	}



function show_full_list_upload()
	{
	document.getElementById('input_links').rows=8;
	document.getElementById('upload_plus_list').innerHTML="&nbsp;<a href=\"#\" onclick=\"javascript: hide_full_list_upload();\" title=\"- Скрыть выбор типа файлов, имени списка и комментариев\" class=\"plus\">-</a>";
	document.getElementById('upload_list').style.display='block';
	saveShow('up_list');
	return false;
	}
function hide_full_list_upload()
	{
	document.getElementById('input_links').rows=2;
	document.getElementById('upload_plus_list').innerHTML="&nbsp;<a href=\"#\" onclick=\"javascript: show_full_list_upload();\" title=\"+ Дополнительно комментарии, имя и тип файла\" class=\"plus\">+</a>";
	document.getElementById('upload_list').style.display='none';
	saveHide('up_list');
	return false;
	}

function checkShowHide()
	{
	if (getShow('up_info')) show_upload_info(); 
		else hide_upload_info();
	if (getShow('up_http')) show_full_http_upload();
		else hide_full_http_upload();
	if (getShow('up_btt')) show_full_btt_upload(); 
		else hide_full_btt_upload();
	if (getShow('up_list')) show_full_list_upload(); 
		else hide_full_list_upload();
	}

function CheckAll(Element,Name)
	{
	thisCheckBoxes = Element.parentNode.parentNode.parentNode.getElementsByTagName('input');
	for (i = 1; i < thisCheckBoxes.length; i++) {
		if (thisCheckBoxes[i].name.indexOf(Name)==0){
			thisCheckBoxes[i].checked = Element.checked;
			}
		}
	}

function er_up_text()
	{
	el=document.upf.links;
	if(up_text!='')
		{
		up_text='';
		el.value='';
		el.style.color='black';
		}
	}

function SetReload(Element,Name)
	{
	if (Element.checked)
		saveShow(Name);
		else
		saveHide(Name);
	}

function SetRows(Element,Name)
	{
	var now = new Date();
	fixDate(now);
	now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	setCookie(Name, Element.value, now);
	}

function count_order_summ(dobavok)
	{
	var form=document.order_summ;
	var summ=form.allsumma.value;
	if (form.post_class.checked) 
		{
		summ=parseInt(dobavok)+parseInt(summ);
		}
	
	document.getElementById('summa').innerHTML=summ;
	}


function submit_wm_order()
	{
	if (document.wm_orderform.wmid.value.length == 12)
		{
		document.wm_orderform.submit();
		return true();
		}
	else 
		{
		alert('неправильно введен WMid покупателя (12 цифр)');
		document.wm_orderform.wmid.focus();
		}
	return false;
	}

function check_list_upload_form()
	{
	if (document.list_dl.individual.checked == true)
		{
		document.list_dl.action='?act=upload';
		}
	else 
		{
		document.list_dl.action='?act=upload_list&step=2';
		}
	}


function check_purse(WmzKurs, WmNum, WmzNum)
	{
	var d=document.WmForm;
	var fpm=parseInt(d.FPM.value);
	var fpm_min=Math.round(WmzKurs)+1;
	if ( (fpm>=10 && d.PURSE[0].checked) || (fpm>=1 && d.PURSE[1].checked) )
		{
		d.go.disabled=false;
		}else{
		fpm=fpm_min;
		d.go.disabled=true;
		}
	if (d.PURSE[0].checked)
		{
		d.LMI_PAYMENT_AMOUNT.value=(Math.round(fpm*100)/100);
		document.getElementById('wmprice').innerHTML=(Math.round(fpm*100)/100);
		d.LMI_PAYEE_PURSE.value=WmNum;
		}
	if (d.PURSE[1].checked)
		{
		d.LMI_PAYMENT_AMOUNT.value=(Math.round((fpm*100)/WmzKurs)/100);
		document.getElementById('wmprice').innerHTML=(Math.round((fpm*100)/WmzKurs)/100);
		d.LMI_PAYEE_PURSE.value=WmzNum;
		}
	}


function check_del_files(a,b)
	{
	if (a=='up') var sel=document.UsrFiles.actup;
		else 
		{
		var sel=document.UsrFiles.actdown;
		document.UsrFiles.gotype.value='godown';
		}
	if (sel.options[4].selected == true)
		{
		if (window.confirm('Вы действительно хотите удалить выбранные файлы?')) document.UsrFiles.submit(); else return false;
		}
		else if (b==1 && sel.options[5].selected == true) 
		{
		document.getElementById('folderSelect2').className='f_select_on';
		if (window.navigator.userAgent.indexOf('IE')!=-1)
			{
			self.scroll(0,0);
			}
		return false;
		}else document.UsrFiles.submit();
	return false;
	}
	
function ending(num)	
	{
	ch=num.toString()
	
	switch(ch.substr(-1))
		{
		case "0":
			end="ов";
			break;
		case "1":
			end="";
			break;
		case "2":
		case "3":
		case "4":
			end="а";
			break;
		default:
			end="ов";
			break;
		}
		if(ch.substr(-2,1)=="1" && ch.length!=1)end="ов"
	return end;
	}
function ending2(num)	
	{
	
	ch=num.toString()
	
	switch(ch.substr(-1))
		{
		case "0":
			end="";
			break;
		case "1":
			end="а";
			break;
		case "2":
		case "3":
		case "4":
			end="ы";
			break;
		default:
			end="";
			break;
		}
	if(ch.substr(-2,1)=="1" && ch.length!=1)end=""
	return end;
	}		
	
function Days(num)	
	{
	
	ch=num.toString()
	
	switch(ch.substr(-1))
		{
		
		case "1":
			end="день";
			break;
		case "2":
		case "3":
		case "4":
			end="дня";
			break;
		default:
			end="дней";
			break;
		}
	if(ch.substr(-2,1)=="1" && ch.length!=1)end="дней"
	return end;
	}		
	

function time_left(now_time, last_time)
	{
	if (now_time<=last_time)
		{
		dysLeft=Math.floor((last_time-now_time)/3600/24);
		hrsLeft=Math.floor((last_time-now_time)/3600-dysLeft*24);
		minsLeft = Math.floor((last_time-now_time)/60 - hrsLeft*60-dysLeft*24*60);
		var secLeft = Math.floor((last_time-now_time) -minsLeft*60 - hrsLeft*3600-dysLeft*24*3600);
		if (dysLeft>0) dysLeftText=dysLeft+" "+Days(dysLeft)+" "; else dysLeftText='';
		document.getElementById('qwe').innerHTML=dysLeftText+hrsLeft+" час"+ending(hrsLeft)+" "+ minsLeft + " минут"+ending2(minsLeft)+" " + secLeft  + " секунд"+ending2(secLeft)
		now_time = now_time + 1;
		setTimeout("time_left("+now_time+", "+last_time+")", 1000);
		}
	}

function time_left2(now_time, last_time)
	{
	dysLeft=Math.floor((last_time-now_time)/3600/24);
	hrsLeft=Math.floor((last_time-now_time)/3600-dysLeft*24);
	minsLeft = Math.floor((last_time-now_time)/60 - hrsLeft*60-dysLeft*24*60);
	var secLeft = Math.floor((last_time-now_time) -minsLeft*60 - hrsLeft*3600-dysLeft*24*3600);
	if (dysLeft>0) retText=dysLeft+"&nbsp;"+Days(dysLeft);
		else if (hrsLeft>0) retText=hrsLeft+"&nbsp;час"+ending(hrsLeft);
		else if (minsLeft>0) retText=minsLeft + "&nbsp;минут"+ending2(minsLeft);
		else if (secLeft>0) retText=secLeft  + "&nbsp;секунд"+ending2(secLeft);
		else retText='0. Истекла.';
	document.getElementById('qwe2').innerHTML=retText;
	now_time = now_time + 10;
	setTimeout("time_left2("+now_time+", "+last_time+")", 10000);
	}

function gdw_time_left(now_time, last_time)
	{
	if (now_time<=last_time)
		{
		dysLeft=Math.floor((last_time-now_time)/3600/24);
		hrsLeft=Math.floor((last_time-now_time)/3600-dysLeft*24);
		minsLeft = Math.floor((last_time-now_time)/60 - hrsLeft*60-dysLeft*24*60);
		var secLeft = Math.floor((last_time-now_time) -minsLeft*60 - hrsLeft*3600-dysLeft*24*3600);
		document.getElementById('gdw').innerHTML=hrsLeft+":"+(minsLeft<10?'0':'')+minsLeft+":"+(secLeft<10?'0':'')+secLeft;
		now_time = now_time + 1;
		setTimeout("gdw_time_left("+now_time+", "+last_time+")", 1000);
		}
	}

var f_name_arr=new Array();

function mf1_rename_file(a,b)
	{
	s=document.getElementById(a);
	f_name_arr[a]=s.innerHTML;
	s.innerHTML='<input name=new_'+a+' type=text value="'+b+'">&nbsp;<input type=button name=rename value=OK onclick="javascript: mf1_rename_file_ok();">&nbsp;<input type=button name=cancel value=Отменить onclick="javascript: mf1_rename_file_cancel(\''+a+'\');">';
	}

function mf1_rename_file_cancel(a)
	{
	s=document.getElementById(a);
	s.innerHTML=f_name_arr[a];
	}
	
function mf1_rename_file_ok()
	{
	can_submit=false;
	var checkFileNameRegex = /[^a-zA-Z0-9\-\_\.\ ]/;
	f=document.UsrFiles;
	for (i = 1; i < f.length; i++) {
		if (f[i].name.indexOf('new_name')==0)
			{
			if (f[i].value.length < 3 || f[i].value.length > 120 || checkFileNameRegex.test(f[i].value))
				{
				can_submit=false;
				alert("Недопустимые символы в имени файла (a-z A-Z 0-9 - _ .) или длина имени файла (от 4 до 120 символов)");
				f[i].focus();
				return false;
				}else can_submit=true;
			}
		}
	if (can_submit)
		{
		document.UsrFiles.gotype.value='rename';
		document.UsrFiles.submit();
		}
	}

function mf1_create_folder()
	{
	var checkFolderNameRegex = /[^a-zA-Z0-9\-\_\.\ ]/;
	fname=prompt("Введите имя папки");
	if (fname.length < 3 || fname.length > 120 || checkFolderNameRegex.test(fname))
		{
		alert("Недопустимые символы в имени папки (a-z A-Z 0-9 - _ .) или длина имени папки (от 4 до 120 символов)");
		return false;
		}else{
		document.UsrFiles.gotype.value='create_folder';
		document.getElementById('f_butt').innerHTML='<input type=hidden name=foldername value="'+fname+'">';
		document.UsrFiles.submit();
		return false;
		}
	return false;
	}

function showToolTip(e,text){
	if(document.all)e = event;
	
	var obj = document.getElementById('bubble_tooltip');
	var obj2 = document.getElementById('bubble_tooltip_content');
	obj2.innerHTML = text;
	obj.style.display = 'block';
	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0; 
	var leftPos = e.clientX - 100;
	if(leftPos<0)leftPos = 0;
	obj.style.left = leftPos + 'px';
	obj.style.top = e.clientY - obj.offsetHeight -1 + st + 'px';
}	

function hideToolTip()
{
	document.getElementById('bubble_tooltip').style.display = 'none';
	
}

function filial_summ(Element)
	{
	var debt=0;
	var reward=0;
	if (DOM)
		{
		thisCheckBoxes = Element.parentNode.parentNode.parentNode.getElementsByTagName('input');
		for (i = 1; i < thisCheckBoxes.length; i++) {
			if (thisCheckBoxes[i].name.indexOf('element')==0 && thisCheckBoxes[i].checked)
				{
				num=thisCheckBoxes[i].value;
				ch=num.toString();
				pos=ch.indexOf('-');
				debt=debt+parseInt(ch.substr(0,pos));
				reward=reward+parseInt(ch.substr(pos+1));
				}
			}
		document.getElementById('debt').innerHTML=debt;
		document.getElementById('reward').innerHTML=reward;
		document.getElementById('d-r').innerHTML=debt-reward;
		}
	}

var persistclose=1 //set to 0 or 1. 1 means once the bar is manually closed, it will remain closed for browser session
var startX = 25 //set x offset of bar in pixels
var startY = 5 //set y offset of bar in pixels
var verticalpos="frombottom" //enter "fromtop" or "frombottom"
var horizontalpos="fromright" //enter "fromleft" or "fromright"

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function closebar(cname){
	if (persistclose)
		{
		var now = new Date();
		fixDate(now);
		now.setTime(now.getTime() + 10 * 24 * 60 * 60 * 1000);
		setCookie(cname, '1', now);
		}
	document.getElementById("divtopbar").style.visibility="hidden"
	}

function staticbar(cname){
	barheight=document.getElementById("divtopbar").offsetHeight
	barwidth=document.getElementById("divtopbar").offsetWidth
	var ns = (navigator.appName.indexOf("Netscape") != -1) || window.opera;
	var d = document;
	function ml(id){
		var el=d.getElementById(id);
		if (!persistclose || persistclose && getCookie(cname)!="1")
		el.style.visibility="visible"
		if(d.layers)el.style=el;
		el.sP=function(x,y){this.style.left=x+"px";this.style.top=y+"px";};
		if (horizontalpos=="fromleft")
		el.x = startX;
		else{
		el.x = ns ? pageXOffset + innerWidth : iecompattest().scrollLeft + iecompattest().clientWidth;
		el.x -= startX+barwidth;
		}
		if (verticalpos=="fromtop")
		el.y = startY;
		else{
		el.y = ns ? pageYOffset + innerHeight  - barheight: iecompattest().scrollTop + iecompattest().clientHeight - barheight;
		el.y -= startY;
		}
		return el;
	}
	window.stayTopLeft=function(){
		if (verticalpos=="fromtop"){
		var pY = ns ? pageYOffset : iecompattest().scrollTop;
		ftlObj.y += (pY + startY - ftlObj.y)/8;
		}
		else{
		var pY = ns ? pageYOffset + innerHeight - barheight: iecompattest().scrollTop + iecompattest().clientHeight - barheight;
		ftlObj.y += (pY - startY - ftlObj.y)/8;
		}
		if (horizontalpos!="fromleft"){
		var pX = ns ? pageXOffset + innerWidth - barwidth: iecompattest().scrollLeft + iecompattest().clientWidth - barwidth;
		ftlObj.x += (pX - startX - ftlObj.x)/8;
		}
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft()", 10);
	}
	ftlObj = ml("divtopbar");
	stayTopLeft();
}