var dom = (document.getElementById) ? true : false;
var moz = (dom && (navigator.appName=="Netscape")) ? true : false;

// Mozilla
function moveHintsN(e)
{
	xoff = window.pageXOffset + e.clientX + 10;
	document.getElementById('hints').style.left = xoff + "px";
	document.getElementById('hints').style.top = window.pageYOffset + e.clientY + 10 + "px";
	document.getElementById('hints').style.visibility = "visible";
}

function hideHintsN(e)
{
	document.onmousemove = null;
	document.onmouseout = null;
    document.getElementById('hints').style.visibility = "hidden";
}

// IE
function moveHints()
{
	if (moz) return;
    xoff = 0;
    yoff = 0;
	xoff += window.event.clientX + document.documentElement.scrollLeft + 10;
	yoff += window.event.clientY + document.documentElement.scrollTop + 10;
	document.getElementById('hints').style.left = xoff;
	document.getElementById('hints').style.top = yoff;
}

function hideHints()
{
	if (moz) return;
	document.getElementById('hints').style.visibility = "hidden";
}

function showHints(text)
{
	if (text == "") return;
	document.getElementById('hints').innerHTML = text;

	if (moz)
    { // for Mozilla
		document.onmousemove = moveHintsN;
		document.onmouseout = hideHintsN;
		return;
	}
    else
    { // for IE & Opera
		moveHints();
		document.getElementById('hints').style.visibility = "visible";
    }
}


//******************************************************************************

function initRollovers()
{
 if (!document.getElementById) return

 var aPreLoad = new Array();
 var sTempSrc;
 var aImages = document.getElementsByTagName('img');

 for (var i = 0; i < aImages.length; i++)
 {
  if (aImages[i].className == 'imgover')
  {
   var src = aImages[i].getAttribute('src');
   var ftype = src.substring(src.lastIndexOf('.'), src.length);
   var hsrc = src.replace(ftype, '_o'+ftype);

   aImages[i].setAttribute('hsrc', hsrc);

   aPreLoad[i] = new Image();
   aPreLoad[i].src = hsrc;

   aImages[i].onmouseover = function()
   {
    sTempSrc = this.getAttribute('src');
    this.setAttribute('src', this.getAttribute('hsrc'));
   }

   aImages[i].onmouseout = function()
   {
    if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
    this.setAttribute('src', sTempSrc);
   }
  }
 }
}

//******************************************************************************

var demoWin;
function DoWin(namehtm,wwin,hwin) {
  if ((demoWin != null) && (!demoWin.closed)){demoWin.close()}
  eval("demoWin=window.open('"+namehtm+"', 'demonstrationWin', 'width="+wwin+",height="+hwin+",location=0,top=0')");
  demoWin.focus();
}

//******************************************************************************

var demoWin2;
function DoWin2(wwin,hwin,imgnum) {
  if ((demoWin2 != null) && (!demoWin2.closed)){demoWin2.close()}
      eval("demoWin2=window.open('', 'demonstrationWin', 'width="+wwin+",height="+hwin+",location=0,top=0')");
  demoWin2.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
  demoWin2.document.writeln('    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
  demoWin2.document.writeln('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" lang="ru">');
  demoWin2.document.writeln('<head>');
  demoWin2.document.writeln('  <title></title>');
  demoWin2.document.writeln('  <style type="text/css">');
  demoWin2.document.writeln('  /*<![CDATA[*/');
  demoWin2.document.writeln('    body  {margin: 0px; padding: 0px}');
  demoWin2.document.writeln('    img   {display: block; margin: 0px auto; padding: 0px; border: none}');
  demoWin2.document.writeln('  /*]]>*/');
  demoWin2.document.writeln('  </style>');
  demoWin2.document.writeln('</head>');
  demoWin2.document.writeln('<body>');
  demoWin2.document.writeln("  <a href=\"#\" onclick=\"self.close(); return false;\" title=\"Кликните для закрытия\"><img src=\"imgs/naruj-reklm/"+imgnum+".jpg\" alt=\"\" /></a>'");
  demoWin2.document.writeln('</body>');
  demoWin2.document.writeln('</html>');
  demoWin2.document.close()
  demoWin2.focus();
}

//******************************************************************************

function check_mail(mail_address)
{
  ParsePetrn = /[a-z_0-9\.]+[-]*[a-z_0-9\.]*[@][a-z_0-9\.]+[-]*[a-z_0-9\.]+[.]\w+[.]\w+|[a-z_0-9\.]+[-]*[a-z_0-9\.]*[@][a-z_0-9\.]+[-]*[a-z_0-9\.]+[.]\w+/i
  return ParsePetrn.test(mail_address);
}

function validForm(f)
{
  if (f.email.value == ""){
    alert("Please, enter your E-mail");
    f.email.focus();
    return false;
  }
  else if (!check_mail(f.email.value))
  {
    alert("Please, enter valid E-mail address");
    f.email.focus();
    return false;
  }

  else f.submit(); // Отправляем на сервер
}

//******************************************************************************

function hide_id(nodeId)
{
    var node = document.getElementById(nodeId);
    if (node)
    {
        node.className=node.className.replace('showed', '');
        node.className += ' hidden';
    }
}

function show_id(nodeId)
{
    var node = document.getElementById(nodeId);
    if (node)
    {
        node.className=node.className.replace('hidden', '');
        node.className += ' showed';
    }
}

function toggle_id(nodeId)
{
    var node = document.getElementById(nodeId);
    if (node)
    {
        if (node.className.indexOf('hidden') != -1)
            node.className=node.className.replace('hidden', 'showed')
        else if (node.className.indexOf('showed') != -1)
            node.className=node.className.replace('showed', 'hidden')
        else node.className += ' showed';
     }
}
// Test's

function browser_test() {
var userAgent = navigator.userAgent;
var opera = (userAgent.indexOf('Opera') != -1);
var ie = (userAgent.indexOf('MSIE') != -1);
var gecko = (userAgent.indexOf('Gecko') != -1);
var oldnetscape = (userAgent.indexOf('Mozilla') != -1);
if (opera){
     var ver = "";
     var version = /Opera (.*)/;
     if (version.test(userAgent)){
     ver = RegExp.$1;
     }
     if (ver < 8.5){
     document.write('<span class="passed">Failed</span>');
     }
     else{
     document.write('<span class="passed">Passed</span>');
     }
}
else if (gecko){
     var version = /Mozilla\/(\d\.\d)/;
     if (version.test(userAgent)){
     ver = RegExp.$1;
     }
     if (ver < 1.0){
     document.write('<span class="passed">Failed</span>');
     }
     else{
     document.write('<span class="passed">Passed</span>');
     }
     }
else if (ie){
     var version = /MSIE (\d\.\d);/;
     if (version.test(userAgent)){
     ver = RegExp.$1;
     }
     if (ver < 5.5){
     document.write('<span class="passed">Failed</span>');
     }
     else{
     document.write('<span class="passed">Passed</span>');
     }
      }
else
     document.write('<div class="failed"><span>Unknown browser</span></div>');
}


function cookie_test() {
	if(navigator.cookieEnabled)
document.write('<span class="passed">Passed</span>');
else
document.write('<span class="passed">Failed</span>');
}


function ajax_test() {
 var req;
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
req = new ActiveXObject("Msxml2.XMLHTTP");
if (req == null) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
}

if (req != null) {
document.write('<span class="passed">Passed</span>');
}
else{
document.write('<span class="passed">Failed</span>');
}
}



//from 52
function swf_timer(){
  timenow = document.getElementById("swf_wait").value;
  m_id1 = document.getElementById("m_id").value;
  swf_id1 = document.getElementById("swf_id").value;
  a_save_swf_time(swf_id1, m_id1, timenow, swf_cb);
}
function swf_cb(response){
return true;
}
function server_time(){
//   a_mytime(a_server_time_cb);
//   timerID = setTimeout("server_time()", 1000);
}

function stop_before_timer(t_h, t_m, t_s){
/*<![CDATA[*/
  var secs = t_h * 60 * 60 + t_m * 60 + t_s;
  var wait = secs * 1000;
  var swf_counter=document.getElementById('swf_counter');

  document.getElementById('agreebutton').disabled=true;
  for(i=1;i<=secs;i++)
  {
    window.setTimeout("update(" + i + ")", i * 1000);
  }
  window.setTimeout("timer()", wait);

}
  function update(num)
  {
    if(num == (wait/1000))
    {
      document.getElementById('agreebutton').value = "Read next";
    }
    else
    {
      printnr = (wait/1000)-num;
      show_min = Math.floor(printnr/60);
      show_sec = printnr%60;
    }
  }
  function timer()
  {
    document.getElementById('agreebutton').disabled=false;
  }

function a_go_next(){
  if (document.getElementById("r_answer").value=="0" && document.getElementById("m_answer").value=="0"){
  alert ("Please save your answer");
  return false;
  }
  a_m_answer = document.getElementById("m_answer").value;
  a_q_id = document.getElementById("q_id").value;
  a_tr_id = document.getElementById("tr_id").value;
  a_tc_id = document.getElementById("tc_id").value;
  a_mc_id = document.getElementById("mc_id").value;
  a_q_t = document.getElementById("time_now").innerHTML;
  a_num = document.getElementById("q_num").value;
  a_num1 = document.getElementById("q_num1").value;
  a_memberid = document.getElementById("memberid").value;
  a_save_step(a_m_answer, a_q_id, a_tc_id, a_tr_id, a_q_t, a_num, a_num1, a_mc_id, a_memberid, a_save_step_cb);
}
function a_go_next1(){
  if (document.getElementById("r_answer").value=="0" && document.getElementById("m_answer").value=="0"){
  alert ("Please save your answer");
  return false;
  }
  a_m_answer = document.getElementById("m_answer").value;
  a_q_id = document.getElementById("q_id").value;
  a_tr_id = document.getElementById("tr_id").value;
  a_tc_id = document.getElementById("tc_id").value;
  a_mc_id = document.getElementById("mc_id").value;
  a_q_t = document.getElementById("time_now").innerHTML;
  a_num = document.getElementById("q_num").value;
  a_num1 = document.getElementById("q_num1").value;
  a_memberid = document.getElementById("memberid").value;
  a_real_mc_id = document.getElementById("real_mc_id").value;
  a_save_step(a_m_answer, a_q_id, a_tc_id, a_tr_id, a_q_t, a_num, a_num1, a_mc_id, a_memberid, a_real_mc_id, a_save_step_cb);
}

function a_restart(){
  a_tr_id = document.getElementById("tr_id").value;
  a_tc_id = document.getElementById("tc_id").value;
  a_mc_id = document.getElementById("mc_id").value;
  a_restart_exam(a_tc_id, a_tr_id, a_mc_id, a_save_step_cb);
}
function pause1(millisecondi)
{
    var now = new Date();
    var exitTime1 = now.getTime() + millisecondi;

    while(true)
    {
        now = new Date();
        if(now.getTime() > exitTime1) return;
    }
}
timerID_reload = 1;
function startreloadTimer(){
  id_i = document.getElementById("reload_timer").value;
  id_i = id_i - 1;
  document.getElementById("reload_timer").value = id_i;
  if (id_i <= 0){
        a_restart();
        clearTimeout(timerID_reload);
        timerID_reload = 0;
  }
   if (timerID_reload!=0){
   timerID_reload = setTimeout("startreloadTimer()", 1000);
   }
}


function a_restart1(){
if (document.getElementById("notpass").value == 2){return false;}
document.getElementById("notpass").value=1;
document.getElementById("lastquestion").value="no";
  alert ("You didn't finish exam with 100% score, please click on restart button.");
//startreloadTimer();
//  pause1(10000);
//alert('hi');
//  document.location.reload()
}

function a_save_step_cb(data){

document.getElementById("testdiv").style.visibility="hidden";
      kol = data.length;
      kol = kol-1;

      data = data.substring(1,kol);
      flag = data.substring(0,1);
      data = data.substring(1,kol);
      if (flag==1){
      document.getElementById("testdiv").innerHTML =data;
      }
      else{
      document.getElementById("testdiv").innerHTML = data;      
      document.getElementById("lastform").submit();
      }
document.getElementById("testdiv").style.visibility="visible";
}


function exittest(){
  a_tr_id = document.getElementById("tr_id").value;
  a_mc_id = document.getElementById("mc_id").value;
  document.getElementById("etr_id1").value = a_tr_id;
  document.getElementById("emc_id1").value = a_mc_id;
  document.getElementById("exitfrm").submit();
}



    var newwin2;
    function openVideo2(name)
    { alert('pidorasi')
      params = "toolbar=0,width=450,height=380,scrollbars=no";
      url = "/video/" + name + ".html";
      newwin2 = window.open(url,"_blank",params);
      setTimeout('newwin2.focus();',250);
    }
