﻿var chnum = 0;
var chid = 0;
var xBookID = 'NoID!';

function hErr(err,place)
{var mess ="Произошла ошибка при выполнении процедуры: "+place+"\n\n" +
             "Ошибка: "+err.description+"\n\n"+
             "Сообщите, пожалуйста, в службу поддержки: help@e-college.ru \n\n"+
             "Нажмите ОК для продолжения\n\n";
   window.alert(mess);          
}
 function WriteCookie (cookieName, cookieValue, expiry) {
            var expDate = new Date();
            try{
            if (expiry) {
                expDate.setTime (expDate.getTime() + expiry);
                document.cookie = cookieName + "=" + escape (cookieValue) + "; expires=" + expDate.toGMTString()+"; path=/";
            } else {
                document.cookie = cookieName + "=" + escape (cookieValue)+"; path=/";
            }
		} catch(err) {hErr(err,"WriteCookie")};
        }

        function wReadCookie (CookieName) {
        try{
            var CookieString = document.cookie;
            var CookieSet = CookieString.split (';');
            var SetSize = CookieSet.length;
            var CookiePieces
            var ReturnValue = "";
            var x = 0;
            for (x = 0; ((x < SetSize) && (ReturnValue == "")); x++) {
                CookiePieces = CookieSet[x].split ('=');
                if (CookiePieces[0].substring (0,1) == ' ') {
                    CookiePieces[0] = CookiePieces[0].substring (1, CookiePieces[0].length);
                }
                if (CookiePieces[0] == CookieName) {
                    ReturnValue = CookiePieces[1];
                }
            }
            return unescape( ReturnValue );
		} catch(err) {hErr(err,"wReadCookie"); return unescape( ReturnValue )};
        }

        function ReadCookie (cookieName) {
            var cookieValue = document.cookie;
            var cookieStartsAt = cookieValue.indexOf(" "+cookieName+"=");
	    if (cookieStartsAt == -1)
		{ cookieStartsAt = cookieValue.indexOf(cookieName+"=")}
	    if (cookieStartsAt == -1)
		{ cookieValue = "" }
	      else
                { cookieStartsAt = cookieValue.indexOf("=",cookieStartsAt)+1;
                  var cookieEndsAt = cookieValue.indexOf(";",cookieStartsAt);  
		  if (cookieEndsAt == -1) {cookieEndsAt = cookieValue.length}
		  cookieValue = unescape(cookieValue.substring(cookieStartsAt,cookieEndsAt));
		}	
          return cookieValue;

        }
function setCookie( key, value )
  {
  WriteCookie( key, value, 1000 * 60 * 60 * 24 * 31 );
  }

function getCookie( key, dflt )
  {try{
  var reslt = ReadCookie( key );
  if (reslt != "undefined" && reslt != "" )
    return reslt;
  else
    return dflt;
} catch(err) {hErr(err,"getCookie"); return dflt};
  }

function doStart()
  {var sa = document.getElementById("sa");
  try{var w = (screen.width*0.7);
  z = getCookie( "tabw", w );
  sa.style.width = z;
} catch(err) {hErr(err,"doStart"); return false};
  }

function getParamURL(sParamName){
    var Params = unescape(location.search.substring(1)).split("&"); // отсекаем «?» и вносим переменные и их значения в массив
    var variable = "";
    for (var i = 0; i < Params.length; i++){ // пробегаем весь массив
        if (Params[i].split("=")[0] == sParamName){ // если это искомая переменная — бинго!
            if (Params[i].split("=").length > 1) variable = Params[i].split("=")[1]; // если значение параметра задано, то возвращаем его
            return variable;
        }
    }
    return "";
}



function inc(sa)
	{
	x = sa.style.width;
	y = parseInt( x.substring( 0, x.length-2 ) );
	y += 50;
	sa.style.width = y;
  setCookie( "tabw", y );
	}

function dec(sa)
	{
	x = sa.style.width;
	y = parseInt( x.substring( 0, x.length-2 ) );
	y -= 50;
	sa.style.width = y;
  setCookie( "tabw", y );
	}


function updhiddenill(apic)
{
 try{
 if (apic.style.display=="none")
    {apic.src=apic.getAttribute("imgSrc"); apic.style.display="block"}
    else {apic.style.display="none"}
   return false 
} catch(err) {hErr(err,"updHIll"); return false};
}

function hideIt(athis)
{ try{athis.style.display="none"} catch(err) {hErr(err,"hideit"); return false};
}

var currSound = null;

function auCtrl(whSound,play) {this.src = play? whSound:''}

function updSound()
{try{ 
document.write('<BGSOUND ID="auIEContainer">')
 document.body.insertAdjacentHTML("BeforeEnd","<DIV ID='auEmb' STYLE='position:absolute;'></DIV>");
 auCon = document.all.auIEContainer;
 auCon.control = auCtrl;
} catch(err) {hErr(err,"updSound"); return false};
}
function doPlaySound(apath){ try{if (window.auCon) auCon.control(apath,true); } catch(err) {hErr(err,"doPlaySound")};}

function playSound(aimg)
{try{
 if (currSound) 
        {currSound.src="../files/mm-audio.gif"};
 if (currSound==aimg){currSound=null; doPlaySound('../files/noSound.mp3')}
     else {currSound=aimg;   aimg.src="../files/mm-audioOn.gif"; doPlaySound(aimg.apath)}
} catch(err) {hErr(err,"playSound"); return false};
}
