
function isNum() {
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])!='number') return false;}
  return true;
}
function checkOnInt(val){
	return (((',35,36,37,39,8,9,46,').indexOf(','+val+',')>-1) || (val>=48 && val<=57) || (val>=96 && val<=105));
}

// ----

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){
//	alert(wheight);
	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;
		new_window = window.open('', 'NewWindow'+rnd, 'width='+wwidth+',height='+wheight+',titlebar=no' + resizable_par + scroll_par + win_coords);
		new_window.location = url;
	}else{
		win_coords =',screenX='+pX+',screenY='+pY;
		new_window = 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 open_picture(url, wwidth, wheight){
	open_html(url, wwidth, wheight, false, false);
}
function switch_element(id){
	var status = document.getElementById(id).style.display;
	document.getElementById(id).style.display = (status=='none')?'block':'none';
}

function win_fit_and_center(){
//	window.resizeBy(0, -200);


// 8-((((( 
//////	window.resizeTo(document.body.scrollWidth, 100);


	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);
	if(document.all){ // fix for MSIE
		resizeX = resizeX + 20;
		resizeY = resizeY + 4;
	}
//	alert(resizeX + ' ' + 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")
	for (e in form.elements) {
		matched=e.match(pat);
		if(matched && form.elements[e].type=='checkbox'){
			form.elements[e].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 collect_IDs2(obj, ID, direct) {
	var listvar = obj.value;
	switch(direct){
		case(true):{
			listvar = listvar+((listvar=='')?'':',')+ID;
			break;
		}
		case(false):{
			var listvar2 = ','+listvar+',';
			var pattern = ','+ID+',';
			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){
	src = src+'?'+Math.random();
	var str = '<object ' +
		'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' +
		'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,79,0" ' +
		((w && w!='')?'width="'+w+'" ':'') +
		((h && 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=WMODE value="'+wmode+'" />' +
		'<param name=swLiveConnect value="true" />' +
		'<param name=allowScriptAccess value="always" />'+
		'<param name=menu value="false" />' +
		'<param name=FlashVars value="'+vars+'" />' +
		'<embed ' +
		'src="'+src+'" ' +
		'menu="false" ' +
		'quality="high" ' +
		'bgcolor="'+bgcolor+'" ' +
		'wmode="'+wmode+'" ' +
		'WMODE="'+wmode+'" ' +
		((w && w!='')?'width="'+w+'" ':'') +
		((h && h!='')?'height="'+h+'" ':'') +
		'name="'+ID+'" ' +
		'align="" ' +
		'swLiveConnect="true" ' +
		'allowScriptAccess="always" '+
		'FlashVars="'+vars+'" ' +
		'type="application/x-shockwave-flash" ' +
		'pluginspage="http://www.macromedia.com/go/getflashplayer">' +
		'</embed>' +
		'</object>';
	return str;
}

function ajust_div_width(div_style, w){
	var size=document.body.offsetWidth;
	if(size<w){
		div_style.paddingRight=0;
	} else {
		div_style.paddingRight=size-w;
	}
}

function acceptLink(mess) {
    if (confirm(mess))
	return true;
    else
	return false;	
}



function ResizeTextArea(txtBox, nRowMin){
	
	nCols = txtBox.cols;
	sVal = txtBox.value;
	nVal = sVal.length;
	
	nBreakCnt = 0;
	nRowCnt = 1;
	
	for (i=0;i<nVal;i++) { 
		if (sVal.charAt(i) == '\n') { nBreakCnt +=1; } 
	}
	
	nRowCnt = 1 + (nVal / nCols) + nBreakCnt;
	if(nRowCnt < nRowMin) nRowCnt = nRowMin;
	
	nRowCnt = Math.floor(nRowCnt);
	txtBox.rows = nRowCnt;
} 

	function open_object(object){
		open_html(htmlrootpath + '/museum/object.htm?object=' + object, 860, 800, true, true);
	}
	
	
	function open_inventory(){
		xajax__respondent('OpenInventory', '');
	}
	
	
	
	