var z;
var i;
var c;
function check_answers(fn1,fn2,quantity)
{
	c = 0;
	z = document.getElementById(fn1).elements;

	for(i=0;i<z.length;i++)
	{
		if (z[i].checked == true && z[i].id == fn2) {c = c+1;}
	}
	if (c >= quantity+1) {return false;}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function search_click(fn_1,fn_2)
{
	if (document.getElementById(fn_1).value != 'y')
	{
		document.getElementById(fn_2).value = '';
		document.getElementById(fn_1).value = 'y'
	}
}

function menu_left_click(fn)
{
	if (document.getElementById(fn).style.display == 'none')
	{
		document.getElementById(fn).style.display = 'inline';
	}
	else
	{
		document.getElementById(fn).style.display = 'none';
	}
}

function bg_change(fn,color)
{
	document.getElementById(fn).style.backgroundColor=color;
}

function show_hide(layer_name)
{
	if (document.getElementById(layer_name).style.display == 'inline')
	{
		document.getElementById(layer_name).style.display = 'none';
	}
	else
	{
		document.getElementById(layer_name).style.display = 'inline';
	}
}

function openWIN(URL,WNAME,w,h,scr)
{
	sw = screen.width-100;
	sh = screen.availHeight-100;
	mtw = (screen.width-w)/2;
	mth = (screen.availHeight-h)/2;
	popup = window.open(URL,WNAME,"width="+w+",height="+h+",top="+mth+",left="+mtw+",status=no,toolbar=no,scrollbars="+scr+",resizable=no,menubar=no");
	popup.focus();
}

var popup;
function openIMG(URL,WNAME,w,h)
{
	if (popup != null && !popup.closed) popup.close();  
	sw = screen.width-100;
	sh = screen.availHeight-100;
	if (w > sw || h > sh)
	{
		if (w > sw) {w1 = sw;} else {w1 = w+17;}
		if (h > sh) {h1 = sh;} else {h1 = h+17;}
		mtw1 = (screen.width-w1)/2;
		mth1 = (screen.availHeight-h1)/2;
		popup = window.open('',WNAME,"width="+w1+",height="+h1+",top="+mth1+",left="+mtw1+",status=no,toolbar=no,scrollbars=yes,resizable=no,menubar=no");
		popup.focus();
	}
	else
	{
		mtw = (screen.width-w)/2;
		mth = (screen.availHeight-h)/2;
    	popup = window.open('',WNAME,"width="+w+",height="+h+",top="+mth+",left="+mtw+",status=no,toolbar=no,scrollbars=no,resizable=no,menubar=no");
		popup.focus();
	}
  	popup.document.writeln('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>Ассоциация Менеджеров</title></head><body style="margin: 0px;"><a href="javascript:window.close();"><img src="'+URL+'" border=0 width="'+w+'" height="'+h+'" alt="Закрыть окно"></a></body></html>');
}

browserName = navigator.appName;
browserVer = navigator.appVersion.substring(0,1);

if (browserName != "Netscape") {
	foo = navigator.appVersion.split(';');
	foo = foo[1].split(' ');
	browserVer = foo[2];

}

function flashDetectHTML(flashHTML,noFlashHTML,required_version) {

	if ( browserName == "Netscape" ) {
		if ( navigator.plugins['Shockwave Flash'] ) { 
			tmp = navigator.plugins['Shockwave Flash'].description; 
			tmp = tmp.split(' ');
			flashversion = tmp[2].split('.');
			flashversion = flashversion[0];

			if (flashversion < required_version ) { 
				document.writeln(noFlashHTML);
			} 
			
			if (flashversion >= required_version ) { 
					document.writeln(flashHTML);
			}
		} 
		if (!navigator.plugins['Shockwave Flash'] ) { 
				document.writeln(noFlashHTML);
		}
	} else {

			if ( navigator.userAgent.indexOf('Win') != -1) {
				var endtag='</';
				document.writeln('<script language=VBscript> ');
				document.writeln('Function Detect() ');
				document.writeln('  on error resume next ');
				document.writeln('  If ScriptEngineMajorVersion >= ' + required_version + ' then ');
				document.writeln('     Detect = False ');  
				document.writeln('     Detect = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash")) ');
				document.writeln('     If (err) then  ');
				document.writeln('        Detect = False ');
				document.writeln('     End If ');
				document.writeln('   Else ');
				document.writeln('    Detect = False ');
				document.writeln('   End If ');
				document.writeln('End Function ');
				document.writeln(endtag+'script >');	

				if (!Detect() ) { 
						if(browserVer < 5) {
							document.writeln(flashHTML);
						} else { document.writeln(noFlashHTML); }
				} else { 
					document.writeln(flashHTML); 
				}
			} else { 
				document.writeln(flashHTML); 
			}
	}

}

window.onError = null;

function frmcheck(fc,fn)
{
	var dt=new Array(fc);
	for (i=0;i<=fc;i++)
	{
		n=document.getElementById('form_dropdown_'+fn+i).selectedIndex;
		if (dt[n]==1)
		{
			alert('Вы дали одинаковые оценки разным ответам');
			return false;
		}
		else
		{
			dt[n] = 1;
		}
	} 
}

function select_check()
{
	if (document.getElementById('form_dropdown_ch_q_2').selectedIndex > 0)
	{
		document.getElementById('form_dropdown_ch_q_0').disabled = true;
	}
	else
	{
		document.getElementById('form_dropdown_ch_q_0').disabled = false;
	}

	if (document.getElementById('form_dropdown_ch_q_0').selectedIndex > 0)
	{
		document.getElementById('form_dropdown_ch_q_2').disabled = true;
	}
	else
	{
		document.getElementById('form_dropdown_ch_q_2').disabled = false;
	}
}