var W = window;
var D = W.document;
var DA = D.all;
var a = 0;
var offsetX = 0;
var offsetY = 0;

var NAVIGATOR = 0;
x = navigator.userAgent;
if( x.indexOf( 'MSIE' ) > 0 && x.indexOf( 'Opera' ) <= 0 ) NAVIGATOR = 1;
else NAVIGATOR = 0;

function go( url, opt, w, h, s, r ){
	if( opt == 1 ){
		if( !w )w = 700;
		if( !h )h = 400;
		if( !s )s = 1; else s = 0;
		if( !r )r = 1; else r = 0;
		l = ( screen.width - w )/2;
		t = ( screen.height - h )/2;
		
		return window.open( url, "_blank", "toolbar=0,scrollbars="+s+",resizable="+r+",left="+l+",top="+t+",width="+w+",height="+h );
	}
	else if( opt == 2 ) {
		return window.open( url, "_blank" );
	}
	else if( opt == 3 ){
		return window.open( url, '_blank', 'fullscreen=1, scrollbars=1, toolbar=0, resizable=1' );
	}
	else {
		window.location.href = url;
	}
}

function page_navigate( prev, next ){
	var key_code = 0;
	document.onkeydown = function( ) {
		if (window.event ){
			key_code = window.event.keyCode;
			if( key_code == 37 && prev ){
					go( prev );
			}
			else if( key_code == 39 && next ){
				go( next )
			}
		}
	}
}

//################################################

function photo_menu( foto_id, e ) {
	if( !e ) e = event;
	
	var acm = document.getElementById( "show_adm_cm" );
	if( !acm || window.innerHeight ) {
		acm = create_element( "SCRIPT", "show_adm_cm" );
	}
	
	if( acm ) {
		var xx = e.clientX;
		var yy = e.clientY;
		
		acm.src = "/w_inc/pmenu.js?foto_id=" + foto_id + "&xx=" + xx + "&yy=" + yy + "&" + (new Date()).getTime();
	}
}

//################################################

function create_element( type, id, father, add ) {
	if( !father ) father = document.body;
	if( !add ) add = '';
	var newElem = document.createElement(type);
	newElem.id = id;
	eval( "with( newElem ) {" + add + "}" );
	father.appendChild(newElem);
	return newElem;
}

//################################################

var EX_INFO = false;
function get_menu( html, x, y ) {
	var FULL_HEIGHT;
	var FULL_WIDTH;
	
	if( !EX_INFO ) {
		EX_INFO = create_element( 'DIV', 'admin_contextmenu' );
		EX_INFO.style.display = "none";
	}
	
	if( !x ) x = 0;
	if( !y ) y = 0;
	var xx = x + document.body.scrollLeft;
	var yy = y + document.body.scrollTop;

	var dw = document.body.scrollWidth;
	var dh = document.body.scrollHeight;

	if( !EX_INFO ) {
		return;
	}
	EX_INFO.innerHTML =  html;
	EX_INFO.style.position = "absolute";
	EX_INFO.style.top = yy;
	EX_INFO.style.left = xx;
	EX_INFO.style.zIndex = "40";
	EX_INFO.style.textAlign = "center";
	EX_INFO.style.filter = "progid:DXImageTransform.Microsoft.Shadow(direction=135,color=black,strength=3)";
	EX_INFO.style.display = "";
	
	if( parseInt( EX_INFO.style.left ) + 230 > dw ) {
		EX_INFO.style.left = dw - 230;
	}
	if( parseInt( EX_INFO.style.top ) + EX_INFO.scrollHeight + 3 > dh ) {
		EX_INFO.style.top = dh - EX_INFO.scrollHeight - 3;
	}

	if( !document.onkeypress ) {
		document.onkeypress = function() {
			if( event.keyCode == 27 ) {
				close_win();
			}
		}
	}
	
	if( !document.mousedown ) {
		document.onmousedown = function() {
			if( !FOCUSED ) {
				close_win();
			}
		}
	}
	
	var FOCUSED = false;
	EX_INFO.onmousedown = function() {
		FOCUSED = true;
	}
	
	EX_INFO.onmouseup = function() {
		FOCUSED = false;
	}
}

//################################################

function close_win() {
	if( !EX_INFO ) return;
	EX_INFO.style.display = "none";
	EX_INFO.innerHTML = "";
	
	document.onkeypress = null;
	document.onmousedown = null;
}

//################################################

function prof_pic( pic, w, h ) {
	with( go( "", 1, w, h, 1, 1 ) ) {
		document.body.style.backgroundColor = "black";
		document.body.style.margin = "0px";
		document.body.innerHTML = '<a href="javascript:;" onclick="self.close();"><img src="' + pic + '" width="' + w + '" height="' + h + '" border="0"></a>';
	}
}

function alert_r(obj, ret, separator) {
	if( !ret ) ret = false;
	if( !separator ) separator = "\n";
	var r = "";
	for( var i in obj ) {
		r += i + ": " + obj[i] + separator;
	}
	if( ret ) {
		return r;
	}
	alert( r );
}

function mail2friend(subj) {
	location.href = "mailto:?subject=" + subj + "&body=" + location.href;
}



function get_admin_menu( uid ) {
	var acm = document.getElementById( "show_adm_cm" );
	if( !acm ) {
		acm = create_element( "SCRIPT", "show_adm_cm" );
	}
	if( acm ) {
		acm.src = "/amenu.js?uid=" + uid + "&xx=" + ( event.x + document.body.scrollLeft ) + "&yy=" + ( event.y + document.body.scrollTop );
	}
}


function create_context_menu( items ) {
	ret = '';
	ret += '<table border="0" cellpadding="0" cellspacing="2" bgcolor="window"';
	ret += '	style="border: solid 1px gray;">';
	ret += '	<tr>';
	ret += '	<td>';
	ret += '	<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%" bgcolor="window" onselectstart="return false;">';
	ret += '';
	for( i = 0; i < items.length; i ++ ) {
		name = items[i][0];
		action = items[i][1];
		if( /^sep[0-9]+$/.test( name ) ) {
			ret += '';
			ret += '<tr><td height="3" style="cursor: default; border-bottom: solid 1px silver; font-size: 2px;">&nbsp;</td></tr>';
			ret += '<tr><td height="3" style="cursor: default;"></td></tr>';
			continue;
		}
		ret += '';
		ret += '<tr>';
		ret += '	<td height="17" style="font: menu; background-color: window; color: windowtext;  padding: 0px 17px; cursor: default; white-space: nowrap;"';
		ret += '		onmouseover="this.style.color = \'highlighttext\'; this.style.backgroundColor = \'highlight\';"';
		ret += '		onmouseout="this.style.color = \'windowtext\'; this.style.backgroundColor = \'window\';"';
		ret += '		onclick="' + action + '">';
		ret += '		' + name + '';
		ret += '	</td>';
		ret += '</tr>';
	}
	ret += '';
	ret += '	</table>';
	ret += '	</td>';
	ret += '	</tr>';
	ret += '</table>';
	
	return ret;
}


var EX_INFO = false;
function get_menu( html, x, y ) {
	height	= document.body.offsetHeight ? document.body.offsetHeight : window.innerHeight;
	width	= document.body.offsetWidth ? document.body.offsetWidth : window.innerWidth;
	
	var FULL_HEIGHT;
	var FULL_WIDTH;
	
	
	if( !EX_INFO ) {
		EX_INFO = create_element( 'DIV', 'admin_contextmenu' );
		EX_INFO.style.display = "none";
	}
	
	if( !x ) x = 0;
	if( !y ) y = 0;
	var xx = event ? event.x : x;
	var yy = event ? event.y : y;

	if( !EX_INFO ) {
		return;
	}
	EX_INFO.innerHTML =  html;
	EX_INFO.style.position = "absolute";
	EX_INFO.style.top = yy;
	EX_INFO.style.left = xx;
	EX_INFO.style.zIndex = "40";
	EX_INFO.style.textAlign = "center";
	EX_INFO.style.filter = "progid:DXImageTransform.Microsoft.Shadow(direction=135,color=gray,strength=3)";
	EX_INFO.style.display = "";
		
	if( !document.onkeypress ) {
		document.onkeypress = function() {
			if( event.keyCode == 27 ) {
				close_win();
			}
		}
	}
	
	if( !document.mousedown ) {
		document.onmousedown = function() {
			if( !FOCUSED ) {
				close_win();
			}
		}
	}
	
	var FOCUSED = false;
	
	EX_INFO.onmousedown = function() {
		FOCUSED = true;
	}
	
	EX_INFO.onmouseup = function() {
		FOCUSED = false;
	}
}