var man = [];
var timer = [];
var dyns = [];

function popupItem(item, width, height) {
	window.open(
	item,
	'_blank',
	'toolbar=0,location=0,statusbar=0,menubar=0,width='+width+',height='+height+',left=20,top=20,scrollbars=yes'
	);
}

function showBlock(block) {
	var blockcontainer = document.getElementById('blockcontainer');
	var maincontainer = document.getElementById('maincontainer');
	maincontainer.style.height=maincontainer.offsetHeight+'px';
	height = blockcontainer.offsetHeight;
	divs = blockcontainer.getElementsByTagName('DIV');
	if(document.getElementById(block).style.display=='block') {
		document.getElementById(block).style.display='none';
	}
	else {
		for(i=0; i<divs.length; i++) {
			if(divs[i].id.indexOf('block')!=-1) {
				divs[i].style.display='none';
			}
		}
		document.getElementById(block).style.display='block';
	}
	maincontainer.style.height=maincontainer.offsetHeight+blockcontainer.offsetHeight-height+'px';
}

function init () {
try {
	city=new Array;
	city[0]=document.getElementById("moscow");
	city[1]=document.getElementById("rostov");
	city[2]=document.getElementById("cherepovec");

	button=new Array;
	button[0]=document.getElementById("moscow").getElementsByTagName("a")[0];
	button[1]=document.getElementById("rostov").getElementsByTagName("a")[0];
	button[2]=document.getElementById("cherepovec").getElementsByTagName("a")[0];

	var count=city.length;

	for (i=0; i<count; i++) {
		button[i].city=i;
		button[i].onclick = function () {
			for (j=0; j<count; j++) city[j].className="scheme";
			city[this.city].className="current scheme";
			return false;
		}
	}
}
catch (err) {}

try {
	man = document.getElementById('triomap').getElementsByTagName('area');

	for (i=0; i<man.length; i++ ) {
		man[i].count = i;
		man[i].onmouseover = function () {
			document.getElementById('p1').style.display = "none";
			document.getElementById('p2').style.display = "none";
			document.getElementById('p3').style.display = "none";
			document.getElementById('bar1').style.display = "none";
			document.getElementById('bar2').style.display = "none";
			document.getElementById('bar3').style.display = "none";
			document.getElementById('p'+(this.count+1)).style.display = "block";
			document.getElementById('bar'+(this.count+1)).style.display = "block";
		}
	}
	document.getElementById('p1map').getElementsByTagName('area')[0].onmouseout = function () {
		clearTimeout(timer[0]);
		timer[0]=setTimeout('document.getElementById("p1").style.display = "none";document.getElementById("bar1").style.display = "none";', 100);
	}
	document.getElementById('p2map').getElementsByTagName('area')[0].onmouseout = function () {
		clearTimeout(timer[1]);
		timer[1]=setTimeout('document.getElementById("p2").style.display = "none";document.getElementById("bar2").style.display = "none";', 100);
	}
	document.getElementById('p3map').getElementsByTagName('area')[0].onmouseout = function () {
		clearTimeout(timer[2]);
		timer[2]=setTimeout('document.getElementById("p3").style.display = "none";document.getElementById("bar3").style.display = "none";', 100);
	}
}
catch (err) { }

try {
	dynz = document.getElementsByTagName('div');
	for ( i=0; i<dynz.length; i++ ) {
		if ( dynz[i].className.indexOf('dyn')>-1 ) dyns.push(dynz[i]);
	}
}
catch (err) { }

//current_yield
try {
	var Payment = [], CurrentYield = [], Dividend = [];

	var tmpTags = document.getElementsByTagName('*');
	for ( i=0; i<tmpTags.length; i++ ) {
		if ( tmpTags[i].className == 'payment' ) Payment.push(tmpTags[i]);
		if ( tmpTags[i].className == 'current_yield' ) CurrentYield.push(tmpTags[i]);
		if ( tmpTags[i].className == 'dividend' ) Dividend.push(tmpTags[i]);
	}

	for ( i=0; i<Dividend.length; i++ ) {
		Dividend[i].innerHTML = parseInt( ( parseInt(CurrentYield[i].innerHTML.replace(/\s/,''))-parseInt(Payment[i].innerHTML.replace(/\s/,'')) )*100/parseInt( Payment[i].innerHTML.replace(/\s/,'') ) ) + '%';
	}
}
catch (err) { }

}//init

function dy(num) {
	n=num;
	text="<img src=\"/imgs/DY/dy"+num+".jpg\" alt=\"\" usemap=\"#dymap1\" />\n";

	text+='<map id="dymap1" name="dymap1"><area alt="" href="javascript:dy(1)" coords="171,187,279,78,347,187,279,295" shape="poly"/><area alt="" href="javascript:dy(2)" coords="171,187,279,295,171,358,62,295" shape="poly"/><area alt="" href="javascript:dy(3)" coords="171,187,62,295,0,187,62,78" shape="poly"/><area alt="" href="javascript:dy(4)" coords="171,187,62,78,171,0,279,78" shape="poly"/><area alt="" href="javascript:dy(2)" coords="0,0,347,358" shape="rect"/></map>'

	document.getElementById("dy").innerHTML=text;

	/*text="<img src=\"/imgs/DY/dy"+num+".jpg\" alt=\"\" usemap=\"#dymap"+num+"\" />\n";

	text+="<map name=\"dymap"+num+"\">\n";
	text+="<area shape=\"poly\" coords=\"171,187,279,78,347,187,279,295\" nohref />\n";
	num++;
	if(num>4) num=1;
	text+="<area shape=\"poly\" coords=\"171,187,279,295,171,358,62,295\" href=\"javascript:dy("+(num)+")\" />\n";
	num++;
	if(num>4) num=1;
	text+="<area shape=\"poly\" coords=\"171,187,62,295,0,187,62,78\" href=\"javascript:dy("+(num)+")\" />\n";
	num++;
	if(num>4) num=1;
	text+="<area shape=\"poly\" coords=\"171,187,62,78,171,0,279,78\" href=\"javascript:dy("+(num)+")\" />\n";
	num=n;
	num++;
	if(num>4) num=1;
	text+="<area shape=\"rect\" coords=\"0,0,347,358\" href=\"javascript:dy("+(num)+")\" />\n";

	text+="</map>";

	document.getElementById("dy").innerHTML=text;*/

	for (i=1; i<5; i++) {
		document.getElementById("dy"+i).className="hidden";
	}
	document.getElementById("dy"+n).className="";
}

function showblock(block) {
	for ( i=0; i<dyns.length; i++ ) {
		dyns[i].className = "dyn";
	}
	dyns[block-1].className = "dyn_active";
}

function checkEmailChar(ch) {
	numcheck = /[\w\d\.\-\_\@]/;
	return numcheck.test(ch);
}

window.onload=init;