var idTimer=null;


/* popup menu */

function menuOpen(){
	if(idTimer){
		clearTimeout(idTimer);
	}	
	document.getElementById("menuClose").style.display="none";
	document.getElementById("menuOpen").style.display="block";	
}

function menuClose(){
	idTimer=setTimeout("do_menuClose()",100);
}

function do_menuClose(){
	idTimer=null;
	document.getElementById("menuOpen").style.display="none";	
	document.getElementById("menuClose").style.display="block";
}


/* dialog menu */

function doMnOver(id){
	var o=document.getElementById(id);
	o.src="/templates/pic/dlg_i_hand.png";
	o.className="";
	o.className="png";
}

function doMnOut(id){
	var o=document.getElementById(id);
	o.src="/templates/pic/x.png";
	o.className="";
	o.className="png";
}

function showDialog(iconSrc,nameSrc,text){
	

}

/* status bar */

var lastStatusMsg="";

function showStatus(msg){
	var o=document.getElementById('StatusBar');
	if(msg=="#"){
		msg=lastStatusMsg;
	}
	else{
		lastStatusMsg=o.innerHTML;	
	}
	o.innerHTML=msg;
}

/* gallery */

var oGallerySelectItem=null;

function showGallery(galleryNum,colNum,defItem){
	var s="";
	
	s+='<table cellspacing="1" cellpadding="0" border="0" class="gallery">';
	for(var i=1; i<=5; i++){
		s+='<tr>';
		if(i==1){
			s+='<td rowspan="5"><img src="/templates/pic/gallery' + galleryNum + '_big' + defItem + '.gif" id="idGalleryBigImg" width="335" height="179" border="0"></td>';
		}					
		for(var j=1; j<=colNum; j++){

			s+='<td style="background:#FFF url(/templates/pic/gallery' + galleryNum + '_sml' + ((j-1)*5+i) + '.gif)"><div  id="idG_' + galleryNum + '_' + ((j-1)*5+i) + '" onClick="selectGalleryItem(this)" onMouseOver="hoverGalleryItem(this,1)" onMouseOut="hoverGalleryItem(this,0)"><span></span></div></td>';								

		}
		s+='</tr>';						
	}
	
	s+='</table>';
	return s;
}


function showGallery_value(img_w,img_h,galleryNum,colNum,defItem){
	var s="";
	
	s+='<table cellspacing="1" cellpadding="0" border="0" class="gallery">';
	for(var i=1; i<=5; i++){
		s+='<tr>';
		if(i==1){
			s+='<td rowspan="5"><img src="/templates/pic/gallery' + galleryNum + '_big' + defItem + '.gif" id="idGalleryBigImg" width="'+img_w+'" height="'+img_h+'" border="0"></td>';
		}					
		for(var j=1; j<=colNum; j++){

			s+='<td style="background:#FFF url(/templates/pic/gallery' + galleryNum + '_sml' + ((j-1)*5+i) + '.gif)"><div  id="idG_' + galleryNum + '_' + ((j-1)*5+i) + '" onClick="selectGalleryItem(this)" onMouseOver="hoverGalleryItem(this,1)" onMouseOut="hoverGalleryItem(this,0)"><span></span></div></td>';								

		}
		s+='</tr>';						
	}
	
	s+='</table>';
	return s;
}


function hoverGalleryItem(o,v){
	if(oGallerySelectItem && o.id==oGallerySelectItem.id) return;
	o.className=(v)?"over":"";
}

function selectGalleryItem(o){
	var params = o.id.split("_")
	if(oGallerySelectItem){
		oGallerySelectItem.className="";
	}	
	o.className="select";
	oGallerySelectItem=o;
	document.getElementById("idGalleryBigImg").src="/templates/pic/gallery" + params[1] + "_big" + params[2] + ".gif" ;
}

/* dialog  */


function show_dialog(id) {
document.getElementById(id).style.display="";	
};



function hide_dialog(id) {
document.getElementById(id).style.display="none";	
	if (document.getElementById('dlgMn1')) {doMnOut('dlgMn1');};
	if (document.getElementById('dlgMn2')) {doMnOut('dlgMn2');};
	if (document.getElementById('dlgMn3')) {doMnOut('dlgMn3');};
};



function close_all (id,i) {
do {
	if (document.getElementById(id+i)) {
		hide_dialog(id+i);
		close_all (id+i,1)
		i=i+1;
	} else (i=i+1);
} while (document.getElementById(id+i))
};


function show_lib_menu (id) {
close_all ('bibl',1);
show_dialog('bibl'+id);
close_all ('sbibl',1);
show_dialog('sbibl'+id);
i=2;
do {
		hide_dialog('abiblmenu'+i);
		show_dialog('biblmenu'+i);
		i=i+1;
} while (document.getElementById('abiblmenu'+i))
		hide_dialog('biblmenu'+id);
		show_dialog('abiblmenu'+id);
};

function show_lib_abc (id) {
close_all ('biblaz',1);
show_dialog('biblaz'+id);
i=1;
do {
		hide_dialog('abiblazmenu'+i);
		show_dialog('biblazmenu'+i);
		i=i+1;
} while (document.getElementById('biblazmenu'+i))
		hide_dialog('biblazmenu'+id);
		show_dialog('abiblazmenu'+id);
};


oGallerySelectItem = false;

function showExtGallery(){
	var s="";
	var colNum = Math.round((gallery.length-1)/5+0.5);
	if (gallery && gallery[1]){
		s+='<table cellspacing="1" cellpadding="0" border="0" class="'+galleryClassName+'">';
		for(var i=1; i<=5; i++){
			s+='<tr>';
			if(i==1) s+='<td rowspan="5"><img src="'+gallery[1]["image"]+'" id="idGalleryBigImg" width="'+galleryImageWidth+'" height="'+galleryImageHeight+'" border="0" alt="'+gallery[1]["alt"]+'" ></td>';
			for(var j=1; j<=colNum; j++)
				if (gallery[((j-1)*5+i)]) 
					if (((j-1)*5+i)==1) {s+='<td style="background:#FFF url('+gallery[((j-1)*5+i)]["thumb"]+')"><div  id="galleryItem_' + ((j-1)*5+i) + '" class="select" onClick="selectGalleryExtItem(this)"><a href="#" onclick="return false" title="'+gallery[((j-1)*5+i)]["alt"]+'">&nbsp;</a></div></td>';}
						else s+='<td style="background:#FFF url('+gallery[((j-1)*5+i)]["thumb"]+')"><div  id="galleryItem_' + ((j-1)*5+i) + '" onClick="selectGalleryExtItem(this)"><a href="#" onclick="return false"  title="'+gallery[((j-1)*5+i)]["alt"]+'">&nbsp;</a></div></td>';
				else s+='<td><div><span>&nbsp;</span></div></td>';
			s+='</tr>';						
		}
		s+='</table>';
		s+='<div id="idgaladd" class="'+galleryClassName+'_description_add">';
		if (gallery[1]["gal_add_text1"]) s+=gallery[1]["gal_add_href1"]+gallery[1]["gal_add_text1"]+'</a>';
		if (gallery[1]["gal_add_text2"]) s+=gallery[1]["gal_add_href2"]+gallery[1]["gal_add_text2"]+'</a>';		
		if (gallery[1]["gal_add_text3"]) s+=gallery[1]["gal_add_href3"]+gallery[1]["gal_add_text3"]+'</a>';		
		s+='</div>';		
		if (gallery[1]["description"]) s+='<div id="idGallerydescription" class="'+galleryClassName+'_description">'+gallery[1]["description"]+'</div>';
	}
	
	document.write(s);
}


function selectGalleryExtItem(o){
	var params = o.id.split("_")
	if(oGallerySelectItem) oGallerySelectItem.className="";
		else document.getElementById("galleryItem_"+1).className="";
	o.className="select";
	oGallerySelectItem=o;
	document.getElementById("idGalleryBigImg").src=gallery[params[1]]["image"];
	document.getElementById("idGalleryBigImg").alt=gallery[params[1]]["alt"];
	if (document.getElementById('idGallerydescription')) 
		if (gallery[params[1]]["description"]) document.getElementById('idGallerydescription').innerHTML=gallery[params[1]]["description"];
			else document.getElementById('idGallerydescription').innerHTML="";
	if (document.getElementById('idgaladd')) 
		if (gallery[params[1]]["gal_add_text1"]) document.getElementById('idgaladd').innerHTML=gallery[params[1]]["gal_add_href1"]+gallery[params[1]]["gal_add_text1"]+"</a>"+gallery[params[1]]["gal_add_href2"]+gallery[params[1]]["gal_add_text2"]+"</a>"+gallery[params[1]]["gal_add_href3"]+gallery[params[1]]["gal_add_text3"]+"</a>";
			else document.getElementById('idgaladd').innerHTML="";
			
}

function showExtGallery_photo(id){
	var s="";
	var colNum = Math.round((gallery.length-1)/5+0.5);
	if (gallery && gallery[id]){
		s+='<table cellspacing="1" cellpadding="0" border="0" class="'+galleryClassName+'">';
		for(var i=1; i<=5; i++){
			s+='<tr>';
			if(i==1) s+='<td rowspan="5"><img src="'+gallery[id]["image"]+'" id="idGalleryBigImg" width="'+galleryImageWidth+'" height="'+galleryImageHeight+'" border="0" alt="'+gallery[id]["alt"]+'" ></td>';
			for(var j=1; j<=colNum; j++)
				if (gallery[((j-1)*5+i)]) 
					if (((j-1)*5+i)==id) {s+='<td style="background:#FFF url('+gallery[((j-1)*5+i)]["thumb"]+')"><div  id="galleryItem_' + ((j-1)*5+i) + '" class="select" onClick="selectGalleryExtItem_photo(this)"><a href="#" onclick="return false" title="'+gallery[((j-1)*5+i)]["alt"]+'">&nbsp;</a></div></td>';}
						else s+='<td style="background:#FFF url('+gallery[((j-1)*5+i)]["thumb"]+')"><div  id="galleryItem_' + ((j-1)*5+i) + '" onClick="selectGalleryExtItem_photo(this)"><a href="#" onclick="return false"  title="'+gallery[((j-1)*5+i)]["alt"]+'">&nbsp;</a></div></td>';
				else s+='<td><div><span>&nbsp;</span></div></td>';
			s+='</tr>';						
		}
		s+='</table>';
		if (gallery[id]["description"]) s+='<div id="idGallerydescription" class="'+galleryClassName+'_description">'+gallery[id]["description"]+'</div>';
	}
	document.write(s);

}

function selectGalleryExtItem_photo(o){
	var params = o.id.split("_")
	if(oGallerySelectItem) oGallerySelectItem.className="";
		else document.getElementById("galleryItem_"+1).className="";
	o.className="select";
	oGallerySelectItem=o;
	document.getElementById("idGalleryBigImg").src=gallery[params[1]]["image"];
	if (document.getElementById('idGallerydescription')) 
		if (gallery[params[1]]["description"]) document.getElementById('idGallerydescription').innerHTML=gallery[params[1]]["description"];
			else document.getElementById('idGallerydescription').innerHTML="";
	if (document.getElementById('idGallery_photodata')) 
		if (gallery[params[1]]["data"]) document.getElementById('idGallery_photodata').innerHTML=gallery[params[1]]["data"];
			else document.getElementById('idGallery_photodata').innerHTML="";
	if (document.getElementById('idGallery_photopoints')) 
		if (gallery[params[1]]["points"]) document.getElementById('idGallery_photopoints').innerHTML="Рейтинг: "+gallery[params[1]]["points"];
			else document.getElementById('idGallery_photopoints').innerHTML="Рейтинг: 0";
			if (document.getElementById("points_form"))	document.points.id.value=gallery[params[1]]["id"];
		if (points[gallery[params[1]]["id"]] || form_off) {
			if (document.getElementById("points_form")) document.getElementById("points_form").style.display="none";			
//			alert ("off"+gallery[params[1]]["id"]);
		} else {
			if (document.getElementById("points_form")) document.getElementById("points_form").style.display="";						
//			alert ("on"+gallery[params[1]]["id"]);
		}
}


function openHelp(){
	W=600;
	H=490;
	X=(window.screen.availWidth/2)-(W/2);
	Y=(window.screen.availHeight/2)-(H/2);
	var param = "scrollbars=yes,status=no,resizable=0,width=" + W + ",height=" + H + ",left=" + X + ",top=" + Y;
	help=window.open('/help/','help', param);
	help.focus();
}

function openUserInfo(){
	W=600;
	H=490;
	X=(window.screen.availWidth/2)-(W/2);
	Y=(window.screen.availHeight/2)-(H/2);
	var param = "scrollbars=yes,status=no,resizable=0,width=" + W + ",height=" + H + ",left=" + X + ",top=" + Y;
	userinfo=window.open('/userinfo/','userinfo', param);
	userinfo.focus();
}

function checkFAQ(){
var flag=1;
	var pat=/.*[a-zA-Zа-яА-Я].*/;
if(!pat.test(document.reg_form.faq_text.value) || document.reg_form.faq_text.value=='') {
	//alert("Введите корректный текст");
	close_all ('dialog',1); show_dialog('dialog4');
	flag=0;
} 


	var pat=/^[a-zA-Z][a-zA-Z_.-d]*@[a-zA-Z_.-d]+.[a-zA-Z]{2,4}$/;
if(!pat.test(document.reg_form.email.value) && document.reg_form.email.value!='') {
   //alert("Введите корректный Email");
   close_all ('dialog',1); show_dialog('dialog3');
   flag=0;
} 	
	var pat=/.*[a-zA-Zа-яА-Я].*/;

if(!pat.test(document.reg_form.userlogin.value) || document.reg_form.userlogin.value=='' || document.reg_form.userlogin.value=='твоё имя') {
	//alert("Введите корректный имя");
	close_all ('dialog',1); show_dialog('dialog2');
	flag=0;
} 

if (flag) {
 document.reg_form.submit();
}

}

function openPopup (href,id) {
	//alert (href+" "+id);
	W=600;
	H=545;
	X=(window.screen.availWidth/2)-(W/2);
	Y=(window.screen.availHeight/2)-(H/2);
	var param = "scrollbars=yes,status=no,resizable=0,width=" + W + ",height=" + H + ",left=" + X + ",top=" + Y;
	userinfo=window.open(href,id, param);
	userinfo.focus();
}

function openPopup_games (href,id) {
	//alert (href+" "+id);
	W=600;
	H=490;
	X=(window.screen.availWidth/2)-(W/2);
	Y=(window.screen.availHeight/2)-(H/2);
	var param = "scrollbars=no,status=no,resizable=0,width=" + W + ",height=" + H + ",left=" + X + ",top=" + Y;
	userinfo=window.open(href,id, param);
	userinfo.focus();
}

function show_sch (id) {
	document.getElementById("sch_vs_1").style.display="none";
	document.getElementById("sch_vs_2").style.display="none";
	document.getElementById("sch_vs_3").style.display="none";
	document.getElementById("sch_vs_4").style.display="none";
	document.getElementById("sch_vs_5").style.display="none";	
	document.getElementById("sch_vs_"+id).style.display="";

}