String.prototype.trim = function() 
{
	//return( this.replace(/^\s*([\s\S]*\S+)-\s*$|^\s*$/,'$1') );
	return( this.replace(/^\s*|\s*$/g,"") );
}

function $id(tagId)
{
	return( document.getElementById(tagId) );
}

function $nm(tagName)
{
	return( document.getElementsByName(tagName).item(0) );
}

function addEventToObject(obj, evt, func)
{
	var oldhandler = obj[evt];
	obj[evt] = (typeof obj[evt] != 'function') ? func : function(){oldhandler();func();};
}

function openPopupWindow(path, name, width, height, resizable, scrollbars, status, toolbar)
{
	var left = (screen.width / 2) - (width / 1.8);
	var top = (screen.height / 2) - (height / 1.8);
	if (width == 1 && height == 1)
	{
		left = 99999;
		top = 99999;
	}
	
	var option = 'width=' + width + 
		',height=' + height + 
		',top=' + top + 
		',left=' + left + 
		',resizable=' + (resizable==1 ? 'yes' : 'no') + 
		',scrollbars=' + (scrollbars==1 ? 'yes' : 'no') + 
		',status=' + (status==1 ? 'yes' : 'no') + 
		',toolbar=' + (toolbar==1 ? 'yes' : 'no');
	
	w = window.open(path, name, option);
	w.focus();
}

function gotherwin(url, w, h)
{
	resizesubwin(w, h);
	location.href = url;
}

function resizesubwin(w, h)
{
	window.resizeTo(w, h);	
	var ww = w - getWinWidth();
	var hh = h - getWinHeight();
	window.resizeTo(w + ww, h + hh);
}

function moveToCenter(win)
{
	var left = (screen.width / 2) - (getWinWidth() / 1.8);
	var top = (screen.height / 2) - (getWinHeight() / 1.8);
	win.moveTo(left, top);
}

function getWinWidth()
{
	if( typeof( window.innerWidth ) == 'number' )
	{//Non-IE
		return(window.innerWidth);
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{//IE 6+ in 'standards compliant mode'
		return(document.documentElement.clientWidth);
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{//IE 4 compatible
		return(document.body.clientWidth);
	}
}

function getWinHeight()
{
	if( typeof( window.innerWidth ) == 'number' )
	{//Non-IE
		return(window.innerHeight);
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{//IE 6+ in 'standards compliant mode'
		return(document.documentElement.clientHeight);
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{//IE 4 compatible
		return(document.body.clientHeight);
	}
}

function isZenKana(text)
{
  for(i = 0; i < text.length; i++)
  {
    if(text.charAt(i) < 'ア' || text.charAt(i) > 'ン')
	{
	  if (text.charAt(i) != 'ー') return( false );
    }
  }
  return( true );
}

function checkEmail(email)
{
	var at   = "@";
	var dot  = ".";
	var lat  = email.indexOf(at);
	var lstr = email.length;
	var ldot = email.indexOf(dot);
	
	if (email.indexOf(at) == -1)
		return( false );
	
	if (email.indexOf(at) == -1 || email.indexOf(at) == 0 || email.indexOf(at) == lstr)
		return( false );
	
	if (email.indexOf(dot) == -1 || email.indexOf(dot) == 0 || email.indexOf(dot) == lstr)
		return( false );
	
	if (email.indexOf(at,(lat+1)) != -1)
		return( false );
	
	if (email.substring(lat-1,lat) == dot || email.substring(lat+1,lat+2) == dot)
		return( false );
	
	if (email.indexOf(dot,(lat+2)) == -1)
		return( false );
	
	if (email.indexOf(" ") != -1)
		return( false );
	
	return( true );
}

function checkDate(year, month, day)
{ 
	if (year < 1900 || year >= 2050) return( false );
	var dtCheck = new Date(); 
	dtCheck.setFullYear(year, month - 1, day); 
	return( dtCheck.getMonth() == (month - 1) );
}

function getOS()
{
	return (((navigator.userAgent).toUpperCase()).indexOf('WIN') >= 0) ? 'win' : 'mac';
}

function getBrowser()
{
	var nav = (navigator.userAgent).toUpperCase();
	if (nav.indexOf('FIREFOX') >= 0) return('Firefox');
	if (nav.indexOf('SAFARI') >= 0) return('Safari');
	return('Internet Explorer');
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function createXMLHttpRequest(cbFunc)
{
	var XMLhttpObject = null;
	try
	{
		// Firefox, Safari, Opera, など
		XMLhttpObject = new XMLHttpRequest();
	}
	catch(e)
	{
		try
		{
			// Internet Explorer 6以降
			XMLhttpObject = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				// Internet Explorer 6以前
				XMLhttpObject = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				return null;
			}
		}
	}
	if (XMLhttpObject) XMLhttpObject.onreadystatechange = cbFunc;
	return XMLhttpObject;
}


var address1 = null;
var address2 = null;
var httpObj = null;

function autoAddress(p1, p2, a1, a2, www)
{
	address1 = $nm(a1);
	address2 = $nm(a2);
	
	var post = String($nm(p1).value) + String($nm(p2).value);
	var url = www + '/postcode.fnc.php?pn=' + post;
	httpObj = createXMLHttpRequest(autoAddress_fnc);
	if (httpObj)
	{
		httpObj.open("GET", url, true);
		httpObj.send(null);
	}
}

function autoAddress_fnc()
{
	if ((httpObj.readyState == 4) && (httpObj.status == 200))
	{
		var arrAddress = httpObj.responseText.split(',');
		address2.value = arrAddress[1] + arrAddress[2];
		for (var i = 0; i < address1.length; i++)
		{
			var selAddress = address1.options[i].value;
			if (selAddress == arrAddress[0])
			{
				address1.selectedIndex = i;
				return;
			}
		}
	}
}


// 右クリックをブロック
if(document.layers) { document.captureEvents(Event.KEYDOWN,Event.KEYPRESS,Event.MOUSEDOWN); }
document.oncontextmenu=function() { return(false); }