function showDiv(t){
			t=document.getElementById(t);
			if(t!=null)
			{
				if(t.style.display=='block' ){t.style.display='none';}
				else{t.style.display='block';}
			}
			return false;
		}
		function swichDiv(){
			showDiv("reg")
			showDiv("log")
			return false;
		}
		function search_on_selection(fn)
		{
			frm=document.forms[fn]
			if(frm.elements['q'].value.length>0){
				document.location="/search/"+frm.elements['q'].value
			}else{
				var txt=window.getSelection().toString()
				if( txt.length>0){
					document.location="/search/"+txt
				}else {alert("First input or select the text cursor");}
			}
		}
function send(form_name){
	frm=document.forms[form_name]
	if(!frm)return false
	el = document.forms[form_name].elements
	sz = el.length
	for (i=0;i<sz;i++){
		if ( el[i].name=='i'  ) {
			t = el[i].value
			if ( el[i].checked )
				addCookei( "i" , t )
			else
				delCookei( "i" , t )
		}
	};
	var it=document.location.toString().indexOf("#")
	if(it >0 )
		document.location=document.location.toString().substring(0,it)
	else
		document.location=document.location
	write_html("итог",GetCookie("i"))
	return false
};

function selectAll(formname,name) {
	var form = document.forms[formname];
	if(form) {
		el=form.elements
		for(i=0;i<el.length;i++) {
			if(el[i].name==name)	{
				el[i].checked = (el[i].checked==true)?false:true;
			}
		}
	}
	return false;
}
/*	функции для работы с cookies	*/
function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
};
function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
			if (i == 0)
				break;
	};
	return null;
};
function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + /*escape (*/ value /*)*/ +
		((expires == null) ? "" : ("; expires="+expires.toGMTString())) +
		((path == null) ? "; path=/" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
};
/*	ищет повторяющиеся значения	*/
function checkRepeat(str,value){
	if(!value || !str)return 0;
	if ( str.indexOf("'"+value+"'",0) == -1)return 0;
	return 1;
}
function myCheck(cname,value) {
	return checkRepeat(GetCookie(cname),value);
}

function write_html(){
	var argv = write_html.arguments;
	var argc = write_html.arguments.length;
	id=argv[0]
	text=""
	for (i=1;i<argc;i++)
		text=text+": "+argv[i]
	//alert(text);return 0
	doc=document.getElementById(id);
	if ( doc ){
		doc.innerHTML += text + "<br/>"
	}
};
function addCookei(name,value){
	if( !myCheck( name,value ) )
		SetCookie( name, GetCookie(name)+",'"+value+"'")
};
function delCookei(nm,val){
	s = GetCookie(nm)
	if(s){
		t=",\'"+val+"\'"
		s=s.replace(t,"")
		SetCookie( nm, s)
	}
};
//SetCookie( "i" , "")

/*alert ( checkRepeat("12;15;16;16;189;45;65;95;","45") );
alert ( myCheck("i","15") )*/
function write_brand(div,count){
	title=document.getElementById(div);
	if ( title ){
		var brand=new Array('Python','Пэхапе','C/C++','Perl','Mysql','Apache','XML','XSLT','Java','IBM','Samsung','LG','HP','Sigate','Hitachi','Pioneer','Kingston','NEC','InWin','Zyxel','NVidia','Logitech','VIA','MSI','Dialog','Intel','Sven','AMD','Genius','Abit','Sharp','Xeros','Motorola','Brother','Microsoft','Linux','Ubuntu')
		sz=brand.length
		title.innerHTML=""
		for(i=0;i<count;i++){
			r=Math.ceil(Math.random()*sz)
			if(r>=brand.length)r/=sz
			title.innerHTML+="<a href=\"?q="+brand[r]+"\"><span id=t"+(i+1)+">"+brand[r]+"</span></a>"
			sp=document.getElementById("t"+(i+1));
			if(sp){
				sps=sp.style
				sps.fontSize=50+Math.ceil(Math.random()*150)+"%"
				sps.color="#"+(Math.ceil(Math.random()*90)+9)+(Math.ceil(Math.random()*90)+9)+(Math.ceil(Math.random()*90)+9)
				sps.zindex=i
				sps.top=Math.ceil(Math.random()*25)
			}
		}
		return title.innerHTML
	}
}

function zakaz(){
	var c=0;
	if(GetCookie('name'))c++
	if(GetCookie('phone'))c++
	if(GetCookie('uin'))c++
	if(GetCookie('mail'))c++
	if(c>2)document.location="/cgi-bin/python/ffcms/jabber_test.py"
	else document.location="/mag.html"
}
function login_mag(){
	frm=document.forms['login']
	if(!frm)return false
	e = frm.elements
	c=0
	s=e['name']
	if (s){c++;
	SetCookie( "name" , escape ( s.value ) )
	}
	s=e['phone']
	if (s){c++;
	SetCookie( "phone" , escape ( s.value ) )
	}
	s=e['uin']
	if (s){c++;
	SetCookie( "uin" , escape ( s.value ) )
	}
	s=e['mail']
	if (s){c++;
	SetCookie( "mail" , escape ( s.value ) )
	}
	if (c>2)document.location="/cgi-bin/python/ffcms/portal.py"
}
function restore_form(){
	frm=document.forms['login']
	if(!frm)return false
	frm.elements['name'].value=GetCookie('name')
	frm.elements['phone'].value=GetCookie('phone')
	frm.elements['uin'].value=GetCookie('uin')
	frm.elements['mail'].value=GetCookie('mail')
}
function addEngine (A)
{if (window.external && ("AddSearchProvider" in window.external)){
window.external.AddSearchProvider (A);
return false}
else{
alert (error_opensearch_unsupported);
return true}
}

