d = document;

function form_validate(form, field) {
   if ( eval('d.' + form + '.' + field + '.value') < 1 ) {
      alert('Введите поисковую фразу');
      return false;
   }
   return true;
}

function offTimer() {
	if (document.timer) {
		window.clearTimeout(document.timer);
		document.timer = null;
	}
}

function show(obj) {
	if (document.vis_l3) {
			document.getElementById(document.vis_l3).style.display = 'none';
			document.vis_l3 = null;
		};
	document.getElementById('sub' + obj).style.display = 'block';
	
	document.getElementById('item' + def).className = '';
	document.getElementById('item' + obj).className = 'selected';
}

function hide() {
	if (document.vis_l3) {
			document.getElementById(document.vis_l3).style.display = 'none';
			document.getElementById('i_' + document.vis_l3).className = 'type2';
			document.vis_l3 = null;
		};
	document.getElementById('sub' + document.vis).style.display = 'none';
	document.getElementById('item' + document.vis).className = '';
	document.getElementById('item' + def).className = 'selected';
}

function on(obj) {
	offTimer();
	if (document.vis) {
		hide();
	}
	show(obj);
}


function off(obj) {
	document.vis = obj;
	document.timer = window.setTimeout('hide()', 300);
}

function on_2 (obj2) {
	if (document.timer2) window.clearInterval(document.timer2);
	document.getElementById('i_' + obj2).className = 'type2_s';
	if (document.vis_l3) {
		document.getElementById(document.vis_l3).style.display = 'none';
		document.getElementById('i_' + document.vis_l3).className = 'type2';
	};
	document.getElementById(obj2).style.display = 'block';
	document.vis_l3 = obj2;
}

function hide_2() {
	document.getElementById('i_' + document.vis_l3).className = 'type2';
	e = document.getElementById(document.vis_l3);
	if ( e == null ) return; 
	e.style.display = 'none';
}


function preloadImg(file) {
	new Image().src = file;
}
function changeImg(file) {
	obj = d.getElementById('pic1');
	obj.src = "img/pictures/" + file;
}

function picwindow(theURL,winName,features,parameter,title) {
	order = window.open(theURL,winName,features);
	order.document.writeln('<html>');
	order.document.writeln('<head>');
	order.document.writeln('<meta http-equiv="Content-Language" content="ru">');
	order.document.writeln('<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">');
	order.document.writeln('<title>' + title + '</title>');
	order.document.writeln('</head>');
	order.document.writeln('<body topmargin="0" leftmargin="0" marginheight=0 marginwidth=0>');
	order.document.writeln('<img src="' + parameter + '" alt="'+ title +'">');
	order.document.writeln('</body>');
	order.document.writeln('</html>');
	order.focus();		 
}


//set message:
/*msg = "Петровский Автоцентр.  Телефон: +7 812 702 1111";

timeID = 10;
stcnt = 16;
wmsg = new Array(33);
        wmsg[0]=msg;
        blnk = "                                                               ";
        for (i=1; i<32; i++)
        {
                b = blnk.substring(0,i);
                wmsg[i]="";
                for (j=0; j<msg.length; j++) wmsg[i]=wmsg[i]+msg.charAt(j)+b;
        }

function wiper()
{
        if (stcnt > -1) str = wmsg[stcnt]; else str = wmsg[0];
        if (stcnt-- < -40) stcnt=31;
        status = str;
        clearTimeout(timeID);
        timeID = setTimeout("wiper()",100);
}

wiper();*/

function toggle_class(o, c) {	
	var re = new RegExp('(^|[^\\S])'+c+'([^\\S]|$)','g');
	var cl = o.className;
	o.className = (cl.match(re)) ? cl.replace(re, '$1').replace(/\s$/,'') : (o.className != '') ? o.className + ' ' + c : c;
}

function extend(o, opts) {
	for (var i in opts) o[i] = opts[i];		
	delete opts;
	return o;	
}

function create_gallery(o) {
	var o = d.getElementById(o);
	extend(o, {i:o.getElementsByTagName('img')[0], itms:o.getElementsByTagName('a')});
	extend(o, {s:extend(o.itms[0],{className:'s'})});
	
	for (var i=0; obj = o.itms[i]; i++)	{
		extend(obj, {
			_p:o,
			i2:(obj.href.indexOf('#') < 0) ? extend(new Image(), {src:obj.href}) : false,
		
			onmouseover:function() {
				this._p.s.className = '';
				this.className = 's';
				this._p.i.src = (this.i2) ? this.i2.src : this.firstChild.src;				
			},
			
			onmouseout:function() {
				this.className = '';
				this._p.s.className = 's';
				this._p.i.src = (this._p.s.i2) ? this._p.s.i2.src : this._p.s.firstChild.src;
			},
			
			onclick:function() {
				this._p.s = this;
				return (false);
			}
		});
	}
}

function show_flash_popup(url, w, h, t) {
		var w1 = window.open('', 'w', 'width='+w+',height='+h+',resizable=no');
		w1.document.writeln('<html>');
		w1.document.writeln('<head><title>'+(t || '. ')+'</title></head>');
		w1.document.writeln('<body style="margin:0; padding:0"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'+w+'" height="'+h+'">');
		w1.document.writeln('<param name="movie" value="'+url+'"/>');
		w1.document.writeln('<param name="quality" value="high"/>');
		w1.document.writeln('<embed src="'+url+'" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'"/></embed></object></body></html>');
		return w1;
}