// For www.pref.nagasaki.jp JavaScript
// No Japanese Please!


// --------------------------------------------------------------------------------------------
// It is a program executed when reading here. 
// --------------------------------------------------------------------------------------------
// CSS switch JavaScript
// It doesn't move when JavaScript is off. 
var cookieName = "nagasakipreffont";// Name of cookie.
var cookieExpDays = 0;// Expiration date of cookie.
var cookiePath = "/";
var FontSizeEm = 0; //
var FontSizeEmDef = 10; //
FontSizeEm = getCookie(cookieName); // It reads from Cookie.
if ((FontSizeEm == "")||(FontSizeEm == "10")) { // When Cookie is empty.
	setCookie(cookieName, FontSizeEmDef, cookieExpDays, cookiePath); //img/header/ Please do not delete it.
} else {
	FontSizeEm = Math.round( (FontSizeEm * 10) ) / 100;
	FontSizeEm = FontSizeEm +"em";

	document.write("<style type=\"text/css\">");
	document.write("<!--");
	document.write("body{ ");
	document.write("	font-size: "+FontSizeEm+";");
	document.write("}");
	document.write("-->");
	document.write("</style>");
}




// --------------------------------------------------------------------------------------------
// From here to function
// --------------------------------------------------------------------------------------------

// It is a script for the search input field. 
function funcOnFocus(txtTargetIn,strNameIn) {
	if(txtTargetIn.value==strNameIn){
		txtTargetIn.value = "" ;
		txtTargetIn.style.color   = '' 
	} else {
		txtTargetIn.select() ; // When having input it, it selects it. 
	}
}

function funcOnBlur(txtTargetIn,strNameIn) {
	if(txtTargetIn.value=="") {
		txtTargetIn.value = strNameIn ;
		txtTargetIn.style.color   = '#CCCCCC' 
	}
}



// from Dreamweaver
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



// Visible/hidden of the id tag is switched a mouse it on. 
function GoshowId (showid) {
	if ( document.getElementById )
		document.getElementById( showid ).style.visibility   = 'visible' 
	else if ( document.all ) document.all( showid ).style.visibility = 'visible' 
	else if ( document.layers ) document.layers[ showid ].visibility = 'show' 

	//document.getElementById(hideid).style.visibility = "hidden";
	//document.getElementById(showid).style.visibility = "visible";
}

function GohideId (showid) {
	if ( document.getElementById )
		document.getElementById( showid ).style.visibility   = 'hidden' 
	else if ( document.all ) document.all( showid ).style.visibility = 'hidden' 
	else if ( document.layers ) document.layers[ showid ].visibility = 'hide' 

	//document.getElementById(showid).style.visibility = "hidden";
}


// Font-size of CSS is adjusted.
function ChangeFONTSIZE (FontSize) {
	// CSS switch JavaScript
	// It doesn't move when JavaScript is off. 
	// Cookie Name
	var cookieName = "nagasakipreffont";
	
	// Expiration date of cookie.
	var cookieExpDays = 30;

	// Cookie Path
	var cookiePath = "/";

	//alert (document.body.style);
	var FontSizeEm = 0; //
	FontSizeEm = getCookie(cookieName); //It reads from Cookie. 
	//alert (FontSizeEm);
	if (FontSizeEm == "") { // When Cookie is empty.
		if (FontSize == "+") {
			FontSizeEm = 11;
			setCookie(cookieName, FontSizeEm, cookieExpDays, cookiePath);
			FontSizeEm = Math.round( (FontSizeEm * 10) ) / 100;
			FontSizeEm = FontSizeEm +"em";
			document.body.style.fontSize = FontSizeEm;
		}
		else if (FontSize == "-") {
			FontSizeEm = 10;
			setCookie(cookieName, FontSizeEm, cookieExpDays, cookiePath);
			FontSizeEm = Math.round( (FontSizeEm * 10) ) / 100;
			FontSizeEm = FontSizeEm +"em";
			document.body.style.fontSize = FontSizeEm;
		}
		else {
			// Nothing is done.
		}
	} else {
		if (FontSize == "+") {
			//FontSizeEm = 1.1;
			FontSizeEm++; //The addition substitution is done. 
			setCookie(cookieName, FontSizeEm, cookieExpDays, cookiePath);
			FontSizeEm = Math.round( (FontSizeEm * 10) ) / 100;
			FontSizeEm = FontSizeEm +"em";
			document.body.style.fontSize = FontSizeEm;
		} 
		else if (FontSize == "-") {
			FontSizeEm = 10;
			setCookie(cookieName, FontSizeEm, cookieExpDays, cookiePath);
			FontSizeEm = Math.round( (FontSizeEm * 10) ) / 100;
			FontSizeEm = FontSizeEm +"em";
			document.body.style.fontSize = FontSizeEm;
		}
		else {
			// Nothing is done.
		}
	}
}


/*
 * The cookie is acquired. 
 */
function getCookie(name) {
	return document.cookie.match("\\b" + name + "=([^;]*)")
	? unescape(RegExp.$1) : "";
}

/*
 * The cookie is issued.
 */
function setCookie(name, value, days, path) {
	var       temp  =   name + "=" + escape(value);
	if (days) temp += "; expires=" + expires(days);
	if (path) temp += "; path="    + escape(path);
	document.cookie = temp;
}

function expires(days) {
	var date = new Date();
	date.setTime(date.getTime() + (days * 24*60*60*1000));
	return date.toGMTString();
}

/*
 * The get variable is analyzed.
 */
function getArg() {
	getArg.data = new Array();
	getArg.string = location.search.substring(1);//? Suppression
	if (getArg.string) {
		getArg.string = getArg.string.split('&');
		for(var i = 0; i != getArg.string.length; i++) {
			getArg.data[ck_shikibetushi(getArg.string[i].split('=')[0])] 
	        =  Escape(unescape(getArg.string[i].split('=')[1]));
		}
	}
}

function ck_shikibetushi(shiki) { //Naming check of identifier (property)
	shiki_TOP = shiki.substring(0,1);
	if(shiki_TOP.match(/[a-zA-Z_$]/g) == null) {
		alert(shiki+"argument is illegal.(Please make the first character either ASCII,_,$)");
		return null;
	}
	else if(shiki.match(/[^a-zA-Z0-9_$]/g) != null) {
		alert(shiki+"argument is illegal.(Please make the first character either ASCII,_,$)");
		return null;
	} 
	return shiki;
}

function Escape(str) { // It converts it into the character reference. 
	str = str.replace( /\&/g, '&amp;' );
	str = str.replace( /</g, '&lt;' ); 
	str = str.replace( />/g, '&gt;' ); 
	str = str.replace( /\"/g, '&quot;' );
	str = str.replace( /\'/g, '&#39;' );
	return str;
}


function SWwopen(WO){
  NewWin=window.open("","SWindow","toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,width=750,height=680");
  NewWin.location.href=WO;
  NewWin.focus();
  NewWin.moveTo(20,20);
}
