var D = document;
var nc = ( navigator.userAgent.indexOf("MSIE") == -1 && navigator.userAgent.indexOf("Opera") == -1 ) ? 1 : 0;

var OFFSET_X = 0;
var OFFSET_Y = 0;

if( nc ) { document.write('<LINK HREF="css/main_nc.css" REL="StyleSheet">'); }

function wopen( url, target, w, h, asize, title, res ) 	{
	if( !url ) {
		event.cancelBubble = true;
		event.returnValue = false;
		return;
	}
	if( !target ) target = '_blank';
	if( !w ) w = 500;
	if( !h ) h = 400
	if( !title ) title = '';

	w = parseInt( w, 10 );
	h = parseInt( h, 10 );
	if( asize ) asize = true;
	else asize = false;

	var aw = screen.availWidth;
	var ah = screen.availHeight;
	if( w > aw ) w = aw;
	if( h > ah ) h = ah;

	if( res )r = 0; else r = 1;

	var left = Math.round( ( aw - w ) / 2 );
	var top = Math.round( ( ah - h ) / 2 );

	var wd = window.open( url, target, 'channelmode= 0, directories=0, fullscreen=0, height='+h+'px, width='+w+'px, location=0, menubar=0, resizable='+r+', scrollbars=1, status=0, toolbar=0, top='+top+'px, left='+left+'px' );
	if ( !asize ) { return; }

	if( url.indexOf( window.location.host ) != -1 || url.indexOf( 'http://' ) == -1  ) wd.attachEvent( "onload", function() {resize_new_win( wd, asize, title )	} );
}

//#########################################################

function go( url ) {
	if ( url ) { top.location.href = url; }
}

//#########################################################

function winfull( url, target ) {
	if ( !url ) { return false; }

	if ( !target ) { target = '_blank'; }
    var wd = window.open( url, target, 'fullscreen=1, scrollbars=1, toolbar=0' );
}

//#########################################################

function get_object_offset( obj ) {
	if( !obj ) return;
	var x = y = 0;
	while ( true ) {
		x += obj.offsetLeft;
		y += obj.offsetTop;
		if ( !obj.offsetParent ) { break; }
		obj = obj.offsetParent;
	}
	OFFSET_X = x;
	OFFSET_Y = y;
}

//#########################################################

function show_menu( cid, mod ) {
	if( !cid ) return;
	if( !mod ) mod = false;

	var menu = document.getElementById( "menu"+cid );
	if( !menu ) return;

	var popup = document.getElementById( "popup"+cid );
	if( !popup ) return;

	get_object_offset( menu );

	var dY = menu.clientHeight ? menu.clientHeight : 22;

	if( mod ) {
		popup.style.top = ( OFFSET_Y + dY ) + "px";
		popup.style.left = OFFSET_X + "px";
		popup.className = "show popup";
		menu.className = "menu_on";
	}
	else {
		popup.className = "hide popup";
		menu.className = "menu_off";
	}
	
}

//#########################################################

function setCookie( name, value, path, domain, expires, secure ) {
	// get expires in days
	// set time in milliseconds
	var today = new Date(); today.setTime(today.getTime());
	var expires_date = new Date( today.getTime() + ( expires ? expires * 1000 * 60 * 60 * 24 : 0 ) );	
	document.cookie = name + "=" + escape( value ) +
	  ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	  ( ( path ) ? ";path=" + path : "" ) + 
	  ( ( domain ) ? ";domain=" + domain : "" ) +
	  ( ( secure ) ? ";secure" : "" );
}

//#########################################################

function getCookie( name ) {
	var cook = document.cookie;
	var pos = cook.indexOf( name + '=' );
	if( pos == -1 ) { return null; } 
	else {
	  var pos2 = cook.indexOf( ';', pos );
	  if( pos2 == -1 ) return unescape( cook.substring( pos + name.length + 1 ) );
	  else return unescape( cook.substring( pos + name.length + 1, pos2 ) );
	}
}

//###########################################################

function wait( mod ) {
	if( !mod ) mod = 0;
	var obj = document.getElementById( "waiting" );
	if( obj ) obj.className = !mod ? "hide" : "show";
	return true;
}

//###########################################################

function show_hide( id ) {
	var obj = document.getElementById( id );
	if( !obj ) return;
	obj.className = obj.className == 'hide' ? 'show' : 'hide'; 
}
