
// pbject of subwindow control
var _window = {
	'minLeft' : 0,
	'minTop' : 0,
	'maxLeft' : screen.availWidth - 10,
	'maxTop' : screen.availHeight - 10,
	'object' : [ ]
};

// get a sort of os
var _OS = getOS ( );

// get a sort of browser and its version
var _browser = getBrowser ( );



/* adjustPopupSize ---------------- */
function adjustPopupSize ( width, height, modes, fullscreen ) {
	// modes : [ scrollbars, resizable, status, menubar, toolbar, addressbar, directories ]

	var bn = _browser.name;
	var bv = _browser.version;

	var scrollbars = modes[ 0 ];
	var resizable = modes[ 1 ];
	var status = modes[ 2 ];
	var menubar = modes[ 3 ];
	var toolbar = modes[ 4 ];
	var addressbar = modes[ 5 ];
	var directories = modes[ 6 ];

	if ( fullscreen ) {
		if ( _OS == 'Mac' && bn == 'Netscape' ) if ( resizable || status ) height -= 18; // Mac Netscape
		if ( bn == 'Safari' ) { // Safari
			var flg = false;
			for ( var i = 0; i < modes.length; i++ ) {
				if ( modes[ i ] ) {
					flg = true;
					break;
				}
			}
			if ( !flg ) height -= 22;
		}
	} else {
		if ( scrollbars ) {
			if ( _OS == 'Win' && bn == 'IE' && bv <= 5 ) width += 18; // Win IE 5.0-
			else if ( _OS == 'Win' && bn == 'IE' && bv == 5.5 ) width += 16; // Win IE 5.5
			else if ( _OS == 'Win' && bn == 'IE' && bv == 6 ) width += 17; // Win IE 6.0
			else if ( _OS == 'Win' && bn == 'IE' && bv >= 7 ) width += 16; // Win IE 7.0+
			else if ( _OS == 'Win' && bn == 'Firefox' ) width += 19; // Win Firefox 1.0+
			else if ( _OS == 'Win' && bn == 'Opera' ) width += 17; // Win Opera 6.x+
			else if ( _OS == 'Win' && bn == 'Mozilla' ) width += 19; // Win Mozilla 1.7.5+
			else if ( _OS == 'Win' && document.layers ) width += 16; // Win Netscape 4.x-
			else if ( _OS == 'Mac' && bn == 'IE' ) { width -= 1; height -= 16; } // Mac IE
			else if ( _OS == 'Mac' && bn == 'Firefox' ) width += 15; // Mac Firefox 1.0+
			else if ( _OS == 'Mac' && bn == 'Opera' ) width += 15; // Mac Opera 6.x+
			else if ( _OS == 'Mac' && bn == 'Mozilla' ) width +=16; // Mozilla
			else if ( _OS == 'Mac' && document.layers ) if ( !status ) width += 15; else height -= 15; // Mac Netscape 4.x-
			else if ( bn == 'Netscape' && bv < 7 ) width += 14; // Netscape 6.x
			else if ( bn == 'Netscape' && bv >= 7 ) width += 15; // Netscape 7.x
			else if ( bn == 'Safari' ) width +=15; // Safari
			else if ( bn == 'Camino' ) width +=15; // Camino
		}
		if ( menubar ) {
			if ( _OS == 'Win' && bn == 'IE' ) height -= 19; // Win IE
			else if ( _OS == 'Win' && document.layers && width < 376 ) height += 18; // Win Netscape 4.x-
		}
		if ( bn == 'Safari' ) { // Safari
			height += 1;
			if ( status ) height += 16;
			if ( addressbar ) height += 51;
		}
	}

	var val = [ width, height ];
	val[ 'width' ] = val[ 'w' ] = width;
	val[ 'height' ] = val[ 'h' ] = height;

	return val;
}

/* openWindow ---------------- */
function openWindow ( loc, name, left, top, width, height, modes, fullscreen ) {
	// modes : [ scrollbars, resizable, status, menubar, toolbar, addressbar, directories ]

	var scrollbars = ( modes[ 0 ] ) ? 'yes' : 'no';
	var resizable = ( modes[ 1 ] ) ? 'yes' : 'no';
	var status = ( modes[ 2 ] ) ? 'yes' : 'no';
	var menubar = ( modes[ 3 ] ) ? 'yes' : 'no';
	var toolbar = ( modes[ 4 ] ) ? 'yes' : 'no';
	var addressbar = ( modes[ 5 ] ) ? 'yes' : 'no';
	var directories = ( modes[ 6 ] ) ? 'yes' : 'no';

	var props = 'menubar=' + menubar + ',toolbar=' + toolbar + ',location=' + addressbar + ',directories=' + directories +
		',status=' + status + ',scrollbars=' + scrollbars + ',resizable=' + resizable;

	if ( fullscreen && _OS == 'Win' && _browser.name == 'IE' ) props += ',fullscreen=yes';
	else props += ',left=' + left + ',top=' + top + ',width=' + width + ',height=' + height;

	_window.object[ name ] = window.open ( loc, name, props );
	_window.object[ name ].focus ( );

	return _window.object[ name ];
}


/* OSの種類を取得 ---------------- */
function getOS ( ) {
	var av = navigator.appVersion;

	return ( av.match ( 'Win' ) ) ? 'Win' : ( av.match ( 'Mac' ) ) ? 'Mac' : 'unknown';
}

/* ブラウザの種類とバージョンを取得 ---------------- */
function getBrowser ( ) {
	// arguments : ( [ mode ] )

	var args = arguments;

	var name = 'unknown';
	var ver = 'unknown';
	var ua = navigator.userAgent;
	var ap = 1;
	if ( ua.match ( /Opera\// ) ) { name = 'Opera'; ua = ua.split ( '/' ); } // Opera 6.x+
	else if ( ua.match ( /Opera / ) ) { name = 'Opera'; ua = ua.split ( 'Opera ' ); } // Opera 6.x+
	else if ( ua.match ( /MSIE/ ) ) { name = 'IE'; ua = ua.split ( 'MSIE ' ); } // IE
	else if ( ua.match ( /Firebird|Firefox/ ) ) { name = 'Firefox'; ua = ua.split ( '/' ); ap = 3; } // Firefox
	else if ( ua.match ( /Safari/ ) ) { name = 'Safari'; ua = ua.split ( '/' ); ap = 3; } // Safari
	else if ( ua.match ( /Netscape/ ) ) { name = 'Netscape'; ua = ua.split ( '/' ); ap = 3; } // Netscape 6.x+
	else if ( ua.match ( /^Mozilla\/[0-9\.]+ \[/ ) ) { name = 'Netscape'; ua = ua.split ( '/' ); } // Netscape 4.x-
	else if ( ua.match ( /Gecko\/[0-9]{8}$/ ) ) { name = 'Mozilla'; ua = ua.split ( 'rv:' ); } // Mozilla
	else if ( ua.match ( /Camino/ ) ) { name = 'Camino'; ua = ua.split ( '/' ); ap = 3; } // Camino
	
	if ( name != 'unknown' ) {
		if ( !ua[ ap ].match ( /\./ ) ) {
			ver = ua[ ap ];
		} else {
			var temp = ua[ ap ].split ( '.' );
			ver = temp[ 0 ] + '.' + temp[ 1 ].substr ( 0, 1 );
		}
	}

	var val = [ name, ver ];
	val[ 'name' ] = name;
	val[ 'version' ] = ver;

	return ( args[ 0 ] == 'name' ) ? name : ( args[ 0 ] == 'ver' ) ? ver : val;
}


function automaticWindow(parmalink){
	
	var path = "feature/f_automatic/index.html";
	if(parmalink != undefined)
	{
		if(parmalink.indexOf('?') > -1)
		{
			path += parmalink;
		}
		else
		{
			path += '#/' + parmalink;
		}
	}
var size = adjustPopupSize (1000,704, [1,1,0,0,0,0,0]);
var win = openWindow (  path,"", screen.availWidth/2-1000/2,  screen.availHeight/2-704/2,size.width, size.height,[1,1,0,0,0,0,0]);
	 if ( _OS == 'Mac' && bn == 'Firefox' ) win.moveTo ( 0, 0 );
	if ( !term && _OS == 'Win' && bn == 'IE' && bv < 6 || _OS == 'Mac' && bn == 'IE' || bn == 'Netscape' || bn == 'Opera' && bv < 8 ) win.resizeTo ( size.width, size.height );

	//popupFullscreen( path, "automatic",[0,1,0,0,0,0,0]);
}

window.onload = function()
{
	if(_browser.name == "IE")
	{
		var areas = document.getElementsByTagName("area")
		
		var alength = areas.length;
		
		while(alength--)
		{			
			areas[alength].setAttribute("onfocus", new Function("this.blur();"));
		}		
	}
	
}

	