var isIE4=(navigator.appName.indexOf("Microsoft")==0);
if (navigator.userAgent.indexOf("Opera")>-1)
	var isOpera=true;
String.prototype.trim=new Function("return this.replace(/^\\s+|\\s+$/g,'')");
var timeout_id;
inhtObject=function (name,value)
	{
	this.name=name;
	this.value=value;
	}
colorObject=function ()
	{
	this.color1='#ff0000';
	this.color2='#737379';
	}
	
	Array.prototype.indexOf=function(obj)
{
var result=-1;
for (var i=0;i<this.length;i++)
	{
	if(this[i]==obj)
		{
		result=i;
		break;
		}
	}
return result;
}
rowobject = function(id,ballkoeff,ball,koeff)
{
this.id=id;
this.elem=document.getElementById(id);
this.order=this.elem.rowIndex;
this.html=this.elem.innerHTML;
this.ballkoeff=ballkoeff;
this.ball=ball;
this.koeff=koeff;
}
function compare (a,b)
{
return b[sortflag]-a[sortflag];
}
function checkTr()
{
myTrs.sort(compare);
var myTable=document.getElementById('sorttable');
while(myTable.rows.length>1&&!isIE4)
	{
	myTable.deleteRow(1);
	}
var data;
var i;
for (i=0;i<100;i++)
	{
	data=i+1;
	if (i%2!=0)myTrs[i].elem.className='tab2';
	else myTrs[i].elem.className='tab3';
	myTable.appendChild(myTrs[i].elem);
	myTrs[i].order=data;
	}
}


Array.prototype.contains=function (obj)
{
return(this.indexOf(obj)>=0);
}

function normalyzeUrl(url)
{
		var regexp=/http:/gi;
		url=url.replace(regexp,'');
		var regexp=/:/gi;
		url=url.replace(regexp,'');
		var regexp=/\//gi;
		url=url.replace(regexp,'');
		var regexp=/\bwww\./gi;
		url=url.replace(regexp,'');
		url='http://'+url;
return url;
}	
var myBlocks=new Array();	
function voteMe(id1,id2,id3,evt)
{
	if (isIE4)
	{
	var x=event.offsetX;
	}
else
	{
	var x=evt.pageX-evt.target.offsetLeft-document.body.offsetLeft;
	}
var pos=parseInt((x-121)/12)*12;
var ball;
if (x>95) ball=5;
else if (x<12&&x>0) ball=1;
else ball=parseInt((x+25)/25);
if (ball==0)ball=1;
pos=ball*24-121;
document.getElementById(id2).value=ball;
document.getElementById(id2).inpuObj.value=ball;
document.getElementById(id2).inpuObj.beginload=true;
document.getElementById(id2).inpuObj.error=false;
document.getElementById(id2).inpuObj.diverr.innerHTML='';
document.getElementById(id2).inpuObj.formEl.inpuObj.beginload=true;
document.getElementById(id1).style.backgroundPosition=pos+'px';
document.getElementById(id3).innerHTML=ball;
document.getElementById(id2).inpuObj.checkMe();
}

var myUrl=new Array();


function checkmyBlock()
{
var i=0;
var len=myBlocks.length;
var elem;
var name;
for(i=0;i<len;i++)
	{
	elem=myBlocks[i];
	name='RegForm.'+elem+'=true;';
	eval(name);
	name='RegForm.'+elem+'ready=false;';
	eval(name);
	} 
RegForm.sending=false;
if (RegForm.timeout_id)clearTimeout(RegForm.timeout_id);	
}

function selectMe(id,elid,compid)
	{
	var url='/index.'+'php?action=check&what=choose';
	var par=new inhtObject('element',elid);
	var urlss=urls.join(',');
	var par1=new inhtObject('url',urlss);
	var par2=new inhtObject('tochange',compid);
	var pars=new Array (par,par1,par2);
	var sender= new ContentLoader(url,'POST',pars,id);
	}
function selectMeComp(id,elid,compid)
	{
	var url='/index.'+'php?action=check&what=choosecomp';
	var par=new inhtObject('element',elid);
	var urlss=conurls.join(',');
	var par1=new inhtObject('url',urlss);
	var par2=new inhtObject('tochange',compid);
	var pars=new Array (par,par1,par2);
	var sender= new ContentLoader(url,'POST',pars,id);
	}
function selectMeTend(id,elid,compid)
	{
	var url='/index.'+'php?action=check&what=choosetend';
	var par=new inhtObject('element',elid);
	var urlss=tenurls.join(',');
	var par1=new inhtObject('url',urlss);
	var par2=new inhtObject('tochange',compid);
	var pars=new Array (par,par1,par2);
	var sender= new ContentLoader(url,'POST',pars,id);
	}
		
	
function viewL(evt,id)
{
evt=(evt)?evt:(window.event)?window.event : "";
var x=parseInt(evt.clientX);
var sdv=window.scrollY;

if (isNaN(sdv)) sdv=document.getElementById('maincont').scrollTop;
var y=parseInt(evt.clientY+sdv);
document.getElementById(id).style.visibility='visible';
document.getElementById(id).style.zIndex='2';
document.getElementById(id).style.left=x-440 + 'px';
document.getElementById(id).style.top=y+20 + 'px';
	}

	function viewLL(evt,id)
{
evt=(evt)?evt:(window.event)?window.event : "";
var x=parseInt(evt.clientX);
var sdv=window.scrollY;

if (isNaN(sdv)) sdv=document.getElementById('maincont').scrollTop;
var y=parseInt(evt.clientY+sdv);
document.getElementById(id).style.left=x-440 + 'px';
document.getElementById(id).style.top=y-25 + 'px';
	}

	
function drop(id)
{
document.getElementById(id).style.visibility='hidden';
document.getElementById(id).style.zIndex='-2';
	}	

	
var colobj=new colorObject();
propObject = function(minvalue,requred,ajax,defaultValue,linked,defaultFill,testetTogether,beginload,testedTogetherJs)
{
this.minvalue=minvalue;
this.requred=requred;
this.ajax=ajax;
this.defaultValue=defaultValue;
this.linked=linked;
this.defaultFill=defaultFill;
this.testetTogether=testetTogether;
this.beginload=beginload;
this.testedTogetherJs=testedTogetherJs;
}

var Properties=new Array();

var myForm;

ContentLoader=function (url,method,params,id,component)
	{
	this.component=component;
//	this.component=false;
	this.head=false;
	this.contid=id;
	this.req=null;
	this.name='ContentLoader';
	this.url=url;
	this.method=method;
	this.params=params;
	this.loadXMLDoc();
	}

ContentLoader.prototype.loadXMLDoc=function ()
		{
		if (!this.method) this.method="GET";
		if (this.method=="POST")
			{
			this.head='application/x-www-form-urlencoded';
			var parL=this.params.length;
			if (parL>0)
				{
				var par= this.params[0].name +'=' + encodeURIComponent(this.params[0].value);
				for (i=1;i<parL;i++)
					{
					par+='&' + this.params[i].name +'=' + encodeURIComponent( this.params[i].value);
					}
				}
			else par='';
			}
		else
			{
			par='';
			}
		try
			{
        this.req=new ActiveXObject('Msxml2.XMLHTTP');
    		}
		catch (e)
			{
			try
				{
	            this.req=new ActiveXObject('Microsoft.XMLHTTP');
    	    	}
				catch (e)
					{
					if(window.XMLHttpRequest)
						{
						this.req=new XMLHttpRequest();
            			}
        			}
    		}	
		if (this.req)
			{
			if (this.req.overrideMimeType)
				{
        		this.req.overrideMimeType('text/html');
        		}
			var loader=this;
			
			this.req.onreadystatechange=function ()
			{
			loader.onReadyState.call(loader);
			}
			this.req.open (this.method,this.url,true);
			if (this.head)
				{
				this.req.setRequestHeader("Content-Type",this.head);
				this.req.setRequestHeader("Content-length", parL);
      			this.req.setRequestHeader("Connection", "close");
				}
			this.req.send (par);
			}
		}
		
ContentLoader.prototype.onReadyState=function ()
		{
		var req=this.req;
		var ready=req.readyState;
		if (ready==4)
			{
			var httpStatus=req.status;
			if (httpStatus==200||httpStatus==0)
				{
				var div=document.getElementById(this.contid);
				var data=req.responseText;
				var arr = data.split("myperfectdevidehtml");
				var unchange=false;
				if (arr.length>1)
					{
					if (arr[1].length>0)div.innerHTML=arr[1];
					}
				arr = data.split("myperfectdevidejavascript");
				if (arr.length>1)
					{
					var theScript;
					if (arr[1].length>0)
						{
						theScript= document.createElement('script');
						theScript.type = "text/javascript";
						theScript.text = arr[1];
						div=document.getElementById('js');
						div.innerHTML='';
						div.appendChild(theScript);
						}
					}
				if (this.component&&this.component.childs&&this.component.childs.length>0&&this.component.childs[this.component.childs.length-1])
					{
					this.component.childs[this.component.childs.length-1].onclick=this.component.sendForm;
					}
					document.body.style.cursor='auto';

				}
			}
		}

function setMySend(object, value)
	{
	document.getElementById('filename').value=value;
	document.getElementById('filename').inpuObj.wait=false;
	}
function setRegions()
{
var elem=document.getElementById('regionsel');
var anelcont=document.getElementById('anotheregioncont');
var anel=document.getElementById('anotheregion');

if (elem.value=='Другой')
	{
	if (anel.value.length==0||anel.value=='Указать в случае если выбран "Другой" регион')
		{
		anel.value='Указать в случае если выбран "Другой" регион';
		anel.inpuObj.beginload=false;
		anel.inpuObj.diverr.innerHTML='';
		anel.inpuObj.error=false;
		anel.inpuObj.domEl.style.color=anel.inpuObj.color;	
		}
	anel.inpuObj.requred=true;
	anel.inpuObj.minvalue=0;
	anelcont.style.display='block';
	}
else
	{
	anel.inpuObj.diverr.innerHTML='';
	anel.inpuObj.beginload=true;
	anel.inpuObj.requred=false;
	anel.inpuObj.minvalue=-1;
	anelcont.style.display='';
	anel.inpuObj.domEl.style.color=anel.inpuObj.color;	
	}	
}	
function checkurl()
{
var urlel=document.getElementById('url');
var emailel=document.getElementById('remail');
var urlo=urlel.inpuObj;
var emailo=emailel.inpuObj;
var url=urlel.value;
var email=emailel.value;
var error=true;
if (emailo.beginload&&urlo.beginload)
	{
	if (email.charAt(email.length-1)!='@')
		{
		var regexp=/http:/gi;
		url=url.replace(regexp,'');
		var regexp=/\//gi;
		url=url.replace(regexp,'');
		var regexp=/\bwww\./gi;
		url=url.replace(regexp,'');
		regexp = eval("/" + url + "/gi");
		var result=email.replace(regexp,'');
		if (result.charAt(result.length-1)=='@')
		error=false;
		}
	if (!error)
		{
		if (emailo.diverr.innerHTML.length=='')
			{
			urlo.diverr.innerHTML='';
			urlo.error=false;
			urlo.domEl.style.color=urlo.color;	
			}
		else
			{
			urlo.error=true;
			urlo.domEl.style.color=urlo.errorcolor;	
			urlo.diverr.innerHTML='Вы неправильно заполнили поле URL официального сайта';
			}
		}
	else
		{
		urlo.error=true;
		urlo.domEl.style.color=urlo.errorcolor;	
		urlo.diverr.innerHTML='URL почтового домена должен совпадать с URL официального сайта компании';
		}
	}
}	

function cms(object)
{
if(object)
	{ 
	if (object.value=='да')
		{
		RegForm.childobjs[1].diverr.innerHTML='';
		RegForm.childobjs[1].value='да';
		RegForm.childobjs[1].beginload=true;
		RegForm.childobjs[1].error=false;
		RegForm.childobjs[1].error=false;
		RegForm.childobjs[1].diverr.innerHTML='';
		RegForm.beginload=true;
		document.getElementById('visio'+RegForm.childobjs[2].id).style.display='block';
		RegForm.childobjs[2].requred=true;
		if (RegForm.childobjs[2].value=='')RegForm.childobjs[2].beginload=false;
		}
	if (object.value=='нет')
		{
		RegForm.childobjs[2].requred=false;
		RegForm.childobjs[2].beginload=true;
		RegForm.childobjs[2].error=false;
		RegForm.childobjs[3].requred=false;
		RegForm.childobjs[3].beginload=true;
		RegForm.childobjs[3].error=false;
		RegForm.childobjs[1].value='нет';
		RegForm.childobjs[1].diverr.innerHTML='';
		RegForm.beginload=true;
		document.getElementById('visio'+RegForm.childobjs[2].id).style.display='none';
		RegForm.childobjs[1].beginload=true;
		RegForm.childobjs[1].error=false;
		}
	if (object.value=='Собственная разработка')
		{
		document.getElementById('visio'+RegForm.childobjs[3].id).style.display='none';
		RegForm.childobjs[3].requred=false;
		RegForm.childobjs[3].beginload=true;
		RegForm.childobjs[3].error=false;
		RegForm.childobjs[2].value='Собственная разработка';
		RegForm.childobjs[2].diverr.innerHTML='';
		RegForm.beginload=true;
		RegForm.childobjs[2].beginload=true;
		RegForm.childobjs[2].error=false;
		}
	if (object.value=='Внешняя коробочная CMS')
		{
		document.getElementById('visio'+RegForm.childobjs[3].id).style.display='block';
		RegForm.childobjs[3].requred=true;
		if (RegForm.childobjs[3].value=='')RegForm.childobjs[3].beginload=false;
		RegForm.childobjs[3].diverr.innerHTML='';
	
		RegForm.childobjs[2].value='Внешняя коробочная CMS';
		RegForm.childobjs[2].diverr.innerHTML='';
		RegForm.beginload=true;
		RegForm.childobjs[2].beginload=true;
		RegForm.childobjs[2].error=false;
		}
	if (object.value=='Используем свою внутреннюю CMS и коробочные решения')
		{
		document.getElementById('visio'+RegForm.childobjs[3].id).style.display='block';
		RegForm.childobjs[3].requred=true;
		if (RegForm.childobjs[3].value=='')RegForm.childobjs[3].beginload=false;
		RegForm.childobjs[3].diverr.innerHTML='';
		
		RegForm.childobjs[2].value='Используем свою внутреннюю CMS и коробочные решения';
		RegForm.childobjs[2].diverr.innerHTML='';
		RegForm.beginload=true;
		RegForm.childobjs[2].beginload=true;
		RegForm.childobjs[2].error=false;
		}
	}
}

function cmsinit()
{
if (RegForm.childobjs[1].value=='нет'||RegForm.childobjs[1].value=='')
	{
	RegForm.childobjs[2].diverr.innerHTML='';
	RegForm.childobjs[3].diverr.innerHTML='';
	RegForm.childobjs[2].requred=false;
	RegForm.childobjs[2].beginload=true;
	RegForm.childobjs[2].error=false;
	RegForm.childobjs[3].requred=false;
	RegForm.childobjs[3].beginload=true;
	RegForm.childobjs[3].error=false;
	if (RegForm.childobjs[1].value=='нет')	RegForm.beginload=true;
	document.getElementById('visio'+RegForm.childobjs[2].id).style.display='none';
	}
else
	{
	RegForm.childobjs[2].diverr.innerHTML='';
	RegForm.childobjs[3].diverr.innerHTML='';
	RegForm.beginload=true;
	document.getElementById('visio'+RegForm.childobjs[2].id).style.display='block';
	RegForm.childobjs[2].requred=true;
	if (RegForm.childobjs[2].value=='')RegForm.childobjs[2].beginload=false;
	if (RegForm.childobjs[2].value=='Собственная разработка')
		{
		document.getElementById('visio'+RegForm.childobjs[3].id).style.display='none';
		RegForm.childobjs[3].requred=false;
		RegForm.childobjs[3].beginload=true;
		RegForm.childobjs[3].error=false;
		}
	else
		{
		document.getElementById('visio'+RegForm.childobjs[3].id).style.display='block';
		RegForm.childobjs[3].requred=true;
		if (RegForm.childobjs[3].value=='')RegForm.childobjs[3].beginload=false;
		}
	}
}
var urls=new Array();	


function checkcompaniesinit()
{
var i=0;
var place;
var ballid;
while(i<10)
	{
	RegForm.childobjs[3*i].requred=true;
	RegForm.childobjs[3*i+1].requred=true;
	RegForm.childobjs[3*i+2].requred=true;
	RegForm.childobjs[3*i].minvalue=0;
	RegForm.childobjs[3*i+1].minvalue=0;
	RegForm.childobjs[3*i+2].minvalue=0;
	RegForm.childobjs[3*i].ajax=false;
	RegForm.childobjs[3*i+1].ajax=false;
	RegForm.childobjs[3*i+2].ajax=false;

	place=i+1;
	RegForm.childobjs[3*i].defaultValue='Оценка компании, занявшей ' + place + ' место';
	RegForm.childobjs[3*i+1].defaultValue='Название компании, занявшей ' + place + ' место';
	RegForm.childobjs[3*i+2].defaultValue='URL компании, занявшей ' + place + ' место';;
	ballid='ball'+RegForm.childobjs[3*i+1].name;
	RegForm.childobjs[3*i].value=parseInt(document.getElementById(ballid).innerHTML);
	if (RegForm.childobjs[3*i].value>0)RegForm.childobjs[3*i].beginload=true;
	else RegForm.childobjs[3*i].beginload=false;
	if (RegForm.childobjs[3*i+1].value!='Название компании') RegForm.childobjs[3*i+1].beginload=true;
	else RegForm.childobjs[3*i+1].beginload=false;

	if (RegForm.childobjs[3*i+2].value!='URL сайта')
		{
		urls[i]=RegForm.childobjs[3*i+2].value;
		RegForm.childobjs[3*i+2].beginload=true;
		}
	else 	RegForm.childobjs[3*i+2].beginload=false;
	
	RegForm.childobjs[3*i].testetTogether=true;
	RegForm.childobjs[3*i+1].testetTogether=true;
	RegForm.childobjs[3*i+2].testetTogether=true;
	RegForm.childobjs[3*i].linked=false;
	RegForm.childobjs[3*i+1].linked=false;
	RegForm.childobjs[3*i+2].linked=false;
	RegForm.childobjs[3*i].defaultFill=false;
	RegForm.childobjs[3*i+1].defaultFill=false;
	RegForm.childobjs[3*i+2].defaultFill=false;
	RegForm.childobjs[3*i].testedTogetherJs=checkcompanies;
	RegForm.childobjs[3*i+1].testedTogetherJs=checkcompanies;
	RegForm.childobjs[3*i+2].testedTogetherJs=checkcompanies;
	
	i++;
	}
	RegForm.top100=true;
	if (!myBlocks.contains('top100'))myBlocks[myBlocks.length]='top100';

}

function checkcompanies()
{
var i;
var url;
var error=false;
var ball;
var cname;
for (i=0;i<10;i++)
	{
	url=RegForm.childobjs[3*i+2].value;
	if (url.length>0&&url!='URL сайта'&&RegForm.childobjs[3*i+2].beginload)
		{
		url=normalyzeUrl(url);

		var pos=urls.indexOf(url);

		if (pos<0||pos==i)
			{

			if (url!=myCompany)
				{
				urls[i]=url;
				RegForm.childobjs[3*i+2].error=false;
				RegForm.childobjs[3*i+2].diverr.innerHTML='';
				}
			else
				{
				error=true;
				RegForm.childobjs[3*i+2].error=true;
				RegForm.childobjs[3*i+2].diverr.innerHTML='Голосование за свою компанию запрещено. Измените URL';
				}
			}
		else
			{
			if (pos>=0)urls[i]='';
			error=true;
			RegForm.childobjs[3*i+2].error=true;
			RegForm.childobjs[3*i+2].diverr.innerHTML='Вы уже проголосовали за эту компанию. Измените URL';
			}
		}
	else error=true;
	ball=RegForm.childobjs[3*i].value;
	if (ball==0||!RegForm.childobjs[3*i].beginload) error=true;
	cname=RegForm.childobjs[3*i+1].value;
	if (cname.length==0||cname=='Название компании'||!RegForm.childobjs[3*i+1].beginload) error=true;
	else
		{
		RegForm.childobjs[3*i+1].error=false;
		RegForm.childobjs[3*i+1].diverr.innerHTML='';
		} 
	}
if (!error)
	{
	if (RegForm.sending)
		{
		RegForm.top100=false;
		var ajaxurl='/index.'+'php?action=check&what=top';
		var pars=new Array ();
		var par=new inhtObject('top','top100');
		pars[pars.length]=par;
		par=new inhtObject('block','top100');
		pars[pars.length]=par;
		for (i=0;i<10;i++)
			{
			par=new inhtObject(RegForm.childobjs[3*i].name,RegForm.childobjs[3*i].value);
			pars[pars.length]=par;
			par=new inhtObject(RegForm.childobjs[3*i+1].name,RegForm.childobjs[3*i+1].value);
			pars[pars.length]=par;
			par=new inhtObject(RegForm.childobjs[3*i+2].name,RegForm.childobjs[3*i+2].value);
			pars[pars.length]=par;
			}
		var sender= new ContentLoader(ajaxurl,'POST',pars,RegForm.childobjs[0].divid,RegForm);
		}
	}
}

var conurls=new Array();
var tenurls=new Array();


function checktenders()
{
var i;
var url;
var error=false;
var ball;
var cname;
for (i=19;i<22;i++)
	{
	url=RegForm.childobjs[2*i].value;
	if (url.length>0&&url!='URL сайта'&&RegForm.childobjs[2*i].beginload)
		{
		url=normalyzeUrl(url);
		var pos=tenurls.indexOf(url);

		if (pos<0||pos==i)
			{

			
			if (url!=myCompany)
				{
				tenurls[i]=url;
				RegForm.childobjs[2*i].error=false;
				RegForm.childobjs[2*i].diverr.innerHTML='';
				}
			else
				{
				error=true;
				RegForm.childobjs[2*i].error=true;
				RegForm.childobjs[2*i].diverr.innerHTML='Выбор своей компании запрещен. Измените URL';
				}
			}
		else
			{
			if (pos>=0)tenurls[i]='';
			error=true;
			RegForm.childobjs[2*i].error=true;
			RegForm.childobjs[2*i].diverr.innerHTML='Вы уже выбрали эту компанию. Измените URL';
			}
		}
	else error=true;
	cname=RegForm.childobjs[2*i-1].value;
	if (cname.length==0||cname=='Название компании'||!RegForm.childobjs[2*i-1].beginload) error=true;
		else
		{
		RegForm.childobjs[2*i-1].error=false;
		RegForm.childobjs[2*i-1].diverr.innerHTML='';
		} 
	}
if (!error)
	{
	if (RegForm.sending)
		{
		RegForm.tenders=false;
		var ajaxurl='/index.'+'php?action=check&what=top';
		var pars=new Array ();
		var par=new inhtObject('top','tenders');
		pars[pars.length]=par;
		par=new inhtObject('block','tenders');
		pars[pars.length]=par;
		for (i=19;i<22;i++)
			{
			par=new inhtObject(RegForm.childobjs[2*i].name,RegForm.childobjs[2*i].value);
			pars[pars.length]=par;
			par=new inhtObject(RegForm.childobjs[2*i-1].name,RegForm.childobjs[2*i-1].value);
			pars[pars.length]=par;
			}
		var sender= new ContentLoader(ajaxurl,'POST',pars,RegForm.childobjs[37].divid,RegForm);
		}
	}

}

function checktendersinit()
{
var i=19;
var place;
while(i<22)
	{
	RegForm.childobjs[2*i-1].requred=true;
	RegForm.childobjs[2*i].requred=true;
	RegForm.childobjs[2*i-1].minvalue=0;
	RegForm.childobjs[2*i].minvalue=0;
	RegForm.childobjs[2*i-1].ajax=false;
	RegForm.childobjs[2*i].ajax=false;
	if (RegForm.childobjs[2*i-1].value!='Название компании') RegForm.childobjs[2*i-1].beginload=true;
	else RegForm.childobjs[2*i-1].beginload=false;
	if (RegForm.childobjs[2*i].value!='URL сайта')
		{
		tenurls[i]=RegForm.childobjs[2*i].value;
		RegForm.childobjs[2*i].beginload=true;
		}
	else RegForm.childobjs[2*i].beginload=false;
	

	RegForm.childobjs[2*i].testetTogether=true;
	RegForm.childobjs[2*i-1].testetTogether=true;
	RegForm.childobjs[2*i].linked=false;
	RegForm.childobjs[2*i-1].linked=false;
	RegForm.childobjs[2*i].defaultFill=false;
	RegForm.childobjs[2*i-1].defaultFill=false;
	RegForm.childobjs[2*i].testedTogetherJs=checktenders;
	RegForm.childobjs[2*i-1].testedTogetherJs=checktenders;
	place=i-18;
	RegForm.childobjs[2*i].defaultValue='URL компании № ' + place + ', которая выигрывала у вас тендеры';
	RegForm.childobjs[2*i-1].defaultValue='Название компании № ' + place + ',  которая выигрывала у вас тендеры';
	i++;
	}
RegForm.tenders=true;
	if (!myBlocks.contains('tenders'))myBlocks[myBlocks.length]='tenders';

}

function checkcon()
{

var i;
var url;
var error=false;
var ball;
var cname;
for (i=16;i<19;i++)
	{
	url=RegForm.childobjs[2*i].value;
	
	if (url.length>0&&url!='URL сайта'&&RegForm.childobjs[2*i].beginload)
		{
		url=normalyzeUrl(url);

		var pos=conurls.indexOf(url);

		if (pos<0||pos==i)
			{

			
			if (url!=myCompany)
				{
				conurls[i]=url;
				RegForm.childobjs[2*i].error=false;
				RegForm.childobjs[2*i].diverr.innerHTML='';
				}
			else
				{
				error=true;
				RegForm.childobjs[2*i].error=true;
				RegForm.childobjs[2*i].diverr.innerHTML='Выбор свой компании в качестве своего конкурента запрещен. Измените URL';
				}
			}
		else
			{
			if (pos>=0)conurls[i]='';
			error=true;
			RegForm.childobjs[2*i].error=true;
			RegForm.childobjs[2*i].diverr.innerHTML='Вы уже выбрали эту компанию. Измените URL';
			}
		}
	else error=true;
	cname=RegForm.childobjs[2*i-1].value;
	if (cname.length==0||cname=='Название компании'||!RegForm.childobjs[2*i-1].beginload) error=true;
	else
		{
		RegForm.childobjs[2*i-1].error=false;
		RegForm.childobjs[2*i-1].diverr.innerHTML='';
		} 
	}
if (!error)
	{
		if (RegForm.sending)
		{
		RegForm.concurents=false;
		var ajaxurl='/index.'+'php?action=check&what=top';
		var pars=new Array ();
		var par=new inhtObject('top','concurents');
		pars[pars.length]=par;
		par=new inhtObject('block','concurents');
		pars[pars.length]=par;
		for (i=16;i<19;i++)
			{
			par=new inhtObject(RegForm.childobjs[2*i].name,RegForm.childobjs[2*i].value);
			pars[pars.length]=par;
			par=new inhtObject(RegForm.childobjs[2*i-1].name,RegForm.childobjs[2*i-1].value);
			pars[pars.length]=par;
			}
		var sender= new ContentLoader(ajaxurl,'POST',pars,RegForm.childobjs[31].divid,RegForm);
		}

	}

}
function checkconinit()
{

var i=16;
var place;
while(i<19)
	{
	RegForm.childobjs[2*i-1].requred=true;
	RegForm.childobjs[2*i].requred=true;
	RegForm.childobjs[2*i-1].minvalue=0;
	RegForm.childobjs[2*i].minvalue=0;
	RegForm.childobjs[2*i-1].ajax=false;
	RegForm.childobjs[2*i].ajax=false;
	if (RegForm.childobjs[2*i-1].value!='Название компании') RegForm.childobjs[2*i-1].beginload=true;
	else RegForm.childobjs[2*i-1].beginload=false;
	if (RegForm.childobjs[2*i].value!='URL сайта')
		{
		conurls[i]=RegForm.childobjs[2*i].value;
		RegForm.childobjs[2*i].beginload=true;
		}
	else RegForm.childobjs[2*i].beginload=false;

	
	RegForm.childobjs[2*i].testetTogether=true;
	RegForm.childobjs[2*i-1].testetTogether=true;
	RegForm.childobjs[2*i].linked=false;
	RegForm.childobjs[2*i-1].linked=false;
	RegForm.childobjs[2*i].defaultFill=false;
	RegForm.childobjs[2*i-1].defaultFill=false;
	RegForm.childobjs[2*i].testedTogetherJs=checkcon;
	RegForm.childobjs[2*i-1].testedTogetherJs=checkcon;
	place=i-15;
	RegForm.childobjs[2*i].defaultValue='Название компании № ' + place + ', которую вы считаете своим конкурентом';
	RegForm.childobjs[2*i-1].defaultValue='URL компании № ' + place + ', которую вы считаете своим конкурентом';
	i++;
	}

	if (!myBlocks.contains('concurents'))myBlocks[myBlocks.length]='concurents';

	RegForm.concurents=true;
}

chekf=function (domEl,name)
	{
	this.name=name;
	this.id=domEl.id;
	this.url='/index.'+'php?action=check&what='+this.id;
	this.domEl=domEl;
	this.childs=this.domEl.elements;
	this.elemNumb=this.childs.length;
	this.divid=this.domEl.parentNode.id;
	this.diverr=this.id+'err';
	this.childobjs=new Array();
	this.childNumb=this.childobjs.length;
	this.beginload=false;
	this.domEl.inpuObj=this;
	this.domEl.onsubmit=this.sendForm;
	this.error=false;
	this.wait=false;
	this.top100=false;
	this.tenders=false;
	this.concurents=false;
	this.top100ready=true;
	this.tendersready=true;	
	this.concurentsready=true;
	this.timeout_id;
	this.sending=false;
	}
chekf.prototype.checkError=function()
		{
		this.error=false;
		if (document.getElementById(this.diverr).innerHTML.length>0)
		document.getElementById(this.diverr).innerHTML='';
		if (this.beginload)
			{
			var inner='';
			for (var i=0;i<this.childNumb;i++)
				if (this.childobjs[i].error==true)
					{
					this.error=true;
					}
				else
					{
					if (!this.childobjs[i].beginload&&this.childobjs[i].requred)
						{
						if (this.childobjs[i].diverr)this.childobjs[i].diverr.innerHTML='Вы не заполнили обязательное поле ' + this.childobjs[i].defaultValue;	
						else inner=inner + '<br>Вы не заполнили обязательное поле ' + this.childobjs[i].defaultValue;						
						this.error=true;
						}
					}
			if (inner.length>0) document.getElementById(this.diverr).innerHTML=inner;
			}
		else
			{
			this.error=true;
			document.getElementById(this.diverr).innerHTML='Вы не заполнили форму';
			}
		}

chekf.prototype.checkWait=function()
		{
		this.wait=false;
		for (var i=0;i<this.childNumb;i++)
			if (this.childobjs[i].wait)
				{
				this.wait=true;
				break;
				}
		}

	
chekf.prototype.prepareForm=function(){
	for (var i=0;i<this.elemNumb;i++)
		{
		if (this.childs[i].value==this.childs[i].defaultValue)this.childs[i].value='';
		}

}
chekf.prototype.createForm=function()
	{
	var prl=Properties.length;
	var val;
	for (var i=0;i<this.elemNumb;i++)
		{
		if (this.childs[i].type=='radio')
			{
			if (this.childobjs.length==0||this.childobjs[this.childobjs.length-1].id!=this.childs[i].name)
				{
				this.childobjs[this.childobjs.length]=new chekEl(this.childs[i]);
					if (Properties[this.childs[i].name])
					{
					this.childobjs[this.childobjs.length-1].minvalue=Properties[this.childs[i].name].minvalue;
					this.childobjs[this.childobjs.length-1].requred=Properties[this.childs[i].name].requred;
					this.childobjs[this.childobjs.length-1].ajax=Properties[this.childs[i].name].ajax;
					this.childobjs[this.childobjs.length-1].defaultValue=Properties[this.childs[i].name].defaultValue;
					this.childobjs[this.childobjs.length-1].linked=Properties[this.childs[i].name].linked;
					this.childobjs[this.childobjs.length-1].defaultFill=Properties[this.childs[i].name].defaultFill;
					this.childobjs[this.childobjs.length-1].testetTogether=Properties[this.childs[i].name].testetTogether;
					this.childobjs[this.childobjs.length-1].beginload=Properties[this.childs[i].name].beginload;
					this.childobjs[this.childobjs.length-1].testedTogetherJs=Properties[this.childs[i].name].testedTogetherJs;
					val=this.childobjs[this.childobjs.length-1].value;
					this.childobjs[this.childobjs.length-1].value='';
					this.childobjs[this.childobjs.length-1].domEl.value=val;
					this.childobjs[this.childobjs.length-1].id=this.childs[i].name;
					}

				}
			if (this.childs[i].checked)
				{
				this.childobjs[this.childobjs.length-1].value=this.childs[i].value;
				}
			}
		else
			{
			this.childobjs[this.childobjs.length]=new chekEl(this.childs[i]);
			if (Properties[this.childobjs[this.childobjs.length-1].id])
				{
				this.childobjs[this.childobjs.length-1].minvalue=Properties[this.childs[i].id].minvalue;
				this.childobjs[this.childobjs.length-1].requred=Properties[this.childs[i].id].requred;
				this.childobjs[this.childobjs.length-1].ajax=Properties[this.childs[i].id].ajax;
				this.childobjs[this.childobjs.length-1].defaultValue=Properties[this.childs[i].id].defaultValue;
				this.childobjs[this.childobjs.length-1].linked=Properties[this.childs[i].id].linked;
				this.childobjs[this.childobjs.length-1].defaultFill=Properties[this.childs[i].id].defaultFill;
				this.childobjs[this.childobjs.length-1].testetTogether=Properties[this.childs[i].id].testetTogether;
				this.childobjs[this.childobjs.length-1].beginload=Properties[this.childs[i].id].beginload;
				this.childobjs[this.childobjs.length-1].testedTogetherJs=Properties[this.childs[i].id].testedTogetherJs;
				if (this.childs[i].type=='textarea'&&this.childs[i].value.length>0)	this.childobjs[this.childobjs.length-1].beginload=true;

				}
			}
		}
	this.childNumb=this.childobjs.length;
	}
chekf.prototype.clearForm=function()
	{
	for (var i=0;i<this.elemNumb;i++)
		{
		this.childs[i].value=this.childs[i].clearMe();
		}
	}

chekf.prototype.checkForm=function()
	{
	for (var i=0;i<this.elemNumb;i++)
		{
		this.childs[i].CheckMe();
		}
	}
chekf.prototype.sendForm=function(){
if (!this.id)
	{
var inpuObj=this.inpuObj.formEl.inpuObj;
	}
else
	{
	var inpuObj=this;
	}
	
//var cmd=inpuObj.name+'.sendForm()';
var cmd='RegForm.sendForm()';
inpuObj.sending=true;

inpuObj.checkWait();
if (!inpuObj.wait)
	{
	if (inpuObj.timeout_id)clearTimeout(inpuObj.timeout_id);
	inpuObj.checkError();
	if (!inpuObj.error)
		{
		if (inpuObj.top100)
			{
			inpuObj.top100ready=false;
			inpuObj.top100=false;
			checkcompanies();
			}
		if (inpuObj.tenders)
			{
			inpuObj.tendersready=false;
			inpuObj.tenders=false;
			checktenders();
			}
		if (inpuObj.concurents)
			{
			inpuObj.concurentsready=false;
			inpuObj.concurents=false;
			checkcon();
			
			}
		if (inpuObj.top100ready&&inpuObj.tendersready&&inpuObj.concurentsready)
			{
			var name;
			var name1;
			var name2;
			var arrmypar=''
			if (inpuObj.timeout_id)clearTimeout(inpuObj.timeout_id);
			for (var i=0;i<inpuObj.elemNumb;i++)
				{
				if (inpuObj.domEl.elements[i].type!='radio'||(inpuObj.domEl.elements[i].type=='radio'&&inpuObj.domEl.elements[i].checked))
					{
					name='var par'+i;
					name2='par'+i;
					name1=name+'= new inhtObject(inpuObj.domEl.elements[i].name,inpuObj.domEl.elements[i].value);';
					eval(name1);
					arrmypar=arrmypar+','+name2;
					}
				}
			arrmyparL=arrmypar.length;
			arrmyparF='new Array('+arrmypar.substring(1,arrmyparL)+');';
			pars=eval(arrmyparF);	
			if (inpuObj.childs.length>0)
				{
				var clen=inpuObj.childs.length-1;
				inpuObj.childs[clen].onclick=null;
				}
			document.body.style.cursor='wait';
			var sender= new ContentLoader(inpuObj.url,'POST',pars,inpuObj.divid,inpuObj);
			}
		else
			{
			inpuObj.timeout_id=setTimeout (cmd,50);
			}
		}
	}
else
	{
	inpuObj.timeout_id=setTimeout (cmd,50);
	}
}




chekEl=function (domEl)
{
this.domEl=domEl;
this.defaultFill=true;
this.linked=false;
this.id=domEl.id;
if (domEl.id)this.id=domEl.id;
else this.id=domEl.name
this.testedTogetherJs=false;
this.requred=false;
this.formEl=this.domEl.form;
this.divid=this.id+'err';
this.beginload=false;
this.name=this.domEl.name;
if (document.getElementById(this.divid))
this.diverr=document.getElementById(this.divid);
else this.diverr=null;
this.value=this.domEl.value;
this.defaultValue=this.domEl.defaultValue;
this.color=colobj.color2;
this.errorcolor=colobj.color1;
this.minvalue=0;
this.methodset=false;
this.error=false;
this.wait=false;
this.nodeid=false;
this.domEl.inpuObj=this;
this.domEl.onfocus=this.prepareMe;
this.domEl.onblur=this.tryMe;
if (this.domEl.type=='button'&&!this.methodset)
	{
	this.domEl.onclick=this.formEl.inpuObj.sendForm;
	this.domEl.onfocus=null;
	this.domEl.onblur=null;
	this.methodset=true;
	this.beginload=true;
	}
}
chekEl.prototype.changeUrls=function()
{
var inpuObj;
if (this.parentNode)inpuObj=this.inpuObj;
else inpuObj=this;
if (inpuObj.beginload)
	{
	try
		{
		var newval=inpuObj.domEl.value.trim();
		if (newval!=inpuObj.urlold&&inpuObj.urlid!=-1)
			{
			var urllen=myUrl.length;
			var urmy=new Array();
			for (var i=0;i<urllen;i++) if (myUrl[i]!=inpuObj.urlid) urmy.push(myUrl[i]);
			myUrl=urmy;
			}
		}
	catch (e)
		{
		
		}
	inpuObj.value=inpuObj.domEl.value;
	inpuObj.checkMe();	
	}	
		
}

chekEl.prototype.changeUrls1=function()
{
var inpuObj;
if (this.parentNode)inpuObj=this.inpuObj;
else inpuObj=this;
if (!inpuObj.beginload)
	{
	inpuObj.prepareMe();
	}
else
	{
	var par=new inhtObject('urltoid',inpuObj.domEl.value);
	var par1=new inhtObject('urltoidmy',inpuObj.domEl.id);
	pars=new Array(par,par1);
	inpuObj.wait=true;
	inpuObj.urlold=inpuObj.domEl.value;
	var sender= new ContentLoader('/index.'+'php?action=check&what=geturlid','POST',pars,inpuObj.id,inpuObj);
	}
}

chekEl.prototype.prepareMe=function()
{
var inpuObj;
if (this.parentNode)inpuObj=this.inpuObj;
else inpuObj=this;

if (this.type=='text'&inpuObj.linked) inpuObj.preparePass();
else
	{
	if (!inpuObj.beginload)
		{
		inpuObj.formEl.inpuObj.beginload=true;
		inpuObj.value='';
		inpuObj.beginload=true;
		if (inpuObj.domEl.type!='radio')
		inpuObj.domEl.value='';
		}
	}
}

chekEl.prototype.loadMe=function()
{
var inpuObj;
if (this.parentNode)inpuObj=this.inpuObj;
else inpuObj=this;
var par;
if (inpuObj.nodeid) par=new inhtObject('nodeid',inpuObj.nodeid);
else par= new inhtObject('who',inpuObj.name);
pars=new Array(par);
var sender= new ContentLoader('/index.'+'php?action=check&what=loadme','POST',pars,inpuObj.id,inpuObj);
}

chekEl.prototype.preparePass=function()
{
var inpuObj=this;
var id1=inpuObj.id+'1';
var newdEl=document.getElementById(id1);
inpuObj.domEl.style.visibility='hidden';
inpuObj.domEl.style.display='none';
newdEl.style.visibility='visible';
newdEl.style.display='block';
newdEl.focus();
}

chekEl.prototype.tryMe=function()
{
var inpuObj=this.inpuObj;
if (this.type=='password'&inpuObj.linked) inpuObj.tryMePass();
else
	{
	if (inpuObj.beginload)
		{
		inpuObj.value=this.value;
		inpuObj.checkMe();	
		}
	}
}

chekEl.prototype.tryMePass=function()
{
var inpuObj=this;
inpuObj.value=inpuObj.domEl.value;
var str=new String(inpuObj.value);
inpuObj.value=str.trim();
if (inpuObj.beginload)
	{
	if (inpuObj.value.length<=inpuObj.minvalue)
		{
		var mess;
		inpuObj.error=true;
		if (inpuObj.minvalue==0)
			{
			mess='Вы не заполнили обязательное поле "'+inpuObj.defaultValue+ '"';
			inpuObj.clearPass();
			}
		else mess='Длина обязательного поля "'+inpuObj.defaultValue+ '" меньше '+inpuObj.minvalue;
		inpuObj.diverr.innerHTML=mess;
		var ind=inpuObj.id.length-1;
		var id1=inpuObj.id.substring(0,ind);
		var newdEl=document.getElementById(id1);
		newdEl.style.color=inpuObj.errorcolor;				 
		}
	else
		{
		inpuObj.error=false;
		var ind=inpuObj.id.length-1;
		var id1=inpuObj.id.substring(0,ind);
		var newdEl=document.getElementById(id1);
		newdEl.style.color=inpuObj.color;				 
		inpuObj.diverr.innerHTML='';
	
		}	
	}
}
function logOut(some)
{
var act;
if (some.length>0) act='/index.'+'php?action=check&what=out&id='+some;
else act='/index.'+'php?action=check&what=out';
var pars=new Array();
var divid='authcont';
var sender=new ContentLoader(act,'POST',pars,divid,null);
}

function logOut1(some)
{
var act;
if (some.length>0) act='/index.'+'php?action=check&what=out1&id='+some;
else act='/index.'+'php?action=check&what=out1';
var pars=new Array();
var divid='authcont';
var sender=new ContentLoader(act,'POST',pars,divid,null);
}


function setRemember()
{
var elem=document.getElementById('authcont');
var inner='<div id=remembererr class=error ></div><div id=loginerr class=error ></div><h2>Вспомнить пароль</h2><form name=remember id=\'remember\' method=\'POST\' ><table style="margin-top:6px;"><tr><td class=for><input type="Text" id="login" minvalue="0" requred="true" defaultValue="Логин" class=int name=email value="Логин"></td><td>&nbsp;</td><td><input  name=but type="Button" value=">>" class=but></td></tr><tr><td colspan=4><span class=sm><a href=/?action=show&id=65365>регистрация</a></span>&nbsp;&nbsp;|&nbsp;&nbsp;<span class=sm><a href="javascript:setAut(\'\');">авторизация</a></span></td></tr></table></form>';
elem.innerHTML=inner;
Properties['login']=new propObject('0',true,false,'Логин',false,true,false,false,false);
myForm=new chekf(document.getElementById('remember'),'myForm');
myForm.createForm();
}
function setAut(txt)
{
var elem=document.getElementById('authcont');
var inner='<div id=autherr class=error >'+txt+'</div><div id=loginerr class=error ></div><div id=pass1err class=error ></div><h2>Авторизация</h2><form name=auth id=\'auth\' method=\'POST\'><table style="margin-top:6px;"><tr><td class=for><input type="Text" id="login" minvalue="0" requred="true" defaultValue="Логин" class=int name=email value="Логин"></td><td class=for><input type="Text" id=\'pass\' class=int value="Пароль"><input type="Password" name=password style="visibility:hidden;display:none;" id=\'pass1\' class=intp value=""></td><td>&nbsp;</td><td><input  name=but type="Button" value=">>" class=but></td></tr><tr><td colspan=4><span class=sm><a href=/?action=show&id=65365>регистрация</a></span>&nbsp;&nbsp;|&nbsp;&nbsp;<span class=sm><a href="javascript:setRemember();">забыли пароль</a></span></td></tr></table></form>';
elem.innerHTML=inner;
Properties['login']=new propObject('0',true,false,'Логин',false,true,false,false,false);
Properties['pass1']=new propObject('0',true,false,'Пароль',true,true,false,false,false);
Properties['pass']=new propObject('0',false,false,'Пароль',true,true,false,false,false);
myForm=new chekf(document.getElementById('auth'),'myForm');myForm.createForm();
}


chekEl.prototype.clearPass=function()
{
var inpuObj=this;
var ind=inpuObj.id.length-1;
var id1=inpuObj.id.substring(0,ind);
var newdEl=document.getElementById(id1);
newdEl.style.visibility='visible';
newdEl.style.display='block';
inpuObj.domEl.style.visibility='hidden';
inpuObj.domEl.style.display='none';
if (inpuObj.defaultFill) newdEl.value=inpuObj.defaultValue;
inpuObj.domEl.value='';
inpuObj.beginload=false;
}


chekEl.prototype.checkMe=function()
	{
	var inpuObj=this;
	var formob=inpuObj.formEl.inpuObj;
	if (inpuObj.requred)
		{
		if (inpuObj.ajax)inpuObj.wait=true;
		var str=new String(inpuObj.value);
		inpuObj.value=str.trim();
		if (inpuObj.value.length<=inpuObj.minvalue)
			{
			var mess;
			inpuObj.error=true;
			if (inpuObj.minvalue==0)
				{
				mess='Вы не заполнили обязательное поле "'+inpuObj.defaultValue+ '"';
				inpuObj.clearMe();
				}
			else mess='Длина обязательного поля "'+inpuObj.defaultValue+ '" меньше '+inpuObj.minvalue;
			if (inpuObj.diverr)inpuObj.diverr.innerHTML=mess;
			inpuObj.domEl.style.color=inpuObj.errorcolor;				 
			}
		else
			{
			if (inpuObj.testedTogetherJs)
				{
				inpuObj.testedTogetherJs.call();
				}
			else inpuObj.error=false;
			if (!inpuObj.error)	
				{
				if (inpuObj.ajax)
					{
					var pars;
					inpuObj.wait=true;
					if (inpuObj.testetTogether)
						{
						var name;
						var name1;
						var name2;
						var arrmypar=''
						for (var k=0;k<formob.childNumb;k++)
							{
							if (formob.childobjs[k].beginload)
								{
								name='var par'+k;
								name2='par'+k;
								name1=name+'= new inhtObject(formob.childobjs[k].name,formob.childobjs[k].value);';
								eval(name1);
								arrmypar=arrmypar+','+name2;
								}
							}
						arrmyparL=arrmypar.length;
						arrmyparF='new Array('+arrmypar.substring(1,arrmyparL)+');';
						pars=eval(arrmyparF);
						}
					else
						{
						var par=new inhtObject(inpuObj.name,inpuObj.value);
						pars=new Array(par);
						}
					var url='/index.'+'php?action=check&what='+inpuObj.id;
					var sender= new ContentLoader(url,'POST',pars,inpuObj.divid,inpuObj,inpuObj);
					}
				else
					{
					inpuObj.error=false;
					if (inpuObj.diverr&&inpuObj.diverr.innerHTML.length>0)inpuObj.diverr.innerHTML='';
					inpuObj.domEl.style.color=inpuObj.color;				 
					}	
				}
			}
		}
	}	
chekEl.prototype.clearMe=function()
{
if (this.diverr) this.diverr.innerHTML='';
this.domEl.style.color=this.color;
if (this.defaultFill)
	{
	this.value=this.defaultValue;
	this.domEl.value=this.defaultValue;
	}
this.beginload=false;
}












	
