// ポップアップウィンドウ
function win_open( name_html, win_width, win_height )
{
	// ウィンドウの状態定義
	var state = "toolbar=no, location=no, directories=no, menubar=no, resizable=yes, width=" + win_width + ", height=" + win_height;

	// ウィンドウを開く
	window.open( name_html, "win_open", state );
}

// 画面遷移
// 遷移先URL、遷移先に渡すパラメータ
function send( url, status )
{
	document.main.status.value = status;
	document.main.action = url;
	document.main.submit();
}

// ラジオボタンのvalueを取得する
function Get_RadioValue( formname, radioname )
{
	var result = "";
	for( i=0; i<document.forms[formname][radioname].length; i++ )
	{
		if( document.forms[formname][radioname][i].checked )
		{
			result = document.forms[formname][radioname][i].value;
		}
	}
	return result;
}

// ラジオボタンのvalueを取得する
function Get_RadioValueNum( formname, radioname,num )
{
	var result = "";
	for( i=0; i<document.forms[formname][radioname][num].length; i++ )
	{
		if( document.forms[formname][radioname][num][i].checked )
		{
			result = document.forms[formname][radioname][num][i].value;
		}
	}
	return result;
}

// 現在年月日を取得する
function GetYMD()
{
	var now = new Date();
	var year = now.getYear();
	var month = now.getMonth() + 1;
	if( month < 10 )
	{
		month = "0" + month;
	}
	var day = now.getDate();
	if( day < 10 )
	{
		day = "0" + day;
	}
	var ymd = year + "/" + month + "/" + day;

	return ymd;
}

// 日付の形式をチェックする。
// 0000/00/00
// この形式であれば0;
// この形式以外ではalertを表示して1
function checkDate( inputDate, inputName )
{
	if( inputDate.match(/(\d{2})\/(\d{2})\/(\d{2})/) )
	{
		return 0;
	}
	else
	{
		alert( inputName+"：日付の形式が不正です。" );
		return 1;
	}
}


var isNN4, isNN7, isIE;
if ((navigator.appName == "Netscape") && (navigator.appVersion.charAt(0) < 5)) {
	isNN4 = true;
} else if ((navigator.appName == "Netscape") && (navigator.appVersion.charAt(0) > 4)) {
	isNN7 = true;
} else if (navigator.appName.indexOf("Microsoft") != -1) {
	isIE = true;
}

var newWindow = null; 
var image = null; 
var orig_width = 0; 
var orig_height = 0; 
var limit_window_size = 1;
var scroll = null;
var h_margin = 30;
var v_margin = 30;

function openNewWindow(image,width,height) {
	orig_width = width; orig_height = height;

	if (limit_window_size) {
		if ((orig_width > screen.availWidth) || (orig_height > screen.availHeight)) { 
			scroll = "scrollbars,";
			if (orig_width > screen.availWidth) { orig_width = screen.availWidth - h_margin }
			if (orig_height > screen.availHeight) { orig_height = screen.availHeight - v_margin }
		} else {
			scroll = "";
		}
	} else {
		scroll = "";
	}	

	if (newWindow && !newWindow.closed) { 
		newWindow.close();
	}

	newWindow = window.open("", "newWindow","width="+orig_width+",height="+orig_height+",left=0,top=0," + scroll + "titlebar=no,resizable");
	var newContent = "<HTML><HEAD><TITLE></TITLE>";
	newContent += "<STYLE>";
	newContent += "BODY { margin:0 }";
	newContent += "</STYLE>";
	newContent += "</HEAD><BODY>";

	newContent += "<LAYER ID='photo' LEFT=0 TOP=0 WIDTH=";
	newContent += width;
	newContent += " HEIGHT=";
	newContent += height;
	newContent += ">";

	newContent += "<a href=\"javascript:window.close()\"><IMG SRC='' WIDTH=";
	newContent += width;
	newContent += " HEIGHT=";
	newContent += height;
	newContent += " border=0></A>";

	newContent += "</LAYER>";

	newContent += "</BODY></HTML>";
	newWindow.document.write(newContent);
	newWindow.document.close();

	if (isNN4) {
		newWindow.document.photo.document.images[0].src = image;
	} else if (isNN7 || isIE) {
		newWindow.document.images[0].src = image;
	}

	newWindow.focus();
	newWindow.window.moveTo(screen.width/2-orig_width/2,screen.height/2-orig_height/2);
}
