if (document.layers) document.all = document.layers

appN=navigator.appName.charAt(0)
appV=navigator.appVersion.charAt(0)

IE=(appN=='M') ? true : false
NN=(appN=='N') ? true : false

IE3=(IE && appV>2) ? true : false
NN3=(NN && appV>2) ? true : false

IE4=(IE && appV>3) ? true : false
NN4=(NN && appV>3) ? true : false

IE5=(IE && appV>4) ? true : false
NN5=(NN && appV>4) ? true : false

//function subscribe(eMail,defMail,old) {
//	defMail = 'почтовый@адрес'
//	eMail = prompt('Укажите адрес электронной почты (e-mail) подписчика. Управление подпиской производитс абонентом через e-mail.',defMail)
//	if( eMail != null && eMail != defMail) {
//		document.location = '/cgi-bin/subscribe.cgi?MAIL=' + escape(eMail) + '&URL=' + escape(document.location)
//		alert ('Дополнительные инструкции вы получите по электронной почте\nОставайтесь с нами!')
//
//	} else if (eMail != null)
//		alert ('Вы не указали e-mail - подписка не будет произведена.')
//	return false;
//}

function selectURL (obj,v) {
	v = obj.options[obj.options.selectedIndex].value
	if (v) document.location = v
	else obj.options.selectedIndex = 0;
	}


function pBn(doc,rnd){
	rnd=parseInt(Math.random()*10000)
	doc.write("<P ALIGN=CENTER><A HREF='http://www.reklama.ru/cgi-bin/href/adv?"+rnd+"' TARGET=_blank><IMG SRC='http://www.reklama.ru/cgi-bin/banner/adv?"+rnd+"' BORDER=1 WIDTH=468 HEIGHT=60></A></P>")
}


function check_bbs_new(checked){
	if (checked){
		setCookie('bbs_hide_new', '0')
	} else {
		setCookie('bbs_hide_new', '1');
	}
	document.location.reload();
}

function getCookie(name,begin,end){
	begin = document.cookie.indexOf(name+"=")
	if(begin==-1) return ""
	begin = document.cookie.indexOf("=",begin)+1
	end = document.cookie.indexOf("; ",begin)
	if (end == -1) end = document.cookie.length
	return document.cookie.substring(begin,end)
}

function setCookie (name,content,expires,path,domain){
  if(expires && expires==-1) expires='Thu, 21 Sep 2010 07:59:00 GMT'
  expires = (expires) ? 'expires='+expires+'; ' : ''

  path = (path) ? 'path='+path+'; ' : ''
  domain = (domain) ? ' domain='+domain+'; ' : '';
  document.cookie = name+'='+content+'; '+path+expires+domain
}


function addToArray(node,array){
	if ( !node && node!='0') { 
		return false
	} else {
		array[ array.length ] = node
	}
}

function existsInArray(node,array){
	for (var i=0;i<array.length;i++)
		if(array[i]==node) return i
	return -1
}

function popArray( arr, id, i, j, newArr ){
	newArr=new Array();j=0
	for(var i=0;i<arr.length;i++)
		if( id==i ) j=1
		else newArr[i-j]=arr[i]
	return newArr;
}

if( !window.name ) window.name='MAIN'

function openwnd( url, target, param, wnd , default_param){
	default_param = 'toolbar=0,status=1,scrollbars=1,top=20,left=20,screenY=20,screenX=20,resizable=1'
	param = (param) ? ','+param : '';
	param =  default_param + param
	wnd=open( url, target, param )
	wnd.focus()
	return wnd
}

// init

function init() {
}

// cookie

function get_list (list_name, my_str) {
	my_str = getCookie( list_name )
	if( my_str ) return my_str.split( ',' )
	return new Array()
}

function add_to_list( list_name, record, list ) {
	list = get_list( list_name )
	if( !check_in_list( list_name, record ) ){
		list += (list.length) ? ',' + record : record
		setCookie( list_name, list, '', '/' )
	}
}

function check_in_list( list_name, record, list) {
	list = get_list( list_name )
	if( record && existsInArray( record, list ) !=-1 )
		return true
	else
		return false;
}

function delete_from_list( list_name, record, list ){
	list=get_list( list_name )
	list=popArray( list, existsInArray( record, list ) )
	setCookie( list_name, list, '', '/' )
}

function reset_list (list_name){
	setCookie(list_name,'','','/')
}

function set_checkbox( obj, flag ){
	if (obj.length)
		for (i=0; i<obj.length; i++)
			obj[i].checked = (flag) ? true : false;
	else
		obj.checked = (flag) ? true : false;
}

function form_submit( name, action, theform ){
	theform=document.forms[ name ]
	theform._action.value=action
	theform.submit()
}

function set_title( title_text ) {
	if ( title_text )
		document.title = title_text;
}

function set_page( name, page ){
	setCookie( '_page_'+name, page )
}

function re_page( name, page ){
	setCookie( '_page_'+name, page )
	location.reload()
}

function wfloat () {
	openwnd ('','wfloat','width=200,height=100,scrollbars=no');
}

// debug

function debug (s) {
	if (typeof(s)=="object") {
		var o = s;
		s = "";
		for (var i in o) s += i+"="+o[i]+"\n";
	}
	return s;
}

function submit_query (obj) {
	var str = ''
	var frm = (obj.form) ? obj.form : obj
	if (!frm || !frm.elements) return 
	var elms = frm.elements
	var i
	for (i=0; i< elms.length ; i++) {
		var elm = elms[i]
		if ( elm.type!='radio' && elm.type!='checkbox' && elm.value != '')
			elm.checked = true
		if ( elm.checked ) {
			var val = (IE4) ? elms[i].value : escape(elms[i].value)
			str	+= '&'+elms[i].name+'='+val
		}
	}
	return str	
}

		 
function default_value (obj,val,flag) {
	if ( flag == 1 ){ // blur
		obj.value = ( obj.value == '' ) ? val : obj.value

	}else { // focus
		obj.value = ( obj.value == val ) ? '' : obj.value
		obj.select()
	}
	return true;
}

