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 open_picture(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 redirect(url){
	document.location=url;
}

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);
}

function switch_element(id){
	var status = document.getElementById(id).style.display;
	document.getElementById(id).style.display = (status=='none')?'block':'none';
}
function switch_tr(id){
	var status = document.getElementById(id).style.display;
	if(document.all) var show='block'; else var show='table-row';
	document.getElementById(id).style.display = (status=='none')?show:'none';
}

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 ajax_indicator_on(div){
	var indicator_pic='<img src=' + htmlrootpath + '/images/ajax/indicator.gif>';
	if (div){ document.getElementById(div).innerHTML=indicator_pic; }
}
function ajax_indicator_off(div){
	if (div){ document.getElementById(div).innerHTML=''; }
}

function hide_element(field){
	document.getElementById(field).style.display = 'none';
}
function show_element(field){
	if(document.all) var show='block'; else var show='table-row';
	document.getElementById(field).style.display = show;
}

function xpand_textarea(a, el){
	var h = Number( document.getElementById(el).style.height.replace('px','') );
	if(a==1) h+=100; else  h-=100;
	if(h>1600) h=1600;
	if(h<100) h=100;
	document.getElementById(el).style.height = h+'px';
	return false;
}

function typo(id, paragrapher){
	var txt=xGetElementById('edit_' + id).value.replace(/'/g, "&prime;");
	if(txt=='') return;
	ajax_indicator_on('aind'+id);
//	alert(txt);
	xajax__respondent('Typografer', "$txt='" + txt + "'; $id='" + id + "'; $paragrapher=" + paragrapher + ";");
	return false;
}

function ch_class(id, c){
	document.getElementById(id).className  = c;
}

function ch_pic(id, pic){
	document.getElementById(id).src  =  htmlrootpath + '/i/' + pic;
}

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 show_exhibitors(country, exhibition_id){
	ch_class('c' + ac, 'clist');
	ch_class('c' + country, 'clist_');
	ac = country;
	xajax__respondent('showExhibitors', "$country=" + country + ";  $exhibition_id=" + exhibition_id + "; ");
	return false;
}

function change_plan(plan){
	ch_class('pt' + ac, 'plantitle');
	ch_class('pt' + plan, 'plantitle_');
	ac = plan;
	xajax__respondent('changePlan', "$plan=" + plan + ";");
	return false;
}


function show_category(cat){
	ch_class('c' + ac, 'clist');
	ch_class('c' + cat, 'clist_');
	ac = cat;
	xajax__respondent('showCategory', "$cat=" + cat + ";");
	return false;
}

function show_object(id){
	xajax__respondent('showObject', "$id=" + id + ";");
	return false;
}

