function digo(id)
{
	inp = document.getElementById('bnum'+id);
	reg = /[А-Яа-яA-Za-z\]\[{};':",/ <>?\-=\\_.+|`~\!@#$%^\&*\(\)№]/g;
	result = inp.value.replace(reg,'');
	if (result.substring(0,1)==0) result = result.substring(1,100);
	inp.value = result;
}

function DigOnly(id)
{
	eval ('setTimeout("digo('+id+');",100)');
}

function digox(id)
{
	inp = document.getElementById('bnum'+id);
	reg = /[А-Яа-яA-Za-z\]\[{};':",/ <>?\-=\\_.|`~\!@#$%^\&*№]/g;
	result = inp.value.replace(reg,'');
	if (result.substring(0,1)==0) result = result.substring(1,100);
	inp.value = result;
}

function DigOnlyX(id)
{
	eval ('setTimeout("digox('+id+');",100)');
}

function ShowAdd()
{
	document.getElementById('ADD').style.display = 'block';
	document.getElementById('ADDB').innerHTML = '<span onclick="HideAdd();">Добавить новую подписку</span>';
}

function HideAdd()
{
	document.getElementById('ADD').style.display = 'none';
	document.getElementById('ADDB').innerHTML = '<span onclick="ShowAdd();">Добавить новую подписку</span>';
}

function ShowAddX()
{
	document.getElementById('ADDX').style.display = 'block';
	document.getElementById('ADDBX').innerHTML = '<span onclick="HideAddX();">Добавить новый шаблон</span>';
}

function HideAddX()
{
	document.getElementById('ADDX').style.display = 'none';
	document.getElementById('ADDBX').innerHTML = '<span onclick="ShowAddX();">Добавить новый шаблон</span>';
}

function isValidEmail(email)
{
	re = /^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i;
	return re.test(email);
}
        

function checkEmpty (val){
	if (val=="" || val.search(/[^\s]+/)==-1) {
		return false;
	}
	return true;
}

function Profile()
{
	Warning = '';
	if (!checkEmpty(document.RF.name.value)) 
	{
		Warning = Warning + '<p>Заполните поле &laquo;Имя&raquo;</p>';
	} else
		{
			if (document.RF.name.value.length<4 || document.RF.name.value.length>25) Warning = Warning + '<p>Допустимая длинна имени от 4-х до 25-ти символов</p>';
		}

	if (!checkEmpty(document.RF.login.value)) 
	{
		Warning = Warning + '<p>Заполните поле &laquo;E-mail&raquo;</p>';
	} else
		{
			if (!isValidEmail(document.RF.login.value)) Warning = Warning + '<p>Введите корректный e-mail</p>';
		}
	if (document.RF.email.value!='')
	{
		if (!isValidEmail(document.RF.email.value)) Warning = Warning + '<p>Введите корректный e-mail</p>';
	}
	if (checkEmpty(document.RF.pass2.value)) 
	{
			if (document.RF.pass2.value.length<4 || document.RF.pass2.value.length>12)
			{
				Warning = Warning + '<p>Допустимая длинна пароля от 4-х до 12-ти символов</p>';
			} else
				{
					if (document.RF.pass2.value!=document.RF.pass3.value)
					{
						Warning = Warning + '<p>Введенные пароль не совпадают</p>';
					} else
						{
							if (!checkEmpty(document.RF.pass1.value)) 
							{
								Warning = Warning + '<p>Введите старый пароль</p>';
							}
						}
				}		
	}
		

if (Warning=='')
{
	document.RF.submit();
} else
	{
		document.getElementById('wrn').innerHTML = Warning;
	}	
}

function Register()
{
	Warning = '';
	if (!checkEmpty(document.RF.name.value)) 
	{
		Warning = Warning + '<p>Заполните поле &laquo;Имя&raquo;</p>';
	} else
		{
			if (document.RF.name.value.length<4 || document.RF.name.value.length>25) Warning = Warning + '<p>Допустимая длинна имени от 4-х до 25-ти символов</p>';
		}

	if (!checkEmpty(document.RF.email1.value)) 
	{
		Warning = Warning + '<p>Заполните поле &laquo;E-mail&raquo;</p>';
	} else
		{
			if (!isValidEmail(document.RF.email1.value)) Warning = Warning + '<p>Введите корректный e-mail</p>';
		}

	if (!checkEmpty(document.RF.pass1.value)) 
	{
		Warning = Warning + '<p>Заполните поле &laquo;Пароль&raquo;</p>';
	} else
		{
			if (document.RF.pass1.value.length<4 || document.RF.pass1.value.length>12)
			{
				Warning = Warning + '<p>Допустимая длинна пароля от 4-х до 12-ти символов</p>';
			} else
				{
					if (!checkEmpty(document.RF.pass2.value))
					{
						Warning = Warning + '<p>Повторите введенный пароль</p>';
					} else
						{
							if (document.RF.pass2.value!=document.RF.pass1.value) Warning = Warning + '<p>Введенные пароли не совпадают</p>';
						}
				}
		}
	

	if (document.RF.capt)
	{
	if (!checkEmpty(document.RF.capt.value)) 
	{
		Warning = Warning + '<p>Введите цифры с картинки</p>';
	}
	}

	if (document.RF.agree) if (document.RF.agree.checked==0) Warning = Warning + '<p>Вы должны принять пользовательское соглашение</p>';

	eval("do"+"cum"+"ent.R"+"F.re"+"g_fo"+"rm.val"+"ue = 'r"+"eg_f"+"orm';");

if (Warning=='')
{
	document.RF.submit();
} else
	{
		document.getElementById('wrn').innerHTML = Warning;
	}

}

function ConfirmDel(msg) 
{ 
  document.RV = confirm(msg); 
} 

function OpenF(id)
{
	document.getElementById('B-1-'+id).style.display = 'block';	
	document.getElementById('ofc'+id).innerHTML = '<div class="Folder" onclick="CloseF('+id+');" id="of'+id+'"></div>';	
	document.getElementById('of'+id).style.backgroundImage = 'url(\'' + '/img/folder_minus.gif' + '\')';
	if (document.getElementById('openc'+id)) document.getElementById('openc'+id).value = 1;
	LoadVendors();
}

function CloseF(id)
{
	document.getElementById('B-1-'+id).style.display = 'none';	
	document.getElementById('ofc'+id).innerHTML = '<div class="Folder" onclick="OpenF('+id+');" id="of'+id+'"></div>';	
	document.getElementById('of'+id).style.backgroundImage = 'url(\'' + '/img/folder_plus.gif' + '\')';
	if (document.getElementById('openc'+id)) document.getElementById('openc'+id).value = 0;
	LoadVendors();
}

function LoadVendors()
{
	cats = '';
	x=1; flag=true;
	while (flag==true)
	{
		if (document.getElementById('cat_id'+x))
		{
			if (document.getElementById('openc'+document.getElementById('cat_id'+x).value).value==1) cats = cats + '-' + document.getElementById('cat_id'+x).value;
		} else
			{
				flag=false;
			}
		x++;
	}

	httpReqZ=createHttpRequest();
    file = '/loadvendors_ajax.php?c_id='+cats;
    sendRequestZ(file);		

}


var httpReqZ;

function sendRequestZ(file)
{
    httpReqZ.open('get',file);
    httpReqZ.onreadystatechange = FillVendors;
    httpReqZ.send(null);
}


function FillVendors()
{
	if (httpReqZ.readyState==4)
    {
		document.getElementById('AllM').innerHTML = httpReqZ.responseText;
	} else
		{
			setTimeout('FillVendors()',100);
		}
}

var tplo; tplo = new Array();

function ChangeTpl(id)
{
	if (tplo[id])
	{
	} else
		{
			tplo[id]=0;
		}
		
	if (tplo[id]==0)
	{
		tplo[id]=1;
		document.getElementById('ta'+id).style.display = 'block';
	} else
		{
			tplo[id]=0;
			document.getElementById('ta'+id).style.display = 'none';
		}

}


var manso; manso = new Array();


var LastFocus; LastFocus = 0;

function ClickMans(id)
{
	if (manso[id])
	{
	} else
		{
			manso[id]=0;
		}
		
	if (manso[id]==0)
	{
		manso[id]=1;
		document.getElementById('mans'+id).style.display = 'block';
		document.getElementById('mans'+id).focus();
		document.getElementById('opent'+id).value = 1;
	} else
		{
			manso[id]=0;
			document.getElementById('mans'+id).style.display = 'none';
			document.getElementById('opent'+id).value = 0;
		}
		
}

function CopyMan(id)
{
	if (LastFocus!=0)
	{
		if (document.getElementById('mans'+LastFocus).value!='') document.getElementById('mans'+LastFocus).value = document.getElementById('mans'+LastFocus).value+', '+document.getElementById('vend'+id).innerHTML;
		if (document.getElementById('mans'+LastFocus).value=='') document.getElementById('mans'+LastFocus).value = document.getElementById('vend'+id).innerHTML;
	}
}

var httpReqCC;
var httpReqA;
var httpReqB;

function createHttpRequest() {

var httpRequest;
var browser = navigator.appName;

if (browser == "Microsoft Internet Explorer") {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
} else {
httpRequest = new XMLHttpRequest();
}

return httpRequest;
} 

function sendRequestCC(file)
{
    httpReqCC.open('get',file);
    httpReqCC.onreadystatechange = ChangeSelect;
    httpReqCC.send(null);
}

function ChangeCat()
{
	httpReqCC=createHttpRequest();
    file = '/main_ajax.php?c_id='+document.forma.cat.value;
    sendRequestCC(file);		
}

function ChangeSelect()
{
	if (httpReqCC.readyState==4)
    {
		document.getElementById('TypeTD').innerHTML = httpReqCC.responseText;
	} else
		{
			setTimeout('ChangeSelect()',200);
		}
}


function sendRequestA(file)
{
    httpReqA.open('get',file);
    httpReqA.onreadystatechange = FillBoxes;
    httpReqA.send(null);
}

function LoadTypes()
{
	httpReqA=createHttpRequest();
    file = '/add_ajax.php?c_id='+document.forma.cat.value;
    sendRequestA(file);		
}

function LoadTypesS()
{
	httpReqA=createHttpRequest();
    file = '/search_ajax.php?c_id='+document.forma.cat.value+'&t_id='+document.forma.type.value+'&zz=1';
    sendRequestA(file);		
}

function sendRequestAX(file)
{
    httpReqA.open('get',file);
    httpReqA.onreadystatechange = FillBoxesX;
    httpReqA.send(null);
}

var CurSub;

function LoadTypesX(s_id)
{
	httpReqA=createHttpRequest();
    ct = document.getElementById('ct'+s_id).value;
    file = '/add_ajax.php?c_id='+ct+'&s_id='+s_id;
    sendRequestAX(file);		
    CurSub = s_id;
}

function FillBoxesX()
{
	if (httpReqA.readyState==4)
    {
		txt = httpReqA.responseText;
		x = txt.indexOf('+<select');
		txt1 = txt.substring(0,x);
		txt2 = txt.substring(x+1);
		document.getElementById('TypeBox'+CurSub).innerHTML = txt1;
		document.getElementById('MansBox'+CurSub).innerHTML = txt2;
	} else
		{
			setTimeout('FillBoxesX()',200);
		}
}

function FillBoxes()
{
	if (httpReqA.readyState==4)
    {
		txt = httpReqA.responseText;
		x = txt.indexOf('+<select');
		txt1 = txt.substring(0,x);
		txt2 = txt.substring(x+1);
		document.getElementById('TypeBox').innerHTML = txt1;
		document.getElementById('MansBox').innerHTML = txt2;
	} else
		{
			setTimeout('FillBoxes()',100);
		}
}



function sendRequestBX(file)
{
    httpReqB.open('get',file);
    httpReqB.onreadystatechange = FillMansX;
    httpReqB.send(null);
}
function sendRequestB(file)
{
    httpReqB.open('get',file);
    httpReqB.onreadystatechange = FillMans;
    httpReqB.send(null);
}

function LoadMans()
{
	httpReqB=createHttpRequest();
    file = '/add_ajax.php?t_id='+document.forma.type.value+'&xxx='+document.forma.cat.value;
    if (document.getElementById('EnterNew')) 
    {
    if (document.forma.type.value=='-1' || document.forma.man.value=='-1') document.getElementById('EnterNew').style.display = 'block';
    if (document.forma.type.value!='-1' && document.forma.man.value!='-1') document.getElementById('EnterNew').style.display = 'none';
    }
    if (document.forma.type.value=='-1')
    {
    	document.getElementById('v1').style.display = 'block';
    	document.getElementById('v12').style.display = 'block';
    } else
    	{
    		document.getElementById('v1').style.display = 'none';
    		document.getElementById('v12').style.display = 'none';
    		document.forma.newtype.value = '';
    	}
    if (document.forma.man.value=='-1')
    {
    	document.getElementById('v2').style.display = 'block';
    	document.getElementById('v22').style.display = 'block';
    } else
    	{
    		document.getElementById('v2').style.display = 'none';
    		document.getElementById('v22').style.display = 'none';
    		document.forma.newman.value = '';
    	}    sendRequestB(file);		
}

function LoadMansS()
{
	httpReqB=createHttpRequest();
    file = '/search_ajax.php?t_id='+document.forma.type.value+'&c_id='+document.forma.cat.value+'&zz=2';
    sendRequestB(file);		
}

function ChangeSub()
{
	httpReqSB=createHttpRequest();
    file = '/subscribe_ajax.php?type='+document.forma.type.value+'&cat='+document.forma.cat.value+'&man='+document.forma.man.value;
    sendRequestSB(file);	
    CurSbs = 0;	
}

var CurSbs;

function ChangeSubX(id)
{
	CurSbs = id;
	httpReqSB=createHttpRequest();
    file = '/subscribe_ajax.php?type='+document.getElementById('tp'+id).value+'&cat='+document.getElementById('ct'+id).value+'&man='+document.getElementById('mn'+id).value+'&sub_id='+id;
    sendRequestSB(file);		
}

function sendRequestSB(file)
{
    httpReqSB.open('get',file);
    httpReqSB.onreadystatechange = InpBoxes;
    httpReqSB.send(null);
}


var xz=1;
function InpBoxes()
{
	if (httpReqSB.readyState==4)
    {
		txt = httpReqSB.responseText;
		x = txt.indexOf('+<select');
		txt1 = txt.substring(0,x);
		txt2 = txt.substring(x+1);
		x = txt2.indexOf('+<select');
		txt22 = txt2.substring(0,x);
		txt3 = txt2.substring(x+1);

		
		
		if (CurSbs==0)
		{
		document.getElementById('CatBox').innerHTML = txt1;
		document.getElementById('TypeBox').innerHTML = txt22;
		document.getElementById('ManBox').innerHTML = txt3;	
		} else
			{
				document.getElementById('CatBox'+CurSbs).innerHTML = txt1;
				document.getElementById('TypeBox'+CurSbs).innerHTML = txt22;
				document.getElementById('ManBox'+CurSbs).innerHTML = txt3;	
			}

		sls = document.getElementsByTagName('select');
		x = sls.length;
		for (i=0; i<x; i++)
		{
			if (xz==1) sls[i].style.display = 'block';
			if (xz==2) sls[i].style.display = 'inline';
		}
		inp = document.getElementsByTagName('input');
		x = inp.length;
		for (i=0; i<x; i++)
		{
			if (xz==1) inp[i].style.display = 'block';
			if (xz==2) inp[i].style.display = 'inline';
		}
			if (xz==1) {xz=2;} else {xz=1;}

	} else
		{
			setTimeout('InpBoxes()',100);
		}
}


function LoadMansX(s_id)
{
	httpReqB=createHttpRequest();
    tp = document.getElementById('tp'+s_id).value;
    file = '/add_ajax.php?t_id='+tp+'&s_id='+s_id;
    sendRequestBX(file);
    CurSub = s_id;		
}

function CheckMan()
{
    if (document.forma.type.value=='-1' || document.forma.man.value=='-1') document.getElementById('EnterNew').style.display = 'block';
    if (document.forma.type.value!='-1' && document.forma.man.value!='-1') document.getElementById('EnterNew').style.display = 'none';
    if (document.forma.type.value=='-1')
    {
    	document.getElementById('v1').style.display = 'block';
    	document.getElementById('v12').style.display = 'block';
    } else
    	{
    		document.getElementById('v1').style.display = 'none';
    		document.getElementById('v12').style.display = 'none';
    		document.forma.newtype.value = '';
    	}
    if (document.forma.man.value=='-1')
    {
    	document.getElementById('v2').style.display = 'block';
    	document.getElementById('v22').style.display = 'block';
    } else
    	{
    		document.getElementById('v2').style.display = 'none';
    		document.getElementById('v22').style.display = 'none';
    		document.forma.newman.value = '';
    	}
}

function FillMansX()
{
	if (httpReqB.readyState==4)
    {
		document.getElementById('MansBox'+CurSub).innerHTML = httpReqB.responseText;
	} else
		{
			setTimeout('FillMansX()',200);
		}
}

function FillMans()
{
	if (httpReqB.readyState==4)
    {
		document.getElementById('MansBox').innerHTML = httpReqB.responseText;
		if (document.getElementById('addpage')) LoadTemplate();
	} else
		{
			setTimeout('FillMans()',200);
		}
}


function ShowPhoto(path,width,height)
{
	for (i=1; i<=fnames.length; i++)
	{
		if (fnames[i]==path) curI=i;
	}
	
	tl = document.getElementById('ToLeft');
	tr = document.getElementById('ToRight');
	tli = document.getElementById('ToLeftImg');
	tri = document.getElementById('ToRightImg');
	
	if ((curI-1)!=0)
	{	
	tli.innerHTML = '<img src="/img/.gif" width="17" height="33" onclick=ShowPhoto("'+fnames[(curI-1)]+'",'+fwidths[(curI-1)]+','+fheights[(curI-1)]+')>';
	tl.style.display = 'block';
	tl.style.marginTop = -44 + document.documentElement.scrollTop + 'px';
	tli.style.display = 'block';
	tli.style.marginTop = -44 + document.documentElement.scrollTop + 'px';
	} else
		{
			tl.style.display = 'none';
			tli.style.display = 'none';
		}
	
	if ((curI+1)<fnames.length)
	{
	tri.innerHTML = '<img src="/img/.gif" width="17" height="33" onclick=ShowPhoto("'+fnames[(curI+1)]+'",'+fwidths[(curI+1)]+','+fheights[(curI+1)]+')>';
	tr.style.display = 'block';
	tr.style.marginTop = -16 + document.documentElement.scrollTop + 'px';
	tri.style.display = 'block';
	tri.style.marginTop = -16 + document.documentElement.scrollTop + 'px';
	} else
		{
			tr.style.display = 'none';
			tri.style.display = 'none';
		}
	
				
	int = document.getElementById('interlaced');
	int.style.height = document.documentElement.scrollHeight + 'px';
	int.style.visibility = 'visible';
	view = document.getElementById('ViewPhoto');
	vd = document.getElementById('Vdiv');
	foto = document.getElementById('Fotka');
	foto.innerHTML = '<img src="'+path+'" onclick="HidePhoto();">';
	view.style.width = width + 'px';
	vd.style.width = width + 'px';
	view.style.height = height + 30 + 'px';
	view.style.marginLeft = -Math.round(width/2) + 'px';
	view.style.marginTop = -Math.round(height/2) - 35 + document.documentElement.scrollTop + 'px';
	view.style.display = 'block';
}

function HidePhoto()
{
	tl = document.getElementById('ToLeft');
	tr = document.getElementById('ToRight');
	tr.style.display = 'none';
	tl.style.display = 'none';
	tli = document.getElementById('ToLeftImg');
	tri = document.getElementById('ToRightImg');
	tri.style.display = 'none';
	tli.style.display = 'none';
	view = document.getElementById('ViewPhoto');
	view.style.display = 'none';
	int = document.getElementById('interlaced');
	int.style.visibility = 'hidden';
}


function DelImg(par1,par2)
{
	httpReqDel=createHttpRequest();
    file = '/del_ajax.php?ph_id='+par1+'&item_id='+par2;
    sendRequestDel(file);		
}

function Arrange()
{
	if (httpReqDel.readyState==4)
    {
		document.getElementById('upif').src = document.getElementById('upif').src;
	} else
		{
			setTimeout('Arrange()',200);
		}
}



function sendRequestDel(file)
{
    httpReqDel.open('get',file);
    httpReqDel.onreadystatechange = Arrange;
    httpReqDel.send(null);
}

function MoveUp(pos,item_id)
{
	httpReqDel=createHttpRequest();
    file = '/move_ajax.php?pos='+pos+'&direct=up'+'&item_id='+item_id;;
    sendRequestDel(file);		
}

function MoveDown(pos,item_id)
{
	httpReqDel=createHttpRequest();
    file = '/move_ajax.php?pos='+pos+'&direct=down'+'&item_id='+item_id;;
    sendRequestDel(file);		
}



	var mouseX = 0;
	var mouseY = 0;
	var curX = 0;
	var curY = 0;
	var Drag = 0;
	var InArea = 0;
	var Empty;
	var LW;
	var RW;	
		
	function getXY(e)
	{
	e = e || window.event

	if (e.pageX == null && e.clientX != null ) { 
		var html = document.documentElement
		var body = document.body
	
		e.pageX = e.clientX + (html && html.scrollLeft || body && body.scrollLeft || 0) - (html.clientLeft || 0)
		e.pageY = e.clientY + (html && html.scrollTop || body && body.scrollTop || 0) - (html.clientTop || 0)
	}

	
	mouseX = e.pageX
	mouseY = e.pageY
		try
		{
		if (Orientation==2) 
		{
		xxx = mouseX-curX;
		
		if (Drag==1 && InArea==1) 
			{
				l = document.getElementById('left');
				r = document.getElementById('right');
				

				LeftWidth = LW*1+xxx*1;
				if (LeftWidth<0) LeftWidth=0; if (LeftWidth>Empty) LeftWidth=Empty;
				RightWidth = RW*1-xxx*1;
				if (RightWidth<0) RightWidth=0; if (RightWidth>Empty) RightWidth=Empty;

				
				document.getElementById('delta').value = LeftWidth;
				l.style.width = LeftWidth + 'px';
				r.style.width = RightWidth + 'px';
			}
		}
		if (Orientation==1) 
		{
		yyy = mouseY-curY;
		if (Drag==1 && InArea==1) 
			{
				l = document.getElementById('left');
				r = document.getElementById('right');
				

				LeftWidth = LW*1+yyy*1;
				if (LeftWidth<0) LeftWidth=0; if (LeftWidth>Empty) LeftWidth=Empty;
				RightWidth = RW*1-yyy*1;
				if (RightWidth<0) RightWidth=0; if (RightWidth>Empty) RightWidth=Empty;

				
				document.getElementById('delta').value = LeftWidth;
				l.style.height = LeftWidth + 'px';
				r.style.height = RightWidth + 'px';
				document.getElementById('btn').style.marginTop = RightWidth + 15 + 'px';
			}
		}
		}
		catch (err)
		{
			
		}
	}

document.onmousemove = getXY;


var Orientation;

	function mouseDown(state)
	{
		
		Empty = document.getElementById('f1').value;
		LW = document.getElementById('f2').value;
		RW = document.getElementById('f3').value;
		Orientation = document.getElementById('f4').value;
				
		if (Drag==0) {Drag = 1; document.getElementById('rArea').style.cursor = 'move';} else {Drag=0; document.getElementById('rArea').style.cursor = 'pointer';}
		curX = mouseX;
		curY = mouseY;
	}


function AddTC()
{
	sm=1;
	
	if (document.forma.op1.checked==0 && document.forma.op2.checked==0 && document.forma.op3.checked==0)
	{
		document.getElementById('w22').style.visibility = 'visible';
		sm=0;
	} else
		{
			document.getElementById('w22').style.visibility = 'hidden';
		}
	
	if (document.forma.price.value=='')
	{
		document.getElementById('w5').style.visibility = 'visible';
		sm=0;
	}  else
		{
			document.getElementById('w5').style.visibility = 'hidden';
		}
	if (document.forma.cat.value==0)
	{
		document.getElementById('w1').style.visibility = 'visible';
		sm=0;
	}  else
		{
			document.getElementById('w1').style.visibility = 'hidden';
		}
	if (document.forma.type.value==0)
	{
				document.getElementById('w2').style.visibility = 'visible';
				sm=0;
	}  else
		{
			if (document.forma.type.value=='n')
			{
				if (document.forma.newtype.value=='')
				{
					document.getElementById('w6').style.visibility = 'visible';
					sm=0;
				} else
					{
						document.getElementById('w6').style.visibility = 'hidden';
					}
			} else
				{
					document.getElementById('w2').style.visibility = 'hidden';
				}
		}
	if (document.forma.man.value==0)
	{
		document.getElementById('w3').style.visibility = 'visible';
		sm=0;
	}  else
		{
			if (document.forma.man.value=='n')
			{
				if (document.forma.newman.value=='')
				{
					document.getElementById('w7').style.visibility = 'visible';
					sm=0;
				} else
					{
						document.getElementById('w7').style.visibility = 'hidden';
					}
			} else
				{
					document.getElementById('w3').style.visibility = 'hidden';
				}	
		}
	if (document.forma.year.value==0)
	{
		document.getElementById('w4').style.visibility = 'visible';
		sm=0;
	}  else
		{
			document.getElementById('w4').style.visibility = 'hidden';
		}

		prs = document.forma.price.value*1; price_min=price_min*1; price_max=price_max*1;
		if (prs<price_min && document.forma.price.value!='') {document.getElementById('w5').innerHTML = 'Мин. '+price_min+'р.'; document.getElementById('w5').style.visibility = 'visible'; sm=0;}
		if (prs>price_max && document.forma.price.value!='') {document.getElementById('w5').innerHTML = 'Макс. '+price_max+'р.'; document.getElementById('w5').style.visibility = 'visible'; sm=0}


	if (sm==1) 
	{


		
		
		document.forma.go.value = 1;
		document.forma.submit();
	}
}

function HideTC()
{
	sm=1;
	if (sm==1) 
	{
		document.forma.go.value = 55;
		document.forma.submit();
	}
}		

function AddTicket()
{
	sm=1;
	
	if (document.forma.cat.value==0)
	{
		document.getElementById('w1').style.visibility = 'visible';
		sm=0;
	}  else
		{
			document.getElementById('w1').style.visibility = 'hidden';
		}
	if (document.forma.type.value==0)
	{
				document.getElementById('w2').style.visibility = 'visible';
				sm=0;
	}  else
		{
			if (document.forma.type.value=='-1')
			{
				if (document.forma.newtype.value=='')
				{
					
					document.getElementById('w6').style.visibility = 'visible';
					document.getElementById('w2').style.visibility = 'hidden';
					sm=0;
				} else
					{
						document.getElementById('w6').style.visibility = 'hidden';
					}
			} else
				{
					document.getElementById('w2').style.visibility = 'hidden';
				}
		}
			if (document.forma.man.value=='-1')
			{
				if (document.forma.newman.value=='')
				{
					document.getElementById('w7').style.visibility = 'visible';
					sm=0;
				} else
					{
						document.getElementById('w7').style.visibility = 'hidden';
					}
			} else
				{
					document.getElementById('w3').style.visibility = 'hidden';
				}
	if (document.forma.year1.value!=0 && document.forma.year2.value!=0)
	{
		if (document.forma.year1.value>document.forma.year2.value)
		{
			document.getElementById('w8').style.visibility = 'visible';
			sm=0;
		} else
			{
				document.getElementById('w8').style.visibility = 'hidden';
			}
	}
	
	pr1=1;
	if (document.forma.price1.value=='')
	{
		document.getElementById('w10').innerHTML = 'Укажите цену';
		document.getElementById('w10').style.visibility = 'visible';
		sm=0;
		pr1=0;
	} else
		{
			document.getElementById('w10').style.visibility = 'hidden';
		}
		
	pr2=1;
	if (document.forma.price2.value=='')
	{
		document.getElementById('w11').innerHTML = 'Укажите цену';
		document.getElementById('w11').style.visibility = 'visible';
		sm=0;
		pr2=0;
	} else
		{
			document.getElementById('w11').style.visibility = 'hidden';
		}
		
	if (pr1==1 && pr2==1)
	{
		p2 = parseInt(document.forma.price2.value);
		p1 = parseInt(document.forma.price1.value);
		if (p2 < p1)
		{
			sm = 0;
			document.getElementById('w11').innerHTML = 'Цена "до" меньше "от"';
			document.getElementById('w11').style.visibility = 'visible';
			document.getElementById('w10').style.visibility = 'hidden';
		} else
			{
				document.getElementById('w10').style.visibility = 'hidden';
				document.getElementById('w11').style.visibility = 'hidden';
			}
	}
	
	if (document.forma.op1.checked==0 && document.forma.op2.checked==0)
	{
		sm=0;
		document.getElementById('w22').style.visibility = 'visible';
	} else
		{
			document.getElementById('w22').style.visibility = 'hidden';
		}
		
	if (document.forma.name.value=='')
	{
		sm=0;
		document.getElementById('w31').style.visibility = 'visible';
	} else
		{
			document.getElementById('w31').style.visibility = 'hidden';
		}	
	if (document.forma.email.value=='')
	{
		sm=0;
		document.getElementById('w32').style.visibility = 'visible';
	} else
		{
			document.getElementById('w32').style.visibility = 'hidden';
		}
	
	
	if (sm==1) document.forma.submit();
		
}

function InsertPhoto(num,pos)
{
	document.getElementById('fotka').src = '/pix/'+ fpath[num];
	document.getElementById('pv'+pos).innerHTML = '<img src="/pix/prev/'+ fpath[CurrentPhoto]+'" onclick="InsertPhoto('+CurrentPhoto+','+pos+')">';
	CurrentPhoto = num;
}

function SendMsg()
{
	error = '';
	if (document.forma.topic.value=='' || document.forma.topic.value=='Тема') error = 'Укажите тему сообщения!';
	if (document.forma.message.value=='' || document.forma.message.value=='Текст сообщения') error = error+'&nbsp;&nbsp;&nbsp;&nbsp;Вы не написали сообщение!';
	if (error=='')
	{
		document.forma.submit();
	} else
		{
			document.getElementById('wrn').innerHTML = error;
		}
}

function CheckBoxes()
{
	x=1; flag = true; check=0;	
	while (flag==true)
	{
		if (document.getElementById('dbox'+x))
		{
			if (document.getElementById('dbox'+x).checked == 1) check=1;
		} else
			{
				flag=false;
			}
		x++;
	}
	if (check==1) 
	{
		document.getElementById('dbut').disabled = false;
	} else
		{
			document.getElementById('dbut').disabled = true;
		}
}

function RestorePass()
{
	error = '';
	if (document.forma.capt.value=='') error = '<p>Введите символы с картинки!</p>';
	if (document.forma.email.value=='') error = error+'<p>Укажите e-mail!</p>';
	if (error=='')
	{
		document.forma.submit();
	} else
		{
			document.getElementById('wrn').innerHTML = error;
		}
}

var InvId;
var InvState;

function SetInvisible(id,state)
{
	httpReqI=createHttpRequest();
    file = '/inv_ajax.php?id='+id+'&hidden='+state;
    sendRequestI(file);		
    InvId = id;
    InvState = state;
}

function sendRequestI(file)
{
    httpReqI.open('get',file);
    httpReqI.onreadystatechange = ChangeInv;
    httpReqI.send(null);
}


function ChangeInv()
{
	if (httpReqI.readyState==4)
    {
		if (InvState==1) document.getElementById('inv'+InvId).innerHTML = '<img src="/img/icons/9.gif" alt="Показывать ТС" title="Показывать ТС" onclick="SetInvisible('+InvId+',0);">';
		if (InvState==0) document.getElementById('inv'+InvId).innerHTML = '<img src="/img/icons/15.gif" alt="Не показывать ТС" title="Не показывать ТС" onclick="SetInvisible('+InvId+',1);">';
	} else
		{
			setTimeout('ChangeInv()',200);
		}
}

function MainSearch()
{
	if (document.forma.myprice.value!='' && document.forma.myprice.value>0) 
	{
		flag=true;
		if (document.forma.myprice.value<price_min) {document.getElementById('wwa').innerHTML = 'Минимальная цена '+price_min+'р.'; document.getElementById('wwa').style.display = 'block'; flag=false;}
		if (document.forma.myprice.value>price_max) {document.getElementById('wwa').innerHTML = 'Максимальная цена '+price_max+'р.'; document.getElementById('wwa').style.display = 'block'; flag=false;}
		if (flag==true) document.forma.submit();
	} else 
		{
			document.getElementById('wwa').style.display = 'block';
		}
}

var CurHide;
var CurHideState;

function HideCat(id,state)
{
	httpR=createHttpRequest();
	file = '/hidecat_ajax.php?id='+id+'&hidden='+state;
	sendR(file);		
	CurHide = id;
	CurHideState = state;
}

function sendR(file)
{
    httpR.open('get',file);
    httpR.onreadystatechange = ChangeHide;
    httpR.send(null);
}


function ChangeHide()
{
	if (httpR.readyState==4)
    {
		if (CurHideState==1) document.getElementById('hc'+CurHide).innerHTML = '<img src="/img/icons/9.gif" alt="Включить категорию" align="absmiddle" onclick="HideCat('+CurHide+',0);">';
		if (CurHideState==0) document.getElementById('hc'+CurHide).innerHTML = '<img src="/img/icons/15.gif" alt="Отключить категорию" align="absmiddle" onclick="HideCat('+CurHide+',1);">';
	} else
		{
			setTimeout('ChangeHide()',200);
		}
}

function MainType()
{
	if (document.getElementById('maintype').value=='inp') document.getElementById('TypeTD').innerHTML = '<input name="newtype" value="Введите тип ТС" onfocus="if(this.value==\'Введите тип ТС\') this.value=\'\';" onblur="if(this.value==\'\') this.value=\'Введите тип ТС\';">';
}

var httpReqT;

function sendRequestT(file)
{
    httpReqT.open('get',file);
    httpReqT.onreadystatechange = FillTpl;
    httpReqT.send(null);
}


function LoadTemplate()
{
	httpReqT=createHttpRequest();
    file = '/tpl_ajax.php?t_id='+document.forma.type.value+'&c_id='+document.forma.cat.value;    
    sendRequestT(file);				
}

function FillTpl()
{
	if (httpReqT.readyState==4)
    {
		if (document.getElementById('TAR')) document.getElementById('TAR').innerHTML = httpReqT.responseText;
	} else
		{
			setTimeout('FillTpl()',100);
		}
}

function SubmitMessage()
{
	sm=true;
	if (!checkEmpty(document.MessageForm.name.value)) 
		{
	sm=false;	
		}
	if (!checkEmpty(document.MessageForm.content.value)) 
		{
	sm=false;	
		}
	if (!checkEmpty(document.MessageForm.contacts.value)) 
		{
	sm=false;	
		}
	if (sm==true) {document.MessageForm.submit();} else {document.getElementById('wrn').style.display='inline';}
}


function SetBox()
{
	x=1; flag=true; chk=0;
	while (flag==true)
	{
		if (document.getElementById('bx'+x))
		{
			if(document.getElementById('bx'+x).checked==1) chk = 1;
		} else
			{
				flag = false;
			}
		x++;
	}
	if (chk==1) document.getElementById('SM').style.display = 'block';
	if (chk==0) document.getElementById('SM').style.display = 'none';
}

function ShowPhotoOne(path,width,height)
{
	int = document.getElementById('interlaced');
	int.style.height = document.documentElement.scrollHeight + 'px';
	int.style.visibility = 'visible';
	view = document.getElementById('ViewPhoto');
	vd = document.getElementById('Vdiv');
	foto = document.getElementById('Fotka');
	foto.innerHTML = '<img src="'+path+'" onclick="HidePhoto();">';
	view.style.width = width + 'px';
	vd.style.width = width + 'px';
	view.style.height = height + 30 + 'px';
	view.style.marginLeft = -Math.round(width/2) + 'px';
	view.style.marginTop = -Math.round(height/2) - 35 + document.documentElement.scrollTop + 'px';
	view.style.display = 'block';
}

function OrgClick()
{
	if (document.forma.org.checked==1)
	{
		document.getElementById('oinf').style.display = 'block';
		document.getElementById('noorg').style.display = 'none';
	} else
		{
		document.getElementById('oinf').style.display = 'none';
		document.getElementById('noorg').style.display = 'block';
		}
}

var ostatus = 0;

function ShowInf()
{
	if (ostatus==0)
	{
		document.getElementById('oo').style.display = 'block';
		ostatus=1;
	} else
		{
			document.getElementById('oo').style.display = 'none';
			ostatus=0;
		}
}

var GoUrl;
var Req;
	
function ClickBan(url,id)
{
	GoUrl = url;
	Req=createHttpRequest();
    file = '/click_ajax.php?id='+id;    
    sendR(file);				
}
	

function sendR(file)
{
    Req.open('get',file);
    Req.onreadystatechange = LinkGo;
    Req.send(null);
}

function LinkGo()
{
	if (Req.readyState==4)
    {
		document.location.href = GoUrl;
	} else
		{
			setTimeout('LinkGo()',100);
		}	
}


function LoadTemplate()
{
	httpReqT=createHttpRequest();
    file = '/tpl_ajax.php?t_id='+document.forma.type.value+'&c_id='+document.forma.cat.value;    
    sendRequestT(file);				
}	

function getBrowserInfo() {
    var t,v = undefined;
   
    if (window.chrome) t = 'Chrome';
    else if (window.opera) t = 'Opera';
    else if (document.all) {
        t = 'IE';
        var nv = navigator.appVersion;
        var s = nv.indexOf('MSIE')+5;
        v = nv.substring(s,s+1);
    }
    else if (navigator.appName) t = 'Netscape';
   
    return {type:t,version:v};
}



function bookmark(a){
    var url = window.document.location;
    var title = window.document.title;
    var b = getBrowserInfo();
   
    if (b.type == 'IE' && 8 >= b.version && b.version >= 4) window.external.AddFavorite(url,title);
    else if (b.type == 'Opera') {
        a.href = url;
        a.rel = "sidebar";
        a.title = url+','+title;
        return true;
    }
    else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
    else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
    return false;
} 

function PressEnter(obj,event)
{
       event = event || window.event;
        var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : null;
        
        if (keyCode == 13) if (document.LogForm.e_login.value!='' && document.LogForm.e_password.value!='' && document.LogForm.e_login .value!='логин' && document.LogForm.e_password.value!='пароль') document.LogForm.submit();
}

function format_price(_num, _sep)
{
    if (_num.length <= 3) return _num;
    var _count = _num.length;
    var _num_parser = '';
    var _count_digits = 0;
    for (var _p = (_count - 1); _p >= 0; _p--){
      var _num_digit = _num.substr(_p, 1);
      if (_count_digits % 3 == 0 && _count_digits != 0 && !isNaN(parseFloat(_num_digit))) _num_parser = _sep + _num_parser;
      _num_parser = _num_digit + _num_parser;
      _count_digits++;
      }
    return _num_parser;
 }




