﻿	
function el(id) {
	return document.getElementById(id)
}

function show(id) {
    document.getElementById(id).style.display='';
}    

function hide(id) {
    document.getElementById(id).style.display='none';
}    

function show_hide(id) {
    var sec =document.getElementById(id);
	if (sec == null) return;
	if (sec.style.display == '') {   
        sec.style.display = 'none';
   	} else {
        sec.style.display = '';
	}
}

function redirect(url) {
	window.location = url;
	return false;
}

function if_confirm(url) {
	if(confirm(text_are_you_sure))
		redirect(url);
}

function select_all_items(form) {
	if(!form) form = 'itemlist'; 
	f = document.forms[form];
	els = f.elements;
	for (e=0; e<els.length; e++) {
		if (els[e].name && els[e].name.substr(0,5)=='item_') els[e].checked='checked';
	}
}

function clear_all_items(form) {
	if(!form) form = 'itemlist'; 
	
	f = document.forms[form];
	els = f.elements;
	for (e=0; e<els.length; e++) {
		if (els[e].name && els[e].name.substr(0,5)=='item_') els[e].checked=null;
	}
}

function select_clear(form) {
	if(!form) form = 'itemlist'; 
	f = document.forms[form];
	els = f.elements;
	for (e=0; e<els.length; e++) 
		if (els[e].name && els[e].name.substr(0,5)=='item_') 
			if(!els[e].checked)
				return select_all_items(form);
	clear_all_items(form);
}

function SendItems(target, mode, form) {
	if(!form) form = 'itemlist';
 	f = document.forms[form];
	els = f.elements;
	sel = 0;
	
	for (e=0; e<els.length; e++) {
		if (els[e].name && els[e].name.substr(0,4)=='item' && els[e].checked) sel++;
	}
	
	if (!sel) {
		alert('Ни одного элемента не выбрано');
		return;
	}
	
	if(mode=='delete') 
		if (!confirm(text_are_you_sure)) return;
	
	f.action = target;
	f.mode.value = mode;
	f.submit();
}

function popup(link, width, height, resizable, scroll) {
    if (!window.focus) 
		return true;
	
	var href;
	if (typeof(link) == 'string')
   		href=link;
	else
   		href=link.href;
	if(!resizable) 
		resizable = 'no';
	
	if(!scroll) 
		scroll = 'no';

	window.open(href, '', 'width='+width+',height='+height+',scrollbars='+scroll+',resizable='+resizable+',alwaysRaised=yes');
}

function Submit(form) {
	f = document.forms[form];
	f.submit();
}

function Locale(lang) {
	switch(lang) {
		case 'en':
			document.cookie = "language=en";
			break;
		case 'ru':
			document.cookie = "language=ru";
			break;	
		default: document.cookie = "language=en";
	}
	window.location.reload();
}

function rating_over(id,mode)
{
	if(mode==1)
	{
		for(i=1;i<=id;i++)
			el('img_'+i).src='./images/star2.gif';
	}
	else
		for(i=1;i<=id;i++)
			el('img_'+i).src='./images/star1.gif';
}

function defPosition(event) {
	var x = 0;
	var y = 0;
	var event = event || window.event;
	if (document.attachEvent != null) {
		x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
		y = window.event.clientY + document.documentElement.scrollTop;
	}
	if (!document.attachEvent && document.addEventListener) {
		x = event.clientX + window.scrollX;
		y = event.clientY + window.scrollY;
	}

	return {x:x, y:y};
}

function ShowComment(id, event) {
	c = defPosition(event);
	block = el('_comment_' + id);
	block.style.left = c.x+20+'px';
	block.style.top = c.y-5+'px';
	block.style.display = '';
	el('_scroll_' + id).start();
}

function HomePage(ob) {
	//~ ob.style.behavior = 'url(#default#homepage)';
	ob.setHomePage(document.location);
} 

function Bookmark(title, url) {
	if (!title) {
		title = "OnlineGayVideo.Com - Огромная коллекция отборного ГЕЙ ПОРНО!";
	}
	if (!url) {
		url = "http://www.onlinegayvideo.com";
	}
	
	if (window.sidebar) {
		window.sidebar.addPanel(title, url, "");
	} else if (window.external) { 
		window.external.AddFavorite(url, title);
	} else if (window.opera && window.print) { 
		return true;
	}
}

function ShowSite(id, event) {
	c = defPosition(event);
	site = el(id);
	site.style.left = c.x+20+'px';
	site.style.top = c.y-5+'px';
	site.style.display = '';
	show(id);
}

function ShowUpdate(date) {
	parent.redirect('index.php?update=' + date);
}

function Calendar(month, year) {
	redirect('calendar.php?month=' + month + '&year=' + year);
}

function preLoadPicture(pic) {
	i = new Image();
	i.src = pic;
}

stopThumb = 0;
curid = 0;

function startThumbRotate(id, num){
	curid = id;
	stopThumb = 0;
	thumbRotate(id, num);
}

function changeImage(pic){
}

function thumbRotate(id, num){
	if(stopThumb == 0 && id == curid){
		num++;
		if(num >= thumbs[curid].length) num = 0;
		document.getElementById('thumbimg'+curid).src = thumbs[curid][num];
		document.getElementById('thumbimg'+curid).style.cursor = 'pointer';
		next = num+1;
		if(next < thumbs[curid].length) {
			preLoadPicture(thumbs[curid][next]);
		} else {
			preLoadPicture(thumbs[curid][0]);
		}
		setTimeout("thumbRotate("+curid+", "+num+")",1000);		
	}
}

function stopThumbRotate(id){
	stopThumb = 1;
	curid = 0;
	document.getElementById('thumbimg'+id).src = thumbs[id][0];
	document.getElementById('thumbimg'+id).style.cursor = 'pointer';
}