
//??????????? ???? ????????
function fnBrowserDetect()
{
	/*	IE: 0
		Opera: 1
		Netscape: 2
	*/
	if(navigator.appName.indexOf("Netscape")>=0)
		return 2;
	if(navigator.userAgent.indexOf("MSIE")>0)
	{
		if(navigator.userAgent.indexOf("Opera")>0)
			return 1;
		if(navigator.userAgent.indexOf("Opera")==-1)
			return 0;
	}
	return -1;
}

// ????????????? ????? ?????? ? ??? ? ??
function correctPNG() 
{
	var MS=navigator.userAgent.indexOf("MSIE");
    var MSVER =   parseFloat(navigator.userAgent.substring(MS+5, MS+8));
	var notOpera = true;
	if(navigator.userAgent.indexOf("Opera")>0)
		notOpera = false;
	if (MS > 0 && MSVER >= 5.5000 && notOpera)
	{
		for(var i=0; i<document.images.length; i++)
		{
			var img = document.images[i]
			var imgName = img.src.toUpperCase()
			//alert(img.className);
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
			{
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText 
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				if(img.className=="inTextImage")
				{
					var sab = img.src.substring(img.src.indexOf("/res/files"),img.src.length);
					sab = ".."+sab;
					var strNewHTML = "<span " + imgID + imgClass + imgTitle
						+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
						+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
						+ "(src=\'" + sab + "\', sizingMethod='scale');\"></span>" 
					img.outerHTML = strNewHTML
					i = i-1
				}
				else
				{
					var sab = img.src.substring(img.src.indexOf("/styles/files"),img.src.length);
					sab	= ".."+sab;
					//alert(img.src);
					var strNewHTML = "<span " + imgID + imgClass + imgTitle
						+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
						+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
						+ "(src=\'" + sab + "\', sizingMethod='image');\"></span>" 
					img.outerHTML = strNewHTML
					i = i-1

				}
			}
	    }
	}
}
//window.attachEvent("onload", correctPNG);

// ????? ???? 
function fnExpandCollapse(id,img_right,img_down)
{
	menu = [["themen"],["beispiele"],["test"]];
	for(i=0;i<3;i++)
	{
		if(document.getElementById(menu[i]) && menu[i]!=id)
		{
			document.getElementById(menu[i]).style.display = "none";
			if(img_right.indexOf('.')>0)
				document.getElementById(menu[i]+"_img").innerHTML='<img src="../styles/files/'+img_right+'"  border="0">'
			else
				document.getElementById(menu[i]+"_img").innerHTML="&#xA0;"
		}
		if(document.getElementById(menu[i]) && menu[i]==id)
		{
			if(document.getElementById(id).style.display=="none")					
			{
				document.getElementById(id).style.display = "block";						
				if(img_down.indexOf('.')>0)
					document.getElementById(menu[i]+"_img").innerHTML='<img src="../styles/files/'+img_down+'"  border="0">'
				else
					document.getElementById(menu[i]+"_img").innerHTML="&#xA0;"
			}
			else
			{
				document.getElementById(id).style.display = "none";						
				if(img_right.indexOf('.')>0)
					document.getElementById(menu[i]+"_img").innerHTML='<img src="../styles/files/'+img_right+'"  border="0">'
				else
					document.getElementById(menu[i]+"_img").innerHTML="&#xA0;"
			}
		}
	}
	//correctPNG();
}

//-----------------tests-----------------------------
function check_multi_choice(q_id,a_id)
	{
	if (document.getElementById(a_id)) 
		{
		if (document.getElementById(a_id).checked)
			{
			return 1;
			}
		else 
			{
			return 0;
			}
		}
	else
		{
		return 0;
		}
	}

function check_multi_answer(q_id,a_array1,a_field_id)
	{
	var a_array=new Array();
	a_array=	eval(a_array1);
	var i=0;
	var right=0;
	for (i=0;i<a_array.length;i++)	
		{
		if (a_array[i]==document.getElementById(a_field_id).value)
			{right=1;}

		}
	if (right==1)
		{
		return 1;
		}
	else 
		{
		return 0;
		}

	}

function check_multi_answer2(q_id,a_array1)
	{

	var a_array=new Array();
	a_array=	eval(a_array1);

	var i=0;
	var right=-1;

	for (i=0;i<a_array.length;i++)	
		{
//		alert(document.getElementById(q_id+"_"+(i+1)).checked);
		if (!document.getElementById(q_id+"_"+(i+1)).checked && a_array[i]=="1")
			{
			right=0;
			}

		if (document.getElementById(q_id+"_"+(i+1)).checked && a_array[i]=="0")
			{
			right=0;
			}
		if (document.getElementById(q_id+"_"+(i+1)).checked && a_array[i]=="1" && right!=0)
			{
			right=1;
			}

		}


	if (right==1)
	{
		return 1 ;
	}
	else 
	{
		return 0;
	}

	}




function check_multi_matching(q_id,a_array1)
	{
	var a_array=new Array();
	a_array=	eval(a_array1);
	var i=0;
	var right=-1;
	for (i=0;i<a_array.length;i++)	
		{
//		alert(a_array[i]);
//		alert(document.getElementById(q_id+"_"+(i+1)).value);

		if (document.getElementById(q_id+"_"+(i+1)).value!=a_array[i])
			{
			right=0;
			}
		if (document.getElementById(q_id+"_"+(i+1)).value==a_array[i] && right!=0)
			{
			right=1;
			}

		}


	if (right==1)
	{
		return 1;
	}
	else 
	{
		return 0;
	}

	}
	
// ?????? ??????? 

function rescount(param)
{
	if(testStatus == 0)
	{
		testStatus =1;
		document.getElementById('checkTest').outerText =document.getElementById('checkTest').innerText;
		document.getElementById("testtime").innerHTML = "&nbsp;";
		for(i=0;i<document.forms.length;i++)
		{
			for(j=0;j<document.forms[i].elements.length;j++)
			{
			
				if(document.forms[i].elements[j].className =="testButton")
				{
					document.forms[i].elements[j].onclick();
				}
			}
		}
	}
	if(oInterval)
		clearInterval(oInterval);
}
// timer
var GtimeOff;
var oInterval;
function startTmr(minutes,param)
{
 var now = new Date();
 now.setTime(now.getTime()+365*24*60*60*1000);
 dtime = new Date();
 if(minutes!=0)
 {
    timeOff = dtime.getTime()+minutes*60*1000+1000;
    GtimeOff = timeOff;
    fnStartInterval(param);
 }
 else
 {
    timeOff = 0;     //если незаданы временные ограничния
  }
}

// Запуск таймера
function fnStartInterval(param)
{
	var fncallback = "fnRecycle('"+param+"')";
	//alert(fncallback);
	oInterval = setInterval(fncallback,1000);
}

// Остановка таймера
function fnStoptInterval(param)
{
	clearInterval(oInterval);//&&&&&&&&&&&&&&&&***********************************************************************************
	rescount(param);
}

function fnRecycle(param)
{
  dt = new Date();
	
  timeLeft = GtimeOff-dt.getTime();
   if(timeLeft<=0)
  {
	alert(alarma);
   fnStoptInterval(param);
  }
  else
  {

   parseMin = parseInt(timeLeft/60000);
   parseSec = parseInt((timeLeft%60000)/1000);
   if(parseSec<10)
      parseSec = "0"+parseSec;
	document.getElementById("testtime").innerHTML = parseMin+":"+parseSec;
   if(timeLeft<20000)
   {
          document.getElementById("testtime").style.color = "#FF0000";
   }
  }
}

