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){
	pX = Math.round((screen.width - wwidth) / 2);
	pY = Math.round((screen.height - wheight) / 2);
	if(document.all){
		win_coords =',left='+pX+',top='+pY;
		var w = window.open('', 'NewWindow', 'width='+wwidth+',height='+wheight+',titlebar=no,resizable=no,scrollbars=yes'+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=no,scrollbars=yes'+win_coords);
	}
}
function open_photo(url, wwidth, wheight){
	pX = Math.round((screen.width - wwidth) / 2);
	pY = Math.round((screen.height - wheight) / 2);
	if(document.all){
		win_coords =',left='+pX+',top='+pY;
		var w = window.open('', 'NewWindow', 'width='+wwidth+',height='+wheight+',titlebar=no,resizable=no,scrollbars=no'+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=no,scrollbars=no'+win_coords);
	}
}

// <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 suppliers_check(theForm){
	arr = document.getElementsByTagName('input');
	at_least_one = false;
	for(i=0; i<arr.length; i++){
		if(arr[i].type == 'checkbox' && arr[i].name.match(/^my_suppliers/)){
			if(arr[i].checked) at_least_one = true;
		}
	}
	var other=theForm.other_supplier.value!='';
	var result=at_least_one || other; 
	if(!result){
		alert('Не выбрано ни одного поставщика!');
		return(false);
	} else {
		return(true);
	}
}
function ask(q, url){
	if (confirm(q)){
		document.location=url;
	}
}
function switchBlockDisplay(ind) {
	var opera = (navigator.userAgent.indexOf('Opera') >= 0)? true : false;
	var dom = (document.getElementById && !opera)? true : false;
	var ie4 = (document.all && !dom && !opera)? true : false;
	if (dom || ie4) {
		eval("var currElement = (dom)? document.getElementById('"+ind+"') : document.all['"+ind+"'];");
		currElement.style.display = (currElement.style.display == '')? 'none' : ((currElement.style.display == 'none')? 'block' : 'none');
	}
}

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

function ajax_indicator_on(div){
	var indicator_pic='<img src=' + htmlrootpath + '/i/ajax/indicator.gif>';
	if (div){ document.getElementById(div).innerHTML=indicator_pic; }
}
function ajax_indicator_off(div){
	if (div){ document.getElementById(div).innerHTML=''; }
}
