// $Id: script.js,v 1.46 2008/05/12 12:25:28 rudakov Exp $
// --------- News images functions -------------
var ImagesSmall = new Array;
var ImagesBig = new Array;
var ImagesId = new Array;
var Alts = new Array;
var CurImage = new Array;
var img = new Array;
var IconOn = new Image;
var IconOff = new Image;

function Preload() {
	for (var key=0; key<ImagesSmall.length; key++) {
		if (!ImagesSmall[key]) continue;
		
		if (!IconOn.src) IconOn.src = '/img/media/icon_image_on.gif';
		
		if (!IconOff.src) IconOff.src = '/img/media/icon_image.gif';
		
		if (document.images["icon_" + key + "_0"]) document.images["icon_" + key + "_0"].src = IconOn.src;
		
		img[key] = new Array();
		
		for (j = 0; j < ImagesSmall[key].length; j++) {
			img[key][j] = new Image;
			img[key][j].src = ImagesSmall[key][j];
		}
	}
}

function ShowImage(parent, index) {
	ShowImage2(parent, index, ImagesId[index][CurImage[index]]);
}

function ShowImage2(parent,id,mediaid) {
	window.open('/cgi-bin/kernel.cgi?module=media&act=show&parent='+parent+'&id=' + id + '&mediaid=' + mediaid,'','resizable=yes, menubar=no, status=no, scrollbars=yes, statusbar=no, toolbar=no, width=550, height=500');
}

function Splash(i,j){
	document.images["icon_"+i+"_"+CurImage[i]].src = IconOff.src;
	
	if (img[i]) {
		document.images["item"+i].src=img[i][j].src;	
		document.images["item"+i].width=img[i][j].width;
		document.images["item"+i].height=img[i][j].height;
	}
	else {
		document.images["item"+i].src=ImagesSmall[i][j];
	}
	
	document.images["item"+i].alt = Alts[i][j];
	CurImage[i] = j;
	document.images["icon_"+i+"_"+j].src = IconOn.src
}

window.onload = Preload;

function flip(did) {
	var des = document.getElementById(did);
	
	if (des.style.display == "block")
		des.style.display = "none";
	else
		des.style.display = "block";
}

function check_children(name, state) {
	var elements = document.getElementsByTagName('input');
	
	if (/where_domain_\d+/.test(name)) {
		var count = 0;
		
		for (i = 0; i < elements.length; i++) {
			if (elements[i].className.match(name)) {
				elements[i].checked = state;
				document.getElementById('title_' + elements[i].id).style.fontWeight = state ? 'bold' : 'normal';
				count++;
			}
		}
		
		check_parent('where_portal', 'parent_where_portal', count);
	}
	else {
		for (i = 0; i < elements.length; i++) {
			if (elements[i].className.match(name)) {
				elements[i].checked = state;
				document.getElementById('title_' + elements[i].id).style.fontWeight = state ? 'bold' : 'normal';
			}
		}
	}
}

function check_parent(name, parent, count) {
	var inputs = document.getElementsByTagName('input');
	var parent = document.getElementById(parent);
	var length = inputs.length;
	var elements = 0;
	var checked = 0;
	
	if (/where_portal/.test(name)) {
		for (i = 0; i < inputs.length; i++) {
			if (inputs[i].className.match(name)) {
				elements++;
				
				if (inputs[i].checked) {
					checked++;
					document.getElementById('title_' + inputs[i].id).style.fontWeight = 'bold';
				}
				else {
					document.getElementById('title_' + inputs[i].id).style.fontWeight = 'normal';
				}
			}
		}
		
		if (checked == elements - 1 && !parent.checked) {
			parent.checked = true;
			document.getElementById('title_' + parent.id).style.fontWeight = 'bold';
		}
		else if (checked == elements - count && parent.checked) {
			parent.checked = false;
			document.getElementById('title_' + parent.id).style.fontWeight = 'normal';
		}	
	}
	else if (/where_domain_\d+/.test(name)) {
		for (i = 0; i < inputs.length; i++) {
			if (inputs[i].className.match(name)) {
				elements++;
				
				if (inputs[i].checked) {
					checked++;
					document.getElementById('title_' + inputs[i].id).style.fontWeight = 'bold';
				}
				else {
					document.getElementById('title_' + inputs[i].id).style.fontWeight = 'normal';
				}
			}
		}
		
		if (checked == elements - 1 && !parent.checked) {
			parent.checked = true;
			document.getElementById('title_' + parent.id).style.fontWeight = 'bold';
		}
		else if (checked == elements - 1 && parent.checked) {
			var portal = document.getElementById('parent_where_portal');
			parent.checked = false;
			portal.checked = false;
			document.getElementById('title_' + parent.id).style.fontWeight = 'normal';
		}
		
		check_parent('where_portal', 'parent_where_portal', elements);
	}
	else {
		for (i = 0; i < length; i++) {
			if (inputs[i].className == name) {
				elements++;
				
				if (inputs[i].checked) {
					checked++;
					document.getElementById('title_' + inputs[i].id).style.fontWeight = 'bold';
				}
				else {
					document.getElementById('title_' + inputs[i].id).style.fontWeight = 'normal';
				}
			}
		}
		
		if (checked == elements - 1 && !parent.checked) {
			parent.checked = true;
			document.getElementById('title_' + parent.id).style.fontWeight = 'bold';
		}
		else if (checked == elements - 1 && parent.checked) {
			parent.checked = false;
			document.getElementById('title_' + parent.id).style.fontWeight = 'normal';
		}
	}
}

function CheckIt() {
	for (var i = 1; i < 5; i++) {
		document.getElementById('titlerb' + i).style.fontWeight = document.getElementById('rb' + i).checked ? 'bold' : 'normal';
	}
}

function showComment(id){
 var obj = document.getElementsByTagName('DIV');
 for(var i in obj){
 if(obj[i].className != 'ans') continue;
 obj[i].style.display = (obj[i].id == 'answerid'+id)?'block':'none';
 }
}

function check_cook()
{
if (plugin) {fl = true;} else {fl = false;}
if (fl)
 {
 document.write('<div style="width:705px; height:337px; background-image:url(/i/bg2.jpg); margin-bottom:-30px;">');
 document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="705" height="337" id="field" align="middle">');
 document.write('<param name="allowScriptAccess" value="sameDomain" />');
 document.write('<param name="movie" value="/i/field.swf" />');
 document.write('<param name="quality" value="high" />');
 document.write('<param name="wmode" value="transparent" />');
 document.write('<embed src="/i/field.swf" quality="high" wmode="transparent" width="705" height="337" name="field" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
 document.write('</object>');
 document.write('</div>');
 }
 else
 {
 document.write('<img src="/i/noflash.jpg" style="margin-bottom:-30px;">');
 }
}
