/*
function winopn(theURL,winName,features) {
	w=500;
	h=600;
	x = (screen.width - w) / 2;
  y = (screen.height - h) / 2;
  opnwin = window.open(theURL,winName,'status=yes,'+'scrollbars=yes,'+'screenX='+x+',screenY='+y+',left='+x+',top='+y+',width='+w+',height='+h);
	opnwin.focus();
}

function getaddress(obj,type){
	address=obj;
	SetDate(address,type);
}

function SetDate(address,type){
if(type==0){
	if(window.opener.document.mailform.to.value==""){
		window.opener.document.mailform.to.value += address;
	}
	else{
			window.opener.document.mailform.to.value += ","+address;
		}
	}
	else if(type==1){
		if(window.opener.document.mailform.Cc.value==""){
			window.opener.document.mailform.Cc.value += address;
		}
		else{
			window.opener.document.mailform.Cc.value += ","+address;
		}
	}
	else if(type==2){
		if(window.opener.document.mailform.Bcc.value==""){
			window.opener.document.mailform.Bcc.value += address;
		}
		else{
			window.opener.document.mailform.Bcc.value += ","+address;
		}
	}
}
*/

function setMailhead(obj,on,off,idx){
	if(document.getElementById){
		document.getElementById(obj).style.display=='none' ? document.getElementById(obj).style.display='': document.getElementById(obj).style.display='none';
	}
	else if(document.all){
		document.all(obj).style.display=='none' ? document.all(obj).style.display='' : document.all(obj).style.display='none';}
	else if(document.layers){
		document.layers[obj].display=='none' ? document.layers[obj].display='' : document.layers[obj].display='none';}
}

function popUpWin( popWindow, popWidth, popHeight, popTitle )
{
	var leftOffset = ( window.screen.width - popWidth ) / 2;
	var topOffset = ( window.screen.height - popHeight ) / 2;
	childWin = window.open(popWindow, popTitle, "height=" + popHeight + ",width=" + popWidth + ",top=" + topOffset + ", left=" + leftOffset + ", toolbar=0,directories=0,status=1,menu=0,scrollbars=no,resizable=no,copyhistory=no,location=0");
	childWin.focus();
}

function insertMail( mailAdd, inputName )
{
	var mailArray = new Array();
	window.opener.document.getElementById(inputName).value = trim(window.opener.document.getElementById(inputName).value);
	var openerMailInput = window.opener.document.getElementById(inputName).value;
	
	// is empty?
	if ( openerMailInput == "" )
	{
		window.opener.document.getElementById(inputName).value = mailAdd + ", ";
		return true;
	}
	
	if ( openerMailInput.length == 1 )
	{
		window.opener.document.getElementById(inputName).value = "";
	}
	
	var mailNewArray = new Array();
	var re = /[\s;,]+/;
	var mailArray = openerMailInput.split(re);
	for ( var i = 0; i < mailArray.length; i++ )
	{
		mailArray[i] = trim( mailArray[i] );
		if ( mailArray[i].length > 0 && emailCheck( mailArray[i] ) && !inArray( mailNewArray, mailArray[i] ) )
		{
			mailNewArray.push( mailArray[i] );
		}
	}
	
	if ( mailNewArray.length > 100 )
	{
		return false;
	}
	else if ( !inArray( mailNewArray, mailAdd ) && emailCheck(mailAdd) && mailAdd.length > 0 )
	{
		mailNewArray.push( mailAdd );
	}
	
	var newMailInput = "";
	for ( var j = 0; j < mailNewArray.length; j++ )
	{
		newMailInput += mailNewArray[j] + ", ";
	}
	
	window.opener.document.getElementById(inputName).value = newMailInput;
}

function inArray(arrayVar, strVar)
{
	for (var i=0; i < arrayVar.length; i++)
	{
		if ( arrayVar[i] === strVar )
		{
			return true;
		}
	}
	return false;
}

function emailCheck( email )
{
	if ( email != '' )
	{
		var reg= /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
		var mail = email;
		if ( reg.test( mail ) )
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return true
	}
}

function trim( str )
{
    return str.replace(/(^\s*)|(\s*$)/g, "");
}

function hiddenObj( objName, inputName, deleteText )
{
	if ( confirm( deleteText ) )
	{
		if ( objName != null )
		{
			window.document.getElementById(objName).style.display = "none";
			window.document.getElementById(inputName).value = '0';
		}
	}
}

function showObj ( objName )
{
	window.document.getElementById(objName).style.display = "";
}

function disableButton( b1 )
{
	//window.document.getElementById( b1 ).disabled = true;
}

function AddFavorite( siteName, url, alertText )
{

		if ( window.sidebar && "object" == typeof( window.sidebar ) && "function" == typeof( window.sidebar.addPanel ) )
		{
			if ( confirm( alertText ) )
			{
				window.sidebar.addPanel( siteName, url, '' );
			}
		}
		else if ( document.all && "object" == typeof( window.external ) )
		{
			if ( confirm( alertText ) )
			{
				window.external.addFavorite( url, siteName );
			}
		}
		else if ( navigator.userAgent.toLowerCase().indexOf('mac')!=-1 )
		{
			if ( confirm( "「お気に入りに追加しますか？」" ) )
			{
				alert('Command/Cmd + Dを押して、このページをお気に入りに追加することをお勧めします');
			}
		}
		else if ( window.opera )
		{
			if ( confirm( "「お気に入りに追加しますか？」" ) )
			{
				alert('Ctrl + Dを押して、このページをお気に入りに追加することをお勧めします');
			}
		}
}
