/*
	copyright 2005 by Ivan Tugoy, for Effecton Project.
*/

var codebase = 'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"';
var embedType = 'type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"';
var paramStr;
var embedStr;
var pic1;
var sss;
var msie;

var mailForm = '<form action="http://www.maillist.ru/cgi/gsps.cgi" target="_blank">\
<input type="hidden" name="topic" value="65744">\
<input type=hidden name=grp value="psychology.effecton">\
<input class=rightedit type=text name=email size=20 maxlength=100 value="ваш e-mail">\
<input type="hidden" name="reg_mode" value="rapid">\
<input type="hidden" name="from" value="na_subconf">\
<center><input type=submit value="Получать!" style="font-size: 8pt; width: 100px"></center>\
</form>';

var labels = '<a href="http://www.effecton.ru/rss.xml"><img width=80 height=15 border=0 src="/media/pics/rss.gif"></a>\
	<a href="http://lenta.yandex.ru/settings.xml?name=feed&url=www.effecton.ru/rss.xml"><img width=100 height=22 border=0 src="/media/pics/addfeed.gif" vspace=3></a>\
	<a target=_top href="http://top.mail.ru/jump?from=1019543"><img SRC="http://de.c8.bf.a0.top.list.ru/counter?id=1019543;t=245;l=1" border=0 height=31 width=88 alt="Рейтинг@Mail.ru"/></a>\
	<a href="http://top100.rambler.ru/top100/Science"><img src="http://top100-images.rambler.ru/top100/banner-88x31-rambler-black2.gif" alt="Rambler\'s Top100" width=88 height=31 border=0></a>';

var style1 = "<style>#sections,#icon,#sibling,#location,#footer,#mainTable{display:none}</style>";
var da = null;
var bulk = '\
<link rel="stylesheet" href="/theme/main.css" type="text/css"/>\
<table width="$mainTableWidth" height="100%" border="0" cellspacing="0" cellpadding="0" align="center" id="mainTable1" style="border-collapse: collapse">\
<tr>\
	<td id="topTabs" colspan="4" align="left" valign="top">\
		<div id="stripeDiv"><div id="stripeInside"><div id="siblingBar">\
			<table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0">\
				<tr><td id="siblingPrev"></td><td id="siblingNext" align="right"></td></tr>\
			</table>\
		</div></div></div>\
		<div id="titleBack"><div id="titleBackInner">&nbsp;</div></div>\
		<div id="iconTray"><img id="iconImage" width="128" height="128" alt=""></div>\
		<div id="logoOut"><div id="logo2"></div></div>\
		<div id="titlesPlace" style="width:$titlesWidthpx">\
			<div class="title" id="title0">&nbsp;</div>\
			<div class="title" id="title1">&nbsp;</div>\
			<div class="title" id="title2">&nbsp;</div>\
		</div>\
		<div id="tobTabsInside"></div>\
	</td>\
</tr>\
<tr>\
	<td id="buttonsTD" width="190" valign="top"><table style="height:100%;width:100%" cellpadding="0" cellspacing="0" border="0">\
		<tr><td id="bt2" valign="top"></td></tr>\
		<tr><td id="bt3" style="filter:alpha(opacity=40);height:5px; padding-top:7px; padding-right:20px" align="left">\
			<div style="width:140px;height:100%; margin-left:15px; text-align: center">'+labels+'</div>\
		</td></tr>\
		</table>\
		</td>\
	<td valign="top" id="bodyInner" style="padding-top: 105px; padding-left: 7px; width:$bodyWidth;overflow: hidden">\
		<div id="divInner" style="width:$bodyWidth1; overflow-x: auto"></div>\
	</td>\
	<td valign="top" align="left" id="rightInner" style="padding-top: 81px"></td>\
</tr>\
<tr>\
	<td id="credits" valign="top"><div id="creditsOuter"><div id="creditsDiv">\
		&copy;1996,2005 Effecton Inc.\
		<a class="credits" href="mailto:support@effecton.ru">support@effecton.ru</a>\
	</div></div></td>\
	<td colspan="2" id="bottom" align="right" valign="top">\
		<div id="bottomTabs"></div>\
	</td>\
</tr>\
</table>';

function getRightIndex(el) {
	var index = -1;
	var titles = da.rightInner.all.tags("h2");
	for (i=0;i<titles.length;i++) {
		index++;
		if (titles[i]==el) return index;
	}
}
function getRightDiv(el) {
	var index = getRightIndex(el);
	var divs = da.rightInner.all.tags("div");
	return divs[index];
}
function toggleRightTitle() {
	var el = window.event.srcElement;
	var s = getRightDiv(el).style;
	var shown = s.display=='none';
	s.display=(shown)?'block':'none';
	el.style.color=(shown)?'black':'#5b5b5b';
}
function cropRight(txt) {
	var pos = txt.indexOf('. ');
	if (pos>-1) return txt.substr(0,pos);
	return txt;
}
function getTitleString(index) {
	var pos = sss.indexOf('<BR>');
	if (pos==-1) pos=sss.indexOf('<br>');
	if (pos==-1) pos=sss.length;
	if (index==1) {return sss.substr(0,pos)}
		else if (index==2) {
			var a = sss.substr(pos+4);
			return cropRight(a);
		};
}
function getLocationString() {
	return da.location.innerHTML;
}
function setTitle(el,text) {
	if (text=='') {
		el.style.height='1px';
		if (el==da.title1) {
			da.title2.style.height = '50px';
			da.title2.style.marginTop = '35px';
		}
		if (el==da.title2) da.title1.style.height = '50px';
	};
	var other='';
	el.insertAdjacentHTML('AfterBegin',text);
}
function assignTitles() {
	setTitle(da.title0,getLocationString());
	setTitle(da.title1,getTitleString(1));
	setTitle(da.title2,getTitleString(2));
}
function assignIcon() {
	da.iconImage.src = da.icon.src;
	da.iconImage.alt = document.all.description.content;
}
function handleRightGroups() {
	var titles = da.rightInner.all;
	for (i=0;i<titles.length;i++) {
		if (titles[i].tagName=='H2') {titles[i].onclick=toggleRightTitle};
		if (titles[i].tagName=='DIV') {titles[i].style.display='block'};
	}
}
function setSibling(dst,src) {
	var text = '<div class="sibdiv"><a href="'+src.href+'" title="'+src.innerText+'" class="sibling">'+src.title+'</a></div>';
	dst.insertAdjacentHTML('AfterBegin',text);
}
function assignSiblings() {
	var sibs = da.sibling.all.tags("A");
	setSibling(da.siblingPrev,sibs[0]);
	setSibling(da.siblingNext,sibs[1]);
}
function doButtonClick(href) {
	location.href = href;
}
function doButtonOver(el) {
	var el = eval("da."+el);
	el.style.backgroundPosition = "bottom left";
}
function doButtonOut(el) {
	var el = eval("da."+el);
	el.style.backgroundPosition = "top left";
}
function assignButtons() {
	var buttons = da.buttons.all.tags("A");
	var text = "";
	for (i=0;i<buttons.length;i++) {
		text += '\
		<table id="btn'+i+'" class="button" style="background-image:url(/theme/pics/buttonBack2.gif)" onclick="doButtonClick(\''+buttons[i].href+'\')" \
		onmouseover="doButtonOver(\'btn'+i+'\')" onmouseout="doButtonOut(\'btn'+i+'\')" \
		width="100%" height="100%" cellspacing="0" cellpadding="0" border="0"><tr>\
		<td class="buttonIcon">&nbsp;</td>\
		<td class="buttonText" valign="middle">\
			<a class="btn" href="'+buttons[i].href+'" title="'+buttons[i].title+'">' + buttons[i].innerText + '</a>\
		</td></tr></table>';
	}
	da.bt2.insertAdjacentHTML('AfterBegin',text);
	if (da.cnt) da.bt3.insertAdjacentHTML('AfterBegin',da.cnt.innerHTML);
	da.buttons.innerHTML='';
}
function assignParts() {
	da.divInner.insertAdjacentHTML('AfterBegin',da.bodyText.innerHTML);
	da.rightInner.insertAdjacentHTML('AfterBegin',da.rightBar.innerHTML);
	assignButtons();
	handleRightGroups();
	assignIcon();
	assignSiblings();
	assignTitles();
//	da.bodyText.innerHTML='';
//	da.rightBar.innerHTML='';
}
function addParam(name,value) {
	paramStr += '<param name="'+name+'" value="'+value+'">';
	embedStr += name+'="'+value+'" ';
}
function addFlash(id,filename,w,h,params) {
	if (location.protocol=='self:') filename = 'D:/Projects/SmarTEST2/site'+filename;
	paramStr = embedStr = "";
	addParam("menu","false"); addParam("quality","high"); addParam("scale","exectfit");
	addParam("bgcolor","#ffffff"); addParam("wmode","transparent");
	return '<object id="'+id+'" ' + codebase + ' width="'+w+'" height="'+h+'">\
		<param name="movie" value="'+filename+params+'">'+paramStr+'\
		<embed src="'+filename+'" '+embedStr+'width="'+w+'" height="'+h+'" '+embedType+'></embed>\
	</object>';
}
/*function getSectionParams() {
	var	s="";
	var currentSection = 0;
	var sections = document.body.all.tags("B")[0].all.tags("A");
	document.body.all.tags("B")[0].style.display = "none"
	for (i=0;i<4;i++){
		s += 'link'+(i+1)+'='+sections[i].href+'&';
		s += 'label'+(i+1)+'='+sections[i].innerText+'&';
		if (sections[i].className=='cs') currentSection=i;
	}
	return '?'+s+'&sectionIndex='+currentSection;
}*/
function getSectionParams() {
    var    s="";
    var currentSection = 0;
    var sections = document.body.all.tags("B")[0].all.tags("A");
    document.body.all.tags("B")[0].style.display = "none"
    for (i=0;i<4;i++){
        s += 'link'+(i+1)+'='+sections[i].href+'&';
        if (i>0) 
          s += 'label'+(i+1)+'='+sections[i].innerText+'&';
        else
          s += 'label'+(i+1)+'=Тесты&';
        if (sections[i].className=='cs') currentSection=i;
    }
    return '?'+s+'&sectionIndex='+currentSection;
}

function createView() {
	var sectionsParams = getSectionParams();
	var topTabs = addFlash("topTabFlash","/theme/pics/topTabs.swf",406,43,sectionsParams);
	var bottomTabs = addFlash("bottomTabFlash","/theme/pics/bottomTabs.swf",421,48,sectionsParams);
//	var logo = addFlash("logoFlash","/theme/pics/logo.swf",280,92,'');
	da.tobTabsInside.insertAdjacentHTML('AfterBegin',topTabs);
	da.bottomTabs.insertAdjacentHTML('AfterBegin',bottomTabs);
//	da.logo.insertAdjacentHTML('AfterBegin',logo);
}
function esc(txt) {
   return txt.replace(/\"/g,'\'');
}
function doResize() {}
function getOuterHTML(para) {
	var a = para.children[0];
	var href = a.href;
	var img = a.children[0].src;
	a.children[0].outerHTML = '';
	var text = a.children[0].innerHTML;
	var text1 = text2 = '&nbsp';
	var pos = text.indexOf(': ');
	if (pos==-1) {
		text1 = text
	} else {
		text1 = text.substring(0,pos);
		text2 = text.substr(pos+2);
	}
	var table = '\
		<table width="100%" cellspacing="0" cellpadding="0" border="0" style="margin-bottom: 5px; margin-top: 5px">\
			<tr><td rowspan="2" width="68" align="left"><a href="'+href+'"><img border="0" src="'+img+'" alt="'+esc(text)+'" width="64" height="64"></a></td>\
			<td class="sectionTocTitle1" valign="bottom"><a href="'+href+'" class="sti">'+text1+'</a></td></tr>\
			<tr><td class="sectionTocTitle2" valign="top"><a href="'+href+'" class="sectionTocItem2">'+text2+'</a></td></tr>\
		</table>';
	return table;
}
function processContent() {
	var para = da.bodyText.all.tags("P");
	for (i=0;i<para.length;i++) {
		if (para[i].className=='stt') {
			para[i].outerHTML = getOuterHTML(para[i]);
		}
	}
}
function getWidth() {
	var n = document.body.offsetWidth-25;
	if (n<758) n=758;
	if (n>950) n=950;
	return n;
}
function cacheFirstH1() {
	var h0 = da.tags("H1")[0];
	sss = h0.innerHTML;
//	h0.style.display = 'none';
}
function doLoad() {
	if (!msie) return;
	da = document.all;
	createView();
	cacheFirstH1();
	processContent();
	assignParts();
	document.body.onresize = doResize;
}
function detectBrowsers() {
	msie = (navigator.appVersion.indexOf("MSIE")>-1);
	if (msie) {
		if (document.bgColor=='') {msie = false; return}
		var msieIndex = navigator.appVersion.indexOf("MSIE") + 5;
		var ver = navigator.appVersion.substr(msieIndex,1);
		if (parseInt(ver)<5) msie = false;
		var host=document.location.hostname;
		msie = (host==''||host.indexOf("effecton")>-1);
	}
}
function doInit() {
	detectBrowsers();
	if (!msie) return;
	document.write(style1);
	pic1 = new Image(193,80);
	pic1.src="/theme/pics/buttonBack2.gif";
	var w = getWidth();
	bulk = bulk.replace(/\$mainTableWidth/,w);
	bulk = bulk.replace(/\$titlesWidth/,w-215);
	bulk = bulk.replace(/\$bodyWidth/,w-215-182);
	bulk = bulk.replace(/\$bodyWidth1/,w-215-182);
	document.write(bulk);
}
function doResize() {
	var w = getWidth();
	da.mainTable1.style.width = w;
	da.titlesPlace.style.width = w-215;
	da.bodyInner.style.width = w-215-182;
	da.divInner.style.width = w-215-182;
}
function addRight(head,href,icon,body){
	if (!msie) return;
	r_text = '';
	r_text += '<h2 class="rightHead">'+head+'</h2><div class="rightDiv">';
	r_text += '<a class="rightLink" href="'+href+'">';
//	r_text += '<img src="/media/icons/'+icon+'" width="64" height="64" align="left" border="0">';
	r_text += '<p class="rightText">'+body+'</p></a>';
	r_text += '</div>';
	document.write(r_text);
}

var spoStyle = "<style>#spoBody {height:92px;border-bottom:1px solid black;border-top:1px solid black;padding-left:10px}\
#spoTitle {height:21px;background:#ad6645;color:#f00;font:bold 8pt verdana;border-top:1px solid black;border-right:1px solid\ black}\
#spoTitle0 {height:18px;font-size:8pt;font-weight:bold;color:maroon}\
#spoTitleInner {width:100%;filter:glow(color=black,strength=1);font-size:8pt;text-align:center}\
#spoBodyInner {font-size: 8pt}\
td#spoBody div ul li {margin-bottom: 2px}\
</style>";
function addSpo(title0,title1,message,alink,img,price) {
	var s = ' onclick="location.href=\''+alink+'\'" style="cursor:hand;position:absolute;';
	var s2 = 'onmouseover="this.style.color=\'aqua\'" onmouseout="this.style.color=\'#ffffe4\'"';
	spoText = '<table style="height:165px; width:100%" border="0" cellpadding="0" cellspacing="0">\
	<tr><td style="width:144;color:#ffffe4" '+s2+' rowspan="4">\
		<span'+s+'width:105px;height:45px;text-align:center;margin-top:109px;font:bold 30pt sans-serif; filter:glow(color=black,strength=5)">'+price+'</span>\
		<span'+s+'width:32px;height:20px;margin-top:119px;margin-left:112px;font:bold 12pt sans-serif; filter:glow(color=black,strength=5)">руб</span>\
		<a href="'+alink+'"><img src="'+img+'" alt="'+title0+' '+title1+'" width="144" height="165" border="0"></a>\
	</td>\
	<td id="spoTitle0" align="right">'+title0+'</td></tr>\
	<tr><td id="spoTitle" style="padding-right:5px">\
		<span id="spoTitleInner">'+title1+'</span>\
	</td></tr>\
	<tr><td id="spoBody">\
		<div style="overflow:auto;height:92px"><table border="0" height="100%"><tr><td id="spoBodyInner">\
		<ul style="margin-bottom:0px; margin-top: 2px">'+message+'</ul>\
		</td></tr></table><div>\
	</td></tr>\
	<tr style="height:33px"><td valign="top" align="right" style="text-align: right; text-align: 10pt verdana">\
		<a href="'+alink+'" style="color: maroon; font-size: 14pt">Заказать!</a>\
	</td></tr>\
</table>';
	document.write(spoText+spoStyle);
}

function updateCart(txt) {
	el = da.cartHead;
	if (el) {
		txt.search(/<h2.*?>(.*?)<\/h2>/im);
		el.innerText = RegExp.$1;
		n = txt.indexOf('</h2>')+5;
		a = txt.substr(n);
		getRightDiv(el).outerHTML = a;
	} else {
		da.rightInner.insertAdjacentHTML('AfterBegin',txt);
		handleRightGroups();
	}
	alert('Товар добавлен в корзину, спасибо!');
}

function alertContents(http_request) {
	if (http_request.readyState == 4) {
     if (http_request.status == 200) {
     	updateCart(http_request.responseText);
     } else {
       alert('Произошла ошибка - товар не был добавлен.');
     }
   }
}

function doOrder(code) {
	http_request = new ActiveXObject("Microsoft.XMLHTTP");
	http_request.onreadystatechange = function() { alertContents(http_request) };
	http_request.open('GET', 'http://www.effecton.ru/shop/add.php?code='+code, true);
	http_request.send(null);
}