show_preview=new Array();

function switch_layer(layer){
	if(!show_preview[layer]){
		show_preview[layer]=1;
		document.getElementById(layer).style.display = 'block';
	} else {
		show_preview[layer]=0;
		document.getElementById(layer).style.display = 'none';
	}
}

function open_html(url, wwidth, wheight, resized, scrolls){
	if(resized) resizable_par=resized?',resizable=yes':',resizable=no'; else resizable_par=',resizable=no';
	if(scrolls) scroll_par=scrolls?',scrollbars=yes':',scrollbars=no'; else scroll_par=',scrollbars=no';
	pX = Math.round((screen.width - wwidth) / 2);
	pY = Math.round((screen.height - wheight) / 2);
	var rnd=Math.round(1000*Math.random());
	if(document.all){
		win_coords =',left='+pX+',top='+pY;
		var w = window.open('', 'NewWindow'+rnd, 'width='+wwidth+',height='+wheight+',titlebar=no' + resizable_par + scroll_par + win_coords);
		w.location = url;
	}else{
		win_coords =',screenX='+pX+',screenY='+pY;
		window.open(url,'_blank', 'width='+wwidth+',height='+wheight+',titlebar=no,menubar=no,status=no,location=no,fullscreen=no,directories=no' + resizable_par + scroll_par + win_coords);
	}
}
function open_photo(url, wwidth, wheight){
	open_html(url, wwidth, wheight, false, false);
}

function win_fit_and_center(){
	resizeX=document.body.scrollWidth-document.body.offsetWidth;
	resizeY=document.body.scrollHeight-document.body.offsetHeight;
	if(document.body.scrollHeight>screen.height){
		resizeY=screen.height-document.body.offsetHeight-100;
	}
//	alert(document.body.scrollHeight);
//	alert(document.body.offsetHeight);
//	alert(resizeY);

	window.resizeBy(resizeX, resizeY);
	new_width=document.body.scrollWidth;
	new_height=document.body.scrollHeight;
	pX = Math.round((screen.width - new_width) / 2);
	pY = Math.round((screen.height - new_height) / 2);
	if(pY<0) pY=0;
	window.moveTo(pX,pY);
}

// <input type=checkbox value=1 onclick='switch_checkboxes(this.form, \"mailme\", this.checked);' title='Вкл./Выкл. все'>
function switch_checkboxes(form, group_name, status){
	var pat = new RegExp(group_name + "\[[0-9]+\]", "i");
	var arr = form.elements;	var a;
	for (var i=0;i<arr.length;i++) {
		a = arr[i];
		matched=a.name.match(pat);
		if(matched && a.type=='checkbox'){
			a.checked=status;
		}
	}
}

function collect_IDs(obj, ID, direct) {
	var listvar = obj.value;
	switch(direct){
		case(true):{
			listvar = listvar+((listvar=='')?'':',')+ID;
			break;
		}
		case(false):{
			var listvar2 = ','+listvar+',';
			var pattern = ','+ID.replace(/\[/g, '\\[').replace(/\]/g, '\\]')+',';
			eval('listvar = listvar2.replace(/'+pattern+'/g,",").replace(/^,/,"").replace(/,$/,"");');
			break;
		}
	}
	obj.value = listvar;
}


function ask(q, url){
	if (confirm(q)){
		document.location=url;
	}
}
show_preview_layer=0;
		
function switch_preview_layer(div){
	if(!show_preview_layer){
		show_preview_layer=1;
		document.getElementById(div).style.display = 'block';
	} else {
		show_preview_layer=0;
		document.getElementById(div).style.display = 'none';
	}
}
		
function fajust_flashtable(div_style, w){
	var size=document.body.offsetWidth;
	document.getElementById("left_width").style.width='50%';
	document.getElementById("right_width").style.width='50%';
//	alert('size='+size+', left_width='+flash_left.style.width + ', right_width='+ flash_right.style.width);
	return;

//	alert(size);
	if(size>1024){
		left_width=512;
		right_width=size-512;
	} else {
		if(size<500) {
			left_width='200';
			right_width=size-200;
		} else {
			left_width='50%';
			right_width='50%';
		}
	}
	flash_left.style.width=left_width;
	flash_right.style.width=right_width;
	alert('size='+size+', left_width='+left_width + ', right_width='+ right_width);
}

function oldTagInsert(form, field, Tag, Tag2)
	{
	form[field].focus();
	sel = document.selection.createRange();
	sel.text= Tag+sel.text+Tag2;
//	alert(sel.text);
}
function TagInsert(form, field, Tag, Tag2){
	var obj = form[field];
	obj.focus();
	if(document.selection){
		var sel = document.selection.createRange();
		sel.text= Tag+sel.text+Tag2;
	} else {
		var start=obj.selectionStart;
		var end=obj.selectionEnd;
		var text=obj.value;
		var len=text.length;
		obj.value=text.substring(0, start) + Tag + 
			text.substring(start, end) + Tag2 +
			text.substring(end, len);
	}
}

function drawFlash(src,w,h,ID,bgcolor,wmode,vars, adds){
	var s =	'<object ' +
		'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' +
		'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ' +
		(parseInt(w)?'width="'+w+'" ':'') +
		(parseInt(h)?'height="'+h+'" ':'') +
		'bgcolor="'+bgcolor+'" ' +
		'id="'+ID+'" ' +
		'align="" ' +
		adds +'>' +
		'<param name=movie value="'+src+'">' +
		'<param name=quality value="high">' +
		'<param name=wmode value="'+wmode+'">' +
		'<param name=swLiveConnect value="true">' +
		'<param name=menu value="false">' +
		'<param name=FlashVars value="'+vars+'">' +
		'<embed ' +
		'src="'+src+'" ' +
		'menu="false" ' +
		'quality="high" ' +
		'bgcolor="'+bgcolor+'" ' +
		'wmode="'+wmode+'" ' +
		(parseInt(w)?'width="'+w+'" ':'') +
		(parseInt(h)?'height="'+h+'" ':'') +
		'name="'+ID+'" ' +
		'align="" ' +
		'swLiveConnect="true" ' +
		'FlashVars="'+vars+'" ' +
		'type="application/x-shockwave-flash" ' +
		'pluginspage="http://www.macromedia.com/go/getflashplayer">' +
		'<'+'/embed>' +
		'<'+'/object>';
	document.write(s);
}
